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 "ncwinpath.h"
46 NC_Dispatch *UDF0_dispatch_table = NULL;
48 NC_Dispatch *UDF1_dispatch_table = NULL;
119 UDF0_dispatch_table = dispatch_table;
124 UDF1_dispatch_table = dispatch_table;
160 *dispatch_table = UDF0_dispatch_table;
166 *dispatch_table = UDF1_dispatch_table;
442 size_t *chunksizehintp,
int *ncidp)
444 return NC_create(path, cmode, initialsz, 0,
445 chunksizehintp, 0, NULL, ncidp);
491 return NC_create(path, mode, initialsize, 0, NULL, 0, NULL, ncidp);
514 nc__create_mp(
const char *path,
int cmode,
size_t initialsz,
515 int basepe,
size_t *chunksizehintp,
int *ncidp)
517 return NC_create(path, cmode, initialsz, basepe,
518 chunksizehintp, 0, NULL, ncidp);
635 nc_open(
const char *path,
int omode,
int *ncidp)
637 return NC_open(path, omode, 0, NULL, 0, NULL, ncidp);
693 size_t *chunksizehintp,
int *ncidp)
698 return NC_open(path, omode, 0, chunksizehintp, 0, NULL, ncidp);
747 nc_open_mem(
const char* path,
int omode,
size_t size,
void* memory,
int* ncidp)
752 if(memory == NULL || size < MAGIC_NUMBER_LEN || path == NULL)
758 meminfo.memory = memory;
759 meminfo.flags = NC_MEMIO_LOCKED;
760 return NC_open(path, omode, 0, NULL, 0, &meminfo, ncidp);
815 if(path == NULL || params == NULL)
817 if(params->memory == NULL || params->size < MAGIC_NUMBER_LEN)
823 return NC_open(path, omode, 0, NULL, 0, params, ncidp);
845 nc__open_mp(
const char *path,
int omode,
int basepe,
846 size_t *chunksizehintp,
int *ncidp)
848 return NC_open(path, omode, basepe, chunksizehintp, 0, NULL, ncidp);
873 if ((stat = NC_check_id(ncid, &ncp)))
875 if(ncp->path == NULL) {
876 if(pathlen) *pathlen = 0;
877 if(path) path[0] =
'\0';
879 if (pathlen) *pathlen = strlen(ncp->path);
880 if (path) strcpy(path, ncp->path);
937 int stat = NC_check_id(ncid, &ncp);
939 return ncp->dispatch->redef(ncid);
1002 status = NC_check_id(ncid, &ncp);
1003 if(status !=
NC_NOERR)
return status;
1004 return ncp->dispatch->_enddef(ncid,0,1,0,1);
1089 nc__enddef(
int ncid,
size_t h_minfree,
size_t v_align,
size_t v_minfree,
1093 int stat = NC_check_id(ncid, &ncp);
1095 return ncp->dispatch->_enddef(ncid,h_minfree,v_align,v_minfree,r_align);
1169 int stat = NC_check_id(ncid, &ncp);
1171 return ncp->dispatch->sync(ncid);
1221 int stat = NC_check_id(ncid, &ncp);
1224 stat = ncp->dispatch->abort(ncid);
1225 del_from_NCList(ncp);
1274 int stat = NC_check_id(ncid, &ncp);
1277 stat = ncp->dispatch->close(ncid,NULL);
1281 del_from_NCList(ncp);
1333 int stat = NC_check_id(ncid, &ncp);
1336 stat = ncp->dispatch->close(ncid,memio);
1340 del_from_NCList(ncp);
1448 int stat = NC_check_id(ncid, &ncp);
1450 return ncp->dispatch->set_fill(ncid,fillmode,old_modep);
1468 nc_inq_base_pe(
int ncid,
int *pe)
1471 int stat = NC_check_id(ncid, &ncp);
1492 nc_set_base_pe(
int ncid,
int pe)
1495 int stat = NC_check_id(ncid, &ncp);
1521 int stat = NC_check_id(ncid, &ncp);
1523 return ncp->dispatch->inq_format(ncid,formatp);
1556 int stat = NC_check_id(ncid, &ncp);
1558 return ncp->dispatch->inq_format_extended(ncid,formatp,modep);
1606 nc_inq(
int ncid,
int *ndimsp,
int *nvarsp,
int *nattsp,
int *unlimdimidp)
1609 int stat = NC_check_id(ncid, &ncp);
1611 return ncp->dispatch->inq(ncid,ndimsp,nvarsp,nattsp,unlimdimidp);
1628 int stat = NC_check_id(ncid, &ncp);
1630 return ncp->dispatch->inq(ncid, NULL, nvarsp, NULL, NULL);
1708 if(xtype <= ATOMICTYPEMAX4) {
1709 if(name) strncpy(name,NC_atomictypename(xtype),
NC_MAX_NAME);
1710 if(size) *size = NC_atomictypelen(xtype);
1715 stat = NC_check_id(ncid, &ncp);
1719 return ncp->dispatch->inq_type(ncid,xtype,name,size);
1750 if (mode_format && (mode_format & (mode_format - 1)))
1804 NC_create(
const char *path0,
int cmode,
size_t initialsz,
1805 int basepe,
size_t *chunksizehintp,
int useparallel,
1806 void* parameters,
int *ncidp)
1810 const NC_Dispatch* dispatcher = NULL;
1813 char* newpath = NULL;
1828 if ((stat = nc_initialize()))
1835 for(p=(
char*)path0;*p;p++) {
if(*p >
' ')
break;}
1838 path = NCpathcvt(p);
1844 memset(&model,0,
sizeof(model));
1845 if((stat = NC_infermodel(path,&cmode,1,useparallel,NULL,&model,&newpath)))
1853 assert(model.format != 0 && model.impl != 0);
1870 switch (model.impl) {
1873 dispatcher = HDF5_dispatch_table;
1878 dispatcher = NCP_dispatch_table;
1883 dispatcher = UDF0_dispatch_table;
1886 dispatcher = UDF1_dispatch_table;
1890 dispatcher = NC3_dispatch_table;
1897 if((stat = new_NC(dispatcher,path,cmode,&ncp)))
goto done;
1903 if ((stat = dispatcher->create(ncp->path, cmode, initialsz, basepe, chunksizehintp,
1904 parameters, dispatcher, ncp->ext_ncid))) {
1905 del_from_NCList(ncp);
1908 if(ncidp)*ncidp = ncp->ext_ncid;
1939 NC_open(
const char *path0,
int omode,
int basepe,
size_t *chunksizehintp,
1940 int useparallel,
void* parameters,
int *ncidp)
1944 const NC_Dispatch* dispatcher = NULL;
1950 char* newpath = NULL;
1954 stat = nc_initialize();
1955 if(stat)
return stat;
1968 if(diskless && inmemory) {stat =
NC_EDISKLESS;
goto done;}
1983 for(p=(
char*)path0;*p;p++) {
if(*p >
' ')
break;}
1986 path = NCpathcvt(p);
1992 memset(&model,0,
sizeof(model));
1994 if((stat = NC_infermodel(path,&omode,0,useparallel,parameters,&model,&newpath)))
2002 if(model.impl == 0) {
2004 fprintf(stderr,
"implementation == 0\n");
2025 if(UDF0_dispatch_table != NULL)
2027 if(UDF1_dispatch_table != NULL)
2043 switch (model.impl) {
2046 dispatcher = NCD2_dispatch_table;
2051 dispatcher = NCD4_dispatch_table;
2056 dispatcher = NCP_dispatch_table;
2061 dispatcher = HDF5_dispatch_table;
2066 dispatcher = HDF4_dispatch_table;
2071 dispatcher = UDF0_dispatch_table;
2074 dispatcher = UDF1_dispatch_table;
2078 dispatcher = NC3_dispatch_table;
2088 if (!dispatcher) {stat =
NC_ENOTNC;
goto done;}
2091 if((stat = new_NC(dispatcher,path,omode,&ncp)))
goto done;
2097 stat = dispatcher->open(ncp->path, omode, basepe, chunksizehintp,
2098 parameters, dispatcher, ncp->ext_ncid);
2100 if(ncidp) *ncidp = ncp->ext_ncid;
2102 del_from_NCList(ncp);
2116 static int pseudofd = 0;
2130 #ifdef HAVE_GETRLIMIT
2132 if(getrlimit(RLIMIT_NOFILE,&rl) == 0) {
2133 if(rl.rlim_max != RLIM_INFINITY)
2134 maxfd = (int)rl.rlim_max;
2135 if(rl.rlim_cur != RLIM_INFINITY)
2136 maxfd = (int)rl.rlim_cur;