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

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

// method: get_selvec_cc
//
// arguments:
//  FILE* fp: (input) the file pointer of the parameter file
//
// return: a logical_1 value indicating status
//
// this method reads the select vector from a parameter file.
//
logical_1 Image_analysis::get_selvec_cc(FILE* fp_a) {
  
  // rewind the file
  //
  rewind(fp_a);

  // counter to keep track of the active features
  //
  int_4 counter = 0;
  
  // declare local variables
  //
  char_1 buf[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[2];
    
    if ((buf[0] != ISIP_POUND) &&
	(sscanf((char*)buf, "%1s", nonwhitespace) > (int)0)) {
      
      // parse the line
      //
      char_1 str_key[ISIP_MAX_STRING_LENGTH];
      char_1 str_val[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_SEL) == (int)0) {

	strcpy((char*)model_name_d, (char*)str_val);
	
	fgets((char*)buf, ISIP_MAX_STRING_LENGTH,fp_a);

	char_1* set_tmp = (char_1*)buf;
	
	// read the selection vector
	//
	for (int_4 i=0; i < IMAGA_HE_VECTORS_VALUE; i++) {
	  
	  // read the vector into an array
	  //
	  sel_vec_d[i] = strtol((char*)set_tmp, (char**) &set_tmp, 10);
	  if (sel_vec_d[i] == 1) {
	    counter++;
	  }
	}
      }
    }
  }
  
  // recoding the number of active features
  //
  pca_t_values_read_d = counter;
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
