// file: $USFS/class/image_eval/v1.0/image_eval.h
//

// make sure definitions are made only once
//
#ifndef __ISIP_IMAGE_EVAL
#define __ISIP_IMAGE_EVAL

// isip include files
//
#ifndef __ISIP_INTEGRAL
#include <integral.h>
#endif

// Image_eval: a class to handle evaluation of the sbe scores
// of reference file and test file
//
class Image_eval {
  //---------------------------------------------------------------------------
  //
  // protected members
  //
  //---------------------------------------------------------------------------
protected:

  // declare a variable for debugging
  //
  int_4 debug_level_d;
  logical_1 fatal_mode_d;
    
  //---------------------------------------------------------------------------
  //
  // public methods
  //
  //---------------------------------------------------------------------------
public:
  
  // required methods
  //
  char_1* name_cc();
  logical_1 error_handler_cc(char_1* method_name, char_1* message);
  logical_1 debug_cc(FILE* fp, char_1* message);
  logical_1 set_value_cc(int_4 debug_level);
  logical_1 set_value_cc(logical_1 fatal_mode);
  
  // destructor/constructor
  //
  ~Image_eval();
  Image_eval();
  Image_eval(logical_1 fatal_mode);

  // load method
  //
  logical_1 load_cc(char_1** &fnames, float_4* &values,
		    int_4 &num_item, int_4 &array_size, char_1* fname_in);

  // statistical analysis methods 
  //
  logical_1 histogram_cc(float_4* bins_midpts, int_4* bins_freqs,
			 float_4 min_val, float_4 max_val,
			 int_4 num_bins, char_1** ref_fnames,
			 float_4* ref_values, int_4 ref_num_items,
			 char_1** tst_fnames, float_4* tst_values,
			 int_4 tst_num_items);
    
  logical_1 stats_cc(float_4& min, float_4& median, float_4& max, float_4& avg,
		     float_4& rms, char_1* min_file, char_1* median_file,
		     char_1* max_file, int_4& proc, int_4& total,
		     char_1** ref_fnames, float_4* ref_values,
		     int_4 ref_num_items, char_1** tst_fnames, 
		     float_4* tst_values, int_4 tst_num_items);

  float_4 correlation_cc(char_1** ref_fnames, float_4* ref_values,
			 int_4 ref_num_items, char_1** tst_fnames,
			 float_4* tst_values, int_4 tst_num_items);

  // utility methods
  //

  // diff method
  //
  logical_1 diff_cc(float_4* values, int_4& counter, char_1** ref_fnames,
		    float_4* ref_values, int_4 ref_num_items,
		    int_4* ref_index, char_1** tst_fnames,
		    float_4* tst_values, int_4 tst_num_items);

  float_4 average_cc(float_4* values, int_4 num_items);
  
  // sort methods
  //
  logical_1 qsort_cc(int_4* index, float_4* values, int_4 num_items);  
  logical_1 qsort_cc(int_4* index, char_1** values, int_4 num_items);

  // print methods
  //
  logical_1 print_summary_cc(float_4 min_a, float_4 max_a, float_4 avg,
			     float_4 median_a, float_4 rms_a,
			     char_1* min_file, char_1* max_file,
			     char_1* median_file);

  logical_1 print_histogram_cc(int_4 num_bins, float_4* bins_midpts,
			       int_4* bins_freqs);

  logical_1 print_correlation_cc(float_4 value);
  
  // cleanup methods
  //
  logical_1 cleanup_cc(char_1** &fnames, int_4 num_items);
  logical_1 cleanup_cc(float_4* values);

  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
private:

  // exit handler methods
  //
  volatile void exit_handler_cc();
  
  // grow_arrays_cc grows arrays by creating a new copy
  //
  logical_1 grow_arrays_cc(float_4* arrays, int_4& cur_size, int_4 grow_size);
  logical_1 grow_arrays_cc(char_1** &arrays, int_4& cur_size, int_4 grow_size);

  // utility methods
  //
  int_4 lookup_cc(char_1* str, char_1** fnames, int_4 num_items, int_4* index);

  // compare methods
  //
 
  // compare_cc compares two floats and returns an int to indicate
  // the status of the comparison
  static int compare_float_cc(const void* num1, const void* num2);
  static int compare_str_cc(const void* str1, const void* str2);

};

// end of file
//
#endif






