Index: /trunk/NEMO/OPA_SRC/DIA/diawri_dimg.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/DIA/diawri_dimg.h90	(revision 404)
+++ /trunk/NEMO/OPA_SRC/DIA/diawri_dimg.h90	(revision 405)
@@ -3,6 +3,6 @@
   !!----------------------------------------------------------------------
   !!   OPA 9.0 , LOCEAN-IPSL (2005) 
-   !! $Header$ 
-   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
+  !! $Header$ 
+  !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
   !!----------------------------------------------------------------------
 
@@ -43,20 +43,22 @@
     !!  level 1:  taux(:,:) * umask(:,:,1) zonal stress in N.m-2
     !!  level 2:  tauy(:,:) * vmask(:,:,1) meridional stress in N. m-2
-    !!  level 3:   qt (:,:)                total heat flux (W/m2)
-    !!  level 4:   emp (:,:) 	        	  E-P flux (mm/day)
-    !!  level 5:  tb  (:,:,1)-sst            model SST -forcing sst (degree C)
-    !!  level 6:  bsfb(:,:)		          streamfunction (m**3/s)
-    !!  level 7:  qsr (:,:)		          solar flux (W/m2)
-    !!  level 8:  qrp (:,:)                  relax component of T flux.
-    !!  level 9:  erp (:,:)                  relax component of S flux
-    !!  level 10: hmld(:,:)                   turbocline depth
-    !!  level 11: hmlp(:,:)                   mixed layer depth
-    !!  level 12: freeze (:,:)               Ice cover (1. or 0.)
-    !!  level 13: sst(:,:)                   the observed SST we relax to.
-    !!  level 14: qct(:,:)                   equivalent flux due to treshold SST
-    !!  level 15: fbt(:,:)                   feedback term .
-    !!  level 16: gps(:,:)                   the surface pressure (m).
-    !!  level 17: spgu(:,:)                  the surface pressure gradient in X direction.
-    !!  level 18: spgv(:,:)                  the surface pressure gradient in Y direction.
+    !!  level 3:   qt  (:,:)               total heat flux (W/m2)
+    !!  level 4:   emp (:,:)               E-P flux (mm/day)
+    !!  level 5:  tb  (:,:,1)-sst          model SST -forcing sst (degree C)
+    !!  level 6:  bsfb(:,:)		   streamfunction (m**3/s)
+    !!  level 7:  qsr (:,:)		   solar flux (W/m2)
+    !!  level 8:  qrp (:,:)                relax component of T flux.
+    !!  level 9:  erp (:,:)                relax component of S flux
+    !!  level 10: hmld(:,:)                turbocline depth
+    !!  level 11: hmlp(:,:)                mixed layer depth
+    !!  level 12: freeze (:,:)             Ice cover (1. or 0.)
+    !!  level 13: sst(:,:)                 the observed SST we relax to.
+    !!  level 14: qct(:,:)                 equivalent flux due to treshold SST
+    !!  level 15: fbt(:,:)                 feedback term .
+    !!  level 16: emps(:,:)                concentration/dilution water flux
+    !!  level 17: fsalt(:,:)               Ice=>ocean net freshwater
+    !!  level 18: gps(:,:)                 the surface pressure (m).
+    !!  level 19: spgu(:,:)                the surface pressure gradient in X direction.
+    !!  level 20: spgv(:,:)                the surface pressure gradient in Y direction.
     !! 
     !! History 
@@ -69,4 +71,5 @@
     !!      additions : 97-2002 ( Clipper Group ) dimg files
     !!                  dec 2003 ( J.M. Molines) f90, mpp output for OPA9.0
+    !!   9.0  !  05-05  (S. Theetten) add emps fsalt move gps spgu spgv 2 lines below
     !!   9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
     !!----------------------------------------------------------------------
@@ -92,4 +95,5 @@
     REAL(wp), SAVE, DIMENSION (jpi,jpj,jpk) ::  um , vm   ! used to compute mean u, v fields
     REAL(wp), SAVE, DIMENSION (jpi,jpj,jpk) ::  wm        ! used to compute mean w fields
