Index: /branches/dev_1784_WEEK/NEMO/OPA_SRC/DOM/daymod.F90
===================================================================
--- /branches/dev_1784_WEEK/NEMO/OPA_SRC/DOM/daymod.F90	(revision 2058)
+++ /branches/dev_1784_WEEK/NEMO/OPA_SRC/DOM/daymod.F90	(revision 2059)
@@ -67,4 +67,7 @@
       !!              - nmonth_len, nyear_len, nmonth_half, nmonth_end through day_mth
       !!----------------------------------------------------------------------
+      INTEGER :: inbday, irest
+      REAL(wp) :: zjul
+      !!----------------------------------------------------------------------
 
       ! all calendar staff is based on the fact that MOD( rday, rdttra(1) ) == 0
@@ -105,13 +108,23 @@
       ! day since january 1st
       nday_year = nday + SUM( nmonth_len(1:nmonth - 1) )
-      
+
+      !compute number of days between last monday and today      
+      IF( nn_leapy==1 )THEN
+         CALL ymds2ju( 1900, 01, 01, 0.0, zjul )  ! compute julian day value of 01.01.1900 (monday)
+         inbday = INT(fjulday) - NINT(zjul)       ! compute nb day between  01.01.1900 and current day fjulday 
+         irest = MOD(inbday,7)                    ! compute nb day between last monday and current day fjulday 
+         IF(irest==0 )irest = 7 
+      ENDIF
+
       ! number of seconds since the beginning of current year/month at the middle of the time-step
       nsec_year  = nday_year * nsecd - ndt05   ! 1 time step before the middle of the first time step
       nsec_month = nday      * nsecd - ndt05   ! because day will be called at the beginning of step
       nsec_day   =             nsecd - ndt05
+      nsec_week  = 0
+      IF( nn_leapy==1 ) nsec_week  = irest     * nsecd - ndt05
 
       ! control print
       IF(lwp) WRITE(numout,'(a,i6,a,i2,a,i2,a,i6)')' ==============>> 1/2 time step before the start of the run DATE Y/M/D = ',   &
-           &                   nyear, '/', nmonth, '/', nday, '  nsec_day:', nsec_day
+           &                   nyear, '/', nmonth, '/', nday, '  nsec_day:', nsec_day, '  nsec_week:', nsec_week
 
       ! Up to now, calendar parameters are related to the end of previous run (nit000-1)
@@ -200,4 +213,5 @@
       nsec_year  = nsec_year  + ndt 
       nsec_month = nsec_month + ndt                 
+      IF( nn_leapy==1 ) nsec_week  = nsec_week  + ndt
       nsec_day   = nsec_day   + ndt                
       adatrj  = adatrj  + rdttra(1) / rday
@@ -228,9 +242,14 @@
          ndastp = nyear * 10000 + nmonth * 100 + nday   ! NEW date
          !
+         !compute first day of the year in julian days
+         CALL ymds2ju( nyear, 01, 01, 0.0, fjulstartyear )
+         !
          IF(lwp) WRITE(numout,'(a,i8,a,i4.4,a,i2.2,a,i2.2,a,i3.3)') '======>> time-step =', kt,   &
               &   '      New day, DATE Y/M/D = ', nyear, '/', nmonth, '/', nday, '      nday_year = ', nday_year
          IF(lwp) WRITE(numout,'(a,i8,a,i7,a,i5)') '         nsec_year = ', nsec_year,   &
-              &   '   nsec_month = ', nsec_month, '   nsec_day = ', nsec_day
-      ENDIF
+              &   '   nsec_month = ', nsec_month, '   nsec_day = ', nsec_day, '   nsec_week = ', nsec_week
+      ENDIF
+
+      IF( nsec_week .GT. 7*86400 ) nsec_week = ndt05
       
       IF(ln_ctl) THEN
Index: /branches/dev_1784_WEEK/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- /branches/dev_1784_WEEK/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 2058)
+++ /branches/dev_1784_WEEK/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 2059)
@@ -195,15 +195,17 @@
    !! calendar variables
    !! ---------------------------------------------------------------------
