18 #ifdef HAVE_SYS_RESOURCE_H
19 #include <sys/resource.h>
21 #ifdef HAVE_SYS_TYPES_H
22 #include <sys/types.h>
24 #ifdef HAVE_SYS_STAT_H
36 #include "ncdispatch.h"
38 #include "ncpathmgr.h"
46 NC_Dispatch *UDF0_dispatch_table = NULL;
48 NC_Dispatch *UDF1_dispatch_table = NULL;
131 if (dispatch_table->dispatch_version != NC_DISPATCH_VERSION)
139 UDF0_dispatch_table = dispatch_table;
144 UDF1_dispatch_table = dispatch_table;
180 *dispatch_table = UDF0_dispatch_table;
186 *dispatch_table = UDF1_dispatch_table;
462 size_t *chunksizehintp,
int *ncidp)
464 return NC_create(path, cmode, initialsz, 0,
465 chunksizehintp, 0, NULL, ncidp);
511 return NC_create(path, mode, initialsize, 0, NULL, 0, NULL, ncidp);
534 nc__create_mp(
const char *path,
int cmode,
size_t initialsz,
535 int basepe,
size_t *chunksizehintp,
int *ncidp)
537 return NC_create(path, cmode, initialsz, basepe,
538 chunksizehintp, 0, NULL, ncidp);
655 nc_open(
const char *path,
int omode,
int *ncidp)
657 return NC_open(path, omode, 0, NULL, 0, NULL, ncidp);
713 size_t *chunksizehintp,
int *ncidp)
718 return NC_open(path, omode, 0, chunksizehintp, 0, NULL, ncidp);
767 nc_open_mem(
const char* path,
int omode,
size_t size,
void* memory,
int* ncidp)
772 if(memory == NULL || size < MAGIC_NUMBER_LEN || path == NULL)
778 meminfo.memory = memory;
779 meminfo.flags = NC_MEMIO_LOCKED;
780 return NC_open(path, omode, 0, NULL, 0, &meminfo, ncidp);
835 if(path == NULL || params == NULL)
837 if(params->memory == NULL || params->size < MAGIC_NUMBER_LEN)
843 return NC_open(path, omode, 0, NULL, 0, params, ncidp);
865 nc__open_mp(
const char *path,
int omode,
int basepe,
866 size_t *chunksizehintp,
int *ncidp)
868 return NC_open(path, omode, basepe, chunksizehintp, 0, NULL, ncidp);
893 if ((stat = NC_check_id(ncid, &ncp)))
895 if(ncp->path == NULL) {
896 if(pathlen) *pathlen = 0;
897 if(path) path[0] =
'\0';
899 if (pathlen) *pathlen = strlen(ncp->path);
900 if (path) strcpy(path, ncp->path);
957 int stat = NC_check_id(ncid, &ncp);
959 return ncp->dispatch->redef(ncid);
1022 status = NC_check_id(ncid, &ncp);
1023 if(status !=
NC_NOERR)
return status;
1024 return ncp->dispatch->_enddef(ncid,0,1,0,1);
1109 nc__enddef(
int ncid,
size_t h_minfree,
size_t v_align,
size_t v_minfree,
1113 int stat = NC_check_id(ncid, &ncp);
1115 return ncp->dispatch->_enddef(ncid,h_minfree,v_align,v_minfree,r_align);
1189 int stat = NC_check_id(ncid, &ncp);
1191 return ncp->dispatch->sync(ncid);
1241 int stat = NC_check_id(ncid, &ncp);
1244 stat = ncp->dispatch->abort(ncid);
1245 del_from_NCList(ncp);
1294 int stat = NC_check_id(ncid, &ncp);
1297 stat = ncp->dispatch->close(ncid,NULL);
1301 del_from_NCList(ncp);
1353 int stat = NC_check_id(ncid, &ncp);
1356 stat = ncp->dispatch->close(ncid,memio);
1360 del_from_NCList(ncp);
1468 int stat = NC_check_id(ncid, &ncp);
1470 return ncp->dispatch->set_fill(ncid,fillmode,old_modep);
1488 nc_inq_base_pe(
int ncid,
int *pe)
1491 int stat = NC_check_id(ncid, &ncp);
1512 nc_set_base_pe(
int ncid,
int pe)
1515 int stat = NC_check_id(ncid, &ncp);
1541 int stat = NC_check_id(ncid, &ncp);
1543 return ncp->dispatch->inq_format(ncid,formatp);
1576 int stat = NC_check_id(ncid, &ncp);
1578 return ncp->dispatch->inq_format_extended(ncid,formatp,modep);
1626 nc_inq(
int ncid,
int *ndimsp,
int *nvarsp,
int *nattsp,
int *unlimdimidp)
1629 int stat = NC_check_id(ncid, &ncp);
1631 return ncp->dispatch->inq(ncid,ndimsp,nvarsp,nattsp,unlimdimidp);
1648 int stat = NC_check_id(ncid, &ncp);
1650 return ncp->dispatch->inq(ncid, NULL, nvarsp, NULL, NULL);
1728 if(xtype <= ATOMICTYPEMAX4) {
1729 if(name) strncpy(name,NC_atomictypename(xtype),
NC_MAX_NAME);
1730 if(size) *size = NC_atomictypelen(xtype);
1735 stat = NC_check_id(ncid, &ncp);
1739 return ncp->dispatch->inq_type(ncid,xtype,name,size);
1770 if (mode_format && (mode_format & (mode_format - 1)))
1824 NC_create(
const char *path0,
int cmode,
size_t initialsz,
1825 int basepe,
size_t *chunksizehintp,
int useparallel,
1826 void* parameters,
int *ncidp)
1830 const NC_Dispatch* dispatcher = NULL;
1833 char* newpath = NULL;
1848 if ((stat = nc_initialize()))
1854 const unsigned char* p;
1855 for(p=(
const unsigned char*)path0;*p;p++) {
if(*p >
' ')
break;}
1856 path = nulldup((
const char*)p);
1859 memset(&model,0,
sizeof(model));
1861 if((stat = NC_infermodel(path,&cmode,1,useparallel,NULL,&model,&newpath))) {
1871 assert(model.format != 0 && model.impl != 0);
1888 switch (model.impl) {
1891 dispatcher = HDF5_dispatch_table;
1896 dispatcher = NCP_dispatch_table;
1901 dispatcher = UDF0_dispatch_table;
1904 dispatcher = UDF1_dispatch_table;
1907 #ifdef ENABLE_NCZARR
1909 dispatcher = NCZ_dispatch_table;
1913 dispatcher = NC3_dispatch_table;
1920 if((stat = new_NC(dispatcher,path,cmode,&ncp)))
goto done;
1926 if ((stat = dispatcher->create(ncp->path, cmode, initialsz, basepe, chunksizehintp,
1927 parameters, dispatcher, ncp->ext_ncid))) {
1928 del_from_NCList(ncp);
1931 if(ncidp)*ncidp = ncp->ext_ncid;
1962 NC_open(
const char *path0,
int omode,
int basepe,
size_t *chunksizehintp,
1963 int useparallel,
void* parameters,
int *ncidp)
1967 const NC_Dispatch* dispatcher = NULL;
1973 char* newpath = NULL;
1977 stat = nc_initialize();
1978 if(stat)
return stat;
1991 if(diskless && inmemory) {stat =
NC_EDISKLESS;
goto done;}
2006 for(p=(
const char*)path0;*p;p++) {
if(*p < 0 || *p >
' ')
break;}
2010 memset(&model,0,
sizeof(model));
2012 if((stat = NC_infermodel(path,&omode,0,useparallel,parameters,&model,&newpath)))
2021 if(model.impl == 0) {
2023 fprintf(stderr,
"implementation == 0\n");
2036 int nczarrbuilt = 0;
2046 #ifdef ENABLE_NCZARR
2049 if(UDF0_dispatch_table != NULL)
2051 if(UDF1_dispatch_table != NULL)
2069 switch (model.impl) {
2072 dispatcher = NCD2_dispatch_table;
2077 dispatcher = NCD4_dispatch_table;
2080 #ifdef ENABLE_NCZARR
2082 dispatcher = NCZ_dispatch_table;
2087 dispatcher = NCP_dispatch_table;
2092 dispatcher = HDF5_dispatch_table;
2097 dispatcher = HDF4_dispatch_table;
2102 dispatcher = UDF0_dispatch_table;
2105 dispatcher = UDF1_dispatch_table;
2109 dispatcher = NC3_dispatch_table;
2119 if (!dispatcher) {stat =
NC_ENOTNC;
goto done;}
2122 if((stat = new_NC(dispatcher,path,omode,&ncp)))
goto done;
2128 stat = dispatcher->open(ncp->path, omode, basepe, chunksizehintp,
2129 parameters, dispatcher, ncp->ext_ncid);
2131 if(ncidp) *ncidp = ncp->ext_ncid;
2133 del_from_NCList(ncp);
2148 static int pseudofd = 0;
2162 #ifdef HAVE_GETRLIMIT
2164 if(getrlimit(RLIMIT_NOFILE,&rl) == 0) {
2165 if(rl.rlim_max != RLIM_INFINITY)
2166 maxfd = (int)rl.rlim_max;
2167 if(rl.rlim_cur != RLIM_INFINITY)
2168 maxfd = (int)rl.rlim_cur;