// file: $USFS/eval/exp_13/code/sbe_compute.cc
//

// isip include files
//
#include "sbe_eval.h"
#include <string.h>

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

// program to find the mean value
//
logical_1 Sbe_eval::compute_cc(char_1** input_file, char_1** output_file,
			       int option) {
  
  FILE** fp_in = (FILE**)NULL;
  FILE** fp_out = (FILE**)NULL;;

  fp_in = new FILE*[no_of_input];
  fp_out = new FILE*[no_of_output];
  
  // opening the input and output files
  //
  for (int_4 i=0; i < no_of_input; i++) {
    fp_in[i] = fopen((char*)input_file[i], "r");
  }

  for (int_4 i=0; i < no_of_output; i++) {
    fp_out[i] = fopen((char*)output_file[i], "w");
  }
    
  if (option == SBE_PARTITION) {

    // finding the mean value
    //
    if (mean_cc(fp_in) == ISIP_FALSE) {
      error_handler_cc((char_1*)"main_cc",
			   (char_1*)"error computing the mean");
    }
    
    // finding the standard deviation
    //
    if (std_cc() == ISIP_FALSE) {
      error_handler_cc((char_1*)"main_cc",
		       (char_1*)"error computing the std");
    }
    
    // writing to the output files
    //
    if (output_cc(fp_out) == ISIP_FALSE) {
      error_handler_cc((char_1*)"main_cc",
		       (char_1*)"error outputting the files");
      return ISIP_FALSE;
    }
  }
  
  if (option == SBE_ASSIGN) {
    
    if (combine_cc(fp_in, fp_out) == ISIP_FALSE) {
      error_handler_cc((char_1*)"main_cc",
		       (char_1*)"error outputting the files");
      return ISIP_FALSE;
    }
  }

  if (option == SBE_ERROR) {

    if (error_cc(fp_in) == ISIP_FALSE) {
      error_handler_cc((char_1*)"main_cc",
		       (char_1*)"error outputting the files");
      return ISIP_FALSE;
    }
  }

  if (option == SBE_INDEX) {
    
    if (assign_cc(fp_in, fp_out) == ISIP_FALSE) {
      error_handler_cc((char_1*)"main_cc",
		       (char_1*)"error assigning the files");
      return ISIP_FALSE;
    }
  }
  
  // opening the input and output files
  //
  for (int_4 i=0; i < no_of_input; i++) {
    fclose(fp_in[i]);
  }
  
  for (int_4 i=0; i < no_of_output; i++) {
    fclose(fp_out[i]);
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
  
}



