Index: IOIPSL/trunk/src/restcom.f90
===================================================================
--- IOIPSL/trunk/src/restcom.f90	(revision 246)
+++ IOIPSL/trunk/src/restcom.f90	(revision 259)
@@ -6,5 +6,5 @@
 !-
 USE errioipsl, ONLY : ipslerr
-USE stringop 
+USE stringop
 USE calendar
 USE mathelp
@@ -20,5 +20,5 @@
  &  ioget_expval, ioget_vdim
 !-
-INTERFACE restput 
+INTERFACE restput
   MODULE PROCEDURE &
  &  restput_r3d, restput_r2d, restput_r1d, &
@@ -28,10 +28,10 @@
 INTERFACE restget
   MODULE PROCEDURE &
- &  restget_r3d, restget_r2d, restget_r1d, &
- &  restget_opp_r2d, restget_opp_r1d
+ &  restget_r3d,restget_r2d,restget_r1d, &
+ &  restget_opp_r2d,restget_opp_r1d
 END INTERFACE
 !-
 ! We do not use allocatable arrays because these sizes are safe
-! and we do not know from start how many variables will be in 
+! and we do not know from start how many variables will be in
 ! the out file.
 !-
@@ -42,7 +42,7 @@
 !-
 ! The IDs of the netCDF files are going in pairs.
-! The input one (netcdf_id(?,1)) and the output one (netcdf_id(?,2)) 
-!-
-  INTEGER,SAVE :: nbfiles = 0 
+! The input one (netcdf_id(?,1)) and the output one (netcdf_id(?,2))
+!-
+  INTEGER,SAVE :: nb_fi = 0
   INTEGER,DIMENSION(max_file,2),SAVE :: netcdf_id = -1
 !-
@@ -81,5 +81,5 @@
 !   ?ax_infs (if,in,1) = size of axis
 !   ?ax_infs (if,in,2) = id of dimension
-! Number of x,y and z axes in the output file : 
+! Number of x,y and z axes in the output file :
 !   ?ax_nb(if)
 !-
@@ -139,13 +139,16 @@
   LOGICAL,SAVE :: lock_valexp = .FALSE.
 !-
-!- Temporary variables in which we store the attributed
-!- which are going to be given to
-!- a new variable which is going to be defined.
+! Temporary variables in which we store the attributed which are going
+! to be given to a new variable which is going to be defined.
 !-
   CHARACTER(LEN=80),SAVE :: rest_units='XXXXX',rest_lname='XXXXX'
 !-
-!===
-!-
+! For allocations
+!-
+  REAL,ALLOCATABLE,DIMENSION(:),SAVE :: buff_tmp1,buff_tmp2
+!-
+!===
 CONTAINS
+!===
 !-
 SUBROUTINE restini &
@@ -154,5 +157,5 @@
 !---------------------------------------------------------------------
 !- This subroutine sets up all the restart process.
-!- It will call the subroutine which opens the input 
+!- It will call the subroutine which opens the input
 !- and output files.
 !- The time step (itau), date of origine (date0) and time step are
@@ -181,5 +184,5 @@
 !- llm      : Dimension in the vertical
 !- lev      : Positions of the levels
-!- fnameout : 
+!- fnameout :
 !-
 !- OUTPUT
@@ -194,5 +197,5 @@
 !-
 !- owrite_time_in : logical  argument which allows to
-!-                  overwrite the time in the restart file 
+!-                  overwrite the time in the restart file
 !- domain_id      : Domain identifier
 !---------------------------------------------------------------------
@@ -210,6 +213,4 @@
   INTEGER :: ncfid
   REAL :: dt_tmp,date0_tmp
-  INTEGER,ALLOCATABLE :: tmp_index(:,:)
-  REAL,ALLOCATABLE :: tmp_julian(:,:)
   LOGICAL :: l_fi,l_fo,l_rw
   LOGICAL :: overwrite_time
@@ -230,7 +231,7 @@
   ENDIF
 !-
-  nbfiles = nbfiles+1
-!-
-  IF (nbfiles > max_file) THEN
+  nb_fi = nb_fi+1
+!-
+  IF (nb_fi > max_file) THEN
     CALL ipslerr (3,'restini',&
  &   'Too many restart files are used. The problem can be',&
@@ -254,21 +255,19 @@
   ENDIF
 !-
-! 1.0 Open the input file.  
+! 1.0 Open the input file.
 !-
   IF (l_fi) THEN
 !---
-    IF (check) WRITE(*,*) 'restini 1.0 : Open input file' 
+    IF (check) WRITE(*,*) 'restini 1.0 : Open input file'
 !-- Add DOMAIN number and ".nc" suffix in file names if needed
     fname = fnamein
     CALL flio_dom_file (fname,domain_id)
 !-- Open the file
-    CALL restopenin &
-      (nbfiles,fname,l_rw,iim,jjm, &
-       lon,lat,llm,lev,ncfid)
-    netcdf_id(nbfiles,1) = ncfid
+    CALL restopenin (nb_fi,fname,l_rw,iim,jjm,lon,lat,llm,lev,ncfid)
+    netcdf_id(nb_fi,1) = ncfid
 !---
 !-- 1.3 Extract the time information
 !---
-    CALL restsett (nbfiles,dt_tmp,date0_tmp)
+    CALL restsett (dt_tmp,date0_tmp,itau,overwrite_time)
     IF (.NOT.overwrite_time) THEN
       dt = dt_tmp
@@ -279,5 +278,5 @@
 !---
 !-- 2.0 The case of a missing restart file is dealt with
-!---         
+!---
     IF (check) WRITE(*,*) 'restini 2.0'
 !---
@@ -306,37 +305,8 @@
 !-- 2.2 Allocate the time axes and write the inputed variables
 !---
-    tax_size_in(nbfiles) = 1
-    IF ( .NOT.ALLOCATED(t_index) .AND. .NOT.ALLOCATED(t_julian) ) THEN
-      IF (check) THEN
-        WRITE(*,*) 'restini : Allocate times axes at :', &
-                   max_file,tax_size_in(nbfiles)
-      ENDIF
-      ALLOCATE(t_index(max_file,tax_size_in(nbfiles)))
-      t_index (:,:) = 0
-      ALLOCATE(t_julian(max_file,tax_size_in(nbfiles)))
-      t_julian (:,:) = 0.0
-    ELSE
-      IF (    (SIZE(t_index,DIM=2)  < tax_size_in(nbfiles)) &
-          .OR.(SIZE(t_julian,DIM=2) < tax_size_in(nbfiles)) ) THEN
-        IF (check) THEN
-          WRITE(*,*) 'restini : Reallocate times axes at :', &
-                     max_file,tax_size_in(nbfiles)
-        ENDIF
-        ALLOCATE(tmp_index(max_file,tax_size_in(nbfiles)))
-        ALLOCATE(tmp_julian(max_file,tax_size_in(nbfiles)))
-        tmp_index(:,:) = t_index(:,:)
-        tmp_julian(:,:) = t_julian(:,:)
-        DEALLOCATE(t_index)
-        DEALLOCATE(t_julian)
-        ALLOCATE(t_index(max_file,tax_size_in(nbfiles)))
-        ALLOCATE(t_julian(max_file,tax_size_in(nbfiles)))
-        t_index(:,:) = tmp_index(:,:)
-        t_julian(:,:) = tmp_julian(:,:)
-      ENDIF
-    ENDIF
-!---
-    t_index(nbfiles,1) = itau
-    t_julian(nbfiles,1) = date0
-!---
+    tax_size_in(nb_fi) = 1
+    CALL rest_atim (check,'restini')
+    t_index(nb_fi,1) = itau
+    t_julian(nb_fi,1) = date0
   ENDIF
 !-
@@ -347,15 +317,14 @@
 !-- Open the file
     CALL restopenout &
-      (nbfiles,fname,iim,jjm, &
-       lon,lat,llm,lev,dt,date0,ncfid,domain_id)
-    netcdf_id(nbfiles,2) = ncfid
+      (nb_fi,fname,iim,jjm,lon,lat,llm,lev,dt,date0,ncfid,domain_id)
+    netcdf_id(nb_fi,2) = ncfid
   ELSE IF (l_fi.AND.l_fo) THEN
-    netcdf_id(nbfiles,2) = netcdf_id(nbfiles,1)
-    varname_out(nbfiles,:) = varname_in(nbfiles,:) 
-    nbvar_out(nbfiles) = nbvar_in(nbfiles) 
-    tind_varid_out(nbfiles) = tind_varid_in(nbfiles) 
-    tax_varid_out(nbfiles) = tax_varid_in(nbfiles) 
-    varid_out(nbfiles,:) = varid_in(nbfiles,:) 
-    touched_out(nbfiles,:) = .TRUE.
+    netcdf_id(nb_fi,2) = netcdf_id(nb_fi,1)
+    varname_out(nb_fi,:) = varname_in(nb_fi,:)
+    nbvar_out(nb_fi) = nbvar_in(nb_fi)
+    tind_varid_out(nb_fi) = tind_varid_in(nb_fi)
+    tax_varid_out(nb_fi) = tax_varid_in(nb_fi)
+    varid_out(nb_fi,:) = varid_in(nb_fi,:)
+    touched_out(nb_fi,:) = .TRUE.
   ENDIF
 !-
@@ -372,27 +341,27 @@
   IF (INDEX(calend_str,'unknown') < 1) THEN
     CALL ioconf_calendar (calend_str)
-  ENDIF
-!-
-  IF (check) WRITE(*,*) 'After possible calendar configuration'
+    IF (check) THEN
+      WRITE(*,*) 'restini 2.3b : new calendar : ',calend_str
+    ENDIF
+  ENDIF
 !-
 ! Save some data in the module
 !-
-  deltat(nbfiles) = dt
+  deltat(nb_fi) = dt
 !-
 ! Prepare the variables which will be returned
 !-
-  fid = nbfiles
+  fid = nb_fi
   IF (check) THEN
     WRITE(*,*) 'SIZE of t_index :',SIZE(t_index), &
                SIZE(t_index,dim=1),SIZE(t_index,dim=2)
+    WRITE(*,*) 't_index = ',t_index(fid,:)
   ENDIF
   itau = t_index(fid,1)
 !-
-  IF (check) WRITE(*,*) 'restini END' 
+  IF (check) WRITE(*,*) 'restini END'
 !---------------------
 END SUBROUTINE restini
-!-
-!===
-!-
+!===
 SUBROUTINE restopenin &
   (fid,fname,l_rw,iim,jjm,lon,lat,llm,lev,ncfid)
@@ -415,12 +384,13 @@
 ! LOCAL
 !-
-  INTEGER :: var_dims(max_dim),dimlen(max_dim)
+  INTEGER,DIMENSION(max_dim) :: var_dims,dimlen
   INTEGER :: nb_dim,nb_var,id_unl,id,iv
-  INTEGER :: iread,jread,lread,iret,idi
+  INTEGER :: iread,jread,lread,iret
   INTEGER :: lon_vid,lat_vid
   REAL :: lon_read(iim,jjm),lat_read(iim,jjm)
   REAL :: lev_read(llm)
   REAL :: mdlon,mdlat
-  CHARACTER(LEN=80) :: units,dimname
+  CHARACTER(LEN=80) :: units
+  CHARACTER(LEN=NF90_max_name),DIMENSION(max_dim) :: dimname
   LOGICAL :: check = .FALSE.
 !---------------------------------------------------------------------
@@ -444,5 +414,5 @@
       & 'More dimensions present in file that can be store',&
       & 'Please increase max_dim in the global variables ',&
-      & ' in restcom.F90')
+      & 'in restcom.F90')
   ENDIF
   IF (nb_var > max_var) THEN