-   INTEGER , PUBLIC ::   nyear       !: current year
-   INTEGER , PUBLIC ::   nmonth      !: current month
-   INTEGER , PUBLIC ::   nday        !: current day of the month
-   INTEGER , PUBLIC ::   ndastp      !: time step date in yyyymmdd format
-   INTEGER , PUBLIC ::   nday_year   !: current day counted from jan 1st of the current year
-   INTEGER , PUBLIC ::   nsec_year   !: current time step counted in second since 00h jan 1st of the current year
-   INTEGER , PUBLIC ::   nsec_month  !: current time step counted in second since 00h 1st day of the current month
-   INTEGER , PUBLIC ::   nsec_day    !: current time step counted in second since 00h of the current day
-   REAL(wp), PUBLIC ::   fjulday     !: julian day 
-   REAL(wp), PUBLIC ::   adatrj      !: number of elapsed days since the begining of the whole simulation
-   !                                 !: (cumulative duration of previous runs that may have used different time-step size)
+   INTEGER , PUBLIC ::   nyear         !: current year
+   INTEGER , PUBLIC ::   nmonth        !: current month
+   INTEGER , PUBLIC ::   nday          !: current day of the month
+   INTEGER , PUBLIC ::   ndastp        !: time step date in yyyymmdd format
+   INTEGER , PUBLIC ::   nday_year     !: current day counted from jan 1st of the current year
+   INTEGER , PUBLIC ::   nsec_year     !: current time step counted in second since 00h jan 1st of the current year
+   INTEGER , PUBLIC ::   nsec_month    !: current time step counted in second since 00h 1st day of the current month
+   INTEGER , PUBLIC ::   nsec_week     !: current time step counted in second since 00h of last monday
+   INTEGER , PUBLIC ::   nsec_day      !: current time step counted in second since 00h of the current day
+   REAL(wp), PUBLIC ::   fjulday       !: current julian day 
+   REAL(wp), PUBLIC ::   fjulstartyear !: first day of the current year in julian days
+   REAL(wp), PUBLIC ::   adatrj        !: number of elapsed days since the begining of the whole simulation
+   !                                   !: (cumulative duration of previous runs that may have used different time-step size)
    INTEGER , PUBLIC, DIMENSION(0: 1) ::   nyear_len     !: length in days of the previous/current year
    INTEGER , PUBLIC, DIMENSION(0:13) ::   nmonth_len    !: length in days of the months of the current year
Index: /branches/dev_1784_WEEK/NEMO/OPA_SRC/SBC/fldread.F90
===================================================================
--- /branches/dev_1784_WEEK/NEMO/OPA_SRC/SBC/fldread.F90	(revision 2058)
+++ /branches/dev_1784_WEEK/NEMO/OPA_SRC/SBC/fldread.F90	(revision 2059)
@@ -15,4 +15,5 @@
    USE oce             ! ocean dynamics and tracers
    USE dom_oce         ! ocean space and time domain
+   USE ioipsl, ONLY :   ymds2ju, ju2ymds   ! for calendar
    USE phycst          ! ???
    USE in_out_manager  ! I/O manager
@@ -29,5 +30,5 @@
       LOGICAL              ::   ln_tint     ! time interpolation or not (T/F)
       LOGICAL              ::   ln_clim     ! climatology or not (T/F)
-      CHARACTER(len = 7)   ::   cltype      ! type of data file 'daily', 'monthly' or yearly'
+      CHARACTER(len = 8)   ::   cltype      ! type of data file 'daily', 'monthly' or yearly'
       CHARACTER(len = 34)  ::   wname       ! generic name of a NetCDF weights file to be used, blank if not
       CHARACTER(len = 34)  ::   vcomp       ! symbolic component name if a vector that needs rotation
@@ -43,5 +44,5 @@
       LOGICAL                         ::   ln_tint      ! time interpolation or not (T/F)
       LOGICAL                         ::   ln_clim      ! climatology or not (T/F)
-      CHARACTER(len = 7)              ::   cltype       ! type of data file 'daily', 'monthly' or yearly'
+      CHARACTER(len = 8)              ::   cltype       ! type of data file 'daily', 'monthly' or yearly'
       INTEGER                         ::   num          ! iom id of the jpfld files to be read
       INTEGER                         ::   nswap_sec    ! swapping time in second since Jan. 1st 00h of nit000 year
@@ -159,7 +160,8 @@
                IF( sd(jf)%nfreqh == -1 ) THEN                  ;   ireclast = 12
                ELSE                             
-                  IF(     sd(jf)%cltype == 'monthly'   ) THEN  ;   ireclast = 24 * nmonth_len(nmonth) / sd(jf)%nfreqh 
-                  ELSEIF( sd(jf)%cltype == 'daily'     ) THEN  ;   ireclast = 24                      / sd(jf)%nfreqh
-                  ELSE                                         ;   ireclast = 24 * nyear_len(     1 ) / sd(jf)%nfreqh 
+                  IF(     sd(jf)%cltype      == 'monthly' ) THEN  ;   ireclast = 24 * nmonth_len(nmonth) / sd(jf)%nfreqh 
+                  ELSEIF( sd(jf)%cltype(1:4) == 'week'    ) THEN  ;   ireclast = 24.* 7                  / sd(jf)%nfreqh
+                  ELSEIF( sd(jf)%cltype      == 'daily'   ) THEN  ;   ireclast = 24                      / sd(jf)%nfreqh
+                  ELSE                                            ;   ireclast = 24 * nyear_len(     1 ) / sd(jf)%nfreqh 
                   ENDIF
                ENDIF
@@ -313,20 +315,25 @@
       TYPE(FLD), INTENT(inout) ::   sdjf        ! input field related variables
       !!
-      LOGICAL :: llprevyr       ! are we reading previous year  file?
-      LOGICAL :: llprevmth      ! are we reading previous month file?
-      LOGICAL :: llprevday      ! are we reading previous day   file?
-      LOGICAL :: llprev         ! llprevyr .OR. llprevmth .OR. llprevday
-      INTEGER :: idvar          ! variable id 
-      INTEGER :: inrec          ! number of record existing for this variable
+      LOGICAL :: llprevyr              ! are we reading previous year  file?
+      LOGICAL :: llprevmth             ! are we reading previous month file?
+      LOGICAL :: llprevweek            ! are we reading previous week file?
+      LOGICAL :: llprevday             ! are we reading previous day   file?
+      LOGICAL :: llprev                ! llprevyr .OR. llprevmth .OR. llprevday
+      INTEGER :: idvar                 ! variable id 
+      INTEGER :: inrec                 ! number of record existing for this variable
       INTEGER :: kwgt
+      INTEGER :: iyear, imonth, iday   ! first day of the current file in yyyy mm dd
+      INTEGER :: isec_week             ! number of seconds since start of the weekly file
       CHARACTER(LEN=1000) ::   clfmt   ! write format
       !!---------------------------------------------------------------------
-
+      
       ! some default definitions...
       sdjf%num = 0   ! default definition for non-opened file
       IF( sdjf%ln_clim )   sdjf%clname = TRIM( sdjf%clrootname )   ! file name defaut definition, never change in this case
-      llprevyr  = .FALSE.
-      llprevmth = .FALSE.
-      llprevday = .FALSE.
+      llprevyr   = .FALSE.
+      llprevmth  = .FALSE.
+      llprevweek = .FALSE.
+      llprevday  = .FALSE.
+      isec_week  = 0
             
       ! define record informations
@@ -350,4 +357,7 @@
                   llprevmth = .NOT. sdjf%ln_clim                                           ! use previous month file?
                   llprevyr  = llprevmth .AND. nmonth == 1                                  ! use previous year  file?
+               ELSE IF ( sdjf%cltype(1:4) == 'week' ) THEN !weekly file
+                  isec_week = 86400 * 7
+                  sdjf%nrec_b(1) = 24. / sdjf%nfreqh * 7                                   ! last record of previous weekly file
                ELSEIF( sdjf%cltype == 'daily' ) THEN ! daily file
                   sdjf%nrec_b(1) = 24 / sdjf%nfreqh                                        ! last record of previous day
