/************************************************************************ * conv.c -- Sample data conversion program for ParVox. * * (C) Copyright 1998, California Institute of Technology * ALL RIGHTS RESERVED. * U.S. Government Sponsorship Acknowledged under NAS7-1260 * * Usage: conv infile outfile * * Output: outfile.vox.nc * * static char sccsid[] = "@(#)conv.c 1.2 3/27/98"; ************************************************************************/ #include #include #include #include #include "parvox.h" main(int argc, char** argv) { vlmeta_voxel4d v4d; float *next; int i, size; FILE *fdin; float min, max; /* * Fill in voxel data definitions. */ v4d.idim = 128; /* length of data */ v4d.jdim = 128; /* width of data */ v4d.kdim = 128; /* depth of data */ v4d.num_vars = 1; /* number of variables stored in data */ v4d.byte_per_voxel = 4; /* number of bytes per data point */ /* char = 1, short = 2, float = 4, etc. */ v4d.spacing.x = 1.0; /* relative gaps between data points */ v4d.spacing.y = 1.0; v4d.spacing.z = 1.0; v4d.nodata[0]=0.0; /* for multiple timesteps, add more intelligent code here */ v4d.time_tag = 1; /* name for the variable */ strncpy(v4d.var_name[0], "density", MAX_VAR_NAME - 1); /* * Read in original data and store in datablock. */ size = v4d.idim * v4d.jdim * v4d.kdim; /* allocate "size" of floats */ /* if not enough memory on t3d, need to do something smarter */ if(NULL == (v4d.voxel_data = (float *)malloc(size * sizeof(float)))) fprintf(stderr, "Error: Cannot malloc data space."); /* the maximum min and the minimum max values. Place holders. */ min = 99999; max = 0; next = v4d.voxel_data; /* read in voxel data */ if(!(fdin = fopen(argv[1], "r"))) { fprintf(stderr, "Cannot open input file %s.\n", argv[1]); exit(1); } fread(v4d.voxel_data, size, sizeof(float), fdin); for (i = 0; i < size; i++, next++) { if (*next <= -1.0) *next = 0; else *next = logf(1.0+*next); /* keep track of min and max so far */ if (*next < min) min = *next; if (*next > max) max = *next; } v4d.range[0][0] = min; /* min value for first (and only) variable */ v4d.range[0][1] = max; /* max value for first (and only) variable */ /* * Write to file. */ fprintf(stderr, "Convert %s to %s....\n", argv[1], argv[2]); fprintf(stderr, "Range: %f %f\n", min, max); vlmput_voxel4d(argv[2], &v4d); fclose(fdin); }