Index: branches/2012/dev_r3322_NOCS09_SAS/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90
===================================================================
--- branches/2012/dev_r3322_NOCS09_SAS/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 3363)
+++ branches/2012/dev_r3322_NOCS09_SAS/NEMOGCM/NEMO/OPA_SRC/SBC/sbcmod.F90	(revision 3364)
@@ -76,4 +76,5 @@
       !!
       !! ** Method  :   Read the namsbc namelist and set derived parameters
+      !!                Call init routines for all other SBC modules that have one
       !!
       !! ** Action  : - read namsbc parameters
@@ -200,6 +201,13 @@
       ENDIF
 
+      !!----------------------------------------------------------------------
+      !!   Other SBC modules to initialise come here
+      !!----------------------------------------------------------------------
+
+      CALL sbc_ssm_init
+
       IF( nn_ice == 4 )   CALL cice_sbc_init (nsbc)
       !
+      !!----------------------------------------------------------------------
    END SUBROUTINE sbc_init
 
Index: branches/2012/dev_r3322_NOCS09_SAS/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90
===================================================================
--- branches/2012/dev_r3322_NOCS09_SAS/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90	(revision 3363)
+++ branches/2012/dev_r3322_NOCS09_SAS/NEMOGCM/NEMO/OPA_SRC/SBC/sbcssm.F90	(revision 3364)
@@ -27,4 +27,7 @@
    PUBLIC   sbc_ssm    ! routine called by step.F90
    
+   LOGICAL, SAVE  ::   l_ssm_mean = .FALSE.       ! keep track of whether means have been read
+                                                  ! from restart file
+
    !! * Substitutions
 #  include "domzgr_substitute.h90"
@@ -54,12 +57,6 @@
       !!---------------------------------------------------------------------
       !                                                   ! ---------------------------------------- !
-      IF( nn_fsbc == 1 ) THEN                             !      Instantaneous surface fields        !
+      IF( nn_fsbc == 1 ) THEN                             !   Instantaneous surface fields        !
          !                                                ! ---------------------------------------- !
-         IF( kt == nit000 ) THEN
-            IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) 'sbc_ssm : sea surface mean fields, nn_fsbc=1 : instantaneous values'
-            IF(lwp) WRITE(numout,*) '~~~~~~~ '
-         ENDIF
-         !
          ssu_m(:,:) = ub(:,:,1)
          ssv_m(:,:) = vb(:,:,1)
@@ -73,42 +70,17 @@
          !
       ELSE
-         !                                                ! ---------------------------------------- !
-         IF( kt == nit000) THEN                           !       Initialisation: 1st time-step      !
-            !                                             ! ---------------------------------------- !
+         !                                                ! ----------------------------------------------- !
+         IF( kt == nit000 && .NOT. l_ssm_mean ) THEN      !   Initialisation: 1st time-step, no input means !
+            !                                             ! ----------------------------------------------- !
             IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) 'sbc_ssm : sea surface mean fields'
-            !
-            IF( ln_rstart .AND. iom_varid( numror, 'nn_fsbc', ldstop = .FALSE. ) > 0 ) THEN 
-               CALL iom_get( numror               , 'nn_fsbc', zf_sbc )   ! sbc frequency of previous run
-               CALL iom_get( numror, jpdom_autoglo, 'ssu_m'  , ssu_m  )   ! sea surface mean velocity    (T-point)
-               CALL iom_get( numror, jpdom_autoglo, 'ssv_m'  , ssv_m  )   !   "         "    velocity    (V-point)
-               CALL iom_get( numror, jpdom_autoglo, 'sst_m'  , sst_m  )   !   "         "    temperature (T-point)
-               CALL iom_get( numror, jpdom_autoglo, 'sss_m'  , sss_m  )   !   "         "    salinity    (T-point)
-               CALL iom_get( numror, jpdom_autoglo, 'ssh_m'  , ssh_m  )   !   "         "    height      (T-point)
-               !
-               IF( zf_sbc /= REAL( nn_fsbc, wp ) ) THEN      ! nn_fsbc has changed between 2 runs
-                  IF(lwp) WRITE(numout,*) '~~~~~~~   restart with a change in the frequency of mean ',   &
-                     &                    'from ', zf_sbc, ' to ', nn_fsbc
-                  zcoef = REAL( nn_fsbc - 1, wp ) / zf_sbc
-                  ssu_m(:,:) = zcoef * ssu_m(:,:)
-                  ssv_m(:,:) = zcoef * ssv_m(:,:)
-                  sst_m(:,:) = zcoef * sst_m(:,:)
-                  sss_m(:,:) = zcoef * sss_m(:,:)
-                  ssh_m(:,:) = zcoef * ssh_m(:,:)
-               ELSE
-                  IF(lwp) WRITE(numout,*) '~~~~~~~   mean fields read in the ocean restart file'
-               ENDIF
-            ELSE
-               IF(lwp) WRITE(numout,*) '~~~~~~~   mean fields initialised to instantaneous values'
-               zcoef = REAL( nn_fsbc - 1, wp )
-               ssu_m(:,:) = zcoef * ub(:,:,1)
-               ssv_m(:,:) = zcoef * vb(:,:,1)
-               sst_m(:,:) = zcoef * tsn(:,:,1,jp_tem)
-               sss_m(:,:) = zcoef * tsn(:,:,1,jp_sal)
-               !                          ! removed inverse barometer ssh when Patm forcing is used 
-               IF( ln_apr_dyn ) THEN   ;   ssh_m(:,:) = zcoef * ( sshn(:,:) - 0.5 * ( ssh_ib(:,:) + ssh_ibb(:,:) ) )
-               ELSE                    ;   ssh_m(:,:) = zcoef *   sshn(:,:)
-               ENDIF
-
+            IF(lwp) WRITE(numout,*) '~~~~~~~   mean fields initialised to instantaneous values'
+            zcoef = REAL( nn_fsbc - 1, wp )
+            ssu_m(:,:) = zcoef * ub(:,:,1)
+            ssv_m(:,:) = zcoef * vb(:,:,1)
+            sst_m(:,:) = zcoef * tsn(:,:,1,jp_tem)
+            sss_m(:,:) = zcoef * tsn(:,:,1,jp_sal)
+            !                          ! removed inverse barometer ssh when Patm forcing is used 
+            IF( ln_apr_dyn ) THEN   ;   ssh_m(:,:) = zcoef * ( sshn(:,:) - 0.5 * ( ssh_ib(:,:) + ssh_ibb(:,:) ) )
+            ELSE                    ;   ssh_m(:,:) = zcoef *   sshn(:,:)
             ENDIF
             !                                             ! ---------------------------------------- !
@@ -165,4 +137,53 @@
    END SUBROUTINE sbc_ssm
 
+   SUBROUTINE sbc_ssm_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE sbc_ssm_init  ***
+      !!
+      !! ** Purpose :   Initialisation of the sbc data
+      !!
+      !! ** Action  : - read parameters
+      !!----------------------------------------------------------------------
+      REAL(wp) ::   zcoef               ! local scalar
+      !!----------------------------------------------------------------------
+
+      IF( nn_fsbc == 1 ) THEN
+         !
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'sbc_ssm : sea surface mean fields, nn_fsbc=1 : instantaneous values'
+         IF(lwp) WRITE(numout,*) '~~~~~~~ '
+         !
+      ELSE
+         !               
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'sbc_ssm : sea surface mean fields'
+         IF(lwp) WRITE(numout,*) '~~~~~~~ '
+         !
+         IF( ln_rstart .AND. iom_varid( numror, 'nn_fsbc', ldstop = .FALSE. ) > 0 ) THEN
+            l_ssm_mean = .TRUE.
+            CALL iom_get( numror               , 'nn_fsbc', zf_sbc )   ! sbc frequency of previous run
+            CALL iom_get( numror, jpdom_autoglo, 'ssu_m'  , ssu_m  )   ! sea surface mean velocity    (T-point)
+            CALL iom_get( numror, jpdom_autoglo, 'ssv_m'  , ssv_m  )   !   "         "    velocity    (V-point)
+            CALL iom_get( numror, jpdom_autoglo, 'sst_m'  , sst_m  )   !   "         "    temperature (T-point)
+            CALL iom_get( numror, jpdom_autoglo, 'sss_m'  , sss_m  )   !   "         "    salinity    (T-point)
+            CALL iom_get( numror, jpdom_autoglo, 'ssh_m'  , ssh_m  )   !   "         "    height      (T-point)
+            !
+            IF( zf_sbc /= REAL( nn_fsbc, wp ) ) THEN      ! nn_fsbc has changed between 2 runs
+               IF(lwp) WRITE(numout,*) '~~~~~~~   restart with a change in the frequency of mean ',   &
+                  &                    'from ', zf_sbc, ' to ', nn_fsbc 
+               zcoef = REAL( nn_fsbc - 1, wp ) / zf_sbc 
+               ssu_m(:,:) = zcoef * ssu_m(:,:) 
+               ssv_m(:,:) = zcoef * ssv_m(:,:)
+               sst_m(:,:) = zcoef * sst_m(:,:)
+               sss_m(:,:) = zcoef * sss_m(:,:)
+               ssh_m(:,:) = zcoef * ssh_m(:,:)
+            ELSE
+               IF(lwp) WRITE(numout,*) '~~~~~~~   mean fields read in the ocean restart file'
+            ENDIF
+         ENDIF
+      ENDIF
+      !
+   END SUBROUTINE sbc_ssm_init
+
    !!======================================================================
 END MODULE sbcssm