@@ -361,10 +371,19 @@
             ENDIF
          ENDIF
-         llprev = llprevyr .OR. llprevmth .OR. llprevday
-
-         CALL fld_clopn( sdjf, nyear  - COUNT((/llprevyr /))                                              ,               &
-            &                  nmonth - COUNT((/llprevmth/)) + 12                   * COUNT((/llprevyr /)),               &
-            &                  nday   - COUNT((/llprevday/)) + nmonth_len(nmonth-1) * COUNT((/llprevmth/)), .NOT. llprev )
-         
+         llprev = llprevyr .OR. llprevmth .OR. llprevweek .OR. llprevday
+
+         IF ( sdjf%cltype(1:4) == 'week' ) THEN
+            isec_week  = ksec_week( sdjf%cltype(6:8) )
+            if(lwp)write(numout,*)'cbr test2 isec_week = ',isec_week
+            llprevmth  = ( isec_week .GT. nsec_month )
+            llprevyr   = llprevmth  .AND. nmonth==1
+         ENDIF
+         !
+         iyear  = nyear  - COUNT((/llprevyr /))
+         imonth = nmonth - COUNT((/llprevmth/)) + 12* COUNT((/llprevyr /))
+         iday   = nday   - COUNT((/llprevday/)) + nmonth_len(nmonth-1) * COUNT((/llprevmth/)) - INT( isec_week )/86400
+         !
+         CALL fld_clopn( sdjf , iyear , imonth , iday , .NOT. llprev )
+
          ! if previous year/month/day file does not exist, we switch to the current year/month/day
          IF( llprev .AND. sdjf%num == 0 ) THEN
@@ -399,8 +418,26 @@
       ENDIF
 
-      IF( sdjf%num == 0 )   CALL fld_clopn( sdjf, nyear, nmonth, nday )   ! make sure current year/month/day file is opened
+      ! make sure current year/month/day file is opened
+      IF( sdjf%num == 0 ) THEN
+         isec_week   = 0
+         llprevyr    = .FALSE.
+         llprevmth   = .FALSE.
+         llprevweek  = .FALSE.
+         !
+         IF ( sdjf%cltype(1:4) == 'week' ) THEN
+            isec_week  = ksec_week( sdjf%cltype(6:8) )
+            llprevmth  = ( isec_week .GT. nsec_month )
+            llprevyr   = llprevmth  .AND. nmonth==1
+         ENDIF
+         !
+         iyear  = nyear  - COUNT((/llprevyr /))
+         imonth = nmonth - COUNT((/llprevmth/)) + 12* COUNT((/llprevyr /))
+         iday   = nday   + nmonth_len(nmonth-1) * COUNT((/llprevmth/)) - isec_week/86400
+         !
+         CALL fld_clopn( sdjf, iyear, imonth, iday )
+      ENDIF 
 
       sdjf%nswap_sec = nsec_year + nsec1jan000 - 1   ! force read/update the after data in the following part of fld_read 
-      
+
    END SUBROUTINE fld_init
 
@@ -420,4 +457,5 @@
       REAL(wp) ::   ztmp        ! temporary variable
       INTEGER  ::   ifreq_sec   ! frequency mean (in seconds)
+      INTEGER  ::   isec_week   ! number of seconds since the start of the weekly file
       !!----------------------------------------------------------------------
       !
@@ -453,8 +491,10 @@
          !
          ifreq_sec = sdjf%nfreqh * 3600   ! frequency mean (in seconds)
+         IF( sdjf%cltype(1:4) == 'week'    ) isec_week = ksec_week( sdjf%cltype(6:8)) !since the first day of the current week
          ! number of second since the beginning of the file
