// file: ht_print_2.cc
//
// isip include files
//
#include "hmm_train.h"
#include "hmm_train_constants.h"

// method: print_trans_cc
//
// arguments:
//  char_1* file : (output) the new transitions file
//  int_4 num_trans : (input) the number of transitions matrix
//  int_4* trans_size : (input) size of each transition matrix
//  float_4*** transitions : (input) the updated transitions matrixes
//
// return: a logical flag to indicate success
//
logical_1 print_trans_cc(char_1* file_a, int_4 num_trans_a,
			 int_4* trans_size_a, float_4*** transitions_a) {

  // open the file
  //
  FILE* fp = fopen((char*)file_a, "w");
  if (fp == (FILE*)NULL) {
    fprintf(stdout, "Cannot open output transitions file %s\n", file_a);
    exit(ISIP_PROTO_ERROR);
  }

  // output the number of transition
  //
  fprintf(fp, "\n");
  fprintf(fp, "num_transitions = %ld\n\n", num_trans_a);
  
  // output the first matrix for all null models
  //
  fprintf(fp, "0. 2\n");
  for (int_4 i = 0; i < 2; i++) {
    fprintf(fp, " 0.0 0.0\n");
  }
  fprintf(fp, "\n");
  
  // output all the rest matrixes
  //
  for (int_4 i = 1; i < num_trans_a; i++) {
    fprintf(fp, "%ld. %ld\n", i, trans_size_a[i]);
    for (int_4 j = 0; j < trans_size_a[i]; j++) {
      for (int_4 k = 0; k < trans_size_a[i]; k++) {
        fprintf(fp, " %e", transitions_a[i][j][k]);
      }
      fprintf(fp, "\n");
    }
    fprintf(fp, "\n");
  }


  fclose(fp);

  // exit gracefully
  //
  return ISIP_TRUE;
}