+    REAL(wp), SAVE, DIMENSION (jpi,jpj,jpk) ::  avtm      ! used to compute mean kz fields
     REAL(wp), SAVE, DIMENSION (jpi,jpj,jpk) ::  tm , sm   ! used to compute mean t, s fields
     REAL(wp), SAVE, DIMENSION (jpi,jpj,jpk) ::  fsel      ! used to compute mean 2d fields
@@ -105,14 +109,14 @@
     !
 #ifdef key_diaspr
-    inbsel = 18
+    inbsel = 20
 #else
-    inbsel = 15
-#endif
-
-    IF (inbsel >  jpk) THEN
-       IF (lwp) WRITE(numout,*)  &
+    inbsel = 17
+#endif
+
+    IF( inbsel >  jpk) THEN
+       IF( lwp) WRITE(numout,*)  &
             ' STOP inbsel =',inbsel,' is larger than jpk=',jpk
        STOP
-    END IF
+    ENDIF
 
 
@@ -126,5 +130,5 @@
     clver='@!01'
     !
-    IF ( .NOT. ll_dia_inst ) THEN
+    IF( .NOT. ll_dia_inst ) THEN
        !#if ! defined key_diainstant
        !
@@ -132,8 +136,8 @@
        !! ----------------------
        !
-       IF (kt == nit000 .AND. lwp ) WRITE(numout,*) &
+       IF( kt == nit000 .AND. lwp ) WRITE(numout,*) &
             'THE OUTPUT FILES CONTAINS THE AVERAGE OF EACH FIELD'
        !
-       IF ( kt == nit000 .AND. kindic > 0 ) THEN
+       IF( kt == nit000  ) THEN
           ! reset arrays for average computation
           nmoyct = 0
@@ -142,9 +146,10 @@
           vm(:,:,:) = 0._wp
           wm(:,:,:) = 0._wp
+          avtm(:,:,:) = 0._wp
           tm(:,:,:) = 0._wp
           sm(:,:,:) = 0._wp
           fsel(:,:,:) = 0._wp
           !
-       END IF
+       ENDIF
 
        !  cumulate values
@@ -156,4 +161,5 @@
        vm(:,:,:)=vm(:,:,:) + vn (:,:,:)
        wm(:,:,:)=wm(:,:,:) + wn (:,:,:)
+       avtm(:,:,:)=avtm(:,:,:) + avt (:,:,:)
        tm(:,:,:)=tm(:,:,:) + tn (:,:,:)
        sm(:,:,:)=sm(:,:,:) + sn (:,:,:)
@@ -178,6 +184,10 @@
        !        fsel(:,:,14) = fsel(:,:,14) + qct(:,:)
        !        fsel(:,:,15) = fsel(:,:,15) + fbt(:,:)
+       fsel(:,:,16) = fsel(:,:,16) + emps(:,:)
+#if defined key_ice_lim
+       fsel(:,:,17) = fsel(:,:,17) + fsalt(:,:)
+#endif
 #ifdef key_diaspr   
-       fsel(:,:,16) = fsel(:,:,16) + gps(:,:)/g 
+       fsel(:,:,18) = fsel(:,:,18) + gps(:,:)/g 
 #endif
        !
