New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
dia25h.F90 in branches/UKMO/AMM15_v3_6_STABLE_package_debug/NEMOGCM/NEMO/OPA_SRC/DIA – NEMO

source: branches/UKMO/AMM15_v3_6_STABLE_package_debug/NEMOGCM/NEMO/OPA_SRC/DIA/dia25h.F90 @ 8250

Last change on this file since 8250 was 8250, checked in by niall, 7 years ago
File size: 14.4 KB
Line 
1MODULE dia25h 
2   !!======================================================================
3   !!                       ***  MODULE  diaharm  ***
4   !! Harmonic analysis of tidal constituents
5   !!======================================================================
6   !! History :  3.6  !  2014  (E O'Dea)  Original code
7   !!----------------------------------------------------------------------
8   USE oce             ! ocean dynamics and tracers variables
9   USE dom_oce         ! ocean space and time domain
10   USE diainsitutem, ONLY: rinsitu_t, theta2t
11   USE in_out_manager  ! I/O units
12   USE iom             ! I/0 library
13   USE wrk_nemo        ! working arrays
14#if defined key_zdftke 
15   USE zdftke, ONLY: en
16#endif
17   USE zdf_oce, ONLY: avt, avm
18#if defined key_zdfgls
19   USE zdfgls, ONLY: mxln
20   USE zdf_oce, ONLY: en
21#endif
22
23   IMPLICIT NONE
24   PRIVATE
25
26   LOGICAL , PUBLIC ::   ln_dia25h     !:  25h mean output
27   PUBLIC   dia_25h_init               ! routine called by nemogcm.F90
28   PUBLIC   dia_25h                    ! routine called by diawri.F90
29
30  !! * variables for calculating 25-hourly means
31   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:) ::   tn_25h  , sn_25h, rinsitu_t_25h 
32   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:)   ::   sshn_25h 
33   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:) ::   un_25h  , vn_25h  , wn_25h
34   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:) ::   avt_25h , avm_25h
35#if defined key_zdfgls || key_zdftke
36   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:) ::   en_25h
37#endif
38#if defined key_zdfgls 
39   REAL(wp),SAVE, ALLOCATABLE,   DIMENSION(:,:,:) ::   rmxln_25h
40#endif
41   INTEGER, SAVE :: cnt_25h     ! Counter for 25 hour means
42
43
44
45   !!----------------------------------------------------------------------
46   !! NEMO/OPA 3.6 , NEMO Consortium (2014)
47   !! $Id$
48   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
49   !!----------------------------------------------------------------------
50CONTAINS
51
52   SUBROUTINE dia_25h_init 
53      !!---------------------------------------------------------------------------
54      !!                  ***  ROUTINE dia_25h_init  ***
55      !!     
56      !! ** Purpose: Initialization of 25h mean namelist
57      !!       
58      !! ** Method : Read namelist
59      !!   History
60      !!   3.6  !  08-14  (E. O'Dea) Routine to initialize dia_25h
61      !!---------------------------------------------------------------------------
62      !!
63      INTEGER ::   ios                 ! Local integer output status for namelist read
64      INTEGER ::   ierror              ! Local integer for memory allocation
65      !
66      NAMELIST/nam_dia25h/ ln_dia25h
67      !!----------------------------------------------------------------------
68      !
69      WRITE(numout,*) 'NIALL 1'
70      REWIND ( numnam_ref )              ! Read Namelist nam_dia25h in reference namelist : 25hour mean diagnostics
71      READ   ( numnam_ref, nam_dia25h, IOSTAT=ios, ERR= 901 )
72901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_dia25h in reference namelist', lwp )
73      WRITE(numout,*) 'NIALL 2'
74      REWIND( numnam_cfg )              ! Namelist nam_dia25h in configuration namelist  25hour diagnostics
75      READ  ( numnam_cfg, nam_dia25h, IOSTAT = ios, ERR = 902 )
76      WRITE(numout,*) 'NIALL 3'
77902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_dia25h in configuration namelist', lwp )
78      IF(lwm) WRITE ( numond, nam_dia25h )
79      WRITE(numout,*) 'NIALL 4'
80      IF(lwp) THEN                   ! Control print
81         WRITE(numout,*)
82         WRITE(numout,*) 'dia_25h_init : Output 25 hour mean diagnostics'
83         WRITE(numout,*) '~~~~~~~~~~~~'
84         WRITE(numout,*) 'Namelist nam_dia25h : set 25h outputs '
85         WRITE(numout,*) 'Switch for 25h diagnostics (T) or not (F)  ln_dia25h  = ', ln_dia25h
86      ENDIF
87      IF( .NOT. ln_dia25h )   RETURN
88      ! ------------------- !
89      ! 1 - Allocate memory !
90      ! ------------------- !
91      ALLOCATE( tn_25h(jpi,jpj,jpk), STAT=ierror )
92      IF( ierror > 0 ) THEN
93         CALL ctl_stop( 'dia_25h: unable to allocate tn_25h' )   ;   RETURN
94      ENDIF
95      ALLOCATE( sn_25h(jpi,jpj,jpk), STAT=ierror )
96      IF( ierror > 0 ) THEN
97         CALL ctl_stop( 'dia_25h: unable to allocate sn_25h' )   ;   RETURN
98      ENDIF
99      ALLOCATE( rinsitu_t_25h(jpi,jpj,jpk), STAT=ierror )
100      IF( ierror > 0 ) THEN
101         CALL ctl_stop( 'dia_25h: unable to allocate rinsitu_t_25h' )   ;   RETURN
102      ENDIF
103      ALLOCATE( un_25h(jpi,jpj,jpk), STAT=ierror )
104      IF( ierror > 0 ) THEN
105         CALL ctl_stop( 'dia_25h: unable to allocate un_25h' )   ;   RETURN
106      ENDIF
107      ALLOCATE( vn_25h(jpi,jpj,jpk), STAT=ierror )
108      IF( ierror > 0 ) THEN
109         CALL ctl_stop( 'dia_25h: unable to allocate vn_25h' )   ;   RETURN
110      ENDIF
111      ALLOCATE( wn_25h(jpi,jpj,jpk), STAT=ierror )
112      IF( ierror > 0 ) THEN
113         CALL ctl_stop( 'dia_25h: unable to allocate wn_25h' )   ;   RETURN
114      ENDIF
115      ALLOCATE( avt_25h(jpi,jpj,jpk), STAT=ierror )
116      IF( ierror > 0 ) THEN
117         CALL ctl_stop( 'dia_25h: unable to allocate avt_25h' )   ;   RETURN
118      ENDIF
119      ALLOCATE( avm_25h(jpi,jpj,jpk), STAT=ierror )
120      IF( ierror > 0 ) THEN
121         CALL ctl_stop( 'dia_25h: unable to allocate avm_25h' )   ;   RETURN
122      ENDIF
123# if defined key_zdfgls || defined key_zdftke
124      ALLOCATE( en_25h(jpi,jpj,jpk), STAT=ierror )
125      IF( ierror > 0 ) THEN
126         CALL ctl_stop( 'dia_25h: unable to allocate en_25h' )   ;   RETURN
127      ENDIF
128#endif
129# if defined key_zdfgls 
130      ALLOCATE( rmxln_25h(jpi,jpj,jpk), STAT=ierror )
131      IF( ierror > 0 ) THEN
132         CALL ctl_stop( 'dia_25h: unable to allocate rmxln_25h' )   ;   RETURN
133      ENDIF
134#endif
135      ALLOCATE( sshn_25h(jpi,jpj), STAT=ierror )
136      IF( ierror > 0 ) THEN
137         CALL ctl_stop( 'dia_25h: unable to allocate sshn_25h' )   ;   RETURN
138      ENDIF
139      ! ------------------------- !
140      ! 2 - Assign Initial Values !
141      ! ------------------------- !
142      cnt_25h = 1  ! sets the first value of sum at timestep 1 (note - should strictly be at timestep zero so before values used where possible)
143      tn_25h(:,:,:) = tsb(:,:,:,jp_tem)
144      sn_25h(:,:,:) = tsb(:,:,:,jp_sal)
145      CALL theta2t
146      rinsitu_t_25h(:,:,:) = rinsitu_t(:,:,:)
147      sshn_25h(:,:) = sshb(:,:)
148      un_25h(:,:,:) = ub(:,:,:)
149      vn_25h(:,:,:) = vb(:,:,:)
150      wn_25h(:,:,:) = wn(:,:,:)
151      avt_25h(:,:,:) = avt(:,:,:)
152      avm_25h(:,:,:) = avm(:,:,:)
153# if defined key_zdfgls || defined key_zdftke
154         en_25h(:,:,:) = en(:,:,:)
155#endif
156# if defined key_zdfgls
157         rmxln_25h(:,:,:) = mxln(:,:,:)
158#endif
159#if defined key_lim3 || defined key_lim2
160         CALL ctl_stop('STOP', 'dia_25h not setup yet to do tidemean ice')
161#endif 
162
163      ! -------------------------- !
164      ! 3 - Return to dia_wri      !
165      ! -------------------------- !
166
167
168   END SUBROUTINE dia_25h_init
169
170
171   SUBROUTINE dia_25h( kt ) 
172      !!----------------------------------------------------------------------
173      !!                 ***  ROUTINE dia_25h  ***
174      !!         
175      !!
176      !!--------------------------------------------------------------------
177      !!                   
178      !! ** Purpose :   Write diagnostics with M2/S2 tide removed
179      !!
180      !! ** Method  :   
181      !!      25hr mean outputs for shelf seas
182      !!
183      !! History :
184      !!   ?.0  !  07-04  (A. Hines) New routine, developed from dia_wri_foam
185      !!   3.4  !  02-13  (J. Siddorn) Routine taken from old dia_wri_foam
186      !!   3.6  !  08-14  (E. O'Dea) adapted for VN3.6
187      !!----------------------------------------------------------------------
188      !! * Modules used
189
190      IMPLICIT NONE
191
192      !! * Arguments
193      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
194
195
196      !! * Local declarations
197      INTEGER ::   ji, jj, jk
198
199      LOGICAL ::   ll_print = .FALSE.    ! =T print and flush numout
200      REAL(wp)                         ::   zsto, zout, zmax, zjulian, zdt, zmdi  ! temporary reals
201      INTEGER                          ::   i_steps                               ! no of timesteps per hour
202      REAL(wp), DIMENSION(jpi,jpj    ) ::   zw2d, un_dm, vn_dm                    ! temporary workspace
203      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zw3d                                  ! temporary workspace
204      REAL(wp), DIMENSION(jpi,jpj,3)   ::   zwtmb                                 ! temporary workspace
205      INTEGER                          ::   iyear0, nimonth0,iday0                ! start year,imonth,day
206
207      !!----------------------------------------------------------------------
208
209      ! 0. Initialisation
210      ! -----------------
211      ! Define frequency of summing to create 25 h mean
212      zdt = rdt
213      IF( nacc == 1 ) zdt = rdtmin
214
215      IF( MOD( 3600,INT(zdt) ) == 0 ) THEN
216         i_steps = 3600/INT(zdt)
217      ELSE
218         CALL ctl_stop('STOP', 'dia_wri_tide: timestep must give MOD(3600,rdt) = 0 otherwise no hourly values are possible')
219      ENDIF
220
221#if defined key_lim3 || defined key_lim2
222      CALL ctl_stop('STOP', 'dia_wri_tide not setup yet to do tidemean ice')
223#endif
224
225      ! local variable for debugging
226      ll_print = ll_print .AND. lwp
227
228      ! Sum of 25 hourly instantaneous values to give a 25h mean from 24hours
229      ! every day
230      IF( MOD( kt, i_steps ) == 0  .and. kt .ne. nn_it000 ) THEN
231
232         IF (lwp) THEN
233              WRITE(numout,*) 'dia_wri_tide : Summing instantaneous hourly diagnostics at timestep ',kt
234              WRITE(numout,*) '~~~~~~~~~~~~ '
235         ENDIF
236
237         tn_25h(:,:,:)        = tn_25h(:,:,:) + tsn(:,:,:,jp_tem)
238         sn_25h(:,:,:)        = sn_25h(:,:,:) + tsn(:,:,:,jp_sal)
239         CALL theta2t
240         rinsitu_t_25h(:,:,:)  = rinsitu_t_25h(:,:,:) + rinsitu_t(:,:,:)
241         sshn_25h(:,:)        = sshn_25h(:,:) + sshn (:,:)
242         un_25h(:,:,:)        = un_25h(:,:,:) + un(:,:,:)
243         vn_25h(:,:,:)        = vn_25h(:,:,:) + vn(:,:,:)
244         wn_25h(:,:,:)        = wn_25h(:,:,:) + wn(:,:,:)
245         avt_25h(:,:,:)       = avt_25h(:,:,:) + avt(:,:,:)
246         avm_25h(:,:,:)       = avm_25h(:,:,:) + avm(:,:,:)
247# if defined key_zdfgls || defined key_zdftke
248         en_25h(:,:,:)        = en_25h(:,:,:) + en(:,:,:)
249#endif
250# if defined key_zdfgls
251         rmxln_25h(:,:,:)      = rmxln_25h(:,:,:) + mxln(:,:,:)
252#endif
253         cnt_25h = cnt_25h + 1
254
255         IF (lwp) THEN
256            WRITE(numout,*) 'dia_tide : Summed the following number of hourly values so far',cnt_25h
257         ENDIF
258
259      ENDIF ! MOD( kt, i_steps ) == 0
260
261         ! Write data for 25 hour mean output streams
262      IF( cnt_25h .EQ. 25 .AND.  MOD( kt, i_steps*24) == 0 .AND. kt .NE. nn_it000 ) THEN
263
264            IF(lwp) THEN
265               WRITE(numout,*) 'dia_wri_tide : Writing 25 hour mean tide diagnostics at timestep', kt
266               WRITE(numout,*) '~~~~~~~~~~~~ '
267            ENDIF
268
269            tn_25h(:,:,:)        = tn_25h(:,:,:) / 25.0_wp
270            sn_25h(:,:,:)        = sn_25h(:,:,:) / 25.0_wp
271            rinsitu_t_25h(:,:,:)  = rinsitu_t_25h(:,:,:) / 25.0_wp
272            sshn_25h(:,:)        = sshn_25h(:,:) / 25.0_wp
273            un_25h(:,:,:)        = un_25h(:,:,:) / 25.0_wp
274            vn_25h(:,:,:)        = vn_25h(:,:,:) / 25.0_wp
275            wn_25h(:,:,:)        = wn_25h(:,:,:) / 25.0_wp
276            avt_25h(:,:,:)       = avt_25h(:,:,:) / 25.0_wp
277            avm_25h(:,:,:)       = avm_25h(:,:,:) / 25.0_wp
278# if defined key_zdfgls || defined key_zdftke
279            en_25h(:,:,:)        = en_25h(:,:,:) / 25.0_wp
280#endif
281# if defined key_zdfgls
282            rmxln_25h(:,:,:)       = rmxln_25h(:,:,:) / 25.0_wp
283#endif
284
285            IF (lwp)  WRITE(numout,*) 'dia_wri_tide : Mean calculated by dividing 25 hour sums and writing output'
286            zmdi=1.e+20 !missing data indicator for masking
287            ! write tracers (instantaneous)
288            zw3d(:,:,:) = tn_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
289            CALL iom_put("temper25h", zw3d)   ! potential temperature
290            CALL theta2t                                                                    ! calculate insitu temp
291            zw3d(:,:,:) = rinsitu_t_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
292            CALL iom_put("tempis25h", zw3d)   ! in-situ temperature
293            zw3d(:,:,:) = sn_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
294            CALL iom_put( "salin25h", zw3d  )   ! salinity
295            zw2d(:,:) = sshn_25h(:,:)*tmask(:,:,1) + zmdi*(1.0-tmask(:,:,1))
296            CALL iom_put( "ssh25h", zw2d )   ! sea surface
297
298
299            ! Write velocities (instantaneous)
300            zw3d(:,:,:) = un_25h(:,:,:)*umask(:,:,:) + zmdi*(1.0-umask(:,:,:))
301            CALL iom_put("vozocrtx25h", zw3d)    ! i-current
302            zw3d(:,:,:) = vn_25h(:,:,:)*vmask(:,:,:) + zmdi*(1.0-vmask(:,:,:))
303            CALL iom_put("vomecrty25h", zw3d  )   ! j-current
304
305            zw3d(:,:,:) = wn_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
306            CALL iom_put("vomecrtz25h", zw3d )   ! k-current
307            zw3d(:,:,:) = avt_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
308            CALL iom_put("avt25h", zw3d )   ! diffusivity
309            zw3d(:,:,:) = avm_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
310            CALL iom_put("avm25h", zw3d)   ! viscosity
311#if defined key_zdftke || defined key_zdfgls 
312!           zw3d(:,:,:) = en_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
313!           CALL iom_put("tke25h", zw3d)   ! tke
314#endif
315#if defined key_zdfgls 
316!           zw3d(:,:,:) = rmxln_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
317!           CALL iom_put( "mxln25h",zw3d)
318#endif
319
320            ! After the write reset the values to cnt=1 and sum values equal current value
321            tn_25h(:,:,:) = tsn(:,:,:,jp_tem)
322            sn_25h(:,:,:) = tsn(:,:,:,jp_sal)
323            CALL theta2t
324            rinsitu_t_25h(:,:,:) = rinsitu_t(:,:,:)
325            sshn_25h(:,:) = sshn (:,:)
326            un_25h(:,:,:) = un(:,:,:)
327            vn_25h(:,:,:) = vn(:,:,:)
328            wn_25h(:,:,:) = wn(:,:,:)
329            avt_25h(:,:,:) = avt(:,:,:)
330            avm_25h(:,:,:) = avm(:,:,:)
331# if defined key_zdfgls || defined key_zdftke
332            en_25h(:,:,:) = en(:,:,:)
333#endif
334# if defined key_zdfgls
335            rmxln_25h(:,:,:) = mxln(:,:,:)
336#endif
337            cnt_25h = 1
338            IF (lwp)  WRITE(numout,*) 'dia_wri_tide : After 25hr mean write, reset sum to current value and cnt_25h to one for overlapping average',cnt_25h
339
340      ENDIF !  cnt_25h .EQ. 25 .AND.  MOD( kt, i_steps * 24) == 0 .AND. kt .NE. nn_it000
341
342
343   END SUBROUTINE dia_25h 
344
345   !!======================================================================
346END MODULE dia25h
Note: See TracBrowser for help on using the repository browser.