int _nrrdFieldCheck_old_max(const Nrrd *nrrd, int useBiff) { char me[]="_nrrdFieldCheck_old_max", err[BIFF_STRLEN]; int ret; if ((ret=airIsInf_d(nrrd->oldMax))) { sprintf(err, "%s: old max %sinf invalid", me, 1==ret ? "+" : "-"); biffMaybeAdd(NRRD, err, useBiff); return 1; } /* oldMin == oldMax is perfectly valid */ return 0; }
static int _nrrdFieldCheck_old_max(const Nrrd *nrrd, int useBiff) { static const char me[]="_nrrdFieldCheck_old_max"; int ret; if ((ret=airIsInf_d(nrrd->oldMax))) { biffMaybeAddf(useBiff, NRRD, "%s: old max %sinf invalid", me, 1==ret ? "+" : "-"); return 1; } /* oldMin == oldMax is perfectly valid */ return 0; }
int _nrrdFieldCheck_thicknesses(const Nrrd *nrrd, int useBiff) { char me[]="_nrrdFieldCheck_thicknesses", err[BIFF_STRLEN]; double val[NRRD_DIM_MAX]; unsigned int ai; nrrdAxisInfoGet_nva(nrrd, nrrdAxisInfoThickness, val); for (ai=0; ai<nrrd->dim; ai++) { /* note that unlike spacing, we allow zero thickness, but it makes no sense to be negative */ if (!( !airIsInf_d(val[ai]) && (airIsNaN(val[ai]) || (0 <= val[ai])) )) { sprintf(err, "%s: axis %d thickness (%g) invalid", me, ai, val[ai]); biffMaybeAdd(NRRD, err, useBiff); return 1; } } return 0; }
int _nrrdFieldCheck_spacings(const Nrrd *nrrd, int useBiff) { char me[]="_nrrdFieldCheck_spacings", err[BIFF_STRLEN]; double val[NRRD_DIM_MAX]; unsigned int ai; nrrdAxisInfoGet_nva(nrrd, nrrdAxisInfoSpacing, val); for (ai=0; ai<nrrd->dim; ai++) { if (!( !airIsInf_d(val[ai]) && (airIsNaN(val[ai]) || (0 != val[ai])) )) { sprintf(err, "%s: axis %d spacing (%g) invalid", me, ai, val[ai]); biffMaybeAdd(NRRD, err, useBiff); return 1; } } if (_nrrdFieldCheckSpaceInfo(nrrd, useBiff)) { sprintf(err, "%s: trouble", me); biffMaybeAdd(NRRD, err, useBiff); return 1; } return 0; }
static int _nrrdFieldCheck_axis_maxs(const Nrrd *nrrd, int useBiff) { static const char me[]="_nrrdFieldCheck_axis_maxs"; double val[NRRD_DIM_MAX]; unsigned int ai; int ret; nrrdAxisInfoGet_nva(nrrd, nrrdAxisInfoMax, val); for (ai=0; ai<nrrd->dim; ai++) { if ((ret=airIsInf_d(val[ai]))) { biffMaybeAddf(useBiff, NRRD, "%s: axis %d max %sinf invalid", me, ai, 1==ret ? "+" : "-"); return 1; } } if (_nrrdFieldCheckSpaceInfo(nrrd, useBiff)) { biffMaybeAddf(useBiff, NRRD, "%s: trouble", me); return 1; } /* HEY: contemplate checking min != max, but what about stub axes ... */ return 0; }
int _nrrdFieldCheck_axis_mins(const Nrrd *nrrd, int useBiff) { char me[]="_nrrdFieldCheck_axis_mins", err[BIFF_STRLEN]; double val[NRRD_DIM_MAX]; unsigned int ai; int ret; nrrdAxisInfoGet_nva(nrrd, nrrdAxisInfoMin, val); for (ai=0; ai<nrrd->dim; ai++) { if ((ret=airIsInf_d(val[ai]))) { sprintf(err, "%s: axis %d min %sinf invalid", me, ai, 1==ret ? "+" : "-"); biffMaybeAdd(NRRD, err, useBiff); return 1; } } if (_nrrdFieldCheckSpaceInfo(nrrd, useBiff)) { sprintf(err, "%s: trouble", me); biffMaybeAdd(NRRD, err, useBiff); return 1; } /* HEY: contemplate checking min != max, but what about stub axes ... */ return 0; }
int _nrrdSpaceVectorParse(double val[NRRD_SPACE_DIM_MAX], char **hhP, unsigned int spaceDim, int useBiff) { char me[]="_nrrdSpaceVectorParse", err[BIFF_STRLEN], *hh, *buff, sep[]=",)"; airArray *mop; unsigned int ret, dd, length; mop = airMopNew(); hh = *hhP; /* skip past space */ length = strspn(hh, _nrrdFieldSep); hh += length; /* make sure we have something */ if (!*hh) { sprintf(err, "%s: hit end of string before seeing (", me); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } /* first, see if we're getting the non-vector */ if ( (strstr(hh, _nrrdNoSpaceVector) == hh) ) { if (!hh[strlen(_nrrdNoSpaceVector)] || strchr(_nrrdFieldSep, hh[strlen(_nrrdNoSpaceVector)])) { /* yes, we got the non-vector */ for (dd=0; dd<spaceDim; dd++) { val[dd] = AIR_NAN; } length += strlen(_nrrdNoSpaceVector); } else { /* we got something that started out looking like the non-vector */ sprintf(err, "%s: couldn't parse non-vector \"%s\"", me, hh); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } } else { /* this isn't a non-vector */ /* make sure we have an open paren */ if ('(' != *hh) { sprintf(err, "%s: first vector in \"%s\" didn't start with '('", me, hh); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } /* copy string (including open paren) for local fiddling */ if (!(buff = airStrdup(hh))) { sprintf(err, "%s: couldn't allocate local buffer", me); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } airMopAdd(mop, buff, airFree, airMopAlways); /* scan for close paren */ hh = buff+1; while (*hh) { if (')' == *hh) { break; } else { hh++; } } if (')' != *hh) { sprintf(err, "%s: didn't see ')' at end of first vector in \"%s\"", me, hh); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } /* terminate at end paren */ *(hh+1) = 0; length += strlen(buff); /* see if we have too many fields */ ret = airStrntok(buff+1, sep); if (ret > spaceDim) { sprintf(err, "%s: space dimension is %d, but seem to have %d " "coefficients", me, spaceDim, ret); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } /* try to parse the values */ ret = airParseStrD(val, buff+1, ",", spaceDim); if (spaceDim != ret) { sprintf(err, "%s: parsed %d values, but space dimension is %d", me, ret, spaceDim); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } } /* probably not useful */ for (dd=spaceDim; dd<NRRD_SPACE_DIM_MAX; dd++) { val[dd] = AIR_NAN; } /* make sure all coefficients exist or not together */ for (dd=1; dd<spaceDim; dd++) { if (!!AIR_EXISTS(val[0]) ^ !!AIR_EXISTS(val[dd])) { sprintf(err, "%s: existance of all space vector coefficients must " "be consistent (val[0] not like val[%d])", me, dd); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } } for (dd=0; dd<spaceDim; dd++) { if (airIsInf_d(val[dd])) { sprintf(err, "%s: vector coefficient %d can't be infinite", me, dd); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } } *hhP += length; airMopOkay(mop); return 0; }