|
NetCDF
4.8.1
|
Go to the documentation of this file.
39 #if SIZEOF_LONG == SIZEOF_SIZE_T
48 # define A_DECL(name, type, ndims, rhs) \
49 const type *const name = ((const type *)(rhs))
53 # define A_INIT(lhs, type, ndims, rhs)
67 nvdims(
int ncid,
int varid)
73 nc_advise(
"ncvdims", status,
"ncid %d", ncid);
81 static void* nvmalloc(off_t size) {
89 #define NDIMS_DECL const int ndims = nvdims(ncid, varid); \
92 # define A_DECL(name, type, ndims, rhs) \
93 type *const name = (type*) nvmalloc((ndims) * sizeof(type))
97 ALLOC_ONSTACK(name, type, ndims)
100 # define A_FREE(name) \
103 # define A_INIT(lhs, type, ndims, rhs) \
105 if((off_t)ndims >= 0) { \
106 const long *lp = rhs; \
108 type *const end = lhs + ndims; \
111 *tp++ = (type) *lp++; \
116 if ((off_t)ndims < 0) {nc_advise("nvdims",NC_EMAXDIMS,"ndims %d",ndims); return -1;}
154 if (recdimid == -1) {
159 for (varid = 0; varid < nvars; varid++) {
166 if (ndims > 0 && dimids[0] == recdimid) {
167 if (recvarids != NULL)
168 recvarids[nrecvars] = varid;
172 *nrecvarsp = nrecvars;
211 if (ndims == 0 || dimids[0] != recdimid) {
214 size = nctypelen(type);
215 for (
id = 1;
id < ndims;
id++) {
222 *recsizep = (size_t)size;
253 if (ndims == 0 || sizes == NULL)
255 for (
id = 0;
id < ndims;
id++) {
317 if (nrecvarsp != NULL)
318 *nrecvarsp = (size_t)nrvars;
320 if (recvarids != NULL)
321 for (varid = 0; varid < nrvars; varid++)
322 recvarids[varid] = rvarids[varid];
324 if (recsizes != NULL)
325 for (varid = 0; varid < nrvars; varid++) {
327 status =
ncrecsize(ncid, rvarids[varid], &rsize);
330 recsizes[varid] = rsize;
375 for (varid = 1; varid < nrvars; varid++)
378 for (varid = 0; varid < nrvars; varid++) {
379 if (datap[varid] != NULL) {
380 status =
dimsizes(ncid, rvarids[varid], edges);
385 status =
nc_put_vara(ncid, rvarids[varid], start, edges, datap[varid]);
436 for (varid = 1; varid < nrvars; varid++)
439 for (varid = 0; varid < nrvars; varid++) {
440 if (datap[varid] != NULL) {
441 status =
dimsizes(ncid, rvarids[varid], edges);
445 status =
nc_get_vara(ncid, rvarids[varid], start, edges, datap[varid]);
466 nc_advise(
const char *routine_name,
int err,
const char *fmt,...)
477 (void) fprintf(stderr,
"%s: ", routine_name);
479 (void) vfprintf(stderr,fmt,args);
483 (void) fprintf(stderr,
": %s",
486 (void) fputc(
'\n',stderr);
487 (void) fflush(stderr);
514 const int status =
nc_create(path, cmode, &ncid);
517 nc_advise(
"nccreate", status,
"filename \"%s\"", path);
539 const int status =
nc_open(path, mode, &ncid);
542 nc_advise(
"ncopen", status,
"filename \"%s\"", path);
565 nc_advise(
"ncredef", status,
"ncid %d", ncid);
588 nc_advise(
"ncendef", status,
"ncid %d", ncid);
611 nc_advise(
"ncclose", status,
"ncid %d", ncid);
644 const int status =
nc_inq(ncid, &nd, &nv, &na, recdim);
648 nc_advise(
"ncinquire", status,
"ncid %d", ncid);
679 const int status =
nc_sync(ncid);
682 nc_advise(
"ncsync", status,
"ncid %d", ncid);
705 nc_advise(
"ncabort", status,
"ncid %d", ncid);
736 nc_advise(
"ncdimdef", status,
"ncid %d", ncid);
739 status =
nc_def_dim(ncid, name, (
size_t)length, &dimid);
742 nc_advise(
"ncdimdef", status,
"ncid %d", ncid);
767 nc_advise(
"ncdimid", status,
"ncid %d", ncid);
796 const int status =
nc_inq_dim(ncid, dimid, name, &ll);
800 nc_advise(
"ncdiminq", status,
"ncid %d", ncid);
834 nc_advise(
"ncdimrename", status,
"ncid %d", ncid);
865 const int status =
nc_def_var(ncid, name, datatype, ndims, dim, &varid);
868 nc_advise(
"ncvardef", status,
"ncid %d", ncid);
896 nc_advise(
"ncvarid", status,
"ncid %d", ncid);
931 const int status =
nc_inq_var(ncid, varid, name, datatype,
936 nc_advise(
"ncvarinq", status,
"ncid %d", ncid);
973 A_DECL(coordp,
size_t, (
size_t)ndims, index);
974 A_INIT(coordp,
size_t, (
size_t)ndims, index);
976 const int status =
nc_put_var1(ncid, varid, coordp, value);
980 nc_advise(
"ncvarput1", status,
"ncid %d", ncid);
1010 A_DECL(coordp,
size_t, ndims, index);
1011 A_INIT(coordp,
size_t, ndims, index);
1013 const int status =
nc_get_var1(ncid, varid, coordp, value);
1017 nc_advise(
"ncdimid", status,
"ncid %d", ncid);
1049 A_DECL(stp,
size_t, ndims, start);
1050 A_DECL(cntp,
size_t, ndims, count);
1051 A_INIT(stp,
size_t, ndims, start);
1052 A_INIT(cntp,
size_t, ndims, count);
1054 const int status =
nc_put_vara(ncid, varid, stp, cntp, value);
1059 nc_advise(
"ncvarput", status,
"ncid %d", ncid);
1091 A_DECL(stp,
size_t, ndims, start);
1092 A_DECL(cntp,
size_t, ndims, count);
1093 A_INIT(stp,
size_t, ndims, start);
1094 A_INIT(cntp,
size_t, ndims, count);
1096 const int status =
nc_get_vara(ncid, varid, stp, cntp, value);
1101 nc_advise(
"ncvarget", status,
"ncid %d; varid %d", ncid, varid);
1135 return ncvarput(ncid, varid, start, count, value);
1140 A_DECL(stp,
size_t, ndims, start);
1141 A_DECL(cntp,
size_t, ndims, count);
1142 A_DECL(strdp, ptrdiff_t, ndims, stride);
1143 A_INIT(stp,
size_t, ndims, start);
1144 A_INIT(cntp,
size_t, ndims, count);
1145 A_INIT(strdp, ptrdiff_t, ndims, stride);
1147 const int status =
nc_put_vars(ncid, varid, stp, cntp, strdp, value);
1153 nc_advise(
"ncvarputs", status,
"ncid %d", ncid);
1188 return ncvarget(ncid, varid, start, count, value);
1192 A_DECL(stp,
size_t, ndims, start);
1193 A_DECL(cntp,
size_t, ndims, count);
1194 A_DECL(strdp, ptrdiff_t, ndims, stride);
1195 A_INIT(stp,
size_t, ndims, start);
1196 A_INIT(cntp,
size_t, ndims, count);
1197 A_INIT(strdp, ptrdiff_t, ndims, stride);
1199 const int status =
nc_get_vars(ncid, varid, stp, cntp, strdp, value);
1205 nc_advise(
"ncvargets", status,
"ncid %d", ncid);
1243 return ncvarputs(ncid, varid, start, count, stride, value);
1246 ptrdiff_t *imp=NULL;
1256 el_size = nctypelen(type);
1257 imp = (ptrdiff_t*) malloc(ndims *
sizeof(ptrdiff_t));
1258 for (i=0; i<ndims; i++) imp[i] = map[i] / el_size;
1262 A_DECL(stp,
size_t, ndims, start);
1263 A_DECL(cntp,
size_t, ndims, count);
1264 A_DECL(strdp, ptrdiff_t, ndims, stride);
1265 A_INIT(stp,
size_t, ndims, start);
1266 A_INIT(cntp,
size_t, ndims, count);
1267 A_INIT(strdp, ptrdiff_t, ndims, stride);
1270 stp, cntp, strdp, imp, value);
1271 if (imp!=NULL) free(imp);
1277 nc_advise(
"ncvarputg", status,
"ncid %d", ncid);
1316 return ncvargets(ncid, varid, start, count, stride, value);
1319 ptrdiff_t *imp=NULL;
1329 el_size = nctypelen(type);
1330 imp = (ptrdiff_t*) malloc(ndims *
sizeof(ptrdiff_t));
1331 for (i=0; i<ndims; i++) imp[i] = map[i] / el_size;
1335 A_DECL(stp,
size_t, ndims, start);
1336 A_DECL(cntp,
size_t, ndims, count);
1337 A_DECL(strdp, ptrdiff_t, ndims, stride);
1338 A_INIT(stp,
size_t, ndims, start);
1339 A_INIT(cntp,
size_t, ndims, count);
1340 A_INIT(strdp, ptrdiff_t, ndims, stride);
1343 stp, cntp, strdp, imp, value);
1344 if (imp!=NULL) free(imp);
1350 nc_advise(
"ncvargetg", status,
"ncid %d", ncid);
1382 nc_advise(
"ncvarrename", status,
"ncid %d", ncid);
1414 const int status =
nc_put_att(ncid, varid, name, datatype, len, value);
1417 nc_advise(
"ncattput", status,
"ncid %d", ncid);
1449 const int status =
nc_inq_att(ncid, varid, name, datatype, &ll);
1453 "ncid %d; varid %d; attname \"%s\"",
1486 const int status =
nc_get_att(ncid, varid, name, value);
1489 nc_advise(
"ncattget", status,
"ncid %d", ncid);
1519 const int status =
nc_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
1522 nc_advise(
"ncattcopy", status,
"%s", name);
1553 nc_advise(
"ncattname", status,
"ncid %d", ncid);
1581 const int status =
nc_rename_att(ncid, varid, name, newname);
1584 nc_advise(
"ncattrename", status,
"ncid %d", ncid);
1610 const int status =
nc_del_att(ncid, varid, name);
1613 nc_advise(
"ncattdel", status,
"ncid %d", ncid);
1642 const int status =
nc_set_fill(ncid, fillmode, &oldmode);
1645 nc_advise(
"ncsetfill", status,
"ncid %d", ncid);
1681 status =
nc_inq_rec(ncid, &nrv, recvarids, rs);
1684 nc_advise(
"ncrecinq", status,
"ncid %d", ncid);
1685 if(rs != NULL) free(rs);
1689 if(nrecvars != NULL)
1690 *nrecvars = (int) nrv;
1692 if(recsizes != NULL)
1695 for(ii = 0; ii < nrv; ii++)
1697 recsizes[ii] = (long) rs[ii];
1701 if(rs != NULL) free(rs);
1729 const int status =
nc_get_rec(ncid, (
size_t)recnum, datap);
1732 nc_advise(
"ncrecget", status,
"ncid %d", ncid);
1760 const int status =
nc_put_rec(ncid, (
size_t)recnum, datap);
1763 nc_advise(
"ncrecput", status,
"ncid %d", ncid);
#define NC_NOERR
No Error.
int ncvardef(int ncid, const char *name, nc_type datatype, int ndims, const int *dim)
int ncdimid(int ncid, const char *name)
EXTERNL int nc_inq_varndims(int ncid, int varid, int *ndimsp)
Learn how many dimensions are associated with a variable.
int ncvarid(int ncid, const char *name)
EXTERNL int nc_redef(int ncid)
static int numrecvars(int ncid, int *nrecvarsp, int *recvarids)
Computes number of record variables in an open netCDF file, and an array of the record variable ids,...
int ncattdel(int ncid, int varid, const char *name)
EXTERNL int nc_def_var(int ncid, const char *name, nc_type xtype, int ndims, const int *dimidsp, int *varidp)
Define a new variable.
int ncvargets(int ncid, int varid, const long *start, const long *count, const long *stride, void *value)
int ncrecinq(int ncid, int *nrecvars, int *recvarids, long *recsizes)
EXTERNL int nc_def_dim(int ncid, const char *name, size_t len, int *idp)
Define a new dimension.
int ncvargetg(int ncid, int varid, const long *start, const long *count, const long *stride, const long *map, void *value)
int ncattcopy(int ncid_in, int varid_in, const char *name, int ncid_out, int varid_out)
#define MAX_NC_VARS
Backward compatible alias.
int ncdiminq(int ncid, int dimid, char *name, long *length)
EXTERNL int nc_put_vars(int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, const void *op)
int ncattget(int ncid, int varid, const char *name, void *value)
int ncdimrename(int ncid, int dimid, const char *name)
int ncvarput(int ncid, int varid, const long *start, const long *count, const void *value)
int ncinquire(int ncid, int *ndims, int *nvars, int *natts, int *recdim)
EXTERNL int nc_inq(int ncid, int *ndimsp, int *nvarsp, int *nattsp, int *unlimdimidp)
EXTERNL int nc_put_vara(int ncid, int varid, const size_t *startp, const size_t *countp, const void *op)
int ncvarget1(int ncid, int varid, const long *index, void *value)
EXTERNL int nc_del_att(int ncid, int varid, const char *name)
Delete an attribute.
EXTERNL int nc_inq_dim(int ncid, int dimid, char *name, size_t *lenp)
Find the name and length of a dimension.
EXTERNL int nc_inq_dimlen(int ncid, int dimid, size_t *lenp)
Find the length of a dimension.
int nccreate(const char *path, int cmode)
EXTERNL int nc_put_var1(int ncid, int varid, const size_t *indexp, const void *op)
EXTERNL int nc_rename_var(int ncid, int varid, const char *name)
Rename a variable.
EXTERNL int nc_get_varm(int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, const ptrdiff_t *imapp, void *ip)
int ncattrename(int ncid, int varid, const char *name, const char *newname)
EXTERNL int nc_put_varm(int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, const ptrdiff_t *imapp, const void *op)
int ncvarputs(int ncid, int varid, const long *start, const long *count, const long *stride, const void *value)
int ncvarputg(int ncid, int varid, const long *start, const long *count, const long *stride, const long *map, const void *value)
EXTERNL int nc_close(int ncid)
int ncattput(int ncid, int varid, const char *name, nc_type datatype, int len, const void *value)
EXTERNL int nc_inq_dimid(int ncid, const char *name, int *idp)
Find the ID of a dimension from the name.
EXTERNL int nc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, size_t *lenp)
#define MAX_NC_DIMS
Backward compatible alias.
EXTERNL int nc_inq_unlimdim(int ncid, int *unlimdimidp)
Find the ID of the unlimited dimension.
static int dimsizes(int ncid, int varid, size_t *sizes)
Retrieves the dimension sizes of a variable with a specified variable id in an open netCDF file.
EXTERNL int nc_inq_varid(int ncid, const char *name, int *varidp)
EXTERNL int nc_abort(int ncid)
int ncsetfill(int ncid, int fillmode)
#define NC_MAX_VARS
Maximum for classic library.
EXTERNL int nc_copy_att(int ncid_in, int varid_in, const char *name, int ncid_out, int varid_out)
Copy an attribute from one open file to another.
int ncrecput(int ncid, long recnum, void *const *datap)
EXTERNL int nc_set_fill(int ncid, int fillmode, int *old_modep)
#define A_INIT(lhs, type, ndims, rhs)
Init a variable.
EXTERNL int nc_open(const char *path, int mode, int *ncidp)
Open an existing netCDF file.
EXTERNL int nc_put_att(int ncid, int varid, const char *name, nc_type xtype, size_t len, const void *op)
int ncvarget(int ncid, int varid, const long *start, const long *count, void *value)
int nc_type
The nc_type type is just an int.
EXTERNL int nc_inq_vartype(int ncid, int varid, nc_type *xtypep)
Learn the type of a variable.
EXTERNL int nc_get_var1(int ncid, int varid, const size_t *indexp, void *ip)
#define NC_FATAL
For V2 API, exit on error.
int ncvarput1(int ncid, int varid, const long *index, const void *value)
EXTERNL int nc_get_vara(int ncid, int varid, const size_t *startp, const size_t *countp, void *ip)
#define NC_ENOMEM
Memory allocation (malloc) failure.
#define NC_VERBOSE
For V2 API, be verbose on error.
int ncattinq(int ncid, int varid, const char *name, nc_type *datatype, int *len)
static int ncrecsize(int ncid, int varid, size_t *recsizep)
Computes record size (in bytes) of the record variable with a specified variable id.
EXTERNL const char * nc_strerror(int ncerr)
Given an error number, return an error message.
EXTERNL int nc_inq_nvars(int ncid, int *nvarsp)
Learn the number of variables in a file or group.
int nc_put_rec(int ncid, size_t recnum, void *const *datap)
#define NC_SYSERR
V2 API system error.
#define NC_EDIMSIZE
Invalid dimension size.
int ncerr
V2 API error code.
EXTERNL int nc_inq_attname(int ncid, int varid, int attnum, char *name)
EXTERNL int nc_enddef(int ncid)
int ncvarinq(int ncid, int varid, char *name, nc_type *datatype, int *ndims, int *dim, int *natts)
void nc_advise(const char *routine_name, int err, const char *fmt,...)
EXTERNL int nc_get_vars(int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, void *ip)
int ncattname(int ncid, int varid, int attnum, char *name)
#define A_FREE(name)
Free a variable.
int ncopts
The subroutines in error.c emit no messages unless NC_VERBOSE bit is on.
EXTERNL int nc_rename_att(int ncid, int varid, const char *name, const char *newname)
Rename an attribute.
int nc_get_rec(int ncid, size_t recnum, void **datap)
#define NC_ISSYSERR(err)
The netcdf version 3 functions all return integer error status.
EXTERNL int nc_create(const char *path, int cmode, int *ncidp)
int ncvarrename(int ncid, int varid, const char *name)
EXTERNL int nc_sync(int ncid)
EXTERNL int nc_rename_dim(int ncid, int dimid, const char *name)
Rename a dimension.
int ncopen(const char *path, int mode)
signed char schar
Signed character type.
EXTERNL int nc_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, int *dimidsp, int *nattsp)
int nc_inq_rec(int ncid, size_t *nrecvarsp, int *recvarids, size_t *recsizes)
#define NDIMS_DECL
NDIMS declaration.
EXTERNL int nc_get_att(int ncid, int varid, const char *name, void *ip)
int ncrecget(int ncid, long recnum, void **datap)
EXTERNL int nc_inq_vardimid(int ncid, int varid, int *dimidsp)
Learn the dimension IDs associated with a variable.
int ncdimdef(int ncid, const char *name, long length)