Describes the sciNetCDF low level interface
The sciNetCDF low level interface relies on the NetCDF C interface.
As consequence of this, all the functions of the C interface are available in Scilab (with a few exceptions, obsolete functions for example). Function, constant names are the same as in the C interface.
Also, all functions of the C interface (about 200) are not described here, and details can be found in the link below. That are adaptations from C to Scilab which will be described here.
Function names are the same as in C, the differences rely in the argument passing.
When a C function has an primitive type output parameter (such as double*, int*
...), this one is a return argument in the related Scilab function.
C function | Scilab function |
int nc_open(const char *path, int mode, int *ncidp) |
[ret, ncid] = nc_open(path, mode) |
int nc_inq_ncid(int ncid, const char *name, int *grp_ncid) |
[ret, grp_ncid] = nc_inq_ncid(ncid, name) |
int nc_inq_natts(int ncid, int *nattsp) |
[ret, natts] = nc_inq_natts(ncid) |
int nc_inq_dimid(int ncid, char *name, int *idp) |
[ret, id] = nc_inq_dimid(ncid, name) |
int nc_get_var1_short(int ncid, int varid, const size_t *indexp, const short *ip) |
[ret, val] = nc_get_var1_short(ncid, varid, index) |
int nc_get_var1_double(int ncid, int varid, const size_t *indexp, const double *ip) |
[ret, val] = nc_get_var1_double(ncid, varid, index) |
We have the same mechanism for functions that have a string output argument, such as functions that 'return a name':
C function | Scilab function |
int nc_inq_grpname(int *ncid, char *name) |
[ret, name] = nc_inq_grpname(ncid) |
int nc_inq_dimname(int ncid, in dimid, char *name) |
[ret, name] = nc_inq_dimname(ncid, dimid) |
int nc_inq_attname(int ncid, in dimid, int attnum, char *name) |
[ret, name] = nc_inq_attname(ncid, varid, attnum) |
Input/output array of size_t
arguments are automatically converted from/to a Scilab matrix.
C function | Scilab function |
int nc_get_var1_short(int ncid, int varid, const size_t *indexp, const short *ip) |
[ret, val] = nc_get_var1_short(ncid, varid, index) |
int nc_put_vara_text(int ncid, int varid, const size_t *startp, count, size_t * countp, const char *op) |
[ret, name] = [ret, name] = nc_put_vara_text(ncid, varid, index, count, op) |
Some functions accept a buffer as input/output parameter and need a pointer to be passed as in C. Pointers cannot be used natively in Scilab, that's why dedicated functions are provided for that purpose. These functions are used to create pointers and /read/write data from/to these pointers (see the further section Types for more details). Some examples of this special case are the following:
C function | Scilab function |
double *op = (double*) malloc(N * sizeof(double));
nc_get_att_double(ncid, varid, op);
x = op[2]; |
dblArray = new_DoubleArray(N);
nc_get_att_double(ncid, varid, dblArray);
x = DoubleArray_getitem(dblArray, 2); |
int *ip = (int*) malloc(N * sizeof(int));
ip[1] = 3;
nc_put_var_int(ncid, varid, ip); |
intArray = new_IntArray(N);
IntArray_setitem(intArray, 1, 3);
nc_put_var_int(ncid, varid, intArray); |
Constants have the same name as in C but need to be initiliazed in the Scilab environment with the provided function:
Once the initialization done, constants are used the same manner as in C:
filepath = fullfile(TMPDIR, 'test.nc'); [ret, ncid] = nc_create(filepath, NC_NETCDF4 + NC_CLOBBER); ret = nc_close(ncid); [ret, ncid] = nc_open(filepath, NC_NOWRITE); ret = nc_close(ncid); | ![]() | ![]() |
As previously said, some functions require pointers to be created and manipulated. For each primitive type there is a set of dedicated functions to create/read/write the pointer of that type. The related functions are prefixed, basing on the primitive type, as following:
C pointer type | Prefix of Scilab functions |
*double | DoubleArray |
*float | FloatArray |
*int | IntArray |
*unsigned int | UIntArray |
*signed short | ShortArray |
*unsigned short | UShortArray |
*signed char | CharArray |
*unsigned char | UCharArray |
For each type <Type> we have 4 functions:
ptr = new_<Type>(size)
value = <Type>_getitem(ptr, index)
value = <Type>_setitem(ptr, index, value)
delete_<Type>_(ptr)
An example of this, for pointer on integer: