From: Gordon K. <kin...@us...> - 2005-01-24 01:09:56
|
Update of /cvsroot/teem/teem/src/unrrdu In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5486 Modified Files: make.c Log Message: can now specify per-axis kinds, per-axis centerings, and per-coefficient space units Index: make.c =================================================================== RCS file: /cvsroot/teem/teem/src/unrrdu/make.c,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** make.c 23 Jan 2005 22:57:10 -0000 1.61 --- make.c 24 Jan 2005 01:09:45 -0000 1.62 *************** *** 22,32 **** #include "privateUnrrdu.h" ! /* bad Gordon */ ! extern int _nrrdReadNrrdParse_keyvalue(Nrrd *nrrd, NrrdIoState *io, ! int useBiff); ! extern int _nrrdReadNrrdParse_space_origin(Nrrd *nrrd, NrrdIoState *io, ! int useBiff); ! extern int _nrrdReadNrrdParse_space_directions(Nrrd *nrrd, NrrdIoState *io, ! int useBiff); #define INFO "Create a nrrd (or nrrd header) from scratch" --- 22,26 ---- #include "privateUnrrdu.h" ! #define NO_STRING "." #define INFO "Create a nrrd (or nrrd header) from scratch" *************** *** 39,43 **** "or to save to disk. However, with \"-h\", this creates " "only a detached nrrd header file, without ever reading " ! "or writing data. When reading multiple files, each file must contain " "the data for one slice along the slowest axis. Nearly all the options " "below refer to the finished nrrd resulting from joining all the slices " --- 33,38 ---- "or to save to disk. However, with \"-h\", this creates " "only a detached nrrd header file, without ever reading " ! "or writing data. \n \n " ! "When reading multiple files, each file must contain " "the data for one slice along the slowest axis. Nearly all the options " "below refer to the finished nrrd resulting from joining all the slices " *************** *** 45,49 **** "to every input slice file. When reading data from many seperate files, it " "may be easier to put their filenames in a response file; there can be one " ! "or more filenames per line of the response file. "); int --- 40,50 ---- "to every input slice file. When reading data from many seperate files, it " "may be easier to put their filenames in a response file; there can be one " ! "or more filenames per line of the response file. \n \n " ! "NOTE: for the \"-l\" (labels), \"-u\" (units), and \"-spu\" (space units) " ! "options below, you can use a single unquoted period (\".\") to signify " ! "an empty string. This creates a convenient way to convey something that " ! "the shell doesn't make it easy to convey. Shell expansion weirdness " ! "also requires the use of quotes around the arguments to \"-orig\" (space " ! "origin) and \"-dirs\" (space directions)."); int *************** *** 90,101 **** int *size, sizeLen, buflen, nameLen, kvpLen, ii, spacingLen, thicknessLen, labelLen, unitsLen, ! headerOnly, pret, lineSkip, byteSkip, endian, slc, type, encodingType, gotSpacing, gotThickness, space, spaceDim, kindsLen, ! centeringsLen; double *spacing, *thickness; airArray *mop; NrrdIoState *nio; FILE *fileOut; ! char **label, **units, **kinds, **centerings, *parseBuf, *spcStr, *_origStr, *origStr, *_dirStr, *dirStr; const NrrdEncoding *encoding; --- 91,102 ---- int *size, sizeLen, buflen, nameLen, kvpLen, ii, spacingLen, thicknessLen, labelLen, unitsLen, ! spunitsLen, headerOnly, pret, lineSkip, byteSkip, endian, slc, type, encodingType, gotSpacing, gotThickness, space, spaceDim, kindsLen, ! centeringsLen, spaceSet; double *spacing, *thickness; airArray *mop; NrrdIoState *nio; FILE *fileOut; ! char **label, **units, **spunits, **kinds, **centerings, *parseBuf, *spcStr, *_origStr, *origStr, *_dirStr, *dirStr; const NrrdEncoding *encoding; *************** *** 143,150 **** "what \"kind\" is each axis, from the nrrdKind airEnum " "(e.g. space, time, 3-vector, 3D-masked-symmetric-matrix, " ! "or ??? to signify no kind)", &kindsLen); hestOptAdd(&opt, "cn", "cent0 cent1", airTypeString, 1, -1, ¢erings, "", "kind of centering (node or cell) for each axis, or " ! "??? to signify no centering", ¢eringsLen); hestOptAdd(&opt, "l", "lb0 lb1", airTypeString, 1, -1, &label, "", "short string labels for each of the axes", &labelLen); --- 144,151 ---- "what \"kind\" is each axis, from the nrrdKind airEnum " "(e.g. space, time, 3-vector, 3D-masked-symmetric-matrix, " ! "or \"none\" to signify no kind)", &kindsLen); hestOptAdd(&opt, "cn", "cent0 cent1", airTypeString, 1, -1, ¢erings, "", "kind of centering (node or cell) for each axis, or " ! "\"none\" to signify no centering", ¢eringsLen); hestOptAdd(&opt, "l", "lb0 lb1", airTypeString, 1, -1, &label, "", "short string labels for each of the axes", &labelLen); *************** *** 211,214 **** --- 212,218 ---- "around vector list (not individually) is needed because of " "limitations in the parser."); + hestOptAdd(&opt, "spu", "spu0 spu1", airTypeString, 1, -1, &spunits, "", + "short strings giving units with which the coefficients of the " + "space origin and direction vectors are measured.", &spunitsLen); OPT_ADD_NOUT(out, "output filename"); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); *************** *** 220,223 **** --- 224,238 ---- encoding = nrrdEncodingArray[encodingType]; + + /******************************************************************** + ******************************************************************** + It is no secret that this code is awful and needs a re-write. + The deficiencies have nearly everything to do with hest, though, + and little to do with nrrd itself, except that having a + nrrdMake() function would probably simplify the following... + ******************************************************************** + ********************************************************************/ + + /* given the information we have, we set the fields in the nrrdIoState so as to simulate having read the information from a header */ *************** *** 232,237 **** if (gotSpacing && spacingLen != sizeLen) { fprintf(stderr, ! "%s: got different numbers of sizes (%d) and spacings (%d)\n", ! me, sizeLen, spacingLen); airMopError(mop); return 1; --- 247,252 ---- if (gotSpacing && spacingLen != sizeLen) { fprintf(stderr, ! "%s: number of spacings (%d) not same as dimension (%d)\n", ! me, spacingLen, sizeLen); airMopError(mop); return 1; *************** *** 241,246 **** if (gotThickness && thicknessLen != sizeLen) { fprintf(stderr, ! "%s: got different numbers of sizes (%d) and thicknesses (%d)\n", ! me, sizeLen, thicknessLen); airMopError(mop); return 1; --- 256,261 ---- if (gotThickness && thicknessLen != sizeLen) { fprintf(stderr, ! "%s: number of thicknesses (%d) not same as dimension (%d)\n", ! me, thicknessLen, sizeLen); airMopError(mop); return 1; *************** *** 248,253 **** if (airStrlen(label[0]) && sizeLen != labelLen) { fprintf(stderr, ! "%s: got different numbers of sizes (%d) and labels (%d)\n", ! me, sizeLen, labelLen); airMopError(mop); return 1; --- 263,268 ---- if (airStrlen(label[0]) && sizeLen != labelLen) { fprintf(stderr, ! "%s: number of labels (%d) not same as dimension (%d)\n", ! me, labelLen, sizeLen); airMopError(mop); return 1; *************** *** 255,260 **** if (airStrlen(units[0]) && sizeLen != unitsLen) { fprintf(stderr, ! "%s: got different numbers of sizes (%d) and units (%d)\n", ! me, sizeLen, unitsLen); airMopError(mop); return 1; --- 270,275 ---- if (airStrlen(units[0]) && sizeLen != unitsLen) { fprintf(stderr, ! "%s: number of units (%d) not same as dimension (%d)\n", ! me, unitsLen, sizeLen); airMopError(mop); return 1; *************** *** 262,267 **** if (airStrlen(kinds[0]) && sizeLen != kindsLen) { fprintf(stderr, ! "%s: got different numbers of sizes (%d) and kinds (%d)\n", ! me, sizeLen, kindsLen); airMopError(mop); return 1; --- 277,282 ---- if (airStrlen(kinds[0]) && sizeLen != kindsLen) { fprintf(stderr, ! "%s: number of kinds (%d) not same as dimension (%d)\n", ! me, kindsLen, sizeLen); airMopError(mop); return 1; *************** *** 269,274 **** if (airStrlen(centerings[0]) && sizeLen != centeringsLen) { fprintf(stderr, ! "%s: got different numbers of sizes (%d) and centerings (%d)\n", ! me, sizeLen, centeringsLen); airMopError(mop); return 1; --- 284,289 ---- if (airStrlen(centerings[0]) && sizeLen != centeringsLen) { fprintf(stderr, ! "%s: number of centerings (%d) not same as dimension (%d)\n", ! me, centeringsLen, sizeLen); airMopError(mop); return 1; *************** *** 290,296 **** --- 305,321 ---- } if (airStrlen(label[0])) { + for (ii=0; ii<nrrd->dim; ii++) { + if (!strcmp(NO_STRING, label[ii])) { + strcpy(label[ii], ""); + } + } nrrdAxisInfoSet_nva(nrrd, nrrdAxisInfoLabel, label); } if (airStrlen(units[0])) { + for (ii=0; ii<nrrd->dim; ii++) { + if (!strcmp(NO_STRING, units[ii])) { + strcpy(units[ii], ""); + } + } nrrdAxisInfoSet_nva(nrrd, nrrdAxisInfoUnits, units); } *************** *** 324,328 **** buflen += 1; parseBuf = calloc(buflen, sizeof(char)); - fprintf(stderr, "!%s: buflen = %d\n", me, buflen); airMopAdd(mop, parseBuf, airFree, airMopAlways); strcpy(parseBuf, ""); --- 349,352 ---- *************** *** 333,337 **** strcat(parseBuf, kinds[ii]); } - fprintf(stderr, "!%s: parseBuf = |%s|\n", me, parseBuf); nio->line = parseBuf; nio->pos = 0; --- 357,360 ---- *************** *** 360,364 **** strcat(parseBuf, centerings[ii]); } - fprintf(stderr, "!%s: parseBuf = |%s|\n", me, parseBuf); nio->line = parseBuf; nio->pos = 0; --- 383,386 ---- *************** *** 387,393 **** --- 409,417 ---- nrrdSpaceSet(nrrd, space); } + spaceSet = AIR_TRUE; } else { /* we got no space information at all */ nrrdSpaceSet(nrrd, nrrdSpaceUnknown); + spaceSet = AIR_FALSE; } if (airStrlen(_origStr)) { *************** *** 431,435 **** nio->line = NULL; } ! fprintf(stderr, "!%s: bingo 5 \n", me); if (_nrrdCheck(nrrd, AIR_FALSE)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); --- 455,503 ---- nio->line = NULL; } ! if (airStrlen(spunits[0])) { ! if (!spaceSet) { ! fprintf(stderr, "%s: can't have space units with no space set\n", me); ! airMopError(mop); return 1; ! } ! if (nrrd->spaceDim != spunitsLen) { ! fprintf(stderr, ! "%s: number of space units (%d) " ! "not same as space dimension (%d)\n", ! me, spunitsLen, nrrd->spaceDim); ! airMopError(mop); ! return 1; ! } ! for (ii=0; ii<nrrd->spaceDim; ii++) { ! if (!strcmp(NO_STRING, spunits[ii])) { ! strcpy(spunits[ii], ""); ! } ! } ! /* have to allocate line then pass it to parsing */ ! buflen = 0; ! for (ii=0; ii<sizeLen; ii++) { ! buflen += (!ii ? 0 : airStrlen("\"\" ")) + airStrlen(spunits[ii]); ! } ! buflen += 1; ! parseBuf = calloc(buflen, sizeof(char)); ! airMopAdd(mop, parseBuf, airFree, airMopAlways); ! strcpy(parseBuf, ""); ! for (ii=0; ii<nrrd->spaceDim; ii++) { ! if (ii) { ! strcat(parseBuf, " "); ! } ! strcat(parseBuf, "\""); ! strcat(parseBuf, spunits[ii]); ! strcat(parseBuf, "\""); ! } ! nio->line = parseBuf; ! nio->pos = 0; ! if (nrrdFieldInfoParse[nrrdField_space_units](nrrd, nio, AIR_TRUE)) { ! airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); ! fprintf(stderr, "%s: trouble with space units \"%s\":\n%s", ! me, parseBuf, err); ! nio->line = NULL; airMopError(mop); return 1; ! } ! nio->line = NULL; ! } if (_nrrdCheck(nrrd, AIR_FALSE)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); *************** *** 437,441 **** airMopError(mop); return 1; } - fprintf(stderr, "!%s: bingo 6\n", me); if (headerOnly) { --- 505,508 ---- *************** *** 471,475 **** nrrdFormatNRRD->write(fileOut, nrrd, nio); } else { - fprintf(stderr, "!%s: bingo 7\n", me); /* we're not actually using the handy unrrduHestFileCB, since we have to open the input data file by hand */ --- 538,541 ---- *************** *** 547,557 **** nrrdSwapEndian(nrrd); } - fprintf(stderr, "!%s: bingo 8\n", me); /* we are saving normally- no need to subvert nrrdSave() here; we just pass it the output filename */ SAVE(out, nrrd, NULL); - fprintf(stderr, "!%s: bingo 9\n", me); } - fprintf(stderr, "!%s: bingo 10\n", me); airMopOkay(mop); --- 613,620 ---- |