Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
main.cpp
Go to the documentation of this file.
1 /* rc_cmp - compares results from simulations and experiments using multiple file
2  * formats and multiple difference metrics
3  *
4  *
5  * Joseph Kaczmarek, June 2009
6  */
7 
8 #include "main.h"
9 
11 
12 int main(int argc, char *argv[]){
13 
14  //Parse command line options
15  gCmdSwitches.setArguments(argc, argv);
16  gCmdSwitches.parseOptions();
17 
18  //Open files
19  vector<datafile*> files = openAndParseFiles();
20  if(files.size() != 2)
21  return 1;
22 
23  //Perform work on the files
24  compareFiles(files);
25 
26  //Free resources
27  for(int file_num = 0; file_num < files.size(); file_num++){
28  if( files[file_num] != NULL )
29  delete files[file_num];
30  }
31 
32  return 0;
33 }
34 
35 
36 /*
37  * Open the files specified at the command line
38  * and parse them
39  */
40 vector<datafile*> openAndParseFiles(){
41 
42  vector<datafile*> file_pointers;
43 
44  //Create file objects
45  datafile *file1 = Fileselect::detectFiletype(gCmdSwitches.getInputFile(1),
46  gCmdSwitches.getLogFile(),
47  gCmdSwitches.getVerbosity(),
48  gCmdSwitches.getFileName(1),
49  gCmdSwitches.getFileDimensions(1),
50  gCmdSwitches.getFieldMappings(1),
51  gCmdSwitches.getIndexOrder(1),
52  gCmdSwitches.getConvFactor(1),
53  gCmdSwitches.getNormVal(1));
54 
55  datafile *file2 = Fileselect::detectFiletype(gCmdSwitches.getInputFile(2),
56  gCmdSwitches.getLogFile(),
57  gCmdSwitches.getVerbosity(),
58  gCmdSwitches.getFileName(2),
59  gCmdSwitches.getFileDimensions(2),
60  gCmdSwitches.getFieldMappings(2),
61  gCmdSwitches.getIndexOrder(2),
62  gCmdSwitches.getConvFactor(2),
63  gCmdSwitches.getNormVal(2));
64 
65  //Check to make sure files have been properly opened
66  if(file1 == NULL || file2 == NULL){
67 
68  if(file1 != NULL)
69  delete file1;
70 
71  if(file2 != NULL)
72  delete file2;
73 
74  file1 = NULL;
75  file2 = NULL;
76 
77  return file_pointers;
78 
79  }
80 
81  //Parse file content
82  file1->parse();
83  file2->parse();
84 
85  file_pointers.push_back(file1);
86  file_pointers.push_back(file2);
87 
88  return file_pointers;
89 }
90 
91 
92 /*
93  * Compare two files, ouput results
94  */
95 void compareFiles(vector<datafile*> pFiles){
96 
97  datafile *file1 = pFiles[0];
98  datafile *file2 = pFiles[1];
99 
100  if(gCmdSwitches.getVerbosity())
101  gCmdSwitches.getLogFile() << "\n";
102 
103 
104  //Get comparison list
105  std::vector<cmp_map> comparison_list = gCmdSwitches.getComparisonList();
106 
107  std::vector<points*> interp_pts;
108 
109  for(int i=0; i<comparison_list.size(); i++){
110 
111  cmp_map curr_comp = comparison_list[i];
112 
113  //Check if previous interp_pts satisfies current interp_pts
114  if( i > 0 ){
115  cmp_map prev_comp = comparison_list[(i-1)];
116 
117  if( !same_elements(curr_comp.file1_partitions, curr_comp.file1_partitions) ||
118  curr_comp.file2_partition != prev_comp.file2_partition ||
119  curr_comp.var1 != prev_comp.var1 ||
120  curr_comp.var2 != prev_comp.var2 ){
121 
122  points::delete_all(interp_pts);
123 
124  for(int partition_1_num = 0; partition_1_num < curr_comp.file1_partitions.size(); partition_1_num++){
125  points *temp_points;
126  temp_points = Interpolate::bilinear( file1->get_points(curr_comp.file1_partitions[partition_1_num]),
127  file2->get_points(curr_comp.file2_partition),
128  curr_comp.var1,
129  curr_comp.var2 );
130  interp_pts.push_back(temp_points);
131  }
132 
133  }
134  }
135  else{
136 
137  for(int partition_1_num = 0; partition_1_num < curr_comp.file1_partitions.size(); partition_1_num++){
138  points *temp_points;
139  temp_points = Interpolate::bilinear( file1->get_points(curr_comp.file1_partitions[partition_1_num]),
140  file2->get_points(curr_comp.file2_partition),
141  curr_comp.var1,
142  curr_comp.var2 );
143  interp_pts.push_back(temp_points);
144  }
145  }
146 
147  if(points::contains_null(interp_pts)){
148 
149  string out_msg;
150  out_msg = "ERROR | Interpolation Failed, ";
151  out_msg += "Possible Invalid Partition or Variable Argument: \"";
152  out_msg += itoa(curr_comp.metric) + "=";
153 
154  for(int partition_1_num = 0; partition_1_num < curr_comp.file1_partitions.size(); partition_1_num++){
155 
156  if(partition_1_num != 0)
157  out_msg += ",";
158 
159  out_msg += itoa(curr_comp.file1_partitions[partition_1_num]);
160  }
161 
162  out_msg += ":";
163  out_msg += itoa(curr_comp.var1) + "/" + itoa(curr_comp.file2_partition) + ":";
164  out_msg += itoa(curr_comp.var2) + "\"";
165 
166  gCmdSwitches.getLogFile() << out_msg << endl;
167  cout << out_msg << endl;
168 
169  continue;
170  }
171 
172  //Construct the outprefix string for the metric
173  //Used by the metric to prefix output files
174  string metric_outprefix = gCmdSwitches.getOutPrefix();
175  metric_outprefix += "_part1_";
176 
177  for(int partition_1_num = 0; partition_1_num < curr_comp.file1_partitions.size(); partition_1_num++){
178 
179  if(partition_1_num != 0)
180  metric_outprefix += "_";
181 
182  metric_outprefix += itoa(curr_comp.file1_partitions[partition_1_num]);
183  }
184 
185  metric_outprefix += "_part2_" + itoa(curr_comp.file2_partition);
186 
187  //Create metric object
188  metric *comp = metric_select(curr_comp.metric, retrievePoints(file1, curr_comp.file1_partitions),
189  interp_pts, curr_comp.var1, 2, //Interpolation only returns the desired point
190  gCmdSwitches.getLogFile(), metric_outprefix);
191 
192  if( gCmdSwitches.isRangeSpecified( ) )
193  {
194  BoundingBox range = gCmdSwitches.getRange( );
195  comp ->setRange( &range );
196  }
197 
198  //Check metric object
199  if(comp == NULL){
200  gCmdSwitches.getLogFile() << "ERROR | " << "Invalid Metric Number: \"";
201  gCmdSwitches.getLogFile() << curr_comp.metric << "\"" << endl;
202 
203  cout << "ERROR | " << "Invalid Metric Number: \"";
204  cout << curr_comp.metric << "\"" << endl;
205 
206  continue;
207  }
208 
209  //Calculate metric
210  string res = comp->get_res();
211 
212  //Print result
213  gCmdSwitches.getLogFile().precision(10);
214  gCmdSwitches.getLogFile().width(65);
215  string msg_out = "RESULT | (" + itoa(curr_comp.file1_partitions[0]) + ":"
216  + itoa(curr_comp.var1) + " "
217  + itoa(curr_comp.file2_partition) + ":"
218  + itoa(curr_comp.var2) + ") "
219  + comp->get_metric_name() + ": ";
220 
221  gCmdSwitches.getLogFile() << std::left << msg_out;
222  gCmdSwitches.getLogFile() << std::right << res << "\n";
223 
224  cout.precision(10);
225  cout.width(65);
226  cout << std::left << msg_out;
227  cout << std::right << res << "\n";
228 
229  delete comp;
230  }
231 
232  //Cleanup Memory
233  points::delete_all(interp_pts);
234 }
235 
236 
237 /*
238  * Construct a vector of pointers to datasets
239  */
240 std::vector<points*> retrievePoints(datafile* pFile, vector<int> rPartitions){
241 
242  std::vector<points*> datasets;
243 
244  for(int partition_record = 0; partition_record < rPartitions.size(); partition_record++){
245  if(rPartitions[partition_record] < pFile->get_num_partitions()){
246  datasets.push_back( pFile->get_points(rPartitions[partition_record]) );
247  }
248  else
249  datasets.push_back( NULL );
250  }
251 
252  return datasets;
253 }
254 
255 
256 /*
257  * Output point values to stdout
258  */
259 void printPointValues(points* pPoints){
260 
261  //Print points
262  for(int point_num = 0; point_num < pPoints->get_num_points(); point_num++){
263  pnt curr = pPoints->get_point(point_num);
264 
265  for(int dimension = 0; dimension < curr.size; dimension++)
266  cout << curr.vals[dimension] << ", ";
267  cout << endl;
268  }
269 
270  cout << endl << "Printed " << pPoints->get_num_points() << " points" << endl;
271 }
272 
273 /*
274  * Find the average of the var of the points specified
275  */
276 long double calcAverageValue(points *pPoints, int rVar){
277 
278  long double sum = 0.0;
279 
280  //Sum the points
281  for(int point_num = 0; point_num < pPoints->get_num_points(); point_num++){
282  pnt curr = pPoints->get_point(point_num);
283  sum += curr.vals[rVar];
284  }
285 
286  return (sum / (long double)pPoints->get_num_points());
287 }
288 
289 
290 /*
291  * Find the minimum point value
292  */
293 long double minPoint(points *pPoints, int rVar){
294  long double min = std::numeric_limits<long double>::infinity();
295 
296  for(int point_num = 0; point_num < pPoints->get_num_points(); point_num++){
297  pnt curr = pPoints->get_point(point_num);
298  if(curr.vals[rVar] < min)
299  min = curr.vals[rVar];
300  }
301 
302  return min;
303 }
304 
305 
306 /*
307  * Find the maximum point value
308  */
309 long double maxPoint(points *pPoints, int rVar){
310  long double max = -std::numeric_limits<long double>::infinity();
311 
312  for(int point_num = 0; point_num < pPoints->get_num_points(); point_num++){
313  pnt curr = pPoints->get_point(point_num);
314  if(curr.vals[rVar] > max)
315  max = curr.vals[rVar];
316  }
317 
318  return max;
319 }
320 
321 
322 
323 /*
324  * Print the rc_cmp usage message
325  */
326 void printUsage(string rErrorMessage){
327 
328  if(rErrorMessage.compare("") != 0)
329  cout << "\n" << rErrorMessage << endl;
330  cout << "\n" << gUsage << endl;
331 
332  cout << "Comparisons are made at the point locations of input file 1" << endl << endl;
333 
334  cout << "Valid Filetypes:\n";
336  cout << endl;
337 
338  cout << "Metrics:\n";
339  print_metrics();
340  cout << endl;
341 
342 }
343 
344 
345 
346 /* ComSwitch Implementation --------------------------------------------- */
347 
349 
350  //Set default values
351  setDefaultVars();
352 }
353 
354 ComSwitch::ComSwitch(int argc, char *argv[]){
355 
356  //Set default values
357  setDefaultVars();
358 
359  setArguments(argc, argv);
360 }
361 
362 /*
363  * Set Arguments
364  */
365 void ComSwitch::setArguments(int rArgc, char *rpArgv[]){
366  mArgc = rArgc;
367  mpArgv = rpArgv;
368 }
369 
370 /*
371  * Set default member variables
372  */
374 
375  //Help message flag
376  mHelp = false;
377 
378  //Bad command line switches
379  mBadSwitch = false;
380 
381  //File dimensions
382  mInfile1Dimensions = -1;
383  mInfile2Dimensions = -1;
384 
385  //Log verbosity
386  mLoud = false;
387 
388  // Restrict search
389  restrictToRange = false;
390 }
391 
392 /*
393  * Parse command options
394  */
396 
397  //Parse Arguments
398  readOptions();
399 
400  if( mHelp ){
401  printUsage(string(""));
402  exit(0);
403  }
404 
405  if( mBadSwitch ){
406  printUsage(string(""));
407  exit(1);
408  }
409 
410  if( !initializeFileStreams() )
411  exit(1);
412 
413  //Check completeness
414  if(requiredArgsSet()){
415  writeLogHeader();
416  }
417  else{
418  string err_ps("Missing Arguments");
419  printUsage(err_ps);
420 
421  exit(1);
422  }
423 
424  return true;
425 
426 }
427 
429 
430  //Close files
431  mLog.close();
432  mInfile1.close();
433  mInfile2.close();
434 }
435 
437 
438  if( mOutPrefix.compare("") == 0 )
439  return false;
440 
441  if( !mLog.is_open() )
442  return false;
443 
444  if( !mInfile1.is_open() || !mInfile2.is_open() )
445  return false;
446 
447  if( mComparisonList.size() <= 0 )
448  return false;
449 
450  if( mInfile1Dimensions <= 0 || mInfile2Dimensions <= 0 )
451  return false;
452 
453  if( mBadSwitch )
454  return false;
455 
456  return true;
457 }
458 
459 /*
460  * Get file dimensions
461  */
463  if(file == 1)
464  return mInfile1Dimensions;
465  else if(file == 2)
466  return mInfile2Dimensions;
467  else
468  return -1;
469 }
470 
471 /*
472  * Get conversion factors for file
473  */
474 std::vector<adj_map> ComSwitch::getConvFactor(int file){
475  if(file == 1){
476  return mFile1ConversionFactor;
477  }
478  else if(file == 2){
479  return mFile2ConversionFactor;
480  }
481 
482  std::vector<adj_map> ret;
483  return ret;
484 }
485 
486 /*
487  * Get normalization values
488  */
489 std::vector<adj_map> ComSwitch::getNormVal(int file){
490  if(file == 1){
491  return mFile1Norm;
492  }
493  else if(file == 2){
494  return mFile2Norm;
495  }
496 
497  std::vector<adj_map> ret;
498  return ret;
499 }
500 
501 /*
502  * Get logging verbosity
503  */
505  return mLoud;
506 }
507 
508 /*
509  * Get input file
510  */
511 ifstream & ComSwitch::getInputFile(int rFile){
512 
513  if(rFile == 1)
514  return mInfile1;
515  else
516  return mInfile2;
517 
518 }
519 
520 /*
521  * Get file name
522  */
523 string ComSwitch::getFileName(int rFile){
524  string ret("");
525  if(rFile == 1)
526  ret = mInfileName1;
527  else if(rFile == 2)
528  ret = mInfileName2;
529 
530  return ret;
531 }
532 
533 /*
534  * Get log file
535  */
537  return mLog;
538 }
539 
540 /*
541  * Get Outprefix
542  */
544  return mOutPrefix;
545 }
546 
547 /*
548  * Get comparison list
549  */
550 std::vector<cmp_map> ComSwitch::getComparisonList(){
551  return mComparisonList;
552 }
553 
554 /*
555  * Get field mapping
556  */
557 std::vector< std::vector<int> > ComSwitch::getFieldMappings(int rFile){
558  switch( rFile ){
559 
560  case 1 :
561  return mFieldMappingsFile1;
562  break;
563 
564  case 2 :
565  return mFieldMappingsFile2;
566  break;
567 
568  default :
569  std::vector< std::vector<int> > empty;
570  return empty;
571  }
572 }
573 
574 /*
575  * Get index order
576  */
577 std::vector<index_order> ComSwitch::getIndexOrder(int rFile){
578  switch( rFile ){
579 
580  case 1 :
581  return mIndexOrderFile1;
582  break;
583 
584  case 2 :
585  return mIndexOrderFile2;
586  break;
587 
588  default :
589  std::vector<index_order> empty;
590  return empty;
591  }
592 }
593 
594 /*
595  * Set option string and long opts struct
596  */
598 
599  //Short options
600  string opt_string("o:1:2:f:i:c:n:m:r:vh");
601 
602  //Long options
603  static const struct option long_opts[] = {
604  {"outfile", required_argument, NULL, 'o'},
605  {"infile1", required_argument, NULL, '1'},
606  {"infile2", required_argument, NULL, '2'},
607  {"fieldmap", required_argument, NULL, 'f'},
608  {"index-order", required_argument, NULL, 'i'},
609  {"conv", required_argument, NULL, 'c'},
610  {"norm", required_argument, NULL, 'n'},
611  {"range", required_argument, NULL, 'r'},
612  {"metric", required_argument, NULL, 'm'},
613  {"verbose", no_argument, NULL, 'v'},
614  {"help", no_argument, NULL, 'h'},
615  {NULL, no_argument, NULL, 0 }
616  };
617 
618  return parseValuesFromArguments(opt_string, long_opts);
619 }
620 
621 /*
622  * Read and parse options from array
623  */
624 bool ComSwitch::parseValuesFromArguments(string rOptString,
625  const struct option *rLongOpts){
626 
627 
628  //Parse options
629  int opt = 0;
630  opt = getopt_long( mArgc, mpArgv, rOptString.c_str(), rLongOpts, NULL );
631 
632  while( opt != -1 ){
633  switch( opt ){
634 
635  //Outfile
636  case 'o': {
637  mOutPrefix = optarg;
638  } break;
639 
640  //File 1
641  case '1': {
642  std::vector<string> infile_info = str_tokenize(string(optarg), string(":"));
643 
644  if(infile_info.size() != 2)
645  break;
646 
647  if( check_non_numeric_str( infile_info[1] ) )
648  break;
649 
650  mInfileName1 = infile_info[0];
651  mInfile1Dimensions = atoi(infile_info[1].c_str());
652  } break;
653 
654  //File 2
655  case '2': {
656  std::vector<string> infile_info = str_tokenize(string(optarg), string(":"));
657 
658  if(infile_info.size() != 2)
659  break;
660 
661  if( check_non_numeric_str( infile_info[1] ) )
662  break;
663 
664  mInfileName2 = infile_info[0];
665  mInfile2Dimensions = atoi(infile_info[1].c_str());
666  } break;
667 
668  //Field mapping
669  case 'f': {
670  std::vector<string> field_map = str_tokenize(string(optarg), string(":/"));
671 
672  if(field_map.size() != 3)
673  break;
674 
675  //Make sure we only have numerals or "null"
676  if( check_non_numeric_str( field_map[0] ) ||
677  check_non_numeric_str( field_map[1] ) ){
678 
679  if(check_non_numeric_str( field_map[2] ) &&
680  field_map[2].compare("null") != 0 ){
681  break;
682  }
683  }
684 
685  //Pack entry
686  vector<int> entry;
687  entry.push_back( atoi(field_map[1].c_str()) );
688 
689  if(field_map[2].compare("null") != 0)
690  entry.push_back( atoi(field_map[2].c_str()) );
691  else
692  entry.push_back( -1 );
693 
694  //Add entry to list of mappings
695  switch( atoi(field_map[0].c_str()) ){
696 
697  case 1:
698  mFieldMappingsFile1.push_back(entry);
699  break;
700 
701  case 2:
702  mFieldMappingsFile2.push_back(entry);
703  break;
704 
705  default:
706  break;
707 
708  }
709 
710  } break;
711 
712  //Index order
713  case 'i': {
714  std::vector<string> order = str_tokenize(string(optarg), string(":,"));
715  std::vector<int> order_int;
716 
717  if(order.size() <= 0)
718  break;
719 
720  //Get the file number
721  int file_num = 0;
722  if(!check_non_numeric_str(order[0])){
723  file_num = atoi(order[0].c_str());
724 
725  if(file_num != 1 && file_num != 2){
726  break;
727  }
728  }
729 
730  //Get the partition number
731  int partition_num = -1;
732  if(!check_non_numeric_str(order[1])){
733  partition_num = atoi(order[1].c_str());
734  if(partition_num < 0)
735  break;
736  }
737 
738  bool non_numeric = false;
739 
740  //Loop through remaining values
741  for(int token_num = 2; token_num < order.size(); token_num++){
742 
743  if(!check_non_numeric_str(order[token_num])){
744 
745  //Convert to int
746  int value = atoi(order[token_num].c_str());
747 
748  //Check for repeats
749  bool repeat = false;
750  for(int prev_num = 0; prev_num < order_int.size(); prev_num++){
751  if(value == order_int[prev_num]){
752  repeat = true;
753  break;
754  }
755  }
756 
757  //Add value to the list
758  if(!repeat)
759  order_int.push_back(value);
760  }
761  else{
762  non_numeric = true;
763  break;
764  }
765  }
766 
767  //Discard all values if any are non-numeric
768  if(non_numeric)
769  break;
770 
771  index_order curr_index;
772  curr_index.order = order_int;
773  curr_index.partition_number = partition_num;
774 
775  if(file_num == 1)
776  mIndexOrderFile1.push_back(curr_index);
777  else if(file_num == 2)
778  mIndexOrderFile2.push_back(curr_index);
779 
780  } break;
781 
782  //Conversion factor
783  case 'c': {
784  std::vector<string> conv_info = str_tokenize(string(optarg), string(":"));
785 
786  if(conv_info.size() != 3)
787  break;
788 
789  adj_map add;
790  add.variable = atoi(conv_info[1].c_str());
791  add.factor = strtold(conv_info[2].c_str(), NULL);
792 
793  int file = atoi(conv_info[0].c_str());
794 
795  if(file == 1)
796  mFile1ConversionFactor.push_back(add);
797  else if(file == 2)
798  mFile2ConversionFactor.push_back(add);
799 
800  } break;
801 
802  // Range used for cropping
803  case 'r': {
804 
805  // Set the flag to indicate that matrics are going to be restricted to the user-supplied range.
806  restrictToRange = true;
807 
808  std::vector< std::string > conv_info = str_tokenize( std::string( optarg ), std::string( "," ) );
809 
810  //
811  // The expected parameters are of the form "xmin,ymin,zmin,xmax,ymax,zmax"
812  //
813  if( conv_info.size( ) != 6 )
814  break;
815 
816  double xmin = std::atof( conv_info[ 0 ].c_str( ) );
817  double ymin = std::atof( conv_info[ 1 ].c_str( ) );
818  double zmin = std::atof( conv_info[ 2 ].c_str( ) );
819  double xmax = std::atof( conv_info[ 3 ].c_str( ) );
820  double ymax = std::atof( conv_info[ 4 ].c_str( ) );
821  double zmax = std::atof( conv_info[ 5 ].c_str( ) );
822 
823  mRange.setCoordinates( xmin, ymin, zmin, xmax, ymax, zmax );
824 
825  }
826 
827  //Normalization factor
828  case 'n': {
829  std::vector<string> norm_info = str_tokenize(string(optarg), string(":"));
830 
831  if(norm_info.size() != 3)
832  break;
833 
834  adj_map add;
835  add.variable = atoi(norm_info[1].c_str());
836  add.factor = strtold(norm_info[2].c_str(), NULL);
837 
838  int file = atoi(norm_info[0].c_str());
839 
840  if(file == 1)
841  mFile1Norm.push_back(add);
842  else if(file == 2)
843  mFile2Norm.push_back(add);
844  } break;
845 
846  //Comparison
847  case 'm': {
848  std::vector<string> comp = str_tokenize(string(optarg), string("=:/"));
849 
850  if(comp.size() != 5)
851  break;
852 
853  if( check_non_numeric_str( comp[0] ) ||
854  check_non_numeric_str( comp[2] ) ||
855  check_non_numeric_str( comp[3] ) ||
856  check_non_numeric_str( comp[4] ) ){
857 
858  break;
859  }
860 
861  bool bad_entry = false;
862 
863  //Get file 1's partition list
864  std::vector<string> partitions_1 = str_tokenize(string(comp[1]), string(","));
865  std::vector<int> partitions_1_int;
866 
867  for(int token_num = 0; token_num < partitions_1.size(); token_num++){
868 
869  if(check_non_numeric_str( partitions_1[token_num] )){
870  bad_entry = true;
871  break;
872  }
873 
874  partitions_1_int.push_back( atoi(partitions_1[token_num].c_str()) );
875  }
876 
877  if(bad_entry)
878  break;
879 
880  cmp_map add_cmp;
881  add_cmp.metric = atoi(comp[0].c_str());
882  add_cmp.file1_partitions = partitions_1_int;
883  add_cmp.var1 = atoi(comp[2].c_str());
884  add_cmp.file2_partition = atoi(comp[3].c_str());
885  add_cmp.var2 = atoi(comp[4].c_str());
886 
887  mComparisonList.push_back(add_cmp);
888 
889  } break;
890 
891  //Logging Level
892  case 'v': {
893  mLoud = true;
894  } break;
895 
896  //Help message
897  case 'h': {
898  mHelp = true;
899  return false;
900  } break;
901 
902  case 0: {
903  mBadSwitch = true;
904  return false;
905  } break;
906 
907  case '?': {
908  mBadSwitch = true;
909  return false;
910  } break;
911  }
912 
913  opt = getopt_long( mArgc, mpArgv, rOptString.c_str(), rLongOpts, NULL );
914  }
915 
916  return true;
917 }
918 
919 /*
920  * Initialize files stream
921  */
923 
924  //Intialize Log File
925  if(mOutPrefix.compare("") != 0){
926  mLog.open((mOutPrefix + ".log").c_str(), ofstream::out);
927 
928  if(!mLog.is_open()){
929  string err_ps("Invalid Output File Prefix Specified: Directory may not exist");
930  printUsage(err_ps);
931 
932  return false;
933  }
934  }
935 
936  //Initialize Input File 1
937  if(mInfileName1.compare("") != 0){
938  mInfile1.open(mInfileName1.c_str(), ifstream::in);
939 
940  if(!mInfile1.is_open()){
941  string err_ps("Could Not Open Input File 1: ");
942  err_ps += mInfileName1;
943  printUsage(err_ps);
944 
945  return false;
946  }
947  }
948 
949  //Initialize Input File 2
950  if(mInfileName2.compare("") != 0){
951  mInfile2.open(mInfileName2.c_str(), ifstream::in);
952 
953  if(!mInfile2.is_open()){
954  string err_ps("Could Not Open Input File 2: ");
955  err_ps += mInfileName2;
956  printUsage(err_ps);
957 
958  return false;
959  }
960  }
961 
962  return true;
963 
964 }
965 
966 /*
967  * Write the log file header
968  */
970 
971  //Write the program name to the log file
972  if(mArgc > 0)
973  mLog << mpArgv[0] << endl;
974 
975  mLog << endl;
976 
977  //Write the supplied arguments to the log file
978  mLog << "ARGUMENTS: " << endl;
979 
980  for(int arg_num=0; arg_num < mArgc; arg_num++){
981  mLog << mpArgv[arg_num] << " ";
982  }
983 
984  mLog << endl << endl;
985 
986  //Write input files to log file
987  mLog << "INPUT FILES: " << endl;
988  mLog << mInfileName1;
989  mLog << ", " << mInfileName2 << endl << endl;
990 
991  //Write header for run output
992  mLog << "RUN OUTPUT:" << endl << flush;
993 
994  return false;
995 }
996 
BoundingBox getRange()
Returns a bounding box corresponding to the range of the region of interest.
Definition: main.h:144
static datafile * detectFiletype(ifstream &infile, ofstream &outfile, bool loud, string infile_name, int dim, std::vector< std::vector< int > > rFieldMappings, std::vector< index_order > rIndexOrder, std::vector< adj_map > conv_factor, std::vector< adj_map > norm_val)
Use test functions to determine the filetype and to create a new file object for the input file...
Definition: fileselect.cpp:3
string mInfileName1
Definition: main.h:231
int variable
Definition: datatypedef.h:32
void compareFiles(vector< datafile * > pFiles)
Compare the two files, interpolating the points from the second onto the first mesh.
Definition: main.cpp:95
virtual string get_res()
Definition: metric.cpp:30
A concrete object that provides the functionality for representing a bounding box geometric primitive...
Definition: BoundingBox.hpp:21
bool getVerbosity()
Get logging verbosity.
Definition: main.cpp:504
int mInfile2Dimensions
Infile 1 independent variable dimensions.
Definition: main.h:217
std::vector< int > file1_partitions
Definition: datatypedef.h:45
bool restrictToRange
Infile 2 independent variable dimensions.
Definition: main.h:219
std::vector< adj_map > mFile1Norm
Definition: main.h:225
int metric
Definition: datatypedef.h:43
int size
Definition: datatypedef.h:70
ifstream mInfile1
Definition: main.h:234
void setArguments(int rArgc, char *rpArgv[])
Set command line arguments.
Definition: main.cpp:365
void setRange(BoundingBox *rangePtr)
Definition: metric.h:46
const char * option(const char *const name, const int argc, const char *const *const argv, const char *defaut, const char *const usage=0)
Definition: CImg.h:5604
std::vector< adj_map > getNormVal(int rFile)
Get normalization values.
Definition: main.cpp:489
long double maxPoint(points *pPoints, int rVar)
Find the maximum value.
Definition: main.cpp:309
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
Base class for file parsing.
Definition: file.h:32
virtual void parse()
Parse the data file.
Definition: file.cpp:57
~ComSwitch()
Free memory, and close open file handles.
Definition: main.cpp:428
boolean empty(T_VertexSet s)
string gUsage("Usage: [--outfile | -o] <output file prefix>\n\t""[--infile1 | -1] <intput file 1 name>:<dimensions>\n\t""[--infile2 | -2] <intput file 2 name>:<dimensions>\n\t""[--fieldmap | -f] <File (1,2)>:<File Dimension>/<Mapped Dimension or \"null\">\n\t""[--index-order | -i] <File (1,2)>:<Partition>:<Dimension 1>,<Dimension 2>,...\n\t""[--conv | -c] <File (1,2)>:<Variable>:<Conversion Factor> \n\t""[--norm | -n] <File (1,2)>:<Variable>:<Normalization Factor> \n\t""[--range | -r] <xmin>,<ymin>,<zmin>,<xmax>,<ymax>,<zmax> \n\t""[--metric | -m] <metric number>=<file 1 partition 1>,<file 1 partition 2>,...:<file 1 variable>/\n\t"" <file 2 partition>:<file 2 variable>\n\t""[--verbose | -v]\n")
Definition: points.h:30
std::vector< cmp_map > mComparisonList
Definition: main.h:237
Used to store index order information.
Definition: datatypedef.h:22
int partition_number
Definition: datatypedef.h:24
long double minPoint(points *pPoints, int rVar)
Find the minimum value.
Definition: main.cpp:293
Used by cmd parser to store comparison information.
Definition: datatypedef.h:41
bool mLoud
Definition: main.h:245
ifstream & getInputFile(int rFile)
Get Input File.
Definition: main.cpp:511
long double * vals
Definition: datatypedef.h:69
std::vector< cmp_map > getComparisonList()
Get Comparison List.
Definition: main.cpp:550
void printUsage(const char *why)
Definition: makeflo.cpp:68
bool isRangeSpecified()
Returns a flag that indicates whether a range was supplied to this instance of CommSwitch.
Definition: main.h:133
void print_metrics()
Sample Correlation Coefficient.
Definition: metric.cpp:1161
std::vector< index_order > mIndexOrderFile2
Definition: main.h:243
std::vector< int > order
Definition: datatypedef.h:23
void setDefaultVars()
Set default member variables.
Definition: main.cpp:373
int var2
Definition: datatypedef.h:49
BoundingBox mRange
Flag used to indicate if the metrics will be restricted to a given range.
Definition: main.h:220
float atof(const char *const str)
Read a float number from a C-string.
Definition: CImg.h:4905
void setCoordinates(const double x, const double y, const double z, const double X, const double Y, const double Z)
Sets the coordinates of this BoundingBox instance.
bool writeLogHeader()
Write the log file header Program Name - switches Input files.
Definition: main.cpp:969
bool requiredArgsSet()
Check if required arguments are set.
Definition: main.cpp:436
ofstream & getLogFile()
Get Log File.
Definition: main.cpp:536
pnt get_point(int n)
Definition: points.cpp:183
Point object that represents a single point.
Definition: datatypedef.h:68
bool mHelp
Help flag is set from command line options.
Definition: main.h:211
ofstream mLog
Definition: main.h:228
std::vector< std::vector< int > > mFieldMappingsFile1
Definition: main.h:239
string itoa(int n)
Convert an int to a string.
std::vector< points * > retrievePoints(datafile *pFile, vector< int > rPartitions)
Construct a vector of pointers to datasets (point objects) from a list of partition numbers...
Definition: main.cpp:240
std::vector< std::vector< int > > getFieldMappings(int rFile)
Get the field mapping vector for the specified file.
Definition: main.cpp:557
virtual string get_metric_name()
Definition: metric.cpp:34
string getFileName(int rFile)
Get File Name.
Definition: main.cpp:523
ComSwitch gCmdSwitches
Definition: main.cpp:10
string mOutPrefix
Definition: main.h:229
points * get_points(int partition)
Get a partitions&#39; points.
Definition: file.cpp:100
bool readOptions()
Set option string and long opts struct then parse arguments.
Definition: main.cpp:597
char ** mpArgv
Number of arguments.
Definition: main.h:214
blockLoc i
Definition: read.cpp:79
int get_num_partitions()
Get number of partition in the file.
Definition: file.cpp:151
int mInfile1Dimensions
Bad command line switch detection.
Definition: main.h:216
std::vector< adj_map > mFile2ConversionFactor
Definition: main.h:223
long double calcAverageValue(points *pPoints, int rVar)
Calculates the average value of the points.
Definition: main.cpp:276
metric * metric_select(int m, std::vector< points * > dss1, std::vector< points * > dss2, int var_ds1, int var_ds2, ofstream &outfile, string outprefix)
Definition: metric.cpp:1194
int main(int argc, char *argv[])
Definition: blastest.C:94
string mInfileName2
Definition: main.h:232
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
Definition: main.h:32
std::vector< std::vector< int > > mFieldMappingsFile2
Definition: main.h:240
static void delete_all(std::vector< points * > points_vector)
Definition: points.cpp:227
long double factor
Definition: datatypedef.h:33
vector< datafile * > openAndParseFiles()
Open the files specified at the command line and parse them.
Definition: main.cpp:40
static points * bilinear(points *pTarget, points *pSource, int rTargetVariable, int rSourceVariable)
Performs bilinear interpolation to find values from source mesh at the target points.
std::vector< adj_map > getConvFactor(int rFile)
Get conversion factors.
Definition: main.cpp:474
ifstream mInfile2
Definition: main.h:235
int mArgc
Definition: main.h:213
bool parseOptions()
Parse command options, begin logging.
Definition: main.cpp:395
static bool contains_null(std::vector< points * > points_vector)
Definition: points.cpp:237
ComSwitch()
Default Constructor.
Definition: main.cpp:348
Used to store adjustment (normalization factor, conversion factor) information.
Definition: datatypedef.h:31
bool same_elements(std::vector< int > vector_1, std::vector< int > vector_2)
CGAL_KERNEL_INLINE Comparison_result compare(const NT &n1, const NT &n2)
Definition: number_utils.h:143
std::vector< index_order > getIndexOrder(int rFile)
Get the index order for the specified file.
Definition: main.cpp:577
string getOutPrefix()
Get OutPrefix.
Definition: main.cpp:543
std::vector< adj_map > mFile1ConversionFactor
Range of region of interest.
Definition: main.h:222
bool parseValuesFromArguments(string rOptString, const struct option *rLongOpts)
Read and parse options from array.
Definition: main.cpp:624
Definition: metric.h:35
std::vector< string > str_tokenize(string full, string delimiters)
static void printFiletypes()
Print list valid filetypes to stdout.
Definition: fileselect.cpp:193
int var1
Definition: datatypedef.h:46
std::vector< index_order > mIndexOrderFile1
Definition: main.h:242
int file2_partition
Definition: datatypedef.h:48
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation ** files(the"Software")
void printPointValues(points *pPoints)
Write point values to standard out.
Definition: main.cpp:259
std::vector< adj_map > mFile2Norm
Definition: main.h:226
bool mBadSwitch
The actual command line arguments.
Definition: main.h:215
bool check_non_numeric_str(string test_str)
int get_num_points()
Definition: points.cpp:117
bool initializeFileStreams()
Initialize file streams.
Definition: main.cpp:922
int getFileDimensions(int rFile)
Get file dimensions.
Definition: main.cpp:462