Index: branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90
===================================================================
--- branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90	(revision 7692)
+++ branches/UKMO/dev_r5518_MEDUSA_optim_RH/NEMOGCM/NEMO/TOP_SRC/CFC/trcsms_cfc.F90	(revision 7693)
@@ -15,4 +15,5 @@
    !!   cfc_init     :  sets constants for CFC surface forcing computation
    !!----------------------------------------------------------------------
+   USE dom_oce       ! ocean space and time domain
    USE oce_trc       ! Ocean variables
    USE par_trc       ! TOP parameters
@@ -31,4 +32,6 @@
    INTEGER , PUBLIC            ::   jpyear         ! Number of years read in CFC1112 file
    INTEGER , PUBLIC            ::   ndate_beg      ! initial calendar date (aammjj) for CFC
+   INTEGER , PUBLIC            ::   simu_type      ! Kind of simulation: 1- Spin-up 
+                                                   !                     2- Hindcast/projection
    INTEGER , PUBLIC            ::   nyear_res      ! restoring time constant (year)
    INTEGER , PUBLIC            ::   nyear_beg      ! initial year (aa) 
@@ -79,5 +82,5 @@
       !
       INTEGER  ::   ji, jj, jn, jl, jm, js
-      INTEGER  ::   iyear_beg, iyear_end
+      INTEGER  ::   iyear_beg, iyear_end, iyear_tmp
       INTEGER  ::   im1, im2, ierr
       REAL(wp) ::   ztap, zdtap        
@@ -103,5 +106,41 @@
       ! Temporal interpolation
       ! ----------------------
-      iyear_beg = nyear - 1900
+      !! JPALM -- 15-06-2016 -- define 2 kind of CFC run.
+      !!                     we want to make cycle experiments, 
+      !!                     to periodically compare the ocean dynamic within
+      !!                     1- the SPIN-UP and 2- Hincast/Projections
+      !!                     -- main difference is the way to define the year of
+      !!                     simulation, that determine the atm pCFC.
+      !!                     1-- Spin-up: our atm forcing is of 30y we cycle on.
+      !!                     So we do 90y CFC cycles to be in good
+      !!                     correspondance with the atmosphere
+      !!                     2-- Hindcast/proj, instead of nyear-1900 we keep
+      !!                     the 2 last digit, and enable 3 cycle from 1800 to 2100.  
+      !!----------------------------------------------------------------------
+      !! 1 -- SPIN-UP
+      IF (simu_type==1) THEN
+         iyear_tmp = nyear - nyear_res  !! JPALM -- in our spin-up, nyear_res is 1000
+         iyear_beg = MOD( iyear_tmp , 90 )
+         !! JPALM -- the pCFC file only got 78 years.
+         !!       So if iyear_beg > 78 then we set pCFC to 0
+         !!             iyear_beg = 0 as well -- must try to avoid obvious problems
+         !!             as Pcfc is set to 0.00 up to year 32, let set iyear_beg to year 10
+         !!          else, must add 30 to iyear_beg to match with P_cfc indices
+         !!---------------------------------------
+         IF ((iyear_beg > 77) .OR. (iyear_beg==0)) THEN
+            iyear_beg = 10
+         ELSE 
+            iyear_beg = iyear_beg + 30
+         ENDIF
+      !!
+      !! 2 -- Hindcast/proj
+      ELSEIF (simu_type==2) THEN
+         iyear_beg = MOD(nyear, 100)
+         IF (iyear_beg < 9)  iyear_beg = iyear_beg + 100
+         !! JPALM -- Same than previously, if iyear_beg is out of P_cfc range,
+         !!       we want to set p_CFC to 0.00 --> set iyear_beg = 10
+         IF ((iyear_beg < 30) .OR. (iyear_beg > 107)) iyear_beg = 10             
+      ENDIF
+      !!
       IF ( nmonth <= 6 ) THEN
          iyear_beg = iyear_beg - 1
@@ -176,14 +215,41 @@
          !                                                  !----------------!
       END DO                                                !  end CFC loop  !
