Пример #1
0
/* fut_new_gtbl creates a new grid table and optionally intializes it.
 * The input channels defined for the grid are specified in the input
 * channel mask portion of iomask.	Each input defined must have a size
 * specified in a KpInt32_t array.
 * Gfun must be a pointer to a function accepting from zero to three
 * doubles (depending on values of sx, sy, and sz) in the range (0.0,1.0)
 * and returning a fut_gtbldat_t in the range (0,FUT_GRD_MAXVAL).
 * A pointer to the newly allocated table is returned if there were no
 * errors.	(If gfun is NULL, the table is not initialized).
 */
fut_gtbl_p
	fut_new_gtblEx (	PTTableType_t	tableType,
						KpInt32_t		iomask,
						fut_gfunc_t		gfun,
						fut_calcData_p	data,
						KpInt32_p		dimList)
{
fut_gtbl_p	gtbl;
KpInt32_t	imask, i, dim_size, grid_size;

					/* get input mask */
	imask = (KpInt32_t)FUT_IMASK(iomask);

					/* allocate grid table structure */
	gtbl = fut_alloc_gtbl ();
	if ( gtbl == FUT_NULL_GTBL ) {
		DIAG("fut_new_gtblA: can't alloc grid table struct.\n", 0);
		return (FUT_NULL_GTBL);
	}

	/* get sizes from dimList */
	grid_size = 1;
	for ( i=0; i<FUT_NCHAN; i++ ) {
		dim_size = (imask & FUT_BIT(i)) ? dimList[i] : 1;
		if ( dim_size <= 0 ) {
			dim_size = 1;		/* make sure > 0 */
		}
		gtbl->size[i] = (KpInt16_t)dim_size;
		grid_size *= (KpInt32_t)dim_size;
	}

					/* check for valid grid size */
	if ( grid_size <= 0 || grid_size > FUT_GRD_MAX_ENT ) {
		DIAG("fut_new_gtblA: bad grid table size (%d).\n", grid_size);
		fut_free_gtbl(gtbl);
		return (FUT_NULL_GTBL);
	}
	gtbl->tbl_size = (KpInt32_t)grid_size * (KpInt32_t)sizeof(fut_gtbldat_t);

					/* allocate grid table */
	if (tableType == KCP_PT_TABLES) {
		gtbl->refTbl = fut_alloc_gtbldat (gtbl);
	} else {
		gtbl->refTbl = fut_alloc_gmftdat (gtbl);
	}
	if ( gtbl->refTbl == NULL ) {
		DIAG("fut_new_gtblA: can't alloc grid table array.\n", 0);
		fut_free_gtbl(gtbl);
		return (FUT_NULL_GTBL);
	}

					/* compute the grid table entries */
	if ( ! fut_calc_gtblEx (gtbl, gfun, data) ) {
		fut_free_gtbl(gtbl);
		return (FUT_NULL_GTBL);
	}

	return (gtbl);
}
Пример #2
0
/* fut_copy_gtbl makes an exact copy of an existing fut_gtbl_t
 */
fut_gtbl_p
	fut_copy_gtbl (fut_gtbl_p gtbl)
{
fut_gtbl_p		new_gtbl;
KpInt32_t		gsize;
KpHandle_t		h;

				/* check for valid gtbl */
	if ( ! IS_GTBL(gtbl) ) {
		return (FUT_NULL_GTBL);
	}

	new_gtbl = fut_alloc_gtbl ();	/* allocate the new gtbl structure */
	if ( new_gtbl == FUT_NULL_GTBL ) {
		DIAG("fut_copy_gtbl: can't alloc grid table struct.\n", 0);
		return (FUT_NULL_GTBL);
	}

	h = new_gtbl->handle;	/* save handle before copying over old gtbl */

	*new_gtbl = *gtbl;		/* copy entire struct except reference count */

	new_gtbl->handle = h;
	new_gtbl->ref = 0;		/* first reference */

	if (gtbl->tbl != NULL) {	/* copy fixed gtbl data */
		gsize = gtbl->tbl_size / (KpInt32_t)sizeof(fut_gtbldat_t);
		new_gtbl->tbl = fut_alloc_gtbldat (new_gtbl);
		if ( new_gtbl->tbl == NULL ) {
			DIAG("fut_copy_gtbl: can't alloc grid table array.\n", 0);
			goto ErrOut;
		}
		new_gtbl->tblHandle = getHandleFromPtr((KpGenericPtr_t)new_gtbl->tbl);

		/* copy the table entries */
		KpMemCpy (new_gtbl->tbl, gtbl->tbl, gtbl->tbl_size);
	}

	if (gtbl->refTbl != NULL) {	/* copy reference gtbl data */
		new_gtbl->refTbl = fut_alloc_gmftdat (new_gtbl);
		if (new_gtbl->refTbl == NULL ) {
			DIAG("fut_copy_gtbl: can't alloc ref grid table array.\n", 0);
			goto ErrOut;
		}

		/* copy the table entries */
		KpMemCpy (new_gtbl->refTbl, gtbl->refTbl, gtbl->tbl_size);
	}

	return (new_gtbl);
	

ErrOut:
	fut_free_gtbl (new_gtbl);
	return (FUT_NULL_GTBL);
}