Index: branches/2012/dev_r3322_NOCS09_SAS/NEMOGCM/NEMO/SAS_SRC/sbcssm.F90
===================================================================
--- branches/2012/dev_r3322_NOCS09_SAS/NEMOGCM/NEMO/SAS_SRC/sbcssm.F90	(revision 3363)
+++ branches/2012/dev_r3322_NOCS09_SAS/NEMOGCM/NEMO/SAS_SRC/sbcssm.F90	(revision 3364)
@@ -33,6 +33,6 @@
    PRIVATE
 
-   PUBLIC   sbc_ssm_sas_init   ! called by opa.F90
-   PUBLIC   sbc_ssm            ! called by step.F90
+   PUBLIC   sbc_ssm_init   ! called by sbc_init
+   PUBLIC   sbc_ssm        ! called by sbc
 
    CHARACTER(len=100)   ::   cn_dir     = './'    !: Root directory for location of ssm files
@@ -82,41 +82,4 @@
       !
       IF( nn_timing == 1 )  CALL timing_start( 'sbc_ssm')
-      !
-      IF( kt == nit000 ) THEN
-         !
-         !! switch off stuff that isn't sensible with a standalone module
-         !! do it here rather than in sbc_ssm_init so that we don't have to rely on the order
-         !! init routines are called in nemogcm
-         !! note that we still need sbc_ssm called first in sbc
-         !
-         IF( ln_cpl ) THEN 
-            IF( lwp ) WRITE(numout,*) 'Coupled mode not sensible with StandAlone Surface scheme'
-            ln_cpl = .FALSE.
-         ENDIF
-         IF( ln_apr_dyn ) THEN
-            IF( lwp ) WRITE(numout,*) 'No atmospheric gradient needed with StandAlone Surface scheme'
-            ln_apr_dyn = .FALSE.
-         ENDIF
-         IF( ln_dm2dc ) THEN
-            IF( lwp ) WRITE(numout,*) 'No diurnal cycle needed with StandAlone Surface scheme'
-            ln_dm2dc = .FALSE.
-         ENDIF
-         IF( ln_rnf ) THEN
-            IF( lwp ) WRITE(numout,*) 'No runoff needed with StandAlone Surface scheme'
-            ln_rnf = .FALSE.
-         ENDIF
-         IF( ln_ssr ) THEN
-            IF( lwp ) WRITE(numout,*) 'No surface relaxation needed with StandAlone Surface scheme'
-            ln_ssr = .FALSE.
-         ENDIF
-         IF( nn_fwb > 0 ) THEN
-            IF( lwp ) WRITE(numout,*) 'No freshwater budget adjustment needed with StandAlone Surface scheme'
-            nn_fwb = 0
-         ENDIF
-         IF( nn_closea > 0 ) THEN      
-            IF( lwp ) WRITE(numout,*) 'No closed seas adjustment needed with StandAlone Surface scheme'
-            nn_closea = 0  
-         ENDIF
-      ENDIF
 
       IF( nfld_3d > 0 ) CALL fld_read( kt, 1, sf_ssm_3d )      !==   read data at kt time step   ==!
@@ -153,5 +116,5 @@
 
 
-   SUBROUTINE sbc_ssm_sas_init
+   SUBROUTINE sbc_ssm_init
       !!----------------------------------------------------------------------
       !!                  ***  ROUTINE sbc_ssm_init  ***
@@ -166,11 +129,11 @@
       INTEGER  :: inum, idv, idimv, jpm              ! local integer
       !!
-      CHARACTER(len=100)               ::  cn_dir       ! Root directory for location of core files
-      TYPE(FLD_N), DIMENSION(jpfld_3d) ::  slf_3d       ! array of namelist information on the fields to read
-      TYPE(FLD_N), DIMENSION(jpfld_2d) ::  slf_2d       ! array of namelist information on the fields to read
+      CHARACTER(len=100)                     ::  cn_dir       ! Root directory for location of core files
+      TYPE(FLD_N), ALLOCATABLE, DIMENSION(:) ::  slf_3d       ! array of namelist information on the fields to read
+      TYPE(FLD_N), ALLOCATABLE, DIMENSION(:) ::  slf_2d       ! array of namelist information on the fields to read
       TYPE(FLD_N) :: sn_tem, sn_sal                     ! information about the fields to be read
       TYPE(FLD_N) :: sn_usp, sn_vsp, sn_ssh
       !
-      NAMELIST/namsbc_ssm_sas/cn_dir, ln_3d_uv, sn_tem, sn_sal, sn_usp, sn_vsp, sn_ssh
+      NAMELIST/namsbc_ssm/cn_dir, ln_3d_uv, sn_tem, sn_sal, sn_usp, sn_vsp, sn_ssh
 
       !!----------------------------------------------------------------------
@@ -188,15 +151,56 @@
       !
       REWIND( numnam )                          ! read in namlist namsbc_ssm
-      READ  ( numnam, namsbc_ssm_sas )
+      READ  ( numnam, namsbc_ssm )
       !                                         ! store namelist information in an array
       !                                         ! Control print
       IF(lwp) THEN
          WRITE(numout,*)
-         WRITE(numout,*) 'sbc_ssm_sas : standalone surface scheme '
+         WRITE(numout,*) 'sbc_ssm : standalone surface scheme '
          WRITE(numout,*) '~~~~~~~~~~~ '
-         WRITE(numout,*) '   Namelist namsbc_ssm_sas'
+         WRITE(numout,*) '   Namelist namsbc_ssm'
          WRITE(numout,*)
       ENDIF
+      
+      !
+      !! switch off stuff that isn't sensible with a standalone module
+      !! note that we need sbc_ssm called first in sbc
+      !
+      IF( ln_cpl ) THEN
+         IF( lwp ) WRITE(numout,*) 'Coupled mode not sensible with StandAlone Surface scheme'
+         ln_cpl = .FALSE.
+      ENDIF
+      IF( ln_apr_dyn ) THEN
+         IF( lwp ) WRITE(numout,*) 'No atmospheric gradient needed with StandAlone Surface scheme'
+         ln_apr_dyn = .FALSE.
+      ENDIF
+      IF( ln_dm2dc ) THEN
+         IF( lwp ) WRITE(numout,*) 'No diurnal cycle needed with StandAlone Surface scheme'
+         ln_dm2dc = .FALSE.
+      ENDIF
+      IF( ln_rnf ) THEN
+         IF( lwp ) WRITE(numout,*) 'No runoff needed with StandAlone Surface scheme'
+         ln_rnf = .FALSE.
+      ENDIF
+      IF( ln_ssr ) THEN
+         IF( lwp ) WRITE(numout,*) 'No surface relaxation needed with StandAlone Surface scheme'
+         ln_ssr = .FALSE.
+      ENDIF
+      IF( nn_fwb > 0 ) THEN
+         IF( lwp ) WRITE(numout,*) 'No freshwater budget adjustment needed with StandAlone Surface scheme'
+         nn_fwb = 0
+      ENDIF
+      IF( nn_closea > 0 ) THEN
+         IF( lwp ) WRITE(numout,*) 'No closed seas adjustment needed with StandAlone Surface scheme'
+         nn_closea = 0
+      ENDIF
+
       ! 
