On Sep 30, 2004, at 2:05 PM, Ken Mankoff wrote:
I'm having trouble getting a declare statement working. Perhaps
someone here can help me set this up.
Here is the C documentation I have:
The function nc_get_var1_text gets a single data value from a variable
of an open netCDF dataset that is in data mode. Inputs are the netCDF
ID, the variable ID, a multidimensional index that specifies which
value to get, and the address of a location into which the data value
will be read. The value is converted from the external data type of
the variable, if necessary.
int nc_get_var1_text (int ncid, int varid, const size_t index[], char
*tp);
ncid: NetCDF ID, from a previous call to nc_open or nc_create.
varid: Variable ID.
index[]: The index of the data value to be read. The indices
are relative to 0, so for example, the first data value of a
two-dimensional variable would have index (0,0). The elements
of index must correspond to the variable's dimensions. Hence,
if the variable is a record variable, the first index is the
record number.
tp Pointer to the location into which the data value is read.
Here is my RB code:
declare function nc_get_var1_text lib library ( _
ncid as integer, _
varid as integer, _
indexPtr as ptr, _
stringPtr as cstring ) _
as integer
dim stringPtr as memoryBlock = newMemoryBlock(256) // max string length
dim indexPtr as MemoryBlock = newMemoryBlock(8) // 2 array elements
// get the element at position (0,2)
indexPtr.long(0) = 0
indexPtr.long(4) = 2
dim err as integer
err = nc_get_var1_text( ncid, varid, indexPtr, stringPtr )
s = stringPtr.CString(0)
return err
First, the stringPtr work is unnecessary; you can pass an Rb String in
the function, and somehow a CString will be what's actually fed to the
function.
It looks to me as if index is being passed inline; thus the declaration
as Ptr will not work, for obvious reasons. If you're working on a Mac,
then you might try the declaration (assuming size_t is a 4-byte thing)
declare function nc_get_var1_text lib library ( _
ncid as integer, _
varid as integer, _
index1 as Integer, _
index2 as Integer, _
stringPtr as cstring ) _
as integer
If you're working on an x86 machine, then you should get a Mac because
passing structs inline from Rb to an external function doesn't appear
to be possible for x86.
Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>
|