Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
moab::point_locator::io Namespace Reference

Classes

class  File_options
 

Functions

bool check_for_flag (const char *str)
 
ErrorCode get_file_options (int argc, char **argv, std::vector< std::string > &meshFiles, std::string &interpTag, std::string &gNormTag, std::string &ssNormTag, std::vector< const char * > &ssTagNames, std::vector< const char * > &ssTagValues, std::string &readOpts, std::string &outFile, std::string &writeOpts, std::string &dbgFile, bool &help)
 
template<typename Options >
ErrorCode get_file_options (int argc, char **argv, Options &o)
 

Function Documentation

◆ check_for_flag()

bool moab::point_locator::io::check_for_flag ( const char *  str)

Definition at line 41 of file io.hpp.

42  {
43  if( str[0] == '-' )
44  return true;
45  else
46  return false;
47  }

Referenced by get_file_options().

◆ get_file_options() [1/2]

template<typename Options >
ErrorCode moab::point_locator::io::get_file_options ( int  argc,
char **  argv,
Options &  o 
)

Definition at line 280 of file io.hpp.

281  {
282  return get_file_options( argc, argv, o.meshFiles, o.interpTag, o.gNormTag, o.ssNormTag, o.ssTagNames,
283  o.ssTagValues, o.readOpts, o.outFile, o.writeOpts, o.dbgFile, o.help );
284  }

References get_file_options().

◆ get_file_options() [2/2]

ErrorCode moab::point_locator::io::get_file_options ( int  argc,
char **  argv,
std::vector< std::string > &  meshFiles,
std::string &  interpTag,
std::string &  gNormTag,
std::string &  ssNormTag,
std::vector< const char * > &  ssTagNames,
std::vector< const char * > &  ssTagValues,
std::string &  readOpts,
std::string &  outFile,
std::string &  writeOpts,
std::string &  dbgFile,
bool &  help 
)

Definition at line 50 of file io.hpp.

63  {
64  // Initialize some of the outputs to null values indicating not present
65  // in the argument list.
66  gNormTag = "";
67  ssNormTag = "";
68  readOpts = "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARTITION_DISTRIBUTE;"
69  "PARALLEL_RESOLVE_SHARED_ENTS;PARALLEL_GHOSTS=3.0.1;CPUTIME";
70  outFile = "";
71  writeOpts = "PARALLEL=WRITE_PART;CPUTIME";
72  dbgFile = "";
73  std::string defaultDbgFile = argv[0]; // The executable name will be the default debug output file.
74 
75  // These will indicate if we've gotten our required parameters at the end of parsing.
76  bool haveMeshes = false;
77  bool haveInterpTag = false;
78 
79  // Loop over the values in argv pulling out an parsing each one
80  int npos = 1;
81 
82  if( argc > 1 && argv[1] == std::string( "-h" ) )
83  {
84  help = true;
85  return MB_SUCCESS;
86  }
87 
88  while( npos < argc )
89  {
90  if( argv[npos] == std::string( "-meshes" ) )
91  {
92  // Parse out the mesh filenames
93  npos++;
94  int numFiles = 2;
95  meshFiles.resize( numFiles );
96  for( int i = 0; i < numFiles; i++ )
97  {
98  if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
99  meshFiles[i] = argv[npos++];
100  else
101  {
102  std::cerr << " ERROR - missing correct number of mesh filenames" << std::endl;
103  return MB_FAILURE;
104  }
105  }
106 
107  haveMeshes = true;
108  }
109  else if( argv[npos] == std::string( "-itag" ) )
110  {
111  // Parse out the interpolation tag
112  npos++;
113  if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
114  interpTag = argv[npos++];
115  else
116  {
117  std::cerr << " ERROR - missing <interp_tag>" << std::endl;
118  return MB_FAILURE;
119  }
120 
121  haveInterpTag = true;
122  }
123  else if( argv[npos] == std::string( "-gnorm" ) )
124  {
125  // Parse out the global normalization tag
126  npos++;
127  if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
128  gNormTag = argv[npos++];
129  else
130  {
131  std::cerr << " ERROR - missing <gnorm_tag>" << std::endl;
132  return MB_FAILURE;
133  }
134  }
135  else if( argv[npos] == std::string( "-ssnorm" ) )
136  {
137  // Parse out the subset normalization tag and selection criteria
138  npos++;
139  if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
140  ssNormTag = argv[npos++];
141  else
142  {
143  std::cerr << " ERROR - missing <ssnorm_tag>" << std::endl;
144  return MB_FAILURE;
145  }
146 
147  if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
148  {
149  char* opts = argv[npos++];
150  char sep1[1] = { ';' };
151  char sep2[1] = { '=' };
152  bool end_vals_seen = false;
153  std::vector< char* > tmpTagOpts;
154 
155  // first get the options
156  for( char* i = strtok( opts, sep1 ); i; i = strtok( 0, sep1 ) )
157  {
158  tmpTagOpts.push_back( i );
159  }
160 
161  // parse out the name and val or just name.
162  for( unsigned int j = 0; j < tmpTagOpts.size(); j++ )
163  {
164  char* e = strtok( tmpTagOpts[j], sep2 );
165  ssTagNames.push_back( e );
166  e = strtok( 0, sep2 );
167  if( e != NULL )
168  {
169  // We have a value
170  if( end_vals_seen )
171  {
172  // ERROR we should not have a value after none are seen
173  std::cerr << " ERROR - new value seen after end of values "
174  "in <ssnorm_selection>"
175  << std::endl;
176  return MB_FAILURE;
177  }
178  // Otherwise get the value string from e and convert it to an int
179  int* valp = new int;
180  *valp = atoi( e );
181  ssTagValues.push_back( (const char*)valp );
182  }
183  else
184  {
185  // Otherwise there is no '=' so push a null on the list
186  end_vals_seen = true;
187  ssTagValues.push_back( (const char*)0 );
188  }
189  }
190  }
191  else
192  {
193  std::cerr << " ERROR - missing <ssnorm_selection>" << std::endl;
194  return MB_FAILURE;
195  }
196  }
197  else if( argv[npos] == std::string( "-ropts" ) )
198  {
199  // Parse out the mesh file read options
200  npos++;
201  if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
202  readOpts = argv[npos++];
203  else
204  {
205  std::cerr << " ERROR - missing <roptions>" << std::endl;
206  return MB_FAILURE;
207  }
208  }
209  else if( argv[npos] == std::string( "-outfile" ) )
210  {
211  // Parse out the output file name
212  npos++;
213  if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
214  outFile = argv[npos++];
215  else
216  {
217  std::cerr << " ERROR - missing <out_file>" << std::endl;
218  return MB_FAILURE;
219  }
220  }
221  else if( argv[npos] == std::string( "-wopts" ) )
222  {
223  // Parse out the output file write options
224  npos++;
225  if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
226  writeOpts = argv[npos++];
227  else
228  {
229  std::cerr << " ERROR - missing <woptions>" << std::endl;
230  return MB_FAILURE;
231  }
232  }
233  else if( argv[npos] == std::string( "-dbgout" ) )
234  {
235  // Parse out the debug output file name.
236  // If no name then use the default.
237  npos++;
238  if( ( npos < argc ) && ( !check_for_flag( argv[npos] ) ) )
239  dbgFile = argv[npos++];
240  else
241  dbgFile = defaultDbgFile;
242  }
243  else
244  {
245  // Unrecognized parameter. Skip it and move along.
246  std::cerr << " ERROR - Unrecognized parameter:" << argv[npos] << std::endl;
247  std::cerr << " Skipping..." << std::endl;
248  npos++;
249  }
250  }
251 
252  if( !haveMeshes )
253  {
254  meshFiles.resize( 2 );
255  meshFiles[0] = std::string( TestDir + "/64bricks_1khex.h5m" );
256  meshFiles[1] = std::string( TestDir + "/64bricks_12ktet.h5m" );
257  std::cout << "Mesh files not entered; using default files " << meshFiles[0] << " and " << meshFiles[1]
258  << std::endl;
259  }
260 
261  if( !haveInterpTag )
262  {
263  interpTag = "vertex_field";
264  std::cout << "Interpolation field name not given, using default of " << interpTag << std::endl;
265  }
266 
267 #ifdef MOAB_HAVE_HDF5
268  if( 1 == argc )
269  {
270  std::cout << "No arguments given; using output file dum.h5m." << std::endl;
271  outFile = "dum.h5m";
272  }
273 #endif
274 
275  return MB_SUCCESS;
276  }

References check_for_flag(), help(), and MB_SUCCESS.

Referenced by get_file_options().