dyv *mk_dyv_read( PFILE *f) { int i, size, lineno; double val; char line[101]; dyv *dv; lineno = 1; line[100] = '\0'; /* Read size and make dyv. */ if (pfeof(f)) { my_errorf( "mk_dyv_read: unexpected end-of-file while reading size,\n" "after line %d of file", lineno); } if (pfgets( line, 100, f) == NULL) { my_errorf( "mk_dyv_read: failed to read line %d from the passed stream.", lineno); } else lineno++; size = atoi( line); dv = mk_dyv( size); /* Read values. */ for (i=0; i<size; ++i) { if (pfeof(f)) { my_errorf( "mk_dyv_read: unexpected end-of-file while reading %d vals,\n" "after line %d of file (after the %dth value)", size, lineno, lineno-1); } if (pfgets( line, 100, f) == NULL) { my_errorf( "mk_dyv_read: failed to read line %d from the passed stream.", lineno); } else lineno++; val = atof( line); dyv_set( dv, i, val); } return dv; }
//parses the input file, runs phoneme tests and produces output to be parsed by perl script void doInputTestPhonemes(SR_Vocabulary *vocab, PFile* fin, FILE* fout) { #if 0 //waste of space with all of these arrays, they are too large, but leave for now ESR_ReturnCode rc; LCHAR line[2 * MAX_PRONS_LENGTH]; LCHAR phoneme[MAX_PRONS_LENGTH]; LCHAR* phrase; LCHAR* expectedPhoneme; LCHAR** tokenArray; size_t len; //read through the test file parsing it into the variables while(!pfeof(fin)) { pfgets(line, MAX_LINE_LENGTH, fin); rc = ESR_ProcessLinearToCommandLineTokens(line, &tokenArray, &len); if (rc!=ESR_SUCCESS || len!=2) { LFPRINTF(fout, "ERROR: INVALID FORMAT for input line\n"); continue; } phrase = tokenArray[0]; expectedPhoneme = tokenArray[1]; LPRINTF( "expected %s\n", expectedPhoneme); len = MAX_PRONS_LENGTH; rc = vocab->getPronunciation(vocab, phrase, phoneme, &len); if(rc != ESR_SUCCESS) LFPRINTF(fout,"ERROR: %s\n", ESR_rc2str(rc)); else { LFPRINTF(fout,"%s|%s|%s|", phrase, expectedPhoneme, phoneme); if(LSTRCMP(expectedPhoneme, phoneme) == 0) LFPRINTF(fout,"PASSED\n"); else LFPRINTF(fout,"FAILED\n"); } } #endif }
bool PStreamFile::isEndOfStream() { return pfeof(m_file); }
int init_newton_transform(preprocessed *prep, float reqscale, char *filename, int dimen) /* */ { int ii, jj; unsigned short matdim; double scale, onerow[MAX_DIMEN]; PFile* dfpt; long foffset; double xfp; /* Open file */ ASSERT(prep); ASSERT(filename); dfpt = file_must_open(NULL, filename, ("rb"), ESR_TRUE); prep->post_proc |= LIN_TRAN; prep->use_dim = dimen; pfread(&matdim, sizeof(short), 1, dfpt); if (matdim > MAX_DIMEN) SERVICE_ERROR(BAD_IMELDA); create_linear_transform(prep, matdim, 1); pfread(&scale, sizeof(double), 1, dfpt); if (reqscale != 0) scale = reqscale; #if DEBUG PLogMessage("L: LDA Suggested scale is %.1f\n", scale); #endif if (!prep->dim) prep->dim = matdim; else if (prep->dim != matdim) { log_report("Data (%d) and LDA (%d) dimensions don't match\n", prep->dim, matdim); SERVICE_ERROR(BAD_IMELDA); } /* Eigenvalues, ignored */ pfread(onerow, sizeof(double), matdim, dfpt); /* Translation Vector */ pfread(onerow, sizeof(double), matdim, dfpt); for (ii = 0; ii < matdim; ii++) { xfp = scale * (onerow[ii] - UTB_MEAN) + UTB_MEAN; if (xfp > 0.0) xfp += 0.5; else if (xfp < 0.0) xfp -= 0.5; prep->offset[ii] = (imeldata) xfp; } /* The imelda matrix */ for (ii = 0; ii < matdim; ii++) { pfread(onerow, sizeof(double), matdim, dfpt); for (jj = 0; jj < matdim; jj++) prep->imelda[ii][jj] = (covdata)(scale * onerow[jj]); } prep->imel_shift = scale_matrix_for_fixedpoint(prep->matrix, prep->imelda, matdim); /* The inverse imelda matrix */ foffset = pftell(dfpt); pfread(onerow, sizeof(double), matdim, dfpt); if (pfeof(dfpt) != 0) { #ifdef SREC_ENGINE_VERBOSE_LOGGING PLogMessage("W: Inverting imelda matrix"); #endif invert_matrix(prep->imelda, prep->inverse, prep->dim); } else { pfseek(dfpt, foffset, SEEK_SET); for (ii = 0; ii < matdim; ii++) { pfread(onerow, sizeof(double), matdim, dfpt); for (jj = 0; jj < matdim; jj++) prep->inverse[ii][jj] = (covdata)(onerow[jj] / scale); } } prep->inv_shift = scale_matrix_for_fixedpoint(prep->invmat, prep->inverse, matdim); pfclose(dfpt); return (0); }