#ifndef _NOMAGICK_
#include <Magick++.h>
#endif

#include <iostream>
#include <string>
#include <math.h>
#include "imagealign.h"
#include "image2d.h"
#include <fftw3.h>
#include <tclap/CmdLine.h>
#include "bdbenv.h"
#include "dbimage.h"

int main( int argc, char *argv[] )
{
  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");

      cmd.add(dbdir);

      cmd.parse(argc, argv);
      image2d ima, imb;
      bdbenv bdb;
      dbimage imstore;
      imagealign imaln;
      bdb.open( dbdir.getValue() );
      imstore.init( bdb.envptr() );
      bdb.adddb( &imstore );
      bdb.cleanlog();
      std::vector< int > stackx, stacky;
      imstore.rows( stackx );
      for( unsigned i = 0; i < stackx.size(); i++ )
        std::cout << stackx[i] << " ";
      std::cout << "\n";
      for( unsigned i = 0; i < stackx.size(); i++ )
        {
          imstore.rowstacks( stackx[i], stacky );
          for( unsigned j = 0; j < stacky.size(); j++ )
            std::cout << stacky[j] << " ";
          stacky.clear();
          std::cout << "\n";
        }
      imstore.close();
      bdb.close();
    }
  catch (TCLAP::ArgException &e)
    {
      std::cout << "ERROR: " << e.error() 
                << " for arg " << e.argId() << "\n";
      return 0;
    }
  return 0;
}
