-
Notifications
You must be signed in to change notification settings - Fork 0
/
trcstp.F90
246 lines (236 loc) · 10.7 KB
/
trcstp.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
MODULE trcstp
!!======================================================================
!! *** MODULE trcstp ***
!! Time-stepping : time loop of opa for passive tracer
!!======================================================================
!! History : 1.0 ! 2004-03 (C. Ethe) Original
!!----------------------------------------------------------------------
#if defined key_top
!!----------------------------------------------------------------------
!! trc_stp : passive tracer system time-stepping
!!----------------------------------------------------------------------
USE oce_trc ! ocean dynamics and active tracers variables
USE sbc_oce
USE trc
USE trctrp ! passive tracers transport
USE trcsms ! passive tracers sources and sinks
USE trcwri
USE trcrst
USE trcsub !
USE trdtrc_oce
USE trdmxl_trc
!
USE prtctl_trc ! Print control for debbuging
USE iom !
USE in_out_manager !
IMPLICIT NONE
PRIVATE
PUBLIC trc_stp ! called by step
LOGICAL :: llnew ! ???
REAL(wp) :: rdt_sampl ! ???
INTEGER :: nb_rec_per_day, ktdcy ! ???
REAL(wp) :: rsecfst, rseclast ! ???
REAL(wp), DIMENSION(:,:,:), SAVE, ALLOCATABLE :: qsr_arr ! save qsr during TOP time-step
!!----------------------------------------------------------------------
!! NEMO/TOP 3.3 , NEMO Consortium (2018)
!! $Id: trcstp.F90 9598 2018-05-15 22:47:16Z nicolasmartin $
!! Software governed by the CeCILL licence (./LICENSE)
!!----------------------------------------------------------------------
CONTAINS
SUBROUTINE trc_stp( kt )
!!-------------------------------------------------------------------
!! *** ROUTINE trc_stp ***
!!
!! ** Purpose : Time loop of opa for passive tracer
!!
!! ** Method : Compute the passive tracers trends
!! Update the passive tracers
!!-------------------------------------------------------------------
INTEGER, INTENT( in ) :: kt ! ocean time-step index
!
INTEGER :: jk, jn ! dummy loop indices
REAL(wp):: ztrai ! local scalar
CHARACTER (len=25) :: charout !
!!-------------------------------------------------------------------
!
IF( ln_timing ) CALL timing_start('trc_stp')
!
IF( ( neuler == 0 .AND. kt == nittrc000 ) .OR. ln_top_euler ) THEN ! at nittrc000
r2dttrc = rdttrc ! = rdttrc (use or restarting with Euler time stepping)
ELSEIF( kt <= nittrc000 + nn_dttrc ) THEN ! at nittrc000 or nittrc000+1
r2dttrc = 2. * rdttrc ! = 2 rdttrc (leapfrog)
ENDIF
!
IF( kt == nittrc000 .AND. lk_trdmxl_trc ) CALL trd_mxl_trc_init ! trends: Mixed-layer
!
IF( .NOT.ln_linssh ) THEN ! update ocean volume due to ssh temporal evolution
DO jk = 1, jpk
cvol(:,:,jk) = e1e2t(:,:) * e3t_n(:,:,jk) * tmask(:,:,jk)
END DO
areatot = glob_sum( cvol(:,:,:) )
ENDIF
!
IF( l_trcdm2dc ) CALL trc_mean_qsr( kt )
!
IF( nn_dttrc /= 1 ) CALL trc_sub_stp( kt ) ! averaging physical variables for sub-stepping
!
IF( MOD( kt , nn_dttrc ) == 0 ) THEN ! only every nn_dttrc time step
!
IF(ln_ctl) THEN
WRITE(charout,FMT="('kt =', I4,' d/m/y =',I2,I2,I4)") kt, nday, nmonth, nyear
CALL prt_ctl_trc_info(charout)
ENDIF
!
tra(:,:,:,:) = 0.e0
!
CALL trc_rst_opn ( kt ) ! Open tracer restart file
IF( lrst_trc ) CALL trc_rst_cal ( kt, 'WRITE' ) ! calendar
CALL trc_wri ( kt ) ! output of passive tracers with iom I/O manager
CALL trc_sms ( kt ) ! tracers: sinks and sources
CALL trc_trp ( kt ) ! transport of passive tracers
IF( kt == nittrc000 ) THEN
CALL iom_close( numrtr ) ! close input tracer restart file
IF(lwm) CALL FLUSH( numont ) ! flush namelist output
ENDIF
IF( lrst_trc ) CALL trc_rst_wri ( kt ) ! write tracer restart file
IF( lk_trdmxl_trc ) CALL trd_mxl_trc ( kt ) ! trends: Mixed-layer
!
IF( nn_dttrc /= 1 ) CALL trc_sub_reset( kt ) ! resetting physical variables when sub-stepping
!
ENDIF
!
ztrai = 0._wp ! content of all tracers
DO jn = 1, jptra
ztrai = ztrai + glob_sum( trn(:,:,:,jn) * cvol(:,:,:) )
END DO
IF( lwp ) WRITE(numstr,9300) kt, ztrai / areatot
9300 FORMAT(i10,D23.16)
!
IF( ln_timing ) CALL timing_stop('trc_stp')
!
END SUBROUTINE trc_stp
SUBROUTINE trc_mean_qsr( kt )
!!----------------------------------------------------------------------
!! *** ROUTINE trc_mean_qsr ***
!!
!! ** Purpose : Compute daily mean qsr for biogeochemical model in case
!! of diurnal cycle
!!
!! ** Method : store in TOP the qsr every hour ( or every time-step if the latter
!! is greater than 1 hour ) and then, compute the mean with
!! a moving average over 24 hours.
!! In coupled mode, the sampling is done at every coupling frequency
!!----------------------------------------------------------------------
INTEGER, INTENT( in ) :: kt ! ocean time-step index
!
INTEGER :: jn ! dummy loop indices
REAL(wp) :: zkt, zrec ! local scalars
CHARACTER(len=1) :: cl1 ! 1 character
CHARACTER(len=2) :: cl2 ! 2 characters
!!----------------------------------------------------------------------
!
IF( ln_timing ) CALL timing_start('trc_mean_qsr')
!
IF( kt == nittrc000 ) THEN
IF( ln_cpl ) THEN
rdt_sampl = rday / ncpl_qsr_freq
nb_rec_per_day = ncpl_qsr_freq
ELSE
rdt_sampl = MAX( 3600., rdttrc )
nb_rec_per_day = INT( rday / rdt_sampl )
ENDIF
!
IF(lwp) THEN
WRITE(numout,*)
WRITE(numout,*) ' Sampling frequency dt = ', rdt_sampl, 's',' Number of sampling per day nrec = ', nb_rec_per_day
WRITE(numout,*)
ENDIF
!
ALLOCATE( qsr_arr(jpi,jpj,nb_rec_per_day ) )
!
! !* Restart: read in restart file
IF( ln_rsttr .AND. nn_rsttr /= 0 .AND. iom_varid( numrtr, 'qsr_mean' , ldstop = .FALSE. ) > 0 &
& .AND. iom_varid( numrtr, 'qsr_arr_1', ldstop = .FALSE. ) > 0 &
& .AND. iom_varid( numrtr, 'ktdcy' , ldstop = .FALSE. ) > 0 &
& .AND. iom_varid( numrtr, 'nrdcy' , ldstop = .FALSE. ) > 0 ) THEN
CALL iom_get( numrtr, 'ktdcy', zkt )
rsecfst = INT( zkt ) * rdttrc
IF(lwp) WRITE(numout,*) 'trc_qsr_mean: qsr_mean read in the restart file at time-step rsecfst =', rsecfst, ' s '
CALL iom_get( numrtr, jpdom_autoglo, 'qsr_mean', qsr_mean ) ! A mean of qsr
CALL iom_get( numrtr, 'nrdcy', zrec ) ! Number of record per days
IF( INT( zrec ) == nb_rec_per_day ) THEN
DO jn = 1, nb_rec_per_day
IF( jn <= 9 ) THEN
WRITE(cl1,'(i1)') jn
CALL iom_get( numrtr, jpdom_autoglo, 'qsr_arr_'//cl1, qsr_arr(:,:,jn) ) ! A mean of qsr
ELSE
WRITE(cl2,'(i2.2)') jn
CALL iom_get( numrtr, jpdom_autoglo, 'qsr_arr_'//cl2, qsr_arr(:,:,jn) ) ! A mean of qsr
ENDIF
END DO
ELSE
DO jn = 1, nb_rec_per_day
qsr_arr(:,:,jn) = qsr_mean(:,:)
ENDDO
ENDIF
ELSE !* no restart: set from nit000 values
IF(lwp) WRITE(numout,*) 'trc_qsr_mean: qsr_mean set to nit000 values'
rsecfst = kt * rdttrc
!
qsr_mean(:,:) = qsr(:,:)
DO jn = 1, nb_rec_per_day
qsr_arr(:,:,jn) = qsr_mean(:,:)
END DO
ENDIF
!
ENDIF
!
rseclast = kt * rdttrc
!
llnew = ( rseclast - rsecfst ) .ge. rdt_sampl ! new shortwave to store
IF( llnew ) THEN
ktdcy = kt
IF( lwp .AND. kt < nittrc000 + 100 ) WRITE(numout,*) ' New shortwave to sample for TOP at time kt = ', ktdcy, &
& ' time = ', rseclast/3600.,'hours '
rsecfst = rseclast
DO jn = 1, nb_rec_per_day - 1
qsr_arr(:,:,jn) = qsr_arr(:,:,jn+1)
ENDDO
qsr_arr (:,:,nb_rec_per_day) = qsr(:,:)
qsr_mean(:,: ) = SUM( qsr_arr(:,:,:), 3 ) / nb_rec_per_day
ENDIF
!
IF( lrst_trc ) THEN !* Write the mean of qsr in restart file
IF(lwp) WRITE(numout,*)
IF(lwp) WRITE(numout,*) 'trc_mean_qsr : write qsr_mean in restart file kt =', kt
IF(lwp) WRITE(numout,*) '~~~~~~~'
zkt = REAL( ktdcy, wp )
zrec = REAL( nb_rec_per_day, wp )
CALL iom_rstput( kt, nitrst, numrtw, 'ktdcy', zkt )
CALL iom_rstput( kt, nitrst, numrtw, 'nrdcy', zrec )
DO jn = 1, nb_rec_per_day
IF( jn <= 9 ) THEN
WRITE(cl1,'(i1)') jn
CALL iom_rstput( kt, nitrst, numrtw, 'qsr_arr_'//cl1, qsr_arr(:,:,jn) )
ELSE
WRITE(cl2,'(i2.2)') jn
CALL iom_rstput( kt, nitrst, numrtw, 'qsr_arr_'//cl2, qsr_arr(:,:,jn) )
ENDIF
END DO
CALL iom_rstput( kt, nitrst, numrtw, 'qsr_mean', qsr_mean(:,:) )
ENDIF
!
IF( ln_timing ) CALL timing_stop('trc_mean_qsr')
!
END SUBROUTINE trc_mean_qsr
#else
!!----------------------------------------------------------------------
!! Default key NO passive tracers
!!----------------------------------------------------------------------
CONTAINS
SUBROUTINE trc_stp( kt ) ! Empty routine
WRITE(*,*) 'trc_stp: You should not have seen this print! error?', kt
END SUBROUTINE trc_stp
#endif
!!======================================================================
END MODULE trcstp