/* ******** airArrayNew() ** ** creates a new airArray struct and returns a pointer to it. ** dataP is a pointer to the user's data pointer ** lenP is a pointer to the user's array length variable (optional) ** unit is the size (in bytes) of one element in the array ** incr is the number of units by which the array will grow or shrink ** ** returns NULL on error, or the new airArray pointer if okay ** errors: bogus arguments, or couldn't alloc airArray struct ** ** --> The user CAN NOT change the pointer variable (of which *dataP ** is the address) after this is called, or else everything will ** get all bolloxed up. The same goes for the array length ** variable, if its address is passed- though in that case the ** correct value will over-write any other. */ airArray * airArrayNew(void **dataP, unsigned int *lenP, size_t unit, unsigned int incr) { airArray *a; if (unit<=0 || incr<=0) { return NULL; } a = AIR_CALLOC(1, airArray); if (!a) { return NULL; } a->dataP = dataP; _airSetData(a, NULL); a->lenP = lenP; _airLenSet(a, 0); a->incr = incr; a->unit = unit; a->noReallocWhenSmaller = AIR_FALSE; a->allocCB = NULL; a->freeCB = NULL; a->initCB = NULL; a->doneCB = NULL; return a; }
airThreadMutex * airThreadMutexNew(void) { airThreadMutex *mutex; mutex = AIR_CALLOC(1, airThreadMutex); return mutex; }
airThreadCond * airThreadCondNew(void) { airThreadCond *cond; cond = AIR_CALLOC(1, airThreadCond); return cond; }
hestParm * hestParmNew() { hestParm *parm; parm = AIR_CALLOC(1, hestParm); if (parm) { parm->verbosity = hestVerbosity; parm->respFileEnable = hestRespFileEnable; parm->elideSingleEnumType = hestElideSingleEnumType; parm->elideSingleOtherType = hestElideSingleOtherType; parm->elideSingleOtherDefault = hestElideSingleOtherDefault; parm->greedySingleString = hestGreedySingleString; parm->elideSingleNonExistFloatDefault = hestElideSingleNonExistFloatDefault; parm->elideMultipleNonExistFloatDefault = hestElideMultipleNonExistFloatDefault; parm->elideSingleEmptyStringDefault = hestElideSingleEmptyStringDefault; parm->elideMultipleEmptyStringDefault = hestElideMultipleEmptyStringDefault; parm->cleverPluralizeOtherY = hestCleverPluralizeOtherY; parm->columns = hestColumns; parm->respFileFlag = hestRespFileFlag; parm->respFileComment = hestRespFileComment; parm->varParamStopFlag = hestVarParamStopFlag; parm->multiFlagSep = hestMultiFlagSep; } return parm; }
biffMsg * biffMsgNew(const char *key) { static const char me[]="biffMsgNew"; biffMsg *msg; if (!key) { fprintf(stderr, "%s: PANIC got NULL key\n", me); return NULL; /* exit(1); */ } msg = AIR_CALLOC(1, biffMsg); if (msg) { airPtrPtrUnion appu; msg->key = airStrdup(key); msg->err = NULL; msg->errNum = 0; appu.cp = &(msg->err); msg->errArr = airArrayNew(appu.v, &(msg->errNum), sizeof(char*), _MSG_INCR); if (msg->errArr) { airArrayPointerCB(msg->errArr, NULL, airFree); } } if (!( msg && msg->key && msg->errArr )) { fprintf(stderr, "%s: PANIC couldn't calloc new msg\n", me); return NULL; /* exit(1); */ } return msg; }
airThread * airThreadNew(void) { airThread *thread; thread = AIR_CALLOC(1, airThread); /* HEY: not sure if this can be usefully initialized */ return thread; }
airThread * airThreadNew(void) { airThread *thread; thread = AIR_CALLOC(1, airThread); thread->ret = NULL; return thread; }
airThread * airThreadNew(void) { airThread *thread; thread = AIR_CALLOC(1, airThread); /* HEY: any useful way to initialized a HANDLE? */ thread->handle = NULL; thread->body = NULL; thread->arg = thread->ret = NULL; return thread; }
tenExperSpec* tenExperSpecNew(void) { tenExperSpec* espec; espec = AIR_CALLOC(1, tenExperSpec); espec->set = AIR_FALSE; espec->imgNum = 0; espec->bval = NULL; espec->grad = NULL; /* espec->wght = NULL; */ return espec; }
rvaLattSpec * rvaLattSpecNew(void) { rvaLattSpec *lsp; unsigned int pi; lsp = AIR_CALLOC(1, rvaLattSpec); lsp->latt = rvaLattUnknown; for (pi=0; pi<RVA_LATT_PARM_NUM; pi++) { lsp->parm[pi] = AIR_NAN; } return lsp; }
airThreadMutex * airThreadMutexNew() { airThreadMutex *mutex; mutex = AIR_CALLOC(1, airThreadMutex); if (mutex) { if (!(mutex->handle = CreateMutex(NULL, FALSE, NULL))) { return airFree(mutex); } } return mutex; }
airThreadMutex * airThreadMutexNew(void) { airThreadMutex *mutex; mutex = AIR_CALLOC(1, airThreadMutex); if (mutex) { if (pthread_mutex_init(&(mutex->id), NULL)) { mutex = (airThreadMutex *)airFree(mutex); } } return mutex; }
airThreadCond * airThreadCondNew(void) { airThreadCond *cond; cond = AIR_CALLOC(1, airThreadCond); if (cond) { if (pthread_cond_init(&(cond->id), NULL)) { /* there was an error */ cond = (airThreadCond *)airFree(cond); } } return cond; }
meetPullVol * meetPullVolNew(void) { meetPullVol *ret; ret = AIR_CALLOC(1, meetPullVol); if (ret) { ret->kind = NULL; ret->fileName = ret->volName = NULL; ret->sbp = NULL; ret->leeching = AIR_FALSE; ret->derivNormSS = AIR_FALSE; ret->recomputedSS = AIR_FALSE; ret->derivNormBiasSS = 0.0; ret->nin = NULL; ret->ninSS = NULL; } return ret; }
airThreadBarrier * airThreadBarrierNew(unsigned int numUsers) { airThreadBarrier *barrier; barrier = AIR_CALLOC(1, airThreadBarrier); if (barrier) { barrier->numUsers = numUsers; barrier->numDone = 0; if (!(barrier->doneMutex = airThreadMutexNew())) { airFree(barrier); return NULL; } if (!(barrier->doneCond = airThreadCondNew())) { barrier->doneMutex = airThreadMutexNix(barrier->doneMutex); airFree(barrier); return NULL; } } return barrier; }
meetPullVol * meetPullVolNew(void) { meetPullVol *ret; ret = AIR_CALLOC(1, meetPullVol); if (ret) { ret->kind = NULL; ret->fileName = ret->volName = NULL; ret->derivNormSS = AIR_FALSE; ret->uniformSS = AIR_FALSE; ret->optimSS = AIR_FALSE; ret->leeching = AIR_FALSE; ret->numSS = 0; ret->rangeSS[0] = ret->rangeSS[1] = AIR_NAN; ret->derivNormBiasSS = 0.0; ret->posSS = NULL; ret->nin = NULL; ret->ninSS = NULL; } return ret; }
airThreadCond * airThreadCondNew(void) { airThreadCond *cond; cond = AIR_CALLOC(1, airThreadCond); if (cond) { cond->count = 0; cond->broadcast = 0; cond->sema = CreateSemaphore(NULL, 0, 0x7fffffff, NULL); if (NULL == cond->sema) { return airFree(cond); } InitializeCriticalSection(&(cond->lock)); cond->done = CreateEvent(NULL, FALSE, FALSE, NULL); if (NULL == cond->done) { CloseHandle(cond->sema); return airFree(cond); } } return cond; }
/* ** as of Sept 2013 this returns information: the index of the ** option just added. Returns UINT_MAX in case of error. */ unsigned int hestOptAdd(hestOpt **optP, const char *flag, const char *name, int type, int min, int max, void *valueP, const char *dflt, const char *info, ...) { hestOpt *ret = NULL; int num; va_list ap; unsigned int retIdx; if (!optP) return UINT_MAX; num = *optP ? _hestNumOpts(*optP) : 0; if (!( ret = AIR_CALLOC(num+2, hestOpt) )) { return UINT_MAX; } if (num) memcpy(ret, *optP, num*sizeof(hestOpt)); retIdx = AIR_UINT(num); ret[num].flag = airStrdup(flag); ret[num].name = airStrdup(name); ret[num].type = type; ret[num].min = min; ret[num].max = max; ret[num].valueP = valueP; ret[num].dflt = airStrdup(dflt); ret[num].info = airStrdup(info); /* initialize the things that may be set below */ ret[num].sawP = NULL; ret[num].enm = NULL; ret[num].CB = NULL; /* seems to be redundant with above _hestOptInit() */ ret[num].source = hestSourceUnknown; /* deal with var args */ if (5 == _hestKind(&(ret[num]))) { va_start(ap, info); ret[num].sawP = va_arg(ap, unsigned int*); va_end(ap); }
/* Creates a new heap, returning NULL upon error. If additional data * is to be stored with each node, dataUnit needs to be set to the * number of data bytes needed per element. incr is used for dynamic * memory allocation (an additional number of incr elements are * allocated each time the heap grows past its current capacity). */ airHeap *airHeapNew(size_t dataUnit, unsigned int incr) { airHeap *h; h = AIR_CALLOC(1, airHeap); if (h==NULL) { return NULL; } h->key_a = airArrayNew((void**)&h->key, NULL, sizeof(double), incr); if (dataUnit>0) { /* data is optional */ h->data_a = airArrayNew((void**)&h->data, NULL, dataUnit, incr); } h->idx_a = airArrayNew((void**)&h->idx, NULL, sizeof(unsigned int), incr); h->invidx_a = airArrayNew((void**)&h->invidx, NULL, sizeof(unsigned int), incr); if (h->key_a==NULL || (dataUnit>0 && h->data_a==NULL) || h->idx_a==NULL || h->invidx_a==NULL) { /* allocation failed (partly) */ airHeapNuke(h); return NULL; } return h; }
/* ** _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; }