Try to find the bathymetry variable by common names
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ncid | |||
| integer, | intent(out) | :: | varid | |||
| integer, | intent(out), | optional | :: | ierr |
Non-zero when none of the recognised variable names is found,
when present; absent behaves as today (leaves |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private | :: | status |
subroutine try_get_bathymetry_var(ncid, varid, ierr) !! Try to find the bathymetry variable by common names use netcdf, only: nf90_inq_varid integer, intent(in) :: ncid integer, intent(out) :: varid integer, intent(out), optional :: ierr !! Non-zero when none of the recognised variable names is found, !! when present; absent behaves as today (leaves `varid` !! unset and lets the caller's next NetCDF call fail). integer :: status ! Try "b" first (our convention) status = nf90_inq_varid(ncid, "b", varid) if (status == nf90_noerr) then if (present(ierr)) ierr = OCEAN_STATUS_OK return end if ! Try "elevation" status = nf90_inq_varid(ncid, "elevation", varid) if (status == nf90_noerr) then if (present(ierr)) ierr = OCEAN_STATUS_OK return end if ! Try "depth" status = nf90_inq_varid(ncid, "depth", varid) if (status == nf90_noerr) then if (present(ierr)) ierr = OCEAN_STATUS_OK return end if ! None found call logger%error("No bathymetry variable found (tried: b, elevation, depth)") if (present(ierr)) then ierr = OCEAN_STATUS_ERR_IO return end if end subroutine try_get_bathymetry_var