From: Gordon K. <kin...@us...> - 2005-05-05 16:59:19
|
Update of /cvsroot/teem/teem/src/unrrdu In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14214 Modified Files: dice.c Log Message: allowed user specification of filename sprintf format/template to allow direct control of number of digits used in filenames, as well as (implicitly) output file format, and, fixed apparent bug in action of -s flag Index: dice.c =================================================================== RCS file: /cvsroot/teem/teem/src/unrrdu/dice.c,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** dice.c 8 Apr 2005 20:31:07 -0000 1.30 --- dice.c 5 May 2005 16:58:52 -0000 1.31 *************** *** 27,36 **** ". Calls \"unu slice\" for each position " "along the indicated axis, and saves out a different " ! "nrrd for each position. "); int unrrdu_diceMain(int argc, char **argv, char *me, hestParm *hparm) { hestOpt *opt = NULL; ! char *base, out[512], *err, format[512]; Nrrd *nin, *nout; int pos, axis, top, pret, start, fit; --- 27,38 ---- ". Calls \"unu slice\" for each position " "along the indicated axis, and saves out a different " ! "file for each sample along that axis. "); int unrrdu_diceMain(int argc, char **argv, char *me, hestParm *hparm) { hestOpt *opt = NULL; ! char *base, *err, fnout[AIR_STRLEN_MED], /* file name out */ ! fffname[AIR_STRLEN_MED], /* format for filename */ ! *ftmpl; /* format template */ Nrrd *nin, *nout; int pos, axis, top, pret, start, fit; *************** *** 41,49 **** hestOptAdd(&opt, "s", "start", airTypeInt, 1, 1, &start, "0", "integer value to start numbering with"); hestOptAdd(&opt, "o", "prefix", airTypeString, 1, 1, &base, NULL, ! "output filename prefix. Output nrrds will be saved out as " ! "<prefix>00.nrrd, <prefix>01.nrrd, <prefix>02.nrrd, and so on " ! "(with \"-s\" option, numbering will be different). If this is a " ! "directory name, you probably want to end it with a \"/\"."); mop = airMopNew(); --- 43,58 ---- hestOptAdd(&opt, "s", "start", airTypeInt, 1, 1, &start, "0", "integer value to start numbering with"); + hestOptAdd(&opt, "ff", "form", airTypeString, 1, 1, &ftmpl, "", + "a printf-style format to use for generating all " + "filenames. Use this to override the number of characters " + "used to represent the slice position, or the file format " + "of the output, e.g. \"-ff %03.ppm\" for 000.ppm, " + "001.ppm, etc. By default (not using this option), slices " + "are saved in NRRD format (or PNM or PNG where possible) " + "with shortest possible filenames."); hestOptAdd(&opt, "o", "prefix", airTypeString, 1, 1, &base, NULL, ! "output filename prefix (excluding info set via \"-ff\"), " ! "basically to set path of output files (so be sure to end " ! "with \"/\"."); mop = airMopNew(); *************** *** 66,86 **** } ! top = start + nin->axis[axis].size-1; ! if (top > 9999999) ! sprintf(format, "%%s%%08d.nrrd"); ! else if (top > 999999) ! sprintf(format, "%%s%%07d.nrrd"); ! else if (top > 99999) ! sprintf(format, "%%s%%06d.nrrd"); ! else if (top > 9999) ! sprintf(format, "%%s%%05d.nrrd"); ! else if (top > 999) ! sprintf(format, "%%s%%04d.nrrd"); ! else if (top > 99) ! sprintf(format, "%%s%%03d.nrrd"); ! else if (top > 9) ! sprintf(format, "%%s%%02d.nrrd"); ! else ! sprintf(format, "%%s%%01d.nrrd"); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); --- 75,100 ---- } ! if (airStrlen(ftmpl)) { ! sprintf(fffname, "%%s%s", ftmpl); ! } else { ! top = start + nin->axis[axis].size-1; ! if (top > 9999999) { ! sprintf(fffname, "%%s%%08d.nrrd"); ! } else if (top > 999999) { ! sprintf(fffname, "%%s%%07d.nrrd"); ! } else if (top > 99999) { ! sprintf(fffname, "%%s%%06d.nrrd"); ! } else if (top > 9999) { ! sprintf(fffname, "%%s%%05d.nrrd"); ! } else if (top > 999) { ! sprintf(fffname, "%%s%%04d.nrrd"); ! } else if (top > 99) { ! sprintf(fffname, "%%s%%03d.nrrd"); ! } else if (top > 9) { ! sprintf(fffname, "%%s%%02d.nrrd"); ! } else { ! sprintf(fffname, "%%s%%01d.nrrd"); ! } ! } nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); *************** *** 93,116 **** return 1; } ! if (0 == pos) { /* See if these slices would be better saved as PNG or PNM images. Altering the file name will tell nrrdSave() to use a different file format. */ if (nrrdFormatPNG->fitsInto(nout, nrrdEncodingRaw, AIR_FALSE)) { ! strcpy(format + strlen(format) - 4, "png"); } else { fit = nrrdFormatPNM->fitsInto(nout, nrrdEncodingRaw, AIR_FALSE); if (2 == fit) { ! strcpy(format + strlen(format) - 4, "pgm"); } else if (3 == fit) { ! strcpy(format + strlen(format) - 4, "ppm"); } } } ! sprintf(out, format, base, pos+start); ! fprintf(stderr, "%s: %s ...\n", me, out); ! if (nrrdSave(out, nout, NULL)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); ! fprintf(stderr, "%s: error writing nrrd to \"%s\":%s\n", me, out, err); airMopError(mop); return 1; --- 107,131 ---- return 1; } ! if (0 == pos && !airStrlen(ftmpl)) { /* See if these slices would be better saved as PNG or PNM images. Altering the file name will tell nrrdSave() to use a different file format. */ if (nrrdFormatPNG->fitsInto(nout, nrrdEncodingRaw, AIR_FALSE)) { ! strcpy(fffname + strlen(fffname) - 4, "png"); } else { fit = nrrdFormatPNM->fitsInto(nout, nrrdEncodingRaw, AIR_FALSE); if (2 == fit) { ! strcpy(fffname + strlen(fffname) - 4, "pgm"); } else if (3 == fit) { ! strcpy(fffname + strlen(fffname) - 4, "ppm"); } } } ! sprintf(fnout, fffname, base, pos+start); ! fprintf(stderr, "%s: %s ...\n", me, fnout); ! if (nrrdSave(fnout, nout, NULL)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); ! fprintf(stderr, "%s: error writing nrrd to \"%s\":%s\n", ! me, fnout, err); airMopError(mop); return 1; |