@@ -455,10 +425,22 @@
   nbvar_in(fid) = nb_var
   nbdim_in(fid) = nb_dim
-  DO idi=1,nb_dim
-    iret = NF90_INQUIRE_DIMENSION(ncfid,idi,len=dimlen(idi))
+  iread = -1; jread = -1; lread = -1;
+  DO id=1,nb_dim
+    iret = NF90_INQUIRE_DIMENSION(ncfid,id, &
+ &           len=dimlen(id),name=dimname(id))
+    IF (check) THEN
+      WRITE (*,*) "restopenin 0.0 dimname",id,TRIM(dimname(id))
+    ENDIF
+    IF      (TRIM(dimname(id)) == 'x') THEN
+      iread = dimlen(id)
+      IF (check) WRITE (*,*) "iread",iread
+    ELSE IF (TRIM(dimname(id)) == 'y') THEN
+      jread = dimlen(id)
+      IF (check) WRITE (*,*) "jread",jread
+    ELSE IF (TRIM(dimname(id)) == 'z') THEN
+      lread = dimlen(id)
+      IF (check) WRITE (*,*) "lread",lread
+    ENDIF
   ENDDO
-  iread = dimlen(1)
-  jread = dimlen(2)
-  lread = dimlen(3)
 !-
   IF (id_unl > 0) THEN
@@ -469,7 +451,12 @@
 !---
     IF (l_rw) THEN
-      iret = NF90_INQUIRE_DIMENSION(ncfid,id_unl,len=tstp_out(fid))
+      tstp_out(fid) = dimlen(id_unl)
       itau_out(fid) = -1
-      tdimid_out(fid) =  tdimid_in(fid) 
+      tdimid_out(fid) =  tdimid_in(fid)
+      IF (check) THEN
+        WRITE (*,*) &
+ &       "restopenin 0.0 unlimited axis dimname", &
+ &       dimname(id_unl),tstp_out(fid)
+      ENDIF
 !-----
       xax_nb(fid) = 0
@@ -478,19 +465,15 @@
 !-----
       DO id=1,nb_dim
-        iret = NF90_INQUIRE_DIMENSION(ncfid,id,name=dimname)
-        IF      (dimname(1:1) == 'x') THEN
+        IF      (dimname(id)(1:1) == 'x') THEN
           xax_nb(fid) = xax_nb(fid)+1
-          iret = NF90_INQUIRE_DIMENSION &
- &                 (ncfid,id,len=xax_infs(fid,xax_nb(fid),1))
+          xax_infs(fid,xax_nb(fid),1) = dimlen(id)
           xax_infs(fid,xax_nb(fid),2) = id
-        ELSE IF (dimname(1:1) == 'y') THEN
+        ELSE IF (dimname(id)(1:1) == 'y') THEN
           yax_nb(fid) = yax_nb(fid)+1
-          iret = NF90_INQUIRE_DIMENSION &
- &                 (ncfid,id,len=yax_infs(fid,yax_nb(fid),1))
+          yax_infs(fid,yax_nb(fid),1) = dimlen(id)
           yax_infs(fid,yax_nb(fid),2) = id
-        ELSE IF (dimname(1:1) == 'z') THEN
+        ELSE IF (dimname(id)(1:1) == 'z') THEN
           zax_nb(fid) = zax_nb(fid)+1
-          iret = NF90_INQUIRE_DIMENSION &
- &                 (ncfid,id,len=zax_infs(fid,zax_nb(fid),1))
+          zax_infs(fid,zax_nb(fid),1) = dimlen(id)
           zax_infs(fid,zax_nb(fid),2) = id
         ENDIF
@@ -507,14 +490,5 @@
 ! 1.0 First let us check that we have the righ restart file
 !-
-  IF (iread /= iim .OR. jread /= jjm .OR. lread /= llm) THEN
-    CALL ipslerr (3,'restopenin',&
- &    'The grid of the restart file does not correspond',&
- &    'to that of the model',' ')
-  ENDIF
-!-
-! We know that we have a time axis. Thus the 4th dimension needs
-! to be the levels.
-!-
-  IF (nb_dim > 3 .AND. dimlen(3) /= llm) THEN
+  IF ((iread /= iim).OR.(jread /= jjm).OR.(lread /= llm)) THEN
     CALL ipslerr (3,'restopenin',&
  &    'The grid of the restart file does not correspond',&
@@ -561,5 +535,5 @@
       ENDIF
       IF (     (INDEX(units,'seconds since') > 0) &
-          .AND.(tax_varid_in(fid) < 0) ) THEN    
+          .AND.(tax_varid_in(fid) < 0) ) THEN
         tax_varid_in(fid) = iv
         tax_size_in(fid) = vardims_in(fid,iv,1)
@@ -578,5 +552,5 @@
   ENDDO
 !-
-! 2.4 None of the variables was yet read 
+! 2.4 None of the variables was yet read
 !-
   nbvar_read(fid) = 0
@@ -616,5 +590,5 @@
 !---- We can not test against epsilon here as the longitude
 !---- can be stored at another precision in the netCDF file.
-!---- The test here does not need to be very precise.            
+!---- The test here does not need to be very precise.
 !-----
       IF (mdlon > 1.e-4 .OR. mdlat > 1.e-4) THEN
@@ -628,10 +602,8 @@
 !------------------------
 END SUBROUTINE restopenin
-!-
-!===
-!-
-SUBROUTINE restsett (fid,timestep,date0)
-!---------------------------------------------------------------------
-!- Here we get all the time information from the file. 
+!===
+SUBROUTINE restsett (timestep,date0,itau,owrite_time_in)
+!---------------------------------------------------------------------
+!- Here we get all the time information from the file.
 !-
 !- The time information can come in three forms :
@@ -642,66 +614,59 @@
 !- -A time-step axis exists and itau is positioned on it.
 !-
-!- What takes precedence ? No idea yet !
+!- What takes precedence : the model
+!-
+!- itau     : Time step of the model
+!-
+!- Optional INPUT arguments
+!-
+!- owrite_time_in : logical  argument which allows to
+!-                  overwrite the time in the restart file
 !---------------------------------------------------------------------
   IMPLICIT NONE
 !-
-  INTEGER :: fid
   REAL :: date0,timestep
+  INTEGER :: itau
+  LOGICAL,OPTIONAL :: owrite_time_in
 !-
 ! LOCAL
 !-
-  INTEGER :: ncfid,iret,it,iax,iv,tszij
-  INTEGER,ALLOCATABLE :: tmp_index(:,:)
-  REAL,ALLOCATABLE :: tmp_julian(:,:)
+  INTEGER :: ncfid,iret,it,iax,iv
   CHARACTER(LEN=80) :: itau_orig,tax_orig,calendar
   CHARACTER(LEN=9) :: tmp_cal
   INTEGER :: year0,month0,day0,hours0,minutes0,seci
-  REAL :: sec0,un_jour,un_an,date0_ju,ttmp
+  REAL :: sec0,one_day,one_year,date0_ju,ttmp
   CHARACTER :: strc
+  LOGICAL :: ow_time
 !-
   LOGICAL :: check = .FALSE.
 !---------------------------------------------------------------------
-!-
-  ncfid = netcdf_id(fid,1)
-!-
-!  Allocate the space we need for the time axes
-!-
-  IF (.NOT.ALLOCATED(t_index) .AND. .NOT.ALLOCATED(t_julian) ) THEN
-    IF (check) THEN
-      WRITE(*,*) 'restsett : Allocate times axes at :', &
-                 max_file,tax_size_in(fid)
-    ENDIF
-    ALLOCATE(t_index(max_file,tax_size_in(fid)))
-    ALLOCATE(t_julian(max_file,tax_size_in(fid)))
+  IF (PRESENT(owrite_time_in)) THEN
+    ow_time = owrite_time_in
   ELSE
-    tszij = SIZE(t_index,DIM=2)
-    IF (tszij < tax_size_in(fid)) THEN
+    ow_time = .FALSE.
+  ENDIF
+!-
+  ncfid = netcdf_id(nb_fi,1)
+!-
+! Allocate the space we need for the time axes
+!-
+  CALL rest_atim (check,'restsett')
+!-
+! Get the calendar if possible. Else it will be gregorian.
+!-
+  IF (tax_size_in(nb_fi) > 0 ) THEN
+    calendar = 'XXXXX'
+    iret = NF90_GET_ATT(ncfid,tax_varid_in(nb_fi),'calendar',calendar)
+    IF ( INDEX(calendar,'XXXXX') < 0 ) THEN
+      CALL ioconf_calendar (calendar)
       IF (check) THEN
-        WRITE(*,*) 'restsett : Reallocate times axes at :', &
-                   max_file,tax_size_in(fid)
+        WRITE(*,*) 'restsett : calendar of the restart ',calendar
       ENDIF
-      ALLOCATE(tmp_index(max_file,tax_size_in(fid)))
-      ALLOCATE(tmp_julian(max_file,tax_size_in(fid)))
-      tmp_index(:,1:tszij) = t_index(:,1:tszij)
-      tmp_julian(:,1:tszij) = t_julian(:,1:tszij)
-      DEALLOCATE(t_index)
-      DEALLOCATE(t_julian)
-      ALLOCATE(t_index(max_file,tax_size_in(fid)))
-      ALLOCATE(t_julian(max_file,tax_size_in(fid)))
-      t_index(:,:) = tmp_index(:,:)
-      t_julian(:,:) = tmp_julian(:,:)
-    ENDIF
-  ENDIF
-!-
-! Get the calendar if possible. Else it will be gregorian.
-!-
-  IF (tax_size_in(fid) > 0 ) THEN
-     calendar = 'XXXXX'
-     iret = NF90_GET_ATT(ncfid,tax_varid_in(fid),'calendar',calendar)
-     IF ( INDEX(calendar,'XXXXX') < 0 ) THEN
-       CALL ioconf_calendar (calendar)
-     ENDIF
-  ENDIF
-  CALL ioget_calendar (un_an,un_jour)
+    ENDIF
+  ENDIF
+  CALL ioget_calendar (one_year,one_day)
+  IF (check) THEN
+    WRITE(*,*) 'one_year,one_day = ',one_year,one_day
+  ENDIF
 !-
   itau_orig = 'XXXXX'
