data_input_dims_ok Function

public function data_input_dims_ok(filename, var, nx_phys, ny_phys, is_3d, nz_src) result(ok)

Uses

    • netcdf
  • proc~~data_input_dims_ok~~UsesGraph proc~data_input_dims_ok data_input_dims_ok netcdf netcdf proc~data_input_dims_ok->netcdf

Self-contained, non-erroring dimension validator — the single-rank (i_offset_global = j_offset_global = 0) testable twin of register_common’s inline checks; mirrors zinit_dims_ok. Opens filename, inspects var’s rank and lengths, and returns .false. on any mismatch, missing variable, or I/O error — NEVER aborts, so test code can probe the false branch without a subprocess/death-test harness (the house convention — see zinit_dims_ok).

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename
character(len=*), intent(in) :: var
integer, intent(in) :: nx_phys
integer, intent(in) :: ny_phys
logical, intent(in) :: is_3d
integer, intent(in), optional :: nz_src

Return Value logical


Calls

proc~~data_input_dims_ok~~CallsGraph proc~data_input_dims_ok data_input_dims_ok nf90_close nf90_close proc~data_input_dims_ok->nf90_close nf90_inq_varid nf90_inq_varid proc~data_input_dims_ok->nf90_inq_varid nf90_inquire_dimension nf90_inquire_dimension proc~data_input_dims_ok->nf90_inquire_dimension nf90_inquire_variable nf90_inquire_variable proc~data_input_dims_ok->nf90_inquire_variable nf90_open nf90_open proc~data_input_dims_ok->nf90_open

Variables

Type Visibility Attributes Name Initial
integer, private :: d1
integer, private :: d2
integer, private :: d3
integer, private :: expect_nd
integer, private :: ierr
integer, private :: ncid
integer, private :: var_dimids(4)
integer, private :: var_ndims
integer, private :: varid

Source Code

   function data_input_dims_ok(filename, var, nx_phys, ny_phys, is_3d, nz_src) result(ok)
      !! Self-contained, non-erroring dimension validator — the
      !! single-rank (`i_offset_global = j_offset_global = 0`) testable
      !! twin of `register_common`'s inline checks; mirrors
      !! `zinit_dims_ok`.  Opens `filename`, inspects `var`'s rank and
      !! lengths, and returns `.false.` on any mismatch, missing
      !! variable, or I/O error — NEVER aborts, so test code can probe
      !! the false branch without a subprocess/death-test harness (the
      !! house convention — see `zinit_dims_ok`).
      use netcdf, only: nf90_open, nf90_close, nf90_nowrite
      character(len=*), intent(in) :: filename, var
      integer, intent(in) :: nx_phys, ny_phys
      logical, intent(in) :: is_3d
      integer, intent(in), optional :: nz_src
      logical :: ok

      integer :: ncid, varid, ierr, var_ndims, expect_nd
      integer :: var_dimids(4)
      integer :: d1, d2, d3

      ok = .false.
      ierr = nf90_open(trim(filename), nf90_nowrite, ncid)
      if (ierr /= nf90_noerr) return

      expect_nd = merge(4, 3, is_3d)
      ierr = nf90_inq_varid(ncid, trim(var), varid)
      if (ierr == nf90_noerr) then
         ierr = nf90_inquire_variable(ncid, varid, ndims=var_ndims, &
                                      dimids=var_dimids(1:expect_nd))
      end if
      if (ierr == nf90_noerr .and. var_ndims /= expect_nd) ierr = -1
      if (ierr == nf90_noerr) ierr = nf90_inquire_dimension(ncid, var_dimids(1), len=d1)
      if (ierr == nf90_noerr) ierr = nf90_inquire_dimension(ncid, var_dimids(2), len=d2)
      if (is_3d .and. ierr == nf90_noerr) then
         ierr = nf90_inquire_dimension(ncid, var_dimids(3), len=d3)
      end if

      if (ierr == nf90_noerr) then
         ok = (d1 >= nx_phys) .and. (d2 >= ny_phys)
         if (is_3d .and. present(nz_src)) ok = ok .and. (d3 == nz_src)
      end if

      ierr = nf90_close(ncid)
   end function data_input_dims_ok