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 NEMO/branches/UKMO/NEMO_4.0_mirror/src/OCE/DIA – NEMO

source: NEMO/branches/UKMO/NEMO_4.0_mirror/src/OCE/DIA/dia25h.F90 @ 10888

Last change on this file since 10888 was 10888, checked in by davestorkey, 5 years ago

branches/UKMO/NEMO_4.0_mirror : clear SVN keywords

File size: 12.2 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 zdf_oce         ! ocean vertical physics   
11   USE zdfgls   , ONLY : hmxl_n
12   !
13   USE in_out_manager  ! I/O units
14   USE iom             ! I/0 library
15   USE wet_dry
16
17   IMPLICIT NONE
18   PRIVATE
19
20   PUBLIC   dia_25h_init               ! routine called by nemogcm.F90
21   PUBLIC   dia_25h                    ! routine called by diawri.F90
22
23   LOGICAL, PUBLIC ::   ln_dia25h      !:  25h mean output
24
25   ! variables for calculating 25-hourly means
26   INTEGER , SAVE ::   cnt_25h           ! Counter for 25 hour means
27   REAL(wp), SAVE ::   r1_25 = 0.04_wp   ! =1/25
28   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   tn_25h  , sn_25h
29   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:)   ::   sshn_25h 
30   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   un_25h  , vn_25h  , wn_25h
31   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   avt_25h , avm_25h
32   REAL(wp), SAVE, ALLOCATABLE, DIMENSION(:,:,:) ::   en_25h  , rmxln_25h
33
34   !!----------------------------------------------------------------------
35   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
36   !! $Id$
37   !! Software governed by the CeCILL license (see ./LICENSE)
38   !!----------------------------------------------------------------------
39CONTAINS
40
41   SUBROUTINE dia_25h_init 
42      !!---------------------------------------------------------------------------
43      !!                  ***  ROUTINE dia_25h_init  ***
44      !!     
45      !! ** Purpose: Initialization of 25h mean namelist
46      !!       
47      !! ** Method : Read namelist
48      !!---------------------------------------------------------------------------
49      INTEGER ::   ios                 ! Local integer output status for namelist read
50      INTEGER ::   ierror              ! Local integer for memory allocation
51      !
52      NAMELIST/nam_dia25h/ ln_dia25h
53      !!----------------------------------------------------------------------
54      !
55      REWIND ( numnam_ref )              ! Read Namelist nam_dia25h in reference namelist : 25hour mean diagnostics
56      READ   ( numnam_ref, nam_dia25h, IOSTAT=ios, ERR= 901 )
57901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'nam_dia25h in reference namelist', lwp )
58      REWIND( numnam_cfg )              ! Namelist nam_dia25h in configuration namelist  25hour diagnostics
59      READ  ( numnam_cfg, nam_dia25h, IOSTAT = ios, ERR = 902 )
60902   IF( ios >  0 )   CALL ctl_nam ( ios , 'nam_dia25h in configuration namelist', lwp )
61      IF(lwm) WRITE ( numond, nam_dia25h )
62
63      IF(lwp) THEN                   ! Control print
64         WRITE(numout,*)
65         WRITE(numout,*) 'dia_25h_init : Output 25 hour mean diagnostics'
66         WRITE(numout,*) '~~~~~~~~~~~~'
67         WRITE(numout,*) '   Namelist nam_dia25h : set 25h outputs '
68         WRITE(numout,*) '      Switch for 25h diagnostics (T) or not (F)  ln_dia25h  = ', ln_dia25h
69      ENDIF
70      IF( .NOT. ln_dia25h )   RETURN
71      ! ------------------- !
72      ! 1 - Allocate memory !
73      ! ------------------- !
74      !                                ! ocean arrays
75      ALLOCATE( tn_25h (jpi,jpj,jpk), sn_25h (jpi,jpj,jpk), sshn_25h(jpi,jpj)  ,     &
76         &      un_25h (jpi,jpj,jpk), vn_25h (jpi,jpj,jpk), wn_25h(jpi,jpj,jpk),     &
77         &      avt_25h(jpi,jpj,jpk), avm_25h(jpi,jpj,jpk),                      STAT=ierror )
78      IF( ierror > 0 ) THEN
79         CALL ctl_stop( 'dia_25h: unable to allocate ocean arrays' )   ;   RETURN
80      ENDIF
81      IF( ln_zdftke ) THEN             ! TKE physics
82         ALLOCATE( en_25h(jpi,jpj,jpk), STAT=ierror )
83         IF( ierror > 0 ) THEN
84            CALL ctl_stop( 'dia_25h: unable to allocate en_25h' )   ;   RETURN
85         ENDIF
86      ENDIF
87      IF( ln_zdfgls ) THEN             ! GLS physics
88         ALLOCATE( en_25h(jpi,jpj,jpk), rmxln_25h(jpi,jpj,jpk), STAT=ierror )
89         IF( ierror > 0 ) THEN
90            CALL ctl_stop( 'dia_25h: unable to allocate en_25h and rmxln_25h' )   ;   RETURN
91         ENDIF
92      ENDIF
93      ! ------------------------- !
94      ! 2 - Assign Initial Values !
95      ! ------------------------- !
96      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)
97      tn_25h  (:,:,:) = tsb (:,:,:,jp_tem)
98      sn_25h  (:,:,:) = tsb (:,:,:,jp_sal)
99      sshn_25h(:,:)   = sshb(:,:)
100      un_25h  (:,:,:) = ub  (:,:,:)
101      vn_25h  (:,:,:) = vb  (:,:,:)
102      avt_25h (:,:,:) = avt (:,:,:)
103      avm_25h (:,:,:) = avm (:,:,:)
104      IF( ln_zdftke ) THEN
105         en_25h(:,:,:) = en(:,:,:)
106      ENDIF
107      IF( ln_zdfgls ) THEN
108         en_25h   (:,:,:) = en    (:,:,:)
109         rmxln_25h(:,:,:) = hmxl_n(:,:,:)
110      ENDIF
111#if defined key_si3
112      CALL ctl_stop('STOP', 'dia_25h not setup yet to do tidemean ice')
113#endif 
114      !
115   END SUBROUTINE dia_25h_init
116
117
118   SUBROUTINE dia_25h( kt ) 
119      !!----------------------------------------------------------------------
120      !!                 ***  ROUTINE dia_25h  ***
121      !!         
122      !! ** Purpose :   Write diagnostics with M2/S2 tide removed
123      !!
124      !! ** Method  :   25hr mean outputs for shelf seas
125      !!----------------------------------------------------------------------
126      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
127      !!
128      INTEGER ::   ji, jj, jk
129      INTEGER                          ::   iyear0, nimonth0,iday0            ! start year,imonth,day
130      LOGICAL ::   ll_print = .FALSE.    ! =T print and flush numout
131      REAL(wp)                         ::   zsto, zout, zmax, zjulian, zmdi   ! local scalars
132      INTEGER                          ::   i_steps                           ! no of timesteps per hour
133      REAL(wp), DIMENSION(jpi,jpj    ) ::   zw2d, un_dm, vn_dm                ! workspace
134      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zw3d                              ! workspace
135      REAL(wp), DIMENSION(jpi,jpj,3)   ::   zwtmb                             ! workspace
136      !!----------------------------------------------------------------------
137
138      ! 0. Initialisation
139      ! -----------------
140      ! Define frequency of summing to create 25 h mean
141      IF( MOD( 3600,NINT(rdt) ) == 0 ) THEN
142         i_steps = 3600/NINT(rdt)
143      ELSE
144         CALL ctl_stop('STOP', 'dia_wri_tide: timestep must give MOD(3600,rdt) = 0 otherwise no hourly values are possible')
145      ENDIF
146
147      ! local variable for debugging
148      ll_print = ll_print .AND. lwp
149
150      ! wn_25h could not be initialised in dia_25h_init, so we do it here instead
151      IF( kt == nn_it000 ) THEN
152         wn_25h(:,:,:) = wn(:,:,:)
153      ENDIF
154
155      ! Sum of 25 hourly instantaneous values to give a 25h mean from 24hours every day
156      IF( MOD( kt, i_steps ) == 0  .AND. kt /= nn_it000 ) THEN
157
158         IF (lwp) THEN
159              WRITE(numout,*) 'dia_wri_tide : Summing instantaneous hourly diagnostics at timestep ',kt
160              WRITE(numout,*) '~~~~~~~~~~~~ '
161         ENDIF
162
163         tn_25h  (:,:,:)     = tn_25h  (:,:,:) + tsn (:,:,:,jp_tem)
164         sn_25h  (:,:,:)     = sn_25h  (:,:,:) + tsn (:,:,:,jp_sal)
165         sshn_25h(:,:)       = sshn_25h(:,:)   + sshn(:,:)
166         un_25h  (:,:,:)     = un_25h  (:,:,:) + un  (:,:,:)
167         vn_25h  (:,:,:)     = vn_25h  (:,:,:) + vn  (:,:,:)
168         wn_25h  (:,:,:)     = wn_25h  (:,:,:) + wn  (:,:,:)
169         avt_25h (:,:,:)     = avt_25h (:,:,:) + avt (:,:,:)
170         avm_25h (:,:,:)     = avm_25h (:,:,:) + avm (:,:,:)
171         IF( ln_zdftke ) THEN
172            en_25h(:,:,:)    = en_25h  (:,:,:) + en(:,:,:)
173         ENDIF
174         IF( ln_zdfgls ) THEN
175            en_25h   (:,:,:) = en_25h   (:,:,:) + en    (:,:,:)
176            rmxln_25h(:,:,:) = rmxln_25h(:,:,:) + hmxl_n(:,:,:)
177         ENDIF
178         cnt_25h = cnt_25h + 1
179         !
180         IF (lwp) THEN
181            WRITE(numout,*) 'dia_tide : Summed the following number of hourly values so far',cnt_25h
182         ENDIF
183         !
184      ENDIF ! MOD( kt, i_steps ) == 0
185
186      ! Write data for 25 hour mean output streams
187      IF( cnt_25h == 25 .AND.  MOD( kt, i_steps*24) == 0 .AND. kt /= nn_it000 ) THEN
188         !
189         IF(lwp) THEN
190            WRITE(numout,*) 'dia_wri_tide : Writing 25 hour mean tide diagnostics at timestep', kt
191            WRITE(numout,*) '~~~~~~~~~~~~ '
192         ENDIF
193         !
194         tn_25h  (:,:,:) = tn_25h  (:,:,:) * r1_25
195         sn_25h  (:,:,:) = sn_25h  (:,:,:) * r1_25
196         sshn_25h(:,:)   = sshn_25h(:,:)   * r1_25
197         un_25h  (:,:,:) = un_25h  (:,:,:) * r1_25
198         vn_25h  (:,:,:) = vn_25h  (:,:,:) * r1_25
199         wn_25h  (:,:,:) = wn_25h  (:,:,:) * r1_25
200         avt_25h (:,:,:) = avt_25h (:,:,:) * r1_25
201         avm_25h (:,:,:) = avm_25h (:,:,:) * r1_25
202         IF( ln_zdftke ) THEN
203            en_25h(:,:,:) = en_25h(:,:,:) * r1_25
204         ENDIF
205         IF( ln_zdfgls ) THEN
206            en_25h   (:,:,:) = en_25h   (:,:,:) * r1_25
207            rmxln_25h(:,:,:) = rmxln_25h(:,:,:) * r1_25
208         ENDIF
209         !
210         IF(lwp)  WRITE(numout,*) 'dia_wri_tide : Mean calculated by dividing 25 hour sums and writing output'
211         zmdi=1.e+20 !missing data indicator for masking
212         ! write tracers (instantaneous)
213         zw3d(:,:,:) = tn_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
214         CALL iom_put("temper25h", zw3d)   ! potential temperature
215         zw3d(:,:,:) = sn_25h(:,:,:)*tmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
216         CALL iom_put( "salin25h", zw3d  )   ! salinity
217         zw2d(:,:) = sshn_25h(:,:)*tmask(:,:,1) + zmdi*(1.0-tmask(:,:,1))
218         IF( ll_wd ) THEN
219            CALL iom_put( "ssh25h", zw2d+ssh_ref )   ! sea surface
220         ELSE
221            CALL iom_put( "ssh25h", zw2d )   ! sea surface
222         ENDIF
223         ! Write velocities (instantaneous)
224         zw3d(:,:,:) = un_25h(:,:,:)*umask(:,:,:) + zmdi*(1.0-umask(:,:,:))
225         CALL iom_put("vozocrtx25h", zw3d)    ! i-current
226         zw3d(:,:,:) = vn_25h(:,:,:)*vmask(:,:,:) + zmdi*(1.0-vmask(:,:,:))
227         CALL iom_put("vomecrty25h", zw3d  )   ! j-current
228         zw3d(:,:,:) = wn_25h(:,:,:)*wmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
229         CALL iom_put("vovecrtz25h", zw3d )   ! k-current
230         ! Write vertical physics
231         zw3d(:,:,:) = avt_25h(:,:,:)*wmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
232         CALL iom_put("avt25h", zw3d )   ! diffusivity
233         zw3d(:,:,:) = avm_25h(:,:,:)*wmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
234         CALL iom_put("avm25h", zw3d)   ! viscosity
235         IF( ln_zdftke ) THEN
236            zw3d(:,:,:) = en_25h(:,:,:)*wmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
237            CALL iom_put("tke25h", zw3d)   ! tke
238         ENDIF
239         IF( ln_zdfgls ) THEN
240            zw3d(:,:,:) = en_25h(:,:,:)*wmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
241            CALL iom_put("tke25h", zw3d)   ! tke
242            zw3d(:,:,:) = rmxln_25h(:,:,:)*wmask(:,:,:) + zmdi*(1.0-tmask(:,:,:))
243            CALL iom_put( "mxln25h",zw3d)
244         ENDIF
245         !
246         ! After the write reset the values to cnt=1 and sum values equal current value
247         tn_25h  (:,:,:) = tsn (:,:,:,jp_tem)
248         sn_25h  (:,:,:) = tsn (:,:,:,jp_sal)
249         sshn_25h(:,:)   = sshn(:,:)
250         un_25h  (:,:,:) = un  (:,:,:)
251         vn_25h  (:,:,:) = vn  (:,:,:)
252         wn_25h  (:,:,:) = wn  (:,:,:)
253         avt_25h (:,:,:) = avt (:,:,:)
254         avm_25h (:,:,:) = avm (:,:,:)
255         IF( ln_zdftke ) THEN
256            en_25h(:,:,:) = en(:,:,:)
257         ENDIF
258         IF( ln_zdfgls ) THEN
259            en_25h   (:,:,:) = en    (:,:,:)
260            rmxln_25h(:,:,:) = hmxl_n(:,:,:)
261         ENDIF
262         cnt_25h = 1
263         IF(lwp)  WRITE(numout,*) 'dia_wri_tide :   &
264            &    After 25hr mean write, reset sum to current value and cnt_25h to one for overlapping average', cnt_25h
265      ENDIF !  cnt_25h .EQ. 25 .AND.  MOD( kt, i_steps * 24) == 0 .AND. kt .NE. nn_it000
266      !
267   END SUBROUTINE dia_25h 
268
269   !!======================================================================
270END MODULE dia25h
Note: See TracBrowser for help on using the repository browser.