Index: /branches/NERC/dev_r5518_GO6_CO2_cmip/NEMOGCM/CONFIG/SHARED/xco2.atm
===================================================================
--- /branches/NERC/dev_r5518_GO6_CO2_cmip/NEMOGCM/CONFIG/SHARED/xco2.atm	(revision 9297)
+++ /branches/NERC/dev_r5518_GO6_CO2_cmip/NEMOGCM/CONFIG/SHARED/xco2.atm	(revision 9298)
@@ -3,5 +3,5 @@
 % Year  xCO2
 %       (ppm)
-1849.5  284.3200000
+1849.5  284.3170000
 1850.5  284.3169999
 1851.5  284.4509998
Index: /branches/NERC/dev_r5518_GO6_CO2_cmip/NEMOGCM/NEMO/TOP_SRC/MEDUSA/sms_medusa.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_CO2_cmip/NEMOGCM/NEMO/TOP_SRC/MEDUSA/sms_medusa.F90	(revision 9297)
+++ /branches/NERC/dev_r5518_GO6_CO2_cmip/NEMOGCM/NEMO/TOP_SRC/MEDUSA/sms_medusa.F90	(revision 9298)
@@ -287,5 +287,6 @@
 !!
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:)   ::   hist_pco2 !: pCO2
-   INTEGER :: co2_yinit, co2_yend, co2_rec
+   INTEGER  :: co2_rec
+   REAL(wp) :: co2_yinit, co2_yend
 #endif
 
Index: /branches/NERC/dev_r5518_GO6_CO2_cmip/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcbio_medusa.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_CO2_cmip/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcbio_medusa.F90	(revision 9297)
+++ /branches/NERC/dev_r5518_GO6_CO2_cmip/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcbio_medusa.F90	(revision 9298)
@@ -182,5 +182,6 @@
       !! 
       !! temporary variables
-      REAL(wp) ::    fq0,fq1,fq2,fq3,fq4
+      REAL(wp) ::    fq3,fq4
+      REAL(wp) ::    this_y, this_d, this_s, fyear
       !!
       !! T and S check temporary variable
@@ -295,30 +296,41 @@
       !!
       !! what's atmospheric pCO2 doing? (data start in 1859)
-      iyr1  = nyear 
-      iyr2  = iyr1 + 1
-      if (iyr1 .le. co2_yinit) then
-         !! before 1850
-         f_xco2a(:,:) = 284.317  
-      elseif (iyr2 .ge. co2_yend) then
-         !! after 2010
-         f_xco2a(:,:) = hist_pco2(co2_yend - co2_yinit +1)
-      else
+      !! AXY - JPALM new interpolation scheme usinf nyear_len
+      this_y = real(nyear)
+      this_d = real(nday_year)
+      this_s = real(nsec_day)
+      !!
+      fyear = this_y + ((this_d - 1) + (this_s / (60. * 60. * 24.))) / real(nyear_len(1))
+      !!
+      IF ( ( kt == nittrc000 ) .AND. lwp ) THEN 
+         WRITE(numout,*) ' MEDUSA year      =', this_y
+         WRITE(numout,*) ' Year length      =', real(nyear_len(1))
+         WRITE(numout,*) ' MEDUSA nday_year =', this_d
+         WRITE(numout,*) ' MEDUSA nsec_day  =', this_s
+      ENDIF
+      !! 
+      !! different case test 
+      IF (fyear .LE. co2_yinit) THEN
+         !! before first record -- pre-industrial value
+         f_xco2a(:,:) = hist_pco2(1)  
+      ELSEIF (fyear .GE. co2_yend) THEN
+         !! after last record - continue to use the last value
+         f_xco2a(:,:) = hist_pco2(int(co2_yend - co2_yinit + 1.) )
+      ELSE
          !! just right
-         fq0 = hist_pco2(iyr1)
-         fq1 = hist_pco2(iyr2)
-         fq2 = real(nsec_day) / (60.0 * 60.0 * 24.0)
-         fq3 = (real(nday_year) - 1.0 + fq2) / real(nyear_len(1))
-         !! AXY (14/06/12): tweaked to make more sense (and be correct)
-!!#  if defined key_bs_axy_yrlen
-!!         !! bugfix: for 360d year with HadGEM2-ES forcing
-!!         fq3 = (real(nday_year) - 1.0 + fq2) / 360.0  
-!!#  else
-!!         !! original use of 365 days (not accounting for leap year or 
-!!         !! 360d year)
-!!         fq3 = (real(nday_year) - 1.0 + fq2) / 365.0
-!!#  endif
-         fq4 = (fq0 * (1.0 - fq3)) + (fq1 * fq3)
+         iyr1 = int(fyear - co2_yinit) + 1
+         iyr2 = iyr1 + 1 
+         fq3 = fyear - real(iyr1) - co2_yinit + 1.
+         fq4 = ((1 - fq3) * hist_pco2(iyr1)) + (fq3 * hist_pco2(iyr2))
          f_xco2a(:,:) = fq4
