// file: normalize_features/nf_param_0.cc
//

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

// local include files
//
#include "normalize_features.h"
#include "normalize_features_constants.h"

// function: get_parameters_cc
//
// arguments:
//
//  int argc: (input) argc from the main program
//  char** argv: (input) argv from the main program
//  char_1* input_file : (output) the name of the input file
//  char_1* output_file : (output) the name of the output file
//  int_4& num_coeffs: (output) number of coefficients in each feature vector
//  int_4&  num_subtract: (output) number of coefficients to be subtracted
//                        from the mean
//  int_4&  num_div: (output) number of coefficients to be divided by the
//                   standard deviation
//  int_4& input_mode: (output) the ascii or binary mode of the input file
//  int_4& output_mode: (output) the ascii or binary mode of the output file
//
// return value: a logical_1 indicating status
//
// this function parses command line arguments
//
logical_1 get_parameter_cc(int_4 argc, char_1** argv, char_1* input_file_a,
			   char_1* output_file_a, int_4& num_coeffs_a,
			   int_4& num_subtract_a, int_4& num_div_a,
			   int_4& input_mode_a, int_4& output_mode_a) {
  
  // loop over all of the arguments and set the appropriate variables
  //
  for (int_4 index = 1; index < argc; index++) {

    if (strcmp((char*)NF_OPT_FILE_IN, (char*)argv[index]) == (int)0) {

      // get the input file name
      //
      strcpy((char*)input_file_a, (char*)argv[++index]);
    }

    else if (strcmp((char*)NF_OPT_FILE_OUT, (char*)argv[index]) == (int)0) {

      // get the output file name
      //
      strcpy((char*)output_file_a, (char*)argv[++index]);
    }
    
    else if (strcmp((char*)NF_OPT_NUM_COEFFS, (char*)argv[index])
	     == (int)0) {
      
      // get the number of coefficients
      //
      num_coeffs_a = (int_4)atoi((char*)argv[++index]);
    }

    else if (strcmp((char*)NF_OPT_NUM_SUBTRACT, (char*)argv[index])
	     == (int)0) {
      
      // get the number of coefficients to be subtracted
      //
      num_subtract_a = (int_4)atoi((char*)argv[++index]);
    }

    else if (strcmp((char*)NF_OPT_NUM_DIV, (char*)argv[index])
	     == (int)0) {
      
      // get the number of coefficients to be divided
      //
      num_div_a = (int_4)atoi((char*)argv[++index]);
    }    
    
    else if (strcmp((char*)NF_OPT_IN_MODE, (char*)argv[index]) == (int)0) {
      
      // get the input mode ascii or binary
      //
      index++;
      if (strcmp((char*)NF_OPT_IO_MODE_ASCII, (char*)argv[index])
	  == (int)0) {
	input_mode_a = (int_4)NF_IO_MODE_ASCII;
      }
      else if (strcmp((char*)NF_OPT_IO_MODE_BINA, (char*)argv[index])
	       == (int)0) {
	input_mode_a = (int_4)NF_IO_MODE_BINA;
      }
    }
      
    else if (strcmp((char*)NF_OPT_OUT_MODE, (char*)argv[index]) == (int)0) {
      
      // get the output mode ascii or binary
      //
      index++;
      if (strcmp((char*)NF_OPT_IO_MODE_ASCII, (char*)argv[index])
	  == (int)0) {
	output_mode_a = (int_4)NF_IO_MODE_ASCII;
      }
      else if (strcmp((char*)NF_OPT_IO_MODE_BINA, (char*)argv[index])
	       == (int)0) {
	output_mode_a = (int_4)NF_IO_MODE_BINA;
      }
    }

    // display the help screen
    //
    else {

      // allocate memory for the command string
      //
      char_1 command_string[ISIP_MAX_STRING_LENGTH];

      // create the command line to display the help file
      //
      sprintf((char*)command_string, (char*)ISIP_HELP_FORMAT,
	      (char*)NF_HELP_FILE);

      // display the help file
      //
      system((char*)command_string);
      
      // exit gracefully
      //
      exit(ISIP_PROTO_ERROR);
    }
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
