Validate the T/S variable’s dims against the model grid and
detect whether the file is C-ordered (z, y, x) =>
needs_transpose = .true. (by the first Fortran dim name).
Returns source z-level count nz_src; error-stops on mismatch.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(in) | :: | varid | |||
| type(hgrid_t), | intent(in) | :: | grid | |||
| integer, | intent(out) | :: | nz_src | |||
| logical, | intent(out) | :: | needs_transpose | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero on a dimensionality/shape mismatch when present;
absent behaves as today ( |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private | :: | d1_len | ||||
| character(len=64), | private | :: | d1_name | ||||
| integer, | private | :: | d2_len | ||||
| integer, | private | :: | d3_len | ||||
| integer, | private | :: | local_ierr | ||||
| logical, | private | :: | ok | ||||
| integer, | private | :: | var_dimids(3) | ||||
| integer, | private | :: | var_ndims |
subroutine read_dims(ncid, varid, grid, nz_src, needs_transpose, ierr) !! Validate the T/S variable's dims against the model grid and !! detect whether the file is C-ordered (z, y, x) => !! `needs_transpose = .true.` (by the first Fortran dim name). !! Returns source z-level count `nz_src`; error-stops on mismatch. integer, intent(in) :: ncid, varid type(hgrid_t), intent(in) :: grid integer, intent(out) :: nz_src logical, intent(out) :: needs_transpose integer, intent(out), optional :: ierr !! Non-zero on a dimensionality/shape mismatch when present; !! absent behaves as today (`error stop`). integer :: var_ndims integer :: var_dimids(3) integer :: d1_len, d2_len, d3_len integer :: local_ierr character(len=64) :: d1_name logical :: ok call nc_check(nf90_inquire_variable(ncid, varid, ndims=var_ndims, dimids=var_dimids), & "querying z-level T/S variable", local_ierr) if (.not. zinit_io_ok(local_ierr, ierr, ncid)) return if (var_ndims /= 3) then call nc_close(ncid) call fail("ocean_zinit: T/S variable must be 3D (x,y,z); got "// & to_string(var_ndims)//" dims", ierr, OCEAN_STATUS_ERR_IO) return end if call nc_check(nf90_inquire_dimension(ncid, var_dimids(1), name=d1_name, len=d1_len), & "querying T/S dim 1", local_ierr) if (.not. zinit_io_ok(local_ierr, ierr, ncid)) return call nc_check(nf90_inquire_dimension(ncid, var_dimids(2), len=d2_len), & "querying T/S dim 2", local_ierr) if (.not. zinit_io_ok(local_ierr, ierr, ncid)) return call nc_check(nf90_inquire_dimension(ncid, var_dimids(3), len=d3_len), & "querying T/S dim 3", local_ierr) if (.not. zinit_io_ok(local_ierr, ierr, ncid)) return ! C-ordered files store temp(x,y,z); Fortran's NetCDF lib reverses ! that to temp(z,y,x) so dim1 is "z". Fortran-ordered files keep ! dim1 == "x". needs_transpose = (trim(d1_name) == "z" .or. trim(d1_name) == "depth" .or. & trim(d1_name) == "lev" .or. trim(d1_name) == "z_src") if (needs_transpose) then ! Fortran storage (z, y, x): physical lengths are d3=x, d2=y, d1=z. ok = (d3_len == grid%nx_global .and. d2_len == grid%ny_global) nz_src = d1_len else ! Fortran storage (x, y, z): physical lengths are d1=x, d2=y, d3=z. ok = (d1_len == grid%nx_global .and. d2_len == grid%ny_global) nz_src = d3_len end if if (.not. ok) then call nc_close(ncid) call fail("ocean_zinit: T/S grid mismatch: file horizontal dims do not match "// & "simulation "//to_string(grid%nx_global)//" x "//to_string(grid%ny_global), & ierr, OCEAN_STATUS_ERR_IO) return end if if (present(ierr)) ierr = OCEAN_STATUS_OK end subroutine read_dims