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.
diawri.F90 in branches/2018/dev_r8864_nemo_v3_6_ZTILDE/NEMOGCM/NEMO/OPA_SRC/DIA – NEMO

source: branches/2018/dev_r8864_nemo_v3_6_ZTILDE/NEMOGCM/NEMO/OPA_SRC/DIA/diawri.F90 @ 9545

Last change on this file since 9545 was 9545, checked in by jchanut, 6 years ago

Add diagnostics in diawri - revert to old interface interpolation - change default regriding parameters - add linear ramp at startup

  • Property svn:keywords set to Id
File size: 60.3 KB
Line 
1MODULE diawri
2   !!======================================================================
3   !!                     ***  MODULE  diawri  ***
4   !! Ocean diagnostics :  write ocean output files
5   !!=====================================================================
6   !! History :  OPA  ! 1991-03  (M.-A. Foujols)  Original code
7   !!            4.0  ! 1991-11  (G. Madec)
8   !!                 ! 1992-06  (M. Imbard)  correction restart file
9   !!                 ! 1992-07  (M. Imbard)  split into diawri and rstwri
10   !!                 ! 1993-03  (M. Imbard)  suppress writibm
11   !!                 ! 1998-01  (C. Levy)  NETCDF format using ioipsl INTERFACE
12   !!                 ! 1999-02  (E. Guilyardi)  name of netCDF files + variables
13   !!            8.2  ! 2000-06  (M. Imbard)  Original code (diabort.F)
14   !!   NEMO     1.0  ! 2002-06  (A.Bozec, E. Durand)  Original code (diainit.F)
15   !!             -   ! 2002-09  (G. Madec)  F90: Free form and module
16   !!             -   ! 2002-12  (G. Madec)  merge of diabort and diainit, F90
17   !!                 ! 2005-11  (V. Garnier) Surface pressure gradient organization
18   !!            3.2  ! 2008-11  (B. Lemaire) creation from old diawri
19   !!----------------------------------------------------------------------
20
21   !!----------------------------------------------------------------------
22   !!   dia_wri       : create the standart output files
23   !!   dia_wri_state : create an output NetCDF file for a single instantaeous ocean state and forcing fields
24   !!----------------------------------------------------------------------
25   USE oce             ! ocean dynamics and tracers
26   USE dom_oce         ! ocean space and time domain
27   USE dynadv, ONLY: ln_dynadv_vec
28   USE zdf_oce         ! ocean vertical physics
29   USE ldftra_oce      ! ocean active tracers: lateral physics
30   USE ldfdyn_oce      ! ocean dynamics: lateral physics
31   USE traldf_iso_grif, ONLY : psix_eiv, psiy_eiv
32   USE sol_oce         ! solver variables
33   USE sbc_oce         ! Surface boundary condition: ocean fields
34   USE sbc_ice         ! Surface boundary condition: ice fields
35   USE icb_oce         ! Icebergs
36   USE icbdia          ! Iceberg budgets
37   USE sbcssr          ! restoring term toward SST/SSS climatology
38   USE phycst          ! physical constants
39   USE zdfmxl          ! mixed layer
40   USE dianam          ! build name of file (routine)
41   USE zdfddm          ! vertical  physics: double diffusion
42   USE diahth          ! thermocline diagnostics
43   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
44   USE in_out_manager  ! I/O manager
45   USE diadimg         ! dimg direct access file format output
46   USE iom
47   USE ioipsl
48   USE dynspg_oce, ONLY: un_adv, vn_adv ! barotropic velocities     
49
50#if defined key_lim2
51   USE limwri_2 
52#elif defined key_lim3
53   USE limwri 
54#endif
55   USE lib_mpp         ! MPP library
56   USE timing          ! preformance summary
57   USE wrk_nemo        ! working array
58
59   IMPLICIT NONE
60   PRIVATE
61
62   PUBLIC   dia_wri                 ! routines called by step.F90
63   PUBLIC   dia_wri_state
64   PUBLIC   dia_wri_alloc           ! Called by nemogcm module
65
66   INTEGER ::   nid_T, nz_T, nh_T, ndim_T, ndim_hT   ! grid_T file
67   INTEGER ::          nb_T              , ndim_bT   ! grid_T file
68   INTEGER ::   nid_U, nz_U, nh_U, ndim_U, ndim_hU   ! grid_U file
69   INTEGER ::   nid_V, nz_V, nh_V, ndim_V, ndim_hV   ! grid_V file
70   INTEGER ::   nid_W, nz_W, nh_W                    ! grid_W file
71   INTEGER ::   ndex(1)                              ! ???
72   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_hT, ndex_hU, ndex_hV
73   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_T, ndex_U, ndex_V
74   INTEGER, SAVE, ALLOCATABLE, DIMENSION(:) :: ndex_bT
75
76   !! * Substitutions
77#  include "zdfddm_substitute.h90"
78#  include "domzgr_substitute.h90"
79#  include "vectopt_loop_substitute.h90"
80   !!----------------------------------------------------------------------
81   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
82   !! $Id$
83   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
84   !!----------------------------------------------------------------------
85CONTAINS
86
87   INTEGER FUNCTION dia_wri_alloc()
88      !!----------------------------------------------------------------------
89      INTEGER, DIMENSION(2) :: ierr
90      !!----------------------------------------------------------------------
91      ierr = 0
92      ALLOCATE( ndex_hT(jpi*jpj) , ndex_T(jpi*jpj*jpk) ,     &
93         &      ndex_hU(jpi*jpj) , ndex_U(jpi*jpj*jpk) ,     &
94         &      ndex_hV(jpi*jpj) , ndex_V(jpi*jpj*jpk) , STAT=ierr(1) )
95         !
96      dia_wri_alloc = MAXVAL(ierr)
97      IF( lk_mpp )   CALL mpp_sum( dia_wri_alloc )
98      !
99  END FUNCTION dia_wri_alloc
100
101#if defined key_dimgout
102   !!----------------------------------------------------------------------
103   !!   'key_dimgout'                                      DIMG output file
104   !!----------------------------------------------------------------------
105#   include "diawri_dimg.h90"
106
107#else
108   !!----------------------------------------------------------------------
109   !!   Default option                                   NetCDF output file
110   !!----------------------------------------------------------------------
111# if defined key_iomput
112   !!----------------------------------------------------------------------
113   !!   'key_iomput'                                        use IOM library
114   !!----------------------------------------------------------------------
115
116   SUBROUTINE dia_wri( kt )
117      !!---------------------------------------------------------------------
118      !!                  ***  ROUTINE dia_wri  ***
119      !!                   
120      !! ** Purpose :   Standard output of opa: dynamics and tracer fields
121      !!      NETCDF format is used by default
122      !!
123      !! ** Method  :  use iom_put
124      !!----------------------------------------------------------------------
125      !!
126      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
127      !!
128      INTEGER                      ::   ji, jj, jk              ! dummy loop indices
129      INTEGER                      ::   jkbot                   !
130      REAL(wp)                     ::   zztmp, zztmpx, zztmpy   !
131      !!
132      REAL(wp), POINTER, DIMENSION(:,:)   :: z2d      ! 2D workspace
133      REAL(wp), POINTER, DIMENSION(:,:,:) :: z3d      ! 3D workspace
134      !!----------------------------------------------------------------------
135      !
136      IF( nn_timing == 1 )   CALL timing_start('dia_wri')
137      !
138      CALL wrk_alloc( jpi , jpj      , z2d )
139      CALL wrk_alloc( jpi , jpj, jpk , z3d )
140      !
141      ! Output the initial state and forcings
142      IF( ninist == 1 ) THEN                       
143         CALL dia_wri_state( 'output.init', kt )
144         ninist = 0
145      ENDIF
146
147      ! Output of initial vertical scale factor
148      CALL iom_put("e3t_0", e3t_0(:,:,:) )
149      CALL iom_put("e3u_0", e3t_0(:,:,:) )
150      CALL iom_put("e3v_0", e3t_0(:,:,:) )
151      !
152      CALL iom_put( "e3t" , fse3t_n(:,:,:) )
153      CALL iom_put( "e3u" , fse3u_n(:,:,:) )
154      CALL iom_put( "e3v" , fse3v_n(:,:,:) )
155      CALL iom_put( "e3w" , fse3w_n(:,:,:) )
156      IF( iom_use("e3tdef") )   &
157         CALL iom_put( "e3tdef"  , ( ( fse3t_n(:,:,:) - e3t_0(:,:,:) ) / e3t_0(:,:,:) * 100 * tmask(:,:,:) ) ** 2 )
158      CALL iom_put("tpt_dep", fsdept_n(:,:,:) )
159      IF( iom_use("gdepwt") )  THEN
160#if defined key_vvl
161         z3d(:,:,1) = (fsdepw(:,:,1)-sshn(:,:))*tmask(:,:,1)
162         DO jk=2,jpk
163            z3d(:,:,jk) = (fsdepw(:,:,jk)-sshn(:,:))*tmask(:,:,jk-1)
164         END DO
165#else
166         z3d(:,:,1) = 0._wp
167         DO jk=2,jpk
168            z3d(:,:,jk) = fsdepw(:,:,jk)*tmask(:,:,jk-1)
169         END DO
170#endif
171         CALL iom_put("gdepwt" , z3d(:,:,:) )
172      END IF
173
174      IF( iom_use("gdepwu") )  THEN
175         z2d(:,:) = 0._wp
176         DO jj = 1, jpjm1
177            DO ji = 1, fs_jpim1   ! vector opt.
178               z2d(ji,jj) = 0.5_wp * umask(ji,jj,1) * r1_e12u(ji,jj)                             &
179                        &          * ( e12t(ji,jj) * sshn(ji,jj) + e12t(ji+1,jj) * sshn(ji+1,jj) )
180            END DO
181         END DO
182         CALL lbc_lnk( z2d(:,:), 'U', 1._wp )
183
184         z3d(:,:,1)=0._wp
185         DO jk=2,jpk
186            z3d(:,:,jk) = z3d(:,:,jk-1) + fse3u_n(:,:,jk-1) * umask(:,:,jk-1)
187         END DO
188
189         z3d(:,:,1) = (z3d(:,:,1)-z2d(:,:))*umask(:,:,1)
190         DO jk=2,jpk
191            z3d(:,:,jk) = (z3d(:,:,jk)-z2d(:,:))*umask(:,:,jk-1)
192         END DO
193         CALL iom_put("gdepwu" , z3d(:,:,:) )
194      END IF
195
196      IF( iom_use("gdepwv") )  THEN
197         z2d(:,:) = 0._wp
198         DO jj = 1, jpjm1
199            DO ji = 1, fs_jpim1   ! vector opt.
200               z2d(ji,jj) = 0.5_wp * vmask(ji,jj,1) * r1_e12v(ji,jj)                             &
201                        &          * ( e12t(ji,jj) * sshn(ji,jj) + e12t(ji,jj+1) * sshn(ji,jj+1) )
202            END DO
203         END DO
204         CALL lbc_lnk( z2d(:,:), 'V', 1._wp )
205
206         z3d(:,:,1)=0._wp
207         DO jk=2,jpk
208            z3d(:,:,jk) = z3d(:,:,jk-1) + fse3v_n(:,:,jk-1) * vmask(:,:,jk-1)
209         END DO
210
211         z3d(:,:,1) = (z3d(:,:,1)-z2d(:,:))*vmask(:,:,1)
212         DO jk=2,jpk
213            z3d(:,:,jk) = (z3d(:,:,jk)-z2d(:,:))*vmask(:,:,jk-1)
214         END DO
215         CALL iom_put("gdepwv" , z3d(:,:,:) )
216      END IF
217
218      CALL iom_put( "ssh" , sshn )                 ! sea surface height
219     
220      CALL iom_put( "toce", tsn(:,:,:,jp_tem) )    ! 3D temperature
221      CALL iom_put(  "sst", tsn(:,:,1,jp_tem) )    ! surface temperature
222      IF ( iom_use("sbt") ) THEN
223         DO jj = 1, jpj
224            DO ji = 1, jpi
225               jkbot = mbkt(ji,jj)
226               z2d(ji,jj) = tsn(ji,jj,jkbot,jp_tem)
227            END DO
228         END DO
229         CALL iom_put( "sbt", z2d )                ! bottom temperature
230      ENDIF
231     
232      CALL iom_put( "soce", tsn(:,:,:,jp_sal) )    ! 3D salinity
233      CALL iom_put(  "sss", tsn(:,:,1,jp_sal) )    ! surface salinity
234      IF ( iom_use("sbs") ) THEN
235         DO jj = 1, jpj
236            DO ji = 1, jpi
237               jkbot = mbkt(ji,jj)
238               z2d(ji,jj) = tsn(ji,jj,jkbot,jp_sal)
239            END DO
240         END DO
241         CALL iom_put( "sbs", z2d )                ! bottom salinity
242      ENDIF
243
244      IF ( iom_use("taubot") ) THEN                ! bottom stress
245         z2d(:,:) = 0._wp
246         DO jj = 2, jpjm1
247            DO ji = fs_2, fs_jpim1   ! vector opt.
248               zztmpx = (  bfrua(ji  ,jj) * un(ji  ,jj,mbku(ji  ,jj))  &
249                      &  + bfrua(ji-1,jj) * un(ji-1,jj,mbku(ji-1,jj))  )     
250               zztmpy = (  bfrva(ji,  jj) * vn(ji,jj  ,mbkv(ji,jj  ))  &
251                      &  + bfrva(ji,jj-1) * vn(ji,jj-1,mbkv(ji,jj-1))  ) 
252               z2d(ji,jj) = rau0 * SQRT( zztmpx * zztmpx + zztmpy * zztmpy ) * tmask(ji,jj,1) 
253               !
254            ENDDO
255         ENDDO
256         CALL lbc_lnk( z2d, 'T', 1. )
257         CALL iom_put( "taubot", z2d )           
258      ENDIF
259         
260      CALL iom_put( "uoce", un(:,:,:)         )    ! 3D i-current
261      CALL iom_put(  "ssu", un(:,:,1)         )    ! surface i-current
262      IF ( iom_use("sbu") ) THEN
263         DO jj = 1, jpj
264            DO ji = 1, jpi
265               jkbot = mbku(ji,jj)
266               z2d(ji,jj) = un(ji,jj,jkbot)
267            END DO
268         END DO
269         CALL iom_put( "sbu", z2d )                ! bottom i-current
270      ENDIF
271#if defined key_dynspg_ts
272      CALL iom_put(  "ubar", un_adv(:,:)      )    ! barotropic i-current
273#else
274      CALL iom_put(  "ubar", un_b(:,:)        )    ! barotropic i-current
275#endif
276     
277      CALL iom_put( "voce", vn(:,:,:)         )    ! 3D j-current
278      CALL iom_put(  "ssv", vn(:,:,1)         )    ! surface j-current
279      IF ( iom_use("sbv") ) THEN
280         DO jj = 1, jpj
281            DO ji = 1, jpi
282               jkbot = mbkv(ji,jj)
283               z2d(ji,jj) = vn(ji,jj,jkbot)
284            END DO
285         END DO
286         CALL iom_put( "sbv", z2d )                ! bottom j-current
287      ENDIF
288#if defined key_dynspg_ts
289      CALL iom_put(  "vbar", vn_adv(:,:)      )    ! barotropic j-current
290#else
291      CALL iom_put(  "vbar", vn_b(:,:)        )    ! barotropic j-current
292#endif
293
294      CALL iom_put( "woce", wn )                   ! vertical velocity
295      IF( iom_use('w_masstr') .OR. iom_use('w_masstr2') ) THEN   ! vertical mass transport & its square value
296         ! Caution: in the VVL case, it only correponds to the baroclinic mass transport.
297         z2d(:,:) = rau0 * e12t(:,:)
298         DO jk = 1, jpk
299            z3d(:,:,jk) = wn(:,:,jk) * z2d(:,:)
300         END DO
301         CALL iom_put( "w_masstr" , z3d ) 
302         IF( iom_use('w_masstr2') )   CALL iom_put( "w_masstr2", z3d(:,:,:) * z3d(:,:,:) )
303      ENDIF
304
305      CALL iom_put( "avt" , avt                        )    ! T vert. eddy diff. coef.
306      CALL iom_put( "avm" , avmu                       )    ! T vert. eddy visc. coef.
307      CALL iom_put( "avs" , fsavs(:,:,:)               )    ! S vert. eddy diff. coef. (useful only with key_zdfddm)
308                                                            ! Log of eddy diff coef
309      IF( iom_use('logavt') )   CALL iom_put( "logavt", LOG( MAX( 1.e-20_wp, avt  (:,:,:) ) ) )
310      IF( iom_use('logavs') )   CALL iom_put( "logavs", LOG( MAX( 1.e-20_wp, fsavs(:,:,:) ) ) )
311
312      IF ( iom_use("sstgrad") .OR. iom_use("sstgrad2") ) THEN
313         DO jj = 2, jpjm1                                    ! sst gradient
314            DO ji = fs_2, fs_jpim1   ! vector opt.
315               zztmp      = tsn(ji,jj,1,jp_tem)
316               zztmpx     = ( tsn(ji+1,jj  ,1,jp_tem) - zztmp ) / e1u(ji,jj) + ( zztmp - tsn(ji-1,jj  ,1,jp_tem) ) / e1u(ji-1,jj  )
317               zztmpy     = ( tsn(ji  ,jj+1,1,jp_tem) - zztmp ) / e2v(ji,jj) + ( zztmp - tsn(ji  ,jj-1,1,jp_tem) ) / e2v(ji  ,jj-1)
318               z2d(ji,jj) = 0.25 * ( zztmpx * zztmpx + zztmpy * zztmpy )   &
319                  &              * umask(ji,jj,1) * umask(ji-1,jj,1) * vmask(ji,jj,1) * umask(ji,jj-1,1)
320            END DO
321         END DO
322         CALL lbc_lnk( z2d, 'T', 1. )
323         CALL iom_put( "sstgrad2",  z2d               )    ! square of module of sst gradient
324         z2d(:,:) = SQRT( z2d(:,:) )
325         CALL iom_put( "sstgrad" ,  z2d               )    ! module of sst gradient
326      ENDIF
327         
328      ! clem: heat and salt content
329      IF( iom_use("heatc") ) THEN
330         z2d(:,:)  = 0._wp 
331         DO jk = 1, jpkm1
332            DO jj = 1, jpj
333               DO ji = 1, jpi
334                  z2d(ji,jj) = z2d(ji,jj) + fse3t(ji,jj,jk) * tsn(ji,jj,jk,jp_tem) * tmask(ji,jj,jk)
335               END DO
336            END DO
337         END DO
338         CALL iom_put( "heatc", (rau0 * rcp) * z2d )    ! vertically integrated heat content (J/m2)
339      ENDIF
340
341      IF( iom_use("saltc") ) THEN
342         z2d(:,:)  = 0._wp 
343         DO jk = 1, jpkm1
344            DO jj = 1, jpj
345               DO ji = 1, jpi
346                  z2d(ji,jj) = z2d(ji,jj) + fse3t(ji,jj,jk) * tsn(ji,jj,jk,jp_sal) * tmask(ji,jj,jk)
347               END DO
348            END DO
349         END DO
350         CALL iom_put( "saltc", rau0 * z2d )   ! vertically integrated salt content (PSU*kg/m2)
351      ENDIF
352      !
353      IF ( iom_use("eken") ) THEN
354         rke(:,:,jpk) = 0._wp                               !      kinetic energy
355         DO jk = 1, jpkm1
356            DO jj = 2, jpjm1
357               DO ji = fs_2, fs_jpim1   ! vector opt.
358                  zztmp   =  1 / (e1e2t(ji,jj) * fse3t(ji,jj,jk))
359                  zztmpx  = 0.5 * (  un(ji-1,jj,jk) * un(ji-1,jj,jk) * e1u(ji-1,jj) * e2u(ji-1,jj) * fse3u(ji-1,jj,jk)    &
360                     &             + un(ji  ,jj,jk) * un(ji  ,jj,jk) * e1u(ji,  jj) * e2u(ji  ,jj) * fse3u(ji  ,jj,jk) )  &
361                     &          *  zztmp 
362                  !
363                  zztmpy  = 0.5 * (  vn(ji,jj-1,jk) * vn(ji,jj-1,jk) * e1v(ji,jj-1) * e2v(ji,jj-1) * fse3v(ji,jj-1,jk)    &
364                     &             + vn(ji,jj  ,jk) * vn(ji,jj  ,jk) * e1v(ji,jj  ) * e2v(ji,jj  ) * fse3v(ji,jj  ,jk) )  &
365                     &          *  zztmp 
366                  !
367                  rke(ji,jj,jk) = 0.5_wp * ( zztmpx + zztmpy )
368                  !
369               ENDDO
370            ENDDO
371         ENDDO
372         CALL lbc_lnk( rke, 'T', 1. )
373         CALL iom_put( "eken", rke )           
374      ENDIF
375      !
376      CALL iom_put( "hdiv", hdivn )                  ! Horizontal divergence
377      !
378      IF( iom_use("u_masstr") .OR. iom_use("u_masstr_vint") .OR. iom_use("u_heattr") .OR. iom_use("u_salttr") ) THEN
379         z3d(:,:,jpk) = 0.e0
380         z2d(:,:) = 0.e0
381         DO jk = 1, jpkm1
382            z3d(:,:,jk) = rau0 * un(:,:,jk) * e2u(:,:) * fse3u(:,:,jk) * umask(:,:,jk)
383            z2d(:,:) = z2d(:,:) + z3d(:,:,jk)
384         END DO
385         CALL iom_put( "u_masstr", z3d )                  ! mass transport in i-direction
386         CALL iom_put( "u_masstr_vint", z2d )             ! mass transport in i-direction vertical sum
387      ENDIF
388     
389      IF( iom_use("u_heattr") ) THEN
390         z2d(:,:) = 0.e0 
391         DO jk = 1, jpkm1
392            DO jj = 2, jpjm1
393               DO ji = fs_2, fs_jpim1   ! vector opt.
394                  z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * ( tsn(ji,jj,jk,jp_tem) + tsn(ji+1,jj,jk,jp_tem) )
395               END DO
396            END DO
397         END DO
398         CALL lbc_lnk( z2d, 'U', -1. )
399         CALL iom_put( "u_heattr", (0.5 * rcp) * z2d )    ! heat transport in i-direction
400      ENDIF
401
402      IF( iom_use("u_salttr") ) THEN
403         z2d(:,:) = 0.e0 
404         DO jk = 1, jpkm1
405            DO jj = 2, jpjm1
406               DO ji = fs_2, fs_jpim1   ! vector opt.
407                  z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * ( tsn(ji,jj,jk,jp_sal) + tsn(ji+1,jj,jk,jp_sal) )
408               END DO
409            END DO
410         END DO
411         CALL lbc_lnk( z2d, 'U', -1. )
412         CALL iom_put( "u_salttr", 0.5 * z2d )            ! heat transport in i-direction
413      ENDIF
414
415     
416      IF( iom_use("v_masstr") .OR. iom_use("v_heattr") .OR. iom_use("v_salttr") ) THEN
417         z3d(:,:,jpk) = 0.e0
418         DO jk = 1, jpkm1
419            z3d(:,:,jk) = rau0 * vn(:,:,jk) * e1v(:,:) * fse3v(:,:,jk) * vmask(:,:,jk)
420         END DO
421         CALL iom_put( "v_masstr", z3d )                  ! mass transport in j-direction
422      ENDIF
423     
424      IF( iom_use("v_heattr") ) THEN
425         z2d(:,:) = 0.e0 
426         DO jk = 1, jpkm1
427            DO jj = 2, jpjm1
428               DO ji = fs_2, fs_jpim1   ! vector opt.
429                  z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * ( tsn(ji,jj,jk,jp_tem) + tsn(ji,jj+1,jk,jp_tem) )
430               END DO
431            END DO
432         END DO
433         CALL lbc_lnk( z2d, 'V', -1. )
434         CALL iom_put( "v_heattr", (0.5 * rcp) * z2d )    !  heat transport in j-direction
435      ENDIF
436
437      IF( iom_use("v_salttr") ) THEN
438         z2d(:,:) = 0.e0 
439         DO jk = 1, jpkm1
440            DO jj = 2, jpjm1
441               DO ji = fs_2, fs_jpim1   ! vector opt.
442                  z2d(ji,jj) = z2d(ji,jj) + z3d(ji,jj,jk) * ( tsn(ji,jj,jk,jp_sal) + tsn(ji,jj+1,jk,jp_sal) )
443               END DO
444            END DO
445         END DO
446         CALL lbc_lnk( z2d, 'V', -1. )
447         CALL iom_put( "v_salttr", 0.5 * z2d )            !  heat transport in j-direction
448      ENDIF
449
450      ! Vertical integral of temperature
451      IF( iom_use("tosmint") ) THEN
452         z2d(:,:)=0._wp
453         DO jk = 1, jpkm1
454            DO jj = 2, jpjm1
455               DO ji = fs_2, fs_jpim1   ! vector opt.
456                  z2d(ji,jj) = z2d(ji,jj) + rau0 * fse3t(ji,jj,jk) *  tsn(ji,jj,jk,jp_tem)
457               END DO
458            END DO
459         END DO
460         CALL lbc_lnk( z2d, 'T', -1. )
461         CALL iom_put( "tosmint", z2d ) 
462      ENDIF
463
464      ! Vertical integral of salinity
465      IF( iom_use("somint") ) THEN
466         z2d(:,:)=0._wp
467         DO jk = 1, jpkm1
468            DO jj = 2, jpjm1
469               DO ji = fs_2, fs_jpim1   ! vector opt.
470                  z2d(ji,jj) = z2d(ji,jj) + rau0 * fse3t(ji,jj,jk) * tsn(ji,jj,jk,jp_sal)
471               END DO
472            END DO
473         END DO
474         CALL lbc_lnk( z2d, 'T', -1. )
475         CALL iom_put( "somint", z2d ) 
476      ENDIF
477
478      CALL iom_put( "bn2", rn2 )  !Brunt-Vaisala buoyancy frequency (N^2)
479      !
480      CALL wrk_dealloc( jpi , jpj      , z2d )
481      CALL wrk_dealloc( jpi , jpj, jpk , z3d )
482      !
483      IF( nn_timing == 1 )   CALL timing_stop('dia_wri')
484      !
485   END SUBROUTINE dia_wri
486
487#else
488   !!----------------------------------------------------------------------
489   !!   Default option                                  use IOIPSL  library
490   !!----------------------------------------------------------------------
491
492   SUBROUTINE dia_wri( kt )
493      !!---------------------------------------------------------------------
494      !!                  ***  ROUTINE dia_wri  ***
495      !!                   
496      !! ** Purpose :   Standard output of opa: dynamics and tracer fields
497      !!      NETCDF format is used by default
498      !!
499      !! ** Method  :   At the beginning of the first time step (nit000),
500      !!      define all the NETCDF files and fields
501      !!      At each time step call histdef to compute the mean if ncessary
502      !!      Each nwrite time step, output the instantaneous or mean fields
503      !!----------------------------------------------------------------------
504      !!
505      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
506      !!
507      LOGICAL ::   ll_print = .FALSE.                        ! =T print and flush numout
508      CHARACTER (len=40) ::   clhstnam, clop, clmx           ! local names
509      INTEGER  ::   inum = 11                                ! temporary logical unit
510      INTEGER  ::   ji, jj, jk                               ! dummy loop indices
511      INTEGER  ::   ierr                                     ! error code return from allocation
512      INTEGER  ::   iimi, iima, ipk, it, itmod, ijmi, ijma   ! local integers
513      INTEGER  ::   jn, ierror                               ! local integers
514      REAL(wp) ::   zsto, zout, zmax, zjulian, zdt           ! local scalars
515      !!
516      REAL(wp), POINTER, DIMENSION(:,:)   :: zw2d       ! 2D workspace
517      REAL(wp), POINTER, DIMENSION(:,:,:) :: zw3d       ! 3D workspace
518      !!----------------------------------------------------------------------
519      !
520      IF( nn_timing == 1 )   CALL timing_start('dia_wri')
521      !
522      CALL wrk_alloc( jpi , jpj      , zw2d )
523      IF ( ln_traldf_gdia .OR. lk_vvl )  call wrk_alloc( jpi , jpj , jpk  , zw3d )
524      !
525      ! Output the initial state and forcings
526      IF( ninist == 1 ) THEN                       
527         CALL dia_wri_state( 'output.init', kt )
528         ninist = 0
529      ENDIF
530      !
531      ! 0. Initialisation
532      ! -----------------
533
534      ! local variable for debugging
535      ll_print = .FALSE.
536      ll_print = ll_print .AND. lwp
537
538      ! Define frequency of output and means
539      zdt = rdt
540      IF( nacc == 1 ) zdt = rdtmin
541      clop = "x"         ! no use of the mask value (require less cpu time, and otherwise the model crashes)
542#if defined key_diainstant
543      zsto = nwrite * zdt
544      clop = "inst("//TRIM(clop)//")"
545#else
546      zsto=zdt
547      clop = "ave("//TRIM(clop)//")"
548#endif
549      zout = nwrite * zdt
550      zmax = ( nitend - nit000 + 1 ) * zdt
551
552      ! Define indices of the horizontal output zoom and vertical limit storage
553      iimi = 1      ;      iima = jpi
554      ijmi = 1      ;      ijma = jpj
555      ipk = jpk
556
557      ! define time axis
558      it = kt
559      itmod = kt - nit000 + 1
560
561
562      ! 1. Define NETCDF files and fields at beginning of first time step
563      ! -----------------------------------------------------------------
564
565      IF( kt == nit000 ) THEN
566
567         ! Define the NETCDF files (one per grid)
568
569         ! Compute julian date from starting date of the run
570         CALL ymds2ju( nyear, nmonth, nday, rdt, zjulian )
571         zjulian = zjulian - adatrj   !   set calendar origin to the beginning of the experiment
572         IF(lwp)WRITE(numout,*)
573         IF(lwp)WRITE(numout,*) 'Date 0 used :', nit000, ' YEAR ', nyear,   &
574            &                    ' MONTH ', nmonth, ' DAY ', nday, 'Julian day : ', zjulian
575         IF(lwp)WRITE(numout,*) ' indexes of zoom = ', iimi, iima, ijmi, ijma,   &
576                                 ' limit storage in depth = ', ipk
577
578         ! WRITE root name in date.file for use by postpro
579         IF(lwp) THEN
580            CALL dia_nam( clhstnam, nwrite,' ' )
581            CALL ctl_opn( inum, 'date.file', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
582            WRITE(inum,*) clhstnam
583            CLOSE(inum)
584         ENDIF
585
586         ! Define the T grid FILE ( nid_T )
587
588         CALL dia_nam( clhstnam, nwrite, 'grid_T' )
589         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
590         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
591            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
592            &          nit000-1, zjulian, zdt, nh_T, nid_T, domain_id=nidom, snc4chunks=snc4set )
593         CALL histvert( nid_T, "deptht", "Vertical T levels",      &  ! Vertical grid: gdept
594            &           "m", ipk, gdept_1d, nz_T, "down" )
595         !                                                            ! Index of ocean points
596         CALL wheneq( jpi*jpj*ipk, tmask, 1, 1., ndex_T , ndim_T  )      ! volume
597         CALL wheneq( jpi*jpj    , tmask, 1, 1., ndex_hT, ndim_hT )      ! surface
598         !
599         IF( ln_icebergs ) THEN
600            !
601            !! allocation cant go in dia_wri_alloc because ln_icebergs is only set after
602            !! that routine is called from nemogcm, so do it here immediately before its needed
603            ALLOCATE( ndex_bT(jpi*jpj*nclasses), STAT=ierror )
604            IF( lk_mpp )   CALL mpp_sum( ierror )
605            IF( ierror /= 0 ) THEN
606               CALL ctl_stop('dia_wri: failed to allocate iceberg diagnostic array')
607               RETURN
608            ENDIF
609            !
610            !! iceberg vertical coordinate is class number
611            CALL histvert( nid_T, "class", "Iceberg class",      &  ! Vertical grid: class
612               &           "number", nclasses, class_num, nb_T )
613            !
614            !! each class just needs the surface index pattern
615            ndim_bT = 3
616            DO jn = 1,nclasses
617               ndex_bT((jn-1)*jpi*jpj+1:jn*jpi*jpj) = ndex_hT(1:jpi*jpj)
618            ENDDO
619            !
620         ENDIF
621
622         ! Define the U grid FILE ( nid_U )
623
624         CALL dia_nam( clhstnam, nwrite, 'grid_U' )
625         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam    ! filename
626         CALL histbeg( clhstnam, jpi, glamu, jpj, gphiu,           &  ! Horizontal grid: glamu and gphiu
627            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
628            &          nit000-1, zjulian, zdt, nh_U, nid_U, domain_id=nidom, snc4chunks=snc4set )
629         CALL histvert( nid_U, "depthu", "Vertical U levels",      &  ! Vertical grid: gdept
630            &           "m", ipk, gdept_1d, nz_U, "down" )
631         !                                                            ! Index of ocean points
632         CALL wheneq( jpi*jpj*ipk, umask, 1, 1., ndex_U , ndim_U  )      ! volume
633         CALL wheneq( jpi*jpj    , umask, 1, 1., ndex_hU, ndim_hU )      ! surface
634
635         ! Define the V grid FILE ( nid_V )
636
637         CALL dia_nam( clhstnam, nwrite, 'grid_V' )                   ! filename
638         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
639         CALL histbeg( clhstnam, jpi, glamv, jpj, gphiv,           &  ! Horizontal grid: glamv and gphiv
640            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
641            &          nit000-1, zjulian, zdt, nh_V, nid_V, domain_id=nidom, snc4chunks=snc4set )
642         CALL histvert( nid_V, "depthv", "Vertical V levels",      &  ! Vertical grid : gdept
643            &          "m", ipk, gdept_1d, nz_V, "down" )
644         !                                                            ! Index of ocean points
645         CALL wheneq( jpi*jpj*ipk, vmask, 1, 1., ndex_V , ndim_V  )      ! volume
646         CALL wheneq( jpi*jpj    , vmask, 1, 1., ndex_hV, ndim_hV )      ! surface
647
648         ! Define the W grid FILE ( nid_W )
649
650         CALL dia_nam( clhstnam, nwrite, 'grid_W' )                   ! filename
651         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
652         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,           &  ! Horizontal grid: glamt and gphit
653            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,       &
654            &          nit000-1, zjulian, zdt, nh_W, nid_W, domain_id=nidom, snc4chunks=snc4set )
655         CALL histvert( nid_W, "depthw", "Vertical W levels",      &  ! Vertical grid: gdepw
656            &          "m", ipk, gdepw_1d, nz_W, "down" )
657
658
659         ! Declare all the output fields as NETCDF variables
660
661         !                                                                                      !!! nid_T : 3D
662         CALL histdef( nid_T, "votemper", "Temperature"                        , "C"      ,   &  ! tn
663            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
664         CALL histdef( nid_T, "vosaline", "Salinity"                           , "PSU"    ,   &  ! sn
665            &          jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
666         IF(  lk_vvl  ) THEN
667            CALL histdef( nid_T, "vovvle3t", "Level thickness"                    , "m"      ,&  ! e3t_n
668            &             jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
669            CALL histdef( nid_T, "vovvldep", "T point depth"                      , "m"      ,&  ! e3t_n
670            &             jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
671            CALL histdef( nid_T, "vovvldef", "Squared level deformation"          , "%^2"    ,&  ! e3t_n
672            &             jpi, jpj, nh_T, ipk, 1, ipk, nz_T, 32, clop, zsto, zout )
673         ENDIF
674         !                                                                                      !!! nid_T : 2D
675         CALL histdef( nid_T, "sosstsst", "Sea Surface temperature"            , "C"      ,   &  ! sst
676            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
677         CALL histdef( nid_T, "sosaline", "Sea Surface Salinity"               , "PSU"    ,   &  ! sss
678            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
679         CALL histdef( nid_T, "sossheig", "Sea Surface Height"                 , "m"      ,   &  ! ssh
680            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
681         CALL histdef( nid_T, "sowaflup", "Net Upward Water Flux"              , "Kg/m2/s",   &  ! (emp-rnf)
682            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
683         CALL histdef( nid_T, "sorunoff", "River runoffs"                      , "Kg/m2/s",   &  ! runoffs
684            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
685         CALL histdef( nid_T, "sosfldow", "downward salt flux"                 , "PSU/m2/s",  &  ! sfx
686            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
687         IF(  .NOT. lk_vvl  ) THEN
688            CALL histdef( nid_T, "sosst_cd", "Concentration/Dilution term on temperature"     &  ! emp * tsn(:,:,1,jp_tem)
689            &                                                                  , "KgC/m2/s",  &  ! sosst_cd
690            &             jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
691            CALL histdef( nid_T, "sosss_cd", "Concentration/Dilution term on salinity"        &  ! emp * tsn(:,:,1,jp_sal)
692            &                                                                  , "KgPSU/m2/s",&  ! sosss_cd
693            &             jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
694         ENDIF
695         CALL histdef( nid_T, "sohefldo", "Net Downward Heat Flux"             , "W/m2"   ,   &  ! qns + qsr
696            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
697         CALL histdef( nid_T, "soshfldo", "Shortwave Radiation"                , "W/m2"   ,   &  ! qsr
698            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
699         CALL histdef( nid_T, "somixhgt", "Turbocline Depth"                   , "m"      ,   &  ! hmld
700            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
701         CALL histdef( nid_T, "somxl010", "Mixed Layer Depth 0.01"             , "m"      ,   &  ! hmlp
702            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
703         CALL histdef( nid_T, "soicecov", "Ice fraction"                       , "[0,1]"  ,   &  ! fr_i
704            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
705         CALL histdef( nid_T, "sowindsp", "wind speed at 10m"                  , "m/s"    ,   &  ! wndm
706            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
707!
708         IF( ln_icebergs ) THEN
709            CALL histdef( nid_T, "calving"             , "calving mass input"                       , "kg/s"   , &
710               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
711            CALL histdef( nid_T, "calving_heat"        , "calving heat flux"                        , "XXXX"   , &
712               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
713            CALL histdef( nid_T, "berg_floating_melt"  , "Melt rate of icebergs + bits"             , "kg/m2/s", &
714               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
715            CALL histdef( nid_T, "berg_stored_ice"     , "Accumulated ice mass by class"            , "kg"     , &
716               &          jpi, jpj, nh_T, nclasses  , 1, nclasses  , nb_T , 32, clop, zsto, zout )
717            IF( ln_bergdia ) THEN
718               CALL histdef( nid_T, "berg_melt"           , "Melt rate of icebergs"                    , "kg/m2/s", &
719                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
720               CALL histdef( nid_T, "berg_buoy_melt"      , "Buoyancy component of iceberg melt rate"  , "kg/m2/s", &
721                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
722               CALL histdef( nid_T, "berg_eros_melt"      , "Erosion component of iceberg melt rate"   , "kg/m2/s", &
723                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
724               CALL histdef( nid_T, "berg_conv_melt"      , "Convective component of iceberg melt rate", "kg/m2/s", &
725                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
726               CALL histdef( nid_T, "berg_virtual_area"   , "Virtual coverage by icebergs"             , "m2"     , &
727                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
728               CALL histdef( nid_T, "bits_src"           , "Mass source of bergy bits"                , "kg/m2/s", &
729                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
730               CALL histdef( nid_T, "bits_melt"          , "Melt rate of bergy bits"                  , "kg/m2/s", &
731                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
732               CALL histdef( nid_T, "bits_mass"          , "Bergy bit density field"                  , "kg/m2"  , &
733                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
734               CALL histdef( nid_T, "berg_mass"           , "Iceberg density field"                    , "kg/m2"  , &
735                  &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
736               CALL histdef( nid_T, "berg_real_calving"   , "Calving into iceberg class"               , "kg/s"   , &
737                  &          jpi, jpj, nh_T, nclasses  , 1, nclasses  , nb_T , 32, clop, zsto, zout )
738            ENDIF
739         ENDIF
740
741         IF( .NOT. ln_cpl ) THEN
742            CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
743               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
744            CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
745               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
746            CALL histdef( nid_T, "sosafldp", "Surface salt flux: damping"         , "Kg/m2/s",   &  ! erp * sn
747               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
748         ENDIF
749
750         IF( ln_cpl .AND. nn_ice <= 1 ) THEN
751            CALL histdef( nid_T, "sohefldp", "Surface Heat Flux: Damping"         , "W/m2"   ,   &  ! qrp
752               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
753            CALL histdef( nid_T, "sowafldp", "Surface Water Flux: Damping"        , "Kg/m2/s",   &  ! erp
754               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
755            CALL histdef( nid_T, "sosafldp", "Surface salt flux: Damping"         , "Kg/m2/s",   &  ! erp * sn
756               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
757         ENDIF
758         
759         clmx ="l_max(only(x))"    ! max index on a period
760         CALL histdef( nid_T, "sobowlin", "Bowl Index"                         , "W-point",   &  ! bowl INDEX
761            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clmx, zsto, zout )
762#if defined key_diahth
763         CALL histdef( nid_T, "sothedep", "Thermocline Depth"                  , "m"      ,   & ! hth
764            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
765         CALL histdef( nid_T, "so20chgt", "Depth of 20C isotherm"              , "m"      ,   & ! hd20
766            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
767         CALL histdef( nid_T, "so28chgt", "Depth of 28C isotherm"              , "m"      ,   & ! hd28
768            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
769         CALL histdef( nid_T, "sohtc300", "Heat content 300 m"                 , "W"      ,   & ! htc3
770            &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
771#endif
772
773         IF( ln_cpl .AND. nn_ice == 2 ) THEN
774            CALL histdef( nid_T,"soicetem" , "Ice Surface Temperature"            , "K"      ,   &  ! tn_ice
775               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
776            CALL histdef( nid_T,"soicealb" , "Ice Albedo"                         , "[0,1]"  ,   &  ! alb_ice
777               &          jpi, jpj, nh_T, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
778         ENDIF
779
780         CALL histend( nid_T, snc4chunks=snc4set )
781
782         !                                                                                      !!! nid_U : 3D
783         CALL histdef( nid_U, "vozocrtx", "Zonal Current"                      , "m/s"    ,   &  ! un
784            &          jpi, jpj, nh_U, ipk, 1, ipk, nz_U, 32, clop, zsto, zout )
785         IF( ln_traldf_gdia ) THEN
786            CALL histdef( nid_U, "vozoeivu", "Zonal EIV Current"                  , "m/s"    ,   &  ! u_eiv
787                 &          jpi, jpj, nh_U, ipk, 1, ipk, nz_U, 32, clop, zsto, zout )
788         ELSE
789#if defined key_diaeiv
790            CALL histdef( nid_U, "vozoeivu", "Zonal EIV Current"                  , "m/s"    ,   &  ! u_eiv
791            &          jpi, jpj, nh_U, ipk, 1, ipk, nz_U, 32, clop, zsto, zout )
792#endif
793         END IF
794         !                                                                                      !!! nid_U : 2D
795         CALL histdef( nid_U, "sozotaux", "Wind Stress along i-axis"           , "N/m2"   ,   &  ! utau
796            &          jpi, jpj, nh_U, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
797
798         CALL histend( nid_U, snc4chunks=snc4set )
799
800         !                                                                                      !!! nid_V : 3D
801         CALL histdef( nid_V, "vomecrty", "Meridional Current"                 , "m/s"    ,   &  ! vn
802            &          jpi, jpj, nh_V, ipk, 1, ipk, nz_V, 32, clop, zsto, zout )
803         IF( ln_traldf_gdia ) THEN
804            CALL histdef( nid_V, "vomeeivv", "Meridional EIV Current"             , "m/s"    ,   &  ! v_eiv
805                 &          jpi, jpj, nh_V, ipk, 1, ipk, nz_V, 32, clop, zsto, zout )
806         ELSE 
807#if defined key_diaeiv
808            CALL histdef( nid_V, "vomeeivv", "Meridional EIV Current"             , "m/s"    ,   &  ! v_eiv
809            &          jpi, jpj, nh_V, ipk, 1, ipk, nz_V, 32, clop, zsto, zout )
810#endif
811         END IF
812         !                                                                                      !!! nid_V : 2D
813         CALL histdef( nid_V, "sometauy", "Wind Stress along j-axis"           , "N/m2"   ,   &  ! vtau
814            &          jpi, jpj, nh_V, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
815
816         CALL histend( nid_V, snc4chunks=snc4set )
817
818         !                                                                                      !!! nid_W : 3D
819         CALL histdef( nid_W, "vovecrtz", "Vertical Velocity"                  , "m/s"    ,   &  ! wn
820            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
821         IF( ln_traldf_gdia ) THEN
822            CALL histdef( nid_W, "voveeivw", "Vertical EIV Velocity"              , "m/s"    ,   &  ! w_eiv
823                 &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
824         ELSE
825#if defined key_diaeiv
826            CALL histdef( nid_W, "voveeivw", "Vertical EIV Velocity"              , "m/s"    ,   &  ! w_eiv
827                 &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
828#endif
829         END IF
830         CALL histdef( nid_W, "votkeavt", "Vertical Eddy Diffusivity"          , "m2/s"   ,   &  ! avt
831            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
832         CALL histdef( nid_W, "votkeavm", "Vertical Eddy Viscosity"             , "m2/s"  ,   &  ! avmu
833            &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
834
835         IF( lk_zdfddm ) THEN
836            CALL histdef( nid_W,"voddmavs","Salt Vertical Eddy Diffusivity"    , "m2/s"   ,   &  ! avs
837               &          jpi, jpj, nh_W, ipk, 1, ipk, nz_W, 32, clop, zsto, zout )
838         ENDIF
839         !                                                                                      !!! nid_W : 2D
840#if defined key_traldf_c2d
841         CALL histdef( nid_W, "soleahtw", "lateral eddy diffusivity"           , "m2/s"   ,   &  ! ahtw
842            &          jpi, jpj, nh_W, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
843# if defined key_traldf_eiv 
844            CALL histdef( nid_W, "soleaeiw", "eddy induced vel. coeff. at w-point", "m2/s",   &  ! aeiw
845               &       jpi, jpj, nh_W, 1  , 1, 1  , - 99, 32, clop, zsto, zout )
846# endif
847#endif
848
849         CALL histend( nid_W, snc4chunks=snc4set )
850
851         IF(lwp) WRITE(numout,*)
852         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization'
853         IF(ll_print) CALL FLUSH(numout )
854
855      ENDIF
856
857      ! 2. Start writing data
858      ! ---------------------
859
860      ! ndex(1) est utilise ssi l'avant dernier argument est different de
861      ! la taille du tableau en sortie. Dans ce cas , l'avant dernier argument
862      ! donne le nombre d'elements, et ndex la liste des indices a sortir
863
864      IF( lwp .AND. MOD( itmod, nwrite ) == 0 ) THEN
865         WRITE(numout,*) 'dia_wri : write model outputs in NetCDF files at ', kt, 'time-step'
866         WRITE(numout,*) '~~~~~~ '
867      ENDIF
868
869      IF( lk_vvl ) THEN
870         CALL histwrite( nid_T, "votemper", it, tsn(:,:,:,jp_tem) * fse3t_n(:,:,:) , ndim_T , ndex_T  )   ! heat content
871         CALL histwrite( nid_T, "vosaline", it, tsn(:,:,:,jp_sal) * fse3t_n(:,:,:) , ndim_T , ndex_T  )   ! salt content
872         CALL histwrite( nid_T, "sosstsst", it, tsn(:,:,1,jp_tem) * fse3t_n(:,:,1) , ndim_hT, ndex_hT )   ! sea surface heat content
873         CALL histwrite( nid_T, "sosaline", it, tsn(:,:,1,jp_sal) * fse3t_n(:,:,1) , ndim_hT, ndex_hT )   ! sea surface salinity content
874      ELSE
875         CALL histwrite( nid_T, "votemper", it, tsn(:,:,:,jp_tem) , ndim_T , ndex_T  )   ! temperature
876         CALL histwrite( nid_T, "vosaline", it, tsn(:,:,:,jp_sal) , ndim_T , ndex_T  )   ! salinity
877         CALL histwrite( nid_T, "sosstsst", it, tsn(:,:,1,jp_tem) , ndim_hT, ndex_hT )   ! sea surface temperature
878         CALL histwrite( nid_T, "sosaline", it, tsn(:,:,1,jp_sal) , ndim_hT, ndex_hT )   ! sea surface salinity
879      ENDIF
880      IF( lk_vvl ) THEN
881         zw3d(:,:,:) = ( ( fse3t_n(:,:,:) - e3t_0(:,:,:) ) / e3t_0(:,:,:) * 100 * tmask(:,:,:) ) ** 2
882         CALL histwrite( nid_T, "vovvle3t", it, fse3t_n (:,:,:) , ndim_T , ndex_T  )   ! level thickness
883         CALL histwrite( nid_T, "vovvldep", it, fsdept_n(:,:,:) , ndim_T , ndex_T  )   ! t-point depth
884         CALL histwrite( nid_T, "vovvldef", it, zw3d             , ndim_T , ndex_T  )   ! level thickness deformation
885      ENDIF
886      CALL histwrite( nid_T, "sossheig", it, sshn          , ndim_hT, ndex_hT )   ! sea surface height
887      CALL histwrite( nid_T, "sowaflup", it, ( emp-rnf )   , ndim_hT, ndex_hT )   ! upward water flux
888      CALL histwrite( nid_T, "sorunoff", it, rnf           , ndim_hT, ndex_hT )   ! river runoffs
889      CALL histwrite( nid_T, "sosfldow", it, sfx           , ndim_hT, ndex_hT )   ! downward salt flux
890                                                                                  ! (includes virtual salt flux beneath ice
891                                                                                  ! in linear free surface case)
892      IF( .NOT. lk_vvl ) THEN
893         zw2d(:,:) = emp (:,:) * tsn(:,:,1,jp_tem)
894         CALL histwrite( nid_T, "sosst_cd", it, zw2d, ndim_hT, ndex_hT )          ! c/d term on sst
895         zw2d(:,:) = emp (:,:) * tsn(:,:,1,jp_sal)
896         CALL histwrite( nid_T, "sosss_cd", it, zw2d, ndim_hT, ndex_hT )          ! c/d term on sss
897      ENDIF
898      CALL histwrite( nid_T, "sohefldo", it, qns + qsr     , ndim_hT, ndex_hT )   ! total heat flux
899      CALL histwrite( nid_T, "soshfldo", it, qsr           , ndim_hT, ndex_hT )   ! solar heat flux
900      CALL histwrite( nid_T, "somixhgt", it, hmld          , ndim_hT, ndex_hT )   ! turbocline depth
901      CALL histwrite( nid_T, "somxl010", it, hmlp          , ndim_hT, ndex_hT )   ! mixed layer depth
902      CALL histwrite( nid_T, "soicecov", it, fr_i          , ndim_hT, ndex_hT )   ! ice fraction   
903      CALL histwrite( nid_T, "sowindsp", it, wndm          , ndim_hT, ndex_hT )   ! wind speed   
904!
905      IF( ln_icebergs ) THEN
906         !
907         CALL histwrite( nid_T, "calving"             , it, berg_grid%calving      , ndim_hT, ndex_hT ) 
908         CALL histwrite( nid_T, "calving_heat"        , it, berg_grid%calving_hflx , ndim_hT, ndex_hT )         
909         CALL histwrite( nid_T, "berg_floating_melt"  , it, berg_grid%floating_melt, ndim_hT, ndex_hT ) 
910         !
911         CALL histwrite( nid_T, "berg_stored_ice"     , it, berg_grid%stored_ice   , ndim_bT, ndex_bT )
912         !
913         IF( ln_bergdia ) THEN
914            CALL histwrite( nid_T, "berg_melt"           , it, berg_melt        , ndim_hT, ndex_hT   ) 
915            CALL histwrite( nid_T, "berg_buoy_melt"      , it, buoy_melt        , ndim_hT, ndex_hT   ) 
916            CALL histwrite( nid_T, "berg_eros_melt"      , it, eros_melt        , ndim_hT, ndex_hT   ) 
917            CALL histwrite( nid_T, "berg_conv_melt"      , it, conv_melt        , ndim_hT, ndex_hT   ) 
918            CALL histwrite( nid_T, "berg_virtual_area"   , it, virtual_area     , ndim_hT, ndex_hT   ) 
919            CALL histwrite( nid_T, "bits_src"            , it, bits_src         , ndim_hT, ndex_hT   ) 
920            CALL histwrite( nid_T, "bits_melt"           , it, bits_melt        , ndim_hT, ndex_hT   ) 
921            CALL histwrite( nid_T, "bits_mass"           , it, bits_mass        , ndim_hT, ndex_hT   ) 
922            CALL histwrite( nid_T, "berg_mass"           , it, berg_mass        , ndim_hT, ndex_hT   ) 
923            !
924            CALL histwrite( nid_T, "berg_real_calving"   , it, real_calving     , ndim_bT, ndex_bT   )
925         ENDIF
926      ENDIF
927
928      IF( .NOT. ln_cpl ) THEN
929         CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
930         CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
931         IF( ln_ssr ) zw2d(:,:) = erp(:,:) * tsn(:,:,1,jp_sal) * tmask(:,:,1)
932         CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
933      ENDIF
934      IF( ln_cpl .AND. nn_ice <= 1 ) THEN
935         CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping
936         CALL histwrite( nid_T, "sowafldp", it, erp           , ndim_hT, ndex_hT )   ! freshwater flux damping
937         IF( ln_ssr ) zw2d(:,:) = erp(:,:) * tsn(:,:,1,jp_sal) * tmask(:,:,1)
938         CALL histwrite( nid_T, "sosafldp", it, zw2d          , ndim_hT, ndex_hT )   ! salt flux damping
939      ENDIF
940!      zw2d(:,:) = FLOAT( nmln(:,:) ) * tmask(:,:,1)
941!      CALL histwrite( nid_T, "sobowlin", it, zw2d          , ndim_hT, ndex_hT )   ! ???
942
943#if defined key_diahth
944      CALL histwrite( nid_T, "sothedep", it, hth           , ndim_hT, ndex_hT )   ! depth of the thermocline
945      CALL histwrite( nid_T, "so20chgt", it, hd20          , ndim_hT, ndex_hT )   ! depth of the 20 isotherm
946      CALL histwrite( nid_T, "so28chgt", it, hd28          , ndim_hT, ndex_hT )   ! depth of the 28 isotherm
947      CALL histwrite( nid_T, "sohtc300", it, htc3          , ndim_hT, ndex_hT )   ! first 300m heaat content
948#endif
949
950      IF( ln_cpl .AND. nn_ice == 2 ) THEN
951         CALL histwrite( nid_T, "soicetem", it, tn_ice(:,:,1) , ndim_hT, ndex_hT )   ! surf. ice temperature
952         CALL histwrite( nid_T, "soicealb", it, alb_ice(:,:,1), ndim_hT, ndex_hT )   ! ice albedo
953      ENDIF
954
955      CALL histwrite( nid_U, "vozocrtx", it, un            , ndim_U , ndex_U )    ! i-current
956      IF( ln_traldf_gdia ) THEN
957         IF (.not. ALLOCATED(psix_eiv))THEN
958            ALLOCATE( psix_eiv(jpi,jpj,jpk) , psiy_eiv(jpi,jpj,jpk) , STAT=ierr )
959            IF( lk_mpp   )   CALL mpp_sum ( ierr )
960            IF( ierr > 0 )   CALL ctl_stop('STOP', 'diawri: unable to allocate psi{x,y}_eiv')
961            psix_eiv(:,:,:) = 0.0_wp
962            psiy_eiv(:,:,:) = 0.0_wp
963         ENDIF
964         DO jk=1,jpkm1
965            zw3d(:,:,jk) = (psix_eiv(:,:,jk+1) - psix_eiv(:,:,jk))/fse3u(:,:,jk)  ! u_eiv = -dpsix/dz
966         END DO
967         zw3d(:,:,jpk) = 0._wp
968         CALL histwrite( nid_U, "vozoeivu", it, zw3d, ndim_U , ndex_U )           ! i-eiv current
969      ELSE
970#if defined key_diaeiv
971         CALL histwrite( nid_U, "vozoeivu", it, u_eiv, ndim_U , ndex_U )          ! i-eiv current
972#endif
973      ENDIF
974      CALL histwrite( nid_U, "sozotaux", it, utau          , ndim_hU, ndex_hU )   ! i-wind stress
975
976      CALL histwrite( nid_V, "vomecrty", it, vn            , ndim_V , ndex_V  )   ! j-current
977      IF( ln_traldf_gdia ) THEN
978         DO jk=1,jpk-1
979            zw3d(:,:,jk) = (psiy_eiv(:,:,jk+1) - psiy_eiv(:,:,jk))/fse3v(:,:,jk)  ! v_eiv = -dpsiy/dz
980         END DO
981         zw3d(:,:,jpk) = 0._wp
982         CALL histwrite( nid_V, "vomeeivv", it, zw3d, ndim_V , ndex_V )           ! j-eiv current
983      ELSE
984#if defined key_diaeiv
985         CALL histwrite( nid_V, "vomeeivv", it, v_eiv, ndim_V , ndex_V )          ! j-eiv current
986#endif
987      ENDIF
988      CALL histwrite( nid_V, "sometauy", it, vtau          , ndim_hV, ndex_hV )   ! j-wind stress
989
990      CALL histwrite( nid_W, "vovecrtz", it, wn             , ndim_T, ndex_T )    ! vert. current
991      IF( ln_traldf_gdia ) THEN
992         DO jk=1,jpk-1
993            DO jj = 2, jpjm1
994               DO ji = fs_2, fs_jpim1  ! vector opt.
995                  zw3d(ji,jj,jk) = (psiy_eiv(ji,jj,jk) - psiy_eiv(ji,jj-1,jk))/e2v(ji,jj) + &
996                       &    (psix_eiv(ji,jj,jk) - psix_eiv(ji-1,jj,jk))/e1u(ji,jj) ! w_eiv = dpsiy/dy + dpsiy/dx
997               END DO
998            END DO
999         END DO
1000         zw3d(:,:,jpk) = 0._wp
1001         CALL histwrite( nid_W, "voveeivw", it, zw3d          , ndim_T, ndex_T )    ! vert. eiv current
1002      ELSE
1003#   if defined key_diaeiv
1004         CALL histwrite( nid_W, "voveeivw", it, w_eiv          , ndim_T, ndex_T )    ! vert. eiv current
1005#   endif
1006      ENDIF
1007      CALL histwrite( nid_W, "votkeavt", it, avt            , ndim_T, ndex_T )    ! T vert. eddy diff. coef.
1008      CALL histwrite( nid_W, "votkeavm", it, avmu           , ndim_T, ndex_T )    ! T vert. eddy visc. coef.
1009      IF( lk_zdfddm ) THEN
1010         CALL histwrite( nid_W, "voddmavs", it, fsavs(:,:,:), ndim_T, ndex_T )    ! S vert. eddy diff. coef.
1011      ENDIF
1012#if defined key_traldf_c2d
1013      CALL histwrite( nid_W, "soleahtw", it, ahtw          , ndim_hT, ndex_hT )   ! lateral eddy diff. coef.
1014# if defined key_traldf_eiv
1015         CALL histwrite( nid_W, "soleaeiw", it, aeiw       , ndim_hT, ndex_hT )   ! EIV coefficient at w-point
1016# endif
1017#endif
1018
1019      ! 3. Close all files
1020      ! ---------------------------------------
1021      IF( kt == nitend ) THEN
1022         CALL histclo( nid_T )
1023         CALL histclo( nid_U )
1024         CALL histclo( nid_V )
1025         CALL histclo( nid_W )
1026      ENDIF
1027      !
1028      CALL wrk_dealloc( jpi , jpj      , zw2d )
1029      IF ( ln_traldf_gdia .OR. lk_vvl )  call wrk_dealloc( jpi , jpj , jpk  , zw3d )
1030      !
1031      IF( nn_timing == 1 )   CALL timing_stop('dia_wri')
1032      !
1033   END SUBROUTINE dia_wri
1034# endif
1035
1036#endif
1037
1038   SUBROUTINE dia_wri_state( cdfile_name, kt )
1039      !!---------------------------------------------------------------------
1040      !!                 ***  ROUTINE dia_wri_state  ***
1041      !!       
1042      !! ** Purpose :   create a NetCDF file named cdfile_name which contains
1043      !!      the instantaneous ocean state and forcing fields.
1044      !!        Used to find errors in the initial state or save the last
1045      !!      ocean state in case of abnormal end of a simulation
1046      !!
1047      !! ** Method  :   NetCDF files using ioipsl
1048      !!      File 'output.init.nc'  is created if ninist = 1 (namelist)
1049      !!      File 'output.abort.nc' is created in case of abnormal job end
1050      !!----------------------------------------------------------------------
1051      CHARACTER (len=* ), INTENT( in ) ::   cdfile_name      ! name of the file created
1052      INTEGER           , INTENT( in ) ::   kt               ! ocean time-step index
1053      !!
1054      CHARACTER (len=32) :: clname
1055      CHARACTER (len=40) :: clop
1056      INTEGER  ::   id_i , nz_i, nh_i       
1057      INTEGER, DIMENSION(1) ::   idex             ! local workspace
1058      REAL(wp) ::   zsto, zout, zmax, zjulian, zdt
1059      !!----------------------------------------------------------------------
1060      !
1061!     IF( nn_timing == 1 )   CALL timing_start('dia_wri_state') ! not sure this works for routines not called in first timestep
1062
1063      ! 0. Initialisation
1064      ! -----------------
1065
1066      ! Define name, frequency of output and means
1067      clname = cdfile_name
1068      IF( .NOT. Agrif_Root() ) clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
1069      zdt  = rdt
1070      zsto = rdt
1071      clop = "inst(x)"           ! no use of the mask value (require less cpu time)
1072      zout = rdt
1073      zmax = ( nitend - nit000 + 1 ) * zdt
1074
1075      IF(lwp) WRITE(numout,*)
1076      IF(lwp) WRITE(numout,*) 'dia_wri_state : single instantaneous ocean state'
1077      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~   and forcing fields file created '
1078      IF(lwp) WRITE(numout,*) '                and named :', clname, '.nc'
1079
1080
1081      ! 1. Define NETCDF files and fields at beginning of first time step
1082      ! -----------------------------------------------------------------
1083
1084      ! Compute julian date from starting date of the run
1085      CALL ymds2ju( nyear, nmonth, nday, rdt, zjulian )         ! time axis
1086      zjulian = zjulian - adatrj   !   set calendar origin to the beginning of the experiment
1087      CALL histbeg( clname, jpi, glamt, jpj, gphit,   &
1088          1, jpi, 1, jpj, nit000-1, zjulian, zdt, nh_i, id_i, domain_id=nidom, snc4chunks=snc4set ) ! Horizontal grid : glamt and gphit
1089      CALL histvert( id_i, "deptht", "Vertical T levels",   &    ! Vertical grid : gdept
1090          "m", jpk, gdept_1d, nz_i, "down")
1091
1092      ! Declare all the output fields as NetCDF variables
1093
1094      CALL histdef( id_i, "vosaline", "Salinity"              , "PSU"    ,   &   ! salinity
1095         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout )
1096      CALL histdef( id_i, "votemper", "Temperature"           , "C"      ,   &   ! temperature
1097         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout )
1098      CALL histdef( id_i, "sossheig", "Sea Surface Height"    , "m"      ,   &  ! ssh
1099         &          jpi, jpj, nh_i, 1  , 1, 1  , nz_i, 32, clop, zsto, zout )
1100      CALL histdef( id_i, "vozocrtx", "Zonal Current"         , "m/s"    ,   &   ! zonal current
1101         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout )
1102      CALL histdef( id_i, "vomecrty", "Meridional Current"    , "m/s"    ,   &   ! meridonal current
1103         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout ) 
1104      CALL histdef( id_i, "vovecrtz", "Vertical Velocity"     , "m/s"    ,   &   ! vertical current
1105         &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout ) 
1106      CALL histdef( id_i, "sowaflup", "Net Upward Water Flux" , "Kg/m2/S",   &   ! net freshwater
1107         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
1108      CALL histdef( id_i, "sohefldo", "Net Downward Heat Flux", "W/m2"   ,   &   ! net heat flux
1109         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
1110      CALL histdef( id_i, "soshfldo", "Shortwave Radiation"   , "W/m2"   ,   &   ! solar flux
1111         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
1112      CALL histdef( id_i, "soicecov", "Ice fraction"          , "[0,1]"  ,   &   ! fr_i
1113         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
1114      CALL histdef( id_i, "sozotaux", "Zonal Wind Stress"     , "N/m2"   ,   &   ! i-wind stress
1115         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
1116      CALL histdef( id_i, "sometauy", "Meridional Wind Stress", "N/m2"   ,   &   ! j-wind stress
1117         &          jpi, jpj, nh_i, 1  , 1, 1  , -99 , 32, clop, zsto, zout )
1118      IF( lk_vvl ) THEN
1119         CALL histdef( id_i, "vovvldep", "T point depth"         , "m"      ,   &   ! t-point depth
1120            &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout )
1121         CALL histdef( id_i, "vovvle3t", "T point thickness"         , "m"      ,   &   ! t-point depth
1122            &          jpi, jpj, nh_i, jpk, 1, jpk, nz_i, 32, clop, zsto, zout )
1123      END IF
1124
1125#if defined key_lim2
1126      CALL lim_wri_state_2( kt, id_i, nh_i )
1127#elif defined key_lim3
1128      CALL lim_wri_state( kt, id_i, nh_i )
1129#else
1130      CALL histend( id_i, snc4chunks=snc4set )
1131#endif
1132
1133      ! 2. Start writing data
1134      ! ---------------------
1135      ! idex(1) est utilise ssi l'avant dernier argument est diffferent de
1136      ! la taille du tableau en sortie. Dans ce cas , l'avant dernier argument
1137      ! donne le nombre d'elements, et idex la liste des indices a sortir
1138      idex(1) = 1   ! init to avoid compil warning
1139
1140      ! Write all fields on T grid
1141      CALL histwrite( id_i, "votemper", kt, tsn(:,:,:,jp_tem), jpi*jpj*jpk, idex )    ! now temperature
1142      CALL histwrite( id_i, "vosaline", kt, tsn(:,:,:,jp_sal), jpi*jpj*jpk, idex )    ! now salinity
1143      CALL histwrite( id_i, "sossheig", kt, sshn             , jpi*jpj    , idex )    ! sea surface height
1144      CALL histwrite( id_i, "vozocrtx", kt, un               , jpi*jpj*jpk, idex )    ! now i-velocity
1145      CALL histwrite( id_i, "vomecrty", kt, vn               , jpi*jpj*jpk, idex )    ! now j-velocity
1146      CALL histwrite( id_i, "vovecrtz", kt, wn               , jpi*jpj*jpk, idex )    ! now k-velocity
1147      CALL histwrite( id_i, "sowaflup", kt, (emp-rnf )       , jpi*jpj    , idex )    ! freshwater budget
1148      CALL histwrite( id_i, "sohefldo", kt, qsr + qns        , jpi*jpj    , idex )    ! total heat flux
1149      CALL histwrite( id_i, "soshfldo", kt, qsr              , jpi*jpj    , idex )    ! solar heat flux
1150      CALL histwrite( id_i, "soicecov", kt, fr_i             , jpi*jpj    , idex )    ! ice fraction
1151      CALL histwrite( id_i, "sozotaux", kt, utau             , jpi*jpj    , idex )    ! i-wind stress
1152      CALL histwrite( id_i, "sometauy", kt, vtau             , jpi*jpj    , idex )    ! j-wind stress
1153      IF( lk_vvl ) THEN
1154         CALL histwrite( id_i, "vovvldep", kt, fsdept_n(:,:,:), jpi*jpj*jpk, idex )!  T-cell depth       
1155         CALL histwrite( id_i, "vovvle3t", kt, fse3t_n (:,:,:), jpi*jpj*jpk, idex )!  T-cell thickness 
1156      END IF
1157
1158      ! 3. Close the file
1159      ! -----------------
1160      CALL histclo( id_i )
1161#if ! defined key_iomput && ! defined key_dimgout
1162      IF( ninist /= 1  ) THEN
1163         CALL histclo( nid_T )
1164         CALL histclo( nid_U )
1165         CALL histclo( nid_V )
1166         CALL histclo( nid_W )
1167      ENDIF
1168#endif
1169       
1170!     IF( nn_timing == 1 )   CALL timing_stop('dia_wri_state') ! not sure this works for routines not called in first timestep
1171      !
1172
1173   END SUBROUTINE dia_wri_state
1174   !!======================================================================
1175END MODULE diawri
Note: See TracBrowser for help on using the repository browser.