// file: $USFS/class/sbe_eval/v1.0/sbe_error.cc
//

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

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

// program to find the error performance
//
logical_1 Sbe_eval::error_cc(FILE** fp_in) {

  // declare local variables
  //
  int_4 index0, index1;
  float error = 0;
  int_4 count11 = 0, count12 = 0, count13 = 0;
  int_4 count21 = 0, count22 = 0, count23 = 0;
  int_4 count31 = 0, count32 = 0, count33 = 0;
  
  char buf0[ISIP_MAX_STRING_LENGTH];
  char buf1[ISIP_MAX_STRING_LENGTH];
  
  for (int_4 i=0; i < no_of_images_d; i++) {
    
    fscanf(fp_in[0], "%s%ld", buf0, &index0);
    fscanf(fp_in[1], "%s%ld", buf1, &index1);
    
    if ((index0 == 1) && ( index1 == 1)) {
      count11++;
    }
    
    if ((index0 == 1) && (index1 == 2)) {
      count12++;
      error++;
    }

    if ((index0 == 1) && (index1 == 3)) {
      count13++;
      error++;
    }

    if ((index0 == 2) && ( index1 == 1)) {
      count21++;
      error++;
    }
    
    if ((index0 == 2) && (index1 == 2)) {
      count22++;
    }

    if ((index0 == 2) && (index1 == 3)) {
      count23++;
      error++;
    }

    if ((index0 == 3) && ( index1 == 1)) {
      count31++;
      error++;
    }
    
    if ((index0 == 3) && (index1 == 2)) {
      count32++;
      error++;
    }
    
    if ((index0 == 3) && (index1 == 3)) {
      count33++;
    }
    
  }
  
  error = error / no_of_images_d;
  
  // print the error along with the confusion matrix
  //
  fprintf(stdout, "error is %f\n", error);
  fprintf(stdout, "count11 = %ld\n", count11);
  fprintf(stdout, "count12 = %ld\n", count12);
  fprintf(stdout, "count13 = %ld\n", count13);
  fprintf(stdout, "count21 = %ld\n", count21);
  fprintf(stdout, "count22 = %ld\n", count22);
  fprintf(stdout, "count23 = %ld\n", count23);
  fprintf(stdout, "count31 = %ld\n", count31);
  fprintf(stdout, "count32 = %ld\n", count32);
  fprintf(stdout, "count33 = %ld\n", count33);
  
  // exit gracefully
  //
  return ISIP_TRUE;
}





    
