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.
trcdia.F90 in trunk/NEMO/TOP_SRC – NEMO

source: trunk/NEMO/TOP_SRC/trcdia.F90 @ 1715

Last change on this file since 1715 was 1715, checked in by smasson, 14 years ago

move daymod public variables in dom_oce, see ticket:590

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 30.1 KB
Line 
1MODULE trcdia
2   !!======================================================================
3   !!                       *** MODULE trcdia ***
4   !! TOP :   Output of passive tracers
5   !!======================================================================
6   !! History :    -   !  1995-01 (M. Levy)  Original code
7   !!              -   !  1998-01 (C. Levy) NETCDF format using ioipsl interface
8   !!              -   !  1999-01 (M.A. Foujols) adapted for passive tracer
9   !!              -   !  1999-09 (M.A. Foujols) split into three parts
10   !!             1.0  !  2005-03 (O. Aumont, A. El Moussaoui) F90
11   !!                  !  2008-05 (C. Ethe re-organization)
12   !!----------------------------------------------------------------------
13#if defined key_top && ! defined key_iomput
14   !!----------------------------------------------------------------------
15   !!   'key_top'                                                TOP models
16   !!----------------------------------------------------------------------
17   !! trc_dia     : main routine of output passive tracer
18   !! trcdit_wr   : outputs of concentration fields
19   !! trcdid_wr   : outputs of dvection-diffusion trends
20   !! trcdii_wr   : outputs of additional 2D/3D diagnostics
21   !! trcdib_wr   : outputs of biological fields
22   !!----------------------------------------------------------------------
23   USE dom_oce         ! ocean space and time domain variables
24   USE oce_trc
25   USE trc
26   USE trp_trc
27   USE trdmld_trc_oce, ONLY : luttrd
28   USE dianam    ! build name of file (routine)
29   USE in_out_manager  ! I/O manager
30   USE lib_mpp
31   USE ioipsl
32
33   IMPLICIT NONE
34   PRIVATE
35
36   PUBLIC trc_dia     
37
38   INTEGER  ::   nit5      !: id for tracer output file
39   INTEGER  ::   ndepit5   !: id for depth mesh
40   INTEGER  ::   nhorit5   !: id for horizontal mesh
41   INTEGER  ::   ndimt50   !: number of ocean points in index array
42   INTEGER  ::   ndimt51   !: number of ocean points in index array
43   REAL(wp) ::   xjulian   !: ????   not DOCTOR !
44   INTEGER , DIMENSION (jpij*jpk) ::   ndext50   !: integer arrays for ocean 3D index
45   INTEGER , DIMENSION (jpij)     ::   ndext51   !: integer arrays for ocean surface index
46# if defined key_trc_diaadd
47   INTEGER  ::   nitd      !: id for additional array output file
48   INTEGER  ::   ndepitd   !: id for depth mesh
49   INTEGER  ::   nhoritd   !: id for horizontal mesh
50# endif
51# if defined key_trc_diatrd
52   INTEGER , DIMENSION (jptra) ::   nit6      !: id for additional array output file
53   INTEGER , DIMENSION (jptra) ::   ndepit6   !: id for depth mesh
54   INTEGER , DIMENSION (jptra) ::   nhorit6   !: id for horizontal mesh
55# endif
56# if defined key_trc_diabio
57   INTEGER  ::   nitb        !:         id.         for additional array output file
58   INTEGER  ::   ndepitb   !:  id for depth mesh
59   INTEGER  ::   nhoritb   !:  id for horizontal mesh
60# endif
61
62   !! * Substitutions
63#  include "top_substitute.h90"
64   !!----------------------------------------------------------------------
65   !! NEMO/TOP 1.0 , LOCEAN-IPSL (2005)
66   !! $Id$
67   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
68   !!----------------------------------------------------------------------
69
70CONTAINS
71
72   SUBROUTINE trc_dia( kt ) 
73      !!---------------------------------------------------------------------
74      !!                     ***  ROUTINE trc_dia  ***
75      !!
76      !! ** Purpose :   output passive tracers fields
77      !!---------------------------------------------------------------------
78      INTEGER, INTENT( in ) :: kt
79      INTEGER               :: kindic
80      !!---------------------------------------------------------------------
81     
82      CALL trcdit_wr( kt, kindic )      ! outputs for tracer concentration
83      CALL trcdid_wr( kt, kindic )      ! outputs for dynamical trends
84      CALL trcdii_wr( kt, kindic )      ! outputs for additional arrays
85      CALL trcdib_wr( kt, kindic )      ! outputs for biological trends
86
87      !
88   END SUBROUTINE trc_dia
89
90   SUBROUTINE trcdit_wr( kt, kindic )
91      !!----------------------------------------------------------------------
92      !!                     ***  ROUTINE trcdit_wr  ***
93      !!
94      !! ** Purpose :   Standard output of passive tracer : concentration fields
95      !!
96      !! ** Method  :   At the beginning of the first time step (nit000), define all
97      !!             the NETCDF files and fields for concentration of passive tracer
98      !!
99      !!        At each time step call histdef to compute the mean if necessary
100      !!        Each nwritetrc time step, output the instantaneous or mean fields
101      !!
102      !!        IF kindic <0, output of fields before the model interruption.
103      !!        IF kindic =0, time step loop
104      !!        IF kindic >0, output of fields before the time step loop
105      !!----------------------------------------------------------------------
106      INTEGER, INTENT( in ) ::   kt          ! ocean time-step
107      INTEGER, INTENT( in ) ::   kindic      ! indicator of abnormal termination
108      !!
109      INTEGER ::   jn
110      LOGICAL ::   ll_print = .FALSE.
111      CHARACTER (len=40) :: clhstnam, clop
112#if defined key_off_tra
113      INTEGER ::   inum = 11             ! temporary logical unit
114#endif
115      CHARACTER (len=20) :: cltra, cltrau
116      CHARACTER (len=80) :: cltral
117      REAL(wp) :: zsto, zout, zdt
118      INTEGER  :: iimi, iima, ijmi, ijma, ipk, it, itmod
119      !!----------------------------------------------------------------------
120
121      ! Initialisation
122      ! --------------
123
124      ! local variable for debugging
125      ll_print = .FALSE.                  ! change it to true for more control print
126      ll_print = ll_print .AND. lwp
127
128      ! Define frequency of output and means
129      zdt = rdt
130      IF( ln_mskland )   THEN   ;   clop = "only(x)"   ! put 1.e+20 on land (very expensive!!)
131      ELSE                      ;   clop = "x"         ! no use of the mask value (require less cpu time)
132      ENDIF
133# if defined key_diainstant
134      zsto = nwritetrc * rdt
135      clop = "inst("//TRIM(clop)//")"
136# else
137      zsto = zdt
138      clop = "ave("//TRIM(clop)//")"
139# endif
140      zout = nwritetrc * zdt
141
142      ! Define indices of the horizontal output zoom and vertical limit storage
143      iimi = 1      ;      iima = jpi
144      ijmi = 1      ;      ijma = jpj
145      ipk = jpk
146
147      ! define time axis
148      itmod = kt - nittrc000 + 1
149      it    = kt
150
151      ! Define NETCDF files and fields at beginning of first time step
152      ! --------------------------------------------------------------
153
154      IF(ll_print)WRITE(numout,*)'trcdit_wr kt=',kt,' kindic ',kindic
155     
156      IF( kt == nittrc000 ) THEN
157
158         ! Compute julian date from starting date of the run
159         CALL ymds2ju( nyear, nmonth, nday, rdt, xjulian )
160         xjulian = xjulian - adatrj   !   set calendar origin to the beginning of the experiment
161         IF(lwp)WRITE(numout,*)' ' 
162         IF(lwp)WRITE(numout,*)' Date 0 used :', nittrc000                         &
163            &                 ,' YEAR ', nyear, ' MONTH ', nmonth, ' DAY ', nday   &
164            &                 ,'Julian day : ', xjulian 
165 
166         IF(lwp) WRITE(numout,*) ' indexes of zoom = ', iimi, iima, ijmi, ijma,  &
167            &                    ' limit storage in depth = ', ipk
168
169#if defined key_off_tra
170        ! WRITE root name in date.file for use by postpro
171         IF(lwp) THEN
172            CALL dia_nam( clhstnam, nwritetrc,' ' )
173            CALL ctl_opn( inum, 'date.file', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
174            WRITE(inum,*) clhstnam
175            CLOSE(inum)
176         ENDIF
177#endif
178
179         ! Define the NETCDF files for passive tracer concentration
180         CALL dia_nam( clhstnam, nwritetrc, 'ptrc_T' )
181         IF(lwp)WRITE(numout,*)" Name of NETCDF file ", clhstnam
182
183         ! Horizontal grid : glamt and gphit
184         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,     &
185            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,         & 
186            &          nittrc000-ndttrc, xjulian, zdt, nhorit5, nit5 , domain_id=nidom)
187
188         ! Vertical grid for tracer : gdept
189         CALL histvert( nit5, 'deptht', 'Vertical T levels', 'm', ipk, gdept_0, ndepit5)
190
191         ! Index of ocean points in 3D and 2D (surface)
192         CALL wheneq( jpi*jpj*ipk, tmask, 1, 1., ndext50, ndimt50 )
193         CALL wheneq( jpi*jpj    , tmask, 1, 1., ndext51, ndimt51 )
194
195         ! Declare all the output fields as NETCDF variables
196         DO jn = 1, jptra
197            IF( lutsav(jn) ) THEN
198               cltra  = ctrcnm(jn)   ! short title for tracer
199               cltral = ctrcnl(jn)   ! long title for tracer
200               cltrau = ctrcun(jn)   ! UNIT for tracer
201               CALL histdef( nit5, cltra, cltral, cltrau, jpi, jpj, nhorit5,  &
202                  &          ipk, 1, ipk,  ndepit5, 32, clop, zsto, zout ) 
203            ENDIF
204         END DO
205
206         ! end netcdf files header
207         CALL histend( nit5 )
208         IF(lwp) WRITE(numout,*)
209         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization in trcdit_wr'
210         IF( ll_print )   CALL FLUSH(numout )
211
212      ENDIF
213
214      ! Start writing the tracer concentrations
215      ! ---------------------------------------
216
217      IF( lwp .AND. MOD( itmod, nwritetrc ) == 0 ) THEN
218         WRITE(numout,*) 'trcdit_wr : write NetCDF passive tracer concentrations at ', kt, 'time-step'
219         WRITE(numout,*) '~~~~~~~~~ '
220      ENDIF
221
222      DO jn = 1, jptra
223         cltra = ctrcnm(jn)      ! short title for tracer
224         IF( lutsav(jn) ) CALL histwrite( nit5, cltra, it, trn(:,:,:,jn), ndimt50, ndext50 )
225      END DO
226
227      ! close the file
228      ! --------------
229      IF( kt == nitend .OR. kindic < 0 )   CALL histclo( nit5 )
230      !
231
232   END SUBROUTINE trcdit_wr
233
234# if defined key_trc_diatrd
235
236   SUBROUTINE trcdid_wr( kt, kindic )
237      !!----------------------------------------------------------------------
238      !!                     ***  ROUTINE trcdid_wr  ***
239      !!
240      !! ** Purpose :   output of passive tracer : advection-diffusion trends
241      !!
242      !! ** Method  :   At the beginning of the first time step (nit000), define all
243      !!             the NETCDF files and fields for concentration of passive tracer
244      !!
245      !!        At each time step call histdef to compute the mean if necessary
246      !!        Each nwritetrd time step, output the instantaneous or mean fields
247      !!
248      !!        IF kindic <0, output of fields before the model interruption.
249      !!        IF kindic =0, time step loop
250      !!        IF kindic >0, output of fields before the time step loop
251      !!----------------------------------------------------------------------
252      INTEGER, INTENT( in ) ::   kt          ! ocean time-step
253      INTEGER, INTENT( in ) ::   kindic      ! indicator of abnormal termination
254      !!
255      LOGICAL ::   ll_print = .FALSE.
256      CHARACTER (len=40) ::   clhstnam, clop
257      CHARACTER (len=20) ::   cltra, cltrau
258      CHARACTER (len=80) ::   cltral
259      CHARACTER (len=10) ::   csuff
260      INTEGER  ::   jn, jl
261      INTEGER  ::   iimi, iima, ijmi, ijma, ipk, it, itmod
262      REAL(wp) ::   zsto, zout, zdt
263      !!----------------------------------------------------------------------
264
265      ! 0. Initialisation
266      ! -----------------
267     
268
269      ! local variable for debugging
270      ll_print = .FALSE.
271      ll_print = ll_print .AND. lwp
272      !
273      ! Define frequency of output and means
274      zdt = rdt
275      IF( ln_mskland )   THEN   ;   clop = "only(x)"   ! put 1.e+20 on land (very expensive!!)
276      ELSE                      ;   clop = "x"         ! no use of the mask value (require less cpu time)
277      ENDIF
278#  if defined key_diainstant
279      zsto = nwritetrd * rdt
280      clop = "inst("//TRIM(clop)//")"
281#  else
282      zsto = zdt
283      clop = "ave("//TRIM(clop)//")"
284#  endif
285      zout = nwritetrd * zdt
286
287      ! Define indices of the horizontal output zoom and vertical limit storage
288      iimi = 1      ;      iima = jpi
289      ijmi = 1      ;      ijma = jpj
290      ipk = jpk
291
292      ! define time axis
293      itmod = kt - nittrc000 + 1
294      it    = kt
295
296      ! Define the NETCDF files (one per tracer)
297      IF( ll_print ) WRITE(numout,*) 'trcdid kt=', kt, ' kindic ', kindic
298     
299     
300      IF( kt == nittrc000 ) THEN
301
302         DO jn = 1, jptra
303            !
304            IF( luttrd(jn) ) THEN      ! Define the file for dynamical trends - one per each tracer IF required
305
306               IF(lwp)WRITE(numout,*) ' indexes of zoom = ', iimi, iima, ijmi, ijma,  &
307                   &                   ' limit storage in depth = ', ipk
308               csuff='DY_'//ctrcnm(jn)
309               CALL dia_nam( clhstnam, nwritetrd, csuff )
310               IF(lwp)WRITE(numout,*)   " Name of NETCDF file for dynamical trends",   &
311                  &                     " of tracer number : ",clhstnam
312
313               CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,       &
314                  &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,   &
315                  &          nittrc000-ndttrc, xjulian, zdt, nhorit6(jn),  &
316                  &          nit6(jn) , domain_id=nidom )
317
318               ! Vertical grid for tracer trend - one per each tracer IF needed
319               CALL histvert( nit6(jn), 'deptht', 'Vertical T levels', 'm', ipk, gdept_0, ndepit6(jn) ) 
320             END IF
321          END DO
322
323          ! Declare all the output fields as NETCDF variables
324
325          ! trends for tracer concentrations
326          DO jn = 1, jptra
327            IF( luttrd(jn) ) THEN
328                DO jl = 1, jpdiatrc
329                  IF( jl == 1 ) THEN
330                      ! short and long title for x advection for tracer
331                      WRITE (cltra,'("XAD_",16a)') ctrcnm(jn)
332                      WRITE (cltral,'("X advective trend for ",58a)')  &
333                         &      ctrcnl(jn)(1:58)
334                  END IF
335                  IF( jl == 2 ) THEN
336                      ! short and long title for y advection for tracer
337                      WRITE (cltra,'("YAD_",16a)') ctrcnm(jn)
338                      WRITE (cltral,'("Y advective trend for ",58a)')  &
339                         &      ctrcnl(jn)(1:58)
340                  END IF
341                  IF( jl == 3 ) THEN
342                      ! short and long title for Z advection for tracer
343                      WRITE (cltra,'("ZAD_",16a)') ctrcnm(jn)
344                      WRITE (cltral,'("Z advective trend for ",58a)')  &
345                         &      ctrcnl(jn)(1:58)
346                  END IF
347                  IF( jl == 4 ) THEN
348                      ! short and long title for X diffusion for tracer
349                      WRITE (cltra,'("XDF_",16a)') ctrcnm(jn)
350                      WRITE (cltral,'("X diffusion trend for ",58a)')  &
351                         &      ctrcnl(jn)(1:58)
352                  END IF
353                  IF( jl == 5 ) THEN
354                      ! short and long title for Y diffusion for tracer
355                      WRITE (cltra,'("YDF_",16a)') ctrcnm(jn)
356                      WRITE (cltral,'("Y diffusion trend for ",58a)')  &
357                         &      ctrcnl(jn)(1:58)
358                  END IF
359                  IF( jl == 6 ) THEN
360                      ! short and long title for Z diffusion for tracer
361                      WRITE (cltra,'("ZDF_",16a)') ctrcnm(jn)
362                      WRITE (cltral,'("Z diffusion trend for ",58a)')  &
363                         &      ctrcnl(jn)(1:58)
364                  END IF
365# if defined key_trcldf_eiv
366                  IF( jl == 7 ) THEN
367                      ! short and long title for x gent velocity for tracer
368                      WRITE (cltra,'("XGV_",16a)') ctrcnm(jn)
369                      WRITE (cltral,'("X gent velocity trend for ",53a)')  &
370                         &      ctrcnl(jn)(1:53)
371                  END IF
372                  IF( jl == 8 ) THEN
373                      ! short and long title for y gent velocity for tracer
374                      WRITE (cltra,'("YGV_",16a)') ctrcnm(jn)
375                      WRITE (cltral,'("Y gent velocity trend for ",53a)')  &
376                         &      ctrcnl(jn)(1:53)
377                  END IF
378                  IF( jl == 9 ) THEN
379                      ! short and long title for Z gent velocity for tracer
380                      WRITE (cltra,'("ZGV_",16a)') ctrcnm(jn)
381                      WRITE (cltral,'("Z gent velocity trend for ",53a)')  &
382                         &      ctrcnl(jn)(1:53)
383                  END IF
384# endif
385# if defined key_trcdmp
386                  IF( jl == jpdiatrc - 1 ) THEN
387                      ! last trends for tracer damping : short and long title
388                      WRITE (cltra,'("TDM_",16a)') ctrcnm(jn)
389                      WRITE (cltral,'("Tracer damping trend for ",55a)')  &
390                         &      ctrcnl(jn)(1:55)
391                  END IF
392# endif
393                  IF( jl == jpdiatrc ) THEN
394                      ! last trends for tracer damping : short and long title
395                      WRITE (cltra,'("SBC_",16a)') ctrcnm(jn)
396                      WRITE (cltral,'("Surface boundary flux ",58a)')  &
397                      &      ctrcnl(jn)(1:58)
398                  END IF
399
400                  CALL FLUSH( numout )
401                  cltrau = ctrcun(jn)      ! UNIT for tracer /trends
402                  CALL histdef( nit6(jn), cltra, cltral, cltrau, jpi,jpj,  &
403                     &          nhorit6(jn), ipk, 1, ipk,  ndepit6(jn), 32, clop ,  &
404                     &          zsto,zout )
405               END DO
406            END IF
407         END DO
408
409         ! CLOSE netcdf Files
410          DO jn = 1, jptra
411             IF( luttrd(jn) )   CALL histend( nit6(jn) )
412          END DO
413
414         IF(lwp) WRITE(numout,*)
415         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization in trcdid'
416         IF(ll_print) CALL FLUSH(numout )
417         !
418      ENDIF
419
420      ! SOME diagnostics to DO first time
421
422      ! Start writing data
423      ! ---------------------
424
425      ! trends for tracer concentrations
426
427      IF( lwp .AND. MOD( itmod, nwritetrd ) == 0 ) THEN
428         WRITE(numout,*) 'trcdid_wr : write NetCDF dynamical trends at ', kt, 'time-step'
429         WRITE(numout,*) '~~~~~~ '
430      ENDIF
431
432      DO jn = 1, jptra
433         IF( luttrd(jn) ) THEN
434            DO jl = 1, jpdiatrc
435               ! short titles
436               IF( jl == 1)   WRITE (cltra,'("XAD_",16a)') ctrcnm(jn)      ! x advection for tracer
437               IF( jl == 2)   WRITE (cltra,'("YAD_",16a)') ctrcnm(jn)      ! z advection for tracer
438               IF( jl == 3)   WRITE (cltra,'("ZAD_",16a)') ctrcnm(jn)      ! z advection for tracer
439               IF( jl == 4)   WRITE (cltra,'("XDF_",16a)') ctrcnm(jn)      ! x diffusion for tracer
440               IF( jl == 5)   WRITE (cltra,'("YDF_",16a)') ctrcnm(jn)      ! y diffusion for tracer
441               IF( jl == 6)   WRITE (cltra,'("ZDF_",16a)') ctrcnm(jn)      ! z diffusion for tracer
442# if defined key_trcldf_eiv
443               IF( jl == 7)   WRITE (cltra,'("XGV_",16a)') ctrcnm(jn)      ! x gent velocity for tracer
444               IF( jl == 8)   WRITE (cltra,'("YGV_",16a)') ctrcnm(jn)      ! y gent velocity for tracer
445               IF( jl == 9)   WRITE (cltra,'("ZGV_",16a)') ctrcnm(jn)      ! z gent velocity for tracer
446# endif
447# if defined key_trcdmp
448               IF( jl == jpdiatrc - 1 )   WRITE (cltra,'("TDM_",16a)') ctrcnm(jn)      ! damping
449# endif
450               IF( jl == jpdiatrc )   WRITE (cltra,'("SBC_",a)') ctrcnm(jn)      ! surface boundary conditions
451               !
452               CALL histwrite(nit6(jn), cltra, it, trtrd(:,:,:,ikeep(jn),jl),ndimt50, ndext50)
453            END DO
454         END IF
455      END DO
456
457      ! Closing all files
458      ! -----------------
459      IF( kt == nitend .OR. kindic < 0 ) THEN
460         DO jn = 1, jptra
461            IF( luttrd(jn) )   CALL histclo( nit6(jn) )
462         END DO
463      ENDIF
464      !
465
466   END SUBROUTINE trcdid_wr
467
468# else
469
470   SUBROUTINE trcdid_wr( kt, kindic )                      ! Dummy routine
471      INTEGER, INTENT ( in ) ::   kt, kindic
472   END SUBROUTINE trcdid_wr
473
474# endif
475
476#if defined key_trc_diaadd
477
478   SUBROUTINE trcdii_wr( kt, kindic )
479      !!----------------------------------------------------------------------
480      !!                     ***  ROUTINE trcdii_wr  ***
481      !!
482      !! ** Purpose :   output of passive tracer : additional 2D and 3D arrays
483      !!
484      !! ** Method  :   At the beginning of the first time step (nit000), define all
485      !!             the NETCDF files and fields for concentration of passive tracer
486      !!
487      !!        At each time step call histdef to compute the mean if necessary
488      !!        Each nwritedia time step, output the instantaneous or mean fields
489      !!
490      !!        IF kindic <0, output of fields before the model interruption.
491      !!        IF kindic =0, time step loop
492      !!        IF kindic >0, output of fields before the time step loop
493      !!----------------------------------------------------------------------
494      INTEGER, INTENT( in ) ::   kt          ! ocean time-step
495      INTEGER, INTENT( in ) ::   kindic      ! indicator of abnormal termination
496      !!
497      LOGICAL ::   ll_print = .FALSE.
498      CHARACTER (len=40) ::   clhstnam, clop
499      CHARACTER (len=20) ::   cltra, cltrau
500      CHARACTER (len=80) ::   cltral
501      INTEGER  ::   jl
502      INTEGER  ::   iimi, iima, ijmi, ijma, ipk, it, itmod
503      REAL(wp) ::   zsto, zout, zdt
504      !!----------------------------------------------------------------------
505
506      ! Initialisation
507      ! --------------
508     
509      ! local variable for debugging
510      ll_print = .FALSE.
511      ll_print = ll_print .AND. lwp
512      !
513      ! Define frequency of output and means
514      zdt = rdt
515      IF( ln_mskland )   THEN   ;   clop = "only(x)"   ! put 1.e+20 on land (very expensive!!)
516      ELSE                      ;   clop = "x"         ! no use of the mask value (require less cpu time)
517      ENDIF
518#  if defined key_diainstant
519      zsto = nwritedia * zdt
520      clop = "inst("//TRIM(clop)//")"
521#  else
522      zsto = zdt
523      clop = "ave("//TRIM(clop)//")"
524#  endif
525      zout = nwritedia * zdt
526
527      ! Define indices of the horizontal output zoom and vertical limit storage
528      iimi = 1      ;      iima = jpi
529      ijmi = 1      ;      ijma = jpj
530      ipk = jpk
531
532      ! define time axis
533      itmod = kt - nittrc000 + 1
534      it    = kt
535
536      ! 1. Define NETCDF files and fields at beginning of first time step
537      ! -----------------------------------------------------------------
538
539      IF( ll_print ) WRITE(numout,*) 'trcdii_wr kt=', kt, ' kindic ', kindic
540
541      IF( kt == nittrc000 ) THEN
542
543         ! Define the NETCDF files for additional arrays : 2D or 3D
544
545         ! Define the T grid file for tracer auxiliary files
546
547         CALL dia_nam( clhstnam, nwritedia, 'diad_T' )
548         IF(lwp) WRITE(numout,*) " Name of NETCDF file ", clhstnam
549
550         ! Define a netcdf FILE for 2d and 3d arrays
551
552         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,             &
553            &          iimi, iima-iimi+1, ijmi, ijma-ijmi+1,         &
554            &          nittrc000-ndttrc, xjulian, zdt, nhoritd, nitd , domain_id=nidom )
555
556         ! Vertical grid for 2d and 3d arrays
557
558         CALL histvert( nitd, 'deptht', 'Vertical T levels','m', ipk, gdept_0, ndepitd)
559
560         ! Declare all the output fields as NETCDF variables
561
562         ! more 3D horizontal arrays
563         DO jl = 1, jpdia3d
564            cltra  = ctrc3d(jl)   ! short title for 3D diagnostic
565            cltral = ctrc3l(jl)   ! long title for 3D diagnostic
566            cltrau = ctrc3u(jl)   ! UNIT for 3D diagnostic
567            CALL histdef( nitd, cltra, cltral, cltrau, jpi, jpj, nhoritd,   &
568               &          ipk, 1, ipk,  ndepitd, 32, clop, zsto, zout )
569         END DO
570
571         ! more 2D horizontal arrays
572         DO jl = 1, jpdia2d
573            cltra  = ctrc2d(jl)    ! short title for 2D diagnostic
574            cltral = ctrc2l(jl)   ! long title for 2D diagnostic
575            cltrau = ctrc2u(jl)   ! UNIT for 2D diagnostic
576            CALL histdef( nitd, cltra, cltral, cltrau, jpi, jpj, nhoritd,  &
577               &          1, 1, 1,  -99, 32, clop, zsto, zout )
578         END DO
579
580         ! TODO: more 2D vertical sections arrays : I or J indice fixed
581
582         ! CLOSE netcdf Files
583         CALL histend( nitd )
584
585         IF(lwp) WRITE(numout,*)
586         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization in trcdii_wr'
587         IF( ll_print )   CALL FLUSH(numout )
588         !
589      ENDIF
590
591      ! 2. Start writing data
592      ! ---------------------
593
594      IF( lwp .AND. MOD( itmod, nwritedia ) == 0 ) THEN
595         WRITE(numout,*) 'trcdii_wr : write NetCDF additional arrays at ', kt, 'time-step'
596         WRITE(numout,*) '~~~~~~ '
597      ENDIF
598
599      ! more 3D horizontal arrays
600      DO jl = 1, jpdia3d
601         cltra = ctrc3d(jl)   ! short title for 3D diagnostic
602         CALL histwrite( nitd, cltra, it, trc3d(:,:,:,jl), ndimt50 ,ndext50)
603      END DO
604
605      ! more 2D horizontal arrays
606      DO jl = 1, jpdia2d
607         cltra = ctrc2d(jl)   ! short title for 2D diagnostic
608         CALL histwrite(nitd, cltra, it, trc2d(:,:,jl), ndimt51  ,ndext51)
609      END DO
610
611      ! Closing all files
612      ! -----------------
613      IF( kt == nitend .OR. kindic < 0 )   CALL histclo(nitd)
614      !
615
616   END SUBROUTINE trcdii_wr
617
618# else
619
620   SUBROUTINE trcdii_wr( kt, kindic )                      ! Dummy routine
621      INTEGER, INTENT ( in ) :: kt, kindic
622   END SUBROUTINE trcdii_wr
623
624# endif
625
626# if defined key_trc_diabio
627
628   SUBROUTINE trcdib_wr( kt, kindic )
629      !!----------------------------------------------------------------------
630      !!                     ***  ROUTINE trcdib_wr  ***
631      !!
632      !! ** Purpose :   output of passive tracer : biological fields
633      !!
634      !! ** Method  :   At the beginning of the first time step (nit000), define all
635      !!             the NETCDF files and fields for concentration of passive tracer
636      !!
637      !!        At each time step call histdef to compute the mean if necessary
638      !!        Each nwritebio time step, output the instantaneous or mean fields
639      !!
640      !!        IF kindic <0, output of fields before the model interruption.
641      !!        IF kindic =0, time step loop
642      !!        IF kindic >0, output of fields before the time step loop
643      !!----------------------------------------------------------------------
644      !!
645      INTEGER, INTENT( in ) ::   kt          ! ocean time-step
646      INTEGER, INTENT( in ) ::   kindic      ! indicator of abnormal termination
647      !!
648      LOGICAL ::   ll_print = .FALSE.
649      CHARACTER (len=40) ::   clhstnam, clop
650      CHARACTER (len=20) ::   cltra, cltrau
651      CHARACTER (len=80) ::   cltral
652      INTEGER  ::   ji, jj, jk, jl
653      INTEGER  ::   iimi, iima, ijmi, ijma, ipk, it, itmod
654      REAL(wp) ::   zsto, zout, zdt
655      !!----------------------------------------------------------------------
656
657      ! Initialisation
658      ! --------------
659
660     
661      ! local variable for debugging
662      ll_print = .FALSE.
663      ll_print = ll_print .AND. lwp
664
665      ! Define frequency of output and means
666      zdt = rdt
667      IF( ln_mskland )   THEN   ;   clop = "only(x)"   ! put 1.e+20 on land (very expensive!!)
668      ELSE                      ;   clop = "x"         ! no use of the mask value (require less cpu time)
669      ENDIF
670#        if defined key_diainstant
671      zsto = nwritebio * zdt
672      clop = "inst("//TRIM(clop)//")"
673#        else
674      zsto = zdt
675      clop = "ave("//TRIM(clop)//")"
676#        endif
677      zout = nwritebio * zdt
678
679      ! Define indices of the horizontal output zoom and vertical limit storage
680      iimi = 1      ;      iima = jpi
681      ijmi = 1      ;      ijma = jpj
682      ipk = jpk
683
684      ! define time axis
685      itmod = kt - nittrc000 + 1
686      it    = kt
687
688      ! Define NETCDF files and fields at beginning of first time step
689      ! --------------------------------------------------------------
690
691      IF(ll_print) WRITE(numout,*)'trcdib_wr kt=',kt,' kindic ',kindic
692
693      IF( kt == nittrc000 ) THEN
694
695         ! Define the NETCDF files for biological trends
696
697         CALL dia_nam(clhstnam,nwritebio,'biolog')
698         IF(lwp)WRITE(numout,*) " Name of NETCDF file for biological trends ", clhstnam
699         ! Horizontal grid : glamt and gphit
700         CALL histbeg( clhstnam, jpi, glamt, jpj, gphit,      &
701            &    iimi, iima-iimi+1, ijmi, ijma-ijmi+1,          &
702            &    nittrc000-ndttrc, xjulian, zdt, nhoritb, nitb , domain_id=nidom )
703         ! Vertical grid for biological trends
704         CALL histvert(nitb, 'deptht', 'Vertical T levels', 'm', ipk, gdept_0, ndepitb)
705
706         ! Declare all the output fields as NETCDF variables
707         ! biological trends
708         DO jl = 1, jpdiabio
709            cltra  = ctrbio(jl)   ! short title for biological diagnostic
710            cltral = ctrbil(jl)   ! long title for biological diagnostic
711            cltrau = ctrbiu(jl)   ! UNIT for biological diagnostic
712            CALL histdef( nitb, cltra, cltral, cltrau, jpi, jpj, nhoritb,  &
713               &         ipk, 1, ipk,  ndepitb, 32, clop, zsto, zout)
714         END DO
715
716         ! CLOSE netcdf Files
717          CALL histend( nitb )
718
719         IF(lwp) WRITE(numout,*)
720         IF(lwp) WRITE(numout,*) 'End of NetCDF Initialization in trcdib_wr'
721         IF(ll_print) CALL FLUSH(numout )
722         !
723      ENDIF
724
725      ! Start writing data
726      ! ------------------
727
728      ! biological trends
729      IF( lwp .AND. MOD( itmod, nwritebio ) == 0 ) THEN
730         WRITE(numout,*) 'trcdit_wr : write NetCDF biological trends at ', kt, 'time-step'
731         WRITE(numout,*) '~~~~~~ '
732      ENDIF
733
734      DO jl = 1, jpdiabio
735         cltra = ctrbio(jl)  ! short title for biological diagnostic
736         CALL histwrite(nitb, cltra, it, trbio(:,:,:,jl), ndimt50,ndext50)
737      END DO
738
739      ! Closing all files
740      ! -----------------
741      IF( kt == nitend .OR. kindic < 0 )   CALL histclo( nitb )
742      !
743
744   END SUBROUTINE trcdib_wr
745
746# else
747
748   SUBROUTINE trcdib_wr( kt, kindic )                      ! Dummy routine
749      INTEGER, INTENT ( in ) ::   kt, kindic
750   END SUBROUTINE trcdib_wr
751
752# endif 
753
754#else
755   !!----------------------------------------------------------------------
756   !!  Dummy module :                                     No passive tracer
757   !!----------------------------------------------------------------------
758CONTAINS
759   SUBROUTINE trc_dia( kt )                      ! Empty routine   
760      INTEGER, INTENT(in) :: kt
761   END SUBROUTINE trc_dia   
762
763#endif
764
765   !!======================================================================
766END MODULE trcdia
Note: See TracBrowser for help on using the repository browser.