/* * File: convert-mpi.c * Author: Mark Howison * * Description * ----------- * This program converts data stored in the Analyze 7.5 file format to * the H5Block file format. It can also scale the data by an integer * factor and add padding and chunking in all 3 dimensions. * * Created on Thu May 28 13:24:52 PDT 2009 */ #include #include #include #include #include #include #include #include "analyzeIO.h" #define H5_VERBOSITY 3 #define ONE_MEGABYTE 1048576 #define ERROR(msg,my_rank) do{\ fprintf (stderr, "rank %d: %s (%d): %s!\n",\ my_rank, __FILE__, __LINE__, msg);\ fflush (stderr);\ exit (EXIT_FAILURE);\ }while(0); int main (int argc, char** argv) { int i,j,k; int indx0,indx1; int ci,cj,ck; int sx,sy,sz; int px,py,pz; int x,y,z; int rank,nprocs; int decomp[3]; char chunk_str[64]; /* Analyze 7.5 */ int ndims; int dims[8]; int npts=0; int* tdims; float* pdims; int dType; int bytesPerVoxel; void* sd=NULL; char* infile; char* outfile; float* inData; /* H5Block */ H5PartFile* h5file; h5part_int64_t nelems; h5part_int64_t chunk[3]; h5part_int64_t slab[3]; h5part_int64_t start[3]; h5part_int64_t end[3]; h5part_float32_t* outData; MPI_Init (&argc, &argv); MPI_Comm_rank (MPI_COMM_WORLD, &rank); MPI_Comm_size (MPI_COMM_WORLD, &nprocs); if (argc < 12) { if (rank == 0) { printf ("Usage: ./convert-mpi "); printf ("input.hdr output.h5 sx sy sz px py pz cx cy cz\n"); printf ("\tsx,sy,sz = scaling factors\n"); printf ("\tpx,py,pz = padding\n"); printf ("\tcx,cy,cz = chunking\n"); } MPI_Finalize(); exit (EXIT_SUCCESS); } else { infile = argv[1]; outfile = argv[2]; sx = atoi (argv[3]); sy = atoi (argv[4]); sz = atoi (argv[5]); px = atoi (argv[6]); py = atoi (argv[7]); pz = atoi (argv[8]); chunk[0] = atoi(argv[9]); chunk[1] = atoi(argv[10]); chunk[2] = atoi(argv[11]); } if (chunk[0] <= 0 || chunk[1] <= 0 || chunk[2] <= 0) { ERROR("Invalid chunk dimensions: each must be > 0",rank); } H5PartSetVerbosityLevel(H5_VERBOSITY); /************************************************************************/ /* Read in the Analyze 7.5 data */ /************************************************************************/ printf ("Reading from Analyze 7.5 file %s\n", infile); analyzeLoadData (infile, &ndims, &tdims, &pdims, &dType, &bytesPerVoxel, &sd); for (i=0;i x - px) end[0] = x - px; if (end[1] > y - py) end[1] = y - py; if (end[2] > z - pz) end[2] = z - pz; if (rank == 0) printf("Creating chunks... "); nelems = chunk[0]*chunk[1]*chunk[2]; outData = (h5part_float32_t*) malloc(nelems*sizeof(h5part_float32_t)); if (!outData) { ERROR("Could not allocate memory for buffer",rank); } for (i=0;i