Index: /tags/nemo_v3_2/NEMO/OPA_SRC/DIA/diadimg.F90
===================================================================
--- /tags/nemo_v3_2/NEMO/OPA_SRC/DIA/diadimg.F90	(revision 1814)
+++ /tags/nemo_v3_2/NEMO/OPA_SRC/DIA/diadimg.F90	(revision 1815)
@@ -10,4 +10,5 @@
    USE dom_oce         ! ocean space and time domain
    USE in_out_manager  ! I/O manager
+   USE daymod          ! calendar
 
    IMPLICIT NONE
@@ -21,5 +22,5 @@
    !!----------------------------------------------------------------------
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
-   !! $Id$ 
+   !! $Header$ 
    !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
    !!----------------------------------------------------------------------
@@ -56,6 +57,7 @@
     INTEGER :: jk, jn           ! dummy loop indices
     INTEGER :: irecl4,             &    ! record length in bytes
-         &       inum,             &    ! logical unit
-         &       irec                   ! current record to be written
+         &       inum,             &    ! logical unit (set to 14)
+         &       irec,             &    ! current record to be written
+         &       irecend                ! record number where nclit... are stored
     REAL(sp)                    :: zdx,zdy,zspval,zwest,ztimm
     REAL(sp)                    :: zsouth
@@ -69,5 +71,5 @@
     !! * Initialisations
 
-    irecl4 = MAX(jpi*jpj*sp , 84+18*sp + (jpk+8)*jpnij*sp  )
+    irecl4 = MAX(jpi*jpj*sp , 84+(18+1+jpk)*sp )
 
     zspval=0.0_sp    ! special values on land
@@ -101,6 +103,7 @@
 
     IF ( ln_dimgnnn  ) THEN
+     irecl4 = MAX(jpi*jpj*sp , 84+(18+jpk)*sp + 8*jpnij*sp  )
        WRITE(clname,'(a,a,i3.3)') TRIM(cd_name),'.',narea
-       CALL ctl_opn( inum, clname, 'REPLACE', 'UNFORMATTED', 'DIRECT', irecl4, numout, lwp )
+       CALL ctl_opn(inum, clname,'UNKNOWN','UNFORMATTED','DIRECT',irecl4,numout,lwp)
        WRITE(inum,REC=1 ) clver, cd_text, irecl4, &
             &     jpi,jpj, klev, 1 , 1 ,            &
@@ -127,16 +130,36 @@
        ENDIF
     ELSE
+       clver='@!03'           ! dimg string identifier
+       ! note that version @!02 is optimized with respect to record length.
+       ! The vertical dep variable is reduced to klev instead of klev*jpnij :
+       !   this is OK for jpnij < 181 (jpk=46)
+       ! for more processors, irecl4 get huge and that's why we switch to '@!03':
+       !  In this case we just add an extra integer to the standard dimg structure,
+       !  which is a record number where the arrays nlci etc... starts (1 per record)
+       
        !! Standard dimgproc (1 file per variable, all procs. write to this file )
        !! * Open file
-       CALL ctl_opn( inum, cd_name, 'REPLACE', 'UNFORMATTED', 'DIRECT', irecl4, numout, lwp )
+       CALL ctl_opn(inum, cd_name,'UNKNOWN','UNFORMATTED','DIRECT',irecl4,numout,lwp)
 
        !! * Write header on record #1
+       irecend=1 + klev*jpnij 
        IF(lwp) WRITE(inum,REC=1 ) clver, cd_text, irecl4, &
-            &     jpi,jpj, klev*jpnij, 1 , 1 ,            &
+            &     jpi,jpj, klev, 1 , 1 ,            &
             &     zwest, zsouth, zdx, zdy, zspval,  &
-            &     (z4dep(1:klev),jn=1,jpnij),       &
+            &     z4dep(1:klev),       &
             &     ztimm,                            &
-            &     narea, jpnij,jpiglo,jpjglo,jpizoom, jpjzoom,    &    ! extension to dimg for mpp output
-            &     nlcit,nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt  !
+            &     narea, jpnij,jpiglo,jpjglo,jpizoom, jpjzoom, irecend 
+       IF (lwp ) THEN
+         WRITE(inum,REC=irecend + 1 ) nlcit
+         WRITE(inum,REC=irecend + 2 ) nlcjt
+         WRITE(inum,REC=irecend + 3 ) nldit
+         WRITE(inum,REC=irecend + 4 ) nldjt
+         WRITE(inum,REC=irecend + 5 ) nleit
+         WRITE(inum,REC=irecend + 6 ) nlejt
+         WRITE(inum,REC=irecend + 7 ) nimppt
+         WRITE(inum,REC=irecend + 8 ) njmppt
+       ENDIF
+      !   &    ! extension to dimg for mpp output
+      !   &     nlcit,nlcjt, nldit, nldjt, nleit, nlejt, nimppt, njmppt  !
 
        !! * Write klev levels
