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/2017/dev_r7881_no_wrk_alloc/NEMOGCM/NEMO/OPA_SRC/DIA – NEMO

source: branches/2017/dev_r7881_no_wrk_alloc/NEMOGCM/NEMO/OPA_SRC/DIA/dia25h.F90 @ 8016

Last change on this file since 8016 was 8016, checked in by timgraham, 7 years ago

Delete some remaining "USE wrk_array" lines

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