示例#1
0
/*
** same as _meetHestGageKindParse below but without the DWI kind,
** which isn't const
*/
int
_meetHestConstGageKindParse(void *ptr, char *str, char err[AIR_STRLEN_HUGE]) {
  char me[] = "_meetHestGageConstKindParse";
  const gageKind **kindP;
  
  if (!(ptr && str)) {
    sprintf(err, "%s: got NULL pointer", me);
    return 1;
  }
  /* of course, the const correctness goes out the window with all
     the casting that's necessary with hest ... */
  kindP = (const gageKind **)ptr;
  *kindP = meetConstGageKindParse(str);
  if (!*kindP) {
    sprintf(err, "%s: \"%s\" not \"%s\", \"%s\", or \"%s\"", me, str,
            gageKindScl->name, gageKindVec->name,
            tenGageKind->name);
    return 1;
  }

  return 0;
}
示例#2
0
/*
******** meetPullVolParse
**
** parses a string to extract all the information necessary to create
** the pullVolume (this function originated in Deft/src/main-pull.c)
*/
int
meetPullVolParse(meetPullVol *mpv, const char *_str) {
  static const char me[]="meetPullVolParse";
#define VFMT_SHRT "<fileName>:<kind>:<volName>"
#define SFMT "<minScl>-<#smp>-<maxScl>[-no|u]"
#define VFMT_LONG "<fileName>:<kind>:" SFMT ":<volName>"
  char *str, *ctok, *clast=NULL, *dtok, *dlast=NULL;
  airArray *mop;
  int wantSS;

  if (!(mpv && _str)) {
    biffAddf(MEET, "%s: got NULL pointer", me);
    return 1;
  }
  if (!( str = airStrdup(_str) )) {
    biffAddf(MEET, "%s: couldn't strdup input", me);
    return 1;
  }

  mop = airMopNew();
  airMopAdd(mop, str, airFree, airMopAlways);
  if (!( 3 == airStrntok(str, ":") || 4 == airStrntok(str, ":") )) {
    biffAddf(MEET, "%s: didn't get 3 or 4 \":\"-separated tokens in \"%s\"; "
             "not of form " VFMT_SHRT " or " VFMT_LONG , me, _str);
    airMopError(mop); return 1;
  }
  /* mpv->nin is set elsewhere */
  wantSS = (4 == airStrntok(str, ":"));

  ctok = airStrtok(str, ":", &clast);
  if (!(mpv->fileName = airStrdup(ctok))) {
    biffAddf(MEET, "%s: couldn't strdup fileName", me);
    airMopError(mop); return 1;
  }
  airMopAdd(mop, &(mpv->fileName), (airMopper)airSetNull, airMopOnError);
  airMopAdd(mop, mpv->fileName, airFree, airMopOnError);
  ctok = airStrtok(NULL, ":", &clast);
  if (!(mpv->kind = meetConstGageKindParse(ctok))) {
    biffAddf(MEET, "%s: couldn't parse \"%s\" as kind", me, ctok);
    airMopError(mop); return 1;
  }
  if (wantSS) {
    int haveFlags;
    ctok = airStrtok(NULL, ":", &clast);
    if (!( 3 == airStrntok(ctok, "-") || 4 == airStrntok(ctok, "-") )) {
      biffAddf(MEET, "%s: didn't get 3 or 4 \"-\"-separated tokens in \"%s\"; "
               "not of form SFMT" , me, ctok);
      airMopError(mop); return 1;
    }
    haveFlags = (4 == airStrntok(ctok, "-"));
    dtok = airStrtok(ctok, "-", &dlast);
    if (1 != sscanf(dtok, "%lg", &(mpv->rangeSS[0]))) {
      biffAddf(MEET, "%s: couldn't parse \"%s\" as min scale", me, dtok);
      airMopError(mop); return 1;
    }
    dtok = airStrtok(NULL, "-", &dlast);
    if (1 != sscanf(dtok, "%u", &(mpv->numSS))) {
      biffAddf(MEET, "%s: couldn't parse \"%s\" as # scale samples", me, dtok);
      airMopError(mop); return 1;
    }
    if (!( mpv->numSS >= 2 )) {
      biffAddf(MEET, "%s: need # scale samples >= 2 (not %u)", me, mpv->numSS);
      airMopError(mop); return 1;
    }
    dtok = airStrtok(NULL, "-", &dlast);
    if (1 != sscanf(dtok, "%lg", &(mpv->rangeSS[1]))) {
      biffAddf(MEET, "%s: couldn't parse \"%s\" as max scale", me, dtok);
      airMopError(mop); return 1;
    }
    /* initialize things as if there were no flags */
    mpv->derivNormSS = AIR_FALSE;
    mpv->uniformSS = AIR_FALSE;
    mpv->optimSS = AIR_FALSE;
    mpv->derivNormBiasSS = 0.0;
    if (haveFlags) {
      char *flags, *bias;
      /* look for various things in flags */
      flags = airToLower(airStrdup(airStrtok(NULL, "-", &dlast)));
      airMopAdd(mop, flags, airFree, airMopAlways);
      if (strchr(flags, 'n')) {
        mpv->derivNormSS = AIR_TRUE;
      }
      if (strchr(flags, 'u')) {
        mpv->uniformSS = AIR_TRUE;
      }
      if (strchr(flags, 'o')) {
        mpv->optimSS = AIR_TRUE;
      }
      if (mpv->optimSS && mpv->uniformSS) {
        biffAddf(MEET, "%s: can't have both optimal ('o') and uniform ('u') "
                 "flags set in \"%s\"", me, flags);
        airMopError(mop); return 1;
      }
      if ((bias = strchr(flags, '+'))) {
        /* indicating a bias, unfortunately only a positive one is
           possible here, because of the way that other fields are
           tokenized by '-' */
        bias++;
        if (1 != sscanf(bias, "%lf", &(mpv->derivNormBiasSS))) {
          biffAddf(MEET, "%s: couldn't parse bias \"%s\"", me, bias);
          airMopError(mop); return 1;
        }
      }
    }
    /* mpv->ninSS and mpv->posSS are allocated and filled elsewhere */
    mpv->ninSS = NULL;
    mpv->posSS = NULL;
    /* we don't actually create nrrds nor load the volumes here,
       because we don't know cachePath, and because we might want
       different pullVolumes to share the same underlying Nrrds */
  } else {
    /* no scale-space stuff wanted */
    mpv->numSS = 0;
    mpv->rangeSS[0] = mpv->rangeSS[1] = AIR_NAN;
    mpv->ninSS = NULL;
    mpv->posSS = NULL;
  }
  ctok = airStrtok(NULL, ":", &clast);
  if (!(mpv->volName = airStrdup(ctok))) {
    biffAddf(MEET, "%s: couldn't strdup volName", me);
    airMopError(mop); return 1;
  }
  airMopAdd(mop, &(mpv->volName), (airMopper)airSetNull, airMopOnError);
  airMopAdd(mop, mpv->volName, airFree, airMopOnError);

  if (strchr(ctok, '-')) {
    biffAddf(MEET, "%s: you probably don't want \"-\" in volume name \"%s\"; "
             "forgot last \":\" in scale sampling specification?", me, ctok);
    airMopError(mop); return 1;
  }

  airMopOkay(mop);
  return 0;
}