// file: $isip/class/asr/SpeakerVerifier/sv_06.cc
// version: $Id: sv_06.cc
//

// isip include files
//
#include <SpeakerVerifier.h>

// method: setParam
//
// arguments:
//  String param_file_name: (input) parameter file name
//
// set paramter file for verifier and read initial HMM/SVM/RVM
// parameters from it
//
boolean SpeakerVerifier::setParam(String param_file_name) {

  param_file_name_d = param_file_name;

  // check if algorithm is HMM
  //
  if (algorithm_d == HMM) {
    
    // open the parameter file
    //
    Sof param_file_sof;
    if (!param_file_sof.open(param_file_name_d)) {
      return Error::handle(name(), L"setParam: opening model file",
			   Error::FILE_NOTFND, __FILE__, __LINE__);

    }

    // parse the parameter file in a HMM class
    //
    if (!hmm_d.read(param_file_sof,
		    param_file_sof.first(hmm_d.name()))) {
      return Error::handle(name(), L"setParam: reading HMM parameters",
			   Error::ARG, __FILE__, __LINE__);
    }

    // close the parameter file
    //
    param_file_sof.close();
  }

  else if (algorithm_d == SVM) {

    // open the parameter file
    //
     Sof param_file_sof;
    if (!param_file_sof.open(param_file_name_d)) {
      return Error::handle(name(), L"setParam: opening model file",
			   Error::FILE_NOTFND, __FILE__, __LINE__);

    }

    // parse the parameter file in a SVM class
    //
    if (!svm_d.read(param_file_sof,
		    param_file_sof.first(svm_d.name()))) {
      return Error::handle(name(), L"setParam: reading SVM parameters",
			   Error::ARG, __FILE__, __LINE__);
    }

    // close the parameter file
    //
    param_file_sof.close(); 

  }
  else if (algorithm_d == RVM) {
    
    // open the parameter file
    //
     Sof param_file_sof;
     if (!param_file_sof.open(param_file_name_d)) {
       return Error::handle(name(), L"setParam: opening model file",
			    Error::FILE_NOTFND, __FILE__, __LINE__);
       
     }
     
     // parse the parameter file in a SVM class
     //
     if (!rvm_d.read(param_file_sof,
		    param_file_sof.first(rvm_d.name()))) {
      return Error::handle(name(), L"setParam: reading RVM parameters",
			   Error::ARG, __FILE__, __LINE__);
     }
     
     // close the parameter file
     //
     param_file_sof.close(); 
     
  }
  
  // exit gracefully
  //
  return true;  
}
