Ejemplo n.º 1
0
int
s3lambcnt_write(const char *fn,
		const uint32 *lambda_cnt,
		uint32 n_lambda_cnt)
{
    FILE *fp;
    uint32 chksum = 0;
    uint32 ignore = 0;

    s3clr_fattr();
    s3add_fattr("version", LAMBDACNT_FILE_VERSION, TRUE);
    s3add_fattr("chksum0", "yes", TRUE);


    fp = s3open(fn, "wb", NULL);
    if (fp == NULL)
	return S3_ERROR;

    if (s3write_1d((void *)lambda_cnt, sizeof(uint32), n_lambda_cnt, 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 [%u array]\n", fn, n_lambda_cnt);

    return S3_SUCCESS;
}
Ejemplo n.º 2
0
int
s3gau_write_full(const char *fn,
		 const vector_t ****out,
		 uint32 n_mgau,
		 uint32 n_feat,
		 uint32 n_density,
		 const uint32 *veclen)
{
    FILE *fp = NULL;
    uint32 chksum = 0;
    uint32 blk, i, ignore = 0;

    s3clr_fattr();
    s3add_fattr("version", GAU_FILE_VERSION, TRUE);
    s3add_fattr("chksum0", "yes", TRUE);

    fp = s3open(fn, "wb", NULL);
    if (fp == NULL)
	return S3_ERROR;

    if (bio_fwrite(&n_mgau, sizeof(uint32), 1, fp, 0, &chksum) != 1) {
	goto error;
    }

    if (bio_fwrite(&n_feat, sizeof(uint32), 1, fp, 0, &chksum) != 1) {
	goto error;
    }

    if (bio_fwrite(&n_density, sizeof(uint32), 1, fp, 0, &chksum) != 1) {
	goto error;
    }

    if (bio_fwrite(veclen, sizeof(uint32), n_feat, fp, 0, &chksum) != n_feat) {
	goto error;
    }

    for (blk = 0, i = 0; i < n_feat; i++)
	blk += veclen[i] * veclen[i];

    if (bio_fwrite_1d(out[0][0][0][0], sizeof(float32),
		   n_mgau*n_density*blk, fp, &chksum) < 0) {
	goto error;
    }

    if (bio_fwrite(&chksum, sizeof(uint32), 1, fp, 0, &ignore) != 1) {
	goto error;
    }

    s3close(fp);

    E_INFO("Wrote %s [%ux%ux%u array of full matrices]\n",
	   fn, n_mgau, n_feat, n_density);

    return S3_SUCCESS;

error:
    if (fp) s3close(fp);
    return S3_ERROR;
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
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;
}
static FILE *
open_dmp(const char *fn)
{
    FILE *fp;

    s3clr_fattr();
    fp = s3open(fn, "wb", NULL);
    if (fp == NULL) {
	E_ERROR_SYSTEM("Unable to open %s for writing.", fn);
    }

    return fp;
}
Ejemplo n.º 6
0
int
s3map_write(const char *fn,
	    void *map,
	    uint32 n_dom,
	    uint32 n_rng,
	    size_t map_elem_size)
{
    FILE *fp;
    uint32 chksum = 0;
    uint32 ignore = 0;

    s3clr_fattr();
    s3add_fattr("version", MAP_FILE_VERSION, TRUE);
    s3add_fattr("chksum0", "yes", TRUE);

    fp = s3open(fn, "wb", NULL);
    if (fp == NULL)
	return S3_ERROR;

    if (bio_fwrite(&n_rng, sizeof(uint32), 1, fp, &chksum) != 1) {
	s3close(fp);

	return S3_ERROR;
    }

    if (bio_fwrite_1d(map,
		   map_elem_size,
		   n_dom,
		   fp,
		   &chksum) < 0) {
	s3close(fp);

	return S3_ERROR;
    }

    if (bio_fwrite(&chksum, sizeof(uint32), 1, fp, &ignore) != 1) {
	s3close(fp);

	return S3_ERROR;
    }

    s3close(fp);

    E_INFO("Wrote %s [%u mappings to %u]\n", fn, n_dom, n_rng);

    return S3_SUCCESS;
}
int
s3regmatcnt_write(const char *fn,
		  float32 ****regr,
		  float32 *****regl,
		  uint32 n_class,
		  uint32 n_feat,
		  const uint32 *veclen,
		  uint32 mllr_mult,
		  uint32 mllr_add)
{
    FILE *fp;
    uint32 chksum = 0;
    uint32 ignore = 0;
    uint32 m, f;

    s3clr_fattr();
    s3add_fattr("version", REGMATCNT_FILE_VERSION, TRUE);
    s3add_fattr("chksum0", "yes", TRUE);

    fp = s3open(fn, "wb", NULL);
    if (fp == NULL)
	return S3_ERROR;


    if (s3write_1d((void *)veclen, sizeof(uint32), n_feat, fp, &chksum) != S3_SUCCESS) {
	return S3_ERROR;
    }

    if (s3write((void *)&n_class, sizeof(uint32), 1, fp, &chksum) != 1) {
	return S3_ERROR;
    }

    if (s3write((void *)&mllr_mult, sizeof(uint32), 1, fp, &chksum) != 1) {
	return S3_ERROR;
    }

    if (s3write((void *)&mllr_add, sizeof(uint32), 1, fp, &chksum) != 1) {
	return S3_ERROR;
    }

    for (m = 0; m < n_class; m++) {
	for (f = 0; f < n_feat; f++) {
	    if (s3write_3d((void ***)regl[m][f], sizeof(float32),
			   veclen[f], veclen[f]+1, veclen[f]+1, fp, &chksum) != S3_SUCCESS) {
		return S3_ERROR;
	    }
	    if (s3write_2d((void **)regr[m][f], sizeof(float32),
			   veclen[f], veclen[f]+1, fp, &chksum) != S3_SUCCESS) {
		return S3_ERROR;
	    }
	}
    }

    if (s3write(&chksum, sizeof(uint32), 1, fp, &ignore) != 1) {
	s3close(fp);

	return S3_ERROR;
    }
	
    s3close(fp);

    E_INFO("Wrote %s %u*%u regl and regl arrays.\n",
	   fn, n_class, n_feat);

    return S3_SUCCESS;
}
Ejemplo n.º 8
0
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;
}