Index: branches/UKMO/r6232_new_runoff_coupling/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90
===================================================================
--- branches/UKMO/r6232_new_runoff_coupling/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90	(revision 11448)
+++ branches/UKMO/r6232_new_runoff_coupling/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90	(revision 11452)
@@ -24,5 +24,5 @@
    !!   cpl_finalize : finalize the coupled mode communication
    !!----------------------------------------------------------------------
-#if defined key_oasis3
+#if defined key_oasis3 || defined key_oasis3mct
    USE mod_oasis                    ! OASIS3-MCT module
 #endif
@@ -46,5 +46,5 @@
    INTEGER                    ::   ncomp_id          ! id returned by oasis_init_comp
    INTEGER                    ::   nerror            ! return error code
-#if ! defined key_oasis3
+#if ! defined key_oasis3 && ! defined key_oasis3mct
    ! OASIS Variables not used. defined only for compilation purpose
    INTEGER                    ::   OASIS_Out         = -1
@@ -69,4 +69,7 @@
    INTEGER, PUBLIC, PARAMETER ::   nmaxcpl=5    ! Maximum number of coupling fields
    
+   INTEGER, PUBLIC            ::   nn_cpl_river=0 ! Maximum number of rivers being passed through the coupler
+   INTEGER, PUBLIC            ::   runoff_id      ! OASIS coupling id used in oasis_get command
+
    TYPE, PUBLIC ::   FLD_CPL               !: Type for coupling field information
       LOGICAL               ::   laction   ! To be coupled or not
@@ -136,5 +139,6 @@
       INTEGER, INTENT(in) ::   kcplmodel      ! Maximum number of models to/from which NEMO is potentialy sending/receiving data
       !
-      INTEGER :: id_part
+      INTEGER :: id_part        ! Partition for all 2D model fields to be coupled
+      INTEGER :: id_part_rnf_1d ! Partition for river runoff using 1D array
       INTEGER :: paral(5)       ! OASIS3 box partition
       INTEGER :: ishape(2,2)    ! shape of arrays passed to PSMILe
@@ -198,4 +202,12 @@
       CALL oasis_def_partition ( id_part, paral, nerror )
       !
+      ! Another partition is needed for river runoff when using 1D array
+      paral(1) = 0                                              ! serial partitioning
+      paral(2) = 0   
+      paral(3) = nn_cpl_river                                       ! size of array to couple
+      paral(4) = 0
+      paral(5) = 0
+
+      CALL oasis_def_partition ( id_part_rnf_1d, paral, nerror, nn_cpl_river )
       ! ... Announce send variables. 
       !
@@ -289,4 +301,12 @@
       END DO
       
+      ! Define coupled river runoff using 1D array
+      CALL oasis_def_var (runoff_id, 'runoffo', id_part_rnf_1d, (/ 1, 0 /),   &
+                     &                OASIS_In           , (/ 1, nn_cpl_river /) , OASIS_REAL, nerror )
+      IF ( nerror /= OASIS_Ok ) THEN
+          WRITE(numout,*) 'Failed to define transient runoffo'
+          CALL oasis_abort ( runoff_id, 'cpl_define', 'Failure in oasis_def_var' )
+      ENDIF
+
       !------------------------------------------------------------------
       ! End of definition phase
@@ -514,7 +534,8 @@
    END SUBROUTINE oasis_get_localcomm
 
-   SUBROUTINE oasis_def_partition(k1,k2,k3)
-      INTEGER     , INTENT(  out) ::  k1,k3
-      INTEGER     , INTENT(in   ) ::  k2(5)
+   SUBROUTINE oasis_def_partition(k1,k2,k3,k4)
+      INTEGER          , INTENT(  out) ::  k1,k3
+      INTEGER          , INTENT(in   ) ::  k2(5)
+      INTEGER, OPTIONAL, INTENT(in   ) ::  k4
       k1 = k2(1) ; k3 = k2(5)
       WRITE(numout,*) 'oasis_def_partition: Error you sould not be there...'
Index: branches/UKMO/r6232_new_runoff_coupling/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_rnf_1d.F90
===================================================================
--- branches/UKMO/r6232_new_runoff_coupling/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_rnf_1d.F90	(revision 11452)
+++ branches/UKMO/r6232_new_runoff_coupling/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_rnf_1d.F90	(revision 11452)
@@ -0,0 +1,209 @@
+MODULE cpl_rnf_1d
+   !!======================================================================
+   !!                       ***  MODULE  cpl_rnf_1d  ***
+   !! Ocean forcing:  River runoff passed from the atmosphere using
+   !!                 1D array. One value per river.
+   !!=====================================================================
+   !! History : ?.?  ! 2018-01 (D. Copsey) Initial setup
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   cpl_rnf_1d_init : runoffs initialisation
+   !!---------------------------------------------------------------------- 
+
+#if defined key_oasis3 || defined key_oasis3mct
+   USE mod_oasis                    ! OASIS3-MCT module
+#endif
+   USE cpl_oasis3
+   USE timing          ! Timing
+   USE in_out_manager  ! I/O units
+   USE lib_mpp         ! MPP library
+   USE iom
+   USE wrk_nemo        ! Memory allocation
+   USE dom_oce         ! Domain sizes (for grid box area e1e2t)
+   USE sbc_oce         ! Surface boundary condition: ocean fields
+   USE lib_fortran,    ONLY: DDPDD
+   
+   IMPLICIT NONE
+   PRIVATE
+   
+   PUBLIC   cpl_rnf_1d_init     ! routine called in nemo_init
+   PUBLIC   cpl_rnf_1d_rcv      ! routine called in sbccpl.F90
+   
+   TYPE, PUBLIC ::   RIVERS_DATA     !: Storage for river outflow data
+      INTEGER, POINTER, DIMENSION(:,:)    ::   river_number       !: River outflow number
+      REAL(wp), POINTER, DIMENSION(:)     ::   river_area         ! 1D array listing areas of each river outflow (m2)
+      COMPLEX(wp), POINTER, DIMENSION(:)  ::   river_area_c       ! Comlex version of river_area for use in bit reproducible sums (m2)
+   END TYPE RIVERS_DATA
+   
+   TYPE(RIVERS_DATA), PUBLIC, TARGET :: rivers  !: River data
+   
+   LOGICAL                    :: ln_print_river_info  ! Diagnostic prints of river coupling information
+   
+CONTAINS
+
+   SUBROUTINE cpl_rnf_1d_init
+      !!----------------------------------------------------------------------
+      !!                    ***  SUBROUTINE cpl_rnf_1d_init  ***
+      !!                     
+      !! ** Purpose : - Read in file for river outflow numbers.
+      !!                Calculate 2D area of river outflow points.
+      !!                Called from nemo_init (nemogcm.F90).
+      !!
+      !!----------------------------------------------------------------------
+      !! namelist variables
+      !!-------------------
+      CHARACTER(len=80)                         ::   file_riv_number             !: Filename for river numbers
+      INTEGER                                   ::   ios                 ! Local integer output status for namelist read
+      INTEGER                                   ::   inum
+      INTEGER                                   ::   ii, jj, rr          !: Loop indices
+      INTEGER                                   ::   max_river
+      REAL(wp), POINTER, DIMENSION(:,:)         ::   river_number        ! 2D array containing the river outflow numbers
+      
+      NAMELIST/nam_cpl_rnf_1d/file_riv_number, nn_cpl_river, ln_print_river_info
+      !!----------------------------------------------------------------------
+
+      IF( nn_timing == 1 ) CALL timing_start('cpl_rnf_1d_init')
+      
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'cpl_rnf_1d_init : initialization of river runoff coupling'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~'
+      
+      REWIND(numnam_cfg)
+      
+      ! Read the namelist
+      READ  ( numnam_ref, nam_cpl_rnf_1d, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_cpl_rnf_1d in reference namelist', lwp )
+      READ  ( numnam_cfg, nam_cpl_rnf_1d, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nam_cpl_rnf_1d in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, nam_cpl_rnf_1d )
+
+      !                                               ! Parameter control and print
+      IF(lwp) WRITE(numout,*) '  '
+      IF(lwp) WRITE(numout,*) '          Namelist nam_cpl_rnf_1d : Coupled runoff using 1D array'
+      IF(lwp) WRITE(numout,*) '             Input file that contains river numbers = ',file_riv_number
+      IF(lwp) WRITE(numout,*) '             Maximum number of rivers to couple = ',nn_cpl_river
+      IF(lwp) WRITE(numout,*) '             Print river information = ',ln_print_river_info
+      IF(lwp) WRITE(numout,*) ' '
+      
+      ! Assign space for river numbers
+      ALLOCATE( rivers%river_number( jpi, jpj ) )
+      CALL wrk_alloc( jpi, jpj, river_number )
+      
+      ! Read the river numbers from netcdf file
+      CALL iom_open (file_riv_number , inum )
+      CALL iom_get  ( inum, jpdom_data, 'river_number', river_number )
+      CALL iom_close( inum )
+      
+      ! Convert from a real array to an integer array
+      max_river=0
+      DO ii = 1, jpi
+        DO jj = 1, jpj
+          rivers%river_number(ii,jj) = INT(river_number(ii,jj))
+          IF ( rivers%river_number(ii,jj) > max_river ) THEN
+            max_river = rivers%river_number(ii,jj)
+          END IF
+        END DO
+      END DO
+      
+      ! Print out the largest river number
+      WRITE(numout,*) 'Maximum river number in input file = ',max_river
+      
+      ! Get the area of each river outflow
+      ALLOCATE( rivers%river_area( nn_cpl_river ) )
+      ALLOCATE( rivers%river_area_c( nn_cpl_river ) )
+      rivers%river_area_c(:) = CMPLX( 0.e0, 0.e0, wp )
+      DO ii = nldi, nlei      
+        DO jj = nldj, nlej
+          IF ( tmask_i(ii,jj) > 0.5 ) THEN  ! This makes sure we are not at a duplicated point (at north fold or east-west cyclic point)
+            IF ( rivers%river_number(ii,jj) > 0 .AND. rivers%river_number(ii,jj) <= nn_cpl_river ) THEN
+              ! Add the area of each grid box (e1e2t) into river_area_c using DDPDD which should maintain bit reproducibility (needs to be checked)
+              CALL DDPDD( CMPLX( e1e2t(ii,jj), 0.e0, wp ), rivers%river_area_c(rivers%river_number(ii,jj) ) )
+            END IF
+          ELSE
+            IF ( jj == nldj .AND. tmask(ii,jj,1) > 0.5 ) THEN
+              WRITE(numout,*) 'At duplicated point at ii = ',ii
+            END IF
+          END IF
+        END DO
+      END DO
+      
+      ! Use mpp_sum to add together river areas on other processors
+      CALL mpp_sum( rivers%river_area_c, nn_cpl_river )
+      
+      ! Convert from complex number to real
+      ! DO rr = 1, nn_cpl_river
+      !    rivers%river_area(rr) = rivers%river_area_c(rr)
+      ! END DO
+      rivers%river_area(:) = REAL(rivers%river_area_c(:),wp)
+      
+      IF ( ln_print_river_info ) THEN
+        WRITE(numout,*) 'Area of rivers 1 to 10 are ',rivers%river_area(1:10)
+      END IF
+      
+   END SUBROUTINE cpl_rnf_1d_init
+   
+   SUBROUTINE cpl_rnf_1d_rcv( kstep)
+   
+      !!----------------------------------------------------------------------
+      !!                    ***  SUBROUTINE cpl_rnf_1d_rcv  ***
+      !!                     
+      !! ** Purpose : - Get river outflow from 1D array (passed from the
+      !!                atmosphere) and transfer it to the 2D NEMO runoff
+      !!                field.
+      !!                Called from sbc_cpl_rcv (sbccpl.F90).
+      !!
+      !!----------------------------------------------------------------------
+      
+      INTEGER                   , INTENT(in   ) ::   kstep     ! ocean time-step in seconds
+      
+      INTEGER  ::   kinfo                  ! OASIS3 info argument    
+      REAL(wp) ::   runoff_1d(nn_cpl_river)    ! River runoff. One value per river.
+      INTEGER  ::   ii, jj                 ! Loop indices
+      LOGICAL  ::   llaction               ! Has the get worked?
+      
+      IF ( ln_print_river_info ) THEN
+         WRITE(numout,*)' Getting data from 1D river runoff coupling '
+      ENDIF
+   
+      ! Get the river runoff sent by the atmosphere
+      CALL oasis_get ( runoff_id, kstep, runoff_1d, kinfo )
+      llaction =  kinfo == OASIS_Recvd   .OR. kinfo == OASIS_FromRest .OR.   &
+                  &        kinfo == OASIS_RecvOut .OR. kinfo == OASIS_FromRestOut
+                  
+      ! Output coupling info
+      IF ( ln_print_river_info ) THEN
+         WRITE(numout,*)' narea = ', narea
+         WRITE(numout,*)' kstep = ', kstep
+         WRITE(numout,*)' River runoff = ', runoff_1d(1:10)
+         WRITE(numout,*)' kinfo = ', kinfo
+         WRITE(numout,*)' llaction = ', llaction
+         WRITE(numout,*)' OASIS_Recvd = ',OASIS_Recvd
+         WRITE(numout,*)' OASIS_FromRest = ',OASIS_FromRest
+         WRITE(numout,*)' OASIS_RecvOut = ',OASIS_RecvOut
+         WRITE(numout,*)' OASIS_FromRestOut = ',OASIS_FromRestOut
+         WRITE(numout,*)'-------'
+      ENDIF
+      
+      IF ( llaction ) THEN
+      
+        ! Convert the 1D total runoff per river to 2D runoff flux by
+        ! dividing by the area of each runoff zone.
+        DO ii = 1, jpi
+          DO jj = 1, jpj
+            IF ( rivers%river_number(ii,jj) > 0 .AND. rivers%river_number(ii,jj) <= nn_cpl_river ) THEN
+              rnf(ii,jj) = runoff_1d(rivers%river_number(ii,jj)) / rivers%river_area(rivers%river_number(ii,jj))
+            ELSE
+              rnf(ii,jj) = 0.0
+            END IF
+            
+          END DO
+        END DO
+          
+      END IF
+      
+      IF ( ln_print_river_info ) WRITE(numout,*)' River runoff flux of AMAZON (pe 351) is ', rnf(59,29)         
+   
+   END SUBROUTINE cpl_rnf_1d_rcv
+
+END MODULE cpl_rnf_1d
Index: branches/UKMO/r6232_new_runoff_coupling/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90
===================================================================
--- branches/UKMO/r6232_new_runoff_coupling/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 11448)
+++ branches/UKMO/r6232_new_runoff_coupling/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 11452)
@@ -43,4 +43,5 @@
    USE eosbn2
    USE sbcrnf   , ONLY : l_rnfcpl
+   USE cpl_rnf_1d      ! Coupled runoff using 1D array
 #if defined key_cpl_carbon_cycle
    USE p4zflx, ONLY : oce_co2
@@ -401,5 +402,5 @@
       !                                                      ! ------------------------- !
       srcv(jpr_rnf   )%clname = 'O_Runoff'
-      IF( TRIM( sn_rcv_rnf%cldes ) == 'coupled' ) THEN
+      IF( TRIM( sn_rcv_rnf%cldes ) == 'coupled' .OR. TRIM( sn_rcv_rnf%cldes ) == 'coupled1d' ) THEN
          srcv(jpr_rnf)%laction = .TRUE.
          l_rnfcpl              = .TRUE.                      ! -> no need to read runoffs in sbcrnf
@@ -407,4 +408,10 @@
          IF(lwp) WRITE(numout,*)
          IF(lwp) WRITE(numout,*) '   runoffs received from oasis -> force ln_rnf = ', ln_rnf
+         ! Written here like this to allow merging with other branches (river mask)
+         IF( TRIM( sn_rcv_rnf%cldes ) == 'coupled' ) THEN
+           srcv(jpr_rnf)%laction = .TRUE.
+         ELSE
+           srcv(jpr_rnf)%laction = .FALSE.
+         ENDIF
       ENDIF
       !
@@ -761,4 +768,8 @@
          ENDIF
       ENDIF
+
+      ! Initialise 1D river outflow scheme
+      nn_cpl_river = 1
+      IF ( TRIM( sn_rcv_rnf%cldes ) == 'coupled1d' ) CALL cpl_rnf_1d_init   ! Coupled runoff using 1D array
 
       !
@@ -1072,5 +1083,6 @@
          !
          !                                                        ! runoffs and calving (added in emp)
-         IF( srcv(jpr_rnf)%laction )     rnf(:,:) = frcv(jpr_rnf)%z3(:,:,1)
+         IF( srcv(jpr_rnf)%laction )     rnf(:,:) = frcv(jpr_rnf)%z3(:,:,1)               
+         IF ( TRIM( sn_rcv_rnf%cldes ) == 'coupled1d' ) CALL cpl_rnf_1d_rcv( isec)
          IF( srcv(jpr_cal)%laction )     zemp(:,:) = zemp(:,:) - frcv(jpr_cal)%z3(:,:,1)
          
@@ -1331,5 +1343,5 @@
    
 
-   SUBROUTINE sbc_cpl_ice_flx( p_frld, palbi, psst, pist )
+   SUBROUTINE sbc_cpl_ice_flx( kt, p_frld, palbi, psst, pist )
       !!----------------------------------------------------------------------
       !!             ***  ROUTINE sbc_cpl_ice_flx  ***
