// file: $USFS/class/image_eval/v1.0/imgev_diff_0.cc
//

// system include files
//
#include <stdlib.h>

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

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

// method: diff_cc
//
// arguments:
//   float_4* diff_values_a: (output) the difference between reference
//   and test value
//   int_4& counter_a: (output) indicating the number of files successfully
//   processed
//   char_1** ref_fnames_a: (input) reference filename buffer
//   float_4* ref_values_a: (input) reference value buffer
//   int_4 ref_num_items_a: (input) number of reference data
//   int_4* ref_index_a: (input) index array of ref data in ascending order
//   char_1** tst_fnames_a: (input) test filename buffer
//   float_4* tst_values_a: (input) test value buffer
//   int_4 tst_num_items_a: (input) number of test data
//
// return:
//   logical_1 to indicate status
//
// This method calculates the difference between test score
// and the reference score (test-reference).  The output is
// a one-to-one mapping with the test scores.
//
//
logical_1 Image_eval::diff_cc(float_4* diff_values_a, int_4& counter_a,
			      char_1** ref_fnames_a, float_4* ref_values_a,
			      int_4 ref_num_items_a, int_4* ref_index_a,
			      char_1** tst_fnames_a, float_4* tst_values_a,
			      int_4 tst_num_items_a) {

  int_4 pos;

  if (debug_level_d > ISIP_DEBUG_NONE) {
    fprintf(stdout, "\ndifference values:\n");
  }
  
  for (int_4 i = 0; i < tst_num_items_a; i++) {
    pos = lookup_cc(tst_fnames_a[i], ref_fnames_a, ref_num_items_a,
		    ref_index_a);
    if (pos == IMGEV_NOT_FOUND) {
      error_handler_cc((char_1*)"diff_cc", (char_1*)"test item not found");
      return ISIP_FALSE;
    }
    
    diff_values_a[i] = tst_values_a[i] - ref_values_a[ref_index_a[pos]];

    // increment counter
    //
    counter_a++;
    
    // print out debug info
    //
    if (debug_level_d > ISIP_DEBUG_NONE) {
      fprintf(stdout, IMGEV_DEBUG_FORMAT_B, IMAGE_EVAL_CLASS_NAME, "diff_cc",
	      i+1, tst_values_a[i], tst_fnames_a[i],
	      ref_values_a[ref_index_a[pos]], ref_fnames_a[ref_index_a[pos]],
	      diff_values_a[i]);
    }
  }

  // exit gracefully
  //
  return ISIP_TRUE;
}






