NetCDF  4.7.1
dfile.c
Go to the documentation of this file.
1 
13 #include "config.h"
14 #include <stdlib.h>
15 #ifdef HAVE_STRING_H
16 #include <string.h>
17 #endif
18 #ifdef HAVE_SYS_RESOURCE_H
19 #include <sys/resource.h>
20 #endif
21 #ifdef HAVE_SYS_TYPES_H
22 #include <sys/types.h>
23 #endif
24 #ifdef HAVE_SYS_STAT_H
25 #include <sys/stat.h>
26 #endif
27 
28 #ifdef HAVE_UNISTD_H
29 #include <unistd.h> /* lseek() */
30 #endif
31 
32 #ifdef HAVE_STDIO_H
33 #include <stdio.h>
34 #endif
35 
36 #include "ncdispatch.h"
37 #include "netcdf_mem.h"
38 #include "ncwinpath.h"
39 #include "fbits.h"
40 
41 #undef DEBUG
42 
43 extern int NC_initialized;
45 /* User-defined formats. */
46 NC_Dispatch *UDF0_dispatch_table = NULL;
47 char UDF0_magic_number[NC_MAX_MAGIC_NUMBER_LEN + 1] = "";
48 NC_Dispatch *UDF1_dispatch_table = NULL;
49 char UDF1_magic_number[NC_MAX_MAGIC_NUMBER_LEN + 1] = "";
50 
51 /**************************************************/
52 
53 
103 int
104 nc_def_user_format(int mode_flag, NC_Dispatch *dispatch_table, char *magic_number)
105 {
106  /* Check inputs. */
107  if (mode_flag != NC_UDF0 && mode_flag != NC_UDF1)
108  return NC_EINVAL;
109  if (!dispatch_table)
110  return NC_EINVAL;
111  if (magic_number && strlen(magic_number) > NC_MAX_MAGIC_NUMBER_LEN)
112  return NC_EINVAL;
113 
114  /* Retain a pointer to the dispatch_table and a copy of the magic
115  * number, if one was provided. */
116  switch(mode_flag)
117  {
118  case NC_UDF0:
119  UDF0_dispatch_table = dispatch_table;
120  if (magic_number)
121  strncpy(UDF0_magic_number, magic_number, NC_MAX_MAGIC_NUMBER_LEN);
122  break;
123  case NC_UDF1:
124  UDF1_dispatch_table = dispatch_table;
125  if (magic_number)
126  strncpy(UDF1_magic_number, magic_number, NC_MAX_MAGIC_NUMBER_LEN);
127  break;
128  }
129 
130  return NC_NOERR;
131 }
132 
149 int
150 nc_inq_user_format(int mode_flag, NC_Dispatch **dispatch_table, char *magic_number)
151 {
152  /* Check inputs. */
153  if (mode_flag != NC_UDF0 && mode_flag != NC_UDF1)
154  return NC_EINVAL;
155 
156  switch(mode_flag)
157  {
158  case NC_UDF0:
159  if (dispatch_table)
160  *dispatch_table = UDF0_dispatch_table;
161  if (magic_number)
162  strncpy(magic_number, UDF0_magic_number, NC_MAX_MAGIC_NUMBER_LEN);
163  break;
164  case NC_UDF1:
165  if (dispatch_table)
166  *dispatch_table = UDF1_dispatch_table;
167  if (magic_number)
168  strncpy(magic_number, UDF1_magic_number, NC_MAX_MAGIC_NUMBER_LEN);
169  break;
170  }
171 
172  return NC_NOERR;
173 }
174 
368 int
369 nc_create(const char *path, int cmode, int *ncidp)
370 {
371  return nc__create(path,cmode,NC_SIZEHINT_DEFAULT,NULL,ncidp);
372 }
373 
440 int
441 nc__create(const char *path, int cmode, size_t initialsz,
442  size_t *chunksizehintp, int *ncidp)
443 {
444  return NC_create(path, cmode, initialsz, 0,
445  chunksizehintp, 0, NULL, ncidp);
446 }
447 
486 int
487 nc_create_mem(const char* path, int mode, size_t initialsize, int* ncidp)
488 {
489  if(mode & NC_MMAP) return NC_EINVAL;
490  mode |= NC_INMEMORY; /* Specifically, do not set NC_DISKLESS */
491  return NC_create(path, mode, initialsize, 0, NULL, 0, NULL, ncidp);
492 }
493 
513 int
514 nc__create_mp(const char *path, int cmode, size_t initialsz,
515  int basepe, size_t *chunksizehintp, int *ncidp)
516 {
517  return NC_create(path, cmode, initialsz, basepe,
518  chunksizehintp, 0, NULL, ncidp);
519 }
520 
634 int
635 nc_open(const char *path, int omode, int *ncidp)
636 {
637  return NC_open(path, omode, 0, NULL, 0, NULL, ncidp);
638 }
639 
691 int
692 nc__open(const char *path, int omode,
693  size_t *chunksizehintp, int *ncidp)
694 {
695  /* this API is for non-parallel access.
696  * Note nc_open_par() also calls NC_open().
697  */
698  return NC_open(path, omode, 0, chunksizehintp, 0, NULL, ncidp);
699 }
700 
746 int
747 nc_open_mem(const char* path, int omode, size_t size, void* memory, int* ncidp)
748 {
749  NC_memio meminfo;
750 
751  /* Sanity checks */
752  if(memory == NULL || size < MAGIC_NUMBER_LEN || path == NULL)
753  return NC_EINVAL;
754  if(omode & (NC_WRITE|NC_MMAP))
755  return NC_EINVAL;
756  omode |= (NC_INMEMORY); /* Note: NC_INMEMORY and NC_DISKLESS are mutually exclusive*/
757  meminfo.size = size;
758  meminfo.memory = memory;
759  meminfo.flags = NC_MEMIO_LOCKED;
760  return NC_open(path, omode, 0, NULL, 0, &meminfo, ncidp);
761 }
762 
811 int
812 nc_open_memio(const char* path, int omode, NC_memio* params, int* ncidp)
813 {
814  /* Sanity checks */
815  if(path == NULL || params == NULL)
816  return NC_EINVAL;
817  if(params->memory == NULL || params->size < MAGIC_NUMBER_LEN)
818  return NC_EINVAL;
819 
820  if(omode & NC_MMAP)
821  return NC_EINVAL;
822  omode |= (NC_INMEMORY);
823  return NC_open(path, omode, 0, NULL, 0, params, ncidp);
824 }
825 
844 int
845 nc__open_mp(const char *path, int omode, int basepe,
846  size_t *chunksizehintp, int *ncidp)
847 {
848  return NC_open(path, omode, basepe, chunksizehintp, 0, NULL, ncidp);
849 }
850 
868 int
869 nc_inq_path(int ncid, size_t *pathlen, char *path)
870 {
871  NC* ncp;
872  int stat = NC_NOERR;
873  if ((stat = NC_check_id(ncid, &ncp)))
874  return stat;
875  if(ncp->path == NULL) {
876  if(pathlen) *pathlen = 0;
877  if(path) path[0] = '\0';
878  } else {
879  if (pathlen) *pathlen = strlen(ncp->path);
880  if (path) strcpy(path, ncp->path);
881  }
882  return stat;
883 }
884 
933 int
934 nc_redef(int ncid)
935 {
936  NC* ncp;
937  int stat = NC_check_id(ncid, &ncp);
938  if(stat != NC_NOERR) return stat;
939  return ncp->dispatch->redef(ncid);
940 }
941 
997 int
998 nc_enddef(int ncid)
999 {
1000  int status = NC_NOERR;
1001  NC *ncp;
1002  status = NC_check_id(ncid, &ncp);
1003  if(status != NC_NOERR) return status;
1004  return ncp->dispatch->_enddef(ncid,0,1,0,1);
1005 }
1006 
1088 int
1089 nc__enddef(int ncid, size_t h_minfree, size_t v_align, size_t v_minfree,
1090  size_t r_align)
1091 {
1092  NC* ncp;
1093  int stat = NC_check_id(ncid, &ncp);
1094  if(stat != NC_NOERR) return stat;
1095  return ncp->dispatch->_enddef(ncid,h_minfree,v_align,v_minfree,r_align);
1096 }
1097 
1165 int
1166 nc_sync(int ncid)
1167 {
1168  NC* ncp;
1169  int stat = NC_check_id(ncid, &ncp);
1170  if(stat != NC_NOERR) return stat;
1171  return ncp->dispatch->sync(ncid);
1172 }
1173 
1217 int
1218 nc_abort(int ncid)
1219 {
1220  NC* ncp;
1221  int stat = NC_check_id(ncid, &ncp);
1222  if(stat != NC_NOERR) return stat;
1223 
1224  stat = ncp->dispatch->abort(ncid);
1225  del_from_NCList(ncp);
1226  free_NC(ncp);
1227  return stat;
1228 }
1229 
1270 int
1271 nc_close(int ncid)
1272 {
1273  NC* ncp;
1274  int stat = NC_check_id(ncid, &ncp);
1275  if(stat != NC_NOERR) return stat;
1276 
1277  stat = ncp->dispatch->close(ncid,NULL);
1278  /* Remove from the nc list */
1279  if (!stat)
1280  {
1281  del_from_NCList(ncp);
1282  free_NC(ncp);
1283  }
1284  return stat;
1285 }
1286 
1329 int
1330 nc_close_memio(int ncid, NC_memio* memio)
1331 {
1332  NC* ncp;
1333  int stat = NC_check_id(ncid, &ncp);
1334  if(stat != NC_NOERR) return stat;
1335 
1336  stat = ncp->dispatch->close(ncid,memio);
1337  /* Remove from the nc list */
1338  if (!stat)
1339  {
1340  del_from_NCList(ncp);
1341  free_NC(ncp);
1342  }
1343  return stat;
1344 }
1345 
1444 int
1445 nc_set_fill(int ncid, int fillmode, int *old_modep)
1446 {
1447  NC* ncp;
1448  int stat = NC_check_id(ncid, &ncp);
1449  if(stat != NC_NOERR) return stat;
1450  return ncp->dispatch->set_fill(ncid,fillmode,old_modep);
1451 }
1452 
1467 int
1468 nc_inq_base_pe(int ncid, int *pe)
1469 {
1470  NC* ncp;
1471  int stat = NC_check_id(ncid, &ncp);
1472  if(stat != NC_NOERR) return stat;
1473  if (pe) *pe = 0;
1474  return NC_NOERR;
1475 }
1476 
1491 int
1492 nc_set_base_pe(int ncid, int pe)
1493 {
1494  NC* ncp;
1495  int stat = NC_check_id(ncid, &ncp);
1496  if(stat != NC_NOERR) return stat;
1497  return NC_NOERR;
1498 }
1499 
1517 int
1518 nc_inq_format(int ncid, int *formatp)
1519 {
1520  NC* ncp;
1521  int stat = NC_check_id(ncid, &ncp);
1522  if(stat != NC_NOERR) return stat;
1523  return ncp->dispatch->inq_format(ncid,formatp);
1524 }
1525 
1552 int
1553 nc_inq_format_extended(int ncid, int *formatp, int *modep)
1554 {
1555  NC* ncp;
1556  int stat = NC_check_id(ncid, &ncp);
1557  if(stat != NC_NOERR) return stat;
1558  return ncp->dispatch->inq_format_extended(ncid,formatp,modep);
1559 }
1560 
1605 int
1606 nc_inq(int ncid, int *ndimsp, int *nvarsp, int *nattsp, int *unlimdimidp)
1607 {
1608  NC* ncp;
1609  int stat = NC_check_id(ncid, &ncp);
1610  if(stat != NC_NOERR) return stat;
1611  return ncp->dispatch->inq(ncid,ndimsp,nvarsp,nattsp,unlimdimidp);
1612 }
1613 
1624 int
1625 nc_inq_nvars(int ncid, int *nvarsp)
1626 {
1627  NC* ncp;
1628  int stat = NC_check_id(ncid, &ncp);
1629  if(stat != NC_NOERR) return stat;
1630  return ncp->dispatch->inq(ncid, NULL, nvarsp, NULL, NULL);
1631 }
1632 
1698 int
1699 nc_inq_type(int ncid, nc_type xtype, char *name, size_t *size)
1700 {
1701  NC* ncp;
1702  int stat;
1703 
1704  /* Do a quick triage on xtype */
1705  if(xtype <= NC_NAT) return NC_EBADTYPE;
1706  /* For compatibility, we need to allow inq about
1707  atomic types, even if ncid is ill-defined */
1708  if(xtype <= ATOMICTYPEMAX4) {
1709  if(name) strncpy(name,NC_atomictypename(xtype),NC_MAX_NAME);
1710  if(size) *size = NC_atomictypelen(xtype);
1711  return NC_NOERR;
1712  }
1713  /* Apparently asking about a user defined type, so we need
1714  a valid ncid */
1715  stat = NC_check_id(ncid, &ncp);
1716  if(stat != NC_NOERR) /* bad ncid */
1717  return NC_EBADTYPE;
1718  /* have good ncid */
1719  return ncp->dispatch->inq_type(ncid,xtype,name,size);
1720 }
1721 
1738 static int
1740 {
1741  int mode_format;
1742  int mmap = 0;
1743  int inmemory = 0;
1744  int diskless = 0;
1745 
1746  /* This is a clever check to see if more than one format bit is
1747  * set. */
1748  mode_format = (mode & NC_NETCDF4) | (mode & NC_64BIT_OFFSET) |
1749  (mode & NC_CDF5);
1750  if (mode_format && (mode_format & (mode_format - 1)))
1751  return NC_EINVAL;
1752 
1753  mmap = ((mode & NC_MMAP) == NC_MMAP);
1754  inmemory = ((mode & NC_INMEMORY) == NC_INMEMORY);
1755  diskless = ((mode & NC_DISKLESS) == NC_DISKLESS);
1756 
1757  /* NC_INMEMORY and NC_DISKLESS and NC_MMAP are all mutually exclusive */
1758  if(diskless && inmemory) return NC_EDISKLESS;
1759  if(diskless && mmap) return NC_EDISKLESS;
1760  if(inmemory && mmap) return NC_EINMEMORY;
1761 
1762  /* mmap is not allowed for netcdf-4 */
1763  if(mmap && (mode & NC_NETCDF4)) return NC_EINVAL;
1764 
1765 #ifndef USE_NETCDF4
1766  /* If the user asks for a netCDF-4 file, and the library was built
1767  * without netCDF-4, then return an error.*/
1768  if (mode & NC_NETCDF4)
1769  return NC_ENOTBUILT;
1770 #endif /* USE_NETCDF4 undefined */
1771 
1772  /* Well I guess there is some sanity in the world after all. */
1773  return NC_NOERR;
1774 }
1775 
1803 int
1804 NC_create(const char *path0, int cmode, size_t initialsz,
1805  int basepe, size_t *chunksizehintp, int useparallel,
1806  void* parameters, int *ncidp)
1807 {
1808  int stat = NC_NOERR;
1809  NC* ncp = NULL;
1810  const NC_Dispatch* dispatcher = NULL;
1811  char* path = NULL;
1812  NCmodel model;
1813  char* newpath = NULL;
1814 
1815  TRACE(nc_create);
1816  if(path0 == NULL)
1817  return NC_EINVAL;
1818 
1819  /* Check mode flag for sanity. */
1820  if ((stat = check_create_mode(cmode)))
1821  return stat;
1822 
1823  /* Initialize the library. The available dispatch tables
1824  * will depend on how netCDF was built
1825  * (with/without netCDF-4, DAP, CDMREMOTE). */
1826  if(!NC_initialized)
1827  {
1828  if ((stat = nc_initialize()))
1829  return stat;
1830  }
1831 
1832  {
1833  /* Skip past any leading whitespace in path */
1834  const char* p;
1835  for(p=(char*)path0;*p;p++) {if(*p > ' ') break;}
1836 #ifdef WINPATH
1837  /* Need to do path conversion */
1838  path = NCpathcvt(p);
1839 #else
1840  path = nulldup(p);
1841 #endif
1842  }
1843 
1844  memset(&model,0,sizeof(model));
1845  if((stat = NC_infermodel(path,&cmode,1,useparallel,NULL,&model,&newpath)))
1846  goto done;
1847  if(newpath) {
1848  nullfree(path);
1849  path = newpath;
1850  newpath = NULL;
1851  }
1852 
1853  assert(model.format != 0 && model.impl != 0);
1854 
1855  /* Now, check for NC_ENOTBUILT cases limited to create (so e.g. HDF4 is not listed) */
1856 #ifndef USE_HDF5
1857  if (model.impl == NC_FORMATX_NC4)
1858  {stat = NC_ENOTBUILT; goto done;}
1859 #endif
1860 #ifndef USE_PNETCDF
1861  if (model.impl == NC_FORMATX_PNETCDF)
1862  {stat = NC_ENOTBUILT; goto done;}
1863 #endif
1864 #ifndef ENABLE_CDF5
1865  if (model.impl == NC_FORMATX_NC3 && (cmode & NC_64BIT_DATA))
1866  {stat = NC_ENOTBUILT; goto done;}
1867 #endif
1868 
1869  /* Figure out what dispatcher to use */
1870  switch (model.impl) {
1871 #ifdef USE_HDF5
1872  case NC_FORMATX_NC4:
1873  dispatcher = HDF5_dispatch_table;
1874  break;
1875 #endif
1876 #ifdef USE_PNETCDF
1877  case NC_FORMATX_PNETCDF:
1878  dispatcher = NCP_dispatch_table;
1879  break;
1880 #endif
1881 #ifdef USE_NETCDF4
1882  case NC_FORMATX_UDF0:
1883  dispatcher = UDF0_dispatch_table;
1884  break;
1885  case NC_FORMATX_UDF1:
1886  dispatcher = UDF1_dispatch_table;
1887  break;
1888 #endif /* USE_NETCDF4 */
1889  case NC_FORMATX_NC3:
1890  dispatcher = NC3_dispatch_table;
1891  break;
1892  default:
1893  return NC_ENOTNC;
1894  }
1895 
1896  /* Create the NC* instance and insert its dispatcher and model */
1897  if((stat = new_NC(dispatcher,path,cmode,&model,&ncp))) goto done;
1898 
1899  /* Add to list of known open files and define ext_ncid */
1900  add_to_NCList(ncp);
1901 
1902  /* Assume create will fill in remaining ncp fields */
1903  if ((stat = dispatcher->create(ncp->path, cmode, initialsz, basepe, chunksizehintp,
1904  parameters, dispatcher, ncp->ext_ncid))) {
1905  del_from_NCList(ncp); /* oh well */
1906  free_NC(ncp);
1907  } else {
1908  if(ncidp)*ncidp = ncp->ext_ncid;
1909  }
1910 done:
1911  nullfree(path);
1912  return stat;
1913 }
1914 
1938 int
1939 NC_open(const char *path0, int omode, int basepe, size_t *chunksizehintp,
1940  int useparallel, void* parameters, int *ncidp)
1941 {
1942  int stat = NC_NOERR;
1943  NC* ncp = NULL;
1944  const NC_Dispatch* dispatcher = NULL;
1945  int inmemory = 0;
1946  int diskless = 0;
1947  int mmap = 0;
1948  char* path = NULL;
1949  NCmodel model;
1950  char* newpath = NULL;
1951 
1952  TRACE(nc_open);
1953  if(!NC_initialized) {
1954  stat = nc_initialize();
1955  if(stat) return stat;
1956  }
1957 
1958  /* Check inputs. */
1959  if (!path0)
1960  return NC_EINVAL;
1961 
1962  /* Capture the inmemory related flags */
1963  mmap = ((omode & NC_MMAP) == NC_MMAP);
1964  diskless = ((omode & NC_DISKLESS) == NC_DISKLESS);
1965  inmemory = ((omode & NC_INMEMORY) == NC_INMEMORY);
1966 
1967  /* NC_INMEMORY and NC_DISKLESS and NC_MMAP are all mutually exclusive */
1968  if(diskless && inmemory) {stat = NC_EDISKLESS; goto done;}
1969  if(diskless && mmap) {stat = NC_EDISKLESS; goto done;}
1970  if(inmemory && mmap) {stat = NC_EINMEMORY; goto done;}
1971 
1972  /* mmap is not allowed for netcdf-4 */
1973  if(mmap && (omode & NC_NETCDF4)) {stat = NC_EINVAL; goto done;}
1974 
1975  /* Attempt to do file path conversion: note that this will do
1976  nothing if path is a 'file:...' url, so it will need to be
1977  repeated in protocol code (e.g. libdap2, libdap4, etc).
1978  */
1979 
1980  {
1981  /* Skip past any leading whitespace in path */
1982  const char* p;
1983  for(p=(char*)path0;*p;p++) {if(*p > ' ') break;}
1984 #ifdef WINPATH
1985  /* Need to do path conversion */
1986  path = NCpathcvt(p);
1987 #else
1988  path = nulldup(p);
1989 #endif
1990  }
1991 
1992  memset(&model,0,sizeof(model));
1993  /* Infer model implementation and format, possibly by reading the file */
1994  if((stat = NC_infermodel(path,&omode,0,useparallel,parameters,&model,&newpath)))
1995  goto done;
1996  if(newpath) {
1997  nullfree(path);
1998  path = newpath;
1999  }
2000 
2001  /* Still no implementation, give up */
2002  if(model.impl == 0) {
2003 #ifdef DEBUG
2004  fprintf(stderr,"implementation == 0\n");
2005 #endif
2006  {stat = NC_ENOTNC; goto done;}
2007  }
2008 
2009  /* Suppress unsupported formats */
2010  {
2011  int hdf5built = 0;
2012  int hdf4built = 0;
2013  int cdf5built = 0;
2014  int udf0built = 0;
2015  int udf1built = 0;
2016 #ifdef USE_NETCDF4
2017  hdf5built = 1;
2018 #ifdef USE_HDF4
2019  hdf4built = 1;
2020 #endif
2021 #endif
2022 #ifdef ENABLE_CDF5
2023  cdf5built = 1;
2024 #endif
2025  if(UDF0_dispatch_table != NULL)
2026  udf0built = 1;
2027  if(UDF1_dispatch_table != NULL)
2028  udf1built = 1;
2029 
2030  if(!hdf5built && model.impl == NC_FORMATX_NC4)
2031  {stat = NC_ENOTBUILT; goto done;}
2032  if(!hdf4built && model.impl == NC_FORMATX_NC_HDF4)
2033  {stat = NC_ENOTBUILT; goto done;}
2034  if(!cdf5built && model.impl == NC_FORMATX_NC3 && model.format == NC_FORMAT_CDF5)
2035  {stat = NC_ENOTBUILT; goto done;}
2036  if(!udf0built && model.impl == NC_FORMATX_UDF0)
2037  {stat = NC_ENOTBUILT; goto done;}
2038  if(!udf1built && model.impl == NC_FORMATX_UDF1)
2039  {stat = NC_ENOTBUILT; goto done;}
2040  }
2041  /* Figure out what dispatcher to use */
2042  if (!dispatcher) {
2043  switch (model.impl) {
2044 #ifdef ENABLE_DAP
2045  case NC_FORMATX_DAP2:
2046  dispatcher = NCD2_dispatch_table;
2047  break;
2048 #endif
2049 #ifdef ENABLE_DAP4
2050  case NC_FORMATX_DAP4:
2051  dispatcher = NCD4_dispatch_table;
2052  break;
2053 #endif
2054 #ifdef USE_PNETCDF
2055  case NC_FORMATX_PNETCDF:
2056  dispatcher = NCP_dispatch_table;
2057  break;
2058 #endif
2059 #ifdef USE_HDF5
2060  case NC_FORMATX_NC4:
2061  dispatcher = HDF5_dispatch_table;
2062  break;
2063 #endif
2064 #ifdef USE_HDF4
2065  case NC_FORMATX_NC_HDF4:
2066  dispatcher = HDF4_dispatch_table;
2067  break;
2068 #endif
2069 #ifdef USE_NETCDF4
2070  case NC_FORMATX_UDF0:
2071  dispatcher = UDF0_dispatch_table;
2072  break;
2073  case NC_FORMATX_UDF1:
2074  dispatcher = UDF1_dispatch_table;
2075  break;
2076 #endif /* USE_NETCDF4 */
2077  case NC_FORMATX_NC3:
2078  dispatcher = NC3_dispatch_table;
2079  break;
2080  default:
2081  nullfree(path);
2082  return NC_ENOTNC;
2083  }
2084  }
2085 
2086 
2087  /* If we can't figure out what dispatch table to use, give up. */
2088  if (!dispatcher) {stat = NC_ENOTNC; goto done;}
2089 
2090  /* Create the NC* instance and insert its dispatcher */
2091  if((stat = new_NC(dispatcher,path,omode,&model,&ncp))) goto done;
2092 
2093  /* Add to list of known open files. This assignes an ext_ncid. */
2094  add_to_NCList(ncp);
2095 
2096  /* Assume open will fill in remaining ncp fields */
2097  stat = dispatcher->open(ncp->path, omode, basepe, chunksizehintp,
2098  parameters, dispatcher, ncp->ext_ncid);
2099  if(stat == NC_NOERR) {
2100  if(ncidp) *ncidp = ncp->ext_ncid;
2101  } else {
2102  del_from_NCList(ncp);
2103  free_NC(ncp);
2104  }
2105 
2106 done:
2107  nullfree(path);
2108  return stat;
2109 }
2110 
2111 /*Provide an internal function for generating pseudo file descriptors
2112  for systems that are not file based (e.g. dap, memio).
2113 */
2114 
2116 static int pseudofd = 0;
2117 
2125 int
2126 nc__pseudofd(void)
2127 {
2128  if(pseudofd == 0) {
2129  int maxfd = 32767; /* default */
2130 #ifdef HAVE_GETRLIMIT
2131  struct rlimit rl;
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;
2137  }
2138  pseudofd = maxfd+1;
2139 #endif
2140  }
2141  return pseudofd++;
2142 }
#define NC_MAX_MAGIC_NUMBER_LEN
Max len of user-defined format magic number.
Definition: netcdf.h:163
int nc_def_user_format(int mode_flag, NC_Dispatch *dispatch_table, char *magic_number)
Add handling of user-defined format.
Definition: dfile.c:104
int NC_initialized
True when dispatch table is initialized.
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...
Definition: dfile.c:1330
#define NC_FORMATX_NC4
alias
Definition: netcdf.h:212
Main header file for in-memory (diskless) functionality.
int nc_redef(int ncid)
Put open netcdf dataset into define mode.
Definition: dfile.c:934
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.
Definition: dfile.c:1089
#define NC_UDF1
User-defined format 1.
Definition: netcdf.h:136
#define NC_INMEMORY
Read from memory.
Definition: netcdf.h:161
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.
Definition: dfile.c:812
int nc_inq_format(int ncid, int *formatp)
Inquire about the binary format of a netCDF file as presented by the API.
Definition: dfile.c:1518
int nc_inq(int ncid, int *ndimsp, int *nvarsp, int *nattsp, int *unlimdimidp)
Inquire about a file or group.
Definition: dfile.c:1606
int nc_type
The nc_type type is just an int.
Definition: netcdf.h:25
#define NC_64BIT_OFFSET
Use large (64-bit) file offsets.
Definition: netcdf.h:139
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.
Definition: dfile.c:692
#define NC_UDF0
User-defined format 0.
Definition: netcdf.h:135
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.
Definition: dfile.c:1553
#define NC_ENOTNC
Not a netcdf file.
Definition: netcdf.h:381
#define NC_FORMAT_CDF5
Format specifier for nc_set_default_format() and returned by nc_inq_format.
Definition: netcdf.h:185
#define NC_64BIT_DATA
CDF-5 format: classic model but 64 bit dimensions and sizes.
Definition: netcdf.h:132
#define NC_ENOTBUILT
Attempt to use feature that was not turned on when netCDF was built.
Definition: netcdf.h:465
int nc_close(int ncid)
Close an open netCDF dataset.
Definition: dfile.c:1271
#define NC_EDISKLESS
Error in using diskless access.
Definition: netcdf.h:466
int nc_abort(int ncid)
No longer necessary for user to invoke manually.
Definition: dfile.c:1218
#define NC_EBADTYPE
Not a netcdf data type.
Definition: netcdf.h:367
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.
Definition: dfile.c:747
#define NC_SIZEHINT_DEFAULT
Let nc__create() or nc__open() figure out a suitable buffer size.
Definition: netcdf.h:239
#define NC_EINVAL
Invalid Argument.
Definition: netcdf.h:335
#define NC_EINMEMORY
In-memory file error.
Definition: netcdf.h:473
int nc_set_fill(int ncid, int fillmode, int *old_modep)
Change the fill-value mode to improve write performance.
Definition: dfile.c:1445
#define NC_FORMATX_UDF0
Extended format specifier returned by nc_inq_format_extended() Added in version 4.3.1.
Definition: netcdf.h:217
#define NC_MAX_NAME
Maximum for classic library.
Definition: netcdf.h:275
#define NC_NAT
Not A Type.
Definition: netcdf.h:34
int nc_inq_type(int ncid, nc_type xtype, char *name, size_t *size)
Inquire about a type.
Definition: dfile.c:1699
#define NC_FORMATX_DAP2
Extended format specifier returned by nc_inq_format_extended() Added in version 4.3.1.
Definition: netcdf.h:215
#define NC_FORMATX_NC3
Extended format specifier returned by nc_inq_format_extended() Added in version 4.3.1.
Definition: netcdf.h:210
#define NC_NETCDF4
Use netCDF-4/HDF5 format.
Definition: netcdf.h:151
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. ...
Definition: dfile.c:441
#define NC_FORMATX_NC_HDF4
netCDF-4 subset of HDF4
Definition: netcdf.h:213
int nc_open(const char *path, int omode, int *ncidp)
Open an existing netCDF file.
Definition: dfile.c:635
#define NC_FORMATX_UDF1
Extended format specifier returned by nc_inq_format_extended() Added in version 4.3.1.
Definition: netcdf.h:218
#define NC_CDF5
Alias NC_CDF5 to NC_64BIT_DATA.
Definition: netcdf.h:133
#define NC_WRITE
Set read-write access for nc_open().
Definition: netcdf.h:124
int nc_inq_user_format(int mode_flag, NC_Dispatch **dispatch_table, char *magic_number)
Inquire about user-defined format.
Definition: dfile.c:150
int nc_create_mem(const char *path, int mode, size_t initialsize, int *ncidp)
Create a netCDF file with the contents stored in memory.
Definition: dfile.c:487
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&#39;s file...
Definition: dfile.c:869
#define NC_NOERR
No Error.
Definition: netcdf.h:325
int nc_inq_nvars(int ncid, int *nvarsp)
Learn the number of variables in a file or group.
Definition: dfile.c:1625
#define NC_DISKLESS
Use diskless file.
Definition: netcdf.h:129
static int check_create_mode(int mode)
Check the create mode parameter for sanity.
Definition: dfile.c:1739
#define NC_FORMATX_DAP4
Extended format specifier returned by nc_inq_format_extended() Added in version 4.3.1.
Definition: netcdf.h:216
int nc_enddef(int ncid)
Leave define mode.
Definition: dfile.c:998
#define NC_FORMATX_PNETCDF
Extended format specifier returned by nc_inq_format_extended() Added in version 4.3.1.
Definition: netcdf.h:214
#define NC_MMAP
Definition: netcdf.h:130
int nc_sync(int ncid)
Synchronize an open netcdf dataset to disk.
Definition: dfile.c:1166
int nc_create(const char *path, int cmode, int *ncidp)
Create a new netCDF file.
Definition: dfile.c:369

Return to the Main Unidata NetCDF page.
Generated on Tue Aug 27 2019 15:28:55 for NetCDF. NetCDF is a Unidata library.