#include "GLCP.h"
#include "dbimage.h"
#include "bdbenv.h"
#include "dbtmpfeature.h"
#include <tclap/CmdLine.h>
#include "naivebayes.h"
#include "emcluster.h"
#include <string>

int main( int argc, char *argv[] )
{

#ifndef _NOMAGICK_
  try
    {
      ///set up the command line parsing
      TCLAP::CmdLine cmd("Image alignment program", ' ', "0.001");

      TCLAP::ValueArg<std::string> dbdir("d", "db", "database dirctory", true, "", "databaase");
      TCLAP::ValueArg<std::string> dbname("f", "file", "database file", true, "", "file");

      cmd.add(dbdir);
      cmd.add(dbname);

      bdbenv bdb;
      dbtmpfeature dbtf_g;

      cmd.parse(argc, argv);

      dbtf_g.setname( dbname.getValue() );

      bdb.open( dbdir.getValue() );
      dbtf_g.init( bdb.envptr(), 0 );

      bdb.adddb( &dbtf_g );

      bdb.cleanlog();


      unsigned int maxid;
      maxid = dbtf_g.maxid();;
      int bsz;
      dbtf_g.getrecsize( bsz );
      char *buff;
      buff = new char [bsz];
      GLCP myglcp;
      for( unsigned i = 1; i < maxid; i++ )
        {
          dbtf_g.get( i, buff );
          std::vector< double * > s;
          s.clear();
          myglcp.del();
          myglcp.deserialize( buff, bsz );
          int nf;
          nf = 0;
          myglcp.getfeaturets( s, nf );
          
          for( unsigned t = 0; t < s.size(); t++ )
            {
              for( int z = 0; z < nf; z++ )
                {
                  std::cout << s[t][z] << " ";
                }
              delete [] s[t];
              std::cout << "\n";
            }
          s.clear();
        }
      delete [] buff;

      dbtf_g.close();
      bdb.close();
    }
  catch (TCLAP::ArgException &e)
    {
      std::cout << "ERROR: " << e.error() 
                << " for arg " << e.argId() << "\n";
      return 0;
    }
  
#else
  std::cout << "compiled with no image magick\n";
#endif
  return 0;
}