@@ -192,5 +202,5 @@
        !      IF (abs(adatrj-iwrite*rwrite) < zdtj/2.      &
 
-       IF (  ( MOD (kt-nit000+1,nwrite) ==  0 )          &
+       IF(  ( MOD (kt-nit000+1,nwrite) ==  0 )          &
             &   .OR.       kindic <   0            &
             &   .OR. ( kt == 1 .AND. kindic > 0)  ) THEN
@@ -200,4 +210,5 @@
           vm(:,:,:) = vm(:,:,:) / nmoyct
           wm(:,:,:) = wm(:,:,:) / nmoyct
+          avtm(:,:,:) = avtm(:,:,:) / nmoyct
           tm(:,:,:) = tm(:,:,:) / nmoyct
           sm(:,:,:) = sm(:,:,:) / nmoyct
@@ -209,7 +220,7 @@
           !
 #ifdef key_diaspr
-          fsel(:,:,16)= gps(:,:)/g
-          fsel(:,:,17)= spgu(:,:)
-          fsel(:,:,18)= spgv(:,:)
+          fsel(:,:,18)= gps(:,:)/g
+          fsel(:,:,19)= spgu(:,:)
+          fsel(:,:,20)= spgv(:,:)
 #endif
        ENDIF
@@ -221,5 +232,5 @@
        !! ------------------------------
        !
-       IF (kt == nit000 .AND. lwp ) WRITE(numout,*) &
+       IF( kt == nit000 .AND. lwp ) WRITE(numout,*) &
             'THE OUTPUT FILES CONTAINS INSTANTANEOUS VALUES OF EACH FIELD'
        !
@@ -255,8 +266,12 @@
           !         fsel(:,:,14) =  qct(:,:)
           !         fsel(:,:,15) =  fbt(:,:)
+          fsel(:,:,16) =  emps(:,:)
+#if defined key_ice_lim
+          fsel(:,:,17) =  fsalt(:,:)
+#endif
 #ifdef key_diaspr           
-          fsel(:,:,16) =      gps(:,:) /g
-          fsel(:,:,17) =      spgu(:,:)
-          fsel(:,:,18) =      spgv(:,:)
+          fsel(:,:,18) =      gps(:,:) /g
+          fsel(:,:,19) =      spgu(:,:)
+          fsel(:,:,20) =      spgv(:,:)
 #endif
           !
@@ -269,13 +284,13 @@
     ! this file gives a record of the dump date for post processing ( ASCII file )
     !
-    IF (  ( MOD (kt-nit000+1,nwrite) ==  0 )          &
+    IF(  ( MOD (kt-nit000+1,nwrite) ==  0 )          &
          &   .OR.       kindic <   0            &
          &   .OR. ( kt == 1 .AND. kindic > 0)  ) THEN
-       OPEN (14,FILE='datrj.out',FORM='FORMATTED', STATUS='UNKNOWN',POSITION='APPEND')
-
-       IF (lwp) WRITE(14,'(f10.4,1x,i8)') adatrj, ndastp
+       OPEN (14,FILE='datrj.out',FORM='FORMATTED', STATUS='UNKNOWN',POSITION='APPEND ')
+
+       IF( lwp) WRITE(14,'(f10.4,1x,i8)') adatrj, ndastp
        CLOSE(14)
 
-       IF (lwp) WRITE(numout,*)'Days since the begining of the run :',adatrj
+       IF( lwp) WRITE(numout,*)'Days since the begining of the run :',adatrj
 
        !! * U section
@@ -285,14 +300,14 @@
        IF ( kindic < 0 )   cltext=TRIM(cexper)//' U(m/s)  instantaneous (explosion)'
        !
-       IF ( ll_dia_inst) THEN 
+       IF( ll_dia_inst) THEN 
           CALL dia_wri_dimg(clname, cltext, un, jpk, 'T')
 
        ELSE 
-          IF ( kindic ==  -3 ) THEN
+          IF( kindic ==  -3 ) THEN
              ! ... in case of explosion on umax, dump instantateous u field instead of mean.
              CALL dia_wri_dimg(clname, cltext, un, jpk, 'T')
           ELSE
              CALL dia_wri_dimg(clname, cltext, um, jpk, 'T')
-          END  IF
+          ENDIF
        ENDIF
 
@@ -302,9 +317,9 @@
        cltext=TRIM(cexper)//' V(m/s) '//TRIM(clmode)
        !
-       IF ( ll_dia_inst) THEN
+       IF( ll_dia_inst) THEN
           CALL dia_wri_dimg(clname, cltext, vn, jpk, 'T')
        ELSE
           CALL dia_wri_dimg(clname, cltext, vm, jpk, 'T')
-       END IF
+       ENDIF
        !
 
@@ -312,8 +327,11 @@
 
        WRITE(clname,9000) TRIM(cexper),'KZ',iyear,imon,iday
-       cltext=TRIM(cexper)//' KZ(m2/s) instantaneous'
-
-       ! no average on kz (convective area may show up too strongly )
-       CALL dia_wri_dimg(clname, cltext, avt, jpk, 'W')
+       cltext=TRIM(cexper)//' KZ(m2/s) '//TRIM(clmode)
+
+       IF( ll_dia_inst) THEN
+          CALL dia_wri_dimg(clname, cltext, avt, jpk, 'W')
+       ELSE
+          CALL dia_wri_dimg(clname, cltext, avtm, jpk, 'W')
+       ENDIF
        !
 
@@ -323,9 +341,9 @@
        cltext=TRIM(cexper)//' W(m/s) '//TRIM(clmode)
 
-       IF ( ll_dia_inst) THEN
+       IF( ll_dia_inst) THEN
           CALL dia_wri_dimg(clname, cltext, wn, jpk, 'W')
        ELSE
           CALL dia_wri_dimg(clname, cltext, wm, jpk, 'W')
-       END IF
+       ENDIF
 
        !! * T section
@@ -334,9 +352,9 @@
        cltext=TRIM(cexper)//' T (DegC) '//TRIM(clmode)
 
-       IF (ll_dia_inst) THEN
+       IF( ll_dia_inst) THEN
           CALL dia_wri_dimg(clname, cltext, tn, jpk, 'T')
        ELSE
           CALL dia_wri_dimg(clname, cltext, tm, jpk, 'T')
-       END IF
+       ENDIF
        !
 
@@ -346,9 +364,9 @@
        cltext=TRIM(cexper)//' S (PSU) '//TRIM(clmode)
 
-       IF (ll_dia_inst) THEN
+       IF( ll_dia_inst) THEN
           CALL dia_wri_dimg(clname, cltext, sn, jpk, 'T')
        ELSE
           CALL dia_wri_dimg(clname, cltext, sm, jpk, 'T')
-       END IF
+       ENDIF
        !
 
@@ -358,5 +376,5 @@
        cltext='2D fields '//TRIM(clmode)
 
-       IF (ll_dia_inst) THEN
+       IF( ll_dia_inst) THEN
           CALL dia_wri_dimg(clname, cltext, fsel, inbsel, '2')
        ELSE
@@ -368,14 +386,14 @@
        !! * Log message in numout 
 
-       IF(lwp)WRITE(numout,*) ' '
-       IF(lwp)WRITE(numout,*) ' **** WRITE in numwri ',kt
-
-       IF(lwp .AND.        ll_dia_inst) WRITE(numout,*) '    instantaneous fields'
-       IF(lwp .AND. .NOT. ll_dia_inst ) WRITE(numout,*) '    average fields with ',nmoyct,'pdt'
+       IF( lwp)WRITE(numout,*) ' '
+       IF( lwp)WRITE(numout,*) ' **** WRITE in numwri ',kt
+
+       IF( lwp .AND.        ll_dia_inst) WRITE(numout,*) '    instantaneous fields'
+       IF( lwp .AND. .NOT.  ll_dia_inst) WRITE(numout,*) '    average fields with ',nmoyct,'pdt'
        !
        !
        !! * Reset cumulating arrays  and counter to 0 after writing
        !
-       IF ( .NOT. ll_dia_inst ) THEN
+       IF( .NOT. ll_dia_inst ) THEN
           nmoyct = 0
           !
@@ -385,6 +403,7 @@
           sm(:,:,:) = 0._wp
           fsel(:,:,:) = 0._wp
-       ENDIF
-    END IF
+          avtm(:,:,:) = O._wp
+       ENDIF
+    ENDIF
     !
 9000 FORMAT(a,"_",a,"_y",i4.4,"m",i2.2,"d",i2.2,".dimgproc")
@@ -405,7 +424,7 @@
     !!--------------------------------------------------------------------
 
-    IF (lwp) WRITE(numout,*) 'dia_wri_state: Dummy call', cdfile_name
-    IF (lwp) WRITE(numout,*) '-------------'
-    IF (lwp) WRITE(numout,*)
+    IF( lwp) WRITE(numout,*) 'dia_wri_state: Dummy call', cdfile_name
+    IF( lwp) WRITE(numout,*) '-------------'
+    IF( lwp) WRITE(numout,*)
 
   END SUBROUTINE dia_wri_state
