Index: /branches/2015/dev_r5204_CNRS_PISCES_dcy/NEMOGCM/CONFIG/SHARED/namelist_ref
===================================================================
--- /branches/2015/dev_r5204_CNRS_PISCES_dcy/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 5326)
+++ /branches/2015/dev_r5204_CNRS_PISCES_dcy/NEMOGCM/CONFIG/SHARED/namelist_ref	(revision 5327)
@@ -420,4 +420,8 @@
    ln_rnf_tem   = .false.   !  read in temperature information for runoff
    ln_rnf_sal   = .false.   !  read in salinity information for runoff
+   ln_rnf_depth_ini = .false.  ! compute depth at initialisation from runoff file
+   rn_rnf_max   = 5.735e-4  !  max value of the runoff climatologie over global domain ( ln_rnf_depth_ini = .true )
+   rn_dep_max   = 150.      !  depth over which runoffs is spread ( ln_rnf_depth_ini = .true )
+   nn_rnf_depth_file = 0    !  create (=1) a runoff depth file or not (=0)
 /
 !-----------------------------------------------------------------------
Index: /branches/2015/dev_r5204_CNRS_PISCES_dcy/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90
===================================================================
--- /branches/2015/dev_r5204_CNRS_PISCES_dcy/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90	(revision 5326)
+++ /branches/2015/dev_r5204_CNRS_PISCES_dcy/NEMOGCM/NEMO/OPA_SRC/SBC/sbcrnf.F90	(revision 5327)
@@ -37,5 +37,9 @@
    !                                                     !!* namsbc_rnf namelist *
    CHARACTER(len=100), PUBLIC ::   cn_dir          !: Root directory for location of ssr files
-   LOGICAL           , PUBLIC ::   ln_rnf_depth    !: depth       river runoffs attribute specified in a file
+   LOGICAL           , PUBLIC ::   ln_rnf_depth      !: depth       river runoffs attribute specified in a file
+   LOGICAL                    ::   ln_rnf_depth_ini  !: depth       river runoffs  computed at the initialisation
+   REAL(wp)                   ::   rn_rnf_max        !: maximum value of the runoff climatologie ( ln_rnf_depth_ini = .true )
+   REAL(wp)                   ::   rn_dep_max        !: depth over which runoffs is spread ( ln_rnf_depth_ini = .true )
+   INTEGER                    ::   nn_rnf_depth_file !: create (=1) a runoff depth file or not (=0)
    LOGICAL           , PUBLIC ::   ln_rnf_tem      !: temperature river runoffs attribute specified in a file
    LOGICAL           , PUBLIC ::   ln_rnf_sal      !: salinity    river runoffs attribute specified in a file
@@ -104,4 +108,7 @@
       !
       CALL wrk_alloc( jpi,jpj, ztfrz)
+
+      !
+      IF( kt == nit000 )   CALL sbc_rnf_init                           ! Read namelist and allocate structures
 
       !                                            ! ---------------------------------------- !
@@ -252,11 +259,17 @@
       !!----------------------------------------------------------------------
       CHARACTER(len=32) ::   rn_dep_file   ! runoff file name
-      INTEGER           ::   ji, jj, jk    ! dummy loop indices
+      INTEGER           ::   ji, jj, jk, jm    ! dummy loop indices
       INTEGER           ::   ierror, inum  ! temporary integer
       INTEGER           ::   ios           ! Local integer output status for namelist read
+      INTEGER           ::   nbrec         ! temporary integer
+      REAL(wp)          ::   zacoef  
+      REAL(wp), DIMENSION(12)                 :: zrec             ! times records
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: zrnfcl    
+      REAL(wp), DIMENSION(:,:  ), ALLOCATABLE :: zrnf
       !
       NAMELIST/namsbc_rnf/ cn_dir, ln_rnf_emp, ln_rnf_depth, ln_rnf_tem, ln_rnf_sal,   &
          &                 sn_rnf, sn_cnf    , sn_s_rnf    , sn_t_rnf  , sn_dep_rnf,   &
-         &                 ln_rnf_mouth      , rn_hrnf     , rn_avt_rnf, rn_rfact
+         &                 ln_rnf_mouth      , rn_hrnf     , rn_avt_rnf, rn_rfact,     &
+         &                 ln_rnf_depth_ini  , rn_dep_max  , rn_rnf_max, nn_rnf_depth_file
       !!----------------------------------------------------------------------
       !
@@ -296,7 +309,7 @@
          IF(lwp) WRITE(numout,*)
          IF(lwp) WRITE(numout,*) '          runoffs directly provided in the precipitations'
