PDA

View Full Version : changing array size via wavevars



hcrisp
09-16-2010, 04:44 PM
I've been trying to write a .dll to link using LINKNLOAD. I am using the interapp example provided in vni\wave\demo\interapp\win32\linknload\c_from_wave .c as an example for getting wavevars() to access a PV-WAVE variable. I would like to change the array size and values (it is only initialized as a scalar going into the LINKNLOAD call because I don't know the what size will be). The examples given only show how to modify the values of the inital size, however (shown here):



if (v->type == (TYP_FLOAT | TYP_ARRAY)) {

/* Get the pointer to the actual data. */
dataptr = ((float *) v->data);

/* Assign new values to array. */
for (j = 0; j < v->numelems; j++) {
dataptr[j] = (float) j;
}
break;
}


Here is my code for altering the array size which does not work. Nrows is equal to the number of elements and srate_array is already allocated. The variable in PV-WAVE prints as a scalar double with a random number.



double *srate_array;
//...
if (v->type == TYP_DOUBLE) {
/* Assign new values. */
v->type = TYP_DOUBLE | TYP_ARRAY;
v->numdims = 1;
v->dims[0] = nrows;
v->numelems = nrows;
*(v->data) = (double *) srate_array;
break;
}


What do I need to change?

hcrisp
09-17-2010, 02:32 PM
Looks like it can't be done using wavevars. I switched to using OPI functions (still within the context of LINKNLOAD), and it does work. Here's the working code:



ret = wave_get_WVH( "SRATE", &varhandle );
if ( ret != OPI_SUCCESS )
printf(" ***wave_get_WVH returned %d\n", ret);

l_dims[0] = nrows;
l_ndims = 1;

ret = wave_assign_num( varhandle, OPI_TYP_DOUBLE, l_ndims, l_dims, (double *)srate_array, (long)1 );
if ( ret != OPI_SUCCESS )
printf(" ***wave_assign_string() returned %d\n", ret);

wave_free_WVH( &(varhandle) );

hcrisp
09-28-2010, 08:38 AM
The function wave_get_WVH() only works if the variable already exists in PV-WAVE. Is there a recommended way to use wave_assign_num() if the variable does not exist? I would like to initialize it in the C code. I tried the following, but I get "Progam area full" errors if the variables are not declared in WAVE prior to calling this C code:



varname[0] = '\0';
sprintf_s(varname, 100, "SRATE = 0B");
ret = wave_execute(varname);
ret = wave_get_WVH( "SRATE", &varhandle );
ret = wave_assign_num(...)


The OPI Help is a bit vague on creating new variables in C.

donb
09-28-2010, 08:58 AM
You're correct - a variable must exist in PV-WAVE before you can get it's handle. Once the variable is defined in PV-WAVE, you can use the returned handle in wave_assign_num to make changes to the variable (size, type, dimensions, etc.).

By design, there is no way to use wave_assign_num to create variables.

Don B.