configure_ocean_tides Subroutine

public subroutine configure_ocean_tides(cfg, ocean_state, grid, compute_rank, ierr)

Configure the equilibrium body-force tide slot (C1): parse the constituent list + reference dates, fill the astronomy catalog (phase0, nodal f/u), and build the (nx,ny,3) spatial-structure arrays from metrics%geolatT/geolonT. Host-side setup — runs AFTER configure_ocean_metrics (lat/lon must be filled) and BEFORE ocean_state_enter_data. enable=.false. => no-op, bit-identical.

Arguments

Type IntentOptional Attributes Name
type(config_t), intent(in) :: cfg
type(ocean_state_t), intent(inout) :: ocean_state
type(hgrid_t), intent(in) :: grid
integer, intent(in) :: compute_rank
integer, intent(out), optional :: ierr

Non-zero on a tides configuration conflict when present; absent behaves as today (error stop).


Calls

proc~~configure_ocean_tides~~CallsGraph proc~configure_ocean_tides configure_ocean_tides info info proc~configure_ocean_tides->info proc~days_since_1900 days_since_1900 proc~configure_ocean_tides->proc~days_since_1900 proc~fail fail proc~configure_ocean_tides->proc~fail proc~parse_constituent_list parse_constituent_list proc~configure_ocean_tides->proc~parse_constituent_list proc~parse_date_string parse_date_string proc~configure_ocean_tides->proc~parse_date_string proc~tides_build_struct tides_build_struct proc~configure_ocean_tides->proc~tides_build_struct proc~tides_configure_astronomy tides_configure_astronomy proc~configure_ocean_tides->proc~tides_configure_astronomy to_string to_string proc~configure_ocean_tides->to_string warning warning proc~configure_ocean_tides->warning proc~gregorian_day_number gregorian_day_number proc~days_since_1900->proc~gregorian_day_number error error proc~fail->error proc~error_ring_push error_ring_push proc~fail->proc~error_ring_push proc~parse_constituent_list->proc~fail proc~tide_name_index tide_name_index proc~parse_constituent_list->proc~tide_name_index proc~equilibrium_arguments equilibrium_arguments proc~tides_configure_astronomy->proc~equilibrium_arguments proc~nodal_fu nodal_fu proc~tides_configure_astronomy->proc~nodal_fu proc~mean_longitudes mean_longitudes proc~equilibrium_arguments->proc~mean_longitudes proc~nodal_fu->proc~mean_longitudes proc~upcase2 upcase2 proc~tide_name_index->proc~upcase2 proc~wrap360 wrap360 proc~mean_longitudes->proc~wrap360

Called by

proc~~configure_ocean_tides~~CalledByGraph proc~configure_ocean_tides configure_ocean_tides proc~engine_setup engine_setup proc~engine_setup->proc~configure_ocean_tides proc~complete_ocean_create complete_ocean_create proc~complete_ocean_create->proc~engine_setup proc~driver_run_ocean driver_run_ocean proc~driver_run_ocean->proc~engine_setup proc~driver_validate driver_validate proc~driver_validate->proc~engine_setup proc~driver_run driver_run proc~driver_run->proc~driver_run_ocean proc~rdb_ocean_create_finalize rdb_ocean_create_finalize proc~rdb_ocean_create_finalize->proc~complete_ocean_create proc~rdb_ocean_create_from_string rdb_ocean_create_from_string proc~rdb_ocean_create_from_string->proc~complete_ocean_create

Variables

Type Visibility Attributes Name Initial
integer, private :: cat_idx(TIDES_CATALOG_SIZE)
integer, private :: d
real(kind=wp), private :: dnodal
real(kind=wp), private :: dref
integer, private :: local_ierr
integer, private :: m
integer, private :: nconst
character(len=16), private :: nodal_str
integer, private :: nx
integer, private :: ny
logical, private :: ok
integer, private :: y

