S
Sheldon
Hey!
I have a netcdf function:
int nc_put_vara_double(int ncid, int varid, const size_t start[],const
size_t count[], const double *dp);
and the following example:
.....
#include <netcdf.h>
...
#define TIMES 3
#define LATS 5
#define LONS 10
int status; /* error status */
int ncid; /* netCDF ID */
int rh_id; /* variable ID */
static size_t start[] = {0, 0, 0}; /* start at first value */
static size_t count[] = {TIMES, LATS, LONS};
double rh_vals[TIMES*LATS*LONS]; /* array to hold values */
int i;
...
status = nc_open("foo.nc", NC_WRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
for (i = 0; i < TIMES*LATS*LONS; i++)
rh_vals = 0.5;
/* write values into netCDF variable */
status = nc_put_vara_double(ncid, rh_id, start, count, rh_vals);
if (status != NC_NOERR) handle_error(status);
.....
My problem is that I cannot define the rank of the array like in the
example. I tried solving this by doing the following:
const size_t lev = var;
const size_t row = var1;
const size_t col = var2;
and then added in the array per example: static size_t count[] = {var,
var1, var2};
When I compile I get the following error:
error: initializer element is not constant
I don't get this. Can anyone help me with this error. Would greatly
appreciate it!
/S
I have a netcdf function:
int nc_put_vara_double(int ncid, int varid, const size_t start[],const
size_t count[], const double *dp);
and the following example:
.....
#include <netcdf.h>
...
#define TIMES 3
#define LATS 5
#define LONS 10
int status; /* error status */
int ncid; /* netCDF ID */
int rh_id; /* variable ID */
static size_t start[] = {0, 0, 0}; /* start at first value */
static size_t count[] = {TIMES, LATS, LONS};
double rh_vals[TIMES*LATS*LONS]; /* array to hold values */
int i;
...
status = nc_open("foo.nc", NC_WRITE, &ncid);
if (status != NC_NOERR) handle_error(status);
...
status = nc_inq_varid (ncid, "rh", &rh_id);
if (status != NC_NOERR) handle_error(status);
...
for (i = 0; i < TIMES*LATS*LONS; i++)
rh_vals = 0.5;
/* write values into netCDF variable */
status = nc_put_vara_double(ncid, rh_id, start, count, rh_vals);
if (status != NC_NOERR) handle_error(status);
.....
My problem is that I cannot define the rank of the array like in the
example. I tried solving this by doing the following:
const size_t lev = var;
const size_t row = var1;
const size_t col = var2;
and then added in the array per example: static size_t count[] = {var,
var1, var2};
When I compile I get the following error:
error: initializer element is not constant
I don't get this. Can anyone help me with this error. Would greatly
appreciate it!
/S