@@ -1371,4 +1383,5 @@
       !!                   sprecip             solid precipitation over the ocean  
       !!----------------------------------------------------------------------
+      INTEGER, INTENT(in)           ::   kt          ! ocean model time step index
       REAL(wp), INTENT(in   ), DIMENSION(:,:)   ::   p_frld     ! lead fraction                [0 to 1]
       ! optional arguments, used only in 'mixed oce-ice' case
@@ -1384,4 +1397,6 @@
       !!----------------------------------------------------------------------
       !
+      INTEGER  ::   isec                   ! number of seconds since nit000 (assuming rdttra did not change since nit000)
+
       IF( nn_timing == 1 )  CALL timing_start('sbc_cpl_ice_flx')
       !
@@ -1432,4 +1447,6 @@
          CALL iom_put( 'calving_cea', frcv(jpr_cal)%z3(:,:,1) )
       ENDIF
+      isec = ( kt - nit000 ) * NINT( rdttra(1) )
+      CALL cpl_rnf_1d_rcv( isec)
 
       IF( ln_mixcpl ) THEN
Index: branches/UKMO/r6232_new_runoff_coupling/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90
===================================================================
--- branches/UKMO/r6232_new_runoff_coupling/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90	(revision 11448)
+++ branches/UKMO/r6232_new_runoff_coupling/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_cice.F90	(revision 11452)
@@ -139,5 +139,5 @@
             CALL cice_sbc_force(kt)
          ELSE IF ( ksbc == jp_purecpl ) THEN
-            CALL sbc_cpl_ice_flx( 1.0-fr_i  )
+            CALL sbc_cpl_ice_flx( kt, 1.0-fr_i  )
          ENDIF
 