@@ -710,29 +675,55 @@
 ! Get the time steps of the time axis if available on the restart file
 !-
-  IF (tind_varid_in(fid) > 0) THEN
-    iret = NF90_GET_VAR(ncfid,tind_varid_in(fid),t_index(fid,:))
-    iret = NF90_GET_ATT(ncfid,tind_varid_in(fid),'units',itau_orig)
-    itau_orig = &
-      itau_orig(INDEX(itau_orig,'since')+6:LEN_TRIM(itau_orig))
-    iret = &
- &    NF90_GET_ATT(ncfid,tind_varid_in(fid),'tstep_sec',timestep)
-!---
-!-- This time origin will dominate as it is linked to the time steps.
-!---
-    READ (UNIT=itau_orig,FMT='(I4.4,5(a,I2.2))') &
- &    year0,strc,month0,strc,day0,strc, &
- &    hours0,strc,minutes0,strc,seci
-    sec0 = REAL(seci)
-    sec0 = hours0*3600.+minutes0*60.+sec0
-    CALL ymds2ju (year0,month0,day0,sec0,date0)
+  IF (tind_varid_in(nb_fi) > 0) THEN
+    IF (ow_time) THEN
+      t_index(nb_fi,:) = itau
+      IF (check) THEN
+        WRITE(*,*) "nb_fi,t_index",nb_fi,t_index(nb_fi,:)
+      ENDIF
+      CALL ju2ymds (date0,year0,month0,day0,sec0)
+      hours0 = NINT(sec0/3600)
+      sec0 = sec0 - 3600 * hours0
+      minutes0 = NINT(sec0 / 60)
+      sec0 = sec0 - 60 * minutes0
+      seci = NINT(sec0)
+      strc=':'
+      IF (check) THEN
+        WRITE(*,*) date0
+        WRITE (UNIT=itau_orig,FMT='(I4.4,5(A,I2.2))') &
+ &       year0,'-',month0,'-',day0,' ',hours0,':',minutes0,':',seci
+        WRITE(*,*) "itau_orig : ",itau_orig
+      ENDIF
+    ELSE
+      iret = NF90_GET_VAR(ncfid,tind_varid_in(nb_fi),t_index(nb_fi,:))
+      IF (check) THEN
+        WRITE(*,*) "restsett, time axis : ",t_index(nb_fi,:)
+      ENDIF
+      iret = NF90_GET_ATT(ncfid,tind_varid_in(nb_fi),'units',itau_orig)
+      itau_orig = &
+ &      itau_orig(INDEX(itau_orig,'since')+6:LEN_TRIM(itau_orig))
+      iret = &
+ &      NF90_GET_ATT(ncfid,tind_varid_in(nb_fi),'tstep_sec',timestep)
+!-----
+!---- This time origin will dominate as it is linked to the time steps.
+!-----
+      READ (UNIT=itau_orig,FMT='(I4.4,5(A,I2.2))') &
+ &      year0,strc,month0,strc,day0,strc, &
+ &      hours0,strc,minutes0,strc,seci
+      sec0 = REAL(seci)
+      sec0 = hours0*3600.+minutes0*60.+sec0
+      CALL ymds2ju (year0,month0,day0,sec0,date0)
+    ENDIF
   ENDIF
 !-
 ! If a julian day time axis is available then we get it
 !-
-  IF (tax_varid_in(fid) > 0) THEN
-    iret = NF90_GET_VAR(ncfid,tax_varid_in(fid),t_julian(fid,:))
-    iret = NF90_GET_ATT(ncfid,tax_varid_in(fid),'units',tax_orig)
+  IF (tax_varid_in(nb_fi) > 0) THEN
+    iret = NF90_GET_VAR(ncfid,tax_varid_in(nb_fi),t_julian(nb_fi,:))
+    iret = NF90_GET_ATT(ncfid,tax_varid_in(nb_fi),'units',tax_orig)
     tax_orig = tax_orig(INDEX(tax_orig,'since')+6:LEN_TRIM(tax_orig))
-    iret = NF90_GET_ATT(ncfid,tax_varid_in(fid),'calendar',tmp_cal)
+    iret = NF90_GET_ATT(ncfid,tax_varid_in(nb_fi),'calendar',tmp_cal)
+    IF (check) THEN
+      WRITE(*,*) 'restsett : tmp_calendar of the restart ',tmp_cal
+    ENDIF
 !---
     CALL strlowercase (tmp_cal)
@@ -757,5 +748,5 @@
     sec0 = hours0*3600.+minutes0*60.+sec0
     CALL ymds2ju (year0,month0,day0,sec0,date0_ju)
-    t_julian(fid,:) = t_julian(fid,:)/un_jour+date0_ju
+    t_julian(nb_fi,:) = t_julian(nb_fi,:)/one_day+date0_ju
   ENDIF
 !-
@@ -767,6 +758,6 @@
   IF (     (INDEX(tax_orig,'XXXXX')  > 0) &
       .AND.(INDEX(itau_orig,'XXXXX') < 0) ) THEN
-    DO it=1,tax_size_in(fid)
-      t_julian(fid,it) = itau2date(t_index(fid,it),date0,timestep)
+    DO it=1,tax_size_in(nb_fi)
+      t_julian(nb_fi,it) = itau2date(t_index(nb_fi,it),date0,timestep)
     ENDDO
   ENDIF
@@ -775,8 +766,9 @@
 ! This is for compatibility reasons and should not be used.
 !-
-  IF ( (tax_varid_in(fid) < 0) .AND. (tind_varid_in(fid) < 0) ) THEN
+  IF ((tax_varid_in(nb_fi) < 0).AND.(tind_varid_in(nb_fi) < 0)) THEN
     iax = -1
-    DO iv=1,nbvar_in(fid)
-      IF (INDEX(varname_in(fid,iv),'tsteps') > 0) THEN
+    DO iv=1,nbvar_in(nb_fi)
+      IF (    (INDEX(varname_in(nb_fi,iv),'tsteps') > 0) &
+ &        .OR.(INDEX(varname_in(nb_fi,iv),'time_steps') > 0)) THEN
         iax = iv
       ENDIF
@@ -789,6 +781,5 @@
         & ' ')
     ELSE
-      iret = NF90_GET_VAR(ncfid,tind_varid_in(fid),t_index(fid,:))
-!---
+      iret = NF90_GET_VAR(ncfid,tind_varid_in(nb_fi),t_index(nb_fi,:))
       iret = NF90_GET_ATT(ncfid,NF90_GLOBAL,'delta_tstep_sec',timestep)
       iret = NF90_GET_ATT(ncfid,NF90_GLOBAL,'year0',ttmp)
@@ -797,16 +788,14 @@
       month0 = NINT(ttmp)
       iret = NF90_GET_ATT(ncfid,NF90_GLOBAL,'day0',ttmp)
-      day0 = NINT(ttmp) 
+      day0 = NINT(ttmp)
       iret = NF90_GET_ATT(ncfid,NF90_GLOBAL,'sec0',sec0)
 !---
       CALL ymds2ju (year0,month0,day0,sec0,date0)
-      t_julian(fid,1) = itau2date(t_index(fid,1),date0,timestep)
+      t_julian(nb_fi,1) = itau2date(t_index(nb_fi,1),date0,timestep)
     ENDIF
   ENDIF
 !----------------------
 END SUBROUTINE restsett
-!-
-!===
-!-
+!===
 SUBROUTINE restopenout &
   (fid,fname,iim,jjm, &
@@ -873,6 +862,5 @@
   IF (check) WRITE(*,*) "restopenout 1.0"
 !-
-  iret = NF90_DEF_VAR(ncfid,"nav_lon",NF90_FLOAT, &
- &                     (/ x_id, y_id /),nlonid)
+  iret = NF90_DEF_VAR(ncfid,"nav_lon",NF90_FLOAT,(/x_id,y_id/),nlonid)
   iret = NF90_PUT_ATT(ncfid,nlonid,'units',"degrees_east")
   iret = NF90_PUT_ATT(ncfid,nlonid,'valid_min',REAL(-180.,KIND=4))
@@ -884,6 +872,5 @@
   IF (check) WRITE(*,*) "restopenout 2.0"
 !-
-  iret = NF90_DEF_VAR(ncfid,"nav_lat",NF90_FLOAT, &
- &                     (/ x_id, y_id /),nlatid)
+  iret = NF90_DEF_VAR(ncfid,"nav_lat",NF90_FLOAT,(/x_id,y_id/),nlatid)
   iret = NF90_PUT_ATT(ncfid,nlatid,'units',"degrees_north")
   iret = NF90_PUT_ATT(ncfid,nlatid,'valid_min',REAL(-90.,KIND=4))
@@ -902,5 +889,5 @@
  &                     REAL(MAXVAL(lev),KIND=4))
   iret = NF90_PUT_ATT(ncfid,nlevid,'long_name',"Model levels")
-!- 
+!-
 ! 4.0 Time axis, this is the seconds since axis
 !-
@@ -930,5 +917,5 @@
  &  year,cal(month),day,hours,minutes,INT(sec)
   iret = NF90_PUT_ATT(ncfid,timeid,'time_origin',TRIM(str_t))
-!- 
+!-
 ! 5.0 Time axis, this is the time steps since axis
 !-
@@ -994,14 +981,12 @@
 !-
   iret = NF90_REDEF(ncfid)
-!- 
+!-
   IF (check) WRITE(*,*) "restopenout END"
 !-------------------------
 END SUBROUTINE restopenout
-!-
-!===
-!-
+!===
 SUBROUTINE restget_opp_r1d &
-  (fid,vname_q,iim,jjm,llm,itau,def_beha, &
-   var,OPERATOR,nbindex,ijndex)
+ & (fid,vname_q,iim,jjm,llm,itau,def_beha, &
+ &  var,MY_OPERATOR,nbindex,ijndex)
 !---------------------------------------------------------------------
 !- This subroutine serves as an interface to restget_real
@@ -1016,11 +1001,10 @@
   LOGICAL def_beha
   REAL :: var(:)
