// file: ih_cmd_0.cc
//

// isip include files
//
#include "init_hmm.h"
#include "init_hmm_constants.h"

// method: read_cmdline_cc
//
// arguments:
//  int_4 argc : (input) number of arguments
//  char_1** argv : (input) argument variables
//  char_1* input_file : (output) name of the input file
//  char_1* state_file : (output) name of the state file
//  char_1* trans_file : (output) name of the transition file
//  char_1* models_file : (output) name of the models file
//  char_1* var_floor_file : (output) name of the var floor file
//  int_4& mode : (output) input feature file binary/ascii
//  int_4& feat_dim : (output) feature_dimension
//  float_4& var_floor : (output) user defined variance floor
//  logical_1& delta : (output) user defined delta coeff. computations
//  logical_1& acc : (output) user defined acc coeff. computations
//  int_4& delta_win : (output) user defined window size
//  logical_1& feature_format : (output) user defined feature format
// 
// return: a logical_1 flag indicating success
//
// this method reads the commandline and deciphers the various
// arguments and options
//
logical_1 read_cmdline_cc(int_4 argc_a, char_1** argv_a,
			  char_1* input_file_a, char_1* state_file_a,
			  char_1* trans_file_a, char_1* models_file_a,
			  char_1* var_floor_file_a, int_4& mode_a,
			  int_4& feat_dim_a, float_4& var_floor_a,
			  logical_1& delta_a, logical_1& acc_a,
			  int_4& delta_win_a, logical_1& feature_format_a) {

  // create the help message
  //
  char_1* cmd_str = new char_1[ISIP_MAX_STRING_LENGTH];
  sprintf((char*)cmd_str, (char*)ISIP_HELP_FORMAT, (char*)IH_HELP_FILE);
  
  if (argc_a < 9) {
    
    // print the help message
    //
    system((char*)cmd_str);
    fprintf(stdout, "\n");
    
    // exit gracefully
    //
    exit(ISIP_PROTO_ERROR);
  }
  
  // decipher the commandline arguments
  //
  for (int_4 i = 1; i < argc_a; i++) {

    // read the name of the input file
    //
    if (strcmp(IH_INPUT_OPT, (char*)argv_a[i]) == 0) {
      strcpy((char*)input_file_a, (char*)argv_a[++i]);
      expand_filename_cc(input_file_a);
    }
    
    // read the name of the state file
    //
    else if (strcmp(IH_STATE_OPT, (char*)argv_a[i]) == 0) {
      strcpy((char*)state_file_a, (char*)argv_a[++i]);
      expand_filename_cc(state_file_a);
    }


    // read the name of the state file
    //
    else if (strcmp(IH_VAR_FLOOR_FILE_OPT, (char*)argv_a[i]) == 0) {
      strcpy((char*)var_floor_file_a, (char*)argv_a[++i]);
      expand_filename_cc(var_floor_file_a);
    }
    
    // read the name of the models file
    //
    else if (strcmp(IH_MODELS_OPT, (char*)argv_a[i]) == 0) {
      strcpy((char*)models_file_a, (char*)argv_a[++i]);
      expand_filename_cc(models_file_a);
    }

    // read the input feature file mode
    //
    else if (strcmp(IH_MODE_OPT, (char*)argv_a[i]) == 0) {
      if (strcmp((char*)argv_a[++i], IH_ASCII) == 0) {
	mode_a = IH_ASCII_MODE;
      }
      else {
	mode_a = IH_BINARY_MODE;
      }
    }

    // read the name of the transition file
    //
    else if (strcmp(IH_TRANS_OPT, (char*)argv_a[i]) == 0) {
      strcpy((char*)trans_file_a, (char*)argv_a[++i]);
      expand_filename_cc(trans_file_a);
    }

    // read the variance floor defined by user
    //
    else if (strcmp(IH_VAR_FLOOR_OPT, (char*)argv_a[i]) == 0) {
      var_floor_a = (float_8)atof((char*)argv_a[++i]);
    }

    // read the feature dimension
    //
    else if (strcmp(IH_NUM_FEAT_OPT, (char*)argv_a[i]) == 0) {
      feat_dim_a = (int_4)atoi((char*)argv_a[++i]);
    }
    
    // read if deltas are to be computed on the fly
    //
    else if (strcmp(IH_DELTA_OPT, (char*)argv_a[i]) == 0) {
      delta_a = ISIP_TRUE;
    }
    
    // read if accelerations are to be computed on the fly
    //
    else if (strcmp(IH_ACC_OPT, (char*)argv_a[i]) == 0) {
      acc_a = ISIP_TRUE;
    }
    
    // read the window size to be used in delta and/or acceleration
    // computations
    //
    else if (strcmp(IH_DELTA_WIN_OPT, (char*)argv_a[i]) == 0) {
      delta_win_a = (int_4)atoi((char*)argv_a[++i]);
    }
    
    // read if the feature format in htk
    //
    else if (strcmp(IH_HTK_OPT, (char*)argv_a[i]) == 0) {
      feature_format_a = ISIP_TRUE;
    }
    
    // otherwise print the help message
    //
    else {
      
      system((char*)cmd_str);

      // exit gracefully
      //
      exit(ISIP_PROTO_ERROR);
    }
  }
  
  // free memory
  //
  delete [] cmd_str;

  // exit gracefully
  //
  return ISIP_TRUE;
}
