• Main Page
  • Classes
  • Files
  • File List
  • File Members

homcub.cpp

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 ///
00003 /// \file
00004 ///
00005 /// A program for the cubical homology computation.
00006 ///
00007 /////////////////////////////////////////////////////////////////////////////
00008 
00009 // Copyright (C) 2009-2011 by Pawel Pilarczyk.
00010 //
00011 // This file is part of my research software package. This is free software:
00012 // you can redistribute it and/or modify it under the terms of the GNU
00013 // General Public License as published by the Free Software Foundation,
00014 // either version 3 of the License, or (at your option) any later version.
00015 //
00016 // This software is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU General Public License
00022 // along with this software; see the file "license.txt". If not,
00023 // please, see <http://www.gnu.org/licenses/>.
00024 
00025 // Started on March 24, 2009. Last revision: April 4, 2011.
00026 
00027 
00028 // include some standard C++ header files
00029 #include <istream>
00030 #include <ostream>
00031 
00032 // include selected header files from the CHomP library
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 // include relevant local header files
00040 #include "chaincon/cubcell.h"
00041 #include "comphom.h"
00042 
00043 
00044 // --------------------------------------------------
00045 // -------------------- OVERTURE --------------------
00046 // --------------------------------------------------
00047 
00048 /// The title of the program and licensing information.
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 /// Brief help information on the program's usage.
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 // ---------------------- main ----------------------
00074 // --------------------------------------------------
00075 
00076 /// The main procedure of the program.
00077 /// Returns: 0 = Ok, -1 = Error, 1 = Help displayed, 2 = Wrong arguments.
00078 int main (int argc, char *argv [])
00079 {
00080         using namespace chomp::homology;
00081 
00082         // turn on a message that will appear if the program does not finish
00083         program_time = "Aborted after";
00084 
00085         // prepare user-configurable data
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         // analyze the command line
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         // show the program's title
00108         if (argresult >= 0)
00109                 sout << title << '\n';
00110 
00111         // if something was incorrect, show an additional message and exit
00112         if (argresult < 0)
00113         {
00114                 sout << "Call with '--help' for help.\n";
00115                 return 2;
00116         }
00117 
00118         // if help requested or no filename present, show help information
00119         if ((argresult > 0) || !filename)
00120         {
00121                 sout << helpinfo << '\n';
00122                 return 1;
00123         }
00124 
00125         // try running the main function and catch an error message if thrown
00126         try
00127         {
00128                 // prepare the data for storing the result of computation
00129                 typedef tCubCell<int_t> CellT;
00130                 chomp::homology::hashedset<CellT> H;
00131                 tCombLinMap<CellT, CellT> pi, incl, phi;
00132 
00133                 // compute the homology groups and generators
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 } /* main */
00158 

Generated on Tue Apr 5 2011 00:06:32 for Chain Contraction Software by  doxygen 1.7.2