MOAB: Mesh Oriented datABase  (version 5.1.1)
get_file_options.hpp
Go to the documentation of this file.
00001 #ifndef GET_FILE_OPTIONS_H
00002 #define GET_FILE_OPTIONS_H
00003 
00004 #include "moab/Core.hpp"
00005 
00006 namespace moab
00007 {
00008 
00009 // Check first character for a '-'.
00010 // Return true if one is found.  False otherwise.
00011 bool check_for_flag( const char* str )
00012 {
00013     if( str[0] == '-' )
00014         return true;
00015     else
00016         return false;
00017 }
00018 
00019 // New get_file_options() function with added possibilities for mbcoupler_test.
00020 ErrorCode get_file_options( int argc, char** argv, std::vector< std::string >& meshFiles, std::string& interpTag,
00021                             std::string& gNormTag, std::string& ssNormTag, std::vector< const char* >& ssTagNames,
00022                             std::vector< const char* >& ssTagValues, std::string& readOpts, std::string& outFile,
00023                             std::string& writeOpts, std::string& dbgFile, bool& help )
00024 {
00025     // Initialize some of the outputs to null values indicating not present
00026     // in the argument list.
00027     gNormTag  = "";
00028     ssNormTag = "";
00029     readOpts  = "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARTITION_DISTRIBUTE;PARALLEL_"
00030                "RESOLVE_SHARED_ENTS;PARALLEL_GHOSTS=3.0.1;CPUTIME";
00031     outFile                    = "";
00032     writeOpts                  = "PARALLEL=WRITE_PART;CPUTIME";
00033     dbgFile                    = "";
00034     std::string defaultDbgFile = argv[0];  // The executable name will be the default debug output file.
00035 
00036     // These will indicate if we've gotten our required parameters at the end of parsing.
00037     bool haveMeshes    = false;
00038     bool haveInterpTag = false;
00039 
00040     // Loop over the values in argv pulling out an parsing each one
00041     int npos = 1;
00042 
00043     if( argc > 1 && argv[1] == std::string( "-h" ) )
00044     {
00045         help = true;
00046         return MB_SUCCESS;
00047     }
00048 
00049     while( npos < argc )
00050     {
00051         if( argv[npos] == std::string( "-meshes" ) )
00052         {
00053             // Parse out the mesh filenames
00054             npos++;
00055             int numFiles = 2;
00056             meshFiles.resize( numFiles );
00057             for( int i = 0; i < numFiles; i++ )
00058             {
00059                 if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
00060                     meshFiles[i] = argv[npos++];
00061                 else
00062                 {
00063                     std::cerr << "    ERROR - missing correct number of mesh filenames" << std::endl;
00064                     return MB_FAILURE;
00065                 }
00066             }
00067 
00068             haveMeshes = true;
00069         }
00070         else if( argv[npos] == std::string( "-itag" ) )
00071         {
00072             // Parse out the interpolation tag
00073             npos++;
00074             if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
00075                 interpTag = argv[npos++];
00076             else
00077             {
00078                 std::cerr << "    ERROR - missing <interp_tag>" << std::endl;
00079                 return MB_FAILURE;
00080             }
00081 
00082             haveInterpTag = true;
00083         }
00084         else if( argv[npos] == std::string( "-gnorm" ) )
00085         {
00086             // Parse out the global normalization tag
00087             npos++;
00088             if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
00089                 gNormTag = argv[npos++];
00090             else
00091             {
00092                 std::cerr << "    ERROR - missing <gnorm_tag>" << std::endl;
00093                 return MB_FAILURE;
00094             }
00095         }
00096         else if( argv[npos] == std::string( "-ssnorm" ) )
00097         {
00098             // Parse out the subset normalization tag and selection criteria
00099             npos++;
00100             if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
00101                 ssNormTag = argv[npos++];
00102             else
00103             {
00104                 std::cerr << "    ERROR - missing <ssnorm_tag>" << std::endl;
00105                 return MB_FAILURE;
00106             }
00107 
00108             if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
00109             {
00110                 char* opts         = argv[npos++];
00111                 char sep1[1]       = { ';' };
00112                 char sep2[1]       = { '=' };
00113                 bool end_vals_seen = false;
00114                 std::vector< char* > tmpTagOpts;
00115 
00116                 // first get the options
00117                 for( char* i = strtok( opts, sep1 ); i; i = strtok( 0, sep1 ) )
00118                 {
00119                     tmpTagOpts.push_back( i );
00120                 }
00121 
00122                 // parse out the name and val or just name.
00123                 for( unsigned int j = 0; j < tmpTagOpts.size(); j++ )
00124                 {
00125                     char* e = strtok( tmpTagOpts[j], sep2 );
00126                     ssTagNames.push_back( e );
00127                     e = strtok( 0, sep2 );
00128                     if( e != NULL )
00129                     {
00130                         // We have a value
00131                         if( end_vals_seen )
00132                         {
00133                             // ERROR we should not have a value after none are seen
00134                             std::cerr << "    ERROR - new value seen after end of values in "
00135                                          "<ssnorm_selection>"
00136                                       << std::endl;
00137                             return MB_FAILURE;
00138                         }
00139                         // Otherwise get the value string from e and convert it to an int
00140                         int* valp = new int;
00141                         *valp     = atoi( e );
00142                         ssTagValues.push_back( (const char*)valp );
00143                     }
00144                     else
00145                     {
00146                         // Otherwise there is no '=' so push a null on the list
00147                         end_vals_seen = true;
00148                         ssTagValues.push_back( (const char*)0 );
00149                     }
00150                 }
00151             }
00152             else
00153             {
00154                 std::cerr << "    ERROR - missing <ssnorm_selection>" << std::endl;
00155                 return MB_FAILURE;
00156             }
00157         }
00158         else if( argv[npos] == std::string( "-ropts" ) )
00159         {
00160             // Parse out the mesh file read options
00161             npos++;
00162             if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
00163                 readOpts = argv[npos++];
00164             else
00165             {
00166                 std::cerr << "    ERROR - missing <roptions>" << std::endl;
00167                 return MB_FAILURE;
00168             }
00169         }
00170         else if( argv[npos] == std::string( "-outfile" ) )
00171         {
00172             // Parse out the output file name
00173             npos++;
00174             if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
00175                 outFile = argv[npos++];
00176             else
00177             {
00178                 std::cerr << "    ERROR - missing <out_file>" << std::endl;
00179                 return MB_FAILURE;
00180             }
00181         }
00182         else if( argv[npos] == std::string( "-wopts" ) )
00183         {
00184             // Parse out the output file write options
00185             npos++;
00186             if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
00187                 writeOpts = argv[npos++];
00188             else
00189             {
00190                 std::cerr << "    ERROR - missing <woptions>" << std::endl;
00191                 return MB_FAILURE;
00192             }
00193         }
00194         else if( argv[npos] == std::string( "-dbgout" ) )
00195         {
00196             // Parse out the debug output file name.
00197             // If no name then use the default.
00198             npos++;
00199             if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
00200                 dbgFile = argv[npos++];
00201             else
00202                 dbgFile = defaultDbgFile;
00203         }
00204         else
00205         {
00206             // Unrecognized parameter.  Skip it and move along.
00207             std::cerr << "    ERROR - Unrecognized parameter:" << argv[npos] << std::endl;
00208             std::cerr << "            Skipping..." << std::endl;
00209             npos++;
00210         }
00211     }
00212 
00213     if( !haveMeshes )
00214     {
00215         meshFiles.resize( 2 );
00216         meshFiles[0] = std::string( TestDir + "/64bricks_1khex.h5m" );
00217         meshFiles[1] = std::string( TestDir + "/64bricks_12ktet.h5m" );
00218         std::cout << "Mesh files not entered; using default files " << meshFiles[0] << " and " << meshFiles[1]
00219                   << std::endl;
00220     }
00221 
00222     if( !haveInterpTag )
00223     {
00224         interpTag = "vertex_field";
00225         std::cout << "Interpolation field name not given, using default of " << interpTag << std::endl;
00226     }
00227 
00228 #ifdef MOAB_HAVE_HDF5
00229     if( 1 == argc )
00230     {
00231         std::cout << "No arguments given; using output file dum.h5m." << std::endl;
00232         outFile = "dum.h5m";
00233     }
00234 #endif
00235 
00236     return MB_SUCCESS;
00237 }
00238 }  // namespace moab
00239 
00240 #endif  // GET_FILE_OPTIONS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines