00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <istream>
00030 #include <ostream>
00031
00032
00033 #include "chomp/system/config.h"
00034 #include "chomp/system/textfile.h"
00035 #include "chomp/system/timeused.h"
00036 #include "chomp/system/arg.h"
00037 #include "chomp/struct/hashsets.h"
00038
00039
00040 #include "chaincon/cubcell.h"
00041 #include "comphom.h"
00042
00043
00044
00045
00046
00047
00048
00049 const char *title = "\
00050 Cubical homology computation with gradient vector field.\n\
00051 Version 0.01 (Apr 4, 2011). Copyright (C) 1997-2011 by Pawel Pilarczyk.\n\
00052 This is free software. No warranty. Consult 'license.txt' for details.";
00053
00054
00055 const char *helpinfo = "\
00056 This program computes cubical homology groups and homology generators.\n\
00057 The ring of coefficients is set to Z_2, the integers modulo 2.\n\
00058 Call with:\n\
00059 filename - the name of a file that contains a list of cubical cells,\n\
00060 Switches and additional arguments:\n\
00061 -dpi, -dincl, -dphi - display the computed maps: pi, incl, phi,\n\
00062 -aN - homology algorithm: 0 = old (very slow), 1 = new without additional\n\
00063 optimization (relatively fast), 2 = new (default), 3 = using the SNF.\n\
00064 --verify - do additional verification of the computed maps,\n\
00065 --log filename - save the output to a file (without progress indicators),\n\
00066 --quiet - suppress data output to the screen (whcih can be still logged),\n\
00067 --help - display this brief help information only and exit.\n\
00068 For more information please consult the accompanying documentation\n\
00069 or ask the program's author at http://www.PawelPilarczyk.com/.";
00070
00071
00072
00073
00074
00075
00076
00077
00078 int main (int argc, char *argv [])
00079 {
00080 using namespace chomp::homology;
00081
00082
00083 program_time = "Aborted after";
00084
00085
00086 char *filename = 0;
00087 bool displayPi = false;
00088 bool displayIncl = false;
00089 bool displayPhi = false;
00090 bool verify = false;
00091 int algorithmVersion = 2;
00092
00093
00094 arguments a;
00095 arg (a, NULL, filename);
00096 arg (a, "a", algorithmVersion);
00097 argswitch (a, "dpi", displayPi, true);
00098 argswitch (a, "dincl", displayIncl, true);
00099 argswitch (a, "dphi", displayPhi, true);
00100 argswitch (a, "-verify", verify, true);
00101 arghelp (a);
00102
00103 argstreamprepare (a);
00104 int argresult = a. analyze (argc, argv);
00105 argstreamset ();
00106
00107
00108 if (argresult >= 0)
00109 sout << title << '\n';
00110
00111
00112 if (argresult < 0)
00113 {
00114 sout << "Call with '--help' for help.\n";
00115 return 2;
00116 }
00117
00118
00119 if ((argresult > 0) || !filename)
00120 {
00121 sout << helpinfo << '\n';
00122 return 1;
00123 }
00124
00125
00126 try
00127 {
00128
00129 typedef tCubCell<int_t> CellT;
00130 chomp::homology::hashedset<CellT> H;
00131 tCombLinMap<CellT, CellT> pi, incl, phi;
00132
00133
00134 computeHomology<CellT> (filename, H, pi, incl, phi,
00135 displayPi, displayIncl, displayPhi,
00136 verify, algorithmVersion);
00137
00138 program_time = "Total time used:";
00139 program_time = 1;
00140 return 0;
00141 }
00142 catch (const char *msg)
00143 {
00144 sout << "ERROR: " << msg << '\n';
00145 return -1;
00146 }
00147 catch (const std::exception &e)
00148 {
00149 sout << "ERROR: " << e. what () << '\n';
00150 return -1;
00151 }
00152 catch (...)
00153 {
00154 sout << "ABORT: An unknown error occurred.\n";
00155 return -1;
00156 }
00157 }
00158