|
NEP 4.3.0
NetCDF Expansion Pack
|
File state, markers, synchronization, and cleanup for nxCDF. More...
#include "nxcdf/nxcdf.h"#include "config.h"#include <stdlib.h>#include <string.h>#include "nxcdf_internal.h"Functions | |
| static int | swmr_schema (NC_GRP_INFO_T *grp) |
| Check the complete tree for schema excluded from SWMR writer sessions. | |
| int | nxcdf_swmr_validate (NC_FILE_INFO_T *h5, NXCDF_FILE_INFO_T *file) |
| Preflight native serial SWMR without changing definitions or file bounds. | |
| int | nxcdf_swmr_activate (NC_FILE_INFO_T *h5, NXCDF_FILE_INFO_T *file) |
| Activate a committed session without recursively entering enddef. | |
| static int | swmr_flush_group (NC_GRP_INFO_T *grp, int scales) |
| Flush variable datasets or dimension scales throughout a group tree. | |
| int | nxcdf_swmr_flush (NC_FILE_INFO_T *h5, NXCDF_FILE_INFO_T *file) |
| Publish all variable data before flushing dimension scales and the file. | |
| static int | swmr_file (int ncid, NC_FILE_INFO_T **h5p, NXCDF_FILE_INFO_T **filep) |
| Resolve public SWMR IDs without casting another backend's private state. | |
| int | nc_start_swmr_write (int ncid) |
| Start the writer session described by nc_start_swmr_write() in nep.h. See nep.h for parameter, return-value and lifecycle documentation. | |
| int | nc_swmr_flush (int ncid) |
| Publish a writer session as specified by nc_swmr_flush() in nep.h. See nep.h for parameter, return-value and publication documentation. | |
| static int | swmr_refresh_group (NC_GRP_INFO_T *grp, int scales) |
| Refresh variable datasets or dimension scales throughout a group tree. | |
| int | nxcdf_swmr_read_aliases (NC_GRP_INFO_T *grp) |
| Collapse coordinate-variable alias handles to a single dataset id. | |
| int | nxcdf_swmr_refresh (NC_FILE_INFO_T *h5, NXCDF_FILE_INFO_T *file) |
| Refresh all variable data before reloading dimension-scale extents. | |
| int | nc_swmr_refresh (int ncid) |
| Refresh a reader session as specified by nc_swmr_refresh() in nep.h. See nep.h for parameter, return-value and visibility documentation. | |
| void | nxcdf_close_group_hdf (NC_GRP_INFO_T *grp) |
| Recursively close the HDF5 objects belonging to a group. | |
| void | nxcdf_scrub_extended_atomic_data (NC_GRP_INFO_T *grp) |
| Release attribute data and variable fill values that netcdf-c's teardown cannot reclaim. | |
| int | NXCDF_free_file (NXCDF_FILE_INFO_T *file) |
| Close a NXCDF_FILE_INFO_T's HDF5 handles and free it. | |
| int | NXCDF_add_file (int ncid, const char *path, int mode, NXCDF_FILE_INFO_T **filep) |
| Allocate per-file state and attach it to netcdf-c's open-file list. | |
| int | NXCDF_get_file (int ncid, NC_FILE_INFO_T **h5p, NXCDF_FILE_INFO_T **filep) |
| Resolve both the shared and nxCDF-private file state for an ncid. | |
| static int | write_string_att (hid_t location, const char *name, const char *value) |
| Write a null-terminated scalar HDF5 string attribute. | |
| int | NXCDF_write_markers (NXCDF_FILE_INFO_T *file) |
| Write the hidden marker attributes identifying the file as nxCDF. | |
| int | NXCDF_read_markers (NXCDF_FILE_INFO_T *file) |
| Read and validate the hidden marker attributes at open. | |
| int | NXCDF_sync (int ncid) |
| Flush pending writes — the nc_sync() dispatch entry. | |
| int | NXCDF_close (int ncid, void *parameters) |
| Flush, close, and release a file — the nc_close() dispatch entry. | |
| int | NXCDF_abort (int ncid) |
| Abort a file — the nc_abort() dispatch entry. | |
| int | NXCDF_inq_format (int ncid, int *formatp) |
| Report the public format class — the nc_inq_format() dispatch entry. | |
| int | NXCDF_inq_format_extended (int ncid, int *formatp, int *modep) |
| Report the extended format and effective mode — the nc_inq_format_extended() dispatch entry. | |
| static int | commit_group_vars (NC_FILE_INFO_T *h5, NXCDF_FILE_INFO_T *file, NC_GRP_INFO_T *grp) |
| Rebuild dirty variable datasets and mark them committed. | |
| int | NXCDF__enddef (int ncid, size_t h_minfree, size_t v_align, size_t v_minfree, size_t r_align) |
| Materialize pending metadata and leave define mode — the nc_enddef() dispatch entry. | |
| int | NXCDF_redef (int ncid) |
| Return the file to define mode — the nc_redef() dispatch entry. | |
| int | NXCDF_check_mode (int mode) |
| Reject unsupported disk, memory, sharing and parallel modes. | |
| int | NXCDF_set_fill (int ncid, int fillmode, int *old_modep) |
| Change the session default inherited by subsequently defined variables. Existing variables retain their fill properties; this does not enter define mode or persist a file-wide setting. Subgroup IDs address the same default. | |
File state, markers, synchronization, and cleanup for nxCDF.
|
static |
Rebuild dirty variable datasets and mark them committed.
Def-var setters only record their settings and flag the variable dcpl_dirty; _enddef performs the single rebuild per variable that the immutable HDF5 creation properties require. Afterwards every variable with a live dataset is marked var->created, so post-commit setter calls fail with NC_ELATEDEF, matching upstream.
| h5 | NetCDF-4 file state. |
| file | nxCDF file state. |
| grp | Group to walk (recursively). |
| int nc_start_swmr_write | ( | int | ncid | ) |
Start the writer session described by nc_start_swmr_write() in nep.h. See nep.h for parameter, return-value and lifecycle documentation.
Start a single-writer/multiple-reader session on a native nxCDF file.
| int nc_swmr_flush | ( | int | ncid | ) |
Publish a writer session as specified by nc_swmr_flush() in nep.h. See nep.h for parameter, return-value and publication documentation.
Publish all datasets and dimension scales of an active SWMR writer.
| int nc_swmr_refresh | ( | int | ncid | ) |
Refresh a reader session as specified by nc_swmr_refresh() in nep.h. See nep.h for parameter, return-value and visibility documentation.
Refresh a nxCDF SWMR reader session so newly published data becomes visible.
| int NXCDF__enddef | ( | int | ncid, |
| size_t | h_minfree, | ||
| size_t | v_align, | ||
| size_t | v_minfree, | ||
| size_t | r_align ) |
Materialize pending metadata and leave define mode — the nc_enddef() dispatch entry.
While a file is in define mode, nc_def_dim/nc_def_var/ nc_put_att only build the in-memory NC_*_INFO_T tree. _enddef is where it all becomes HDF5: NXCDF_write_types() and the metadata writer in nxcdf_meta.c create the committed datatypes, dimension scales, variable datasets and attributes, then the file flushes and switches to data mode. The alignment arguments exist in the dispatch signature for netcdf-c compatibility but are ignored.
| ncid | NetCDF file identifier. |
| h_minfree | Ignored (reserved for future alignment control). |
| v_align | Ignored (reserved for future alignment control). |
| v_minfree | Ignored (reserved for future alignment control). |
| r_align | Ignored (reserved for future alignment control). |
| int NXCDF_abort | ( | int | ncid | ) |
Abort a file — the nc_abort() dispatch entry.
Dispatch-table entry behind nc_abort(): releases the file's resources; shares the close path.
For nxCDF abort and close share the release path; HDF5 simply discards unflushed state.
| ncid | NetCDF file identifier. |
| int NXCDF_add_file | ( | int | ncid, |
| const char * | path, | ||
| int | mode, | ||
| NXCDF_FILE_INFO_T ** | filep ) |
Allocate per-file state and attach it to netcdf-c's open-file list.
Called by both NXCDF_create() and NXCDF_open(). netcdf-c's nc4_file_list_add creates the shared NC_FILE_INFO_T (with a root NC_GRP_INFO_T); this function then allocates the nxCDF-private NXCDF_FILE_INFO_T and hangs it on format_file_info, plus a NXCDF_GRP_INFO_T on the root group. New files start in define mode with hdfid/rootid unset.
| ncid | NetCDF file identifier. |
| path | File-system path. |
| mode | Effective NetCDF mode. |
| filep | Destination for the allocated state. |
| int NXCDF_check_mode | ( | int | mode | ) |
Reject unsupported disk, memory, sharing and parallel modes.
Validate unsupported create/open flags; return NC_EINVAL if present.
| mode | NetCDF create/open flags, including the UDF selector. |
| int NXCDF_close | ( | int | ncid, |
| void * | parameters ) |
Flush, close, and release a file — the nc_close() dispatch entry.
Dispatch-table entry behind nc_close(): ends define mode if needed, flushes, closes all HDF5 objects and frees state.
A file still in define mode is _enddef'd first (materializing its pending metadata), then all HDF5 handles are closed recursively, the file is flushed if writable, and the state is freed and removed from netcdf-c's open-file list.
| ncid | NetCDF file identifier. |
| parameters | Optional close parameters; currently ignored. |
| void nxcdf_close_group_hdf | ( | NC_GRP_INFO_T * | grp | ) |
Recursively close the HDF5 objects belonging to a group.
At close time every open hid_t under a group must be released: the group's own NXCDF_GRP_INFO_T::hdf_group (skipping the root, whose handle is closed separately via rootid), each variable's dataset hid_t, each dimension's scale hid_t, then all children. HDF5 calls are wrapped in H5E_BEGIN_TRY/H5E_END_TRY so a partially-closed tree does not print spurious error stacks.
| grp | Group. |
| int NXCDF_free_file | ( | NXCDF_FILE_INFO_T * | file | ) |
Close a NXCDF_FILE_INFO_T's HDF5 handles and free it.
Companion to NXCDF_add_file(): closes the root group and the HDF5 file, then releases the path and the struct. Safe to call with NULL. The H5Fget_obj_count log line is a leak check — anything but 1 (the file itself) after H5Fclose means an object was left open.
| file | State to release; may be NULL. |
| int NXCDF_get_file | ( | int | ncid, |
| NC_FILE_INFO_T ** | h5p, | ||
| NXCDF_FILE_INFO_T ** | filep ) |
Resolve both the shared and nxCDF-private file state for an ncid.
Almost every dispatch entry begins here: nc4_find_grp_h5 maps the ncid to netcdf-c's NC_FILE_INFO_T, and format_file_info then yields the NXCDF_FILE_INFO_T. A missing private record means the ncid names a non-nxCDF file.
| ncid | NetCDF file identifier. |
| h5p | Optional destination for common NetCDF-4 state. |
| filep | Optional destination for nxCDF state. |
| int NXCDF_inq_format | ( | int | ncid, |
| int * | formatp ) |
Report the public format class — the nc_inq_format() dispatch entry.
Dispatch-table entry behind nc_inq_format(): reports NC_FORMAT_NETCDF4 — nxCDF files are in the NetCDF-4/HDF5 family.
nxCDF files report as NC_FORMAT_NETCDF4: they are HDF5 files in the NetCDF-4 family, distinguishable only through nc_inq_format_extended().
| ncid | NetCDF file identifier. |
| formatp | Optional destination for NC_FORMAT_NETCDF4. |
| int NXCDF_inq_format_extended | ( | int | ncid, |
| int * | formatp, | ||
| int * | modep ) |
Report the extended format and effective mode — the nc_inq_format_extended() dispatch entry.
Dispatch-table entry behind nc_inq_format_extended(): reports NC_FORMATX_NXCDF and the effective mode flags.
Returns NC_FORMATX_NXCDF plus the mode the file actually runs with: the create/open flags plus NC_NXCDF and, for files carrying the _NxcdfModel marker, NC_NETCDF4_MODEL.
| ncid | NetCDF file identifier. |
| formatp | Optional destination for NC_FORMATX_NXCDF. |
| modep | Optional destination for the effective open/create mode. |
| int NXCDF_read_markers | ( | NXCDF_FILE_INFO_T * | file | ) |
Read and validate the hidden marker attributes at open.
Sets file->backend_marked when _NxcdfBackend matches "nxCDF/1.0", and restores netcdf4_model/NC_NETCDF4_MODEL when _NxcdfModel is present. A file without the backend marker is treated as a plain HDF5/netCDF-4 file and opened anyway — nxCDF can read upstream netCDF-4 files.
| file | Open nxCDF state. |
| int NXCDF_redef | ( | int | ncid | ) |
Return the file to define mode — the nc_redef() dispatch entry.
Flips define_mode and netcdf-c's NC_INDEF flag; the next _enddef writes any newly defined metadata to HDF5.
| ncid | NetCDF file identifier. |
| void nxcdf_scrub_extended_atomic_data | ( | NC_GRP_INFO_T * | grp | ) |
Release attribute data and variable fill values that netcdf-c's teardown cannot reclaim.
nc4_file_list_del() reclaims every att->data and var->fill_value through NC_reclaim_data(), which routes any type id above NC_MAX_ATOMIC_TYPE to nc4_find_type(). The NEP extended atomic types (NC_FLOAT16 through the ids below NC_FIRSTUSERTYPEID) are not registered user types, so the lookup fails and the recursive teardown aborts early, leaking the whole group/var/att tree. Their payloads are flat malloc'd blocks — no nested allocations — so they are released here directly and the attribute's type id is rewritten to NC_BYTE so upstream's reclaim pass skips it.
Must run after all attribute/fill metadata has been materialized to HDF5 and immediately before nc4_file_list_del().
| grp | Root group to scrub; recurses into children. |
| int NXCDF_set_fill | ( | int | ncid, |
| int | fillmode, | ||
| int * | old_modep ) |
Change the session default inherited by subsequently defined variables. Existing variables retain their fill properties; this does not enter define mode or persist a file-wide setting. Subgroup IDs address the same default.
Set the session fill default for subsequently defined variables.
| ncid | File or group identifier. |
| fillmode | NC_FILL or NC_NOFILL. |
| old_modep | Optional destination for the previous session default. |
| int nxcdf_swmr_activate | ( | NC_FILE_INFO_T * | h5, |
| NXCDF_FILE_INFO_T * | file ) |
Activate a committed session without recursively entering enddef.
| h5 | Shared NetCDF file metadata in data mode. |
| file | nxCDF session state. |
| int nxcdf_swmr_flush | ( | NC_FILE_INFO_T * | h5, |
| NXCDF_FILE_INFO_T * | file ) |
Publish all variable data before flushing dimension scales and the file.
| h5 | Shared NetCDF metadata. |
| file | Active writable SWMR file. |
| int nxcdf_swmr_read_aliases | ( | NC_GRP_INFO_T * | grp | ) |
Collapse coordinate-variable alias handles to a single dataset id.
Two open handles to the same HDF5 object defeat SWMR data visibility in a reader: reads through either handle stay frozen at the open-time snapshot even after H5Drefresh. A coordinate variable holds such a pair — the dimension's scale handle and the variable's own handle — so a reader keeps only the variable's handle and points the dimension record at it. The surviving handle must be closed only once; nxcdf_close_group_hdf() already tolerates an identifier that was closed twice.
| grp | Subtree to walk, in metadata index order. |
| int nxcdf_swmr_refresh | ( | NC_FILE_INFO_T * | h5, |
| NXCDF_FILE_INFO_T * | file ) |
Refresh all variable data before reloading dimension-scale extents.
Whole-file reader refresh behind nc_swmr_refresh(). The order matters: a coordinate variable's scale is refreshed through the variable's own dataset handle after the alias collapse, so variables are refreshed first and the scale pass only needs to recover extents. Re-running nxcdf_swmr_read_aliases() first is defensive — a session cache tuning call (nxcdf_reopen_var_cache) closes and reopens the alias pair, which would silently restore the poisonous duplicate handles.
| h5 | Shared NetCDF metadata. |
| file | Read-only SWMR reader file. |
| int nxcdf_swmr_validate | ( | NC_FILE_INFO_T * | h5, |
| NXCDF_FILE_INFO_T * | file ) |
Preflight native serial SWMR without changing definitions or file bounds.
| h5 | Shared NetCDF file metadata. |
| file | nxCDF session state. |
| int NXCDF_sync | ( | int | ncid | ) |
Flush pending writes — the nc_sync() dispatch entry.
Dispatch-table entry behind nc_sync(): flushes a writable file to storage.
Read-only files are a no-op.
| ncid | NetCDF file identifier. |
| int NXCDF_write_markers | ( | NXCDF_FILE_INFO_T * | file | ) |
Write the hidden marker attributes identifying the file as nxCDF.
Every nxCDF file gets _NxcdfBackend = "nxCDF/1.0" on the root group — this is what NXCDF_read_markers checks at open to distinguish nxCDF files from upstream netCDF-4/HDF5 files. Files created with NC_NETCDF4_MODEL additionally get the integer _NxcdfModel marker so the compatibility mode survives reopen. See nxCDF Architecture.
| file | Open writable nxCDF state. |
|
static |
Resolve public SWMR IDs without casting another backend's private state.
Shared ncid validation for nc_start_swmr_write(), nc_swmr_flush() and nc_swmr_refresh(). NC_check_id accepts a file or group ncid; the dispatch-table comparison then proves the file really is nxCDF before any NXCDF_FILE_INFO_T fields are dereferenced, so ids belonging to upstream netcdf-4 or another UDF get a clean NC_ENOTNC4 instead of a bad cast.
| ncid | File or group ID. |
| h5p | Destination for shared metadata. |
| filep | Destination for nxCDF state. |
|
static |
Flush variable datasets or dimension scales throughout a group tree.
| grp | Subtree to flush, in metadata index order. |
| scales | Nonzero selects scales, zero selects variables. |
|
static |
Refresh variable datasets or dimension scales throughout a group tree.
Mirrors swmr_flush_group on the reader side, and is called twice by nxcdf_swmr_refresh(): once with scales zero for the variable index, once nonzero for the dimension index. Variable datasets get a bare H5Drefresh, which brings the handle's view of extent and raw data up to the writer's last publication. Dimension-scale datasets are additionally polled for their current extent, which is reloaded into the cached dim->len that nc_inq_dimlen() reports — the metadata tree is otherwise untouched, since a SWMR writer cannot create new objects. Read paths reacquire the dataspace per call, so no further per-variable state needs resetting here.
| grp | Subtree to refresh, in metadata index order. |
| scales | Nonzero selects scales, zero selects variables. |
|
static |
Check the complete tree for schema excluded from SWMR writer sessions.
| grp | Root of the subtree to validate. |
|
static |
Write a null-terminated scalar HDF5 string attribute.
Helper for NXCDF_write_markers(): creates a scalar dataspace and a fixed-size, null-terminated string type sized to the value, then writes it. All HDF5 handles are closed on both paths.
| location | HDF5 location identifier. |
| name | Name. |
| value | Data buffer. |