-      endif
+         !!
+         IF ( ( kt == nittrc000 ) .AND. lwp ) THEN 
+            WRITE(numout,*) ' MEDUSA year1     =', iyr1
+            WRITE(numout,*) ' MEDUSA year2     =', iyr2
+            WRITE(numout,*) ' xCO2 year1       =', hist_pco2(iyr1)
+            WRITE(numout,*) ' xCO2 year2       =', hist_pco2(iyr2)
+            WRITE(numout,*) ' Year2 weight     =', fq3
+         ENDIF
+      ENDIF
 #  if defined key_axy_pi_co2
       !! OCMIP pre-industrial pCO2
@@ -326,14 +338,7 @@
       f_xco2a(:,:) = 284.317          !! CMIP6 pre-industrial pCO2 
 #  endif
-       IF(lwp) WRITE(numout,*) ' MEDUSA nyear     =', nyear
-       IF(lwp) WRITE(numout,*) ' MEDUSA nyear     =', real(nyear_len(1))
-       IF(lwp) WRITE(numout,*) ' MEDUSA nsec_day  =', real(nsec_day)
-       IF(lwp) WRITE(numout,*) ' MEDUSA nday_year =', real(nday_year)
       !! AXY (29/01/14): remove surplus diagnostics
-       IF(lwp) WRITE(numout,*) ' MEDUSA fq0       =', fq0
-       IF(lwp) WRITE(numout,*) ' MEDUSA fq1       =', fq1
-       IF(lwp) WRITE(numout,*) ' MEDUSA fq2       =', fq2
-       IF(lwp) WRITE(numout,*) ' MEDUSA fq3       =', fq3
-       IF(lwp) WRITE(numout,*) ' MEDUSA atm pCO2  =', f_xco2a(1,1)
+       IF ( ( kt == nittrc000 ) .AND. lwp )   & 
+            WRITE(numout,*) ' final atm xCO2   =', f_xco2a(1,1)
 # endif
 
Index: /branches/NERC/dev_r5518_GO6_CO2_cmip/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcini_medusa.F90
===================================================================
--- /branches/NERC/dev_r5518_GO6_CO2_cmip/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcini_medusa.F90	(revision 9297)
+++ /branches/NERC/dev_r5518_GO6_CO2_cmip/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcini_medusa.F90	(revision 9298)
@@ -497,7 +497,7 @@
       !! ** Method  : - Read the xco2 file
       !!----------------------------------------------------------------------
-      INTEGER  ::  jn, jl, jm, io, ierr, inum
+      INTEGER  ::  jn, jm, io, ierr, inum
       INTEGER  ::  iskip = 4   ! number of 1st descriptor lines
-      REAL(wp) ::  zyy
+      REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:)   ::   zyy !: xCO2 record years
       CHARACTER (len=10) ::   clname = 'xco2.atm'  !! atm CO2 record file
       !!----------------------------------------------------------------------
@@ -525,5 +525,5 @@
       !                                ! Allocate CO2 hist arrays
       ierr = 0 
-      ALLOCATE( hist_pco2(co2_rec), STAT=ierr )
+      ALLOCATE( hist_pco2(co2_rec),zyy(co2_rec), STAT=ierr )
       IF( ierr > 0 ) THEN
          CALL ctl_stop( 'trc_ini_medusa_co2atm: unable to allocate  array' )   ; RETURN
@@ -540,10 +540,10 @@
       jn = 1
       DO
-        READ(inum,*, IOSTAT=io) zyy, hist_pco2(jn)
+        READ(inum,*, IOSTAT=io) zyy(jn), hist_pco2(jn)
         IF( io < 0 ) exit
-        IF(jn==1) co2_yinit = int(zyy)
+        IF(jn==1) co2_yinit = zyy(jn)
         jn = jn + 1
       END DO
-      co2_yend = co2_yinit + co2_rec - 1
+      co2_yend = co2_yinit + real(co2_rec) - 1.
 
       IF(lwp) THEN        ! Control print
@@ -553,6 +553,5 @@
          WRITE(numout,*) ' Year   xCO2 atm '
          DO jn = 1, co2_rec
-            jl = jn + co2_yinit - 1
-            WRITE(numout, '( 1I4, 6F9.2)') jl, hist_pco2(jn)
+            WRITE(numout, '( 5F7.1, 6F9.2)') zyy(jn), hist_pco2(jn)
          END DO
       ENDIF
