/* Copyright (c) 1997-2004
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
   http://www.math.tu-berlin.de/polymake,  mailto:polymake@math.tu-berlin.de

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
*/

#ident "$Project: polymake $$Id: t_f_vector.cc,v 1.5 2005/09/22 17:12:48 gawrilow Exp $"

#include <Poly.h>
#include <complex_tools.h>

namespace polymake {
namespace topaz {
  
void t_f_vector(Poly& p)
{
   const Array< Set<int> > C = p.give("FACETS");
   const int dim = p.give("DIM");
   const bool is_pure = p.give("PURE");

   Array<int> f_vector(dim+1);
   for (int k=0; k<=dim; ++k) {
      const PowerSet<int>& skeleton = k_skeleton(C,k);
      if (is_pure) {
	 f_vector[k] = skeleton.size();
      } else {
	 int f_k=0;
	 for (Entire< PowerSet<int> >::const_iterator f=entire(skeleton); !f.at_end(); ++f)
	    if (f->size()==k+1)
	       ++f_k;

	 f_vector[k] = f_k;
      }
   }
   p.take("F_VECTOR") << f_vector;
}
   
} }

using namespace polymake;

/** @file t_f_vector
 *
 *  Produce the f-vector of a simplicial complex.
 *
 *  @synopsis t_f_vector <file>
 *
 *  @reading  FACETS, DIM, PURE
 *  @writing  F_VECTOR
 */

int main(int argc, const char* argv[])
{
   if (argc!=2) {
      cerr << "usage: " << argv[0] << " <file>" << endl;
      return 1;
   }
   try {
      Poly p(argv[1], ios::in | ios::out);
      topaz::t_f_vector(p);
   }
   catch (const std::exception& e) {
      cerr << e.what() << endl;
      return 1;
   }
   return 0;
}


// Local Variables:
// mode:C++
// c-basic-offset:3
// End:
