Provides NetCDF read/write primitives and an error-checking helper. Used by bathymetry loader and output writer.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | public, | parameter | :: | NC_R4 | = | nf90_float |
Explicit 32-bit NetCDF element type. Used ONLY by the ocean
diagnostic stream when |
| integer, | public, | parameter | :: | NC_WP | = | nf90_float |
NetCDF type matching working precision |
Generate a per-rank filename:
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | base_dir |
Output directory |
||
| character(len=*), | intent(in) | :: | prefix |
File prefix (e.g. “output” or “restart”) |
||
| integer, | intent(in) | :: | rank |
MPI rank number |
Pack a Fortran string into a null-terminated c_char array for
the mkdir binding above. Private duplicate of
rdb_ocean_restart_io’s string_to_c (that one is private to
its own module) — small enough that sharing it is not worth a
cross-module dependency for a two-line helper.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | s |
Create path via libc mkdir(2) if it does not already exist
(single path component — not a recursive mkdir -p; a missing
grandparent still fails, loudly, at the inquire re-check
below). Exists to close the headline P7 crash: &ocean_diag_nml/
&output_nml default output_dir = "./output"
(rdb_config.F90:2316), so a first-time create() against a
fresh checkout with no ./output/ directory would otherwise
reach nc_create_file -> nf90_create -> ENOENT ->
error stop, killing the whole host process.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | path | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero iff |
Check NetCDF return status and log error if it failed
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | status |
Return code from nf90_* call |
||
| character(len=*), | intent(in) | :: | context |
Description of what was being attempted |
||
| integer, | intent(out), | optional | :: | ierr |
Non-zero (the raw |
Close a NetCDF file
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Create a new NetCDF-4 file (overwrites if exists)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | filename | |||
| integer, | intent(out) | :: | ncid | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero (e.g. a missing output directory) when present; absent
behaves as today ( |
Define a dimension (use nf90_unlimited for unlimited)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| character(len=*), | intent(in) | :: | name | |||
| integer, | intent(in) | :: | length | |||
| integer, | intent(out) | :: | dimid | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Define a 2D variable with working precision type
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| character(len=*), | intent(in) | :: | name | |||
| integer, | intent(in) | :: | dimids(2) | |||
| integer, | intent(out) | :: | varid | |||
| integer, | intent(in), | optional | :: | deflate_level |
Compression level (0=none, 1-9=deflate). Enables shuffle when > 0. |
|
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Define a 3D variable (x, y, time) with working precision type
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| character(len=*), | intent(in) | :: | name | |||
| integer, | intent(in) | :: | dimids(3) | |||
| integer, | intent(out) | :: | varid | |||
| integer, | intent(in), | optional | :: | deflate_level |
Compression level (0=none, 1-9=deflate). Enables shuffle when > 0. |
|
| integer, | intent(in), | optional | :: | xtype |
NetCDF element type. Absent => |
|
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Define a 4D variable (x, y, z, time) with working precision type
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| character(len=*), | intent(in) | :: | name | |||
| integer, | intent(in) | :: | dimids(4) | |||
| integer, | intent(out) | :: | varid | |||
| integer, | intent(in), | optional | :: | deflate_level |
Compression level (0=none, 1-9=deflate). Enables shuffle when > 0. |
|
| integer, | intent(in), | optional | :: | xtype |
NetCDF element type. Absent => |
|
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
End define mode, switch to data mode
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Read a global integer attribute
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| character(len=*), | intent(in) | :: | name | |||
| integer, | intent(out) | :: | value | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Read a character (text) attribute from a variable — used for the
CF units attribute on a time axis. Non-fail-loud: ok is
.false. (and value blank) when the attribute is absent or the
wrong type, so callers can fall back to a default rather than
aborting on a missing/optional attribute.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| character(len=*), | intent(in) | :: | name | |||
| character(len=:), | intent(out), | allocatable | :: | value |
Deferred-length (not assumed-length |
|
| logical, | intent(out) | :: | ok |
Get the length of a named dimension
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| character(len=*), | intent(in) | :: | name | |||
| integer, | intent(out) | :: | length | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero (missing dimension) when present; absent behaves as
today ( |
Read a full 1D array (the read sibling of rdb_put_var_1d).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| real(kind=wp), | intent(inout) | :: | data(:) | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Read a full 2D array
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| real(kind=wp), | intent(inout) | :: | data(:,:) | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Read a full 3D array. Mirrors nc_get_var_2d; the target’s
shape must match the file variable’s Fortran storage order
(the caller handles any C/Fortran dimension reversal, as
rdb_bathymetry does for 2D).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| real(kind=wp), | intent(inout) | :: | data(:,:,:) | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Windowed read of a 2D variable: start/count (length 2, FORTRAN
dimension order) select the block that lands in data, whose
shape must equal count. The per-rank readers (bathymetry,
supergrid) use it to load only the rows their tile needs.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| integer, | intent(in) | :: | start(2) | |||
| integer, | intent(in) | :: | count(2) | |||
| real(kind=wp), | intent(inout) | :: | data(:,:) | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Strided slab read: start/count are the NetCDF start/count
vectors in FORTRAN dimension order, with length matching the
target variable’s rank (3 for a 2D-field-plus-time variable, 4
for a 3D-field-plus-time variable). data is always a plain
3D Fortran array; for the 2D-plus-time case pass a target with
a trailing singleton extent (data(:,:,1)) — the netcdf-fortran
generic interface dispatches on the array RANK of data, not
the length of start/count, so one routine covers both
shapes. This is the first strided (non-full-variable) read in
the tree — mirrors nc_put_var_4d_slice for the start/count
shape, on the read side.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| integer, | intent(in) | :: | start(:) | |||
| integer, | intent(in) | :: | count(:) | |||
| real(kind=wp), | intent(inout) | :: | data(:,:,:) | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Get the variable ID for a named variable
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| character(len=*), | intent(in) | :: | name | |||
| integer, | intent(out) | :: | varid | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero (no matching variable) when present; absent behaves
as today ( |
Open an existing NetCDF file for reading
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | filename | |||
| integer, | intent(out) | :: | ncid | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero (a missing/unreadable file) when present; absent
behaves as today ( |
Open an existing NetCDF file for writing
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | filename | |||
| integer, | intent(out) | :: | ncid | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Write a character attribute to a variable
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| character(len=*), | intent(in) | :: | name | |||
| character(len=*), | intent(in) | :: | value | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Write a global character attribute
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| character(len=*), | intent(in) | :: | name | |||
| character(len=*), | intent(in) | :: | value | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Write a global integer attribute
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| character(len=*), | intent(in) | :: | name | |||
| integer, | intent(in) | :: | value | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Write an integer attribute to a variable
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| character(len=*), | intent(in) | :: | name | |||
| integer, | intent(in) | :: | value | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Write a real-valued attribute to a variable
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| character(len=*), | intent(in) | :: | name | |||
| real(kind=wp), | intent(in) | :: | value | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Write a 32-bit real attribute to a variable. NetCDF rejects a
_FillValue whose type differs from the variable’s, so a variable
defined with NC_R4 must have its _FillValue / missing_value
written through here, not through nc_put_att_real (real64).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| character(len=*), | intent(in) | :: | name | |||
| real(kind=real32), | intent(in) | :: | value | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Write a full 2D array
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| real(kind=wp), | intent(in) | :: | data(:,:) | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Write a 2D slice into a 3D variable at a given time index
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| real(kind=wp), | intent(in) | :: | data(:,:) | |||
| integer, | intent(in) | :: | time_index | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Write a 32-bit 2D slice into a 3D variable at a given time index.
The real32 twin of nc_put_var_3d_slice: handing real64 data to
an NF90_FLOAT variable is legal (netcdf converts) but writes the
same bytes at twice the host->library traffic, so the diag writer
stages the conversion itself and calls this.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| real(kind=real32), | intent(in) | :: | data(:,:) | |||
| integer, | intent(in) | :: | time_index | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Write a 3D slice into a 4D variable at a given time index
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| real(kind=wp), | intent(in) | :: | data(:,:,:) | |||
| integer, | intent(in) | :: | time_index | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Write a 32-bit 3D slice into a 4D variable at a given time index.
The real32 twin of nc_put_var_4d_slice.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| real(kind=real32), | intent(in) | :: | data(:,:,:) | |||
| integer, | intent(in) | :: | time_index | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Define a 1D variable with working precision type
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| character(len=*), | intent(in) | :: | name | |||
| integer, | intent(in) | :: | dimid | |||
| integer, | intent(out) | :: | varid | |||
| integer, | intent(in), | optional | :: | deflate_level |
Compression level (0=none, 1-9=deflate). Enables shuffle when > 0. |
|
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Write a full 1D array
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| real(kind=wp), | intent(in) | :: | data(:) | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |
Write a 1D slice into a 2D variable at a given time index
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| real(kind=wp), | intent(in) | :: | data(:) | |||
| integer, | intent(in) | :: | time_index | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on failure when present; absent behaves as today
( |