+      !! following code is a bit messy, but distinguishes between when u,v are 3d arrays and
+      !! when we have other 3d arrays that we need to read in
+      !! so if a new field is added i.e. jf_new, just give it the next integer in sequence
+      !! for the corresponding dimension (currently if ln_3d_uv is true, 4 for 2d and 3 for 3d,
+      !! alternatively if ln_3d_uv is false, 6 for 2d and 1 for 3d), reset nfld_3d, nfld_2d,
+      !! and the rest of the logic should still work
+      !
       jf_tem = 1 ; jf_sal = 2 ; jf_ssh = 3
       !
@@ -205,18 +209,36 @@
          nfld_3d  = 2
          nfld_2d  = 3
-         slf_3d(jf_usp) = sn_usp ; slf_3d(jf_vsp) = sn_vsp
       ELSE
          jf_usp = 4 ; jf_vsp = 5
          nfld_3d  = 0
          nfld_2d  = 5
-         slf_2d(jf_usp) = sn_usp ; slf_2d(jf_vsp) = sn_vsp
-      ENDIF
-
-      slf_2d(jf_tem) = sn_tem ; slf_2d(jf_sal) = sn_sal ; slf_2d(jf_ssh) = sn_ssh
+      ENDIF
+
+      IF( nfld_3d > 0 ) THEN
+         ALLOCATE( slf_3d(nfld_3d), STAT=ierr )         ! set slf structure
+         IF( ierr > 0 ) THEN
+            CALL ctl_stop( 'sbc_ssm_init: unable to allocate slf 3d structure' )   ;   RETURN
+         ENDIF
+         IF( ln_3d_uv ) THEN
+            slf_3d(jf_usp) = sn_usp
+            slf_3d(jf_vsp) = sn_vsp
+         ENDIF
+      ENDIF
+
+      IF( nfld_2d > 0 ) THEN
+         ALLOCATE( slf_2d(nfld_2d), STAT=ierr )         ! set slf structure
+         IF( ierr > 0 ) THEN
+            CALL ctl_stop( 'sbc_ssm_init: unable to allocate slf 2d structure' )   ;   RETURN
+         ENDIF
+         slf_2d(jf_tem) = sn_tem ; slf_2d(jf_sal) = sn_sal ; slf_2d(jf_ssh) = sn_ssh
+         IF( .NOT. ln_3d_uv ) THEN
+            slf_2d(jf_usp) = sn_usp ; slf_2d(jf_vsp) = sn_vsp
+         ENDIF
+      ENDIF
       !
       IF( nfld_3d > 0 ) THEN
          ALLOCATE( sf_ssm_3d(nfld_3d), STAT=ierr )         ! set sf structure
          IF( ierr > 0 ) THEN
-            CALL ctl_stop( 'sbc_ssm: unable to allocate sf structure' )   ;   RETURN
+            CALL ctl_stop( 'sbc_ssm_init: unable to allocate sf structure' )   ;   RETURN
          ENDIF
          DO ifpr = 1, nfld_3d
@@ -234,5 +256,5 @@
          ALLOCATE( sf_ssm_2d(nfld_2d), STAT=ierr )         ! set sf structure
          IF( ierr > 0 ) THEN
-            CALL ctl_stop( 'sbc_ssm: unable to allocate sf 2d structure' )   ;   RETURN
+            CALL ctl_stop( 'sbc_ssm_init: unable to allocate sf 2d structure' )   ;   RETURN
          ENDIF
          DO ifpr = 1, nfld_2d
@@ -260,5 +282,10 @@
       ENDIF
       !
-   END SUBROUTINE sbc_ssm_sas_init
+      ! finally tidy up
+
+      IF( nfld_3d > 0 ) DEALLOCATE( slf_3d, STAT=ierr )
+      IF( nfld_2d > 0 ) DEALLOCATE( slf_2d, STAT=ierr )
+      !
+   END SUBROUTINE sbc_ssm_init
 
    !!======================================================================
