/** * The idea behind oneLevelCoarser.c is to read a set of * volume data at uniform resolution and output a set of volume data * at a resolution that is 1 level coarser. We do this be selectively * removing every other scalar value along each of the x, y, and z * dimensions. We assume that the data is stored in x, y, z order. *
* @author Robert S Laramee
* @start date Tue 11 July 00
*/
#include
* Start the program using:
*
* @param argv[1] -the input data file name
* @param argv[2] -the number of data points along the x dimension
* @param argv[3] -the number of data points along the y dimension
* @param argv[4] -the number of data points along the z dimension
*/
int main(int argc , char *argv[]) {
FILE *inputFile;
char *inputFileName;
int totalOutput = 0;
/* check command line arguments */
if (argc != 5) {
fprintf(stderr, "*** Error, usage: oneLevelCoarser.exe [inputfile] "
"[x] [y] [z] > [output file]\n");
exit(1);
}
inputFileName = argv[1];
if ( !( inputFile = fopen(inputFileName,"rb"))){
printf("***Error, couldn't open input file: %s\n", inputFileName);
exit(1);
}
setLengthOfRows( atoi(argv[2]));
setHeightOfColumns(atoi(argv[3]));
setDepthOfLayers( atoi(argv[4]));
fprintf(stderr, "# main() input file is: %s\n", inputFileName);
fprintf(stderr, "# main() with x, y, z dimensions: %d, %d, %d\n",
getLengthOfRows(), getHeightOfColumns(), getDepthOfLayers());
totalOutput = outputCoarserVolume(inputFile);
if (fclose(inputFile)) {
fprintf(stderr, "***Error main(): closing input file \n");
} else {
fprintf(stderr, "# main(): closed input file \n");
}
fprintf(stderr, "# main(): output: %d scalars \n", totalOutput);
return 0;
}
/**
* This function outputs the coarser resolution volume data.
*
* @param inputFile a handle to the input file
*/
int outputCoarserVolume(FILE *inputFile) {
int debug = 0;
int z = 0;
int totalRead = 0;
int totalOutput = 0;
float layerOfData[getSizeOfLayer()];
if (debug == 1) fprintf(stdout, "# outputCoarserVolume()\n");
/** FOR EACH LAYER */
for (z = 0; z < getDepthOfLayers(); z++) {
/** read every layer */
totalRead = totalRead + readLayer(inputFile, layerOfData);
/** output every other layer (coarser) */
if ( (z % 2) == 0) {
totalOutput = totalOutput + outputCoarserLayer(layerOfData);
}
} /* end FOR EACH LAYER */
if (debug == 1) fprintf(stdout, "# outputCoarserVolume() returning: %d\n",
totalRead);
return totalOutput;
}
/**
* @param data the array to store the data in
* @return the total number of scalars output in that layer
*/
int outputCoarserLayer(float layerOfData[]) {
int debug = 0;
int y = 0;
int layerOffset = 0;
int totalOutput = 0;
if (debug == 1) fprintf(stderr, "# outputCoarserLayer() layer = \n");
if (debug == 1) printLayer(layerOfData);
/* FOR EACH ROW */
for (y = 0; y < getHeightOfColumns(); y++) {
/* index into every row */
layerOffset = y * getLengthOfRows();
/* output every other row (coarser) */
if ( (y % 2) == 0) {
totalOutput = totalOutput +
outputCoarserRow(layerOfData, layerOffset);
}
} /* end FOR EACH ROW */
if (debug == 2) fprintf(stdout, "\n");
return totalOutput;
}
/**
* @param data the array to store the data in
* @return the total number of scalars output in that row
*/
int outputCoarserRow(float layerOfData[], int layerOffset) {
int debug = 0;
int x = 0;
int numOutput = 0;
if (debug == 2) fprintf(stdout, "# outputCoarserRow() layerOffset = %d\n",
layerOffset);
/* FOR EACH ELEMENT in the ROW */
for (x = 0; x < getLengthOfRows(); x++) {
/* output every other scalar in the row */
if ( (x % 2) == 0) {
fprintf(stdout, "%f\n", layerOfData[layerOffset + x]);
numOutput++;
}
}
if (debug == 1) fprintf(stdout, "\n");
return numOutput;
}
/**
* @param inputFile a handle to the input file
* @param data the array to store the data in
*/
int readLayer(FILE *inputFile, float data[]) {
int i = 0;
for (i = 0; i < getSizeOfLayer(); i++) {
fscanf(inputFile, "%f", &data[i]);
}
return getSizeOfLayer();
}
/**
* @param layer a layer of data to print
*/
void printLayer(float layer[]) {
int x = 0;
int y = 0;
int offset = 0;
fprintf(stdout, "[ ");
/* FOR EACH COLUMN */
for (y = 0; y < getHeightOfColumns(); y++) {
offset = y * getLengthOfRows();
/* FOR EACH ROW */
for (x = 0; x < getLengthOfRows(); x++) {
fprintf(stdout, "%f ", layer[offset + x]);
} /* end FOR EACH ROW */
fprintf(stdout, "\n");
} /* end FOR EACH COLUMN */
fprintf(stdout, " ]\n");
}
* level number of sample points
* ----- -----------------------
* 7 2 x 2 x 2 ( 2^{0} + 1 )
* 6 3 x 3 x 3 ( 2^{1} + 1 )
* 5 5 x 5 x 5 ( 2^{2} + 1 )
* 4 9 x 9 x 9 ( 2^{3} + 1 )
* 3 17 x 17 x 17 ( 2^{4} + 1 )
* 2 33 x 33 x 33 ( 2^{5} + 1 )
* 1 65 x 65 x 65 ( 2^{6} + 1 )
* 0 129 x 129 x 129 ( 2^{7} + 1 )
*
* Compile the program using:
*
* % gcc -Wall oneLevelCoarser.c -Iinclude -lm -o oneLevelCoarser.exe
*
*
* % oneLevelCoarser.exe [input file] [x] [y] [z] > [output file]
* e.g.
* % oneLevelCoarser.exe ~rlaramee/data/level5/lev5testFloats.ascii \
* 5 5 5 > ~rlaramee/data/level6/lev6testFloats.ascii
*
*
*