-      !
-      IF( lrst_trc ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'trc_sms_cfc : cumulated input function fields written in ocean restart file ',   &
-            &                    'at it= ', kt,' date= ', ndastp
-         IF(lwp) WRITE(numout,*) '~~~~'
-         DO jn = jp_cfc0, jp_cfc1
-            CALL iom_rstput( kt, nitrst, numrtw, 'qint_'//ctrcnm(jn), qint_cfc(:,:,jn) )
-         END DO
-      ENDIF                                            
+         !
+      IF( kt == nittrc000 ) THEN
+         DO jl = 1, jp_cfc   
+             WRITE(NUMOUT,*) ' '
+             WRITE(NUMOUT,*) 'CFC interpolation verification '  !! Jpalm  
+             WRITE(NUMOUT,*) '################################## '
+             WRITE(NUMOUT,*) ' '
+               if (jl.EQ.1) then
+                   WRITE(NUMOUT,*) 'Traceur = CFC11: '
+               elseif (jl.EQ.2) then
+                   WRITE(NUMOUT,*) 'Traceur = CFC12: '
+               endif
+             WRITE(NUMOUT,*) 'nyear    = ', nyear
+             WRITE(NUMOUT,*) 'nmonth   = ', nmonth
+             WRITE(NUMOUT,*) 'iyear_beg= ', iyear_beg
+             WRITE(NUMOUT,*) 'iyear_end= ', iyear_end
+             WRITE(NUMOUT,*) 'p_cfc(iyear_beg)= ',p_cfc(iyear_beg, 1, jl)
+             WRITE(NUMOUT,*) 'p_cfc(iyear_end)= ',p_cfc(iyear_end, 1, jl)
+             WRITE(NUMOUT,*) 'Im1= ',im1
+             WRITE(NUMOUT,*) 'Im2= ',im2
+             WRITE(NUMOUT,*) 'zpp_cfc = ',zpp_cfc
+             WRITE(NUMOUT,*) ' '
+         END DO  
+# if defined key_debug_medusa
+         CALL flush(numout)
+# endif
+      ENDIF
+        !
+      !IF( lrst_trc ) THEN
+      !   IF(lwp) WRITE(numout,*)
+      !   IF(lwp) WRITE(numout,*) 'trc_sms_cfc : cumulated input function fields written in ocean restart file ',   &
+      !      &                    'at it= ', kt,' date= ', ndastp
+      !   IF(lwp) WRITE(numout,*) '~~~~'
+      !   DO jn = jp_cfc0, jp_cfc1
+      !      CALL iom_rstput( kt, nitrst, numrtw, 'qint_'//ctrcnm(jn), qint_cfc(:,:,jn) )
+      !   END DO
+      !ENDIF                                            
       !
       IF( lk_iomput ) THEN
@@ -203,4 +269,8 @@
       END IF
       !
+# if defined key_debug_medusa
+      IF(lwp) WRITE(numout,*) '   CFC - Check: nn_timing = ', nn_timing
+      CALL flush(numout)
+# endif
       IF( nn_timing == 1 )  CALL timing_stop('trc_sms_cfc')
       !
@@ -214,5 +284,5 @@
       !! ** Purpose : sets constants for CFC model
       !!---------------------------------------------------------------------
-      INTEGER :: jn
+      INTEGER :: jl, jn, iyear_beg, iyear_tmp
 
       ! coefficient for CFC11 
@@ -254,13 +324,52 @@
       sca(4,2) =  -0.067430
 
-      IF( ln_rsttr ) THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) ' Read specific variables from CFC model '
-         IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
-         !
-         DO jn = jp_cfc0, jp_cfc1
-            CALL iom_get( numrtr, jpdom_autoglo, 'qint_'//ctrcnm(jn), qint_cfc(:,:,jn) ) 
-         END DO
+      !!---------------------------------------------
+      !! JPALM -- re-initialize CFC fields and diags if restart a CFC cycle,
+      !!       Or if out of P_cfc range
+      IF (simu_type==1) THEN
+         iyear_tmp = nyear - nyear_res  !! JPALM -- in our spin-up, nyear_res is 1000
+         iyear_beg = MOD( iyear_tmp , 90 )
+         !!---------------------------------------
+         IF ((iyear_beg > 77) .OR. (iyear_beg==0)) THEN
+            qtr_cfc(:,:,:) = 0._wp
+            IF(lwp) THEN
+               WRITE(numout,*) 
+               WRITE(numout,*) 'restart a CFC cycle or out of P_cfc year bounds zero --'
+               WRITE(numout,*) '                          --    set qtr_CFC = 0.00   --'
+               WRITE(numout,*) '                          --   set qint_CFC = 0.00   --'
+               WRITE(numout,*) '                          --   set trn(CFC) = 0.00   --'
+            ENDIF
+            qtr_cfc(:,:,:) = 0._wp
+            qint_cfc(:,:,:) = 0._wp
+            DO jl = 1, jp_cfc
+              jn = jp_cfc0 + jl - 1
+              trn(:,:,:,jn) = 0._wp
+              trb(:,:,:,jn) = 0._wp
+            END DO
+         ENDIF
+      !!
+      !! 2 -- Hindcast/proj
+      ELSEIF (simu_type==2) THEN
+         iyear_beg = MOD(nyear, 100)
+         IF (iyear_beg < 9)  iyear_beg = iyear_beg + 100
+         IF ((iyear_beg < 30) .OR. (iyear_beg > 107)) THEN
+            qtr_cfc(:,:,:) = 0._wp
+            IF(lwp) THEN
+               WRITE(numout,*)
+               WRITE(numout,*) 'restart a CFC cycle or out of P_cfc year bounds zero --'
+               WRITE(numout,*) '                          --    set qtr_CFC = 0.00   --'
+               WRITE(numout,*) '                          --   set qint_CFC = 0.00   --'
+               WRITE(numout,*) '                          --   set trn(CFC) = 0.00   --'
+            ENDIF
+            qtr_cfc(:,:,:) = 0._wp
+            qint_cfc(:,:,:) = 0._wp
+            DO jl = 1, jp_cfc
+              jn = jp_cfc0 + jl - 1
+              trn(:,:,:,jn) = 0._wp
+              trb(:,:,:,jn) = 0._wp
+            END DO
+         ENDIF
       ENDIF
+
       IF(lwp) WRITE(numout,*)
       !
