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 9368)
+++ branches/NERC/dev_r5518_GO6_CO2_cmip/NEMOGCM/NEMO/TOP_SRC/MEDUSA/sms_medusa.F90	(revision 9369)
@@ -288,5 +288,5 @@
    REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:)   ::   hist_pco2 !: pCO2
    INTEGER  :: co2_rec
-   REAL(wp) :: co2_yinit, co2_yend
+   REAL(wp) :: co2_yinit, co2_yend    !: First and Last year read in the xCO2.atm file
 #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 9368)
+++ branches/NERC/dev_r5518_GO6_CO2_cmip/NEMOGCM/NEMO/TOP_SRC/MEDUSA/trcini_medusa.F90	(revision 9369)
@@ -498,8 +498,8 @@
       !! ** Method  : - Read the xco2 file
       !!----------------------------------------------------------------------
-      INTEGER  ::  jn, jm, io, ierr, inum
-      INTEGER  ::  iskip = 4   ! number of 1st descriptor lines
+      INTEGER                       ::  jn, jm, io, ierr, inum, iostatus
+      INTEGER, PARAMETER            ::  iskip = 4   ! number of 1st descriptor lines
       REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:)   ::   zyy !: xCO2 record years
-      CHARACTER (len=10) ::   clname = 'xco2.atm'  !! atm CO2 record file
+      CHARACTER (len=10), PARAMETER ::  clname = 'xco2.atm'  !! atm CO2 record file
       !!----------------------------------------------------------------------
 
@@ -512,14 +512,23 @@
 
       CALL ctl_opn( inum, clname, 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
-      REWIND(inum)
-
-      ! compute the number of year in the file
-      ! file starts in 1849 do jn represent the record number in the file.
-      ! the year is jn + yinit - 1
+      !REWIND(inum)
+      !!!
+      ! -Compute the number of year in the file
+      ! -File starts in co2_yinit, jn represents the record number in the file.
+      ! -Remove the file head (iskip lines) to jn
+      ! -The year is jn + yinit - 1 
+      !! Determine the number of lines in xCO2 input file
+      iostatus = 0
       jn = 1
-      DO
-        READ(inum,'(1x)',END=100)
+      DO WHILE ( iostatus == 0 )
+        READ(inum,'(1x)', IOSTAT=iostatus, END=100)
         jn = jn + 1
-      END DO
+      ENDDO
+      IF( iostatus .NE. 0 ) THEN
+        !! Error while reading xCO2 input file 
+        CALL ctl_stop('trc_ini_medusa_co2atm: &
+                      & Error on the 1st reading of xco2.atm')
+        RETURN
+      ENDIF
  100  co2_rec = jn - 1 - iskip
       IF ( lwp) WRITE(numout,*) '    ', co2_rec ,' years read in the file'
@@ -528,5 +537,6 @@
       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
+         CALL ctl_stop( 'trc_ini_medusa_co2atm: unable to allocate  array' )  
+         RETURN
       ENDIF
 
@@ -539,10 +549,14 @@
       ! Read file till the end
       ! allocate start and end year of the file
-      jn = 1
-      DO
-        READ(inum,*, IOSTAT=io) zyy(jn), hist_pco2(jn)
-        IF( io < 0 ) exit
+      DO jn = 1, co2_rec
+        READ(inum,'(F6.1,F12.7)', IOSTAT=io) zyy(jn), hist_pco2(jn)
+        IF( io .NE. 0 ) THEN
+          !! Error while reading xCO2 input file 
+          CALL ctl_stop('trc_ini_medusa_co2atm: &
+                        & Error on the 2nd reading of xco2.atm')
+          RETURN
+        ENDIF
+
         IF(jn==1) co2_yinit = zyy(jn)
-        jn = jn + 1
       END DO
       co2_yend = co2_yinit + real(co2_rec) - 1.
@@ -554,5 +568,5 @@
          WRITE(numout,*) ' Year   xCO2 atm '
          DO jn = 1, co2_rec
-            WRITE(numout, '( 5F7.1, 6F9.2)') zyy(jn), hist_pco2(jn)
+            WRITE(numout, '(F6.1,F12.7)') zyy(jn), hist_pco2(jn)
          END DO
       ENDIF
