예제 #1
0
int
main(int argc, char **argv) {
  char *me, *err, *key="strong bad", *value;
  Nrrd *nrrd;
  NrrdIoState *io;

  me = argv[0];
  if (2 != argc)
    usage(me);

  io = nrrdIoStateNew();
  nrrdStateVerboseIO = 10;
  
  if (nrrdLoad(nrrd=nrrdNew(), argv[1], NULL)) {
    fprintf(stderr, "%s: trouble loading \"%s\":\n%s", 
            me, argv[1], err = biffGetDone(NRRD));
    free(err);
    exit(1);
  }

  if ((value = nrrdKeyValueGet(nrrd, key))) {
    fprintf(stderr, "%s: '%s':='%s' (%d)\n", me, key, value, 
            (int)strlen(value));
  } else {
    fprintf(stderr, "%s: value not found for key: %s\n", me, key);
  }
  
  nrrdIoStateNix(io);
  nrrdNuke(nrrd);

  exit(0);
}
예제 #2
0
파일: txf.c 프로젝트: CIBC-Internal/teem
/*
** _miteStageSet
**
** ALLOCATES and initializes stage array in a miteThread
*/
int
_miteStageSet(miteThread *mtt, miteRender *mrr) {
  static const char me[]="_miteStageSet";
  char *value;
  int ni, di, stageIdx, rii, stageNum, ilog2;
  Nrrd *ntxf;
  miteStage *stage;
  gageItemSpec isp;
  char rc;

  stageNum = _miteStageNum(mrr);
  /* fprintf(stderr, "!%s: stageNum = %d\n", me, stageNum); */
  mtt->stage = AIR_CALLOC(stageNum, miteStage);
  if (!mtt->stage) {
    biffAddf(MITE, "%s: couldn't alloc array of %d stages", me, stageNum);
    return 1;
  }
  airMopAdd(mtt->rmop, mtt->stage, airFree, airMopAlways);
  mtt->stageNum = stageNum;
  stageIdx = 0;
  for (ni=0; ni<mrr->ntxfNum; ni++) {
    ntxf = mrr->ntxf[ni];
    for (di=ntxf->dim-1; di>=1; di--) {
      stage = mtt->stage + stageIdx;
      _miteStageInit(stage);
      miteVariableParse(&isp, ntxf->axis[di].label);
      stage->val = _miteAnswerPointer(mtt, &isp);
      stage->label = ntxf->axis[di].label;
      /*
      fprintf(stderr, "!%s: ans=%p + offset[%d]=%d == %p\n", me,
              mtt->ans, dom, kind->ansOffset[dom], stage->val);
      */
      stage->size = ntxf->axis[di].size;
      stage->min =  ntxf->axis[di].min;
      stage->max =  ntxf->axis[di].max;
      if (di > 1) {
        stage->data = NULL;
      } else {
        stage->data = (mite_t *)ntxf->data;
        value = nrrdKeyValueGet(ntxf, "miteStageOp");
        if (value) {
          stage->op = airEnumVal(miteStageOp, value);
          if (miteStageOpUnknown == stage->op) {
            stage->op = miteStageOpMultiply;
          }
        } else {
          stage->op = miteStageOpMultiply;
        }
        if (1 == isp.kind->table[isp.item].answerLength) {
          stage->qn = NULL;
        } else if (3 == isp.kind->table[isp.item].answerLength) {
          char stmp[AIR_STRLEN_SMALL];
          ilog2 = airLog2(ntxf->axis[di].size);
          switch(ilog2) {
          case 8:  stage->qn = limnVtoQN_d[ limnQN8octa]; break;
          case 9:  stage->qn = limnVtoQN_d[ limnQN9octa]; break;
          case 10: stage->qn = limnVtoQN_d[limnQN10octa]; break;
          case 11: stage->qn = limnVtoQN_d[limnQN11octa]; break;
          case 12: stage->qn = limnVtoQN_d[limnQN12octa]; break;
          case 13: stage->qn = limnVtoQN_d[limnQN13octa]; break;
          case 14: stage->qn = limnVtoQN_d[limnQN14octa]; break;
          case 15: stage->qn = limnVtoQN_d[limnQN15octa]; break;
          case 16: stage->qn = limnVtoQN_d[limnQN16octa]; break;
          default:
            biffAddf(MITE, "%s: txf axis %d size %s not usable for "
                     "vector txf domain variable %s", me, di,
                     airSprintSize_t(stmp, ntxf->axis[di].size),
                     ntxf->axis[di].label);
            return 1;
            break;
          }
        } else {
          biffAddf(MITE, "%s: %s not scalar or vector (len = %d): can't be "
                   "a txf domain variable", me,
                   ntxf->axis[di].label,
                   isp.kind->table[isp.item].answerLength);
          return 1;
        }
        stage->rangeNum = ntxf->axis[0].size;
        for (rii=0; rii<stage->rangeNum; rii++) {
          rc = ntxf->axis[0].label[rii];
          stage->rangeIdx[rii] = strchr(miteRangeChar, rc) - miteRangeChar;
          /*
          fprintf(stderr, "!%s: range: %c -> %d\n", "_miteStageSet",
                  ntxf->axis[0].label[rii], stage->rangeIdx[rii]);
          */
        }
      }
      stageIdx++;
    }
  }
  return 0;
}