|
From: Gordon K. <kin...@us...> - 2004-05-25 15:35:07
|
Update of /cvsroot/teem/teem/src/nrrd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25138 Modified Files: reorder.c Log Message: made sure that all biff error messages in a function are distinguishable added use of airMop's *whenever* there is local memory allocation enforced GK-standard use of "E" error flag variable rename (temp --> ntmp) error messsage re-arranging white-space games Index: reorder.c =================================================================== RCS file: /cvsroot/teem/teem/src/nrrd/reorder.c,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** reorder.c 20 May 2004 19:09:39 -0000 1.59 --- reorder.c 25 May 2004 15:34:57 -0000 1.60 *************** *** 1067,1077 **** ** fewer dimensions in the output nrrd than in the input nrrd. */ - int nrrdTile(Nrrd *nout, const Nrrd *nin, int ax1, int ax2, int axSplit, int sizeFast, int sizeSlow) { char me[]="nrrdTile", err[AIR_STRLEN_MED]; ! Nrrd *temp; int E, axis[NRRD_DIM_MAX], i, pindex, ax1merge, ax2merge; if (!(nout && nin)) { --- 1067,1077 ---- ** fewer dimensions in the output nrrd than in the input nrrd. */ int nrrdTile(Nrrd *nout, const Nrrd *nin, int ax1, int ax2, int axSplit, int sizeFast, int sizeSlow) { char me[]="nrrdTile", err[AIR_STRLEN_MED]; ! Nrrd *ntmp; int E, axis[NRRD_DIM_MAX], i, pindex, ax1merge, ax2merge; + airArray *mop; if (!(nout && nin)) { *************** *** 1084,1111 **** axis. */ if (ax1 == ax2) { ! sprintf(err, "%s: ax1(%d) cannot equal ax2(%d)", me, ax1, ax2); biffAdd(NRRD, err); return 1; } /* This is the temporary nrrd used for intermediate values. */ ! temp = nrrdNew(); ! if (!temp) { sprintf(err, "%s: failed to allocate temporary nrrd", me); biffAdd(NRRD, err); return 1; } /* Use _nrrdCopyShallow to just copy the header information without copying the data. */ ! E = _nrrdCopyShallow(temp, nin); /* Split the axis we will tile */ ! if (!E) E |= nrrdAxesSplit(temp, temp, axSplit, sizeFast, sizeSlow); /* We'll go ahead not and check for errors now as there is a lot of computation before the next nrrd call. */ if (E) { ! sprintf(err, "%s:", me); biffAdd(NRRD, err); ! nrrdNix(temp); return 1; } --- 1084,1115 ---- axis. */ if (ax1 == ax2) { ! sprintf(err, "%s: ax1 (%d) cannot equal ax2 (%d)", me, ax1, ax2); biffAdd(NRRD, err); return 1; } /* This is the temporary nrrd used for intermediate values. */ ! ntmp = nrrdNew(); ! if (!ntmp) { sprintf(err, "%s: failed to allocate temporary nrrd", me); biffAdd(NRRD, err); return 1; } + mop = airMopNew(); + airMopAdd(mop, ntmp, (airMopper)nrrdNix, airMopAlways); + /* Use _nrrdCopyShallow to just copy the header information without copying the data. */ ! E = AIR_FALSE; ! if (!E) E |= _nrrdCopyShallow(ntmp, nin); /* Split the axis we will tile */ ! if (!E) E |= nrrdAxesSplit(ntmp, ntmp, axSplit, sizeFast, sizeSlow); /* We'll go ahead not and check for errors now as there is a lot of computation before the next nrrd call. */ if (E) { ! sprintf(err, "%s: trouble with initial set-up", me); biffAdd(NRRD, err); ! airMopError(mop); return 1; } *************** *** 1113,1124 **** /* update ax1 and ax2. If the split axis was below ax1 or ax2 we need to increment them */ ! if (axSplit < ax1) ax1++; ! if (axSplit < ax2) ax2++; /******************************************************/ /* Permute the axis. This is the tricky part. */ ! /* This is the index used to write into axis. pindex is set to the next available spot in axis. After writing to it you need to --- 1117,1130 ---- /* update ax1 and ax2. If the split axis was below ax1 or ax2 we need to increment them */ ! if (axSplit < ax1) { ax1++; ! } ! if (axSplit < ax2) { ax2++; + } /******************************************************/ /* Permute the axis. This is the tricky part. */ ! /* This is the index used to write into axis. pindex is set to the next available spot in axis. After writing to it you need to *************** *** 1132,1136 **** /* The idea here is to loop over the input indicies. If the index is one of either ax1 or ax2 copy that index. */ ! for(i = 0; i < temp->dim; i++) { if (i == ax1) { axis[pindex] = i; --- 1138,1142 ---- /* The idea here is to loop over the input indicies. If the index is one of either ax1 or ax2 copy that index. */ ! for (i=0; i<ntmp->dim; i++) { if (i == ax1) { axis[pindex] = i; *************** *** 1156,1167 **** } /* ! for(i = 0; i < temp->dim; i++) { fprintf(stderr, "%s:axis[%d] = %d\n", me, i, axis[i]); } */ ! E = nrrdAxesPermute(nout, temp, axis); ! temp = nrrdNix(temp); ! /* Join the axis */ if (!E) { --- 1162,1172 ---- } /* ! for (i=0; i<ntmp->dim; i++) { fprintf(stderr, "%s:axis[%d] = %d\n", me, i, axis[i]); } */ ! if (!E) E |= nrrdAxesPermute(nout, ntmp, axis); ! /* Join the axis */ if (!E) { *************** *** 1177,1185 **** if (E) { ! sprintf(err, "%s:", me); biffAdd(NRRD, err); return 1; } return 0; } --- 1182,1192 ---- if (E) { ! sprintf(err, "%s: trouble", me); biffAdd(NRRD, err); + airMopError(mop); return 1; } + airMopOkay(mop); return 0; } *************** *** 1194,1203 **** ** nout->axis[axMerge].size == sizeFast*sizeSlow. */ - int nrrdUntile(Nrrd *nout, const Nrrd *nin, int ax1, int ax2, int axMerge, int sizeFast, int sizeSlow) { char me[]="nrrdUntile", err[AIR_STRLEN_MED]; int E, axis[NRRD_DIM_MAX], i, pindex, ax1sizeFast, ax2sizeFast; ! Nrrd *temp; if (!(nout && nin)) { --- 1201,1210 ---- ** nout->axis[axMerge].size == sizeFast*sizeSlow. */ int nrrdUntile(Nrrd *nout, const Nrrd *nin, int ax1, int ax2, int axMerge, int sizeFast, int sizeSlow) { char me[]="nrrdUntile", err[AIR_STRLEN_MED]; int E, axis[NRRD_DIM_MAX], i, pindex, ax1sizeFast, ax2sizeFast; ! Nrrd *ntmp; ! airArray *mop; if (!(nout && nin)) { *************** *** 1206,1226 **** } /* Check to make sure the values of ax1, ax2, and axMerge are valid. */ ! E = 0; if (ax1 >= nin->dim) { ! sprintf(err, "%s: ax1(%d) needs to be less than the number of dimensions (%d)", me, ax1, nin->dim); biffAdd(NRRD, err); ! E |= 1; } if (ax2 >= nin->dim) { ! sprintf(err, "%s: ax2(%d) needs to be less than the number of dimensions (%d)", me, ax2, nin->dim); biffAdd(NRRD, err); ! E |= 1; } if (axMerge > nin->dim) { ! sprintf(err, "%s: axMerge(%d) needs to be less than the number of dimensions + 1 (%d)", me, axMerge, nin->dim + 1); biffAdd(NRRD, err); ! E |= 1; } - if (E) return 1; /* Check the sizes of sizeFast and sizeSlow divide into ax1 --- 1213,1238 ---- } /* Check to make sure the values of ax1, ax2, and axMerge are valid. */ ! E = AIR_FALSE; if (ax1 >= nin->dim) { ! sprintf(err, "%s: ax1 (%d) needs to be < than # dimensions (%d)", ! me, ax1, nin->dim); biffAdd(NRRD, err); ! E |= AIR_TRUE; } if (ax2 >= nin->dim) { ! sprintf(err, "%s: ax2 (%d) needs to be < than # dimensions (%d)", ! me, ax2, nin->dim); biffAdd(NRRD, err); ! E |= AIR_TRUE; } if (axMerge > nin->dim) { ! sprintf(err, "%s: axMerge (%d) needs to be < than # dimensions + 1 (%d)", ! me, axMerge, nin->dim + 1); biffAdd(NRRD, err); ! E |= AIR_TRUE; ! } ! if (E) { ! return 1; } /* Check the sizes of sizeFast and sizeSlow divide into ax1 *************** *** 1229,1233 **** int ax1size = nin->axis[ax1].size; int ax2size = nin->axis[ax2].size; ! E = 0; ax1sizeFast = ax1size/sizeFast; if (ax1size != (sizeFast*ax1sizeFast)) { --- 1241,1246 ---- int ax1size = nin->axis[ax1].size; int ax2size = nin->axis[ax2].size; ! ! E = AIR_FALSE; ax1sizeFast = ax1size/sizeFast; if (ax1size != (sizeFast*ax1sizeFast)) { *************** *** 1235,1239 **** me, sizeFast, ax1size); biffAdd(NRRD, err); ! E |= 1; } ax2sizeFast = ax2size/sizeSlow; --- 1248,1252 ---- me, sizeFast, ax1size); biffAdd(NRRD, err); ! E |= AIR_TRUE; } ax2sizeFast = ax2size/sizeSlow; *************** *** 1242,1251 **** me, sizeSlow, ax2size); biffAdd(NRRD, err); ! E |= 1; } - if (E) return 1; } - /* ax1 and ax2 must not be equal. */ if (ax1 == ax2) { --- 1255,1265 ---- me, sizeSlow, ax2size); biffAdd(NRRD, err); ! E |= AIR_TRUE; ! } ! if (E) { ! return 1; } } /* ax1 and ax2 must not be equal. */ if (ax1 == ax2) { *************** *** 1255,1275 **** /* Make a shallow copy we can use to change axis information. */ ! temp = nrrdNew(); ! if (!temp) { sprintf(err, "%s: Error allocating temp nrrd", me); biffAdd(NRRD, err); return 1; } ! E = _nrrdCopyShallow(temp, nin); /* Now split the axes. Do the larger one first. */ if (ax1 < ax2) { ! if (!E) E |= nrrdAxesSplit(temp, temp, ax2, ax2sizeFast, sizeSlow); ! if (!E) E |= nrrdAxesSplit(temp, temp, ax1, ax1sizeFast, sizeFast); /* Increment the larger value as it will get shifted by the lower split. */ ax2++; } else { ! if (!E) E |= nrrdAxesSplit(temp, temp, ax1, ax1sizeFast, sizeFast); ! if (!E) E |= nrrdAxesSplit(temp, temp, ax2, ax2sizeFast, sizeSlow); ax1++; } --- 1269,1293 ---- /* Make a shallow copy we can use to change axis information. */ ! ntmp = nrrdNew(); ! if (!ntmp) { sprintf(err, "%s: Error allocating temp nrrd", me); biffAdd(NRRD, err); return 1; } ! mop = airMopNew(); ! airMopAdd(mop, ntmp, (airMopper)nrrdNix, airMopAlways); ! ! E = AIR_FALSE; ! if (!E) E |= _nrrdCopyShallow(ntmp, nin); /* Now split the axes. Do the larger one first. */ if (ax1 < ax2) { ! if (!E) E |= nrrdAxesSplit(ntmp, ntmp, ax2, ax2sizeFast, sizeSlow); ! if (!E) E |= nrrdAxesSplit(ntmp, ntmp, ax1, ax1sizeFast, sizeFast); /* Increment the larger value as it will get shifted by the lower split. */ ax2++; } else { ! if (!E) E |= nrrdAxesSplit(ntmp, ntmp, ax1, ax1sizeFast, sizeFast); ! if (!E) E |= nrrdAxesSplit(ntmp, ntmp, ax2, ax2sizeFast, sizeSlow); ax1++; } *************** *** 1277,1287 **** /* Bail if something went wrong. */ if (E) { ! sprintf(err, "%s:", me); ! biffAdd(NRRD, err); return 1; } /* Now determine the permutation of the axes. */ pindex = 0; ! for(i = 0; i < temp->dim; i++) { if (pindex == axMerge) { /* Insert the permuted axes. */ --- 1295,1305 ---- /* Bail if something went wrong. */ if (E) { ! sprintf(err, "%s: trouble with initial splitting", me); ! biffAdd(NRRD, err); airMopError(mop); return 1; } /* Now determine the permutation of the axes. */ pindex = 0; ! for (i=0; i<ntmp->dim; i++) { if (pindex == axMerge) { /* Insert the permuted axes. */ *************** *** 1298,1308 **** /* ! for(i = 0; i < temp->dim; i++) { fprintf(stderr, "%s:axis[%d] = %d\n", me, i, axis[i]); } */ ! E = nrrdAxesPermute(nout, temp, axis); ! temp = nrrdNix(temp); /* Join the axis */ --- 1316,1327 ---- /* ! for (i=0; i<ntmp->dim; i++) { fprintf(stderr, "%s:axis[%d] = %d\n", me, i, axis[i]); } */ ! E = AIR_FALSE; ! if (!E) E |= nrrdAxesPermute(nout, ntmp, axis); ! ntmp = nrrdNix(ntmp); /* Join the axis */ *************** *** 1310,1316 **** if (E) { ! sprintf(err, "%s:", me); ! biffAdd(NRRD, err); ! return 1; } --- 1329,1334 ---- if (E) { ! sprintf(err, "%s: trouble", me); ! biffAdd(NRRD, err); airMopError(mop); return 1; } |