// file: $USFS/util/usfs_eval/v1.0/usfs_gp_0.cc
//
// a simple command line parser
//

// system include files
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// isip include files
//
#include "usfs_eval.h"

#include <integral_constants.h>
#include "usfs_eval_constants.h"

// function: get_parameters_cc
//
// arguments:
//  logical_1 &flag_histogram_a: (output) flag indicating if histogram option
//  as entered
//  logical_1 &flag_stats_a: (output) flag indicating if stats option was
//  entered
//  logical_1 &flag_corr_a: (output) flag indicating if correlation option was
//  entered
//  logical_1 &flag_summary_a: (output) flag indicating if summary option was
//  entered
//  int_4 &debug_level_a: (output) flag indicating the debug level
//  char_1* ref_file_a: (output) reference file
//  char_1* tst_file_a: (output) test file
//  int argc: (input) argc from the main program
//  char** argv: (input) argv from the main program
//
// return value: a logical_1 indicating status
//
// This function parses command line arguments.
//
//
logical_1 get_parameters_cc(logical_1 &flag_histogram_a,
			    logical_1 &flag_stats_a,
			    logical_1 &flag_corr_a, logical_1 &flag_summary_a,
			    int_4 &debug_level_a,
			    char_1* tst_file_a, char_1* ref_file_a,
			    int argc, char** argv) {
    
  // main decoding loop
  //
  int_4 last_index = argc;

  // if no arguments are given then print out a help message
  //
  if (last_index == (int)1) {
    char_1 tmp_string[ISIP_MAX_STRING_LENGTH];
    sprintf((char*)tmp_string,
	    (char*)ISIP_HELP_FORMAT, (char*)USEV_HELP_FILE);
    system((char*)tmp_string);

    // exit gracefully
    //
    exit (ISIP_NO_ERROR);
  }
  
  for (int_4 index=1; index<last_index; index++) {

    // check for help
    //
    if (strcmp((char*)ISIP_HELP_OPTION, argv[index]) == (int)0) {
      char_1 tmp_string[ISIP_MAX_STRING_LENGTH];
      sprintf((char*)tmp_string,
	      (char*)ISIP_HELP_FORMAT, (char*)USEV_HELP_FILE);
      system((char*)tmp_string);

      // exit gracefully
      //
      exit (ISIP_NO_ERROR);
    }

    // pick off histogram option
    //
    else if (strcmp((char*)USEV_OPT_A, argv[index]) == (int)0) {
      flag_histogram_a = ISIP_TRUE;
    }

    // pick off stats option
    //
    else if (strcmp((char*)USEV_OPT_B, argv[index]) == (int)0) {
      flag_stats_a = ISIP_TRUE;
    }

    // pick off correlation option
    //
    else if (strcmp((char*)USEV_OPT_C, argv[index]) == (int)0) {
      flag_corr_a = ISIP_TRUE;
    }

    // pick off summary option
    //
    else if (strcmp((char*)USEV_OPT_D, argv[index]) == (int)0) {
      flag_summary_a = ISIP_TRUE;
    }

    // pick off debug option
    //
    else if (strcmp((char*)USEV_OPT_E, argv[index]) == (int)0) {

      // save the debug level
      //
      debug_level_a = (int_4)atoi(argv[index+1]);

      // skip it to the next argument
      //
      index++; 
    }
  }

  
  // pick off the filenames
  //
  strcpy((char*)tst_file_a, argv[argc-2]);
  strcpy((char*)ref_file_a, argv[argc-1]);
  
  // exit gracefully
  //
  return ISIP_TRUE;
}