Source Code

   subroutine configure_ocean_tides(cfg, ocean_state, grid, compute_rank, ierr)
      !! Configure the equilibrium body-force tide slot (C1): parse the
      !! constituent list + reference dates, fill the astronomy catalog
      !! (phase0, nodal f/u), and build the (nx,ny,3) spatial-structure
      !! arrays from `metrics%geolatT/geolonT`.  Host-side setup — runs
      !! AFTER `configure_ocean_metrics` (lat/lon must be filled) and
      !! BEFORE `ocean_state_enter_data`.  `enable=.false.` => no-op,
      !! bit-identical.
      type(config_t), intent(in) :: cfg
      type(ocean_state_t), intent(inout) :: ocean_state
      type(hgrid_t), intent(in) :: grid
      integer, intent(in) :: compute_rank
      integer, intent(out), optional :: ierr
         !! Non-zero on a tides configuration conflict when present;
         !! absent behaves as today (`error stop`).
      integer :: cat_idx(TIDES_CATALOG_SIZE)
      integer :: nconst, y, m, d, nx, ny, local_ierr
      real(wp) :: dref, dnodal
      logical :: ok
      character(len=16) :: nodal_str

      associate (td => ocean_state%tides, tcfg => cfg%ocean%tides)
         td%enable = tcfg%enable
         if (.not. tcfg%enable) then
            if (present(ierr)) ierr = OCEAN_STATUS_OK
            return
         end if

         td%use_sal = tcfg%use_sal
         td%beta_sal = tcfg%beta_sal
         td%t_epoch = 0.0_wp

         if (td%use_sal .and. td%beta_sal <= 0.0_wp .and. compute_rank == 0) then
            call logger%warning("ocean_tides_nml: use_sal=.true. but "// &
                                "beta_sal<=0 => scalar SAL is inert "// &
                                "(typical beta ~0.085-0.12)")
         end if

         ! Parse the active constituent list -> catalog indices.
         if (present(ierr)) then
            call parse_constituent_list(tcfg%constituents, cat_idx, nconst, ierr=local_ierr)
            if (local_ierr /= 0) then
               ierr = local_ierr
               return
            end if
         else
            call parse_constituent_list(tcfg%constituents, cat_idx, nconst)
         end if
         if (nconst < 1) then
            call fail("ocean_tides_nml: constituents='"// &
                      trim(tcfg%constituents)//"' has no valid entries", ierr, OCEAN_STATUS_ERR_SETUP)
            return
         end if

         ! Reference date -> day number since 1900-01-01.
         call parse_date_string(tcfg%ref_date, y, m, d, ok)
         if (.not. ok) then
            call fail("ocean_tides_nml: bad ref_date '"// &
                      trim(tcfg%ref_date)//"' (want YYYY-MM-DD)", ierr, OCEAN_STATUS_ERR_SETUP)
            return
         end if
         dref = days_since_1900(y, m, d)

         nodal_str = tcfg%nodal_ref_date
         if (len_trim(nodal_str) == 0) nodal_str = tcfg%ref_date
         call parse_date_string(nodal_str, y, m, d, ok)
         if (.not. ok) then
            call fail("ocean_tides_nml: bad nodal_ref_date '"// &
                      trim(nodal_str)//"' (want YYYY-MM-DD)", ierr, OCEAN_STATUS_ERR_SETUP)
            return
         end if
         dnodal = days_since_1900(y, m, d)

         nx = grid%nx_total
         ny = grid%ny_total
         call tides_configure_astronomy(td, cat_idx(1:nconst), nconst, &
                                        dref, dnodal, tcfg%add_nodal, nx, ny)
         call tides_build_struct(td, ocean_state%metrics%geolatT, &
                                 ocean_state%metrics%geolonT, nx, ny)

         if (compute_rank == 0) then
            call logger%info("Equilibrium tide: C1 body force enabled ("// &
                             to_string(nconst)//" constituents, ref="// &
                             trim(tcfg%ref_date)//")")
         end if
      end associate
      if (present(ierr)) ierr = OCEAN_STATUS_OK
   end subroutine configure_ocean_tides