📄 bw_trans_0.cc
字号:
// file: bw_trans_0.cc//// isip include files//#include "bw_train.h"#include "bw_train_constants.h" // method: read_transitions_cc//// arguments:// int_4& num_trans : (output) number of transitions// int_4*& num_states : (output) containing number of states in model// char_1* trans_file : (input) data trans_file name// // return: a float_4*** pointing to a list of transition matrices//// this method reads through the transitions file//float_4*** read_trans_cc(int_4& num_trans_a, int_4*& num_states_a, char_1* trans_file_a) { // open file // FILE* fp = fopen((char*)trans_file_a, "r"); if (fp == (FILE*)NULL) { fprintf(stdout, "Cannot open file %s\n", trans_file_a); exit(ISIP_PROTO_ERROR); } // variables to read data // char_1* tmp = new char_1[ISIP_MAX_STRING_LENGTH]; int_4 num_states = (int_4)0; float_4*** trans_mat = (float_4***)NULL; logical_1 number_flag = ISIP_FALSE; // read data from file // while (fscanf(fp, "%s", tmp) != EOF) { // ignore comment lines // if (tmp[0] == (char_1)'#') { // do nothing // fscanf(fp, "%[^\n]", tmp); fscanf(fp, "%[\n]", tmp); } // read the transition matrix data // else if (strcmp((char*)tmp, (char*)BW_STR_NUM_TRANSITIONS) == 0) { // change the flag // number_flag = ISIP_TRUE; // read the number of transitions // fscanf(fp, "%s", tmp); fscanf(fp, "%ld", &num_trans_a); // allocate space for the tran list // trans_mat = new float_4**[num_trans_a]; // allocate space for num_states_a // num_states_a = new int_4[num_trans_a]; // now read the transitions data // for (int_4 i = 0; i < num_trans_a; i++) { // read the transition index and number of states // fscanf(fp, "%s%ld", tmp, &num_states); num_states_a[i] = num_states; // allocate memory for the data // trans_mat[i] = new float_4*[num_states]; for (int_4 j = 0; j < num_states; j++) { trans_mat[i][j] = new float_4[num_states]; // read the transitions // for (int_4 k = 0; k < num_states; k++) { fscanf(fp, "%f", &trans_mat[i][j][k]); // get the log score // if (trans_mat[i][j][k] == (float_4)0) { trans_mat[i][j][k] = MODEL_NOTRANS_SCORE; } else { trans_mat[i][j][k] = (float_4)log((float_8)trans_mat[i][j][k]); } } } } // end data loop } // end else if } // end while // check the flag // if (number_flag == ISIP_FALSE) { fprintf(stdout, "Error : no number of transitions specified in %s\n", (char*)trans_file_a); exit(ISIP_PROTO_ERROR); } // close file // fclose(fp); // free memory // delete [] tmp; // exit gracefully // return trans_mat;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -