pure integer function parse_vcoord_type(str, default_code) result(coord_type)
!! Convert a namelist string to a `VCOORD_*` constant (shared by coastal
!! and ocean backends). Unrecognised ⇒ `default_code` if given, else
!! `VCOORD_SIGMA`. Ocean callers pass `default_code = VCOORD_EULERIAN_Z`.
character(len=*), intent(in) :: str
integer, intent(in), optional :: default_code
integer :: fallback
fallback = VCOORD_SIGMA
if (present(default_code)) fallback = default_code
select case (trim(adjustl(str)))
case ("lagrangian", "LAGRANGIAN", "isopycnal", "ISOPYCNAL")
coord_type = VCOORD_LAGRANGIAN
case ("eulerian_z", "EULERIAN_Z", "z", "Z")
coord_type = VCOORD_EULERIAN_Z
case ("sigma", "SIGMA")
coord_type = VCOORD_SIGMA
case ("zsigma", "ZSIGMA", "z-sigma", "z_sigma")
coord_type = VCOORD_ZSIGMA
case ("zstar", "ZSTAR", "z-star", "z_star", "zstar_lite", "ZSTAR_LITE")
coord_type = VCOORD_ZSTAR
case ("zstar_full", "ZSTAR_FULL", "z-star-full", "z_star_full", "zstarfull")
coord_type = VCOORD_ZSTAR_FULL
case ("zstar_sigma", "ZSTAR_SIGMA", "z-star-sigma", "z_star_sigma", "zstarsigma")
coord_type = VCOORD_ZSTAR_SIGMA
case ("z_fixed", "Z_FIXED", "z_levels", "Z_LEVELS", "gprime", "GPRIME")
coord_type = VCOORD_Z_FIXED
case ("rho", "RHO", "isopycnic", "ISOPYCNIC", "rho_target", "RHO_TARGET")
coord_type = VCOORD_RHO
case ("hycom", "HYCOM", "hybrid", "HYBRID")
coord_type = VCOORD_HYCOM
case default
coord_type = fallback
end select
end function parse_vcoord_type