// file: $USFS/class/image_analysis/v6.0/imaga_get_0.cc
//

// isip include files
//
#include "image_analysis.h"
#include "image_analysis_constants.h"

// method: get_mode_cc
//
// arguments:
//  FILE* fp: (input) the file pointer of the parameter file
//
// return: a logical_1 value indicating status
//
// this method checks for the option of the mode in the parameter file,
// reads the mode, and converts it to an integer code.
//
logical_1 Image_analysis::get_mode_cc(FILE* fp_a) {
  
  // set the mode to a null value
  //
  mode_d = IMAGA_MODE_NONE;
  
  // rewind the file
  //
  rewind(fp_a);
  
  // declare local variables
  //
  char_1* buf = new char_1[ISIP_MAX_STRING_LENGTH];
  
  while (fgets((char*)buf, ISIP_MAX_STRING_LENGTH, fp_a) != (char*)NULL) { 
    
    // checking for a comment line and/or a blank line
    //
    char_1* nonwhitespace = new char_1[2];
    
    if ((buf[0] != ISIP_POUND) &&
	(sscanf((char*)buf, "%1s", nonwhitespace) > (int)0)) {
      
      // parse the line
      //
      char_1* str_key = new char_1[ISIP_MAX_STRING_LENGTH];
      char_1* str_val = new char_1[ISIP_MAX_STRING_LENGTH];
      sscanf((char*)buf, (char*)IMAGA_FORMAT_0, str_key, str_val);
      
      // checking for the mode keyword
      //
      if (strcmp((char*)str_key, (char*)IMAGA_MODE) == 0) {
	
	// convert the name to an integer code
	//
	if (strcmp((char*)str_val, (char*)IMAGA_MODE_TEST_NAME) == 0) {
	  mode_d = IMAGA_MODE_TEST;
	}
	else if (strcmp((char*)str_val, (char*)IMAGA_MODE_TRAIN_NAME) == 0) {
	  mode_d = IMAGA_MODE_TRAIN;
	}
	else if (strcmp((char*)str_val, (char*)IMAGA_MODE_ANALYSIS_NAME)
		 == 0) {
	  mode_d = IMAGA_MODE_ANALYSIS;
	}
	else if (strcmp ((char*)str_val, (char*)IMAGA_MODE_UPDATE_NAME) == 0) {
	  mode_d = IMAGA_MODE_UPDATE;
	}
      }

      // release memory
      //
      delete [] str_key;
      delete [] str_val;
    }

    // release memory
    //
    delete [] nonwhitespace;
  }

  // release memory
  //
  delete [] buf;
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
