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

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

#include "image_analysis_constants.h"
#include <integral_constants.h>

// method: get_algorithm_cc
//
// arguments:
//  FILE* fp_a: (input) the file pointer of the parameter file
//
// return: an logical_1 value indicating status
//
// this method reads the algorithm choice from a parameter file.
//
logical_1 Image_analysis::get_algorithm_cc(FILE* fp_a) {
  
  // set the algorithm to a null value
  //
  algorithm_d = IMAGA_ALG_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_ALG) == (int)0) {
	
	// convert the name to a code
	//
	if (strcmp ((char*)str_val, (char*)IMAGA_ALG_HISTOGRAM_NAME)
	    == (int)0) {
	  algorithm_d = IMAGA_ALG_HISTOGRAM;
	}
	else if (strcmp ((char*)str_val, (char*)IMAGA_ALG_EDGEDET_NAME)
		 == (int)0) {
	  algorithm_d = IMAGA_ALG_EDGEDET;
	}
	else if (strcmp ((char*)str_val, (char*)IMAGA_ALG_FACTOR_NAME)
		 == (int)0) {
	  algorithm_d = IMAGA_ALG_FACTOR; 
	}
	else if (strcmp ((char*)str_val, (char*)IMAGA_ALG_FFT_NAME)
		 == (int)0) {
	  algorithm_d = IMAGA_ALG_FFT;
	}
	else if (strcmp ((char*)str_val, (char*)IMAGA_ALG_DIFF_NAME)
		 == (int)0) {
	  algorithm_d = IMAGA_ALG_DIFF;
	}
	else if (strcmp ((char*)str_val, (char*)IMAGA_ALG_SD_NAME)
		 == (int)0) {
	  algorithm_d = IMAGA_ALG_SD;
	}
	else if (strcmp ((char*)str_val, (char*)IMAGA_ALG_ENT_NAME)
		 == (int)0) {
	  algorithm_d = IMAGA_ALG_ENT;
	}
	else if (strcmp ((char*)str_val, (char*)IMAGA_ALG_RLE_NAME)
		 == (int)0) {
	  algorithm_d = IMAGA_ALG_RLE;
	}
	else if (strcmp ((char*)str_val, (char*)IMAGA_ALG_FRACT_NAME)
		 == (int)0) {
	  algorithm_d = IMAGA_ALG_FRACT;
	}
      }

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

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

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


