LCOV - code coverage report
Current view: top level - physics/cam - tidal_diag.F90 (source / functions) Hit Total Coverage
Test: coverage.info Lines: 68 114 59.6 %
Date: 2025-01-13 21:54:50 Functions: 3 3 100.0 %

          Line data    Source code
       1             : module tidal_diag 
       2             : 
       3             :   !---------------------------------------------------------------------------------
       4             :   ! Module to compute fourier coefficients for the diurnal and semidiurnal tide 
       5             :   !
       6             :   ! Created by: Dan Marsh
       7             :   ! Date: 12 May 2008
       8             :   !---------------------------------------------------------------------------------
       9             : 
      10             :   use shr_kind_mod,  only: r8 => shr_kind_r8
      11             :   use ppgrid,        only: pcols, pver
      12             : 
      13             :   implicit none
      14             : 
      15             :   private
      16             : 
      17             :   ! Public interfaces
      18             : 
      19             :   public :: tidal_diag_init   ! create coefficient history file variables
      20             :   public :: tidal_diag_write  ! calculate and output dignostics
      21             :   public :: get_tidal_coeffs
      22             : 
      23             : contains
      24             : 
      25             :   !===============================================================================
      26             : 
      27     2992272 :   subroutine  tidal_diag_init()
      28             :     !----------------------------------------------------------------------- 
      29             :     ! Purpose: create fourier coefficient history file variables
      30             :     !-----------------------------------------------------------------------
      31             : 
      32             :     use cam_history, only: addfld, add_default, horiz_only
      33             :     use phys_control,only: phys_getopts
      34             : 
      35             :     logical :: history_waccm
      36             : 
      37        3072 :     call addfld ('T_24_COS',     (/ 'lev' /), 'A','K','Temperature 24hr. cos coeff.')
      38        3072 :     call addfld ('T_24_SIN',     (/ 'lev' /), 'A','K','Temperature 24hr. sin coeff.')
      39        3072 :     call addfld ('T_12_COS',     (/ 'lev' /), 'A','K','Temperature 12hr. cos coeff.')
      40        3072 :     call addfld ('T_12_SIN',     (/ 'lev' /), 'A','K','Temperature 12hr. sin coeff.')
      41        3072 :     call addfld ('T_08_COS',     (/ 'lev' /), 'A','K','Temperature  8hr. cos coeff.')
      42        3072 :     call addfld ('T_08_SIN',     (/ 'lev' /), 'A','K','Temperature  8hr. sin coeff.')
      43             : 
      44        3072 :     call addfld ('U_24_COS',     (/ 'lev' /), 'A','m/s','Zonal wind 24hr. cos coeff.')
      45        3072 :     call addfld ('U_24_SIN',     (/ 'lev' /), 'A','m/s','Zonal wind 24hr. sin coeff.')
      46        3072 :     call addfld ('U_12_COS',     (/ 'lev' /), 'A','m/s','Zonal wind 12hr. cos coeff.')
      47        3072 :     call addfld ('U_12_SIN',     (/ 'lev' /), 'A','m/s','Zonal wind 12hr. sin coeff.')
      48        3072 :     call addfld ('U_08_COS',     (/ 'lev' /), 'A','m/s','Zonal wind  8hr. cos coeff.')
      49        3072 :     call addfld ('U_08_SIN',     (/ 'lev' /), 'A','m/s','Zonal wind  8hr. sin coeff.')
      50             : 
      51        3072 :     call addfld ('V_24_COS',     (/ 'lev' /), 'A','m/s','Meridional wind 24hr. cos coeff.')
      52        3072 :     call addfld ('V_24_SIN',     (/ 'lev' /), 'A','m/s','Meridional wind 24hr. sin coeff.')
      53        3072 :     call addfld ('V_12_COS',     (/ 'lev' /), 'A','m/s','Meridional wind 12hr. cos coeff.')
      54        3072 :     call addfld ('V_12_SIN',     (/ 'lev' /), 'A','m/s','Meridional wind 12hr. sin coeff.')
      55        3072 :     call addfld ('V_08_COS',     (/ 'lev' /), 'A','m/s','Meridional wind  8hr. cos coeff.')
      56        3072 :     call addfld ('V_08_SIN',     (/ 'lev' /), 'A','m/s','Meridional wind  8hr. sin coeff.')
      57             : 
      58        1536 :     call addfld ('PS_24_COS',    horiz_only,  'A','Pa','surface pressure 24hr. cos coeff.')
      59        1536 :     call addfld ('PS_24_SIN',    horiz_only,  'A','Pa','surface pressure 24hr. sin coeff.')
      60        1536 :     call addfld ('PS_12_COS',    horiz_only,  'A','Pa','surface pressure 12hr. cos coeff.')
      61        1536 :     call addfld ('PS_12_SIN',    horiz_only,  'A','Pa','surface pressure 12hr. sin coeff.')
      62        1536 :     call addfld ('PS_08_COS',    horiz_only,  'A','Pa','surface pressure  8hr. cos coeff.')
      63        1536 :     call addfld ('PS_08_SIN',    horiz_only,  'A','Pa','surface pressure  8hr. sin coeff.')
      64             : 
      65        3072 :     call addfld ('OMEGA_24_COS', (/ 'lev' /), 'A','Pa/s','vertical pressure velocity 24hr. cos coeff.')
      66        3072 :     call addfld ('OMEGA_24_SIN', (/ 'lev' /), 'A','Pa/s','vertical pressure velocity 24hr. sin coeff.')
      67        3072 :     call addfld ('OMEGA_12_COS', (/ 'lev' /), 'A','Pa/s','vertical pressure velocity 12hr. cos coeff.')
      68        3072 :     call addfld ('OMEGA_12_SIN', (/ 'lev' /), 'A','Pa/s','vertical pressure velocity 12hr. sin coeff.')
      69        3072 :     call addfld ('OMEGA_08_COS', (/ 'lev' /), 'A','Pa/s','vertical pressure velocity  8hr. cos coeff.')
      70        3072 :     call addfld ('OMEGA_08_SIN', (/ 'lev' /), 'A','Pa/s','vertical pressure velocity  8hr. sin coeff.')
      71             : 
      72        1536 :     call phys_getopts( history_waccm_out = history_waccm )
      73             : 
      74        1536 :     if (history_waccm) then
      75           0 :        call add_default ('T_24_COS', 1, ' ')
      76           0 :        call add_default ('T_24_SIN', 1, ' ')
      77           0 :        call add_default ('T_12_COS', 1, ' ')
      78           0 :        call add_default ('T_12_SIN', 1, ' ')
      79           0 :        call add_default ('U_24_COS', 1, ' ')
      80           0 :        call add_default ('U_24_SIN', 1, ' ')
      81           0 :        call add_default ('U_12_COS', 1, ' ')
      82           0 :        call add_default ('U_12_SIN', 1, ' ')
      83           0 :        call add_default ('V_24_COS', 1, ' ')
      84           0 :        call add_default ('V_24_SIN', 1, ' ')
      85           0 :        call add_default ('V_12_COS', 1, ' ')
      86           0 :        call add_default ('V_12_SIN', 1, ' ')
      87           0 :        call add_default ('PS_24_COS', 1, ' ')
      88           0 :        call add_default ('PS_24_SIN', 1, ' ')
      89           0 :        call add_default ('PS_12_COS', 1, ' ')
      90           0 :        call add_default ('PS_12_SIN', 1, ' ')
      91             :     endif
      92             : 
      93        1536 :     return
      94             : 
      95        1536 :   end subroutine tidal_diag_init
      96             : 
      97             :   !===============================================================================
      98             : 
      99     1495368 :   subroutine  tidal_diag_write(state)
     100             : 
     101             :     !----------------------------------------------------------------------- 
     102             :     ! Purpose: calculate fourier coefficients and save to history files 
     103             :     !-----------------------------------------------------------------------
     104        1536 :     use cam_history,   only: outfld, hist_fld_active
     105             :     use physics_types, only: physics_state
     106             : 
     107             :     implicit none
     108             : 
     109             :     !-----------------------------------------------------------------------
     110             :     !
     111             :     ! Arguments
     112             :     !
     113             :     type(physics_state), intent(in) :: state
     114             :     !
     115             :     !---------------------------Local workspace-----------------------------
     116             : 
     117             :     integer  :: lchnk
     118             : 
     119             :     real(r8) :: dcoef(6) 
     120             :     integer :: ncol
     121             : 
     122             :     !-----------------------------------------------------------------------
     123             : 
     124     1495368 :     lchnk = state%lchnk
     125     1495368 :     ncol = state%ncol
     126             : 
     127     1495368 :     call get_tidal_coeffs( dcoef )
     128             : 
     129     1495368 :     if ( hist_fld_active('T_24_COS') .or. hist_fld_active('T_24_SIN') ) then
     130           0 :        call outfld( 'T_24_SIN', state%t(:ncol,:)*dcoef(1), ncol, lchnk )
     131           0 :        call outfld( 'T_24_COS', state%t(:ncol,:)*dcoef(2), ncol, lchnk )
     132             :     endif
     133     1495368 :     if ( hist_fld_active('T_12_COS') .or. hist_fld_active('T_12_SIN') ) then
     134           0 :        call outfld( 'T_12_SIN', state%t(:ncol,:)*dcoef(3), ncol, lchnk )
     135           0 :        call outfld( 'T_12_COS', state%t(:ncol,:)*dcoef(4), ncol, lchnk )
     136             :     endif
     137     1495368 :     if ( hist_fld_active('T_08_COS') .or. hist_fld_active('T_08_SIN') ) then
     138           0 :        call outfld( 'T_08_SIN', state%t(:ncol,:)*dcoef(5), ncol, lchnk )
     139           0 :        call outfld( 'T_08_COS', state%t(:ncol,:)*dcoef(6), ncol, lchnk )
     140             :     endif
     141             : 
     142     1495368 :     if ( hist_fld_active('U_24_COS') .or. hist_fld_active('U_24_SIN') ) then
     143           0 :        call outfld( 'U_24_SIN', state%u(:ncol,:)*dcoef(1), ncol, lchnk )
     144           0 :        call outfld( 'U_24_COS', state%u(:ncol,:)*dcoef(2), ncol, lchnk )
     145             :     endif
     146     1495368 :     if ( hist_fld_active('U_12_COS') .or. hist_fld_active('U_12_SIN') ) then
     147           0 :        call outfld( 'U_12_SIN', state%u(:ncol,:)*dcoef(3), ncol, lchnk )
     148           0 :        call outfld( 'U_12_COS', state%u(:ncol,:)*dcoef(4), ncol, lchnk )
     149             :     endif
     150     1495368 :     if ( hist_fld_active('U_08_COS') .or. hist_fld_active('U_08_SIN') ) then
     151           0 :        call outfld( 'U_08_SIN', state%u(:ncol,:)*dcoef(5), ncol, lchnk )
     152           0 :        call outfld( 'U_08_COS', state%u(:ncol,:)*dcoef(6), ncol, lchnk )
     153             :     endif
     154             : 
     155     1495368 :     if ( hist_fld_active('V_24_COS') .or. hist_fld_active('V_24_SIN') ) then
     156           0 :        call outfld( 'V_24_SIN', state%v(:ncol,:)*dcoef(1), ncol, lchnk )
     157           0 :        call outfld( 'V_24_COS', state%v(:ncol,:)*dcoef(2), ncol, lchnk )
     158             :     endif
     159     1495368 :     if ( hist_fld_active('V_12_COS') .or. hist_fld_active('V_12_SIN') ) then
     160           0 :        call outfld( 'V_12_SIN', state%v(:ncol,:)*dcoef(3), ncol, lchnk )
     161           0 :        call outfld( 'V_12_COS', state%v(:ncol,:)*dcoef(4), ncol, lchnk )
     162             :     endif
     163     1495368 :     if ( hist_fld_active('V_08_COS') .or. hist_fld_active('V_08_SIN') ) then
     164           0 :        call outfld( 'V_08_SIN', state%v(:ncol,:)*dcoef(5), ncol, lchnk )
     165           0 :        call outfld( 'V_08_COS', state%v(:ncol,:)*dcoef(6), ncol, lchnk )
     166             :     endif
     167             : 
     168     1495368 :     if ( hist_fld_active('PS_24_COS') .or. hist_fld_active('PS_24_SIN') ) then
     169           0 :        call outfld( 'PS_24_SIN', state%ps(:ncol)*dcoef(1), ncol, lchnk )
     170           0 :        call outfld( 'PS_24_COS', state%ps(:ncol)*dcoef(2), ncol, lchnk )
     171             :     endif
     172     1495368 :     if ( hist_fld_active('PS_12_COS') .or. hist_fld_active('PS_12_SIN') ) then
     173           0 :        call outfld( 'PS_12_SIN', state%ps(:ncol)*dcoef(3), ncol, lchnk )
     174           0 :        call outfld( 'PS_12_COS', state%ps(:ncol)*dcoef(4), ncol, lchnk )
     175             :     endif
     176     1495368 :     if ( hist_fld_active('PS_08_COS') .or. hist_fld_active('PS_08_SIN') ) then
     177           0 :        call outfld( 'PS_08_SIN', state%ps(:ncol)*dcoef(5), ncol, lchnk )
     178           0 :        call outfld( 'PS_08_COS', state%ps(:ncol)*dcoef(6), ncol, lchnk )
     179             :     endif
     180             : 
     181     1495368 :     if ( hist_fld_active('OMEGA_24_COS') .or. hist_fld_active('OMEGA_24_SIN') ) then
     182           0 :        call outfld( 'OMEGA_24_SIN', state%omega(:ncol,:)*dcoef(1), ncol, lchnk )
     183           0 :        call outfld( 'OMEGA_24_COS', state%omega(:ncol,:)*dcoef(2), ncol, lchnk )
     184             :     endif
     185     1495368 :     if ( hist_fld_active('OMEGA_12_COS') .or. hist_fld_active('OMEGA_12_SIN') ) then
     186           0 :        call outfld( 'OMEGA_12_SIN', state%omega(:ncol,:)*dcoef(3), ncol, lchnk )
     187           0 :        call outfld( 'OMEGA_12_COS', state%omega(:ncol,:)*dcoef(4), ncol, lchnk )
     188             :     endif
     189     1495368 :     if ( hist_fld_active('OMEGA_08_COS') .or. hist_fld_active('OMEGA_08_SIN') ) then
     190           0 :        call outfld( 'OMEGA_08_SIN', state%omega(:ncol,:)*dcoef(5), ncol, lchnk )
     191           0 :        call outfld( 'OMEGA_08_COS', state%omega(:ncol,:)*dcoef(6), ncol, lchnk )
     192             :     endif
     193             : 
     194     1495368 :     return
     195             : 
     196     1495368 :   end subroutine tidal_diag_write
     197             : 
     198             :   !===============================================================================
     199     2990736 :   subroutine get_tidal_coeffs( dcoef )
     200             : 
     201             :     !----------------------------------------------------------------------- 
     202             :     ! Purpose: calculate fourier coefficients
     203             :     !-----------------------------------------------------------------------
     204             : 
     205     1495368 :     use time_manager,  only: get_curr_date               
     206             :     use physconst, only: pi, cday
     207             : 
     208             :     real(r8), intent(out) :: dcoef(6) 
     209             : 
     210             :  !  variables to calculate tidal coeffs
     211             :     real(r8), parameter :: pi_x_2 = 2._r8*pi
     212             :     real(r8), parameter :: pi_x_4 = 4._r8*pi
     213             :     real(r8), parameter :: pi_x_6 = 6._r8*pi
     214             :     integer  :: year, month
     215             :     integer  :: day              ! day of month
     216             :     integer  :: tod              ! time of day (seconds past 0Z) 
     217             :     real(r8) :: gmtfrac 
     218             : 
     219             :  !  calculate multipliers for Fourier transform in time (tidal analysis)
     220     2990736 :     call get_curr_date(year, month, day, tod)
     221     2990736 :     gmtfrac = tod / cday
     222             : 
     223     2990736 :     dcoef(1) = 2._r8*sin(pi_x_2*gmtfrac)
     224     2990736 :     dcoef(2) = 2._r8*cos(pi_x_2*gmtfrac)
     225     2990736 :     dcoef(3) = 2._r8*sin(pi_x_4*gmtfrac)
     226     2990736 :     dcoef(4) = 2._r8*cos(pi_x_4*gmtfrac)
     227     2990736 :     dcoef(5) = 2._r8*sin(pi_x_6*gmtfrac)
     228     2990736 :     dcoef(6) = 2._r8*cos(pi_x_6*gmtfrac)
     229             : 
     230     2990736 :   end subroutine get_tidal_coeffs
     231             : 
     232             : end module tidal_diag
     233             : 

Generated by: LCOV version 1.14