-         IF(     sdjf%cltype == 'monthly' ) THEN   ;   ztmp = REAL(nsec_month,wp)   ! since 00h on the 1st day of the current month
-         ELSEIF( sdjf%cltype == 'daily'   ) THEN   ;   ztmp = REAL(nsec_day  ,wp)   ! since 00h of the current day
-         ELSE                                      ;   ztmp = REAL(nsec_year ,wp)   ! since 00h on Jan 1 of the current year
+         IF(     sdjf%cltype      == 'monthly' ) THEN   ;   ztmp = REAL(nsec_month ,wp)  ! since 00h on the 1st day of the current month
+         ELSEIF( sdjf%cltype(1:4) == 'week'    ) THEN   ;   ztmp = REAL(isec_week  ,wp)  ! since the first day of the current week
+         ELSEIF( sdjf%cltype      == 'daily'   ) THEN   ;   ztmp = REAL(nsec_day   ,wp)  ! since 00h of the current day
+         ELSE                                           ;   ztmp = REAL(nsec_year  ,wp)  ! since 00h on Jan 1 of the current year
          ENDIF
          IF( sdjf%ln_tint ) THEN                ! time interpolation, shift by 1/2 record
@@ -492,7 +532,9 @@
          ! after record index and second since Jan. 1st 00h of nit000 year
          sdjf%nrec_a(:) = (/ irec, ifreq_sec * irec - ifreq_sec / 2 + nsec1jan000 /)
-         IF( sdjf%cltype == 'monthly' )   &   ! add the number of seconds between 00h Jan 1 and the end of previous month
+         IF( sdjf%cltype == 'monthly' )       &   ! add the number of seconds between 00h Jan 1 and the end of previous month
             sdjf%nrec_a(2) = sdjf%nrec_a(2) + isecd * SUM(nmonth_len(1:nmonth -1))   ! ok if nmonth=1
-         IF( sdjf%cltype == 'daily'   )   &   ! add the number of seconds between 00h Jan 1 and the end of previous day
+         IF( sdjf%cltype(1:4) == 'week'   )   &   ! add the number of seconds between 00h Jan 1 and the end of previous week 
+            sdjf%nrec_a(2) = sdjf%nrec_a(2) + ( nsec_year - isec_week )
+         IF( sdjf%cltype == 'daily'   )       &   ! add the number of seconds between 00h Jan 1 and the end of previous day
             sdjf%nrec_a(2) = sdjf%nrec_a(2) + isecd * ( nday_year - 1 )
 
@@ -500,7 +542,9 @@
          irec = irec - 1.                           ! move back to previous record
          sdjf%nrec_b(:) = (/ irec, ifreq_sec * irec - ifreq_sec / 2 + nsec1jan000 /)
-         IF( sdjf%cltype == 'monthly' )   &   ! add the number of seconds between 00h Jan 1 and the end of previous month
+         IF( sdjf%cltype == 'monthly' )       &   ! add the number of seconds between 00h Jan 1 and the end of previous month
             sdjf%nrec_b(2) = sdjf%nrec_b(2) + isecd * SUM(nmonth_len(1:nmonth -1))   ! ok if nmonth=1
-         IF( sdjf%cltype == 'daily'   )   &   ! add the number of seconds between 00h Jan 1 and the end of previous day
+         IF( sdjf%cltype(1:4) == 'week'   )   &   ! add the number of seconds between 00h Jan 1 and the end of previous week
+            sdjf%nrec_b(2) = sdjf%nrec_b(2) + ( nsec_year - isec_week )
+         IF( sdjf%cltype == 'daily'   )       &   ! add the number of seconds between 00h Jan 1 and the end of previous day
             sdjf%nrec_b(2) = sdjf%nrec_b(2) + isecd * ( nday_year - 1 )
 
@@ -523,15 +567,24 @@
       !! ** Method  :   
       !!----------------------------------------------------------------------
