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.
diahsb.F90 in NEMO/branches/2020/dev_r12377_KERNEL-06_techene_e3/src/OCE/DIA – NEMO

source: NEMO/branches/2020/dev_r12377_KERNEL-06_techene_e3/src/OCE/DIA/diahsb.F90 @ 12680

Last change on this file since 12680 was 12680, checked in by techene, 4 years ago

dynatfQCO.F90, stepLF.F90 : fixed (remove pe3. from dyn_atf_qco input arguments), all : remove e3. tables and include gurvan's feedbacks

  • Property svn:keywords set to Id
File size: 22.9 KB
Line 
1MODULE diahsb
2   !!======================================================================
3   !!                       ***  MODULE  diahsb  ***
4   !! Ocean diagnostics: Heat, salt and volume budgets
5   !!======================================================================
6   !! History :  3.3  ! 2010-09  (M. Leclair)  Original code
7   !!                 ! 2012-10  (C. Rousset)  add iom_put
8   !!----------------------------------------------------------------------
9
10   !!----------------------------------------------------------------------
11   !!   dia_hsb       : Diagnose the conservation of ocean heat and salt contents, and volume
12   !!   dia_hsb_rst   : Read or write DIA file in restart file
13   !!   dia_hsb_init  : Initialization of the conservation diagnostic
14   !!----------------------------------------------------------------------
15   USE oce            ! ocean dynamics and tracers
16   USE dom_oce        ! ocean space and time domain
17   USE phycst         ! physical constants
18   USE sbc_oce        ! surface thermohaline fluxes
19   USE isf_oce        ! ice shelf fluxes
20   USE sbcrnf         ! river runoff
21   USE domvvl         ! vertical scale factors
22   USE traqsr         ! penetrative solar radiation
23   USE trabbc         ! bottom boundary condition
24   USE trabbc         ! bottom boundary condition
25   USE restart        ! ocean restart
26   USE bdy_oce , ONLY : ln_bdy
27   !
28   USE iom            ! I/O manager
29   USE in_out_manager ! I/O manager
30   USE lib_fortran    ! glob_sum
31   USE lib_mpp        ! distributed memory computing library
32   USE timing         ! preformance summary
33
34   IMPLICIT NONE
35   PRIVATE
36
37   PUBLIC   dia_hsb        ! routine called by step.F90
38   PUBLIC   dia_hsb_init   ! routine called by nemogcm.F90
39
40   LOGICAL, PUBLIC ::   ln_diahsb   !: check the heat and salt budgets
41
42   REAL(wp) ::   surf_tot              ! ocean surface
43   REAL(wp) ::   frc_t, frc_s, frc_v   ! global forcing trends
44   REAL(wp) ::   frc_wn_t, frc_wn_s    ! global forcing trends
45   !
46   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE ::   surf 
47   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE ::   surf_ini      , ssh_ini          !
48   REAL(wp), DIMENSION(:,:)  , ALLOCATABLE ::   ssh_hc_loc_ini, ssh_sc_loc_ini   !
49   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   hc_loc_ini, sc_loc_ini, e3t_ini  !
50   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   tmask_ini
51
52   !! * Substitutions
53#  include "domzgr_substitute.h90"
54   !!----------------------------------------------------------------------
55   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
56   !! $Id$
57   !! Software governed by the CeCILL license (see ./LICENSE)
58   !!----------------------------------------------------------------------
59CONTAINS
60
61   SUBROUTINE dia_hsb( kt, Kbb, Kmm )
62      !!---------------------------------------------------------------------------
63      !!                  ***  ROUTINE dia_hsb  ***
64      !!     
65      !! ** Purpose: Compute the ocean global heat content, salt content and volume conservation
66      !!
67      !! ** Method : - Compute the deviation of heat content, salt content and volume
68      !!             at the current time step from their values at nit000
69      !!             - Compute the contribution of forcing and remove it from these deviations
70      !!
71      !!---------------------------------------------------------------------------
72      INTEGER, INTENT(in) ::   kt         ! ocean time-step index
73      INTEGER, INTENT(in) ::   Kbb, Kmm   ! ocean time level indices
74      !
75      INTEGER    ::   ji, jj, jk                  ! dummy loop indice
76      REAL(wp)   ::   zdiff_hc    , zdiff_sc      ! heat and salt content variations
77      REAL(wp)   ::   zdiff_hc1   , zdiff_sc1     !  -         -     -        -
78      REAL(wp)   ::   zdiff_v1    , zdiff_v2      ! volume variation
79      REAL(wp)   ::   zerr_hc1    , zerr_sc1      ! heat and salt content misfit
80      REAL(wp)   ::   zvol_tot                    ! volume
81      REAL(wp)   ::   z_frc_trd_t , z_frc_trd_s   !    -     -
82      REAL(wp)   ::   z_frc_trd_v                 !    -     -
83      REAL(wp)   ::   z_wn_trd_t , z_wn_trd_s     !    -     -
84      REAL(wp)   ::   z_ssh_hc , z_ssh_sc         !    -     -
85      REAL(wp), DIMENSION(jpi,jpj)       ::   z2d0, z2d1   ! 2D workspace
86      REAL(wp), DIMENSION(jpi,jpj,jpkm1) ::   zwrk         ! 3D workspace
87      !!---------------------------------------------------------------------------
88      IF( ln_timing )   CALL timing_start('dia_hsb')     
89      !
90      ts(:,:,:,1,Kmm) = ts(:,:,:,1,Kmm) * tmask(:,:,:) ; ts(:,:,:,1,Kbb) = ts(:,:,:,1,Kbb) * tmask(:,:,:) ;
91      ts(:,:,:,2,Kmm) = ts(:,:,:,2,Kmm) * tmask(:,:,:) ; ts(:,:,:,2,Kbb) = ts(:,:,:,2,Kbb) * tmask(:,:,:) ;
92      ! ------------------------- !
93      ! 1 - Trends due to forcing !
94      ! ------------------------- !
95      z_frc_trd_v = r1_rau0 * glob_sum( 'diahsb', - ( emp(:,:) - rnf(:,:) + fwfisf_cav(:,:) + fwfisf_par(:,:) ) * surf(:,:) )   ! volume fluxes
96      z_frc_trd_t =           glob_sum( 'diahsb', sbc_tsc(:,:,jp_tem) * surf(:,:) )                       ! heat fluxes
97      z_frc_trd_s =           glob_sum( 'diahsb', sbc_tsc(:,:,jp_sal) * surf(:,:) )                       ! salt fluxes
98      !                    !  Add runoff    heat & salt input
99      IF( ln_rnf    )   z_frc_trd_t = z_frc_trd_t + glob_sum( 'diahsb', rnf_tsc(:,:,jp_tem) * surf(:,:) )
100      IF( ln_rnf_sal)   z_frc_trd_s = z_frc_trd_s + glob_sum( 'diahsb', rnf_tsc(:,:,jp_sal) * surf(:,:) )
101      !                    ! Add ice shelf heat & salt input
102      IF( ln_isf    )   z_frc_trd_t = z_frc_trd_t &
103         &                          + glob_sum( 'diahsb', ( risf_cav_tsc(:,:,jp_tem) + risf_par_tsc(:,:,jp_tem) ) * surf(:,:) )
104      !                    ! Add penetrative solar radiation
105      IF( ln_traqsr )   z_frc_trd_t = z_frc_trd_t + r1_rau0_rcp * glob_sum( 'diahsb', qsr     (:,:) * surf(:,:) )
106      !                    ! Add geothermal heat flux
107      IF( ln_trabbc )   z_frc_trd_t = z_frc_trd_t +               glob_sum( 'diahsb', qgh_trd0(:,:) * surf(:,:) )
108      !
109      IF( ln_linssh ) THEN
110         IF( ln_isfcav ) THEN
111            DO ji=1,jpi
112               DO jj=1,jpj
113                  z2d0(ji,jj) = surf(ji,jj) * ww(ji,jj,mikt(ji,jj)) * ts(ji,jj,mikt(ji,jj),jp_tem,Kbb)
114                  z2d1(ji,jj) = surf(ji,jj) * ww(ji,jj,mikt(ji,jj)) * ts(ji,jj,mikt(ji,jj),jp_sal,Kbb)
115               END DO
116            END DO
117         ELSE
118            z2d0(:,:) = surf(:,:) * ww(:,:,1) * ts(:,:,1,jp_tem,Kbb)
119            z2d1(:,:) = surf(:,:) * ww(:,:,1) * ts(:,:,1,jp_sal,Kbb)
120         END IF
121         z_wn_trd_t = - glob_sum( 'diahsb', z2d0 ) 
122         z_wn_trd_s = - glob_sum( 'diahsb', z2d1 )
123      ENDIF
124
125      frc_v = frc_v + z_frc_trd_v * rdt
126      frc_t = frc_t + z_frc_trd_t * rdt
127      frc_s = frc_s + z_frc_trd_s * rdt
128      !                                          ! Advection flux through fixed surface (z=0)
129      IF( ln_linssh ) THEN
130         frc_wn_t = frc_wn_t + z_wn_trd_t * rdt
131         frc_wn_s = frc_wn_s + z_wn_trd_s * rdt
132      ENDIF
133
134      ! ------------------------ !
135      ! 2 -  Content variations  !
136      ! ------------------------ !
137      ! glob_sum_full is needed because you keep the full interior domain to compute the sum (iscpl)
138
139      !                    ! volume variation (calculated with ssh)
140      zdiff_v1 = glob_sum_full( 'diahsb', surf(:,:)*ssh(:,:,Kmm) - surf_ini(:,:)*ssh_ini(:,:) )
141
142      !                    ! heat & salt content variation (associated with ssh)
143      IF( ln_linssh ) THEN       ! linear free surface case
144         IF( ln_isfcav ) THEN          ! ISF case
145            DO ji = 1, jpi
146               DO jj = 1, jpj
147                  z2d0(ji,jj) = surf(ji,jj) * ( ts(ji,jj,mikt(ji,jj),jp_tem,Kmm) * ssh(ji,jj,Kmm) - ssh_hc_loc_ini(ji,jj) ) 
148                  z2d1(ji,jj) = surf(ji,jj) * ( ts(ji,jj,mikt(ji,jj),jp_sal,Kmm) * ssh(ji,jj,Kmm) - ssh_sc_loc_ini(ji,jj) ) 
149               END DO
150            END DO
151         ELSE                          ! no under ice-shelf seas
152            z2d0(:,:) = surf(:,:) * ( ts(:,:,1,jp_tem,Kmm) * ssh(:,:,Kmm) - ssh_hc_loc_ini(:,:) ) 
153            z2d1(:,:) = surf(:,:) * ( ts(:,:,1,jp_sal,Kmm) * ssh(:,:,Kmm) - ssh_sc_loc_ini(:,:) ) 
154         END IF
155         z_ssh_hc = glob_sum_full( 'diahsb', z2d0 ) 
156         z_ssh_sc = glob_sum_full( 'diahsb', z2d1 ) 
157      ENDIF
158      !
159      DO jk = 1, jpkm1           ! volume variation (calculated with scale factors)
160         zwrk(:,:,jk) =   surf    (:,:) * e3t    (:,:,jk,Kmm)*tmask    (:,:,jk)   &
161            &           - surf_ini(:,:) * e3t_ini(:,:,jk    )*tmask_ini(:,:,jk)
162      END DO
163      zdiff_v2 = glob_sum_full( 'diahsb', zwrk(:,:,:) )     ! glob_sum_full needed as tmask and tmask_ini could be different
164      DO jk = 1, jpkm1           ! heat content variation
165         zwrk(:,:,jk) = ( surf    (:,:) * e3t(:,:,jk,Kmm)*ts(:,:,jk,jp_tem,Kmm)   &
166            &           - surf_ini(:,:) *         hc_loc_ini(:,:,jk) )
167      END DO
168      zdiff_hc = glob_sum_full( 'diahsb', zwrk(:,:,:) )
169      DO jk = 1, jpkm1           ! salt content variation
170         zwrk(:,:,jk) = ( surf    (:,:) * e3t(:,:,jk,Kmm)*ts(:,:,jk,jp_sal,Kmm)   &
171            &           - surf_ini(:,:) *         sc_loc_ini(:,:,jk) )
172      END DO
173      zdiff_sc = glob_sum_full( 'diahsb', zwrk(:,:,:) )
174
175      ! ------------------------ !
176      ! 3 -  Drifts              !
177      ! ------------------------ !
178      zdiff_v1 = zdiff_v1 - frc_v
179      IF( .NOT.ln_linssh )   zdiff_v2 = zdiff_v2 - frc_v
180      zdiff_hc = zdiff_hc - frc_t
181      zdiff_sc = zdiff_sc - frc_s
182      IF( ln_linssh ) THEN
183         zdiff_hc1 = zdiff_hc + z_ssh_hc 
184         zdiff_sc1 = zdiff_sc + z_ssh_sc
185         zerr_hc1  = z_ssh_hc - frc_wn_t
186         zerr_sc1  = z_ssh_sc - frc_wn_s
187      ENDIF
188
189      ! ----------------------- !
190      ! 4 - Diagnostics writing !
191      ! ----------------------- !
192      DO jk = 1, jpkm1           ! total ocean volume (calculated with scale factors)
193         zwrk(:,:,jk) = surf(:,:) * e3t(:,:,jk,Kmm) * tmask(:,:,jk)
194      END DO
195      zvol_tot = glob_sum( 'diahsb', zwrk(:,:,:) )
196
197!!gm to be added ?
198!      IF( ln_linssh ) THEN            ! fixed volume, add the ssh contribution
199!        zvol_tot = zvol_tot + glob_sum( 'diahsb', surf(:,:) * ssh(:,:,Kmm) )
200!      ENDIF
201!!gm end
202
203      CALL iom_put(   'bgfrcvol' , frc_v    * 1.e-9    )              ! vol - surface forcing (km3)
204      CALL iom_put(   'bgfrctem' , frc_t    * rau0 * rcp * 1.e-20 )   ! hc  - surface forcing (1.e20 J)
205      CALL iom_put(   'bgfrchfx' , frc_t    * rau0 * rcp /  &         ! hc  - surface forcing (W/m2)
206         &                       ( surf_tot * kt * rdt )        )
207      CALL iom_put(   'bgfrcsal' , frc_s    * 1.e-9    )              ! sc  - surface forcing (psu*km3)
208
209      IF( .NOT. ln_linssh ) THEN
210         CALL iom_put( 'bgtemper' , zdiff_hc / zvol_tot )              ! Temperature drift     (C)
211         CALL iom_put( 'bgsaline' , zdiff_sc / zvol_tot )              ! Salinity    drift     (PSU)
212         CALL iom_put( 'bgheatco' , zdiff_hc * 1.e-20 * rau0 * rcp )   ! Heat content drift    (1.e20 J)
213         CALL iom_put( 'bgheatfx' , zdiff_hc * rau0 * rcp /  &         ! Heat flux drift       (W/m2)
214            &                       ( surf_tot * kt * rdt )        )
215         CALL iom_put( 'bgsaltco' , zdiff_sc * 1.e-9    )              ! Salt content drift    (psu*km3)
216         CALL iom_put( 'bgvolssh' , zdiff_v1 * 1.e-9    )              ! volume ssh drift      (km3) 
217         CALL iom_put( 'bgvole3t' , zdiff_v2 * 1.e-9    )              ! volume e3t drift      (km3) 
218         !
219         IF( kt == nitend .AND. lwp ) THEN
220            WRITE(numout,*)
221            WRITE(numout,*) 'dia_hsb : last time step hsb diagnostics: at it= ', kt,' date= ', ndastp
222            WRITE(numout,*) '~~~~~~~'
223            WRITE(numout,*) '   Temperature drift = ', zdiff_hc / zvol_tot, ' C'
224            WRITE(numout,*) '   Salinity    drift = ', zdiff_sc / zvol_tot, ' PSU'
225            WRITE(numout,*) '   volume ssh  drift = ', zdiff_v1 * 1.e-9   , ' km^3'
226            WRITE(numout,*) '   volume e3t  drift = ', zdiff_v2 * 1.e-9   , ' km^3'
227         ENDIF
228         !
229      ELSE
230         CALL iom_put( 'bgtemper' , zdiff_hc1 / zvol_tot)              ! Heat content drift    (C)
231         CALL iom_put( 'bgsaline' , zdiff_sc1 / zvol_tot)              ! Salt content drift    (PSU)
232         CALL iom_put( 'bgheatco' , zdiff_hc1 * 1.e-20 * rau0 * rcp )  ! Heat content drift    (1.e20 J)
233         CALL iom_put( 'bgheatfx' , zdiff_hc1 * rau0 * rcp /  &        ! Heat flux drift       (W/m2)
234            &                       ( surf_tot * kt * rdt )         )
235         CALL iom_put( 'bgsaltco' , zdiff_sc1 * 1.e-9    )             ! Salt content drift    (psu*km3)
236         CALL iom_put( 'bgvolssh' , zdiff_v1 * 1.e-9    )              ! volume ssh drift      (km3) 
237         CALL iom_put( 'bgmistem' , zerr_hc1 / zvol_tot )              ! hc  - error due to free surface (C)
238         CALL iom_put( 'bgmissal' , zerr_sc1 / zvol_tot )              ! sc  - error due to free surface (psu)
239      ENDIF
240      !
241      IF( lrst_oce )   CALL dia_hsb_rst( kt, Kmm, 'WRITE' )
242      !
243      IF( ln_timing )   CALL timing_stop('dia_hsb')
244      !
245   END SUBROUTINE dia_hsb
246
247
248   SUBROUTINE dia_hsb_rst( kt, Kmm, cdrw )
249      !!---------------------------------------------------------------------
250      !!                   ***  ROUTINE dia_hsb_rst  ***
251      !!                     
252      !! ** Purpose :   Read or write DIA file in restart file
253      !!
254      !! ** Method  :   use of IOM library
255      !!----------------------------------------------------------------------
256      INTEGER         , INTENT(in) ::   kt     ! ocean time-step
257      INTEGER         , INTENT(in) ::   Kmm    ! ocean time level index
258      CHARACTER(len=*), INTENT(in) ::   cdrw   ! "READ"/"WRITE" flag
259      !
260      INTEGER ::   ji, jj, jk   ! dummy loop indices
261      !!----------------------------------------------------------------------
262      !
263      IF( TRIM(cdrw) == 'READ' ) THEN        ! Read/initialise
264         IF( ln_rstart ) THEN                   !* Read the restart file
265            !
266            IF(lwp) WRITE(numout,*)
267            IF(lwp) WRITE(numout,*) '   dia_hsb_rst : read hsb restart at it= ', kt,' date= ', ndastp
268            IF(lwp) WRITE(numout,*)
269            CALL iom_get( numror, 'frc_v', frc_v, ldxios = lrxios )
270            CALL iom_get( numror, 'frc_t', frc_t, ldxios = lrxios )
271            CALL iom_get( numror, 'frc_s', frc_s, ldxios = lrxios )
272            IF( ln_linssh ) THEN
273               CALL iom_get( numror, 'frc_wn_t', frc_wn_t, ldxios = lrxios )
274               CALL iom_get( numror, 'frc_wn_s', frc_wn_s, ldxios = lrxios )
275            ENDIF
276            CALL iom_get( numror, jpdom_autoglo, 'surf_ini'  , surf_ini  , ldxios = lrxios ) ! ice sheet coupling
277            CALL iom_get( numror, jpdom_autoglo, 'ssh_ini'   , ssh_ini   , ldxios = lrxios )
278            CALL iom_get( numror, jpdom_autoglo, 'e3t_ini'   , e3t_ini   , ldxios = lrxios )
279            CALL iom_get( numror, jpdom_autoglo, 'tmask_ini' , tmask_ini , ldxios = lrxios )
280            CALL iom_get( numror, jpdom_autoglo, 'hc_loc_ini', hc_loc_ini, ldxios = lrxios )
281            CALL iom_get( numror, jpdom_autoglo, 'sc_loc_ini', sc_loc_ini, ldxios = lrxios )
282            IF( ln_linssh ) THEN
283               CALL iom_get( numror, jpdom_autoglo, 'ssh_hc_loc_ini', ssh_hc_loc_ini, ldxios = lrxios )
284               CALL iom_get( numror, jpdom_autoglo, 'ssh_sc_loc_ini', ssh_sc_loc_ini, ldxios = lrxios )
285            ENDIF
286         ELSE
287            IF(lwp) WRITE(numout,*)
288            IF(lwp) WRITE(numout,*) '   dia_hsb_rst : initialise hsb at initial state '
289            IF(lwp) WRITE(numout,*)
290            surf_ini(:,:) = e1e2t(:,:) * tmask_i(:,:)         ! initial ocean surface
291            ssh_ini(:,:) = ssh(:,:,Kmm)                          ! initial ssh
292            DO jk = 1, jpk
293              ! if ice sheet/oceqn coupling, need to mask ini variables here (mask could change at the next NEMO instance).
294               e3t_ini   (:,:,jk) =                       e3t(:,:,jk,Kmm)*tmask(:,:,jk)  ! initial vertical scale factors
295               tmask_ini (:,:,jk) = tmask(:,:,jk)                                       ! initial mask
296               hc_loc_ini(:,:,jk) = ts(:,:,jk,jp_tem,Kmm)*e3t(:,:,jk,Kmm)*tmask(:,:,jk)  ! initial heat content
297               sc_loc_ini(:,:,jk) = ts(:,:,jk,jp_sal,Kmm)*e3t(:,:,jk,Kmm)*tmask(:,:,jk)  ! initial salt content
298            END DO
299            frc_v = 0._wp                                           ! volume       trend due to forcing
300            frc_t = 0._wp                                           ! heat content   -    -   -    -   
301            frc_s = 0._wp                                           ! salt content   -    -   -    -       
302            IF( ln_linssh ) THEN
303               IF( ln_isfcav ) THEN
304                  DO ji = 1, jpi
305                     DO jj = 1, jpj
306                        ssh_hc_loc_ini(ji,jj) = ts(ji,jj,mikt(ji,jj),jp_tem,Kmm) * ssh(ji,jj,Kmm)   ! initial heat content in ssh
307                        ssh_sc_loc_ini(ji,jj) = ts(ji,jj,mikt(ji,jj),jp_sal,Kmm) * ssh(ji,jj,Kmm)   ! initial salt content in ssh
308                     END DO
309                   END DO
310                ELSE
311                  ssh_hc_loc_ini(:,:) = ts(:,:,1,jp_tem,Kmm) * ssh(:,:,Kmm)   ! initial heat content in ssh
312                  ssh_sc_loc_ini(:,:) = ts(:,:,1,jp_sal,Kmm) * ssh(:,:,Kmm)   ! initial salt content in ssh
313               END IF
314               frc_wn_t = 0._wp                                       ! initial heat content misfit due to free surface
315               frc_wn_s = 0._wp                                       ! initial salt content misfit due to free surface
316            ENDIF
317         ENDIF
318         !
319      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN   ! Create restart file
320         !                                   ! -------------------
321         IF(lwp) WRITE(numout,*)
322         IF(lwp) WRITE(numout,*) '   dia_hsb_rst : write restart at it= ', kt,' date= ', ndastp
323         IF(lwp) WRITE(numout,*)
324         !
325         IF( lwxios ) CALL iom_swap(      cwxios_context          )
326         CALL iom_rstput( kt, nitrst, numrow, 'frc_v', frc_v, ldxios = lwxios )
327         CALL iom_rstput( kt, nitrst, numrow, 'frc_t', frc_t, ldxios = lwxios )
328         CALL iom_rstput( kt, nitrst, numrow, 'frc_s', frc_s, ldxios = lwxios )
329         IF( ln_linssh ) THEN
330            CALL iom_rstput( kt, nitrst, numrow, 'frc_wn_t', frc_wn_t, ldxios = lwxios )
331            CALL iom_rstput( kt, nitrst, numrow, 'frc_wn_s', frc_wn_s, ldxios = lwxios )
332         ENDIF
333         CALL iom_rstput( kt, nitrst, numrow, 'surf_ini'  , surf_ini  , ldxios = lwxios )      ! ice sheet coupling
334         CALL iom_rstput( kt, nitrst, numrow, 'ssh_ini'   , ssh_ini   , ldxios = lwxios )
335         CALL iom_rstput( kt, nitrst, numrow, 'e3t_ini'   , e3t_ini   , ldxios = lwxios )
336         CALL iom_rstput( kt, nitrst, numrow, 'tmask_ini' , tmask_ini , ldxios = lwxios )
337         CALL iom_rstput( kt, nitrst, numrow, 'hc_loc_ini', hc_loc_ini, ldxios = lwxios )
338         CALL iom_rstput( kt, nitrst, numrow, 'sc_loc_ini', sc_loc_ini, ldxios = lwxios )
339         IF( ln_linssh ) THEN
340            CALL iom_rstput( kt, nitrst, numrow, 'ssh_hc_loc_ini', ssh_hc_loc_ini, ldxios = lwxios )
341            CALL iom_rstput( kt, nitrst, numrow, 'ssh_sc_loc_ini', ssh_sc_loc_ini, ldxios = lwxios )
342         ENDIF
343         IF( lwxios ) CALL iom_swap(      cxios_context          )
344         !
345      ENDIF
346      !
347   END SUBROUTINE dia_hsb_rst
348
349
350   SUBROUTINE dia_hsb_init( Kmm )
351      !!---------------------------------------------------------------------------
352      !!                  ***  ROUTINE dia_hsb  ***
353      !!     
354      !! ** Purpose: Initialization for the heat salt volume budgets
355      !!
356      !! ** Method : Compute initial heat content, salt content and volume
357      !!
358      !! ** Action : - Compute initial heat content, salt content and volume
359      !!             - Initialize forcing trends
360      !!             - Compute coefficients for conversion
361      !!---------------------------------------------------------------------------
362      INTEGER, INTENT(in) :: Kmm ! time level index
363      !
364      INTEGER ::   ierror, ios   ! local integer
365      !!
366      NAMELIST/namhsb/ ln_diahsb
367      !!----------------------------------------------------------------------
368      !
369      IF(lwp) THEN
370         WRITE(numout,*)
371         WRITE(numout,*) 'dia_hsb_init : heat and salt budgets diagnostics'
372         WRITE(numout,*) '~~~~~~~~~~~~ '
373      ENDIF
374      READ  ( numnam_ref, namhsb, IOSTAT = ios, ERR = 901)
375901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namhsb in reference namelist' )
376      READ  ( numnam_cfg, namhsb, IOSTAT = ios, ERR = 902 )
377902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namhsb in configuration namelist' )
378      IF(lwm) WRITE( numond, namhsb )
379
380      IF(lwp) THEN
381         WRITE(numout,*) '   Namelist  namhsb :'
382         WRITE(numout,*) '      check the heat and salt budgets (T) or not (F)       ln_diahsb = ', ln_diahsb
383      ENDIF
384      !
385      IF( .NOT. ln_diahsb )   RETURN
386
387      IF(lwxios) THEN
388! define variables in restart file when writing with XIOS
389        CALL iom_set_rstw_var_active('frc_v')
390        CALL iom_set_rstw_var_active('frc_t')
391        CALL iom_set_rstw_var_active('frc_s')
392        CALL iom_set_rstw_var_active('surf_ini')
393        CALL iom_set_rstw_var_active('ssh_ini')
394        CALL iom_set_rstw_var_active('e3t_ini')
395        CALL iom_set_rstw_var_active('hc_loc_ini')
396        CALL iom_set_rstw_var_active('sc_loc_ini')
397        IF( ln_linssh ) THEN
398           CALL iom_set_rstw_var_active('ssh_hc_loc_ini')
399           CALL iom_set_rstw_var_active('ssh_sc_loc_ini')
400           CALL iom_set_rstw_var_active('frc_wn_t')
401           CALL iom_set_rstw_var_active('frc_wn_s')
402        ENDIF
403      ENDIF
404      ! ------------------- !
405      ! 1 - Allocate memory !
406      ! ------------------- !
407      ALLOCATE( hc_loc_ini(jpi,jpj,jpk), sc_loc_ini(jpi,jpj,jpk), surf_ini(jpi,jpj), &
408         &      e3t_ini(jpi,jpj,jpk), surf(jpi,jpj),  ssh_ini(jpi,jpj), tmask_ini(jpi,jpj,jpk),STAT=ierror  )
409      IF( ierror > 0 ) THEN
410         CALL ctl_stop( 'dia_hsb_init: unable to allocate hc_loc_ini' )   ;   RETURN
411      ENDIF
412
413      IF( ln_linssh )   ALLOCATE( ssh_hc_loc_ini(jpi,jpj), ssh_sc_loc_ini(jpi,jpj),STAT=ierror )
414      IF( ierror > 0 ) THEN
415         CALL ctl_stop( 'dia_hsb: unable to allocate ssh_hc_loc_ini' )   ;   RETURN
416      ENDIF
417
418      ! ----------------------------------------------- !
419      ! 2 - Time independant variables and file opening !
420      ! ----------------------------------------------- !
421      surf(:,:) = e1e2t(:,:) * tmask_i(:,:)               ! masked surface grid cell area
422      surf_tot  = glob_sum( 'diahsb', surf(:,:) )         ! total ocean surface area
423
424      IF( ln_bdy ) CALL ctl_warn( 'dia_hsb_init: heat/salt budget does not consider open boundary fluxes' )         
425      !
426      ! ---------------------------------- !
427      ! 4 - initial conservation variables !
428      ! ---------------------------------- !
429      CALL dia_hsb_rst( nit000, Kmm, 'READ' )  !* read or initialize all required files
430      !
431   END SUBROUTINE dia_hsb_init
432
433   !!======================================================================
434END MODULE diahsb
Note: See TracBrowser for help on using the repository browser.