create/get/set a float array subobject to an object
int FLDadd_float_array (
OMobj_id field,
const char *name,
xp_long size);
int FLDset_array_float (
OMobj_id field,
xp_long size,
int mode,
float *array,
const char *name);
int FLDget_array_float (
OMobj_id field,
float **array,
xp_long *size,
int mode,
const char *name);
These routines add a new float array subobject to an existing field data schema object, and then set/get its values. They could also be used when you want to construct and reference an entirely new data object and add float array subobjects to it, but you want to do this within the code of a function, rather than using V.
Note: If you are accessing an existing, defined subobject, use the specific routine for that subobject (for example, FLDget_coord_extent). Use FLDadd/set/ get_float_array only when you have created your own, unique, named subobject, or when no FLD routine exists for a pre-defined subobject.
FLDadd_float_array adds a float array subobject to the object specified by OMobj_id field. The object is named in the Object Manager by the string name. size indicates the total number of array values. For example, a [100][2] array would have size 200. The new subobject is flagged as "not set."
FLDset_array_float sets the float array object named name within field equal to the array formed by the first size values found in the float array pointed to by array.
FLDget_array_float returns the value of the float subobject name within field in via the double pointer array.
The program intends to write to the array, completely replacing it, but not read it. |
||
The program requires a copy of the array for its own, private use (reading or writing). |
This abstracted section of code is taken from modules/pln_dist.c. It adds a double array of three values to a Plane_Mesh datatype that will hold the plane's normals. It keeps it in the Object Manager, querying its existence each time the function executes. If necessary, it resets the values of the normals array at the end of each execution.
...
int FUNCplane_dist (in, plane, out, dist);
OMobj_id in, plane, out;
{
...
int stat;
int size;
float norm_xfm[3], *norm_x;
float plane_dist;
...
MATxform_vecs(1, norm, xfm, norm_xfm);
plane_dist = VEC_DOT(bounds, norm_xfm);
...
stat = FLDget_array_float(out, "plane_norm", &norm_x, &size, OM_GET_ARRAY_RD);
if (stat < 1) {
if (FLDadd_float_array (out, "plane_norm", 3)!=1 {
ERR_RETURN("cannot create normal array");
}
}
...
VEC_CROSS(cross, norm_xfm, norm_x);
...<test for new data, set recomp if new >...
if (recomp) {
...
for (i=0; i<nnodes; i++)
node_dist[i] = VEC_DOT((coord+3*i), norm_xfm);
if (FLDset_array_float(out, "plane_norm", 3, norm_xfm, OM_SET_ARRAY_COPY)
!= 1)
{
ERR_RETURN("cannot set normal array");
}
}
}