/* fut_new_itbl creates a new input table for one dimension of a grid table * of size 'size'. Ifun must be a pointer to a function accepting a double * and returning a double, both in the range (0.0,1.0). A pointer to the * newly allocated table is returned. (If ifun is NULL, table is not * initialized). */ fut_itbl_p fut_new_itblEx ( PTTableType_t tableType, PTDataClass_t iClass, KpInt32_t size, fut_ifunc_t ifun, fut_calcData_p data) { fut_itbl_p itbl; KpInt32_t nEntries; if ((size <= 1) || (size > FUT_GRD_MAXDIM)) { DIAG("fut_new_itbl: bad grid size (%d).\n", size); return (FUT_NULL_ITBL); } /* allocate input table structure */ itbl = fut_alloc_itbl (); if ( ! IS_ITBL(itbl)) { DIAG("fut_new_itbl: can't alloc input table struct.\n", 0); return (FUT_NULL_ITBL); } itbl->size = size; itbl->dataClass = iClass; /* allocate the table */ if (itbl->dataClass == KCP_VARIABLE_RANGE) { nEntries = MF2_STD_ITBL_SIZE; } else { nEntries = FUT_INPTBL_ENT; } if (tableType == KCP_PT_TABLES) { itbl->tbl = fut_alloc_itbldat (itbl); if ( itbl->tbl == NULL ) { DIAG("fut_new_itbl: can't alloc input table array.\n", 0); goto ErrOut; } } else { itbl->refTbl = fut_alloc_imftdat (itbl, nEntries); if ( itbl->refTbl == NULL ) { DIAG("fut_new_itbl: can't alloc input table array.\n", 0); goto ErrOut; } } /* compute the input table entries */ if ( ! fut_calc_itblEx (itbl, ifun, data) ) { /* Note: fut_calc_itbl prints message on error */ goto ErrOut; } return (itbl); ErrOut: fut_free_itbl (itbl); return (FUT_NULL_ITBL); }
/* fut_copy_itbl makes an exact copy of an existing fut_itbl_t */ fut_itbl_p fut_copy_itbl (fut_itbl_p itbl) { fut_itbl_p new_itbl; KpHandle_t h; /* check for valid itbl */ if ( ! IS_ITBL(itbl) ) { return (FUT_NULL_ITBL); } /* allocate the new itbl structure */ new_itbl = fut_alloc_itbl (); if ( new_itbl == FUT_NULL_ITBL ) { DIAG("fut_copy_itbl: can't alloc input table struct.\n", 0); return (FUT_NULL_ITBL); } h = new_itbl->handle; /* save handle before copying over old itbl */ *new_itbl = *itbl; /* copy entire struct except reference count */ new_itbl->handle = h; /* copy back handle */ new_itbl->ref = 0; /* first reference */ if (itbl->tbl != NULL) { /* copy fixed itbl data */ new_itbl->tbl = fut_alloc_itbldat (new_itbl); if ( new_itbl->tbl == NULL ) { DIAG("fut_copy_itbl: can't alloc input table array.\n", 0); goto ErrOut; } new_itbl->tblHandle = getHandleFromPtr((KpGenericPtr_t)new_itbl->tbl); /* copy the table entries */ KpMemCpy (new_itbl->tbl, itbl->tbl, (FUT_INPTBL_ENT+1)*sizeof(fut_itbldat_t)); } if (itbl->refTbl != NULL) { /* copy reference itbl data */ new_itbl->refTbl = fut_alloc_imftdat (new_itbl, new_itbl->refTblEntries); if (new_itbl->refTbl == NULL ) { DIAG("fut_copy_itbl: can't alloc input table array.\n", 0); goto ErrOut; } /* copy the table entries */ KpMemCpy (new_itbl->refTbl, itbl->refTbl, new_itbl->refTblEntries * sizeof (mf2_tbldat_t)); } return (new_itbl); ErrOut: fut_free_itbl (new_itbl); return (FUT_NULL_ITBL); }