mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-03-31 17:50:26 +08:00
ckp
This commit is contained in:
parent
7592240cb1
commit
25c3167841
4
cf
4
cf
@ -5,8 +5,8 @@ if test $# != 0 ; then
|
||||
cmds=$@
|
||||
fi
|
||||
|
||||
HDF5=1
|
||||
DAP=1
|
||||
#HDF5=1
|
||||
#DAP=1
|
||||
#CDMR=1
|
||||
#RPC=1
|
||||
#PGI=1
|
||||
|
@ -145,7 +145,8 @@ available: NC_NOCLOBBER (do not overwrite existing file), NC_SHARE
|
||||
(limit write caching - netcdf classic files onlt), NC_64BIT_OFFSET
|
||||
(create 64-bit offset file), NC_NETCDF4 (create netCDF-4/HDF5 file),
|
||||
NC_CLASSIC_MODEL (enforce netCDF classic mode on netCDF-4/HDF5
|
||||
files). See discussion below.
|
||||
files), NC_DISKLESS (store data only in memory), NC_WRITE.
|
||||
See discussion below.
|
||||
|
||||
\param ncidp Pointer to location where returned netCDF ID is to be
|
||||
stored.
|
||||
@ -189,6 +190,14 @@ types, multiple unlimited dimensions, or new atomic types. The
|
||||
advantage of this restriction is that such files are guaranteed to
|
||||
work with existing netCDF software.
|
||||
|
||||
Setting NC_DISKLESS causes netCDF to create the file only in memory.
|
||||
This allows for the use of files that have long term purpose. Note that
|
||||
with one exception, the in-memory file is destroyed upon calling
|
||||
nc_close. If, however, if the combination (NC_DISKLESS|NC_WRITE)
|
||||
is used, then at close, the contents of the memory file will be
|
||||
made persistent in the file path that was specified in the nc_create
|
||||
call.
|
||||
|
||||
\returns ::NC_NOERR No error.
|
||||
|
||||
\returns ::NC_ENOMEM System out of memory.
|
||||
@ -198,6 +207,9 @@ work with existing netCDF software.
|
||||
\returns ::NC_EFILEMETA Error writing netCDF-4 file-level metadata in
|
||||
HDF5 file. (netCDF-4 files only).
|
||||
|
||||
\returns ::NC_EDISKLESS if there was an error in creating the
|
||||
in-memory file.
|
||||
|
||||
\note When creating a netCDF-4 file HDF5 error reporting is turned
|
||||
off, if it is on. This doesn't stop the HDF5 error stack from
|
||||
recording the errors, it simply stops their display to the user
|
||||
@ -260,6 +272,33 @@ the classic netCDF-3 data model.
|
||||
if (status != NC_NOERR) handle_error(status);
|
||||
@endcode
|
||||
|
||||
In this example we create a in-memory netCDF classic dataset named
|
||||
diskless.nc whose content will be lost when nc_close() is called.
|
||||
|
||||
@code
|
||||
#include <netcdf.h>
|
||||
...
|
||||
int status = NC_NOERR;
|
||||
int ncid;
|
||||
...
|
||||
status = nc_create("foo_HDF5_classic.nc", NC_DISKLESS, &ncid);
|
||||
if (status != NC_NOERR) handle_error(status);
|
||||
@endcode
|
||||
|
||||
In this example we create a in-memory netCDF classic dataset named
|
||||
diskless.nc and specify that it should be made persistent
|
||||
in a file named diskless.nc when nc_close() is called.
|
||||
|
||||
@code
|
||||
#include <netcdf.h>
|
||||
...
|
||||
int status = NC_NOERR;
|
||||
int ncid;
|
||||
...
|
||||
status = nc_create("foo_HDF5_classic.nc", NC_DISKLESS|NC_WRITE, &ncid);
|
||||
if (status != NC_NOERR) handle_error(status);
|
||||
@endcode
|
||||
|
||||
A variant of nc_create(), nc__create() (note the double underscore) allows
|
||||
users to specify two tuning parameters for the file that it is
|
||||
creating. */
|
||||
|
84
libsrc/nc.c
84
libsrc/nc.c
@ -283,23 +283,15 @@ read_numrecs(NC *ncp)
|
||||
|
||||
#define NC_NUMRECS_OFFSET 4
|
||||
#define NC_NUMRECS_EXTENT 4
|
||||
#ifdef USE_NEWIO
|
||||
if(!(status = ncstdio_seek(ncp->nciop,NC_NUMRECS_OFFSET))
|
||||
return status;
|
||||
status = ncstdio_read(ncp->nciop,NC_NUMRECS_EXTENT, (void*)&xp);
|
||||
#else
|
||||
status = ncp->nciop->get(ncp->nciop,
|
||||
NC_NUMRECS_OFFSET, NC_NUMRECS_EXTENT, 0, (void **)&xp);
|
||||
/* cast away const */
|
||||
#endif
|
||||
if(status != NC_NOERR)
|
||||
return status;
|
||||
|
||||
status = ncx_get_size_t(&xp, &nrecs);
|
||||
|
||||
#ifndef USE_NEWIO
|
||||
(void) ncp->nciop->rel(ncp->nciop, NC_NUMRECS_OFFSET, 0);
|
||||
#endif
|
||||
|
||||
if(status == NC_NOERR)
|
||||
{
|
||||
@ -324,14 +316,8 @@ write_numrecs(NC *ncp)
|
||||
assert(!NC_readonly(ncp));
|
||||
assert(!NC_indef(ncp));
|
||||
|
||||
#ifdef USE_NEWIO
|
||||
if(!(status = ncstdio_seek(ncp->nciop,NC_NUMRECS_OFFSET))
|
||||
return status;
|
||||
status = ncstdio_read(ncp->nciop,NC_NUMRECS_EXTENT, (void*)&xp);
|
||||
#else
|
||||
status = ncp->nciop->get(ncp->nciop,
|
||||
NC_NUMRECS_OFFSET, NC_NUMRECS_EXTENT, RGN_WRITE, &xp);
|
||||
#endif
|
||||
if(status != NC_NOERR)
|
||||
return status;
|
||||
|
||||
@ -340,9 +326,7 @@ write_numrecs(NC *ncp)
|
||||
status = ncx_put_size_t(&xp, &nrecs);
|
||||
}
|
||||
|
||||
#ifndef USE_NEWIO
|
||||
(void) ncp->nciop->rel(ncp->nciop, NC_NUMRECS_OFFSET, RGN_MODIFIED);
|
||||
#endif
|
||||
if(status == NC_NOERR)
|
||||
fClr(ncp->flags, NC_NDIRTY);
|
||||
|
||||
@ -519,7 +503,6 @@ fill_added(NC *gnu, NC *old)
|
||||
}
|
||||
|
||||
|
||||
#ifndef USE_NEWIO
|
||||
/*
|
||||
* Move the records "out".
|
||||
* Fill as needed.
|
||||
@ -622,7 +605,6 @@ move_vars_r(NC *gnu, NC *old)
|
||||
|
||||
return NC_NOERR;
|
||||
}
|
||||
#endif /*!NEWIO*/
|
||||
|
||||
/*
|
||||
* Given a valid ncp, return NC_EVARSIZE if any variable has a bad len
|
||||
@ -797,11 +779,7 @@ NC_endef(NC *ncp,
|
||||
|
||||
fClr(ncp->flags, NC_CREAT | NC_INDEF);
|
||||
|
||||
#ifdef USE_NEWIO
|
||||
return ncstdio_sync(ncp->nciop);
|
||||
#else
|
||||
return ncp->nciop->sync(ncp->nciop);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef LOCKNUMREC
|
||||
@ -936,14 +914,10 @@ NC3_create(const char *path, int ioflags,
|
||||
|
||||
assert(ncp->xsz == ncx_len_NC(ncp,sizeof_off_t));
|
||||
|
||||
#ifdef USE_NEWIO
|
||||
status = ncFile_create(path,ioflags,&ncp->nciop);
|
||||
#else
|
||||
status = ncio_create(path, ioflags,
|
||||
initialsz,
|
||||
0, ncp->xsz, &ncp->chunk,
|
||||
&ncp->nciop, &xp);
|
||||
#endif
|
||||
if(status != NC_NOERR)
|
||||
{
|
||||
/* translate error status */
|
||||
@ -975,23 +949,15 @@ NC3_create(const char *path, int ioflags,
|
||||
if(chunksizehintp != NULL)
|
||||
*chunksizehintp = ncp->chunk;
|
||||
|
||||
#ifdef USE_NEWIO
|
||||
ncstdio_uid(ncp->nciop,&ncp->int_ncid);
|
||||
#else
|
||||
ncp->int_ncid = ncp->nciop->fd;
|
||||
#endif
|
||||
|
||||
if(ncpp) *ncpp = ncp;
|
||||
|
||||
return NC_NOERR;
|
||||
|
||||
unwind_ioc:
|
||||
#ifdef USE_NEWIO
|
||||
ncstdio_close(ncdp->nciop,1); /* delete */
|
||||
#else
|
||||
(void) ncio_close(ncp->nciop, 1); /* N.B.: unlink */
|
||||
ncp->nciop = NULL;
|
||||
#endif
|
||||
/*FALLTHRU*/
|
||||
unwind_alloc:
|
||||
free_NC(ncp);
|
||||
@ -1052,13 +1018,9 @@ NC3_open(const char * path, int ioflags,
|
||||
return NC_EINVAL;
|
||||
#endif
|
||||
|
||||
#ifdef USE_NEWIO
|
||||
status = ncFile_open(path,ioflags,&ncp->nciop);
|
||||
#else
|
||||
status = ncio_open(path, ioflags,
|
||||
0, 0, &ncp->chunk,
|
||||
&ncp->nciop, 0);
|
||||
#endif
|
||||
if(status)
|
||||
goto unwind_alloc;
|
||||
|
||||
@ -1085,24 +1047,15 @@ NC3_open(const char * path, int ioflags,
|
||||
if(chunksizehintp != NULL)
|
||||
*chunksizehintp = ncp->chunk;
|
||||
|
||||
|
||||
#ifdef USE_NEWIO
|
||||
ncstdio_uid(ncp->nciop,&ncp->int_ncid);
|
||||
#else
|
||||
ncp->int_ncid = ncp->nciop->fd;
|
||||
#endif
|
||||
|
||||
if(ncpp) *ncpp = ncp;
|
||||
|
||||
return NC_NOERR;
|
||||
|
||||
unwind_ioc:
|
||||
#ifdef USE_NEWIO
|
||||
(void)ncstdio_close(ncp->nciop,0);
|
||||
#else
|
||||
(void) ncio_close(ncp->nciop, 0);
|
||||
ncp->nciop = NULL;
|
||||
#endif
|
||||
/*FALLTHRU*/
|
||||
unwind_alloc:
|
||||
free_NC(ncp);
|
||||
@ -1151,11 +1104,7 @@ NC3_close(int ncid)
|
||||
{
|
||||
status = NC_sync(ncp);
|
||||
/* flush buffers before any filesize comparisons */
|
||||
#ifdef USE_NEWIO
|
||||
(void)ncstdio_sync(ncp->nciop);
|
||||
#else
|
||||
(void) ncp->nciop->sync(ncp->nciop);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1166,31 +1115,21 @@ NC3_close(int ncid)
|
||||
if (status == ENOERR) {
|
||||
off_t filesize; /* current size of open file */
|
||||
off_t calcsize; /* calculated file size, from header */
|
||||
#ifdef USE_NEWIO
|
||||
#else
|
||||
status = ncio_filesize(ncp->nciop, &filesize);
|
||||
#endif
|
||||
if(status != ENOERR)
|
||||
return status;
|
||||
status = NC_calcsize(ncp, &calcsize);
|
||||
if(status != NC_NOERR)
|
||||
return status;
|
||||
if(filesize < calcsize && !NC_readonly(ncp)) {
|
||||
#ifdef USE_NEWIO
|
||||
#else
|
||||
status = ncio_pad_length(ncp->nciop, calcsize);
|
||||
#endif
|
||||
if(status != ENOERR)
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_NEWIO
|
||||
(void*)ncstdio_close(ncp->nciop,0);
|
||||
#else
|
||||
(void) ncio_close(ncp->nciop, 0);
|
||||
ncp->nciop = NULL;
|
||||
#endif
|
||||
|
||||
del_from_NCList(ncp);
|
||||
|
||||
@ -1234,12 +1173,8 @@ NC3_abort(int ncid)
|
||||
}
|
||||
|
||||
|
||||
#ifdef USE_NEWIO
|
||||
(void)ncstdio_close(ncp->nciop,doUnlink);
|
||||
#else
|
||||
(void) ncio_close(ncp->nciop, doUnlink);
|
||||
ncp->nciop = NULL;
|
||||
#endif
|
||||
|
||||
del_from_NCList(ncp);
|
||||
|
||||
@ -1349,11 +1284,7 @@ NC3_sync(int ncid)
|
||||
if(status != NC_NOERR)
|
||||
return status;
|
||||
|
||||
#ifdef USE_NEWIO
|
||||
status = ncstdio_sync(ncp->nciop);
|
||||
#else
|
||||
status = ncp->nciop->sync(ncp->nciop);
|
||||
#endif
|
||||
if(status != NC_NOERR)
|
||||
return status;
|
||||
return status;
|
||||
@ -1573,13 +1504,9 @@ nc_delete_mp(const char * path, int basepe)
|
||||
return NC_EINVAL;
|
||||
#endif
|
||||
|
||||
#ifdef USE_NEWIO
|
||||
status = ncFile_open(path,NC_NOWRITE,&ncp->nciop);
|
||||
#else
|
||||
status = ncio_open(path, NC_NOWRITE,
|
||||
0, 0, &ncp->chunk,
|
||||
&ncp->nciop, 0);
|
||||
#endif
|
||||
if(status)
|
||||
goto unwind_alloc;
|
||||
|
||||
@ -1590,23 +1517,14 @@ nc_delete_mp(const char * path, int basepe)
|
||||
{
|
||||
/* Not a netcdf file, don't delete */
|
||||
/* ??? is this the right semantic? what if it was just too big? */
|
||||
#ifdef USE_NEWIO
|
||||
status = ncstdio_close(ncp->nciop,0);
|
||||
#else
|
||||
(void) ncio_close(ncp->nciop, 0);
|
||||
ncp->nciop = NULL;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef USE_NEWIO
|
||||
status = ncstdio_close(ncp->nciop,1);
|
||||
#else
|
||||
/* ncio_close does the unlink */
|
||||
status = ncio_close(ncp->nciop, 1); /* ncio_close does the unlink */
|
||||
ncp->nciop = NULL;
|
||||
#endif
|
||||
}
|
||||
ncp->nciop = NULL;
|
||||
|
||||
unwind_alloc:
|
||||
free_NC(ncp);
|
||||
|
@ -21,7 +21,6 @@ Hartnett, and Dennis Heimbigner
|
||||
- \ref building
|
||||
- \ref tutorial
|
||||
- \ref user_guide
|
||||
- <a href="index-413.html">Documentation in previous form</a>
|
||||
|
||||
\internal
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user