Index: NEMO/branches/2019/ENHANCE-02_ISF_nemo/src/OCE/ISF/isfstp.F90
===================================================================
--- NEMO/branches/2019/ENHANCE-02_ISF_nemo/src/OCE/ISF/isfstp.F90	(revision 11541)
+++ NEMO/branches/2019/ENHANCE-02_ISF_nemo/src/OCE/ISF/isfstp.F90	(revision 11553)
@@ -39,5 +39,5 @@
    PRIVATE
 
-   PUBLIC   isf_stp, isf_stp_init  ! routine called in sbcmod and divhor
+   PUBLIC   isf_stp, isf_init, isf_nam  ! routine called in sbcmod and divhor
 
    !!----------------------------------------------------------------------
@@ -114,5 +114,5 @@
    END SUBROUTINE isf_stp
 
-   SUBROUTINE isf_stp_init
+   SUBROUTINE isf_init
       !!---------------------------------------------------------------------
       !!                  ***  ROUTINE isfstp_init  ***
@@ -127,36 +127,64 @@
       !!              - call cav/param init routine
       !!----------------------------------------------------------------------
-      INTEGER               :: inum, ierror
-      INTEGER               :: ios                  ! Local integer output status for namelist read
-      INTEGER               :: ikt, ikb
-      INTEGER               :: ji, jj
-      !!----------------------------------------------------------------------
-      NAMELIST/namisf/ ln_isf       ,                                                                               & 
-         &             ln_isfcav_mlt, cn_isfcav_mlt, cn_gammablk, rn_gammat0, rn_gammas0, rn_htbl, sn_isfcav_fwf,   &
-         &             ln_isfpar_mlt, cn_isfpar_mlt, sn_isfpar_fwf, sn_isfpar_zmin, sn_isfpar_zmax, sn_isfpar_Leff, &
-         &             ln_isfcpl    , nn_drown, ln_isfcpl_cons,                                                     &
-         &             cn_isfload   , cn_isfdir
-      !!----------------------------------------------------------------------
+      !
+      ! constrain: l_isfoasis need to be known
+      !
+      ! Read namelist
+      CALL isf_nam()
       !
       ! Allocate public array
       CALL isf_alloc()
       !
-      ! initalisation of fwf and tsc array to 0
-      riceload(:,:)       = 0.0_wp
-      fwfisf_oasis(:,:)   = 0.0_wp
-      fwfisf_par(:,:)     = 0.0_wp    ; fwfisf_par_b(:,:)     = 0.0_wp
-      fwfisf_cav(:,:)     = 0.0_wp    ; fwfisf_cav_b(:,:)     = 0.0_wp
-      risf_cav_tsc(:,:,:) = 0.0_wp    ; risf_cav_tsc_b(:,:,:) = 0.0_wp
-      risf_par_tsc(:,:,:) = 0.0_wp    ; risf_par_tsc_b(:,:,:) = 0.0_wp
-      !
-      REWIND( numnam_ref )              ! Namelist namsbc_rnf in reference namelist : Runoffs 
-      READ  ( numnam_ref, namisf, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namisf in reference namelist', lwp )
-      !
-      REWIND( numnam_cfg )              ! Namelist namsbc_rnf in configuration namelist : Runoffs
-      READ  ( numnam_cfg, namisf, IOSTAT = ios, ERR = 902 )
-902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namisf in configuration namelist', lwp )
-      IF(lwm) WRITE ( numond, namisf )
-      !
+      ! check option compatibility
+      CALL isf_ctl()
+      !
+      ! compute ice shelf load
+      IF ( ln_isfcav ) CALL isf_load( risfload )
+      !
+      ! terminate routine now if no ice shelf melt formulation specify
+      IF ( ln_isf ) THEN
+         !
+         !---------------------------------------------------------------------------------------------------------------------
+         ! initialisation melt in the cavity
+         IF ( ln_isfcav_mlt ) THEN
+            !
+            ! initialisation  of cav variable
+            CALL isf_cav_init()
+            !
+            ! read cav variable from restart
+            IF ( ln_rstart ) CALL isfrst_read('cav', risf_cav_tsc, fwfisf_cav, risf_cav_tsc_b, fwfisf_cav_b)
+            !
+         END IF
+         !
+         !---------------------------------------------------------------------------------------------------------------------
+         ! initialisation parametrised melt
+         IF ( ln_isfpar_mlt ) THEN
+            !
+            ! initialisation  of par variable
+            CALL isf_par_init()
+            !
+            ! read par variable from restart
+            IF ( ln_rstart ) CALL isfrst_read('par', risf_par_tsc, fwfisf_par, risf_par_tsc_b, fwfisf_par_b)
+            !
+         END IF
+         !
+         !---------------------------------------------------------------------------------------------------------------------
+         ! initialisation ice sheet coupling
+         IF( ln_isfcpl ) THEN 
+            !
+            ! prepare writing restart
+            IF( lwxios ) CALL iom_set_rstw_var_active('ssmask')
+            IF( lwxios ) CALL iom_set_rstw_var_active('tmask')
+            IF( lwxios ) CALL iom_set_rstw_var_active('e3t_n')
+            IF( lwxios ) CALL iom_set_rstw_var_active('e3u_n')
+            IF( lwxios ) CALL iom_set_rstw_var_active('e3v_n')
+            !
+         END IF
+         !
+      END IF
+         
+  END SUBROUTINE isf_init
+
+  SUBROUTINE isf_ctl()!
       IF (lwp) THEN
          WRITE(numout,*)
@@ -166,4 +194,5 @@
          !
          WRITE(numout,*) '   ice shelf cavity (open or parametrised)  ln_isf = ', ln_isf
+         WRITE(numout,*)
          !
          IF ( ln_isf ) THEN
@@ -181,5 +210,5 @@
             WRITE(numout,*) ''
             !
-            WRITE(numout,*) '      ice shelf melt parametrisation          ln_isfpar_mlt    = ', ln_isfpar_mlt
+            WRITE(numout,*) '      ice shelf melt parametrisation          ln_isfpar_mlt   = ', ln_isfpar_mlt
             IF ( ln_isfpar_mlt ) THEN
                WRITE(numout,*) '         isf parametrisation formulation         cn_isfpar_mlt   = ', TRIM(cn_isfpar_mlt)
@@ -187,8 +216,8 @@
             WRITE(numout,*) ''
             !
-            WRITE(numout,*) '      Coupling to an ice sheet model          ln_isfcpl        = ', ln_isfcpl
+            WRITE(numout,*) '      Coupling to an ice sheet model          ln_isfcpl       = ', ln_isfcpl
             IF ( ln_isfcpl ) THEN
-               WRITE(numout,*) '         conservation activated ln_isfcpl_cons           = ', ln_isfcpl_cons
-               WRITE(numout,*) '            number of call of the extrapolation loop = ', nn_drown
+               WRITE(numout,*) '         conservation activated ln_isfcpl_cons     = ', ln_isfcpl_cons
+               WRITE(numout,*) '         number of call of the extrapolation loop  = ', nn_drown
             ENDIF
             WRITE(numout,*) ''
@@ -208,21 +237,10 @@
       END IF
       !
+
       !---------------------------------------------------------------------------------------------------------------------
-      ! initialisation ice shelf load
-      IF ( ln_isfcav ) THEN
-         !
-         ! compute ice shelf mask
-         mskisf_cav(:,:) = (1._wp - tmask(:,:,1)) * ssmask(:,:)
-         !
-         ! compute ice shelf load
-         CALL isf_load( risfload )
-         !
-      END IF
-      !
-      !---------------------------------------------------------------------------------------------------------------------
-      ! sanity check
+      ! sanity check  ! issue ln_isfcav not yet known as well as l_isfoasis  => move this call in isf_stp ?
       ! melt in the cavity without cavity
-      IF ( ln_isfcav_mlt .AND. (.NOT. ln_isfcav) ) &
-         &   CALL ctl_stop('ice shelf melt in the cavity activated (ln_isfcav_mlt) but no cavity detected in domcfg (ln_isfcav), STOP' )
+       IF ( ln_isfcav_mlt .AND. (.NOT. ln_isfcav) ) &
+          &   CALL ctl_stop('ice shelf melt in the cavity activated (ln_isfcav_mlt) but no cavity detected in domcfg (ln_isfcav), STOP' )
       !
       ! ice sheet coupling without cavity
@@ -233,5 +251,7 @@
          &   CALL ctl_stop( 'The coupling between NEMO and an ice sheet model with the conservation option does not work with the linssh option' )
       !
-      IF ( l_isfoasis ) THEN
+      IF ( l_isfoasis .AND. .NOT. ln_isf ) CALL ctl_stop( ' OASIS send ice shelf fluxes to NEMO but NEMO does not have the isf module activated' )
+      !
+      IF ( l_isfoasis .AND. ln_isf ) THEN
          !
          CALL ctl_stop( ' ln_ctl and ice shelf not tested' )
@@ -251,72 +271,35 @@
             IF ( TRIM(cn_isfpar_mlt) == 'oasis' .AND. TRIM(cn_isfcav_mlt) == 'oasis' ) CALL ctl_stop( 'cn_isfpar_mlt = oasis and cn_isfcav_mlt = oasis not coded' )
          END IF
-      END IF
-      !
-      ! terminate routine now if no ice shelf melt formulation specify
-      IF ( ln_isf ) THEN
-         !
-         !---------------------------------------------------------------------------------------------------------------------
-         ! initialisation melt in the cavity
-         IF ( ln_isfcav_mlt ) THEN
-            !
-            ! initialisation  of cav variable
-            CALL isf_cav_init()
-            !
-            ! read cav variable from restart
-            IF ( ln_rstart ) CALL isfrst_read('cav', risf_cav_tsc, fwfisf_cav, risf_cav_tsc_b, fwfisf_cav_b)
-            !
-         END IF
-         !
-         !---------------------------------------------------------------------------------------------------------------------
-         ! initialisation parametrised melt
-         IF ( ln_isfpar_mlt ) THEN
-            !
-            ! initialisation  of par variable
-            CALL isf_par_init()
-            !
-            ! read par variable from restart
-            IF ( ln_rstart ) CALL isfrst_read('par', risf_par_tsc, fwfisf_par, risf_par_tsc_b, fwfisf_par_b)
-            !
-         END IF
-         !
-         !---------------------------------------------------------------------------------------------------------------------
-         ! initialisation ice sheet coupling
-         IF( ln_isfcpl ) THEN
-            ! 
-            ! prepare writing restart
-            IF( lwxios ) CALL iom_set_rstw_var_active('ssmask')
-            IF( lwxios ) CALL iom_set_rstw_var_active('tmask')
-            IF( lwxios ) CALL iom_set_rstw_var_active('e3t_n')
-            IF( lwxios ) CALL iom_set_rstw_var_active('e3u_n')
-            IF( lwxios ) CALL iom_set_rstw_var_active('e3v_n')
-            !
-            IF( ln_rstart ) THEN
-               !
-               CALL isf_alloc_cpl()
-               !
-               ! extrapolation tracer properties
-               CALL isfcpl_tra()
-               !
-               ! correction of the horizontal divergence and associated temp. and salt content flux
-               CALL isfcpl_vol()
-               !
-               ! apply the 'conservation' method
-               IF ( ln_isfcpl_cons ) CALL isfcpl_cons()
-               !
-               ! Need to : - include in the cpl cons the risfcpl_vol/tsc contribution
-               !           - decide how to manage thickness level change in conservation
-               !
-               tsb    (:,:,:,:) = tsn (:,:,:,:)
-               sshb   (:,:)     = sshn(:,:)
-               ub     (:,:,:)   = un(:,:,:)
-               vb     (:,:,:)   = vn(:,:,:)
-               !
-            END IF
-            !
-         END IF
-         !
-      END IF
-         
-  END SUBROUTINE isf_stp_init
+         !
+      END IF
+   END SUBROUTINE isf_ctl
+   !
+   SUBROUTINE isf_nam
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE isf_nam  ***
+      !!
+      !! ** Purpose :   Read ice shelf namelist cfg and ref
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER               :: ios                  ! Local integer output status for namelist read
+      !!----------------------------------------------------------------------
+      NAMELIST/namisf/ ln_isf       ,                                                                               & 
+         &             ln_isfcav_mlt, cn_isfcav_mlt, cn_gammablk, rn_gammat0, rn_gammas0, rn_htbl, sn_isfcav_fwf,   &
+         &             ln_isfpar_mlt, cn_isfpar_mlt, sn_isfpar_fwf, sn_isfpar_zmin, sn_isfpar_zmax, sn_isfpar_Leff, &
+         &             ln_isfcpl    , nn_drown, ln_isfcpl_cons,                                                     &
+         &             cn_isfload   , cn_isfdir
+      !!----------------------------------------------------------------------
+      !
+      REWIND( numnam_ref )              ! Namelist namsbc_rnf in reference namelist : Runoffs 
+      READ  ( numnam_ref, namisf, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namisf in reference namelist', lwp )
+      !
+      REWIND( numnam_cfg )              ! Namelist namsbc_rnf in configuration namelist : Runoffs
+      READ  ( numnam_cfg, namisf, IOSTAT = ios, ERR = 902 )
+902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namisf in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, namisf )
+
+   END SUBROUTINE isf_nam
+   !!
    !!======================================================================
 END MODULE isfstp
