// file: dec_input_0.cc
//
 
// isip include files
//
#include "decoder.h"
#include "decoder_constants.h"

// method: read_features_cc
//
// arguments:
//  none
//  
// return: a logical_1 indicating status
//
// this method reads in the input feature vector from data buffer
// Note: Communicator API
//
logical_1 Decoder::read_features_cc() {

  // check file
  //
  if (buf_d == NULL) {
    error_handler_cc((char_1*)"read_features_cc",
		     (char_1*)"NULL input file pointer");
  }
  
  // initialize features if not done so
  //
  if (features_d == (float_4*)NULL) {
    features_d = new float_4[num_feat_d];
  }

  // mfc file is stored by double, but we will read it by float
  //
  float_8 *tmp_features;
  tmp_features = (float_8*) &buf_d[0];
  tmp_features += current_d;
  
  // dummy flag
  //
  logical_1 flag = ISIP_FALSE;
  int_4 i = 0;
  
  // if this is ascii format data
  //
  if (input_format_d == DEC_ASCII_FORMAT) {

    // read values one at a time
    //
    while (size_d > current_d) {

      // copy the data to the float buffer
      //
      features_d[i] = tmp_features[i++];
      
      // error message if input feature value is NaN
      //
      if (isnan(features_d[i])) {
	error_handler_cc((char_1*)"dec_input_0.cc", (char_1*)"Input feature value is either NaN");
      }
      
      // if data is read
      //
      if (i == num_feat_d) {
	flag = ISIP_TRUE;
	break;
      }
    }
  }
  
  // otherwise this is binary format data
  //
  else {
    
    // read vector at once
    //
    if ((size_d - current_d) >= num_feat_d) {
      for (int_4 j = 0; j < num_feat_d; j++) {
	features_d[j] = (float_4) tmp_features[j];
	current_d++;
	
	// error message if input feature value is NaN
	//
	if (isnan(features_d[j])) {
	  error_handler_cc((char_1*)"dec_input_0.cc", (char_1*)"Input feature value is NaN");
	}
	
      }
      flag = ISIP_TRUE;
    }
    else {
      flag = ISIP_FALSE;
    }
  }

  // exit gracefully
  //
  return flag;
}
