Index: trunk/NEMO/OFF_SRC/DIA/dianam.F90
===================================================================
--- trunk/NEMO/OFF_SRC/DIA/dianam.F90	(revision 1715)
+++ trunk/NEMO/OFF_SRC/DIA/dianam.F90	(revision 1734)
@@ -30,5 +30,5 @@
 CONTAINS
 
-   SUBROUTINE dia_nam( cdfnam, kfreq, cdsuff )
+   SUBROUTINE dia_nam( cdfnam, kfreq, cdsuff, ldfsec )
       !!---------------------------------------------------------------------
       !!                  ***  ROUTINE dia_nam  ***
@@ -42,56 +42,73 @@
       !!
       !!----------------------------------------------------------------------
-      CHARACTER (len=*), INTENT(  out) ::   cdfnam           ! file name
-      CHARACTER (len=*), INTENT(in   ) ::   cdsuff           ! to be added at the end of the file name
-      INTEGER,           INTENT(in   ) ::   kfreq            ! output frequency (in time-step): < 0 for monthly outputs
-      !                                                                                         0 if no frequency
-      CHARACTER (len=20) ::   clfmt, clfmt0                       ! writing format
-      CHARACTER (len=20) ::   clave                               ! name for output frequency
-      CHARACTER (len=20) ::   cldate1                             ! date of the beginning of run
-      CHARACTER (len=20) ::   cldate2                             ! date of the end       of run
-      INTEGER            ::   iyear1, imonth1, iday1              ! year, month, day of the first day of the run
-      INTEGER            ::   iyear2, imonth2, iday2              ! year, month, day of the last  day of the run
-      INTEGER            ::   indg                                ! number of digits needed to write a number     
-      INTEGER            ::   inbsec, inbmn, inbhr, inbday, inbyr ! output frequency in seconds, minutes, hours, days and years
-      INTEGER            ::   iddss, ihhss, immss                 ! number of seconds in 1 day, 1 hour and 1 minute
-      REAL(wp)           ::   zsec1, zsec2                        ! not used
-      REAL(wp)           ::   zdrun, zjul                         ! temporary scalars
+      CHARACTER (len=*), INTENT(  out)           ::   cdfnam   ! file name
+      CHARACTER (len=*), INTENT(in   )           ::   cdsuff   ! to be added at the end of the file name
+      INTEGER          , INTENT(in   )           ::   kfreq    ! output frequency: > 0 in time-step (or seconds see ldfsec)
+      !                                                                            < 0 in months
+      !                                                                            = 0 no frequency
+      LOGICAL          , INTENT(in   ), OPTIONAL ::   ldfsec   ! kfreq in second(in time-step) if .true.(.false. default)
+      !
+      CHARACTER (len=20) ::   clfmt, clfmt0                    ! writing format
+      CHARACTER (len=20) ::   clave                            ! name for output frequency
+      CHARACTER (len=20) ::   cldate1                          ! date of the beginning of run
+      CHARACTER (len=20) ::   cldate2                          ! date of the end       of run
+      LOGICAL            ::   llfsec                           ! local value of ldfsec
+      INTEGER            ::   iyear1, imonth1, iday1           ! year, month, day of the first day of the run
+      INTEGER            ::   iyear2, imonth2, iday2           ! year, month, day of the last  day of the run
+      INTEGER            ::   indg                             ! number of digits needed to write a number     
+      INTEGER            ::   inbsec, inbmn, inbhr             ! output frequency in seconds, minutes and hours
+      INTEGER            ::   inbday, inbmo, inbyr             ! output frequency in days, months and years
+      INTEGER            ::   iyyss, iddss, ihhss, immss       ! number of seconds in 1 year, 1 day, 1 hour and 1 minute
+      INTEGER            ::   iyymo                            ! number of months in 1 year
+      REAL(wp)           ::   zsec1, zsec2                     ! not used
+      REAL(wp)           ::   zdrun, zjul                      ! temporary scalars
       !!----------------------------------------------------------------------
-
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*) ' dia_nam: building output file name'
-      IF(lwp) WRITE(numout,*) ' ~~~~~~~'
-      IF(lwp) WRITE(numout,*)
 
       ! name for output frequency
 
-      inbsec = kfreq * NINT( rdttra(1) )                                    ! output frequency in seconds
+      IF( PRESENT(ldfsec) ) THEN   ;   llfsec = ldfsec
+      ELSE                         ;   llfsec = .FALSE.
+      ENDIF
+
+      IF( llfsec .OR. kfreq < 0 ) THEN   ;   inbsec = kfreq                       ! output frequency already in seconds
+      ELSE                               ;   inbsec = kfreq * NINT( rdttra(1) )   ! from time-step to seconds
+      ENDIF
       iddss = NINT( rday          )                                         ! number of seconds in 1 day
       ihhss = NINT( rmmss * rhhmm )                                         ! number of seconds in 1 hour
       immss = NINT( rmmss         )                                         ! number of seconds in 1 minute