-      TYPE(FLD), INTENT(inout)           ::   sdjf     ! input field related variables
-      INTEGER  , INTENT(in   )           ::   kyear    ! year value
-      INTEGER  , INTENT(in   )           ::   kmonth   ! month value
-      INTEGER  , INTENT(in   )           ::   kday     ! day value
-      LOGICAL  , INTENT(in   ), OPTIONAL ::   ldstop   ! stop if open to read a non-existing file (default = .TRUE.)
+      TYPE(FLD), INTENT(inout)           ::   sdjf                      ! input field related variables
+      INTEGER  , INTENT(in   )           ::   kyear                     ! year value
+      INTEGER  , INTENT(in   )           ::   kmonth                    ! month value
+      INTEGER  , INTENT(in   )           ::   kday                      ! day value
+      LOGICAL  , INTENT(in   ), OPTIONAL ::   ldstop                    ! stop if open to read a non-existing file (default = .TRUE.)
+      INTEGER                            ::   iyear, imonth, iday       ! firt day of the current week in yyyy mm dd
+      REAL(wp)                           ::   zsec, zjul                !temp variable
 
       IF( sdjf%num /= 0 )   CALL iom_close( sdjf%num )   ! close file if already open
       ! build the new filename if not climatological data
-      IF( .NOT. sdjf%ln_clim ) THEN   ;   WRITE(sdjf%clname, '(a,"_y",i4.4)' ) TRIM( sdjf%clrootname ), kyear    ! add year
-         IF( sdjf%cltype /= 'yearly' )    WRITE(sdjf%clname, '(a,"m" ,i2.2)' ) TRIM( sdjf%clname     ), kmonth   ! add month
-         IF( sdjf%cltype == 'daily'  )    WRITE(sdjf%clname, '(a,"d" ,i2.2)' ) TRIM( sdjf%clname     ), kday     ! add day
+      sdjf%clname=TRIM(sdjf%clrootname)
+      !
+      IF(  sdjf%cltype(1:4) == 'week' .AND. nn_leapy==0 )CALL ctl_stop( 'fld_clopn: weekly file and nn_leapy=0 are not compatible' )
+      !
+      IF( .NOT. sdjf%ln_clim ) THEN   
+         WRITE(sdjf%clname, '(a,"_y",i4.4)' ) TRIM( sdjf%clrootname ), kyear    ! add year
+         IF( sdjf%cltype /= 'yearly'        )   & 
+            &     WRITE(sdjf%clname, '(a,"m" ,i2.2)' ) TRIM( sdjf%clname ), kmonth   ! add month
+         IF( sdjf%cltype == 'daily'  .OR. sdjf%cltype(1:4) == 'week' ) &
+            &     WRITE(sdjf%clname, '(a,"d" ,i2.2)' ) TRIM( sdjf%clname ), kday     ! add day
       ENDIF
       CALL iom_open( sdjf%clname, sdjf%num, ldstop = ldstop, ldiof =  LEN(TRIM(sdjf%wgtname)) > 0 )
@@ -998,4 +1051,33 @@
 
    END SUBROUTINE fld_interp
-  
+
+   FUNCTION ksec_week( cdday )
+      !!---------------------------------------------------------------------
+      !!                    ***  FUNCTION kshift_week *** 
+      !!
+      !! ** Purpose :  
+      !!
+      !! ** Method  :
+      !!---------------------------------------------------------------------
+      CHARACTER(len=*), INTENT(in)   ::   cdday   !3 first letters of the first day of the weekly file
+      !!
+      INTEGER                        ::   ksec_week  ! output variable
+      INTEGER                        ::   ijul       !temp variable
+      INTEGER                        ::   ishift     !temp variable
+      CHARACTER(len=3),DIMENSION(7)  ::   cl_week 
+      !!----------------------------------------------------------------------
+      cl_week = (/"sun","sat","fri","thu","wed","tue","mon"/)
+      DO ijul=1,7
+         IF(  cl_week(ijul)==TRIM(cdday) ) EXIT
+      ENDDO
+      IF( ijul .GT. 7 ) CALL ctl_stop( 'ksec_week: wrong day for sdjf%cltype(6:8): ',TRIM(cdday) )
+      !
+      ishift = ( ijul  ) * 86400
+      ! 
+      ksec_week = nsec_week + ishift
+      ksec_week = MOD( ksec_week , 86400*7 )
+      if(lwp)write(numout,*)'cbr ijul ksec_week ',ijul,ksec_week
+      ! 
+   END FUNCTION ksec_week
+
 END MODULE fldread
