/* fut_free_tbl frees any table regardless of type by checking the magic * number in the header. It will also free a fut_t or a fut_chan_t. * * fut_free_tbls will free a null terminated list of any type of table, * useful for disposing of a set of tables which were used for constructing * a fut (which the fut has now absorbed and made shared copies of). */ void fut_free_tbl (KpGenericPtr_t tbl) { /* Make sure that we do not have a NULL pointer */ if( tbl == NULL ) { return; } switch (*(KpInt32_p)tbl) { case FUT_MAGIC: fut_free ((fut_p) tbl); break; case FUT_CMAGIC: fut_free_chan ((fut_chan_p) tbl); break; case FUT_IMAGIC: fut_free_itbl ((fut_itbl_p) tbl); break; case FUT_OMAGIC: fut_free_otbl ((fut_otbl_p) tbl); break; case FUT_GMAGIC: fut_free_gtbl ((fut_gtbl_p) tbl); break; } }
/* fut_copy_otbl makes an exact copy of an existing fut_otbl_t */ fut_otbl_p fut_copy_otbl (fut_otbl_p otbl) { fut_otbl_p new_otbl; KpHandle_t h; /* check for valid otbl */ if ( ! IS_OTBL(otbl) ) { return (FUT_NULL_OTBL); } /* allocate the new otbl structure */ new_otbl = fut_alloc_otbl (); if ( new_otbl == FUT_NULL_OTBL ) { DIAG("fut_copy_otbl: can't alloc output table struct.\n", 0); return (FUT_NULL_OTBL); } h = new_otbl->handle; /* save handle before copying over old otbl */ *new_otbl = *otbl; /* copy entire struct except reference count */ new_otbl->handle = h; new_otbl->ref = 0; /* first reference */ if (otbl->tbl != NULL) { /* copy fixed otbl data */ new_otbl->tbl = fut_alloc_otbldat (new_otbl); if ( new_otbl->tbl == NULL ) { DIAG("fut_copy_otbl: can't alloc output table array.\n", 0); goto ErrOut; } new_otbl->tblHandle = getHandleFromPtr((KpGenericPtr_t)new_otbl->tbl); /* copy the table entries */ KpMemCpy (new_otbl->tbl, otbl->tbl, FUT_OUTTBL_ENT * sizeof (fut_otbldat_t)); } if (otbl->refTbl != NULL) { /* copy reference otbl data */ new_otbl->refTbl = fut_alloc_omftdat (new_otbl, new_otbl->refTblEntries); if (new_otbl->refTbl == NULL ) { DIAG("fut_copy_otbl: can't alloc output table array.\n", 0); goto ErrOut; } /* copy the table entries */ KpMemCpy (new_otbl->refTbl, otbl->refTbl, new_otbl->refTblEntries * sizeof (mf2_tbldat_t)); } return (new_otbl); ErrOut: fut_free_otbl (new_otbl); return (FUT_NULL_OTBL); }
/* fut_new_otbl creates a new output table for one channel of a fut. * Ofun must be a pointer to a function accepting a fut_gtbldat_t in the * range (0,FUT_GRD_MAXVAL) and returning a fut_otbldat_t in the same * interval. A pointer to the newly allocated table is returned. * (If ofun is NULL, table is not intialized!). */ fut_otbl_p fut_new_otblEx ( PTTableType_t tableType, PTDataClass_t oClass, fut_ofunc_t ofun, fut_calcData_p data) { fut_otbl_p otbl; /* allocate output table structure */ otbl = fut_alloc_otbl(); if ( otbl == FUT_NULL_OTBL ) { DIAG("fut_new_otbl: can't alloc output table struct.\n", 0); return (FUT_NULL_OTBL); } otbl->dataClass = oClass; /* allocate the table */ if (tableType == KCP_PT_TABLES) { otbl->tbl = fut_alloc_otbldat (otbl); if ( otbl->tbl == NULL ) { DIAG("fut_new_otbl: can't alloc output table array.\n", 0); fut_free_otbl (otbl); return (FUT_NULL_OTBL); } } else { otbl->refTbl = fut_alloc_omftdat (otbl, FUT_OUTTBL_ENT); if ( otbl->refTbl == NULL ) { DIAG("fut_new_otbl: can't alloc output table array.\n", 0); fut_free_otbl (otbl); return (FUT_NULL_OTBL); } } /* compute the output table entries */ if ( ! fut_calc_otblEx (otbl, ofun, data) ) { fut_free_otbl (otbl); return (FUT_NULL_OTBL); } return (otbl); }
void fut_free_chan (fut_chan_p chan) { if ( ! IS_CHAN(chan) ) /* check if defined */ return; fut_free_itbl_list (chan->itbl); /* free input tables */ fut_free_otbl (chan->otbl); /* free output table */ fut_free_gtbl (chan->gtbl); /* free grid table */ /* free fut_chan_t structure itself */ chan->magic = 0; freeBufferPtr ((KpGenericPtr_t)chan); }