// file: $USFS/util/error_eval/v6.1/error_gps_0.cc
//
// a simple command line parser
//

// isip include files
//
#include "error_eval.h"
#include "error_eval_constants.h"

// function: get_parameters_cc
//
// arguments:
//  char_1**& input_file: (output) input files
//  char_1**& output_file: (output) output files
//  int_4& debug_level: (output) flag indicating the debug level
//  int_4& no_images: (output) number of images to be processed
//  int_4& option: (output) option index
//  int argc: (input) argc from the main program
//  char** argv: (input) argv from the main program
//  int_4& no_of_input: (output) number of input
//  int_4& no_of_output: (output) number of output
//
// return value: a logical_1 indicating status
//
// This function parses command line arguments.
//
//
logical_1 get_parameters_cc(char_1**& input_file_a, char_1**& output_file_a,
			    int_4& debug_level_a, int_4& no_images_a,
			    int_4& option_a, int argc_a, char** argv_a,
			    int_4& no_of_input_a, int_4& no_of_output_a) {
  
  // main decoding loop
  //
  int_4 last_index = argc_a;
  int_4 pos = 0;
  
  char_1 tmp_string[ISIP_MAX_STRING_LENGTH];
  
  // if no arguments are given then print out a help message
  //
  if (last_index == (int)1) {
    sprintf((char*)tmp_string,
	    (char*)ISIP_HELP_FORMAT, (char*)EE_HELP_FILE);
    system((char*)tmp_string);
  
    // exit gracefully
    //
    exit (ISIP_NO_ERROR);
  }

  int_4 index = 1;

  // check for help
  //
  if (strcmp((char*)ISIP_HELP_OPTION, argv_a[index]) == (int)0) {
    sprintf((char*)tmp_string,
	    (char*)ISIP_HELP_FORMAT, (char*)EE_HELP_FILE);
    system((char*)tmp_string);
    
    // exit gracefully
    //
    exit(ISIP_NO_ERROR);
  }
  
  // if the option is partition
  //
  else if (strcmp((char*)EE_OPT_A, argv_a[index]) == (int)0) {
    strcpy ((char*)tmp_string, (char*)argv_a[index+1]);
    no_of_input_a = 1;
    no_of_output_a = 3;
    option_a = 0;
  }
  
  // if the option is assign
  //
  else if (strcmp((char*)EE_OPT_B, argv_a[index]) == (int)0) {
    no_of_input_a = 3;
    no_of_output_a = 1;
    option_a = 1;
  }
  
  // if the option is error
  //
  else if (strcmp((char*)EE_OPT_C, argv_a[index]) == (int)0) {
    no_of_input_a = 2;
    option_a = 2;
  }

  // if the option is indexing a file to a particular class
  //
  else if (strcmp((char*)EE_OPT_D, argv_a[index]) == (int)0) {
    no_of_input_a = 1;
    no_of_output_a = 1;
    option_a = 3;
  }

  // pick off debug option
  //
  else if (strcmp((char*)EE_OPT_E, argv_a[index]) == (int)0) {
    
    // save the debug level
    //
    debug_level_a = (int_4)atoi(argv_a[index+1]);
  }
  
  // if the option is segmentation evaluation
  //
  else if (strcmp((char*)EE_OPT_F, argv_a[index]) == (int)0) {
    no_of_input_a = 2;
    option_a = 4;
  }

  // if the option is line detection evaluation
  //
  else if (strcmp((char*)EE_OPT_G, argv_a[index]) == (int)0) {
    no_of_input_a = 2;
    option_a = 5;
  }

  // read the input and output file names
  //
  if (no_of_input_a != 0) {
    input_file_a = new char_1*[no_of_input_a];
    for (int_4 i=0; i < no_of_input_a; i++) {
      pos++;
      strcpy ((char*)tmp_string, (char*)argv_a[index+pos]);
      input_file_a[i] = new char_1[strlen((char*)tmp_string)+1];
      strcpy ((char*)input_file_a[i], (char*)tmp_string);
    }
  }
  if (no_of_output_a != 0) {
    output_file_a = new char_1*[no_of_output_a];
    for (int_4 i=0; i < no_of_output_a; i++) {
      pos++;
      strcpy ((char*)tmp_string, (char*)argv_a[index+pos]);
      output_file_a[i] = new char_1[strlen((char*)tmp_string)+1];
      strcpy ((char*)output_file_a[i], (char*)tmp_string);
    }
  }

  pos++;
  if ((index + pos) < last_index) {
    no_images_a = atoi(argv_a[index+pos]);
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
