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)
64 if (fIsSet(mode_flag,
NC_UDF0)) { count++; index = 0; }
65 if (fIsSet(mode_flag,
NC_UDF1)) { count++; index = 1; }
66 if (fIsSet(mode_flag,
NC_UDF2)) { count++; index = 2; }
67 if (fIsSet(mode_flag,
NC_UDF3)) { count++; index = 3; }
68 if (fIsSet(mode_flag,
NC_UDF4)) { count++; index = 4; }
69 if (fIsSet(mode_flag,
NC_UDF5)) { count++; index = 5; }
70 if (fIsSet(mode_flag,
NC_UDF6)) { count++; index = 6; }
71 if (fIsSet(mode_flag,
NC_UDF7)) { count++; index = 7; }
72 if (fIsSet(mode_flag,
NC_UDF8)) { count++; index = 8; }
73 if (fIsSet(mode_flag,
NC_UDF9)) { count++; index = 9; }
177 if (dispatch_table->dispatch_version != NC_DISPATCH_VERSION)
193 UDF_dispatch_tables[udf_index] = dispatch_table;
231 *dispatch_table = UDF_dispatch_tables[udf_index];
505 size_t *chunksizehintp,
int *ncidp)
507 return NC_create(path, cmode, initialsz, 0,
508 chunksizehintp, 0, NULL, ncidp);
554 return NC_create(path, mode, initialsize, 0, NULL, 0, NULL, ncidp);
577nc__create_mp(
const char *path,
int cmode,
size_t initialsz,
578 int basepe,
size_t *chunksizehintp,
int *ncidp)
580 return NC_create(path, cmode, initialsz, basepe,
581 chunksizehintp, 0, NULL, ncidp);
698nc_open(
const char *path,
int omode,
int *ncidp)
700 return NC_open(path, omode, 0, NULL, 0, NULL, ncidp);
756 size_t *chunksizehintp,
int *ncidp)
761 return NC_open(path, omode, 0, chunksizehintp, 0, NULL, ncidp);
810nc_open_mem(
const char* path,
int omode,
size_t size,
void* memory,
int* ncidp)
815 if(memory == NULL || size < MAGIC_NUMBER_LEN || path == NULL)
821 meminfo.memory = memory;
822 meminfo.flags = NC_MEMIO_LOCKED;
823 return NC_open(path, omode, 0, NULL, 0, &meminfo, ncidp);
878 if(path == NULL || params == NULL)
880 if(params->memory == NULL || params->size < MAGIC_NUMBER_LEN)
886 return NC_open(path, omode, 0, NULL, 0, params, ncidp);
908nc__open_mp(
const char *path,
int omode,
int basepe,
909 size_t *chunksizehintp,
int *ncidp)
911 return NC_open(path, omode, basepe, chunksizehintp, 0, NULL, ncidp);
936 if ((stat = NC_check_id(ncid, &ncp)))
938 if(ncp->path == NULL) {
939 if(pathlen) *pathlen = 0;
940 if(path) path[0] =
'\0';
942 if (pathlen) *pathlen = strlen(ncp->path);
943 if (path) strcpy(path, ncp->path);
1000 int stat = NC_check_id(ncid, &ncp);
1002 return ncp->dispatch->redef(ncid);
1065 status = NC_check_id(ncid, &ncp);
1066 if(status !=
NC_NOERR)
return status;
1067 return ncp->dispatch->_enddef(ncid,0,1,0,1);
1152nc__enddef(
int ncid,
size_t h_minfree,
size_t v_align,
size_t v_minfree,
1156 int stat = NC_check_id(ncid, &ncp);
1158 return ncp->dispatch->_enddef(ncid,h_minfree,v_align,v_minfree,r_align);
1232 int stat = NC_check_id(ncid, &ncp);
1234 return ncp->dispatch->sync(ncid);
1284 int stat = NC_check_id(ncid, &ncp);
1287 stat = ncp->dispatch->abort(ncid);
1288 del_from_NCList(ncp);
1337 int stat = NC_check_id(ncid, &ncp);
1340 stat = ncp->dispatch->close(ncid,NULL);
1344 del_from_NCList(ncp);
1396 int stat = NC_check_id(ncid, &ncp);
1399 stat = ncp->dispatch->close(ncid,memio);
1403 del_from_NCList(ncp);
1511 int stat = NC_check_id(ncid, &ncp);
1513 return ncp->dispatch->set_fill(ncid,fillmode,old_modep);
1531nc_inq_base_pe(
int ncid,
int *pe)
1534 int stat = NC_check_id(ncid, &ncp);
1555nc_set_base_pe(
int ncid,
int pe)
1558 int stat = NC_check_id(ncid, &ncp);
1584 int stat = NC_check_id(ncid, &ncp);
1586 return ncp->dispatch->inq_format(ncid,formatp);
1619 int stat = NC_check_id(ncid, &ncp);
1621 return ncp->dispatch->inq_format_extended(ncid,formatp,modep);
1669nc_inq(
int ncid,
int *ndimsp,
int *nvarsp,
int *nattsp,
int *unlimdimidp)
1672 int stat = NC_check_id(ncid, &ncp);
1674 return ncp->dispatch->inq(ncid,ndimsp,nvarsp,nattsp,unlimdimidp);
1691 int stat = NC_check_id(ncid, &ncp);
1693 return ncp->dispatch->inq(ncid, NULL, nvarsp, NULL, NULL);
1771 if(xtype <= ATOMICTYPEMAX4) {
1772 if(name) strncpy(name,NC_atomictypename(xtype),
NC_MAX_NAME);
1773 if(size) *size = NC_atomictypelen(xtype);
1778 stat = NC_check_id(ncid, &ncp);
1782 return ncp->dispatch->inq_type(ncid,xtype,name,size);
1820 if (mode_format && (mode_format & (mode_format - 1)))
1874NC_create(
const char *path0,
int cmode,
size_t initialsz,
1875 int basepe,
size_t *chunksizehintp,
int useparallel,
1876 void* parameters,
int *ncidp)
1883 char* newpath = NULL;
1895 if(!NC_initialized) {
1896 if ((stat = nc_initialize()))
goto done;
1901 const unsigned char* p;
1902 for(p=(
const unsigned char*)path0;*p;p++) {
if(*p >
' ')
break;}
1903 path = nulldup((
const char*)p);
1906 memset(&model,0,
sizeof(model));
1908 if((stat = NC_infermodel(path,&cmode,1,useparallel,NULL,&model,&newpath)))
goto done;
1915 assert(model.format != 0 && model.impl != 0);
1926#ifndef NETCDF_ENABLE_CDF5
1932 switch (model.impl) {
1935 dispatcher = HDF5_dispatch_table;
1940 dispatcher = NCP_dispatch_table;
1962 dispatcher = UDF_dispatch_tables[udf_index];
1971#ifdef NETCDF_ENABLE_NCZARR
1973 dispatcher = NCZ_dispatch_table;
1977 dispatcher = NC3_dispatch_table;
1984 if((stat = new_NC(dispatcher,path,cmode,&ncp)))
goto done;
1990 if ((stat = dispatcher->create(ncp->path, cmode, initialsz, basepe, chunksizehintp,
1991 parameters, dispatcher, ncp->ext_ncid))) {
1992 del_from_NCList(ncp);
1995 if(ncidp)*ncidp = ncp->ext_ncid;
2027NC_open(
const char *path0,
int omode,
int basepe,
size_t *chunksizehintp,
2028 int useparallel,
void* parameters,
int *ncidp)
2038 char* newpath = NULL;
2041 if(!NC_initialized) {
2042 stat = nc_initialize();
2056 if(diskless && inmemory) {stat =
NC_EDISKLESS;
goto done;}
2057 if(diskless && use_mmap) {stat =
NC_EDISKLESS;
goto done;}
2058 if(inmemory && use_mmap) {stat =
NC_EINMEMORY;
goto done;}
2071 for(p=(
const char*)path0;*p;p++) {
if(*p < 0 || *p >
' ')
break;}
2075 memset(&model,0,
sizeof(model));
2077 if((stat = NC_infermodel(path,&omode,0,useparallel,parameters,&model,&newpath)))
2086 if(model.impl == 0) {
2088 fprintf(stderr,
"implementation == 0\n");
2102 int nczarrbuilt = 0;
2109#ifdef NETCDF_ENABLE_CDF5
2112#ifdef NETCDF_ENABLE_NCZARR
2119 if(UDF_dispatch_tables[i] != NULL)
2135 if(!udfbuilt[i] && model.impl == formatx)
2149#ifdef NETCDF_ENABLE_NCZARR
2152#ifdef NETCDF_ENABLE_DAP
2155#ifdef NETCDF_ENABLE_DAP4
2165 if(UDF_dispatch_tables[i] != NULL) {
2168 built |= (1U << formatx);
2172 if((built & (1U << model.impl)) == 0)
2174#ifndef NETCDF_ENABLE_CDF5
2183 switch (model.impl) {
2184#ifdef NETCDF_ENABLE_DAP
2186 dispatcher = NCD2_dispatch_table;
2189#ifdef NETCDF_ENABLE_DAP4
2191 dispatcher = NCD4_dispatch_table;
2194#ifdef NETCDF_ENABLE_NCZARR
2196 dispatcher = NCZ_dispatch_table;
2201 dispatcher = NCP_dispatch_table;
2206 dispatcher = HDF5_dispatch_table;
2211 dispatcher = HDF4_dispatch_table;
2233 dispatcher = UDF_dispatch_tables[udf_index];