/**@{*/ int nc_get_vara(int ncid, int varid, const size_t *startp, const size_t *countp, void *ip) { NC* ncp = NULL; nc_type xtype = NC_NAT; int stat = NC_check_id(ncid, &ncp); if(stat != NC_NOERR) return stat; stat = nc_inq_vartype(ncid, varid, &xtype); if(stat != NC_NOERR) return stat; return NC_get_vara(ncid, varid, startp, countp, ip, xtype); }
static int NC5_inq(int ncid, int *ndimsp, int *nvarsp, int *nattsp, int *unlimp) { NC* nc; int status = NC_check_id(ncid, &nc); if(status != NC_NOERR) return status; return ncmpi_inq(nc->int_ncid,ndimsp,nvarsp,nattsp,unlimp); }
/**@{*/ int nc_put_vara(int ncid, int varid, const size_t *startp, const size_t *countp, const void *op) { NC* ncp; int stat = NC_check_id(ncid, &ncp); nc_type xtype; if(stat != NC_NOERR) return stat; stat = nc_inq_vartype(ncid, varid, &xtype); if(stat != NC_NOERR) return stat; return NC_put_vara(ncid, varid, startp, countp, op, xtype); }
int nc_put_varm_string(int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, const ptrdiff_t *imapp, const char**op) { NC *ncp; int stat = NC_check_id(ncid, &ncp); if(stat != NC_NOERR) return stat; return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, (void *)op, NC_STRING); }
int nc_get_vars_string(int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t * stridep, char* *ip) { NC* ncp; int stat = NC_check_id(ncid, &ncp); if(stat != NC_NOERR) return stat; return NC_get_vars(ncid, varid, startp, countp, stridep, (void *)ip, NC_STRING); }
int nc_get_varm_uint(int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, const ptrdiff_t *imapp, unsigned int *ip) { NC *ncp; int stat = NC_check_id(ncid, &ncp); if(stat != NC_NOERR) return stat; return NC_get_varm(ncid, varid, startp, countp, stridep, imapp, (void *)ip, T_uint); }
int nc_put_vars_int(int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, const int *op) { NC *ncp; int stat = NC_check_id(ncid, &ncp); if(stat != NC_NOERR) return stat; return NC_put_vars(ncid, varid, startp, countp, stridep, (void *)op, NC_INT); }
int nc_put_vars_uchar(int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, const unsigned char *op) { NC *ncp; int stat = NC_check_id(ncid, &ncp); if(stat != NC_NOERR) return stat; return NC_put_vars(ncid, varid, startp, countp, stridep, (void *)op, T_uchar); }
int nc_del_att(int ncid, int varid, const char *name) { int status; NC *ncp; NC_attrarray *ncap; NC_attr **attrpp; NC_attr *old = NULL; int attrid; size_t slen; status = NC_check_id(ncid, &ncp); if(status != NC_NOERR) return status; if(!NC_indef(ncp)) return NC_ENOTINDEFINE; ncap = NC_attrarray0(ncp, varid); if(ncap == NULL) return NC_ENOTVAR; /* sortof inline NC_findattr() */ slen = strlen(name); attrpp = (NC_attr **) ncap->value; for(attrid = 0; (size_t) attrid < ncap->nelems; attrid++, attrpp++) { if( slen == (*attrpp)->name->nchars && strncmp(name, (*attrpp)->name->cp, slen) == 0) { old = *attrpp; break; } } if( (size_t) attrid == ncap->nelems ) return NC_ENOTATT; /* end inline NC_findattr() */ /* shuffle down */ for(attrid++; (size_t) attrid < ncap->nelems; attrid++) { *attrpp = *(attrpp + 1); attrpp++; } *attrpp = NULL; /* decrement count */ ncap->nelems--; free_NC_attr(old); return NC_NOERR; }
int nc_put_varm_ulonglong(int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, const ptrdiff_t *imapp, const unsigned long long *op) { NC *ncp; int stat = NC_check_id(ncid, &ncp); if(stat != NC_NOERR) return stat; return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, (void *)op, NC_UINT64); }
int nc_put_varm_double(int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, const ptrdiff_t *imapp, const double *op) { NC *ncp; int stat = NC_check_id(ncid, &ncp); if(stat != NC_NOERR) return stat; return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, (void *)op, T_double); }
/**@{*/ int nc_put_vars (int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, const void *op) { NC *ncp; int stat = NC_NOERR; if ((stat = NC_check_id(ncid, &ncp))) return stat; return ncp->dispatch->put_vars(ncid, varid, startp, countp, stridep, op, NC_NAT); }
static size_t nvdims(int ncid, int varid) { NC *ncp; if(NC_check_id(ncid, &ncp) != NC_NOERR) return 0; { const NC_var *const varp = NC_lookupvar(ncp, varid); if(varp == NULL) return 0; return varp->ndims; } }
/** \{ */ 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) { NC* ncp; int stat = NC_NOERR; if ((stat = NC_check_id(ncid, &ncp))) return stat; return ncp->dispatch->get_varm(ncid, varid, startp, countp, stridep, imapp, ip, NC_NAT); }
/** @ingroup variables Define a new variable. This function adds a new variable to an open netCDF dataset or group. It returns (as an argument) a variable ID, given the netCDF ID, the variable name, the variable type, the number of dimensions, and a list of the dimension IDs. @param ncid NetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid(). @param name Variable \ref object_name. @param xtype \ref data_type of the variable. @param ndims Number of dimensions for the variable. For example, 2 specifies a matrix, 1 specifies a vector, and 0 means the variable is a scalar with no dimensions. Must not be negative or greater than the predefined constant ::NC_MAX_VAR_DIMS. In netCDF-4/HDF5 files, may not exceed the HDF5 maximum number of dimensions (32). @param dimidsp Vector of ndims dimension IDs corresponding to the variable dimensions. For classic model netCDF files, if the ID of the unlimited dimension is included, it must be first. This argument is ignored if ndims is 0. For expanded model netCDF4/HDF5 files, there may be any number of unlimited dimensions, and they may be used in any element of the dimids array. @param varidp Pointer to location for the returned variable ID. @returns ::NC_NOERR No error. @returns ::NC_EBADID Bad ncid. @returns ::NC_ENOTINDEFINE Not in define mode. @returns ::NC_ESTRICTNC3 Attempting netcdf-4 operation on strict nc3 netcdf-4 file. @returns ::NC_EMAXVARS NC_MAX_VARS exceeded [Not enforced after 4.5.0] @returns ::NC_EBADTYPE Bad type. @returns ::NC_EINVAL Invalid input. @returns ::NC_ENAMEINUSE Name already in use. @returns ::NC_EPERM Attempt to create object in read-only file. @section nc_def_var_example Example Here is an example using nc_def_var to create a variable named rh of type double with three dimensions, time, lat, and lon in a new netCDF dataset named foo.nc: @code #include <netcdf.h> ... int status; int ncid; int lat_dim, lon_dim, time_dim; int rh_id; int rh_dimids[3]; ... status = nc_create("foo.nc", NC_NOCLOBBER, &ncid); if (status != NC_NOERR) handle_error(status); ... status = nc_def_dim(ncid, "lat", 5L, &lat_dim); if (status != NC_NOERR) handle_error(status); status = nc_def_dim(ncid, "lon", 10L, &lon_dim); if (status != NC_NOERR) handle_error(status); status = nc_def_dim(ncid, "time", NC_UNLIMITED, &time_dim); if (status != NC_NOERR) handle_error(status); ... rh_dimids[0] = time_dim; rh_dimids[1] = lat_dim; rh_dimids[2] = lon_dim; status = nc_def_var (ncid, "rh", NC_DOUBLE, 3, rh_dimids, &rh_id); if (status != NC_NOERR) handle_error(status); @endcode @author Glenn Davis, Ed Hartnett, Dennis Heimbigner */ int nc_def_var(int ncid, const char *name, nc_type xtype, int ndims, const int *dimidsp, int *varidp) { NC* ncp; int stat = NC_NOERR; if ((stat = NC_check_id(ncid, &ncp))) return stat; TRACE(nc_def_var); return ncp->dispatch->def_var(ncid, name, xtype, ndims, dimidsp, varidp); }
/** \ingroup user_types Get information about one of the fields of a compound type. \param ncid \ref ncid \param xtype The typeid for this compound type, as returned by nc_def_compound(), or nc_inq_var(). \param fieldid A zero-based index number specifying a field in the compound type. \param name Returned \ref object_name of the field. \ref ignored_if_null. \param offsetp A pointer which will get the offset of the field. \ref ignored_if_null. \param field_typeidp A pointer which will get the typeid of the field. \ref ignored_if_null. \param ndimsp A pointer which will get the number of dimensions of the field. \ref ignored_if_null. \param dim_sizesp A pointer which will get the dimension sizes of the field. \ref ignored_if_null. \returns ::NC_NOERR No error. \returns ::NC_EBADID Bad \ref ncid. \returns ::NC_EBADTYPE Bad type id. \returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled. \returns ::NC_EHDFERR An error was reported by the HDF5 layer. */ int nc_inq_compound_field(int ncid, nc_type xtype, int fieldid, char *name, size_t *offsetp, nc_type *field_typeidp, int *ndimsp, int *dim_sizesp) { NC* ncp; int stat = NC_check_id(ncid,&ncp); if(stat != NC_NOERR) return stat; return ncp->dispatch->inq_compound_field(ncid, xtype, fieldid, name, offsetp, field_typeidp, ndimsp, dim_sizesp); }
int NCCR_abort(int ncid) { int ncstat; NC* nc; LOG((1, "nc_abort: ncid 0x%x", ncid)); ncstat = NC_check_id(ncid, (NC**)&nc); if(ncstat != NC_NOERR) return ncstat; /* Turn into close */ return NCCR_close(ncid); }
int NC3_inq_var(int ncid, int varid, char *name, nc_type *typep, int *ndimsp, int *dimids, int *nattsp) { int status; NC *nc; NC3_INFO* ncp; NC_var *varp; size_t ii; status = NC_check_id(ncid, &nc); if(status != NC_NOERR) return status; ncp = NC3_DATA(nc); varp = elem_NC_vararray(&ncp->vars, (size_t)varid); if(varp == NULL) return NC_ENOTVAR; if(name != NULL) { (void) strncpy(name, varp->name->cp, varp->name->nchars); name[varp->name->nchars] = 0; } if(typep != 0) *typep = varp->type; if(ndimsp != 0) { *ndimsp = (int) varp->ndims; } if(dimids != 0) { for(ii = 0; ii < varp->ndims; ii++) { dimids[ii] = varp->dimids[ii]; } } if(nattsp != 0) { *nattsp = (int) varp->attrs.nelems; } return NC_NOERR; }
int NC3_def_var_fill(int ncid, int varid, int no_fill, const void *fill_value) { int status; NC *nc; NC3_INFO* ncp; NC_var *varp; status = NC_check_id(ncid, &nc); if(status != NC_NOERR) return status; ncp = NC3_DATA(nc); if(NC_readonly(ncp)) { return NC_EPERM; } if(!NC_indef(ncp)) { return NC_ENOTINDEFINE; } varp = elem_NC_vararray(&ncp->vars, (size_t)varid); if(varp == NULL) return NC_ENOTVAR; if (no_fill) varp->no_fill = 1; else varp->no_fill = 0; /* Are we setting a fill value? */ if (fill_value != NULL && !varp->no_fill) { /* If there's a _FillValue attribute, delete it. */ status = NC3_del_att(ncid, varid, _FillValue); if (status != NC_NOERR && status != NC_ENOTATT) return status; /* Create/overwrite attribute _FillValue */ status = NC3_put_att(ncid, varid, _FillValue, varp->type, 1, fill_value, varp->type); if (status != NC_NOERR) return status; } return NC_NOERR; }
/** \ingroup variables \internal Called by externally visible nc_get_varm_xxx routines */ static int NC_get_varm(int ncid, int varid, const size_t *start, const size_t *edges, const ptrdiff_t *stride, const ptrdiff_t* map, void *value, nc_type memtype) { NC* ncp; int stat = NC_check_id(ncid, &ncp); if(stat != NC_NOERR) return stat; #ifdef USE_NETCDF4 if(memtype >= NC_FIRSTUSERTYPEID) memtype = NC_NAT; #endif return ncp->dispatch->get_varm(ncid,varid,start,edges,stride,map,value,memtype); }
int nc_inq_natts(int ncid, int *nattsp) { int status; NC *ncp; status = NC_check_id(ncid, &ncp); if(status != NC_NOERR) return status; if(nattsp != NULL) *nattsp = (int) ncp->attrs.nelems; return NC_NOERR; }
static int NC5_close(int ncid) { NC* nc; NC5_INFO* nc5; int status = NC_check_id(ncid, &nc); if(status != NC_NOERR) goto done; status = ncmpi_close(nc->int_ncid); done: nc5 = NC5_DATA(nc); if(nc5 != NULL) free(nc5); /* reclaim allocated space */ return status; }
int nc_inq_unlimdim(int ncid, int *xtendimp) { int status; NC *ncp; status = NC_check_id(ncid, &ncp); if(status != NC_NOERR) return status; if(xtendimp != NULL) *xtendimp = find_NC_Udim(&ncp->dims, NULL); return NC_NOERR; }
/** * @ingroup variables * * Set the fill value for a variable. * * @note For netCDF classic, 64-bit offset, and CDF5 formats, it is * allowed (but not good practice) to set the fill value after data * have been written to the variable. In this case, unless the * variable has been completely specified (without gaps in the data), * any existing filled values will not be recognized as fill values by * applications reading the data. Best practice is to set the fill * value after the variable has been defined, but before any data have * been written to that varibale. In NetCDF-4 files, this is enforced * by the HDF5 library. For netCDF-4 files, an error is returned if * the user attempts to set the fill value after writing data to the * variable. * @param ncid NetCDF ID, from a previous call to nc_open or * nc_create. * @param varid Variable ID. * @param no_fill Set to NC_NOFILL to turn off fill mode for this * variable. Set to NC_FILL (the default) to turn on fill mode for the * variable. * @param fill_value the fill value to be used for this variable. Must * be the same type as the variable. This must point to enough free * memory to hold one element of the data type of the variable. (For * example, an NC_INT will require 4 bytes for it's fill value, which * is also an NC_INT.) * * @returns ::NC_NOERR No error. * @returns ::NC_EBADID Bad ID. * @returns ::NC_ENOTINDEFINE Not in define mode. This is returned * for netCDF classic, 64-bit offset, or 64-bit data files, or for * netCDF-4 files, when they were created with NC_STRICT_NC3 flag. See * @ref nc_create. * @returns ::NC_EPERM Attempt to create object in read-only file. * @returns ::NC_ELATEDEF (NetCDF-4 only). Returned when user attempts * to set fill value after data are written. * @returns ::NC_EGLOBAL Attempt to set fill value on NC_GLOBAL. * * @section nc_def_var_fill_example Example * * In this example from libsrc4/tst_vars.c, a variable is defined, and * the fill mode turned off. Then nc_inq_fill() is used to check that * the setting is correct. Then some data are written to the * variable. Since the data that are written do not cover the full * extent of the variable, the missing values will just be random. If * fill value mode was turned on, the missing values would get the * fill value. * @code #define DIM7_LEN 2 #define DIM7_NAME "dim_7_from_Indiana" #define VAR7_NAME "var_7_from_Idaho" #define NDIMS 1 int dimids[NDIMS]; size_t index[NDIMS]; int varid; int no_fill; unsigned short ushort_data = 42, ushort_data_in, fill_value_in; if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_dim(ncid, DIM7_NAME, DIM7_LEN, &dimids[0])) ERR; if (nc_def_var(ncid, VAR7_NAME, NC_USHORT, NDIMS, dimids, &varid)) ERR; if (nc_def_var_fill(ncid, varid, 1, NULL)) ERR; if (nc_inq_var_fill(ncid, varid, &no_fill, &fill_value_in)) ERR; if (!no_fill) ERR; index[0] = 1; if (nc_put_var1_ushort(ncid, varid, index, &ushort_data)) ERR; index[0] = 0; if (nc_get_var1_ushort(ncid, varid, index, &ushort_data_in)) ERR; if (nc_close(ncid)) ERR; @endcode * @author Glenn Davis, Ed Hartnett, Dennis Heimbigner */ int nc_def_var_fill(int ncid, int varid, int no_fill, const void *fill_value) { NC* ncp; int stat = NC_check_id(ncid,&ncp); if(stat != NC_NOERR) return stat; /* Dennis Heimbigner: Using NC_GLOBAL is illegal, as this API has no * provision for specifying the type of the fillvalue, it must of necessity * be using the type of the variable to interpret the bytes of the * fill_value argument. */ if (varid == NC_GLOBAL) return NC_EGLOBAL; return ncp->dispatch->def_var_fill(ncid,varid,no_fill,fill_value); }
int nc_enddef(int ncid) { int status; NC *ncp; status = NC_check_id(ncid, &ncp); if(status != NC_NOERR) return status; if(!NC_indef(ncp)) return(NC_ENOTINDEFINE); /* return(NC_endef(ncp, 0, 4096, 0, 4096)); */ return (NC_endef(ncp, 0, 1, 0, 1)); }
int nc_inq_format(int ncid, int *formatp) { int status; NC *ncp; status = NC_check_id(ncid, &ncp); if(status != NC_NOERR) return status; /* only need to check for netCDF-3 variants, since this is never called for netCDF-4 files */ *formatp = fIsSet(ncp->flags, NC_64BIT_OFFSET) ? NC_FORMAT_64BIT : NC_FORMAT_CLASSIC; return NC_NOERR; }
/*! \ingroup attributes Get an attribute of any type. The nc_get_att() functions works for any type of attribute, and must be used to get attributes of user-defined type. We recommend that they type safe versions of this function be used where possible. \param ncid NetCDF or group ID, from a previous call to nc_open(), nc_create(), nc_def_grp(), or associated inquiry functions such as nc_inq_ncid(). \param varid Variable ID of the attribute's variable, or ::NC_GLOBAL for a global attribute. \param name Attribute \ref object_name. \param value Pointer to location for returned attribute value(s). All elements of the vector of attribute values are returned, so you must allocate enough space to hold them. Before using the value as a C string, make sure it is null-terminated. Call nc_inq_attlen() first to find out the length of the attribute. \note See documentation for nc_get_att_string() regarding a special case where memory must be explicitly released. */ int nc_get_att(int ncid, int varid, const char *name, void *value) { NC* ncp; int stat = NC_NOERR; nc_type xtype; if ((stat = NC_check_id(ncid, &ncp))) return stat; /* Need to get the type */ if ((stat = nc_inq_atttype(ncid, varid, name, &xtype))) return stat; return ncp->dispatch->get_att(ncid, varid, name, value, xtype); }
/* This function will change the parallel access of a variable from * independent to collective. */ int nc_var_par_access(int ncid, int varid, int par_access) { NC* ncp; int stat = NC_NOERR; if ((stat = NC_check_id(ncid, &ncp))) return stat; #ifndef USE_PARALLEL return NC_ENOPAR; #else return ncp->dispatch->var_par_access(ncid,varid,par_access); #endif }
int nc__enddef(int ncid, size_t h_minfree, size_t v_align, size_t v_minfree, size_t r_align) { int status; NC *ncp; status = NC_check_id(ncid, &ncp); if(status != NC_NOERR) return status; if(!NC_indef(ncp)) return(NC_ENOTINDEFINE); return (NC_endef(ncp, h_minfree, v_align, v_minfree, r_align)); }
int nc_set_fill(int ncid, int fillmode, int *old_mode_ptr) { int status; NC *ncp; int oldmode; status = NC_check_id(ncid, &ncp); if(status != NC_NOERR) return status; if(NC_readonly(ncp)) return NC_EPERM; oldmode = fIsSet(ncp->flags, NC_NOFILL) ? NC_NOFILL : NC_FILL; if(fillmode == NC_NOFILL) { fSet(ncp->flags, NC_NOFILL); } else if(fillmode == NC_FILL) { if(fIsSet(ncp->flags, NC_NOFILL)) { /* * We are changing back to fill mode * so do a sync */ status = NC_sync(ncp); if(status != NC_NOERR) return status; } fClr(ncp->flags, NC_NOFILL); } else { return NC_EINVAL; /* Invalid fillmode */ } if(old_mode_ptr != NULL) *old_mode_ptr = oldmode; return NC_NOERR; }