-  CHARACTER(LEN=*) :: OPERATOR
+  CHARACTER(LEN=*) :: MY_OPERATOR
   INTEGER :: nbindex,ijndex(nbindex)
 !-
-!- LOCAL
-!-
-  INTEGER :: req_sz
-  REAL,ALLOCATABLE,SAVE :: buff_tmp(:),buff_tmp2(:)
+! LOCAL
+!-
+  INTEGER :: req_sz,siz1
   REAL :: scal
   CHARACTER(LEN=7) :: topp
@@ -1028,5 +1012,5 @@
 !---------------------------------------------------------------------
 !-
-!  0.0 What size should be the data in the file
+! 0.0 What size should be the data in the file
 !-
   req_sz = 1
@@ -1041,32 +1025,10 @@
   ENDIF
 !-
-!  1.0 Allocate the temporary buffer we need
-!      to put the variable in right dimension
-!-
-  IF (.NOT.ALLOCATED(buff_tmp)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restget_opp_r1d : allocate buff_tmp = ",SIZE(var)
-    ENDIF
-    ALLOCATE(buff_tmp(SIZE(var)))
-  ELSE IF (SIZE(var) > SIZE(buff_tmp)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restget_opp_r1d : re-allocate buff_tmp= ",SIZE(var)
-    ENDIF
-    DEALLOCATE(buff_tmp)
-    ALLOCATE(buff_tmp(SIZE(var)))
-  ENDIF
-!-
-  IF (.NOT.ALLOCATED(buff_tmp2)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restget_opp_r1d : allocate buff_tmp2 = ",req_sz
-    ENDIF
-    ALLOCATE(buff_tmp2(req_sz))
-  ELSE IF (req_sz > SIZE(buff_tmp2)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restget_opp_r1d : re-allocate buff_tmp2= ",req_sz
-    ENDIF
-    DEALLOCATE(buff_tmp2)
-    ALLOCATE(buff_tmp2(req_sz))
-  ENDIF
+! 1.0 Allocate the temporary buffer we need
+!     to put the variable in right dimension
+!-
+  siz1 = SIZE(var)
+  CALL rest_alloc (1,siz1,check,'restget_opp_r1d')
+  CALL rest_alloc (2,req_sz,check,'restget_opp_r1d')
 !-
 ! 2.0 Here we get the variable from the restart file
@@ -1076,16 +1038,14 @@
      zax_infs(fid,1,1),itau,def_beha,buff_tmp2)
 !-
-!  4.0 Transfer the buffer obtained from the restart file
-!      into the variable the model expects
-!-
-  topp = OPERATOR(1:MIN(LEN_TRIM(OPERATOR),7))
+! 4.0 Transfer the buffer obtained from the restart file
+!     into the variable the model expects
+!-
+  topp = MY_OPERATOR(1:MIN(LEN_TRIM(MY_OPERATOR),7))
 !-
   IF (INDEX(indchfun,topp(:LEN_TRIM(topp))) > 0) THEN
     scal = missing_val
-!---
     CALL mathop (topp,req_sz,buff_tmp2,missing_val, &
-                 nbindex,ijndex,scal,SIZE(var),buff_tmp)
-!---
-    var(:) = buff_tmp(:) 
+ &               nbindex,ijndex,scal,siz1,buff_tmp1)
+    var(:) = buff_tmp1(1:siz1)
   ELSE
     CALL ipslerr (3,'resget_opp_r1d', &
@@ -1095,10 +1055,8 @@
 !-----------------------------
 END SUBROUTINE restget_opp_r1d
-!-
-!===
-!-
+!===
 SUBROUTINE restget_opp_r2d &
-  (fid,vname_q,iim,jjm,llm,itau,def_beha, &
-   var,OPERATOR,nbindex,ijndex)
+ & (fid,vname_q,iim,jjm,llm,itau,def_beha, &
+ &  var,MY_OPERATOR,nbindex,ijndex)
 !---------------------------------------------------------------------
 !- This subroutine serves as an interface to restget_real
@@ -1113,11 +1071,10 @@
   LOGICAL def_beha
   REAL :: var(:,:)
-  CHARACTER(LEN=*) :: OPERATOR
+  CHARACTER(LEN=*) :: MY_OPERATOR
   INTEGER :: nbindex,ijndex(nbindex)
 !-
-!- LOCAL
-!-
-  INTEGER :: jj,req_sz,ist,var_sz
-  REAL,ALLOCATABLE,SAVE :: buff_tmp(:),buff_tmp2(:)
+! LOCAL
+!-
+  INTEGER :: jj,req_sz,ist,var_sz,siz1
   REAL :: scal
   CHARACTER(LEN=7) :: topp
@@ -1125,5 +1082,5 @@
 !---------------------------------------------------------------------
 !-
-!  0.0 What size should be the data in the file
+! 0.0 What size should be the data in the file
 !-
   req_sz = 1
@@ -1146,51 +1103,27 @@
 !     to put the variable in right dimension
 !-
-  IF (.NOT.ALLOCATED(buff_tmp)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restget_opp_r2d : allocate buff_tmp = ",SIZE(var,1)
-    ENDIF
-    ALLOCATE(buff_tmp(SIZE(var,1)))
-  ELSE IF (SIZE(var,1) > SIZE(buff_tmp)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restget_opp_r2d : re-allocate buff_tmp= ",SIZE(var,1)
-    ENDIF
-    DEALLOCATE(buff_tmp)
-    ALLOCATE(buff_tmp(SIZE(var,1)))
-  ENDIF
-!-
-  IF (.NOT.ALLOCATED(buff_tmp2)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restget_opp_r2d : allocate buff_tmp2 = ",req_sz*jjm
-    ENDIF
-    ALLOCATE(buff_tmp2(req_sz*jjm))
-  ELSE IF (req_sz*jjm > SIZE(buff_tmp2)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restget_opp_r2d : re-allocate buff_tmp2= ",req_sz*jjm
-    ENDIF
-    DEALLOCATE(buff_tmp2)
-    ALLOCATE(buff_tmp2(req_sz*jjm))
-  ENDIF
+  siz1 = SIZE(var,1)
+  CALL rest_alloc (1,siz1,check,'restget_opp_r2d')
+  CALL rest_alloc (2,req_sz*jjm,check,'restget_opp_r2d')
 !-
 ! 2.0 Here we get the full variable from the restart file
 !-
   CALL restget_real &
-    (fid,vname_q,xax_infs(fid,1,1),yax_infs(fid,1,1), &
-     jjm,itau,def_beha,buff_tmp2)
-!-
-!  4.0 Transfer the buffer obtained from the restart file
-!      into the variable the model expects
-!-
-  topp = OPERATOR(1:MIN(LEN_TRIM(OPERATOR),7))
+ & (fid,vname_q,xax_infs(fid,1,1),yax_infs(fid,1,1), &
+ &  jjm,itau,def_beha,buff_tmp2)
+!-
+! 4.0 Transfer the buffer obtained from the restart file
+!     into the variable the model expects
+!-
+  topp = MY_OPERATOR(1:MIN(LEN_TRIM(MY_OPERATOR),7))
 !-
   IF (INDEX(indchfun,topp(:LEN_TRIM(topp))) > 0) THEN
     scal = missing_val
-    var_sz = SIZE(var,1)
-!---
+    var_sz = siz1
     DO jj = 1,jjm
       ist = (jj-1)*req_sz+1
       CALL mathop (topp,req_sz,buff_tmp2(ist:ist+req_sz-1), &
- &      missing_val,nbindex,ijndex,scal,var_sz,buff_tmp)
-!-----
-      var(:,jj) = buff_tmp(:) 
+ &      missing_val,nbindex,ijndex,scal,var_sz,buff_tmp1)
+      var(:,jj) = buff_tmp1(1:siz1)
     ENDDO
   ELSE
@@ -1201,9 +1134,7 @@
 !-----------------------------
 END SUBROUTINE restget_opp_r2d
-!-
-!===
-!-
+!===
 SUBROUTINE restget_r1d &
-  (fid,vname_q,iim,jjm,llm,itau,def_beha,var)
+ & (fid,vname_q,iim,jjm,llm,itau,def_beha,var)
 !---------------------------------------------------------------------
 !- This subroutine serves as an interface to restget_real
@@ -1217,8 +1148,7 @@
   REAL :: var(:)
 !-
-!- LOCAL
-!-
-  INTEGER :: ji,jl,req_sz,var_sz
-  REAL,ALLOCATABLE,SAVE :: buff_tmp(:)
+! LOCAL
+!-
+  INTEGER :: ji,jl,req_sz,var_sz,siz1
   CHARACTER(LEN=70) :: str,str2
   LOGICAL :: check = .FALSE.
@@ -1228,14 +1158,7 @@
 !     to put the variable in right dimension
 !-
-  IF (.NOT.ALLOCATED(buff_tmp)) THEN
-    IF (check) WRITE(*,*) "restget_r1d : allocate buff_tmp = ",SIZE(var)
-    ALLOCATE(buff_tmp(SIZE(var)))
-  ELSE IF (SIZE(var) > SIZE(buff_tmp)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restget_r1d : re-allocate buff_tmp= ",SIZE(var)
-    ENDIF
-    DEALLOCATE(buff_tmp)
-    ALLOCATE(buff_tmp(SIZE(var)))
-  ENDIF
+  siz1 = SIZE(var)
+  var_sz = siz1
+  CALL rest_alloc (1,var_sz,check,'restget_r1d')
 !-
 ! 2.0 Here we could check if the sizes specified agree
@@ -1246,5 +1169,4 @@
   IF (jjm > 0) req_sz = req_sz*jjm
   IF (llm > 0) req_sz = req_sz*llm
-  var_sz = SIZE(var,1)
   IF (req_sz > var_sz) THEN
     WRITE(str, &
@@ -1264,5 +1186,5 @@
 !-
   CALL restget_real &
-    (fid,vname_q,iim,jjm,llm,itau,def_beha,buff_tmp)
+ & (fid,vname_q,iim,jjm,llm,itau,def_beha,buff_tmp1)
 !-
 ! 4.0 Transfer the buffer obtained from the restart file
@@ -1270,15 +1192,13 @@
 !-
   jl=0
-  DO ji=1,SIZE(var,1)
+  DO ji=1,siz1
     jl=jl+1
-    var(ji) = buff_tmp(jl)
+    var(ji) = buff_tmp1(jl)
   ENDDO
 !-------------------------
 END SUBROUTINE restget_r1d
-!-
-!===
-!-
+!===
 SUBROUTINE restget_r2d &
-  (fid,vname_q,iim,jjm,llm,itau,def_beha,var)
+ & (fid,vname_q,iim,jjm,llm,itau,def_beha,var)
 !---------------------------------------------------------------------
 !- This subroutine serves as an interface to restget_real
@@ -1292,30 +1212,21 @@
   REAL :: var(:,:)
 !-
-!- LOCAL
-!-
-  INTEGER :: ji,jj,jl,req_sz,var_sz
-  REAL,ALLOCATABLE,SAVE :: buff_tmp(:)
+! LOCAL
+!-
+  INTEGER :: ji,jj,jl,req_sz,var_sz,siz1,siz2
   CHARACTER(LEN=70) :: str,str2
   LOGICAL :: check = .FALSE.
 !---------------------------------------------------------------------
 !-
-!  1.0 Allocate the temporary buffer we need
-!      to put the variable in right dimension
-!-
-  IF (.NOT.ALLOCATED(buff_tmp)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restget_r2d : allocate buff_tmp = ",SIZE(var)
-    ENDIF
-    ALLOCATE(buff_tmp(SIZE(var)))
-  ELSE IF (SIZE(var) > SIZE(buff_tmp)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restget_r2d : re-allocate buff_tmp= ",SIZE(var)
-    ENDIF
-    DEALLOCATE(buff_tmp)
-    ALLOCATE(buff_tmp(SIZE(var)))
-  ENDIF
+! 1.0 Allocate the temporary buffer we need
+!     to put the variable in right dimension
+!-
+  siz1 = SIZE(var,1)
+  siz2 = SIZE(var,2)
+  var_sz = siz1*siz2
+  CALL rest_alloc (1,var_sz,check,'restget_r2d')
 !-
 ! 2.0 Here we check if the sizes specified agree
-!-    with the size of the variable provided
+!     with the size of the variable provided
 !-
   req_sz = 1
@@ -1323,17 +1234,17 @@
   IF (jjm > 0) req_sz = req_sz*jjm
   IF (llm > 0) req_sz = req_sz*llm
-  var_sz = SIZE(var,2)*SIZE(var,1)
   IF (req_sz > var_sz) THEN
-    WRITE(*,*) "RESGET_r2d :",vname_q
     WRITE(str, &
- &    '("Size of variable requested from file should be ",I6)') req_sz
+ &    '("Size of variable ",A, &
+ &      //" requested from file should be ",I6)') TRIM(vname_q),req_sz
     WRITE(str2, &
- &    '("but the provided variable can only hold ",I6)')  var_sz
+ &    '("but the provided variable can only hold ",I6)') var_sz
     CALL ipslerr (3,'restget_r2d',str,str2,' ')
   ENDIF
   IF (req_sz < var_sz) THEN
     WRITE(str, &
- &    '("the size of variable requested from file is ",I6)') req_sz
-    WRITE(str2,'("but the provided variable can hold ",I6)')  var_sz
+ &    '("Size of variable ",A, &
+ &      //" requested from file is ",I6)') TRIM(vname_q),req_sz
+    WRITE(str2,'("but the provided variable can hold ",I6)') var_sz
     CALL ipslerr (2,'restget_r2d', &
       'There could be a problem here :',str,str2)
@@ -1341,5 +1252,5 @@
 !-
   CALL restget_real &
-    (fid,vname_q,iim,jjm,llm,itau,def_beha,buff_tmp)
+ & (fid,vname_q,iim,jjm,llm,itau,def_beha,buff_tmp1)
 !-
 ! 4.0 Transfer the buffer obtained from the restart file
@@ -1347,15 +1258,13 @@
 !-
   jl=0
-  DO jj=1,SIZE(var,2)
-    DO ji=1,SIZE(var,1)
+  DO jj=1,siz2
+    DO ji=1,siz1
       jl=jl+1
-      var(ji,jj) = buff_tmp(jl)
+      var(ji,jj) = buff_tmp1(jl)
     ENDDO
   ENDDO
 !-------------------------
 END SUBROUTINE restget_r2d
-!-
-!===
-!-
+!===
 SUBROUTINE restget_r3d &
   (fid,vname_q,iim,jjm,llm,itau,def_beha,var)
@@ -1373,6 +1282,5 @@
 ! LOCAL
 !-
-  INTEGER :: ji,jj,jk,jl,req_sz,var_sz
-  REAL,ALLOCATABLE,SAVE :: buff_tmp(:)
+  INTEGER :: ji,jj,jk,jl,req_sz,var_sz,siz1,siz2,siz3
   CHARACTER(LEN=70) :: str,str2
   LOGICAL :: check = .FALSE.
@@ -1380,19 +1288,14 @@
 !-
 ! 1.0 Allocate the temporary buffer we need
-!      to put the variable in right dimension
-!-
-  IF (.NOT.ALLOCATED(buff_tmp)) THEN
-    IF (check) WRITE(*,*) "restget_r3d : allocate buff_tmp = ",SIZE(var)
-    ALLOCATE(buff_tmp(SIZE(var)))
-  ELSE IF (SIZE(var) > SIZE(buff_tmp)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restget_r3d : re-allocate buff_tmp= ",SIZE(var)
-    ENDIF
-    DEALLOCATE(buff_tmp)
-    ALLOCATE(buff_tmp(SIZE(var)))
-  ENDIF
+!     to put the variable in right dimension
+!-
+  siz1 = SIZE(var,1)
+  siz2 = SIZE(var,2)
+  siz3 = SIZE(var,3)
+  var_sz = siz1*siz2*siz3
+  CALL rest_alloc (1,var_sz,check,'restget_r3d')
 !-
 ! 2.0 Here we check if the sizes specified agree
-!-    with the size of the variable provided
+!     with the size of the variable provided
 !-
   req_sz = 1
@@ -1400,16 +1303,17 @@
   IF (jjm > 0) req_sz = req_sz*jjm
   IF (llm > 0) req_sz = req_sz*llm
-  var_sz = SIZE(var,3)*SIZE(var,2)*SIZE(var,1)
   IF (req_sz > var_sz) THEN
     WRITE(str, &
- &    '("Size of variable requested from file should be ",I6)') req_sz
+ &    '("Size of variable ",A, &
+ &      //" requested from file should be ",I6)') TRIM(vname_q),req_sz
     WRITE(str2, &
- &    '("but the provided variable can only hold ",I6)')  var_sz
+ &    '("but the provided variable can only hold ",I6)') var_sz
     CALL ipslerr (3,'restget_r3d',str,str2,' ')
   ENDIF
   IF (req_sz < var_sz) THEN
     WRITE(str, &
- &    '("the size of variable requested from file is ",I6)') req_sz
-    WRITE(str2,'("but the provided variable can hold ",I6)')  var_sz
+ &    '("Size of variable ",A, &
+ &      //" requested from file is ",I6)') TRIM(vname_q),req_sz
+    WRITE(str2,'("but the provided variable can hold ",I6)') var_sz
     CALL ipslerr (2,'restget_r3d', &
       'There could be a problem here :',str,str2)
@@ -1417,5 +1321,5 @@
 !-
   CALL restget_real &
-    (fid,vname_q,iim,jjm,llm,itau,def_beha,buff_tmp)
+    (fid,vname_q,iim,jjm,llm,itau,def_beha,buff_tmp1)
 !-
 ! 4.0 Transfer the buffer obtained from the restart file
@@ -1423,9 +1327,9 @@
 !-
   jl=0
-  DO jk=1,SIZE(var,3)
-    DO jj=1,SIZE(var,2)
-      DO ji=1,SIZE(var,1)
+  DO jk=1,siz3
+    DO jj=1,siz2
+      DO ji=1,siz1
         jl=jl+1
-        var(ji,jj,jk) = buff_tmp(jl)
+        var(ji,jj,jk) = buff_tmp1(jl)
       ENDDO
     ENDDO
@@ -1433,7 +1337,5 @@
 !-------------------------
 END SUBROUTINE restget_r3d
-!-
-!===
-!-
+!===
 SUBROUTINE restget_real &
   (fid,vname_q,iim,jjm,llm,itau,def_beha,var)
@@ -1506,5 +1408,5 @@
       touched_in(fid,vnb) = .TRUE.
 !-----
-      CALL restdefv (fid,vname_q,iim,jjm,llm,.TRUE.) 
+      CALL restdefv (fid,vname_q,iim,jjm,llm,.TRUE.)
 !-----
     ELSE
@@ -1535,5 +1437,5 @@
     index = -1
     DO it=1,tax_size_in(fid)
-          IF (t_index(fid,it) == itau) index = it
+      IF (t_index(fid,it) == itau)  index = it
     ENDDO
 !---
@@ -1543,5 +1445,5 @@
  &      str,'is not available in the current file',' ')
     ENDIF
-!---     
+!---
 !-- 4.0 Read the data. Note that the variables in the restart files
 !--     have no time axis is and thus we write -1
@@ -1556,5 +1458,5 @@
       ELSE
         WRITE (str2,'("Incompatibility for iim : ",I6,I6)') &
-             iim,vardims_in(fid,vnb,ndim) 
+             iim,vardims_in(fid,vnb,ndim)
         CALL ipslerr (3,'restget',str,str2,' ')
       ENDIF
@@ -1568,5 +1470,5 @@
       ELSE
         WRITE (str2,'("Incompatibility for jjm : ",I6,I6)') &
-             jjm,vardims_in(fid,vnb,ndim) 
+             jjm,vardims_in(fid,vnb,ndim)
         CALL ipslerr (3,'restget',str,str2,' ')
       ENDIF
@@ -1580,5 +1482,5 @@
       ELSE
         WRITE (str2,'("Incompatibility for llm : ",I6,I6)') &
-             llm,vardims_in(fid,vnb,ndim) 
+             llm,vardims_in(fid,vnb,ndim)
         CALL ipslerr (3,'restget',str,str2,' ')
       ENDIF
@@ -1617,9 +1519,7 @@
 !--------------------------
 END SUBROUTINE restget_real
-!-
-!===
-!-
+!===
 SUBROUTINE restput_opp_r1d &
-  (fid,vname_q,iim,jjm,llm,itau,var,OPERATOR,nbindex,ijndex)
+ & (fid,vname_q,iim,jjm,llm,itau,var,MY_OPERATOR,nbindex,ijndex)
 !---------------------------------------------------------------------
 !- This subroutine is the interface to restput_real which allows
@@ -1639,11 +1539,10 @@
   INTEGER :: iim,jjm,llm,itau
   REAL :: var(:)
-  CHARACTER(LEN=*) :: OPERATOR
+  CHARACTER(LEN=*) :: MY_OPERATOR
   INTEGER :: nbindex,ijndex(nbindex)
 !-
 ! LOCAL
 !-
-  INTEGER :: req_sz
-  REAL,ALLOCATABLE,SAVE :: buff_tmp(:),buff_tmp2(:)
+  INTEGER :: req_sz,siz1
   REAL :: scal
   CHARACTER(LEN=7) :: topp
@@ -1667,29 +1566,7 @@
 !     to put the variable in right dimension
 !-
-  IF (.NOT.ALLOCATED(buff_tmp)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restput_opp_r1d : allocate buff_tmp = ",SIZE(var)
-    ENDIF
-    ALLOCATE(buff_tmp(SIZE(var)))
-  ELSE IF (SIZE(var) > SIZE(buff_tmp)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restput_opp_r1d : re-allocate buff_tmp= ",SIZE(var)
-    ENDIF
-    DEALLOCATE(buff_tmp)
-    ALLOCATE(buff_tmp(SIZE(var)))
-  ENDIF
-!-
-  IF (.NOT.ALLOCATED(buff_tmp2)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restput_opp_r1d : allocate buff_tmp2 = ",req_sz
-    ENDIF
-    ALLOCATE(buff_tmp2(req_sz))
-  ELSE IF (req_sz > SIZE(buff_tmp2)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restput_opp_r1d : re-allocate buff_tmp2= ",req_sz
-    ENDIF
-    DEALLOCATE(buff_tmp2)
-    ALLOCATE(buff_tmp2(req_sz))
-  ENDIF
+  siz1 = SIZE(var)
+  CALL rest_alloc (1,siz1,check,'restput_opp_r1d')
+  CALL rest_alloc (2,req_sz,check,'restput_opp_r1d')
 !-
 ! 2.0 We do the operation needed.
@@ -1697,30 +1574,26 @@
 !     You would not want to change the values in a restart file or ?
 !-
-  topp = OPERATOR(1:MIN(LEN_TRIM(OPERATOR),7))
+  topp = MY_OPERATOR(1:MIN(LEN_TRIM(MY_OPERATOR),7))
 !-
   IF (INDEX(indchfun,topp(:LEN_TRIM(topp))) > 0) THEN
     scal = missing_val
-!---
-    buff_tmp(:) = var(:)
-!---
+    buff_tmp1(1:siz1) = var(:)
     CALL mathop &
-      (topp,SIZE(var),buff_tmp,missing_val,nbindex,ijndex, &
-       scal,req_sz,buff_tmp2)
+ &    (topp,siz1,buff_tmp1,missing_val,nbindex,ijndex, &
+ &     scal,req_sz,buff_tmp2)
   ELSE
     CALL ipslerr (3,'restput_opp_r1d', &
-      'The operation you wish to do on the variable for the ', &
-       & 'restart file is not allowed.',topp)
+ &    'The operation you wish to do on the variable for the ', &
+ &    'restart file is not allowed.',topp)
   ENDIF
 !-
   CALL restput_real &
-    (fid,vname_q,xax_infs(fid,1,1),yax_infs(fid,1,1), &
-     zax_infs(fid,1,1),itau,buff_tmp2)
+ & (fid,vname_q,xax_infs(fid,1,1),yax_infs(fid,1,1), &
+ &  zax_infs(fid,1,1),itau,buff_tmp2)
 !-----------------------------
 END SUBROUTINE restput_opp_r1d
-!-
-!===
-!-
+!===
 SUBROUTINE restput_opp_r2d &
-  (fid,vname_q,iim,jjm,llm,itau,var,OPERATOR,nbindex,ijndex)
+ & (fid,vname_q,iim,jjm,llm,itau,var,MY_OPERATOR,nbindex,ijndex)
 !---------------------------------------------------------------------
 !- This subroutine is the interface to restput_real which allows
@@ -1731,5 +1604,5 @@
 !- In the case iim = nbindex it means that the user attempts
 !- to project the first dimension of the matrix back onto a 3D field
-!- where jjm will be the third dimension. 
+!- where jjm will be the third dimension.
 !- Here we do not allow for 4D data, thus we will take the first
 !- two dimensions in the file and require that llm = 1.
@@ -1743,11 +1616,10 @@
   INTEGER :: iim,jjm,llm,itau
   REAL :: var(:,:)
-  CHARACTER(LEN=*) :: OPERATOR
+  CHARACTER(LEN=*) :: MY_OPERATOR
   INTEGER :: nbindex,ijndex(nbindex)
 !-
 ! LOCAL
 !-
-  INTEGER :: jj,req_sz,var_sz,ist
-  REAL,ALLOCATABLE,SAVE :: buff_tmp(:),buff_tmp2(:)
+  INTEGER :: jj,req_sz,ist,siz1
   REAL :: scal
   CHARACTER(LEN=7) :: topp
@@ -1776,29 +1648,7 @@
 !     to put the variable in right dimension
 !-
-  IF (.NOT.ALLOCATED(buff_tmp)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restput_opp_r2d : allocate buff_tmp = ",SIZE(var,1)
-    ENDIF
-    ALLOCATE(buff_tmp(SIZE(var,1)))
-  ELSE IF (SIZE(var,1) > SIZE(buff_tmp)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restput_opp_r2d : re-allocate buff_tmp= ",SIZE(var,1)
-    ENDIF
-    DEALLOCATE(buff_tmp)
-    ALLOCATE(buff_tmp(SIZE(var,1)))
-  ENDIF
-!-
-  IF (.NOT.ALLOCATED(buff_tmp2)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restput_opp_r2d : allocate buff_tmp2 = ",req_sz*jjm
-    ENDIF
-    ALLOCATE(buff_tmp2(req_sz*jjm))
-  ELSE IF (req_sz*jjm > SIZE(buff_tmp2)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restput_opp_r2d : re-allocate buff_tmp2= ",req_sz*jjm
-    ENDIF
-    DEALLOCATE(buff_tmp2)
-    ALLOCATE(buff_tmp2(req_sz*jjm))
-  ENDIF
+  siz1 = SIZE(var,1)
+  CALL rest_alloc (1,siz1,check,'restput_opp_r2d')
+  CALL rest_alloc (2,req_sz*jjm,check,'restput_opp_r2d')
 !-
 ! 2.0 We do the operation needed.
@@ -1806,32 +1656,27 @@
 !     You would not want to change the values in a restart file or ?
 !-
-  topp = OPERATOR(1:MIN(LEN_TRIM(OPERATOR),7))
+  topp = MY_OPERATOR(1:MIN(LEN_TRIM(MY_OPERATOR),7))
 !-
   IF (INDEX(indchfun,topp(:LEN_TRIM(topp))) > 0) THEN
     scal = missing_val
-    var_sz = SIZE(var,1)
-!---
     DO jj = 1,jjm
-      buff_tmp(:) = var(:,jj)
-!-----
+      buff_tmp1(1:siz1) = var(:,jj)
       ist = (jj-1)*req_sz+1
       CALL mathop &
-        (topp,var_sz,buff_tmp,missing_val,nbindex,ijndex, &
-         scal,req_sz,buff_tmp2(ist:ist+req_sz-1))
+ &      (topp,siz1,buff_tmp1,missing_val,nbindex,ijndex, &
+ &       scal,req_sz,buff_tmp2(ist:ist+req_sz-1))
     ENDDO
   ELSE
     CALL ipslerr (3,'restput_opp_r2d', &
-      'The operation you wish to do on the variable for the ', &
-      'restart file is not allowed.',topp)
+ &    'The operation you wish to do on the variable for the ', &
+ &    'restart file is not allowed.',topp)
   ENDIF
 !-
   CALL restput_real &
-    (fid,vname_q,xax_infs(fid,1,1),yax_infs(fid,1,1), &
-     jjm,itau,buff_tmp2)
+ & (fid,vname_q,xax_infs(fid,1,1),yax_infs(fid,1,1), &
+ &  jjm,itau,buff_tmp2)
 !-----------------------------
 END SUBROUTINE restput_opp_r2d
-!-
-!===
-!-
+!===
 SUBROUTINE restput_r1d (fid,vname_q,iim,jjm,llm,itau,var)
 !---------------------------------------------------------------------
@@ -1847,6 +1692,5 @@
 ! LOCAL
 !-
-  INTEGER :: ji,jl,req_sz,var_sz
-  REAL,ALLOCATABLE,SAVE :: buff_tmp(:)
+  INTEGER :: ji,jl,req_sz,var_sz,siz1
   CHARACTER(LEN=70) :: str,str2
   LOGICAL :: check = .FALSE.
@@ -1854,18 +1698,9 @@
 !-
 ! 1.0 Allocate the temporary buffer we need
-!      to put the variable in right dimension
-!-
-  IF (.NOT.ALLOCATED(buff_tmp)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restput_r1d : allocate buff_tmp = ",SIZE(var)
-    ENDIF
-    ALLOCATE(buff_tmp(SIZE(var)))
-  ELSE IF (SIZE(var) > SIZE(buff_tmp)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restput_r1d : re-allocate buff_tmp= ",SIZE(var)
-    ENDIF
-    DEALLOCATE(buff_tmp)
-    ALLOCATE(buff_tmp(SIZE(var)))
-  ENDIF
+!     to put the variable in right dimension
+!-
+  siz1 = SIZE(var)
+  var_sz = siz1
+  CALL rest_alloc (1,var_sz,check,'restput_r1d')
 !-
 ! 2.0 Here we could check if the sizes specified agree
@@ -1876,15 +1711,14 @@
   IF (jjm > 0) req_sz = req_sz*jjm
   IF (llm > 0) req_sz = req_sz*llm
-  var_sz = SIZE(var,1)
   IF (req_sz > var_sz) THEN
     WRITE(str, &
  &    '("Size of variable put to the file should be ",I6)') req_sz
     WRITE(str2, &
- &    '("but the provided variable is of size  ",I6)')  var_sz
+ &    '("but the provided variable is of size ",I6)') var_sz
     CALL ipslerr (3,'restput_r1d',str,str2,' ')
   ENDIF
   IF (req_sz < var_sz) THEN
     WRITE(str,'("the size of variable put to the file is ",I6)') req_sz
-    WRITE(str2,'("but the provided variable is larger ",I6)')  var_sz
+    WRITE(str2,'("but the provided variable is larger ",I6)') var_sz
     CALL ipslerr (2,'restput_r1d', &
       'There could be a problem here :',str,str2)
@@ -1895,15 +1729,13 @@
 !-
   jl=0
-  DO ji=1,SIZE(var,1)
+  DO ji=1,siz1
     jl=jl+1
-    buff_tmp(jl) = var(ji)
+    buff_tmp1(jl) = var(ji)
   ENDDO
 !-
-  CALL restput_real (fid,vname_q,iim,jjm,llm,itau,buff_tmp)
+  CALL restput_real (fid,vname_q,iim,jjm,llm,itau,buff_tmp1)
 !-------------------------
 END SUBROUTINE restput_r1d
-!-
-!===
-!-
+!===
 SUBROUTINE restput_r2d (fid,vname_q,iim,jjm,llm,itau,var)
 !---------------------------------------------------------------------
@@ -1919,6 +1751,5 @@
 ! LOCAL
 !-
-  INTEGER :: ji,jj,jl,req_sz,var_sz
-  REAL,ALLOCATABLE,SAVE :: buff_tmp(:)
+  INTEGER :: ji,jj,jl,req_sz,var_sz,siz1,siz2
   CHARACTER(LEN=70) :: str,str2
   LOGICAL :: check = .FALSE.
@@ -1928,14 +1759,8 @@
 !     to put the variable in right dimension
 !-
-  IF (.NOT.ALLOCATED(buff_tmp)) THEN
-    IF (check) WRITE(*,*) "restput_r2d : allocate buff_tmp = ",SIZE(var)
-    ALLOCATE(buff_tmp(SIZE(var)))
-  ELSE IF (SIZE(var) > SIZE(buff_tmp)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restput_r2d : re-allocate buff_tmp= ",SIZE(var)
-    ENDIF
-    DEALLOCATE(buff_tmp)
-    ALLOCATE(buff_tmp(SIZE(var)))
-  ENDIF
+  siz1 = SIZE(var,1)
+  siz2 = SIZE(var,2)
+  var_sz = siz1*siz2
+  CALL rest_alloc (1,var_sz,check,'restput_r2d')
 !-
 ! 2.0 Here we could check if the sizes specified agree
@@ -1946,5 +1771,4 @@
   IF (jjm > 0) req_sz = req_sz*jjm
   IF (llm > 0) req_sz = req_sz*llm
-  var_sz = SIZE(var,2)*SIZE(var,1)
   IF (req_sz > var_sz) THEN
     WRITE(str, &
@@ -1964,17 +1788,15 @@
 !-
   jl=0
-  DO jj=1,SIZE(var,2)
-    DO ji=1,SIZE(var,1)
+  DO jj=1,siz2
+    DO ji=1,siz1
       jl=jl+1
-      buff_tmp(jl) = var(ji,jj)
+      buff_tmp1(jl) = var(ji,jj)
     ENDDO
   ENDDO
 !-
-  CALL restput_real(fid,vname_q,iim,jjm,llm,itau,buff_tmp)
+  CALL restput_real(fid,vname_q,iim,jjm,llm,itau,buff_tmp1)
 !-------------------------
 END SUBROUTINE restput_r2d
-!-
-!===
-!-
+!===
 SUBROUTINE restput_r3d (fid,vname_q,iim,jjm,llm,itau,var)
 !---------------------------------------------------------------------
@@ -1990,6 +1812,5 @@
 ! LOCAL
 !-
-  INTEGER :: ji,jj,jk,jl,req_sz,var_sz
-  REAL,ALLOCATABLE,SAVE :: buff_tmp(:)
+  INTEGER :: ji,jj,jk,jl,req_sz,var_sz,siz1,siz2,siz3
   CHARACTER(LEN=70) :: str,str2
   LOGICAL :: check = .FALSE.
@@ -1999,16 +1820,9 @@
 !     to put the variable in right dimension
 !-
-  IF (.NOT.ALLOCATED(buff_tmp)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restput_r3d : allocate buff_tmp = ",SIZE(var)
-    ENDIF
-    ALLOCATE(buff_tmp(SIZE(var)))
-  ELSE IF (SIZE(var) > SIZE(buff_tmp)) THEN
-    IF (check) THEN
-      WRITE(*,*) "restput_r3d : re-allocate buff_tmp= ",SIZE(var)
-    ENDIF
-    DEALLOCATE(buff_tmp)
-    ALLOCATE(buff_tmp(SIZE(var)))
-  ENDIF
+  siz1 = SIZE(var,1)
+  siz2 = SIZE(var,2)
+  siz3 = SIZE(var,3)
+  var_sz = siz1*siz2*siz3
+  CALL rest_alloc (1,var_sz,check,'restput_r3d')
 !-
 ! 2.0 Here we could check if the sizes specified agree
@@ -2019,5 +1833,4 @@
   IF (jjm > 0) req_sz = req_sz*jjm
   IF (llm > 0) req_sz = req_sz*llm
-  var_sz = SIZE(var,3)*SIZE(var,2)*SIZE(var,1)
   IF (req_sz > var_sz) THEN
     WRITE(str, &
@@ -2038,22 +1851,20 @@
 !-
   jl=0
-  DO jk=1,SIZE(var,3)
-    DO jj=1,SIZE(var,2)
-      DO ji=1,SIZE(var,1)
+  DO jk=1,siz3
+    DO jj=1,siz2
+      DO ji=1,siz1
         jl=jl+1
-        buff_tmp(jl) = var(ji,jj,jk)
+        buff_tmp1(jl) = var(ji,jj,jk)
       ENDDO
     ENDDO
   ENDDO
 !-
-  CALL restput_real(fid,vname_q,iim,jjm,llm,itau,buff_tmp)
+  CALL restput_real(fid,vname_q,iim,jjm,llm,itau,buff_tmp1)
 !-------------------------
 END SUBROUTINE restput_r3d
-!-
-!===
-!-
+!===
 SUBROUTINE restput_real (fid,vname_q,iim,jjm,llm,itau,var)
 !---------------------------------------------------------------------
-!- This subroutine will put a variable into the restart file. 
+!- This subroutine will put a variable into the restart file.
 !- But it will do a lot of other things if needed :
 !- - Open a file if non is opened for this time-step
@@ -2088,5 +1899,5 @@
   INTEGER :: iret,vid,ncid,iv,vnb
   INTEGER :: ierr
-  REAL :: secsince,un_jour,un_an
+  REAL :: secsince,one_day,one_year
   INTEGER :: ndims
   INTEGER,DIMENSION(4) :: corner,edge
@@ -2102,7 +1913,7 @@
  &    'The output restart file is undefined.',' ',' ')
   ENDIF
-  CALL ioget_calendar (un_an,un_jour)
-!-
-! 1.0 Check if the variable is already present 
+  CALL ioget_calendar (one_year,one_day)
+!-
+! 1.0 Check if the variable is already present
 !-
   IF (check) WRITE(*,*) 'RESTPUT 1.0 : ',TRIM(vname_q)
@@ -2132,5 +1943,5 @@
     iret = NF90_ENDDEF(ncid)
   ENDIF
-!-     
+!-
 ! 3.0 Is this itau already on the axis ?
 !     If not then check that all variables of previous time is OK.
@@ -2207,5 +2018,5 @@
   ENDIF
   ndims = ndims+1
-  corner(ndims) = tstp_out(fid) 
+  corner(ndims) = tstp_out(fid)
   edge(ndims) = 1
 !-
@@ -2214,5 +2025,7 @@
 !-
   IF (iret /= NF90_NOERR) THEN
-    WRITE (*,*) ' restput error ',NF90_STRERROR(iret)
+    CALL ipslerr (2,'restput_real',NF90_STRERROR(iret), &
+ &    'Bug in restput.',&
+ &    'Please, verify compatibility between get and put commands.')
   ENDIF
 !-
@@ -2222,11 +2035,9 @@
 !---------------------------
 END  SUBROUTINE restput_real
-!-
-!===
-!-
+!===
 SUBROUTINE restdefv (fid,varname,iim,jjm,llm,write_att)
 !---------------------------------------------------------------------
 ! This subroutine adds a variable to the output file.
-! The attributes are either taken from .
+! The attributes are either taken from.
 !---------------------------------------------------------------------
   IMPLICIT NONE
@@ -2256,12 +2067,12 @@
 ! 0.0 Put the file in define mode if needed
 !-
-  IF (itau_out(fid) >= 0) THEN 
+  IF (itau_out(fid) >= 0) THEN
     iret = NF90_REDEF(ncfid)
   ENDIF
 !-
-! 1.0 Do we have all dimensions and can we go ahead     
+! 1.0 Do we have all dimensions and can we go ahead
 !-
   IF (check) THEN
-    WRITE(*,*) 'restdefv 1.0 :',TRIM(varname),nbvar_out(fid) 
+    WRITE(*,*) 'restdefv 1.0 :',TRIM(varname),nbvar_out(fid)
   ENDIF
 !-
@@ -2273,5 +2084,5 @@
     ndim = ndim+1
     xloc = 0
-    DO ic=1,xax_nb(fid) 
+    DO ic=1,xax_nb(fid)
       IF (xax_infs(fid,ic,1) == iim) xloc = ic
     ENDDO
@@ -2294,5 +2105,5 @@
     ndim = ndim+1
     xloc = 0
-    DO ic=1,yax_nb(fid) 
+    DO ic=1,yax_nb(fid)
       IF (yax_infs(fid,ic,1) == jjm) xloc = ic
     ENDDO
@@ -2315,5 +2126,5 @@
     ndim = ndim+1
     xloc = 0
-    DO ic=1,zax_nb(fid) 
+    DO ic=1,zax_nb(fid)
       IF (zax_infs(fid,ic,1) == llm) xloc = ic
     ENDDO
@@ -2350,5 +2161,5 @@
   ENDIF
 !-
-! 3.0 Add the attributes if requested 
+! 3.0 Add the attributes if requested
 !-
   IF (write_att) THEN
@@ -2368,5 +2179,5 @@
  &                      'missing_value',REAL(missing_val,KIND=4))
 !---
-    IF (itau_out(fid) >= 0) THEN 
+    IF (itau_out(fid) >= 0) THEN
       iret = NF90_ENDDEF(ncfid)
     ENDIF
@@ -2379,7 +2190,164 @@
 !----------------------
 END SUBROUTINE restdefv
-!-
-!===
-!-
+!===
+SUBROUTINE rest_atim (l_msg,c_p)
+!---------------------------------------------------------------------
+! Called by "c_p", [re]allocate the time axes
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  LOGICAL,INTENT(IN) :: l_msg
+  CHARACTER(LEN=*),INTENT(IN) :: c_p
+!-
+  INTEGER :: i_err,tszij
+  INTEGER,ALLOCATABLE :: tmp_index(:,:)
+  REAL,ALLOCATABLE :: tmp_julian(:,:)
+!---------------------------------------------------------------------
+!-
+!  Allocate the space we need for the time axes
+!-
+  IF (.NOT.ALLOCATED(t_index) .AND. .NOT.ALLOCATED(t_julian)) THEN
+    IF (l_msg) THEN
+      WRITE(*,*) TRIM(c_p)//' : Allocate times axes at :', &
+ &               max_file,tax_size_in(nb_fi)
+    ENDIF
+!---
+    ALLOCATE(t_index(max_file,tax_size_in(nb_fi)),STAT=i_err)
+    IF (i_err/=0) THEN
+      WRITE(*,*) "ERROR IN ALLOCATION of t_index : ",i_err
+      CALL ipslerr (3,TRIM(c_p), &
+ &      'Problem in allocation of t_index','', &
+ &      '(you must increase memory)')
+    ENDIF
+    t_index (:,:) = 0
+!---
+    ALLOCATE(t_julian(max_file,tax_size_in(nb_fi)),STAT=i_err)
+    IF (i_err/=0) THEN
+      WRITE(*,*) "ERROR IN ALLOCATION of t_julian : ",i_err
+      CALL ipslerr (3,TRIM(c_p), &
+ &      'Problem in allocation of max_file,tax_size_in','', &
+ &      '(you must increase memory)')
+    ENDIF
+    t_julian (:,:) = 0.0
+  ELSE IF (    (SIZE(t_index,DIM=2)  < tax_size_in(nb_fi)) &
+ &         .OR.(SIZE(t_julian,DIM=2) < tax_size_in(nb_fi)) ) THEN
+    IF (l_msg) THEN
+      WRITE(*,*) TRIM(c_p)//' : Reallocate times axes at :', &
+ &               max_file,tax_size_in(nb_fi)
+    ENDIF
+!---
+    ALLOCATE (tmp_index(max_file,tax_size_in(nb_fi)),STAT=i_err)
+    IF (i_err/=0) THEN
+      WRITE(*,*) "ERROR IN ALLOCATION of tmp_index : ",i_err
+      CALL ipslerr (3,TRIM(c_p), &
+ &      'Problem in allocation of tmp_index','', &
+ &      '(you must increase memory)')
+    ENDIF
+    tszij = SIZE(t_index,DIM=2)
+    tmp_index(:,1:tszij) = t_index(:,1:tszij)
+    DEALLOCATE(t_index)
+    ALLOCATE (t_index(max_file,tax_size_in(nb_fi)),STAT=i_err)
+    IF (i_err/=0) THEN
+      WRITE(*,*) "ERROR IN ALLOCATION of t_index : ",i_err
+      CALL ipslerr (3,TRIM(c_p), &
+ &     'Problem in reallocation of t_index','', &
+ &     '(you must increase memory)')
+    ENDIF
+    t_index(:,1:tszij) = tmp_index(:,1:tszij)
+!---
+    ALLOCATE (tmp_julian(max_file,tax_size_in(nb_fi)),STAT=i_err)
+    IF (i_err/=0) THEN
+      WRITE(*,*) "ERROR IN ALLOCATION of tmp_julian : ",i_err
+      CALL ipslerr (3,TRIM(c_p), &
+ &     'Problem in allocation of tmp_julian','', &
+ &     '(you must increase memory)')
+    ENDIF
+    tszij = SIZE(t_julian,DIM=2)
+    tmp_julian(:,1:tszij) = t_julian(:,1:tszij)
+    DEALLOCATE(t_julian)
+    ALLOCATE (t_julian(max_file,tax_size_in(nb_fi)),STAT=i_err)
+    IF (i_err/=0) THEN
+      WRITE(*,*) "ERROR IN ALLOCATION of t_julian : ",i_err
+      CALL ipslerr (3,TRIM(c_p), &
+ &      'Problem in reallocation of t_julian','', &
+ &      '(you must increase memory)')
+    ENDIF
+    t_julian(:,1:tszij) = tmp_julian(:,1:tszij)
+  ENDIF
+!-----------------------
+END SUBROUTINE rest_atim
+!===
+SUBROUTINE rest_alloc (i_buff,i_qsz,l_msg,c_p)
+!---------------------------------------------------------------------
+! Called by "c_p", allocate a temporary buffer
+! (buff_tmp[1/2] depending on "i_buff" value) to the size "i_qsz".
+!---------------------------------------------------------------------
+  IMPLICIT NONE
+!-
+  INTEGER,INTENT(IN) :: i_buff,i_qsz
+  LOGICAL,INTENT(IN) :: l_msg
+  CHARACTER(LEN=*),INTENT(IN) :: c_p
+!-
+  INTEGER :: i_bsz,i_err
+  LOGICAL :: l_alloc1,l_alloc2
+  CHARACTER(LEN=9) :: cbn
+  CHARACTER(LEN=5) :: c_err
+!---------------------------------------------------------------------
+  IF      (i_buff == 1) THEN
+    IF (ALLOCATED(buff_tmp1)) THEN
+      i_bsz = SIZE(buff_tmp1)
+    ELSE
+      i_bsz = 0
+    ENDIF
+    l_alloc1 =    (.NOT.ALLOCATED(buff_tmp1)) &
+ &            .OR.((ALLOCATED(buff_tmp1)).AND.(i_qsz > i_bsz))
+    l_alloc2 = .FALSE.
+    cbn = 'buff_tmp1'
+  ELSE IF (i_buff == 2) THEN
+    IF (ALLOCATED(buff_tmp2)) THEN
+      i_bsz = SIZE(buff_tmp2)
+    ELSE
+      i_bsz = 0
+    ENDIF
+    l_alloc1 = .FALSE.
+    l_alloc2 =    (.NOT.ALLOCATED(buff_tmp2)) &
+ &            .OR.((ALLOCATED(buff_tmp2)).AND.(i_qsz > i_bsz))
+    cbn = 'buff_tmp2'
+  ELSE
+    CALL ipslerr (3,'rest_alloc', &
+ &    'Called by '//TRIM(c_p),'with a wrong value of i_buff','')
+  ENDIF
+!-
+!-
+  IF (l_alloc1.OR.l_alloc2) THEN
+    IF (l_msg) THEN
+      IF (    (l_alloc1.AND.ALLOCATED(buff_tmp1)) &
+ &        .OR.(l_alloc2.AND.ALLOCATED(buff_tmp2)) ) THEN
+        WRITE(*,*) TRIM(c_p)//" : re_allocate "//TRIM(cbn)//"=",i_qsz
+      ELSE
+        WRITE(*,*) TRIM(c_p)//" : allocate "//TRIM(cbn)//"=",i_qsz
+      ENDIF
+    ENDIF
+    IF (l_alloc1) THEN
+      IF (ALLOCATED(buff_tmp1)) THEN
+        DEALLOCATE(buff_tmp1)
+      ENDIF
+      ALLOCATE (buff_tmp1(i_qsz),STAT=i_err)
+    ELSE
+      IF (ALLOCATED(buff_tmp2)) THEN
+        DEALLOCATE(buff_tmp2)
+      ENDIF
+      ALLOCATE (buff_tmp2(i_qsz),STAT=i_err)
+    ENDIF
+    IF (i_err /= 0) THEN
+      WRITE (UNIT=c_err,FMT='(I5)') i_err
+      CALL ipslerr (3,TRIM(c_p), &
+ &      'Problem in allocation of',TRIM(cbn), &
+ &      'Error : '//TRIM(c_err)//' (you must increase memory)')
+    ENDIF
+  ENDIF
+!------------------------
+END SUBROUTINE rest_alloc
+!===
 SUBROUTINE ioconf_setatt (attname,value)
 !---------------------------------------------------------------------
@@ -2406,7 +2374,5 @@
 !---------------------------
 END SUBROUTINE ioconf_setatt
-!-
-!===
-!-
+!===
 SUBROUTINE ioget_vdim (fid,vname_q,varnbdim_max,varnbdim,vardims)
 !---------------------------------------------------------------------
@@ -2446,7 +2412,5 @@
 !------------------------
 END SUBROUTINE ioget_vdim
-!-
-!===
-!-
+!===
 SUBROUTINE ioget_vname (fid,nbvar,varnames)
 !---------------------------------------------------------------------
@@ -2471,7 +2435,5 @@
 !-------------------------
 END SUBROUTINE ioget_vname
-!-
-!===
-!-
+!===
 SUBROUTINE ioconf_expval (new_exp_val)
 !---------------------------------------------------------------------
@@ -2496,7 +2458,5 @@
 !---------------------------
 END SUBROUTINE ioconf_expval
-!-
-!===
-!-
+!===
 SUBROUTINE ioget_expval (get_exp_val)
 !---------------------------------------------------------------------
@@ -2512,7 +2472,5 @@
 !--------------------------
 END SUBROUTINE ioget_expval
-!-
-!===
-!-
+!===
 SUBROUTINE restclo (fid)
 !---------------------------------------------------------------------
@@ -2543,10 +2501,10 @@
       WRITE(*,*) &
         'restclo : Closing specified restart file number :', &
-        fid,netcdf_id(fid,1:2) 
+        fid,netcdf_id(fid,1:2)
     ENDIF
 !---
     IF (netcdf_id(fid,1) > 0) THEN
       iret = NF90_CLOSE(netcdf_id(fid,1))
-      IF (iret /= NF90_NOERR) THEN 
+      IF (iret /= NF90_NOERR) THEN
         WRITE (n_e,'(I6)') iret
         WRITE (n_f,'(I3)') netcdf_id(fid,1)
@@ -2562,5 +2520,5 @@
     IF (netcdf_id(fid,2) > 0)  THEN
       iret = NF90_CLOSE(netcdf_id(fid,2))
-      IF (iret /= NF90_NOERR) THEN 
+      IF (iret /= NF90_NOERR) THEN
         WRITE (n_e,'(I6)') iret
         WRITE (n_f,'(I3)') netcdf_id(fid,2)
@@ -2575,8 +2533,8 @@
     IF (check) WRITE(*,*) 'restclo : Closing all files'
 !---
-    DO ifnc=1,nbfiles
+    DO ifnc=1,nb_fi
       IF (netcdf_id(ifnc,1) > 0) THEN
         iret = NF90_CLOSE(netcdf_id(ifnc,1))
-        IF (iret /= NF90_NOERR) THEN 
+        IF (iret /= NF90_NOERR) THEN
           WRITE (n_e,'(I6)') iret
           WRITE (n_f,'(I3)') netcdf_id(ifnc,1)
@@ -2592,5 +2550,5 @@
       IF (netcdf_id(ifnc,2) > 0) THEN
         iret = NF90_CLOSE(netcdf_id(ifnc,2))
-        IF (iret /= NF90_NOERR) THEN 
+        IF (iret /= NF90_NOERR) THEN
           WRITE (n_e,'(I6)') iret
           WRITE (n_f,'(I3)') netcdf_id(ifnc,2)
@@ -2604,6 +2562,5 @@
 !---------------------
 END SUBROUTINE restclo
-!-
-!===
-!-
+!===
+!-----------------
 END MODULE restcom
