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 73344 : 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 1536 : call addfld ('T_24_COS', (/ 'lev' /), 'A','K','Temperature 24hr. cos coeff.')
38 1536 : call addfld ('T_24_SIN', (/ 'lev' /), 'A','K','Temperature 24hr. sin coeff.')
39 1536 : call addfld ('T_12_COS', (/ 'lev' /), 'A','K','Temperature 12hr. cos coeff.')
40 1536 : call addfld ('T_12_SIN', (/ 'lev' /), 'A','K','Temperature 12hr. sin coeff.')
41 1536 : call addfld ('T_08_COS', (/ 'lev' /), 'A','K','Temperature 8hr. cos coeff.')
42 1536 : call addfld ('T_08_SIN', (/ 'lev' /), 'A','K','Temperature 8hr. sin coeff.')
43 :
44 1536 : call addfld ('U_24_COS', (/ 'lev' /), 'A','m/s','Zonal wind 24hr. cos coeff.')
45 1536 : call addfld ('U_24_SIN', (/ 'lev' /), 'A','m/s','Zonal wind 24hr. sin coeff.')
46 1536 : call addfld ('U_12_COS', (/ 'lev' /), 'A','m/s','Zonal wind 12hr. cos coeff.')
47 1536 : call addfld ('U_12_SIN', (/ 'lev' /), 'A','m/s','Zonal wind 12hr. sin coeff.')
48 1536 : call addfld ('U_08_COS', (/ 'lev' /), 'A','m/s','Zonal wind 8hr. cos coeff.')
49 1536 : call addfld ('U_08_SIN', (/ 'lev' /), 'A','m/s','Zonal wind 8hr. sin coeff.')
50 :
51 1536 : call addfld ('V_24_COS', (/ 'lev' /), 'A','m/s','Meridional wind 24hr. cos coeff.')
52 1536 : call addfld ('V_24_SIN', (/ 'lev' /), 'A','m/s','Meridional wind 24hr. sin coeff.')
53 1536 : call addfld ('V_12_COS', (/ 'lev' /), 'A','m/s','Meridional wind 12hr. cos coeff.')
54 1536 : call addfld ('V_12_SIN', (/ 'lev' /), 'A','m/s','Meridional wind 12hr. sin coeff.')
55 1536 : call addfld ('V_08_COS', (/ 'lev' /), 'A','m/s','Meridional wind 8hr. cos coeff.')
56 1536 : call addfld ('V_08_SIN', (/ 'lev' /), 'A','m/s','Meridional wind 8hr. sin coeff.')
57 :
58 768 : call addfld ('PS_24_COS', horiz_only, 'A','Pa','surface pressure 24hr. cos coeff.')
59 768 : call addfld ('PS_24_SIN', horiz_only, 'A','Pa','surface pressure 24hr. sin coeff.')
60 768 : call addfld ('PS_12_COS', horiz_only, 'A','Pa','surface pressure 12hr. cos coeff.')
61 768 : call addfld ('PS_12_SIN', horiz_only, 'A','Pa','surface pressure 12hr. sin coeff.')
62 768 : call addfld ('PS_08_COS', horiz_only, 'A','Pa','surface pressure 8hr. cos coeff.')
63 768 : call addfld ('PS_08_SIN', horiz_only, 'A','Pa','surface pressure 8hr. sin coeff.')
64 :
65 1536 : call addfld ('OMEGA_24_COS', (/ 'lev' /), 'A','Pa/s','vertical pressure velocity 24hr. cos coeff.')
66 1536 : call addfld ('OMEGA_24_SIN', (/ 'lev' /), 'A','Pa/s','vertical pressure velocity 24hr. sin coeff.')
67 1536 : call addfld ('OMEGA_12_COS', (/ 'lev' /), 'A','Pa/s','vertical pressure velocity 12hr. cos coeff.')
68 1536 : call addfld ('OMEGA_12_SIN', (/ 'lev' /), 'A','Pa/s','vertical pressure velocity 12hr. sin coeff.')
69 1536 : call addfld ('OMEGA_08_COS', (/ 'lev' /), 'A','Pa/s','vertical pressure velocity 8hr. cos coeff.')
70 1536 : call addfld ('OMEGA_08_SIN', (/ 'lev' /), 'A','Pa/s','vertical pressure velocity 8hr. sin coeff.')
71 :
72 768 : call phys_getopts( history_waccm_out = history_waccm )
73 :
74 768 : if (history_waccm) then
75 768 : call add_default ('T_24_COS', 1, ' ')
76 768 : call add_default ('T_24_SIN', 1, ' ')
77 768 : call add_default ('T_12_COS', 1, ' ')
78 768 : call add_default ('T_12_SIN', 1, ' ')
79 768 : call add_default ('U_24_COS', 1, ' ')
80 768 : call add_default ('U_24_SIN', 1, ' ')
81 768 : call add_default ('U_12_COS', 1, ' ')
82 768 : call add_default ('U_12_SIN', 1, ' ')
83 768 : call add_default ('V_24_COS', 1, ' ')
84 768 : call add_default ('V_24_SIN', 1, ' ')
85 768 : call add_default ('V_12_COS', 1, ' ')
86 768 : call add_default ('V_12_SIN', 1, ' ')
87 768 : call add_default ('PS_24_COS', 1, ' ')
88 768 : call add_default ('PS_24_SIN', 1, ' ')
89 768 : call add_default ('PS_12_COS', 1, ' ')
90 768 : call add_default ('PS_12_SIN', 1, ' ')
91 : endif
92 :
93 768 : return
94 :
95 768 : end subroutine tidal_diag_init
96 :
97 : !===============================================================================
98 :
99 24192 : subroutine tidal_diag_write(state)
100 :
101 : !-----------------------------------------------------------------------
102 : ! Purpose: calculate fourier coefficients and save to history files
103 : !-----------------------------------------------------------------------
104 768 : 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 24192 : lchnk = state%lchnk
125 24192 : ncol = state%ncol
126 :
127 24192 : call get_tidal_coeffs( dcoef )
128 :
129 24192 : if ( hist_fld_active('T_24_COS') .or. hist_fld_active('T_24_SIN') ) then
130 40908672 : call outfld( 'T_24_SIN', state%t(:ncol,:)*dcoef(1), ncol, lchnk )
131 40908672 : call outfld( 'T_24_COS', state%t(:ncol,:)*dcoef(2), ncol, lchnk )
132 : endif
133 24192 : if ( hist_fld_active('T_12_COS') .or. hist_fld_active('T_12_SIN') ) then
134 40908672 : call outfld( 'T_12_SIN', state%t(:ncol,:)*dcoef(3), ncol, lchnk )
135 40908672 : call outfld( 'T_12_COS', state%t(:ncol,:)*dcoef(4), ncol, lchnk )
136 : endif
137 24192 : if ( hist_fld_active('T_08_COS') .or. hist_fld_active('T_08_SIN') ) then
138 40908672 : call outfld( 'T_08_SIN', state%t(:ncol,:)*dcoef(5), ncol, lchnk )
139 40908672 : call outfld( 'T_08_COS', state%t(:ncol,:)*dcoef(6), ncol, lchnk )
140 : endif
141 :
142 24192 : if ( hist_fld_active('U_24_COS') .or. hist_fld_active('U_24_SIN') ) then
143 40908672 : call outfld( 'U_24_SIN', state%u(:ncol,:)*dcoef(1), ncol, lchnk )
144 40908672 : call outfld( 'U_24_COS', state%u(:ncol,:)*dcoef(2), ncol, lchnk )
145 : endif
146 24192 : if ( hist_fld_active('U_12_COS') .or. hist_fld_active('U_12_SIN') ) then
147 40908672 : call outfld( 'U_12_SIN', state%u(:ncol,:)*dcoef(3), ncol, lchnk )
148 40908672 : call outfld( 'U_12_COS', state%u(:ncol,:)*dcoef(4), ncol, lchnk )
149 : endif
150 24192 : if ( hist_fld_active('U_08_COS') .or. hist_fld_active('U_08_SIN') ) then
151 40908672 : call outfld( 'U_08_SIN', state%u(:ncol,:)*dcoef(5), ncol, lchnk )
152 40908672 : call outfld( 'U_08_COS', state%u(:ncol,:)*dcoef(6), ncol, lchnk )
153 : endif
154 :
155 24192 : if ( hist_fld_active('V_24_COS') .or. hist_fld_active('V_24_SIN') ) then
156 40908672 : call outfld( 'V_24_SIN', state%v(:ncol,:)*dcoef(1), ncol, lchnk )
157 40908672 : call outfld( 'V_24_COS', state%v(:ncol,:)*dcoef(2), ncol, lchnk )
158 : endif
159 24192 : if ( hist_fld_active('V_12_COS') .or. hist_fld_active('V_12_SIN') ) then
160 40908672 : call outfld( 'V_12_SIN', state%v(:ncol,:)*dcoef(3), ncol, lchnk )
161 40908672 : call outfld( 'V_12_COS', state%v(:ncol,:)*dcoef(4), ncol, lchnk )
162 : endif
163 24192 : if ( hist_fld_active('V_08_COS') .or. hist_fld_active('V_08_SIN') ) then
164 40908672 : call outfld( 'V_08_SIN', state%v(:ncol,:)*dcoef(5), ncol, lchnk )
165 40908672 : call outfld( 'V_08_COS', state%v(:ncol,:)*dcoef(6), ncol, lchnk )
166 : endif
167 :
168 24192 : if ( hist_fld_active('PS_24_COS') .or. hist_fld_active('PS_24_SIN') ) then
169 314496 : call outfld( 'PS_24_SIN', state%ps(:ncol)*dcoef(1), ncol, lchnk )
170 314496 : call outfld( 'PS_24_COS', state%ps(:ncol)*dcoef(2), ncol, lchnk )
171 : endif
172 24192 : if ( hist_fld_active('PS_12_COS') .or. hist_fld_active('PS_12_SIN') ) then
173 314496 : call outfld( 'PS_12_SIN', state%ps(:ncol)*dcoef(3), ncol, lchnk )
174 314496 : call outfld( 'PS_12_COS', state%ps(:ncol)*dcoef(4), ncol, lchnk )
175 : endif
176 24192 : 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 24192 : if ( hist_fld_active('OMEGA_24_COS') .or. hist_fld_active('OMEGA_24_SIN') ) then
182 40908672 : call outfld( 'OMEGA_24_SIN', state%omega(:ncol,:)*dcoef(1), ncol, lchnk )
183 40908672 : call outfld( 'OMEGA_24_COS', state%omega(:ncol,:)*dcoef(2), ncol, lchnk )
184 : endif
185 24192 : if ( hist_fld_active('OMEGA_12_COS') .or. hist_fld_active('OMEGA_12_SIN') ) then
186 40908672 : call outfld( 'OMEGA_12_SIN', state%omega(:ncol,:)*dcoef(3), ncol, lchnk )
187 40908672 : call outfld( 'OMEGA_12_COS', state%omega(:ncol,:)*dcoef(4), ncol, lchnk )
188 : endif
189 24192 : if ( hist_fld_active('OMEGA_08_COS') .or. hist_fld_active('OMEGA_08_SIN') ) then
190 40908672 : call outfld( 'OMEGA_08_SIN', state%omega(:ncol,:)*dcoef(5), ncol, lchnk )
191 40908672 : call outfld( 'OMEGA_08_COS', state%omega(:ncol,:)*dcoef(6), ncol, lchnk )
192 : endif
193 :
194 24192 : return
195 :
196 24192 : end subroutine tidal_diag_write
197 :
198 : !===============================================================================
199 72576 : subroutine get_tidal_coeffs( dcoef )
200 :
201 : !-----------------------------------------------------------------------
202 : ! Purpose: calculate fourier coefficients
203 : !-----------------------------------------------------------------------
204 :
205 24192 : 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 72576 : call get_curr_date(year, month, day, tod)
221 72576 : gmtfrac = tod / cday
222 :
223 72576 : dcoef(1) = 2._r8*sin(pi_x_2*gmtfrac)
224 72576 : dcoef(2) = 2._r8*cos(pi_x_2*gmtfrac)
225 72576 : dcoef(3) = 2._r8*sin(pi_x_4*gmtfrac)
226 72576 : dcoef(4) = 2._r8*cos(pi_x_4*gmtfrac)
227 72576 : dcoef(5) = 2._r8*sin(pi_x_6*gmtfrac)
228 72576 : dcoef(6) = 2._r8*cos(pi_x_6*gmtfrac)
229 :
230 72576 : end subroutine get_tidal_coeffs
231 :
232 : end module tidal_diag
233 :
|