+      iyymo = NINT( raamo         )                                         ! number of months  in 1 year
+      iyyss = iddss * nyear_len(1)                                          ! seconds in 1 year (not good: multi years with leap)
       clfmt0 = "('(a,i',i1,',a)')"                                          ! format '(a,ix,a)' with x to be defined
       ! 
       IF(          inbsec == 0           ) THEN   ;   clave = ''            ! no frequency
-      ELSEIF(      inbsec <  0           ) THEN   ;   clave = '_1m'         ! frequency in month
+      ELSEIF(      inbsec <  0           ) THEN        
+         inbmo = -inbsec                                                    ! frequency in month
+         IF( MOD( inbmo, iyymo  ) == 0 ) THEN                               ! frequency in years
+            inbyr  = inbmo / iyymo
+            indg   = INT(LOG10(REAL(inbyr,wp))) + 1                         ! number of digits needed to write years   frequency
+            WRITE(clfmt, clfmt0) indg             ;   WRITE(clave, clfmt) '_', inbyr , 'y'
+         ELSE                                                               ! frequency in month
+            indg   = INT(LOG10(REAL(inbmo,wp))) + 1                         ! number of digits needed to write months  frequency
+            WRITE(clfmt, clfmt0) indg             ;   WRITE(clave, clfmt) '_', inbmo, 'm'
+         ENDIF
+      ELSEIF( MOD( inbsec, iyyss  ) == 0 ) THEN                             ! frequency in years
+         inbyr  = inbsec / iyyss
+         indg   = INT(LOG10(REAL(inbyr ,wp))) + 1                           ! number of digits needed to write years   frequency
+         WRITE(clfmt, clfmt0) indg                ;   WRITE(clave, clfmt) '_', inbyr , 'y'
       ELSEIF( MOD( inbsec, iddss  ) == 0 ) THEN                             ! frequency in days
          inbday = inbsec / iddss
-         indg = INT(LOG10(REAL(inbday,wp))) + 1                             ! number of digits needed to write days    frequency
+         indg   = INT(LOG10(REAL(inbday,wp))) + 1                           ! number of digits needed to write days    frequency
          WRITE(clfmt, clfmt0) indg                ;   WRITE(clave, clfmt) '_', inbday, 'd'
          IF( inbday == nmonth_len(nmonth) )           clave = '_1m'
-         IF( MOD( inbday, nyear_len(1) ) == 0 ) THEN                        ! frequency in years
-            inbyr = inbday / nyear_len(1)
-            indg  = INT(LOG10(REAL(inbyr ,wp))) + 1                         ! number of digits needed to write years   frequency
-            WRITE(clfmt, clfmt0) indg                ;   WRITE(clave, clfmt) '_', inbyr, 'y'
-         ENDIF
       ELSEIF( MOD( inbsec, ihhss ) == 0 ) THEN                              ! frequency in hours
-         inbhr = inbsec / ihhss
-         indg = INT(LOG10(REAL(inbhr ,wp))) + 1                             ! number of digits needed to write hours   frequency
-         WRITE(clfmt, clfmt0) indg                ;   WRITE(clave, clfmt) '_', inbhr, 'h'
+         inbhr  = inbsec / ihhss
+         indg   = INT(LOG10(REAL(inbhr ,wp))) + 1                           ! number of digits needed to write hours   frequency
+         WRITE(clfmt, clfmt0) indg                ;   WRITE(clave, clfmt) '_', inbhr , 'h'
       ELSEIF( MOD( inbsec, immss ) == 0 ) THEN                              ! frequency in minutes
-         inbmn = inbsec / immss
-         indg = INT(LOG10(REAL(inbmn ,wp))) + 1                             ! number of digits needed to write minutes frequency
-         WRITE(clfmt, clfmt0) indg                ;   WRITE(clave, clfmt) '_', inbmn, 'mn'
+         inbmn  = inbsec / immss
+         indg   = INT(LOG10(REAL(inbmn ,wp))) + 1                           ! number of digits needed to write minutes frequency
+         WRITE(clfmt, clfmt0) indg                ;   WRITE(clave, clfmt) '_', inbmn , 'mn'
       ELSE                                                                  ! frequency in seconds
-         indg = INT(LOG10(REAL(inbsec,wp))) + 1                             ! number of digits needed to write seconds frequency
+         indg   = INT(LOG10(REAL(inbsec,wp))) + 1                           ! number of digits needed to write seconds frequency
          WRITE(clfmt, clfmt0) indg                ;   WRITE(clave, clfmt) '_', inbsec, 's'
       ENDIF
@@ -116,7 +133,4 @@
 #endif    
 
-      IF(lwp) WRITE(numout,*) cdfnam     
-      IF(lwp) WRITE(numout,*)          
-
    END SUBROUTINE dia_nam
 
