// file: ht_param_0.cc
//
// function to read data from parameter file
//

// isip include files
//
#include "init_triphones.h"
#include "init_triphones_constants.h"

// method: read_params_cc
//
// arguments:
//  FILE* fp_param : (input) file pointer to params file
//  char_1* in_models_file : (output) name of file containing input models
//  char_1* out_models_file : (output) name of file containing output model
//  char_1* in_trans_file : (output) name of file containing input trans
//  char_1* out_trans_file : (output) name of file containing output trans
//  char_1* in_states_file : (output) name of file containing input states
//  char_1* out_states_file : (output) name of file containing output states
//  char_1* tri_clist_file : (output) name of file with clustered triphones
//  char_1* ciphones_file : (output) name of file with initial monophones
//                                     from context dependent training  
//
// return: a logical flag to indicate success
//
logical_1 read_params_cc(FILE* fp_param_a, char_1* in_models_file_a,
			 char_1* out_models_file_a, char_1* in_trans_file_a,
			 char_1* out_trans_file_a, char_1* in_states_file_a,
			 char_1* out_states_file_a, char_1* tri_clist_file_a,
			 char_1* ciphones_file_a) {

  // string to hold temporary data
  //
  char_1* tmp = new char_1[ISIP_MAX_STRING_LENGTH];
  
  // read data from file
  //
  while (fscanf(fp_param_a, "%s", tmp) != EOF) {
    
    // ignore comment lines 
    //
    if (tmp[0] == (char_1)'#') {
      
      // do nothing
      //
      fscanf(fp_param_a, "%[^\n]", tmp);
      fscanf(fp_param_a, "%[\n]", tmp);
    }

    // read name of input and output models files
    //
    else if (strcmp((char*)tmp, (char*)ITRI_IN_MODELS ) == 0) {
      fscanf(fp_param_a, "%s", tmp);
      fscanf(fp_param_a, "%s", tmp);
      strcpy((char*)in_models_file_a, (char*)tmp); 
      expand_filename_cc(in_models_file_a);
    }

    else if (strcmp((char*)tmp, (char*)ITRI_OUT_MODELS ) == 0) {
      fscanf(fp_param_a, "%s", tmp);
      fscanf(fp_param_a, "%s", tmp);
      strcpy((char*)out_models_file_a, (char*)tmp); 
      expand_filename_cc(out_models_file_a);
    }

    // read the input  and output transitions files
    //
    else if (strcmp((char*)tmp, (char*)ITRI_IN_TRANS ) == 0) {
      fscanf(fp_param_a, "%s", tmp);
      fscanf(fp_param_a, "%s", tmp);
      strcpy((char*)in_trans_file_a, (char*)tmp); 
      expand_filename_cc(in_trans_file_a);
    }

    else if (strcmp((char*)tmp, (char*)ITRI_OUT_TRANS ) == 0) {
      fscanf(fp_param_a, "%s", tmp);
      fscanf(fp_param_a, "%s", tmp);
      strcpy((char*)out_trans_file_a, (char*)tmp); 
      expand_filename_cc(out_trans_file_a);
    }

    // read the input  and output states files
    //
    else if (strcmp((char*)tmp, (char*)ITRI_IN_STATES ) == 0) {
      fscanf(fp_param_a, "%s", tmp);
      fscanf(fp_param_a, "%s", tmp);
      strcpy((char*)in_states_file_a, (char*)tmp); 
      expand_filename_cc(in_states_file_a);
    }

    else if (strcmp((char*)tmp, (char*)ITRI_OUT_STATES ) == 0) {
      fscanf(fp_param_a, "%s", tmp);
      fscanf(fp_param_a, "%s", tmp);
      strcpy((char*)out_states_file_a, (char*)tmp); 
      expand_filename_cc(out_states_file_a);
    }

    else if (strcmp((char*)tmp, (char*)ITRI_TRI_CLIST ) == 0) {
      fscanf(fp_param_a, "%s", tmp);
      fscanf(fp_param_a, "%s", tmp);
      strcpy((char*)tri_clist_file_a, (char*)tmp); 
      expand_filename_cc(tri_clist_file_a);
    }

    else if (strcmp((char*)tmp, (char*)ITRI_CI_PHONES ) == 0) {
      fscanf(fp_param_a, "%s", tmp);
      fscanf(fp_param_a, "%s", tmp);
      strcpy((char*)ciphones_file_a, (char*)tmp); 
      expand_filename_cc(ciphones_file_a);
    }

    
    // otherwise ignore the line
    //
    else {
      fscanf(fp_param_a, "%[^\n]", tmp);
      fscanf(fp_param_a, "\n");
    }
  }

  
  // delete memory
  //
  delete [] tmp;
  
  // return gracefully
  //
  return(ISIP_TRUE);
}
  


