18#ifdef HAVE_SYS_RESOURCE_H
19#include <sys/resource.h>
21#ifdef HAVE_SYS_TYPES_H
36#include "ncdispatch.h"
44 #define nulldup(s) ((s)?strdup(s):NULL)
49NC_Dispatch *UDF0_dispatch_table = NULL;
51NC_Dispatch *UDF1_dispatch_table = NULL;
132 if (dispatch_table->dispatch_version != NC_DISPATCH_VERSION)
144 UDF0_dispatch_table = dispatch_table;
148 else if(fIsSet(mode_flag,
NC_UDF1))
150 UDF1_dispatch_table = dispatch_table;
185 *dispatch_table = UDF0_dispatch_table;
189 else if(fIsSet(mode_flag,
NC_UDF1))
192 *dispatch_table = UDF1_dispatch_table;
471 size_t *chunksizehintp,
int *ncidp)
473 return NC_create(path, cmode, initialsz, 0,
474 chunksizehintp, 0, NULL, ncidp);
520 return NC_create(path, mode, initialsize, 0, NULL, 0, NULL, ncidp);
543nc__create_mp(
const char *path,
int cmode,
size_t initialsz,
544 int basepe,
size_t *chunksizehintp,
int *ncidp)
546 return NC_create(path, cmode, initialsz, basepe,
547 chunksizehintp, 0, NULL, ncidp);
664nc_open(
const char *path,
int omode,
int *ncidp)
666 return NC_open(path, omode, 0, NULL, 0, NULL, ncidp);
722 size_t *chunksizehintp,
int *ncidp)
727 return NC_open(path, omode, 0, chunksizehintp, 0, NULL, ncidp);
776nc_open_mem(
const char* path,
int omode,
size_t size,
void* memory,
int* ncidp)
781 if(memory == NULL || size < MAGIC_NUMBER_LEN || path == NULL)
787 meminfo.memory = memory;
788 meminfo.flags = NC_MEMIO_LOCKED;
789 return NC_open(path, omode, 0, NULL, 0, &meminfo, ncidp);
844 if(path == NULL || params == NULL)
846 if(params->memory == NULL || params->size < MAGIC_NUMBER_LEN)
852 return NC_open(path, omode, 0, NULL, 0, params, ncidp);
874nc__open_mp(
const char *path,
int omode,
int basepe,
875 size_t *chunksizehintp,
int *ncidp)
877 return NC_open(path, omode, basepe, chunksizehintp, 0, NULL, ncidp);
902 if ((stat = NC_check_id(ncid, &ncp)))
904 if(ncp->path == NULL) {
905 if(pathlen) *pathlen = 0;
906 if(path) path[0] =
'\0';
908 if (pathlen) *pathlen = strlen(ncp->path);
909 if (path) strcpy(path, ncp->path);
966 int stat = NC_check_id(ncid, &ncp);
968 return ncp->dispatch->redef(ncid);
1031 status = NC_check_id(ncid, &ncp);
1032 if(status !=
NC_NOERR)
return status;
1033 return ncp->dispatch->_enddef(ncid,0,1,0,1);
1118nc__enddef(
int ncid,
size_t h_minfree,
size_t v_align,
size_t v_minfree,
1122 int stat = NC_check_id(ncid, &ncp);
1124 return ncp->dispatch->_enddef(ncid,h_minfree,v_align,v_minfree,r_align);
1198 int stat = NC_check_id(ncid, &ncp);
1200 return ncp->dispatch->sync(ncid);
1250 int stat = NC_check_id(ncid, &ncp);
1253 stat = ncp->dispatch->abort(ncid);
1254 del_from_NCList(ncp);
1303 int stat = NC_check_id(ncid, &ncp);
1306 stat = ncp->dispatch->close(ncid,NULL);
1310 del_from_NCList(ncp);
1362 int stat = NC_check_id(ncid, &ncp);
1365 stat = ncp->dispatch->close(ncid,memio);
1369 del_from_NCList(ncp);
1477 int stat = NC_check_id(ncid, &ncp);
1479 return ncp->dispatch->set_fill(ncid,fillmode,old_modep);
1497nc_inq_base_pe(
int ncid,
int *pe)
1500 int stat = NC_check_id(ncid, &ncp);
1521nc_set_base_pe(
int ncid,
int pe)
1524 int stat = NC_check_id(ncid, &ncp);
1550 int stat = NC_check_id(ncid, &ncp);
1552 return ncp->dispatch->inq_format(ncid,formatp);
1585 int stat = NC_check_id(ncid, &ncp);
1587 return ncp->dispatch->inq_format_extended(ncid,formatp,modep);
1635nc_inq(
int ncid,
int *ndimsp,
int *nvarsp,
int *nattsp,
int *unlimdimidp)
1638 int stat = NC_check_id(ncid, &ncp);
1640 return ncp->dispatch->inq(ncid,ndimsp,nvarsp,nattsp,unlimdimidp);
1657 int stat = NC_check_id(ncid, &ncp);
1659 return ncp->dispatch->inq(ncid, NULL, nvarsp, NULL, NULL);
1737 if(xtype <= ATOMICTYPEMAX4) {
1738 if(name) strncpy(name,NC_atomictypename(xtype),
NC_MAX_NAME);
1739 if(size) *size = NC_atomictypelen(xtype);
1744 stat = NC_check_id(ncid, &ncp);
1748 return ncp->dispatch->inq_type(ncid,xtype,name,size);
1786 if (mode_format && (mode_format & (mode_format - 1)))
1840NC_create(
const char *path0,
int cmode,
size_t initialsz,
1841 int basepe,
size_t *chunksizehintp,
int useparallel,
1842 void* parameters,
int *ncidp)
1846 const NC_Dispatch* dispatcher = NULL;
1849 char* newpath = NULL;
1861 if(!NC_initialized) {
1862 if ((stat = nc_initialize()))
goto done;
1867 const unsigned char* p;
1868 for(p=(
const unsigned char*)path0;*p;p++) {
if(*p >
' ')
break;}
1869 path = nulldup((
const char*)p);
1872 memset(&model,0,
sizeof(model));
1874 if((stat = NC_infermodel(path,&cmode,1,useparallel,NULL,&model,&newpath)))
goto done;
1881 assert(model.format != 0 && model.impl != 0);
1892#ifndef NETCDF_ENABLE_CDF5
1898 switch (model.impl) {
1901 dispatcher = HDF5_dispatch_table;
1906 dispatcher = NCP_dispatch_table;
1911 dispatcher = UDF0_dispatch_table;
1914 dispatcher = UDF1_dispatch_table;
1917#ifdef NETCDF_ENABLE_NCZARR
1919 dispatcher = NCZ_dispatch_table;
1923 dispatcher = NC3_dispatch_table;
1930 if((stat = new_NC(dispatcher,path,cmode,&ncp)))
goto done;
1936 if ((stat = dispatcher->create(ncp->path, cmode, initialsz, basepe, chunksizehintp,
1937 parameters, dispatcher, ncp->ext_ncid))) {
1938 del_from_NCList(ncp);
1941 if(ncidp)*ncidp = ncp->ext_ncid;
1973NC_open(
const char *path0,
int omode,
int basepe,
size_t *chunksizehintp,
1974 int useparallel,
void* parameters,
int *ncidp)
1978 const NC_Dispatch* dispatcher = NULL;
1984 char* newpath = NULL;
1987 if(!NC_initialized) {
1988 stat = nc_initialize();
2002 if(diskless && inmemory) {stat =
NC_EDISKLESS;
goto done;}
2003 if(diskless && use_mmap) {stat =
NC_EDISKLESS;
goto done;}
2004 if(inmemory && use_mmap) {stat =
NC_EINMEMORY;
goto done;}
2017 for(p=(
const char*)path0;*p;p++) {
if(*p < 0 || *p >
' ')
break;}
2021 memset(&model,0,
sizeof(model));
2023 if((stat = NC_infermodel(path,&omode,0,useparallel,parameters,&model,&newpath)))
2032 if(model.impl == 0) {
2034 fprintf(stderr,
"implementation == 0\n");
2048 int nczarrbuilt = 0;
2055#ifdef NETCDF_ENABLE_CDF5
2058#ifdef NETCDF_ENABLE_NCZARR
2061 if(UDF0_dispatch_table != NULL)
2063 if(UDF1_dispatch_table != NULL)
2089#ifdef NETCDF_ENABLE_NCZARR
2092#ifdef NETCDF_ENABLE_DAP
2095#ifdef NETCDF_ENABLE_DAP4
2102 if(UDF0_dispatch_table != NULL)
2104 if(UDF1_dispatch_table != NULL)
2107 if((built & (1 << model.impl)) == 0)
2109#ifndef NETCDF_ENABLE_CDF5
2118 switch (model.impl) {
2119#ifdef NETCDF_ENABLE_DAP
2121 dispatcher = NCD2_dispatch_table;
2124#ifdef NETCDF_ENABLE_DAP4
2126 dispatcher = NCD4_dispatch_table;
2129#ifdef NETCDF_ENABLE_NCZARR
2131 dispatcher = NCZ_dispatch_table;
2136 dispatcher = NCP_dispatch_table;
2141 dispatcher = HDF5_dispatch_table;
2146 dispatcher = HDF4_dispatch_table;
2151 dispatcher = UDF0_dispatch_table;
2154 dispatcher = UDF1_dispatch_table;
2158 dispatcher = NC3_dispatch_table;
2168 if (!dispatcher) {stat =
NC_ENOTNC;
goto done;}
2171 if((stat = new_NC(dispatcher,path,omode,&ncp)))
goto done;
2177 stat = dispatcher->open(ncp->path, omode, basepe, chunksizehintp,
2178 parameters, dispatcher, ncp->ext_ncid);
2180 if(ncidp) *ncidp = ncp->ext_ncid;
2182 del_from_NCList(ncp);
2197static int pseudofd = 0;
2210#ifdef HAVE_GETRLIMIT
2213 if(getrlimit(RLIMIT_NOFILE,&rl) == 0) {
2214 if(rl.rlim_max != RLIM_INFINITY)
2215 maxfd = (int)rl.rlim_max;
2216 if(rl.rlim_cur != RLIM_INFINITY)
2217 maxfd = (int)rl.rlim_cur;
int nc_inq_nvars(int ncid, int *nvarsp)
Learn the number of variables in a file or group.
int nc_inq_user_format(int mode_flag, NC_Dispatch **dispatch_table, char *magic_number)
Inquire about user-defined format.
int nc__create(const char *path, int cmode, size_t initialsz, size_t *chunksizehintp, int *ncidp)
Create a netCDF file with some extra parameters controlling classic file caching.
int nc_close(int ncid)
Close an open netCDF dataset.
int nc_abort(int ncid)
No longer necessary for user to invoke manually.
int nc_create(const char *path, int cmode, int *ncidp)
Create a new netCDF file.
int nc_inq(int ncid, int *ndimsp, int *nvarsp, int *nattsp, int *unlimdimidp)
Inquire about a file or group.
int nc_inq_format_extended(int ncid, int *formatp, int *modep)
Obtain more detailed (vis-a-vis nc_inq_format) format information about an open dataset.
int nc_close_memio(int ncid, NC_memio *memio)
Do a normal close (see nc_close()) on an in-memory dataset, then return a copy of the final memory co...
int nc__enddef(int ncid, size_t h_minfree, size_t v_align, size_t v_minfree, size_t r_align)
Leave define mode with performance tuning.
int nc_set_fill(int ncid, int fillmode, int *old_modep)
Change the fill-value mode to improve write performance.
int nc_create_mem(const char *path, int mode, size_t initialsize, int *ncidp)
Create a netCDF file with the contents stored in memory.
int nc__open(const char *path, int omode, size_t *chunksizehintp, int *ncidp)
Open a netCDF file with extra performance parameters for the classic library.
int nc_inq_path(int ncid, size_t *pathlen, char *path)
Get the file pathname (or the opendap URL) which was used to open/create the ncid's file.
int nc_open_mem(const char *path, int omode, size_t size, void *memory, int *ncidp)
Open a netCDF file with the contents taken from a block of memory.
int nc_def_user_format(int mode_flag, NC_Dispatch *dispatch_table, char *magic_number)
Add handling of user-defined format.
int nc_inq_type(int ncid, nc_type xtype, char *name, size_t *size)
Inquire about a type.
int nc_enddef(int ncid)
Leave define mode.
int nc_redef(int ncid)
Put open netcdf dataset into define mode.
int nc_open(const char *path, int omode, int *ncidp)
Open an existing netCDF file.
int nc_open_memio(const char *path, int omode, NC_memio *params, int *ncidp)
Open a netCDF file with the contents taken from a block of memory.
int nc_inq_format(int ncid, int *formatp)
Inquire about the binary format of a netCDF file as presented by the API.
int nc_sync(int ncid)
Synchronize an open netcdf dataset to disk.
static int check_create_mode(int mode)
Check the create mode parameter for sanity.
#define NC_MAX_MAGIC_NUMBER_LEN
Max len of user-defined format magic number.
#define NC_NETCDF4
Use netCDF-4/HDF5 format.
#define NC_UDF0
User-defined format 0.
#define NC_EDISKLESS
Error in using diskless access.
#define NC_SIZEHINT_DEFAULT
Let nc__create() or nc__open() figure out a suitable buffer size.
#define NC_EBADTYPE
Not a netcdf data type.
#define NC_INMEMORY
Read from memory.
#define NC_CDF5
Alias NC_CDF5 to NC_64BIT_DATA.
#define NC_FORMATX_NC3
Extended format specifier returned by nc_inq_format_extended() Added in version 4....
#define NC_FORMATX_NCZARR
Added in version 4.8.0.
#define NC_ENOTNC
Not a netcdf file.
#define NC_NAT
Not A Type.
#define NC_64BIT_OFFSET
Use large (64-bit) file offsets.
#define NC_EINMEMORY
In-memory file error.
#define NC_FORMATX_UDF1
Extended format specifier returned by nc_inq_format_extended() Added in version 4....
#define NC_FORMATX_PNETCDF
Extended format specifier returned by nc_inq_format_extended() Added in version 4....
#define NC_FORMAT_CDF5
Format specifier for nc_set_default_format() and returned by nc_inq_format.
#define NC_FORMATX_NC_HDF4
netCDF-4 subset of HDF4
#define NC_WRITE
Set read-write access for nc_open().
#define NC_FORMATX_NC_HDF5
netCDF-4 subset of HDF5
#define NC_FORMATX_DAP4
Extended format specifier returned by nc_inq_format_extended() Added in version 4....
#define NC_FORMATX_UDF0
Extended format specifier returned by nc_inq_format_extended() Added in version 4....
#define NC_DISKLESS
Use diskless file.
#define NC_FORMATX_DAP2
Extended format specifier returned by nc_inq_format_extended() Added in version 4....
#define NC_EINVAL
Invalid Argument.
#define NC_CLASSIC_MODEL
Enforce classic model on netCDF-4.
#define NC_MAX_NAME
Maximum for classic library.
#define NC_NOERR
No Error.
#define NC_64BIT_DATA
CDF-5 format: classic model but 64 bit dimensions and sizes.
#define NC_ENOTBUILT
Attempt to use feature that was not turned on when netCDF was built.
#define NC_UDF1
User-defined format 1.
int nc_type
The nc_type type is just an int.
#define NC_FORMATX_NC4
alias
Main header file for in-memory (diskless) functionality.