// file: bw_print_4.cc
//
// isip include files
//
#include "bw_train.h"
#include "bw_train_constants.h"

// method: print_acc_cc
//
// arguments:
//  FILE* fp_acc_file : (output) output accumulators file
//  float_8*** new_trans : (input) numerator of transition estimators
//  int_4 num_trans : (input) number of transition matrixes
//  int_4* trans_size : (input) sizes of all transition matrixes
//  float_8*** train_mean : (input) mean accumulators
//  float_8*** train_covar : (input) covariance accumulators
//  float_8** mix_weights : (input) mixture weight accumulators
//  float_8* state_occ : (input) state occupance accumulators
//  int_4 num_states : (input) number of states
//  int_4 num_mix : (input) number of mixtures
//  int_4 num_features : (input) number of features
//  int_4* model_access_counts : (input) the number of times each model was
//                               accessed in this training set
//  int_4 num_models : (input) the number of models
//
// return: a logical flag to indicate success
//

// this method writes out the accumulators file
//
logical_1 print_acc_cc(FILE* fp_acc_file_a, float_8*** new_trans_a,
		       int_4 num_trans_a, int_4* trans_size_a,
		       float_8*** train_mean_a,
		       float_8*** train_covar_a, float_8** mix_weights_a,
		       float_8* state_occ_a, int_4 num_states_a,
		       int_4 num_mix_a, int_4 num_features_a,
		       int_4* model_access_counts, int_4 num_models_a) {

  // local variables
  //
  int_4 tmp;
  
  // print out transition matrix related accumulators
  //
  for (int_4 i = 0; i < num_trans_a; i++) {
    tmp = trans_size_a[i];
    for (int_4 j = 0; j < tmp; j++) {
      fwrite((void_p)new_trans_a[i][j], sizeof(float_8), tmp, fp_acc_file_a);
    }
  }
  
  // print out states related accumulators
  //
  for (int_4 i = 0; i < num_states_a; i++) {
    for (int_4 j = 0; j < num_mix_a; j++) {
      fwrite((void_p)train_mean_a[i][j], sizeof(float_8), num_features_a,
	     fp_acc_file_a);
      fwrite((void_p)train_covar_a[i][j], sizeof(float_8), num_features_a,
	     fp_acc_file_a);
    }
    fwrite((void_p)mix_weights_a[i], sizeof(float_8), num_mix_a,
	   fp_acc_file_a);
  }
  fwrite((void_p)state_occ_a, sizeof(float_8), num_states_a, fp_acc_file_a);

  // print out the model access counts
  //
  fwrite((void_p)model_access_counts, sizeof(int_4), num_models_a,
	 fp_acc_file_a);
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
