int s3mixw_write(const char *fn, float32 ***mixw, uint32 n_mixw, uint32 n_feat, uint32 n_density) { FILE *fp; uint32 chksum = 0; uint32 ignore = 0; uint32 i, j, k; s3clr_fattr(); s3add_fattr("version", MIXW_FILE_VERSION, TRUE); s3add_fattr("chksum0", "yes", TRUE); fp = s3open(fn, "wb", NULL); if (fp == NULL) return S3_ERROR; for (i = 0; i < n_mixw; i++) { for (j = 0; j < n_feat; j++) { for (k = 0; k < n_density; k++) { if (mixw[i][j][k] < 0) { E_ERROR("mixw[%u][%u][%u] < 0 (%e)\n", i,j,k,mixw[i][j][k]); } } } } /* floor all non-zero entries to this value to make sure that results are compatible between machines */ floor_nz_3d(mixw, n_mixw, n_feat, n_density, MIN_POS_FLOAT32); if (bio_fwrite_3d((void ***)mixw, sizeof(float32), n_mixw, n_feat, n_density, fp, &chksum) < 0) { s3close(fp); return S3_ERROR; } if (bio_fwrite(&chksum, sizeof(uint32), 1, fp, 0, &ignore) != 1) { s3close(fp); return S3_ERROR; } s3close(fp); E_INFO("Wrote %s [%ux%ux%u array]\n", fn, n_mixw, n_feat, n_density); return S3_SUCCESS; }
int s3tmat_write(const char *fn, float32 ***tmat, uint32 n_tmat, uint32 n_state) { FILE *fp; uint32 chksum = 0; uint32 ignore = 0; int t, i, j; s3clr_fattr(); s3add_fattr("version", TMAT_FILE_VERSION, TRUE); s3add_fattr("chksum0", "yes", TRUE); fp = s3open(fn, "wb", NULL); if (fp == NULL) return S3_ERROR; for (t = 0; t < n_tmat; t++) { for (i = 0; i < n_state-1; i++) { for (j = 0; j < n_state; j++) { if (tmat[t][i][j] < 0) { E_ERROR("tmat[%u][%u][%u] < 0 (%e)\n", t, i, j, tmat[t][i][j]); } } } } /* floor all non-zero entries to this value to make sure that results are compatible between machines */ floor_nz_3d(tmat, n_tmat, n_state-1, n_state, MIN_POS_FLOAT32); if (s3write_3d((void ***)tmat, sizeof(float32), n_tmat, n_state-1, n_state, fp, &chksum) != S3_SUCCESS) { s3close(fp); return S3_ERROR; } if (s3write(&chksum, sizeof(uint32), 1, fp, &ignore) != 1) { s3close(fp); return S3_ERROR; } s3close(fp); E_INFO("Wrote %s [%ux%ux%u array]\n", fn, n_tmat, n_state-1, n_state); return S3_SUCCESS; }
int s3gaucnt_write_full(const char *fn, vector_t ***wt_mean, vector_t ****wt_var, int32 pass2var, float32 ***dnom, uint32 n_cb, uint32 n_feat, uint32 n_density, const uint32 *veclen) { FILE *fp; int32 chksum = 0; int32 ignore = 0; uint32 n_elem, blk, j, has_means, has_vars; s3clr_fattr(); s3add_fattr("version", GAUCNT_FILE_VERSION, TRUE); s3add_fattr("chksum0", "yes", TRUE); fp = s3open(fn, "wb", NULL); if (fp == NULL) return S3_ERROR; if (wt_mean != NULL) has_means = TRUE; else has_means = FALSE; if (bio_fwrite((void *)&has_means, sizeof(uint32), 1, fp, 0, &chksum) != 1) { return S3_ERROR; } if (wt_var != NULL) has_vars = TRUE; else has_vars = FALSE; if (bio_fwrite((void *)&has_vars, sizeof(uint32), 1, fp, 0, &chksum) != 1) { return S3_ERROR; } if (bio_fwrite((void *)&pass2var, sizeof(uint32), 1, fp, 0, &chksum) != 1) { return S3_ERROR; } if (bio_fwrite((void *)&n_cb, sizeof(uint32), 1, fp, 0, &chksum) != 1) { return S3_ERROR; } if (bio_fwrite((void *)&n_density, sizeof(uint32), 1, fp, 0, &chksum) != 1) { return S3_ERROR; } if (bio_fwrite_1d((void *)veclen, sizeof(uint32), n_feat, fp, &chksum) < 0) { return S3_ERROR; } for (j = 0, blk = 0; j < n_feat; j++) blk += veclen[j]; n_elem = n_cb * n_density * blk; if (has_means) { band_nz_1d(wt_mean[0][0][0], n_elem, MIN_POS_FLOAT32); if (bio_fwrite_1d((void *)wt_mean[0][0][0], sizeof(float32), n_elem, fp, &chksum) < 0) return S3_ERROR; } if (has_vars) { /* Don't floor full variances!!! */ if (bio_fwrite_1d((void *)wt_var[0][0][0][0], sizeof(float32), n_elem * blk, fp, &chksum) < 0) return S3_ERROR; } /* floor all non-zero entries to this value to make sure that results are compatible between machines */ floor_nz_3d(dnom, n_cb, n_feat, n_density, MIN_POS_FLOAT32); if (bio_fwrite_3d((void ***)dnom, sizeof(float32), n_cb, n_feat, n_density, fp, &chksum) < 0) { return S3_ERROR; } if (bio_fwrite(&chksum, sizeof(uint32), 1, fp, 0, &ignore) != 1) { s3close(fp); return S3_ERROR; } s3close(fp); E_INFO("Wrote %s%s%s%s [%ux%ux%u vector/matrix arrays]\n", fn, (has_means ? " with means" : ""), (has_vars ? " with full vars" : ""), (has_vars && pass2var ? " (2pass)" : ""), n_cb, n_feat, n_density); return S3_SUCCESS; }