I have a Julia wrapper function that calls a C function from a shared library. This C function updates an output structure databuf, which is an instance of
How do I retrieve the 2D array vdata? I’ve tried unsafe_wrap, but I don’t seem to get what I was expecting (namely an array of 512 lines and 2048 columns UInt16 values):
The MTKt_DataBuffer structure is used to return geo-located data planes (“arrays”) of MISR data from the MtkReadData routine. It is designed to handle any C datatype. It does this using a union pointer data field which points to the same data pointed to by the dataptr field. The dataptr field points to the main data array which is stored in row-major form. The number of bytes of the data plane can be determined using buf.nline, buf.nsample and sizeof the datatype field. It can be used for bulk transfers. There is also a row vector (Illiffe vector) pointing to each row of the main array to support C bracket index notation for a 2D-array. It can be ignored. The structure does maintain dynamic memory, so use MtkDataBufferFree when finished with this structure.
Type Definition:
typedef enum {
MTKe_void=0,
MTKe_char8,
MTKe_uchar8,
MTKe_int8,
MTKe_uint8,
MTKe_int16,
MTKe_uint16,
MTKe_int32,
MTKe_uint32,
MTKe_int64,
MTKe_uint64,
MTKe_float,
MTKe_double
} MTKt_DataType;
typedef union {
void **v;
MTKt_char8 **c8;
MTKt_uchar8 **uc8;
MTKt_int8 **i8;
MTKt_uint8 **u8;
MTKt_int16 **i16;
MTKt_uint16 **u16;
MTKt_int32 **i32;
MTKt_uint32 **u32;
MTKt_int64 **i64;
MTKt_uint64 **u64;
MTKt_float **f;
MTKt_double **d;
} MTKt_DataBufferType;
typedef struct {
int nline; /**< Number of lines */
int nsample; /**< Number of samples */
int datasize; /**< Data element size (bytes) */
MTKt_DataType datatype; /**< Data type (enumeration) */
MTKt_DataBufferType data; /**< Data type access union */
void **vdata; /**< Row major 2D array with Illiffe vector */
void *dataptr; /**< Pointer data buffer */
} MTKt_DataBuffer;
Example Usage:
#include “MisrToolkit.h”
MTKt_status status;
MTKt_Region region = MTK_REGION_INIT;
MTKt_DataBuffer buf = MTKT_DATABUFFER_INIT;
MTKt_MapInfo mapinfo = MTKT_MAPINFO_INIT;
status = MtkSetRegionByPathBlockRange(32, 65, 125, ®ion);
if (status != MTK_SUCCESS) error;
status = MtkReadData(“MISR_file.hdf”, “MISR_gridname”, “MISR_fieldname”, region, &buf, &mapinfo)
if (status != MTK_SUCCESS) error;
for (l = 0; l < buf.nline; l++)
for (s = 0; s < buf.nsample; s++)
printf(“Data Buffer[%d][%d]: %f\n”, l, s, buf.data.f[l][s]);
MtkDataBufferFree(&buf);
Because it gives StackOverflowError and has no moral support in the docstring?
unsafe_wrap(Array, pointer::Ptr{T}, dims; own = false)
Wrap a Julia Array object around the data at the address given by pointer, without
making a copy. The pointer element type T determines the array element type.