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

// isip include files
//
#include "hmm_train.h"
#include "hmm_train_constants.h"

// method: get_phlist_cc
//
// arguments:
//  FILE* fp : (input) the transcription file
//  char_1** phn_list : (output) the combined phone sequences
//  char_1** monophones : (input) the monophones
//  int_4 num_mono : (input) the number of monophones
//  int_4 ph_size : (input) the context size
//  int_4 context_mode : (input) the current context mode
//  int_4* phone_map : (input) the phone map used to compute the index
//  int_4* phones : (input) the central phones of the models comprising utt.
//  int_4& num_ph : (output) the number of the phones in this utterance
// return: a logical flag to indicate success
//
logical_1 get_phlist_cc(FILE* fp_a, int_4* phn_list_a, char_1** monophones_a,
			int_4 num_mono_a, int_4 ph_size_a,
			int_4 context_mode_a, int_4* phone_map_a,
			int_4* phones_a, int_4& num_ph_a, int_4 num_sph_a,
			int_4* sph_index_a) {
  
  // string to hold temporary data
  //
  char_1* tmp = new char_1[ISIP_MAX_STRING_LENGTH];
  char_1* tmp1 = new char_1[ISIP_MAX_STRING_LENGTH];
  num_ph_a = (int_4)0;
  
  // read data from file
  //
  while (fscanf(fp_a, "%s", tmp) != EOF) {

    
    // ignore comment lines 
    //
    if (tmp[0] == (char_1)'#') {
      
      // do nothing
      //
      fscanf(fp_a, "%[^\n]", tmp);
      fscanf(fp_a, "%[\n]", tmp);
    }

    // read name of monophones file
    //
    else if (tmp[0] == (char_1)'"') {
      //
    }

    else if (tmp[0] == (char_1)'.') {
      fscanf(fp_a, "%[^\n]", tmp);
      fscanf(fp_a, "\n");
      break;
    }
    else {

      // get the phone index
      //
      phn_list_a[num_ph_a] = get_phn_index_cc(tmp, monophones_a, num_mono_a,
					      ph_size_a, context_mode_a,
					      phone_map_a, phones_a[num_ph_a],
					      num_sph_a, sph_index_a);
      num_ph_a++;
    }   
  }
  
  // delete memory
  //
  delete [] tmp;
  delete [] tmp1;
  
  // return gracefully
  //
  return(ISIP_TRUE);
}
  