-         IF( ln_rnf_depth .OR. ln_rnf_tem .OR. ln_rnf_sal ) THEN
+         IF( ln_rnf_depth .OR. ln_rnf_tem .OR. ln_rnf_sal .OR. ln_rnf_depth_ini ) THEN
            CALL ctl_warn( 'runoffs already included in precipitations, so runoff (T,S, depth) attributes will not be used' )
-           ln_rnf_depth = .FALSE.   ;   ln_rnf_tem = .FALSE.   ;   ln_rnf_sal = .FALSE.
+           ln_rnf_depth = .FALSE.   ;   ln_rnf_tem = .FALSE.   ;   ln_rnf_sal = .FALSE.  ;   ln_rnf_depth_ini = .FALSE.
          ENDIF
          !
@@ -372,4 +385,68 @@
                END DO
             END DO
+            !
+         ELSE IF( ln_rnf_depth_ini ) THEN           ! runoffs applied at the surface
+            !
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '    depth of runoff computed once from max value of runoff'
+            IF(lwp) WRITE(numout,*) '    max value of the runoff climatologie (over global domain) rn_rnf_max = ', rn_rnf_max
+            IF(lwp) WRITE(numout,*) '    depth over which runoffs is spread                        rn_dep_max = ', rn_dep_max
+            IF(lwp) WRITE(numout,*) '     create (=1) a runoff depth file or not (=0)      nn_rnf_depth_file  = ', nn_rnf_depth_file
+
+            CALL iom_open( TRIM( sn_rnf%clname ), inum )    !  open runoff file
+            CALL iom_gettime( inum, zrec, kntime=nbrec)
+            ALLOCATE( zrnfcl(jpi,jpj,nbrec) )     ;      ALLOCATE( zrnf(jpi,jpj) )
+            DO jm = 1, nbrec
+               CALL iom_get( inum, jpdom_data, TRIM( sn_rnf%clvar ), zrnfcl(:,:,jm), jm )
+            END DO
+            CALL iom_close( inum )
+            zrnf(:,:) = MAXVAL( zrnfcl(:,:,:), DIM=3 )   !  maximum value in time
+            DEALLOCATE( zrnfcl )
+            !
+            h_rnf(:,:) = 1.
+            !
+            zacoef = rn_dep_max / rn_rnf_max            ! coef of linear relation between runoff and its depth (150m for max of runoff)
+            !
+            WHERE( zrnf(:,:) > 0._wp )  h_rnf(:,:) = zacoef * zrnf(:,:)   ! compute depth for all runoffs
+            !
+            DO jj = 1, jpj                     ! take in account min depth of ocean rn_hmin
+               DO ji = 1, jpi
+                  IF( zrnf(ji,jj) > 0._wp ) THEN
+                     jk = mbkt(ji,jj)
+                     h_rnf(ji,jj) = MIN( h_rnf(ji,jj), gdept_0(ji,jj,jk ) )
+                  ENDIF
+               END DO
+            END DO
+            !
+            nk_rnf(:,:) = 0                       ! number of levels on which runoffs are distributed
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                   IF( zrnf(ji,jj) > 0._wp ) THEN
+                     jk = 2
+                     DO WHILE ( jk /= mbkt(ji,jj) .AND. gdept_0(ji,jj,jk) < h_rnf(ji,jj) ) ;  jk = jk + 1 ;  END DO
+                     nk_rnf(ji,jj) = jk
+                   ELSE
+                     nk_rnf(ji,jj) = 1
+                   ENDIF
+                END DO
+            END DO
+            !
+            DEALLOCATE( zrnf )
+            !
+            DO jj = 1, jpj                                ! set the associated depth
+               DO ji = 1, jpi
+                  h_rnf(ji,jj) = 0._wp
+                  DO jk = 1, nk_rnf(ji,jj)
+                     h_rnf(ji,jj) = h_rnf(ji,jj) + fse3t(ji,jj,jk)
+                  END DO
+               END DO
+            END DO
+            !
+            IF( nn_rnf_depth_file == 1 ) THEN      !  save  output nb levels for runoff
+               IF(lwp) WRITE(numout,*) '              create runoff depht file'
+               CALL iom_open  ( TRIM( sn_dep_rnf%clname ), inum, ldwrt = .TRUE., kiolib = jprstlib )
+               CALL iom_rstput( 0, 0, inum, 'rodepth', h_rnf )
+               CALL iom_close ( inum )
+            ENDIF
          ELSE                                       ! runoffs applied at the surface
             nk_rnf(:,:) = 1
