Index: IOIPSL/trunk/src/histcom.f90
===================================================================
--- IOIPSL/trunk/src/histcom.f90	(revision 845)
+++ IOIPSL/trunk/src/histcom.f90	(revision 856)
@@ -55,5 +55,5 @@
 !-
 !- INPUT
-!- pfileid  : The ID of the file on which this variable is to be,
+!- idf      : The ID of the file on which this variable is to be,
 !-            written. The variable should have been defined in
 !-            this file before.
@@ -108,6 +108,7 @@
   REAL :: freq_opp,freq_wrt
   INTEGER :: &
- &  last_opp,last_wrt,last_opp_chk,last_wrt_chk,nb_opp,nb_wrt,point
+ &  last_opp,last_wrt,last_opp_chk,last_wrt_chk,nb_opp,nb_wrt
 !- For future optimization
+  REAL,ALLOCATABLE,DIMENSION(:) :: t_bf
 !#  REAL,ALLOCATABLE,DIMENSION(:) :: V_1_D
 !#  REAL,ALLOCATABLE,DIMENSION(:,:) :: V_2_D
@@ -148,9 +149,4 @@
   INTEGER,SAVE :: nb_files=0
 !-
-! Book keeping for the buffers
-!-
-  INTEGER,SAVE :: buff_pos=0
-  REAL,ALLOCATABLE,DIMENSION(:),SAVE :: buffer
-!-
 ! A list of functions which require special action
 ! (Needs to be updated when functions are added
@@ -169,5 +165,5 @@
  & (pfilename,pim,plon,pjm,plat,          &
  &  par_orix,par_szx,par_oriy,par_szy,    &
- &  pitau0,pdate0,pdeltat,phoriid,pfileid,domain_id,nb_bits)
+ &  pitau0,pdate0,pdeltat,phoriid,idf,domain_id,nb_bits)
 !---------------------------------------------------------------------
 !- This is just an interface for histbeg_regular in case when
@@ -201,5 +197,5 @@
 !-
 !- phoriid   : ID of the horizontal grid
-!- pfileid   : ID of the netcdf file
+!- idf       : ID of the netcdf file
 !-
 !- Optional INPUT arguments
@@ -227,5 +223,5 @@
   INTEGER,INTENT(IN) :: pitau0
   REAL,INTENT(IN) :: pdate0,pdeltat
-  INTEGER,INTENT(OUT) :: pfileid,phoriid
+  INTEGER,INTENT(OUT) :: idf,phoriid
   INTEGER,INTENT(IN),OPTIONAL :: domain_id,nb_bits
 !-
@@ -245,5 +241,5 @@
  &  (pfilename,pim,lon_tmp,pjm,lat_tmp, &
  &   par_orix,par_szx,par_oriy,par_szy, &
- &   pitau0,pdate0,pdeltat,phoriid,pfileid, &
+ &   pitau0,pdate0,pdeltat,phoriid,idf, &
  &   .TRUE.,domain_id,nb_bits)
 !-
@@ -255,5 +251,5 @@
  & (pfilename,pim,plon,pjm,plat,           &
  &  par_orix,par_szx,par_oriy,par_szy,     &
- &  pitau0,pdate0,pdeltat,phoriid,pfileid, &
+ &  pitau0,pdate0,pdeltat,phoriid,idf, &
  &  opt_rectilinear,domain_id,nb_bits)
 !---------------------------------------------------------------------
@@ -289,5 +285,5 @@
 !-
 !- phoriid   : ID of the horizontal grid
-!- pfileid   : ID of the netcdf file
+!- idf       : ID of the netcdf file
 !-
 !- Optional INPUT arguments
@@ -315,5 +311,5 @@
   INTEGER,INTENT(IN) :: pitau0
   REAL,INTENT(IN) :: pdate0,pdeltat
-  INTEGER,INTENT(OUT) :: pfileid,phoriid
+  INTEGER,INTENT(OUT) :: idf,phoriid
   LOGICAL,INTENT(IN),OPTIONAL :: opt_rectilinear
   INTEGER,INTENT(IN),OPTIONAL :: domain_id,nb_bits
@@ -335,5 +331,5 @@
    &  'in histcom.f90 in order to accomodate all these files',' ')
   ENDIF
-  pfileid  = nb_files
+  idf = nb_files
 !-
 ! 1.0 Transfering into the common for future use
@@ -341,7 +337,7 @@
   IF (l_dbg) WRITE(*,*) "histbeg_regular 1.0"
 !-
-  W_F(pfileid)%itau0  = pitau0
-  W_F(pfileid)%date0  = pdate0
-  W_F(pfileid)%deltat = pdeltat
+  W_F(idf)%itau0  = pitau0
+  W_F(idf)%date0  = pdate0
+  W_F(idf)%deltat = pdeltat
 !-
   IF (PRESENT(opt_rectilinear)) THEN
@@ -355,11 +351,11 @@
   IF (l_dbg) WRITE(*,*) "histbeg_regular 2.0"
 !-
-  W_F(pfileid)%n_var = 0
-  W_F(pfileid)%n_tax = 0
-  W_F(pfileid)%n_hax = 0
-  W_F(pfileid)%n_zax = 0
-!-
-  W_F(pfileid)%slab_ori(1:2) = (/ par_orix,par_oriy /)
-  W_F(pfileid)%slab_sz(1:2)  = (/ par_szx, par_szy  /)
+  W_F(idf)%n_var = 0
+  W_F(idf)%n_tax = 0
+  W_F(idf)%n_hax = 0
+  W_F(idf)%n_zax = 0
+!-
+  W_F(idf)%slab_ori(1:2) = (/ par_orix,par_oriy /)
+  W_F(idf)%slab_sz(1:2)  = (/ par_szx, par_szy  /)
 !-
 ! 3.0 Opening netcdf file and defining dimensions
@@ -392,9 +388,9 @@
 !-
   IF (rectilinear) THEN
-    iret = NF90_DEF_DIM (nfid,'lon',par_szx,W_F(pfileid)%xid)
-    iret = NF90_DEF_DIM (nfid,'lat',par_szy,W_F(pfileid)%yid)
-  ELSE
-    iret = NF90_DEF_DIM (nfid,'x',par_szx,W_F(pfileid)%xid)
-    iret = NF90_DEF_DIM (nfid,'y',par_szy,W_F(pfileid)%yid)
+    iret = NF90_DEF_DIM (nfid,'lon',par_szx,W_F(idf)%xid)
+    iret = NF90_DEF_DIM (nfid,'lat',par_szy,W_F(idf)%yid)
+  ELSE
+    iret = NF90_DEF_DIM (nfid,'x',par_szx,W_F(idf)%xid)
+    iret = NF90_DEF_DIM (nfid,'y',par_szy,W_F(idf)%yid)
   ENDIF
 !-
@@ -417,14 +413,14 @@
 !-
   IF (PRESENT(domain_id)) THEN
-    W_F(pfileid)%dom_id_svg = domain_id
-  ENDIF
-  W_F(pfileid)%ncfid = nfid
-  W_F(pfileid)%full_size(1:2) = (/ pim,pjm /)
+    W_F(idf)%dom_id_svg = domain_id
+  ENDIF
+  W_F(idf)%ncfid = nfid
+  W_F(idf)%full_size(1:2) = (/ pim,pjm /)
 !-
 ! 6.0 storing the geographical coordinates
 !-
-  W_F(pfileid)%regular=.TRUE.
-!-
-  CALL histhori_regular (pfileid,pim,plon,pjm,plat, &
+  W_F(idf)%regular=.TRUE.
+!-
+  CALL histhori_regular (idf,pim,plon,pjm,plat, &
  &  ' ','Default grid',phoriid,rectilinear)
 !-----------------------------
@@ -433,5 +429,5 @@
 SUBROUTINE histbeg_irregular &
  &  (pfilename,pim,plon,plon_bounds,plat,plat_bounds,   &
- &   pitau0,pdate0,pdeltat,phoriid,pfileid,domain_id,nb_bits)
+ &   pitau0,pdate0,pdeltat,phoriid,idf,domain_id,nb_bits)
 !---------------------------------------------------------------------
 !- This subroutine initializes a netcdf file and returns the ID.
@@ -458,5 +454,5 @@
 !-
 !- phoriid   : ID of the horizontal grid
-!- pfileid   : ID of the netcdf file
+!- idf       : ID of the netcdf file
 !-
 !- Optional INPUT arguments
@@ -483,5 +479,5 @@
   INTEGER,INTENT(IN) :: pitau0
   REAL,INTENT(IN) :: pdate0,pdeltat
-  INTEGER,INTENT(OUT) :: pfileid,phoriid
+  INTEGER,INTENT(OUT) :: idf,phoriid
   INTEGER,INTENT(IN),OPTIONAL :: domain_id,nb_bits
 !-
@@ -501,5 +497,5 @@
  &    'in histcom.f90 in order to accomodate all these files',' ')
   ENDIF
-  pfileid  = nb_files
+  idf = nb_files
 !-
 ! 1.0 Transfering into the common for future use
@@ -507,7 +503,7 @@
   IF (l_dbg) WRITE(*,*) "histbeg_irregular 1.0"
 !-
-  W_F(pfileid)%itau0  = pitau0
-  W_F(pfileid)%date0  = pdate0
-  W_F(pfileid)%deltat = pdeltat
+  W_F(idf)%itau0  = pitau0
+  W_F(idf)%date0  = pdate0
+  W_F(idf)%deltat = pdeltat
 !-
 ! 2.0 Initializes all variables for this file
@@ -515,11 +511,11 @@
   IF (l_dbg) WRITE(*,*) "histbeg_irregular 2.0"
 !-
-  W_F(pfileid)%n_var = 0
-  W_F(pfileid)%n_tax = 0
-  W_F(pfileid)%n_hax = 0
-  W_F(pfileid)%n_zax = 0
-!-
-  W_F(pfileid)%slab_ori(1:2) = (/ 1,1 /)
-  W_F(pfileid)%slab_sz(1:2)  = (/ pim,1 /)
+  W_F(idf)%n_var = 0
+  W_F(idf)%n_tax = 0
+  W_F(idf)%n_hax = 0
+  W_F(idf)%n_zax = 0
+!-
+  W_F(idf)%slab_ori(1:2) = (/ 1,1 /)
+  W_F(idf)%slab_sz(1:2)  = (/ pim,1 /)
 !-
 ! 3.0 Opening netcdf file and defining dimensions
@@ -551,6 +547,6 @@
   iret = NF90_CREATE (file,m_c,nfid)
 !-
-  iret = NF90_DEF_DIM (nfid,'x',pim,W_F(pfileid)%xid)
-  W_F(pfileid)%yid = 0
+  iret = NF90_DEF_DIM (nfid,'x',pim,W_F(idf)%xid)
+  W_F(idf)%yid = 0
 !-
 ! 4.0 Declaring the geographical coordinates and other attributes
@@ -572,15 +568,15 @@
 !-
   IF (PRESENT(domain_id)) THEN
-    W_F(pfileid)%dom_id_svg = domain_id
-  ENDIF
-  W_F(pfileid)%ncfid = nfid
-  W_F(pfileid)%full_size(1:2) = (/ pim,1 /)
+    W_F(idf)%dom_id_svg = domain_id
+  ENDIF
+  W_F(idf)%ncfid = nfid
+  W_F(idf)%full_size(1:2) = (/ pim,1 /)
 !-
 ! 6.0 storing the geographical coordinates
 !-
-  W_F(pfileid)%regular=.FALSE.
+  W_F(idf)%regular=.FALSE.
 !-
   CALL histhori_irregular &
- &  (pfileid,pim,plon,plon_bounds,plat,plat_bounds, &
+ &  (idf,pim,plon,plon_bounds,plat,plat_bounds, &
  &   ' ','Default grid',phoriid)
 !-------------------------------
@@ -588,5 +584,5 @@
 !===
 SUBROUTINE histhori_regular &
- &  (pfileid,pim,plon,pjm,plat,phname,phtitle,phid,opt_rectilinear)
+ &  (idf,pim,plon,pjm,plat,phname,phtitle,phid,opt_rectilinear)
 !---------------------------------------------------------------------
 !- This subroutine is made to declare a new horizontale grid.
@@ -600,5 +596,5 @@
 !- INPUT
 !-
-!- pfileid : The id of the file to which the grid should be added
+!- idf     : The id of the file to which the grid should be added
 !- pim     : Size in the longitude direction
 !- plon    : The longitudes
@@ -619,5 +615,5 @@
   IMPLICIT NONE
 !-
-  INTEGER,INTENT(IN) :: pfileid,pim,pjm
+  INTEGER,INTENT(IN) :: idf,pim,pjm
   REAL,INTENT(IN),DIMENSION(pim,pjm) :: plon,plat
   CHARACTER(LEN=*),INTENT(IN) :: phname,phtitle
@@ -639,6 +635,6 @@
 ! 1.0 Check that all fits in the buffers
 !-
-  IF (    (pim /= W_F(pfileid)%full_size(1)) &
- &    .OR.(pjm /= W_F(pfileid)%full_size(2)) ) THEN
+  IF (    (pim /= W_F(idf)%full_size(1)) &
+ &    .OR.(pjm /= W_F(idf)%full_size(2)) ) THEN
     CALL ipslerr (3,"histhori", &
  &   'The new horizontal grid does not have the same size', &
@@ -657,12 +653,12 @@
   IF (l_dbg) WRITE(*,*) "histhori_regular 1.0"
 !-
-  nfid = W_F(pfileid)%ncfid
+  nfid = W_F(idf)%ncfid
 !-
   ndim = 2
-  dims(1:2) = (/ W_F(pfileid)%xid,W_F(pfileid)%yid /)
+  dims(1:2) = (/ W_F(idf)%xid,W_F(idf)%yid /)
 !-
   tmp_name = phname
   IF (rectilinear) THEN
-    IF (W_F(pfileid)%n_hax == 0) THEN
+    IF (W_F(idf)%n_hax == 0) THEN
       lon_name = 'lon'
       lat_name = 'lat'
@@ -672,5 +668,5 @@
     ENDIF
   ELSE
-    IF (W_F(pfileid)%n_hax == 0) THEN
+    IF (W_F(idf)%n_hax == 0) THEN
       lon_name = 'nav_lon'
       lat_name = 'nav_lat'
@@ -683,7 +679,7 @@
 ! 1.2 Save the informations
 !-
-  phid = W_F(pfileid)%n_hax+1
-  W_F(pfileid)%n_hax = phid
-  W_F(pfileid)%hax_name(phid,1:2) = (/ lon_name,lat_name /)
+  phid = W_F(idf)%n_hax+1
+  W_F(idf)%n_hax = phid
+  W_F(idf)%hax_name(phid,1:2) = (/ lon_name,lat_name /)
   tmp_title = phtitle
 !-
@@ -694,5 +690,5 @@
   IF (rectilinear) THEN
     ndim = 1
-    dims(1:1) = (/ W_F(pfileid)%xid /)
+    dims(1:1) = (/ W_F(idf)%xid /)
   ENDIF
   iret = NF90_DEF_VAR (nfid,lon_name,NF90_FLOAT,dims(1:ndim),nlonid)
@@ -715,5 +711,5 @@
   IF (rectilinear) THEN
     ndim = 1
-    dims(1:1) = (/ W_F(pfileid)%yid /)
+    dims(1:1) = (/ W_F(idf)%yid /)
   ENDIF
   iret = NF90_DEF_VAR (nfid,lat_name,NF90_FLOAT,dims(1:ndim),nlatid)
@@ -736,8 +732,8 @@
   IF (l_dbg) WRITE(*,*) "histhori_regular 4.0"
 !-
-  orix = W_F(pfileid)%slab_ori(1)
-  oriy = W_F(pfileid)%slab_ori(2)
-  par_szx = W_F(pfileid)%slab_sz(1)
-  par_szy = W_F(pfileid)%slab_sz(2)
+  orix = W_F(idf)%slab_ori(1)
+  oriy = W_F(idf)%slab_ori(2)
+  par_szx = W_F(idf)%slab_sz(1)
+  par_szy = W_F(idf)%slab_sz(2)
 !-
 ! Transfer the longitude
@@ -764,5 +760,5 @@
 !===
 SUBROUTINE histhori_irregular &
- &  (pfileid,pim,plon,plon_bounds,plat,plat_bounds, &
+ &  (idf,pim,plon,plon_bounds,plat,plat_bounds, &
  &   phname,phtitle,phid)
 !---------------------------------------------------------------------
@@ -777,5 +773,5 @@
 !- INPUT
 !-
-!- pfileid     : The id of the file to which the grid should be added
+!- idf         : The id of the file to which the grid should be added
 !- pim         : Size in the longitude direction
 !- plon        : The longitudes
@@ -792,5 +788,5 @@
   IMPLICIT NONE
 !-
-  INTEGER,INTENT(IN) :: pfileid,pim
+  INTEGER,INTENT(IN) :: idf,pim
   REAL,DIMENSION(pim),INTENT(IN) :: plon,plat
   REAL,DIMENSION(:,:),INTENT(IN) :: plon_bounds,plat_bounds
@@ -814,6 +810,6 @@
 ! 1.0 Check that all fits in the buffers
 !-
-  IF (    (pim /= W_F(pfileid)%full_size(1)) &
- &    .OR.(W_F(pfileid)%full_size(2) /= 1) ) THEN
+  IF (    (pim /= W_F(idf)%full_size(1)) &
+ &    .OR.(W_F(idf)%full_size(2) /= 1) ) THEN
     CALL ipslerr (3,"histhori", &
  &   'The new horizontal grid does not have the same size', &
@@ -826,5 +822,5 @@
   IF (l_dbg) WRITE(*,*) 'histhori_irregular 1.0'
 !-
-  nfid = W_F(pfileid)%ncfid
+  nfid = W_F(idf)%ncfid
 !-
   IF     (SIZE(plon_bounds,DIM=1) == pim) THEN
@@ -845,10 +841,10 @@
   iret = NF90_DEF_DIM (nfid,'nbnd',nbbounds,twoid)
   ndim = 1
-  dims(1) = W_F(pfileid)%xid
+  dims(1) = W_F(idf)%xid
   ndimb = 2
-  dimsb(1:2) = (/ twoid,W_F(pfileid)%xid /)
+  dimsb(1:2) = (/ twoid,W_F(idf)%xid /)
 !-
   tmp_name = phname
-  IF (W_F(pfileid)%n_hax == 0) THEN
+  IF (W_F(idf)%n_hax == 0) THEN
     lon_name = 'nav_lon'
     lat_name = 'nav_lat'
@@ -862,7 +858,7 @@
 ! 1.2 Save the informations
 !-
-  phid = W_F(pfileid)%n_hax+1
-  W_F(pfileid)%n_hax = phid
-  W_F(pfileid)%hax_name(phid,1:2) = (/ lon_name,lat_name /)
+  phid = W_F(idf)%n_hax+1
+  W_F(idf)%n_hax = phid
+  W_F(idf)%hax_name(phid,1:2) = (/ lon_name,lat_name /)
   tmp_title = phtitle
 !-
@@ -949,5 +945,5 @@
 END SUBROUTINE histhori_irregular
 !===
-SUBROUTINE histvert (pfileid,pzaxname,pzaxtitle,pzaxunit, &
+SUBROUTINE histvert (idf,pzaxname,pzaxtitle,pzaxunit, &
  &                   pzsize,pzvalues,pzaxid,pdirect)
 !---------------------------------------------------------------------
@@ -959,5 +955,5 @@
 !- INPUT
 !-
-!- pfileid  : ID of the file the variable should be archived in
+!- idf      : ID of the file the variable should be archived in
 !- pzaxname : Name of the vertical axis
 !- pzaxtitle: title of the vertical axis
@@ -978,5 +974,5 @@
   IMPLICIT NONE
 !-
-  INTEGER,INTENT(IN) :: pfileid,pzsize
+  INTEGER,INTENT(IN) :: idf,pzsize
   CHARACTER(LEN=*),INTENT(IN) :: pzaxname,pzaxunit,pzaxtitle
   REAL,INTENT(IN) :: pzvalues(pzsize)
@@ -1022,5 +1018,5 @@
   ENDIF
 !-
-  IF (W_F(pfileid)%n_zax+1 > nb_zax_max) THEN
+  IF (W_F(idf)%n_zax+1 > nb_zax_max) THEN
     CALL ipslerr (3,"histvert", &
    &  'Table of vertical axes too small. You should increase ',&
@@ -1029,7 +1025,7 @@
   ENDIF
 !-
-  iv = W_F(pfileid)%n_zax
+  iv = W_F(idf)%n_zax
   IF (iv > 1) THEN
-    CALL find_str (W_F(pfileid)%zax_name(1:iv-1),pzaxname,pos)
+    CALL find_str (W_F(idf)%zax_name(1:iv-1),pzaxname,pos)
   ELSE
     pos = 0
@@ -1038,5 +1034,5 @@
   IF (pos > 0) THEN
     WRITE(str71,'("Check variable ",A," in file",I3)') &
- &    TRIM(pzaxname),pfileid
+ &    TRIM(pzaxname),idf
     CALL ipslerr (3,"histvert", &
  &    "Vertical axis already exists",TRIM(str71), &
@@ -1044,5 +1040,5 @@
   ENDIF
 !-
-  iv = W_F(pfileid)%n_zax+1
+  iv = W_F(idf)%n_zax+1
 !-
 ! 2.0 Add the information to the file
@@ -1051,5 +1047,5 @@
  &  WRITE(*,*) "histvert : 2.0 Add the information to the file"
 !-
-  nfid = W_F(pfileid)%ncfid
+  nfid = W_F(idf)%ncfid
 !-
   leng = MIN(LEN_TRIM(pzaxname),20)
@@ -1084,8 +1080,8 @@
   &  WRITE(*,*) "histvert : 3.0 add the information to the common"
 !-
-  W_F(pfileid)%n_zax = iv
-  W_F(pfileid)%zax_size(iv) = pzsize
-  W_F(pfileid)%zax_name(iv) = pzaxname
-  W_F(pfileid)%zax_ids(iv) = zaxid_tmp
+  W_F(idf)%n_zax = iv
+  W_F(idf)%zax_size(iv) = pzsize
+  W_F(idf)%zax_name(iv) = pzaxname
+  W_F(idf)%zax_ids(iv) = zaxid_tmp
   pzaxid = iv
 !----------------------
@@ -1093,5 +1089,5 @@
 !===
 SUBROUTINE histdef &
- &  (pfileid,pvarname,ptitle,punit, &
+ &  (idf,pvarname,ptitle,punit, &
  &   pxsize,pysize,phoriid,pzsize,par_oriz,par_szz,pzid, &
  &   xtype,popp,pfreq_opp,pfreq_wrt,var_range,standard_name)
@@ -1106,5 +1102,5 @@
 !- INPUT
 !-
-!- pfileid  : ID of the file the variable should be archived in
+!- idf      : ID of the file the variable should be archived in
 !- pvarname : Name of the variable, short and easy to remember
 !- ptitle   : Full name of the variable
@@ -1146,5 +1142,5 @@
   IMPLICIT NONE
 !-
-  INTEGER,INTENT(IN) :: pfileid,pxsize,pysize,pzsize,pzid
+  INTEGER,INTENT(IN) :: idf,pxsize,pysize,pzsize,pzid
   INTEGER,INTENT(IN) :: par_oriz,par_szz,xtype,phoriid
   CHARACTER(LEN=*),INTENT(IN) :: pvarname,punit,popp,ptitle
@@ -1153,5 +1149,5 @@
   CHARACTER(LEN=*),OPTIONAL,INTENT(IN) :: standard_name
 !-
-  INTEGER :: iv,i
+  INTEGER :: iv
   CHARACTER(LEN=70) :: str70,str71,str72
   CHARACTER(LEN=20) :: tmp_name
@@ -1167,6 +1163,6 @@
   ex_topps = 'ave, inst, t_min, t_max, t_sum, once, never, l_max, l_min'
 !-
-  W_F(pfileid)%n_var = W_F(pfileid)%n_var+1
-  iv = W_F(pfileid)%n_var
+  W_F(idf)%n_var = W_F(idf)%n_var+1
+  iv = W_F(idf)%n_var
 !-
   IF (iv > nb_var_max) THEN
@@ -1183,5 +1179,5 @@
 !-
   IF (iv > 1) THEN
-    CALL find_str (W_F(pfileid)%W_V(1:iv-1)%v_name,pvarname,pos)
+    CALL find_str (W_F(idf)%W_V(1:iv-1)%v_name,pvarname,pos)
   ELSE
     pos = 0
@@ -1191,34 +1187,34 @@
     str70 = "Variable already exists"
     WRITE(str71,'("Check variable  ",a," in file",I3)') &
- &    TRIM(pvarname),pfileid
+ &    TRIM(pvarname),idf
     str72 = "Can also be a wrong file ID in another declaration"
     CALL ipslerr (3,"histdef",str70,str71,str72)
   ENDIF
 !-
-  W_F(pfileid)%W_V(iv)%v_name = pvarname
-  W_F(pfileid)%W_V(iv)%title = ptitle
-  W_F(pfileid)%W_V(iv)%unit_name = punit
+  W_F(idf)%W_V(iv)%v_name = pvarname
+  W_F(idf)%W_V(iv)%title = ptitle
+  W_F(idf)%W_V(iv)%unit_name = punit
   IF (PRESENT(standard_name)) THEN
-    W_F(pfileid)%W_V(iv)%std_name = standard_name
-  ELSE
-    W_F(pfileid)%W_V(iv)%std_name = ptitle
-  ENDIF
-  tmp_name = W_F(pfileid)%W_V(iv)%v_name
+    W_F(idf)%W_V(iv)%std_name = standard_name
+  ELSE
+    W_F(idf)%W_V(iv)%std_name = ptitle
+  ENDIF
+  tmp_name = W_F(idf)%W_V(iv)%v_name
 !-
 ! 1.1 decode the operations
 !-
-  W_F(pfileid)%W_V(iv)%fullop = popp
+  W_F(idf)%W_V(iv)%fullop = popp
   CALL buildop &
- &  (TRIM(popp),ex_topps,W_F(pfileid)%W_V(iv)%topp,missing_val, &
- &   W_F(pfileid)%W_V(iv)%sopp,W_F(pfileid)%W_V(iv)%scal, &
- &   W_F(pfileid)%W_V(iv)%nbopp)
+ &  (TRIM(popp),ex_topps,W_F(idf)%W_V(iv)%topp,missing_val, &
+ &   W_F(idf)%W_V(iv)%sopp,W_F(idf)%W_V(iv)%scal, &
+ &   W_F(idf)%W_V(iv)%nbopp)
 !-
 ! 1.2 If we have an even number of operations
 !     then we need to add identity
 !-
-  IF ( MOD(W_F(pfileid)%W_V(iv)%nbopp,2) == 0) THEN
-    W_F(pfileid)%W_V(iv)%nbopp = W_F(pfileid)%W_V(iv)%nbopp+1
-    W_F(pfileid)%W_V(iv)%sopp(W_F(pfileid)%W_V(iv)%nbopp) = 'ident'
-    W_F(pfileid)%W_V(iv)%scal(W_F(pfileid)%W_V(iv)%nbopp) = missing_val
+  IF ( MOD(W_F(idf)%W_V(iv)%nbopp,2) == 0) THEN
+    W_F(idf)%W_V(iv)%nbopp = W_F(idf)%W_V(iv)%nbopp+1
+    W_F(idf)%W_V(iv)%sopp(W_F(idf)%W_V(iv)%nbopp) = 'ident'
+    W_F(idf)%W_V(iv)%scal(W_F(idf)%W_V(iv)%nbopp) = missing_val
   ENDIF
 !-
@@ -1226,7 +1222,7 @@
 !-
   IF (xtype == hist_r8) THEN
-    W_F(pfileid)%W_V(iv)%v_typ = hist_r8
-  ELSE
-    W_F(pfileid)%W_V(iv)%v_typ = hist_r4
+    W_F(idf)%W_V(iv)%v_typ = hist_r8
+  ELSE
+    W_F(idf)%W_V(iv)%v_typ = hist_r4
   ENDIF
 !-
@@ -1234,24 +1230,24 @@
 !-
   IF (l_dbg) THEN
-    WRITE(*,*) "histdef : 2.0",pfileid,iv,W_F(pfileid)%W_V(iv)%nbopp, &
- &    W_F(pfileid)%W_V(iv)%sopp(1:W_F(pfileid)%W_V(iv)%nbopp), &
- &    W_F(pfileid)%W_V(iv)%scal(1:W_F(pfileid)%W_V(iv)%nbopp)
-  ENDIF
-!-
-  W_F(pfileid)%W_V(iv)%scsize(1:3) = (/ pxsize,pysize,pzsize /)
-  W_F(pfileid)%W_V(iv)%zorig(1:3) = &
- &  (/ W_F(pfileid)%slab_ori(1),W_F(pfileid)%slab_ori(2),par_oriz /)
-  W_F(pfileid)%W_V(iv)%zsize(1:3) = &
- &  (/ W_F(pfileid)%slab_sz(1),W_F(pfileid)%slab_sz(2),par_szz /)
+    WRITE(*,*) "histdef : 2.0",idf,iv,W_F(idf)%W_V(iv)%nbopp, &
+ &    W_F(idf)%W_V(iv)%sopp(1:W_F(idf)%W_V(iv)%nbopp), &
+ &    W_F(idf)%W_V(iv)%scal(1:W_F(idf)%W_V(iv)%nbopp)
+  ENDIF
+!-
+  W_F(idf)%W_V(iv)%scsize(1:3) = (/ pxsize,pysize,pzsize /)
+  W_F(idf)%W_V(iv)%zorig(1:3) = &
+ &  (/ W_F(idf)%slab_ori(1),W_F(idf)%slab_ori(2),par_oriz /)
+  W_F(idf)%W_V(iv)%zsize(1:3) = &
+ &  (/ W_F(idf)%slab_sz(1),W_F(idf)%slab_sz(2),par_szz /)
 !-
 ! Is the size of the full array the same as that of the coordinates ?
 !-
-  IF (    (pxsize > W_F(pfileid)%full_size(1)) &
- &    .OR.(pysize > W_F(pfileid)%full_size(2)) ) THEN
+  IF (    (pxsize > W_F(idf)%full_size(1)) &
+ &    .OR.(pysize > W_F(idf)%full_size(2)) ) THEN
 !-
     str70 = "The size of the variable is different "// &
  &          "from the one of the coordinates"
     WRITE(str71,'("Size of coordinates :",2I4)') &
- &   W_F(pfileid)%full_size(1),W_F(pfileid)%full_size(2)
+ &   W_F(idf)%full_size(1),W_F(idf)%full_size(2)
     WRITE(str72,'("Size declared for variable ",a," :",2I4)') &
  &   TRIM(tmp_name),pxsize,pysize
@@ -1261,10 +1257,10 @@
 ! Is the size of the zoom smaller than the coordinates ?
 !-
-  IF (    (W_F(pfileid)%full_size(1) < W_F(pfileid)%slab_sz(1)) &
- &    .OR.(W_F(pfileid)%full_size(2) < W_F(pfileid)%slab_sz(2)) ) THEN
+  IF (    (W_F(idf)%full_size(1) < W_F(idf)%slab_sz(1)) &
+ &    .OR.(W_F(idf)%full_size(2) < W_F(idf)%slab_sz(2)) ) THEN
     str70 = &
  &   "Size of variable should be greater or equal to those of the zoom"
     WRITE(str71,'("Size of XY zoom :",2I4)') &
- &   W_F(pfileid)%slab_sz(1),W_F(pfileid)%slab_sz(2)
+ &   W_F(idf)%slab_sz(1),W_F(idf)%slab_sz(2)
     WRITE(str72,'("Size declared for variable ",A," :",2I4)') &
  &   TRIM(tmp_name),pxsize,pysize
@@ -1275,8 +1271,8 @@
 !     and a fall back onto the default grid
 !-
-  IF ( (phoriid > 0).AND.(phoriid <= W_F(pfileid)%n_hax) ) THEN
-    W_F(pfileid)%W_V(iv)%h_axid = phoriid
-  ELSE
-    W_F(pfileid)%W_V(iv)%h_axid = 1
+  IF ( (phoriid > 0).AND.(phoriid <= W_F(idf)%n_hax) ) THEN
+    W_F(idf)%W_V(iv)%h_axid = phoriid
+  ELSE
+    W_F(idf)%W_V(iv)%h_axid = 1
     CALL ipslerr (2,"histdef", &
    &  'We use the default grid for variable as an invalide',&
@@ -1290,5 +1286,5 @@
 !-- Does the vertical coordinate exist ?
 !-
-    IF (pzid > W_F(pfileid)%n_zax) THEN
+    IF (pzid > W_F(idf)%n_zax) THEN
       WRITE(str70, &
  &    '("The vertical coordinate chosen for variable ",a)') &
@@ -1300,10 +1296,10 @@
 !-- Is the vertical size of the variable equal to that of the axis ?
 !-
-    IF (par_szz /= W_F(pfileid)%zax_size(pzid)) THEN
+    IF (par_szz /= W_F(idf)%zax_size(pzid)) THEN
       str70 = "The size of the zoom does not correspond "// &
  &            "to the size of the chosen vertical axis"
       WRITE(str71,'("Size of zoom in z :",I4)') par_szz
       WRITE(str72,'("Size declared for axis ",A," :",I4)') &
- &     TRIM(W_F(pfileid)%zax_name(pzid)),W_F(pfileid)%zax_size(pzid)
+ &     TRIM(W_F(idf)%zax_name(pzid)),W_F(idf)%zax_size(pzid)
       CALL ipslerr (3,"histdef",str70,str71,str72)
     ENDIF
@@ -1319,32 +1315,28 @@
       CALL ipslerr (3,"histdef",str70,str71,str72)
     ENDIF
-    W_F(pfileid)%W_V(iv)%z_axid = pzid
-  ELSE
-    W_F(pfileid)%W_V(iv)%z_axid = -99
-  ENDIF
-!-
-! 3.0 Determine the position of the variable in the buffer
-!     If it is instantaneous output then we do not use the buffer
-!-
-  IF (l_dbg) WRITE(*,*) "histdef : 3.0"
-!-
-! 3.1 We get the size of the arrays histwrite will get and check
-!     that they fit into the tmp_buffer
-!-
-  buff_sz = W_F(pfileid)%W_V(iv)%zsize(1) &
- &         *W_F(pfileid)%W_V(iv)%zsize(2) &
- &         *W_F(pfileid)%W_V(iv)%zsize(3)
-!-
-! 3.2 move the pointer of the buffer array for operation
-!     which need bufferisation
-!-
-  IF (     (TRIM(W_F(pfileid)%W_V(iv)%topp) /= "inst") &
- &    .AND.(TRIM(W_F(pfileid)%W_V(iv)%topp) /= "once") &
- &    .AND.(TRIM(W_F(pfileid)%W_V(iv)%topp) /= "never") )THEN
-    W_F(pfileid)%W_V(iv)%point = buff_pos+1
-    buff_pos = buff_pos+buff_sz
+    W_F(idf)%W_V(iv)%z_axid = pzid
+  ELSE
+    W_F(idf)%W_V(iv)%z_axid = -99
+  ENDIF
+!-
+! 3.0 We get the size of the arrays histwrite will get
+!     and eventually allocate the time_buffer
+!-
+  IF (l_dbg) THEN
+    WRITE(*,*) "histdef : 3.0"
+  ENDIF
+!-
+  buff_sz = W_F(idf)%W_V(iv)%zsize(1) &
+ &         *W_F(idf)%W_V(iv)%zsize(2) &
+ &         *W_F(idf)%W_V(iv)%zsize(3)
+!-
+  IF (     (TRIM(W_F(idf)%W_V(iv)%topp) /= "inst") &
+ &    .AND.(TRIM(W_F(idf)%W_V(iv)%topp) /= "once") &
+ &    .AND.(TRIM(W_F(idf)%W_V(iv)%topp) /= "never") )THEN
+    ALLOCATE(W_F(idf)%W_V(iv)%t_bf(buff_sz))
+    W_F(idf)%W_V(iv)%t_bf(:) = 0.
     IF (l_dbg) THEN
-      WRITE(*,*) "histdef : 3.2 bufpos for iv = ",iv, &
- &      " pfileid = ",pfileid," is = ",W_F(pfileid)%W_V(iv)%point
+      WRITE(*,*) "histdef : 3.0 allocating time_buffer for", &
+ &      " idf = ",idf," iv = ",iv," size = ",buff_sz
     ENDIF
   ENDIF
@@ -1357,6 +1349,6 @@
   IF (l_dbg) WRITE(*,*) "histdef : 4.0"
 !-
-  W_F(pfileid)%W_V(iv)%freq_opp = pfreq_opp
-  W_F(pfileid)%W_V(iv)%freq_wrt = pfreq_wrt
+  W_F(idf)%W_V(iv)%freq_opp = pfreq_opp
+  W_F(idf)%W_V(iv)%freq_wrt = pfreq_wrt
 !-
   CALL ioget_calendar(un_an,un_jour)
@@ -1376,5 +1368,5 @@
 ! 4.1 Frequency of operations and output should be larger than deltat !
 !-
-  IF (test_fopp < W_F(pfileid)%deltat) THEN
+  IF (test_fopp < W_F(idf)%deltat) THEN
     str70 = 'Frequency of operations should be larger than deltat'
     WRITE(str71,'("It is not the case for variable ",a," :",F10.4)') &
@@ -1384,8 +1376,8 @@
     CALL ipslerr (2,"histdef",str70,str71,str72)
 !-
-    W_F(pfileid)%W_V(iv)%freq_opp = W_F(pfileid)%deltat
-  ENDIF
-!-
-  IF (test_fwrt < W_F(pfileid)%deltat) THEN
+    W_F(idf)%W_V(iv)%freq_opp = W_F(idf)%deltat
+  ENDIF
+!-
+  IF (test_fwrt < W_F(idf)%deltat) THEN
     str70 = 'Frequency of output should be larger than deltat'
     WRITE(str71,'("It is not the case for variable ",a," :",F10.4)') &
@@ -1395,5 +1387,5 @@
     CALL ipslerr (2,"histdef",str70,str71,str72)
 !-
-    W_F(pfileid)%W_V(iv)%freq_wrt = W_F(pfileid)%deltat
+    W_F(idf)%W_V(iv)%freq_wrt = W_F(idf)%deltat
   ENDIF
 !-
@@ -1401,5 +1393,5 @@
 !     its compaticility with the choice of frequencies
 !-
-  IF (TRIM(W_F(pfileid)%W_V(iv)%topp) == "inst") THEN
+  IF (TRIM(W_F(idf)%W_V(iv)%topp) == "inst") THEN
     IF (test_fopp /= test_fwrt) THEN
       str70 = 'For instantaneous output the frequency '// &
@@ -1411,12 +1403,12 @@
       CALL ipslerr (2,"histdef",str70,str71,str72)
       IF (test_fopp < test_fwrt) THEN
-        W_F(pfileid)%W_V(iv)%freq_opp = pfreq_opp
-        W_F(pfileid)%W_V(iv)%freq_wrt = pfreq_opp
+        W_F(idf)%W_V(iv)%freq_opp = pfreq_opp
+        W_F(idf)%W_V(iv)%freq_wrt = pfreq_opp
       ELSE
-        W_F(pfileid)%W_V(iv)%freq_opp = pfreq_wrt
-        W_F(pfileid)%W_V(iv)%freq_wrt = pfreq_wrt
+        W_F(idf)%W_V(iv)%freq_opp = pfreq_wrt
+        W_F(idf)%W_V(iv)%freq_wrt = pfreq_wrt
       ENDIF
     ENDIF
-  ELSE IF (INDEX(ex_topps,TRIM(W_F(pfileid)%W_V(iv)%topp)) > 0) THEN
+  ELSE IF (INDEX(ex_topps,TRIM(W_F(idf)%W_V(iv)%topp)) > 0) THEN
     IF (test_fopp > test_fwrt) THEN
       str70 = 'For averages the frequency of operations '// &
@@ -1427,5 +1419,5 @@
       str72 = 'PATCH : The output frequency is used for both'
       CALL ipslerr (2,"histdef",str70,str71,str72)
-      W_F(pfileid)%W_V(iv)%freq_opp = pfreq_wrt
+      W_F(idf)%W_V(iv)%freq_opp = pfreq_wrt
     ENDIF
   ELSE
@@ -1433,6 +1425,6 @@
  &   TRIM(tmp_name)
     WRITE (str71,'("operation requested is :",A)') &
- &   W_F(pfileid)%W_V(iv)%topp
-    WRITE (str72,'("File ID :",I3)') pfileid
+ &   W_F(idf)%W_V(iv)%topp
+    WRITE (str72,'("File ID :",I3)') idf
     CALL ipslerr (3,"histdef",str70,str71,str72)
   ENDIF
@@ -1442,25 +1434,25 @@
   IF (l_dbg) WRITE(*,*) "histdef : 5.0"
 !-
-  W_F(pfileid)%W_V(iv)%hist_wrt_rng = (PRESENT(var_range))
-  IF (W_F(pfileid)%W_V(iv)%hist_wrt_rng) THEN
-    W_F(pfileid)%W_V(iv)%hist_calc_rng = (var_range(1) > var_range(2))
-    IF (W_F(pfileid)%W_V(iv)%hist_calc_rng) THEN
-      W_F(pfileid)%W_V(iv)%hist_minmax(1:2) = &
+  W_F(idf)%W_V(iv)%hist_wrt_rng = (PRESENT(var_range))
+  IF (W_F(idf)%W_V(iv)%hist_wrt_rng) THEN
+    W_F(idf)%W_V(iv)%hist_calc_rng = (var_range(1) > var_range(2))
+    IF (W_F(idf)%W_V(iv)%hist_calc_rng) THEN
+      W_F(idf)%W_V(iv)%hist_minmax(1:2) = &
  &      (/ ABS(missing_val),-ABS(missing_val) /)
     ELSE
-      W_F(pfileid)%W_V(iv)%hist_minmax(1:2) = var_range(1:2)
-    ENDIF
-  ENDIF
-!-
-! - freq_opp(pfileid,iv)/2./deltat(pfileid)
-  W_F(pfileid)%W_V(iv)%last_opp = W_F(pfileid)%itau0
-! - freq_wrt(pfileid,iv)/2./deltat(pfileid)
-  W_F(pfileid)%W_V(iv)%last_wrt = W_F(pfileid)%itau0
-! - freq_opp(pfileid,iv)/2./deltat(pfileid)
-  W_F(pfileid)%W_V(iv)%last_opp_chk = W_F(pfileid)%itau0
-! - freq_wrt(pfileid,iv)/2./deltat(pfileid)
-  W_F(pfileid)%W_V(iv)%last_wrt_chk = W_F(pfileid)%itau0
-  W_F(pfileid)%W_V(iv)%nb_opp = 0
-  W_F(pfileid)%W_V(iv)%nb_wrt = 0
+      W_F(idf)%W_V(iv)%hist_minmax(1:2) = var_range(1:2)
+    ENDIF
+  ENDIF
+!-
+! - freq_opp(idf,iv)/2./deltat(idf)
+  W_F(idf)%W_V(iv)%last_opp = W_F(idf)%itau0
+! - freq_wrt(idf,iv)/2./deltat(idf)
+  W_F(idf)%W_V(iv)%last_wrt = W_F(idf)%itau0
+! - freq_opp(idf,iv)/2./deltat(idf)
+  W_F(idf)%W_V(iv)%last_opp_chk = W_F(idf)%itau0
+! - freq_wrt(idf,iv)/2./deltat(idf)
+  W_F(idf)%W_V(iv)%last_wrt_chk = W_F(idf)%itau0
+  W_F(idf)%W_V(iv)%nb_opp = 0
+  W_F(idf)%W_V(iv)%nb_wrt = 0
 !-
 ! 6.0 Get the time axis for this variable
@@ -1468,32 +1460,32 @@
   IF (l_dbg) WRITE(*,*) "histdef : 6.0"
 !-
-  IF (W_F(pfileid)%W_V(iv)%freq_wrt > 0) THEN
-    WRITE(str10,'(I8.8)') INT(W_F(pfileid)%W_V(iv)%freq_wrt)
-    str40 = TRIM(W_F(pfileid)%W_V(iv)%topp)//"_"//TRIM(str10)
-  ELSE
-    WRITE(str10,'(I2.2,"month")') ABS(INT(W_F(pfileid)%W_V(iv)%freq_wrt))
-    str40 = TRIM(W_F(pfileid)%W_V(iv)%topp)//"_"//TRIM(str10)
-  ENDIF
-  CALL find_str (W_F(pfileid)%W_V(1:W_F(pfileid)%n_tax)%tax_name,str40,pos)
+  IF (W_F(idf)%W_V(iv)%freq_wrt > 0) THEN
+    WRITE(str10,'(I8.8)') INT(W_F(idf)%W_V(iv)%freq_wrt)
+    str40 = TRIM(W_F(idf)%W_V(iv)%topp)//"_"//TRIM(str10)
+  ELSE
+    WRITE(str10,'(I2.2,"month")') ABS(INT(W_F(idf)%W_V(iv)%freq_wrt))
+    str40 = TRIM(W_F(idf)%W_V(iv)%topp)//"_"//TRIM(str10)
+  ENDIF
+  CALL find_str (W_F(idf)%W_V(1:W_F(idf)%n_tax)%tax_name,str40,pos)
 !-
 ! No time axis for once, l_max, l_min or never operation
 !-
-  IF (     (TRIM(W_F(pfileid)%W_V(iv)%topp) /= 'once')  &
- &    .AND.(TRIM(W_F(pfileid)%W_V(iv)%topp) /= 'never') &
- &    .AND.(TRIM(W_F(pfileid)%W_V(iv)%topp) /= 'l_max') &
- &    .AND.(TRIM(W_F(pfileid)%W_V(iv)%topp) /= 'l_min') ) THEN
+  IF (     (TRIM(W_F(idf)%W_V(iv)%topp) /= 'once')  &
+ &    .AND.(TRIM(W_F(idf)%W_V(iv)%topp) /= 'never') &
+ &    .AND.(TRIM(W_F(idf)%W_V(iv)%topp) /= 'l_max') &
+ &    .AND.(TRIM(W_F(idf)%W_V(iv)%topp) /= 'l_min') ) THEN
     IF (pos < 0) THEN
-      W_F(pfileid)%n_tax = W_F(pfileid)%n_tax+1
-      W_F(pfileid)%W_V(W_F(pfileid)%n_tax)%tax_name = str40
-      W_F(pfileid)%W_V(W_F(pfileid)%n_tax)%tax_last = 0
-      W_F(pfileid)%W_V(iv)%t_axid = W_F(pfileid)%n_tax
+      W_F(idf)%n_tax = W_F(idf)%n_tax+1
+      W_F(idf)%W_V(W_F(idf)%n_tax)%tax_name = str40
+      W_F(idf)%W_V(W_F(idf)%n_tax)%tax_last = 0
+      W_F(idf)%W_V(iv)%t_axid = W_F(idf)%n_tax
     ELSE
-      W_F(pfileid)%W_V(iv)%t_axid = pos
+      W_F(idf)%W_V(iv)%t_axid = pos
     ENDIF
   ELSE
     IF (l_dbg) THEN
-      WRITE(*,*) "histdef : 7.0 ",TRIM(W_F(pfileid)%W_V(iv)%topp),'----'
-    ENDIF
-    W_F(pfileid)%W_V(iv)%t_axid = -99
+      WRITE(*,*) "histdef : 7.0 ",TRIM(W_F(idf)%W_V(iv)%topp),'----'
+    ENDIF
+    W_F(idf)%W_V(iv)%t_axid = -99
   ENDIF
 !-
@@ -1501,13 +1493,13 @@
 !     for never or once operation
 !-
-  IF (    (TRIM(W_F(pfileid)%W_V(iv)%topp) == 'once')  &
- &    .OR.(TRIM(W_F(pfileid)%W_V(iv)%topp) == 'never') ) THEN
-    W_F(pfileid)%W_V(iv)%freq_opp = 0.
-    W_F(pfileid)%W_V(iv)%freq_wrt = 0.
+  IF (    (TRIM(W_F(idf)%W_V(iv)%topp) == 'once')  &
+ &    .OR.(TRIM(W_F(idf)%W_V(iv)%topp) == 'never') ) THEN
+    W_F(idf)%W_V(iv)%freq_opp = 0.
+    W_F(idf)%W_V(iv)%freq_wrt = 0.
   ENDIF
 !---------------------
 END SUBROUTINE histdef
 !===
-SUBROUTINE histend (pfileid)
+SUBROUTINE histend (idf)
 !---------------------------------------------------------------------
 !- This subroutine end the decalaration of variables and sets the
@@ -1516,5 +1508,5 @@
 !- INPUT
 !-
-!- pfileid : ID of the file to be worked on
+!- idf : ID of the file to be worked on
 !-
 !- VERSION
@@ -1523,5 +1515,5 @@
   IMPLICIT NONE
 !-
-  INTEGER,INTENT(IN) :: pfileid
+  INTEGER,INTENT(IN) :: idf
 !-
   INTEGER :: nfid,nvid,iret,ndim,iv,itx,ziv,itax,dim_cnt
@@ -1541,5 +1533,5 @@
   CALL ipsldbg (old_status=l_dbg)
 !-
-  nfid = W_F(pfileid)%ncfid
+  nfid = W_F(idf)%ncfid
 !-
 ! 1.0 Create the time axes
@@ -1548,21 +1540,21 @@
 !---
   iret = NF90_DEF_DIM (nfid,'time_counter', &
- &                     NF90_UNLIMITED,W_F(pfileid)%tid)
+ &                     NF90_UNLIMITED,W_F(idf)%tid)
 !-
 ! 1.1 Define all the time axes needed for this file
 !-
-  DO itx=1,W_F(pfileid)%n_tax
-    dims(1) = W_F(pfileid)%tid
-    IF (W_F(pfileid)%n_tax > 1) THEN
-      str30 = "t_"//W_F(pfileid)%W_V(itx)%tax_name
+  DO itx=1,W_F(idf)%n_tax
+    dims(1) = W_F(idf)%tid
+    IF (W_F(idf)%n_tax > 1) THEN
+      str30 = "t_"//W_F(idf)%W_V(itx)%tax_name
     ELSE
       str30 = "time_counter"
     ENDIF
     iret = NF90_DEF_VAR (nfid,str30,NF90_DOUBLE, &
- &           dims(1),W_F(pfileid)%W_V(itx)%tdimid)
-    IF (W_F(pfileid)%n_tax <= 1) THEN
-      iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid,'axis',"T")
-    ENDIF
-    iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid, &
+ &           dims(1),W_F(idf)%W_V(itx)%tdimid)
+    IF (W_F(idf)%n_tax <= 1) THEN
+      iret = NF90_PUT_ATT (nfid,W_F(idf)%W_V(itx)%tdimid,'axis',"T")
+    ENDIF
+    iret = NF90_PUT_ATT (nfid,W_F(idf)%W_V(itx)%tdimid, &
  &           'standard_name',"time")
 !---
@@ -1573,6 +1565,6 @@
 !   if there is a ioconf routine to control it.
 !---
-!-- rtime0 = itau2date(itau0(pfileid),date0(pfileid),deltat(pfileid))
-    rtime0 = W_F(pfileid)%date0
+!-- rtime0 = itau2date(itau0(idf),date0(idf),deltat(idf))
+    rtime0 = W_F(idf)%date0
 !-
     CALL ju2ymds(rtime0,year,month,day,sec)
@@ -1591,15 +1583,15 @@
  &   FMT='(A,I4.4,"-",I2.2,"-",I2.2," ",I2.2,":",I2.2,":",I2.2)') &
  &    'seconds since ',year,month,day,hours,minutes,INT(sec)
-    iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid, &
+    iret = NF90_PUT_ATT (nfid,W_F(idf)%W_V(itx)%tdimid, &
  &           'units',TRIM(str70))
 !-
     CALL ioget_calendar (str30)
-    iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid, &
+    iret = NF90_PUT_ATT (nfid,W_F(idf)%W_V(itx)%tdimid, &
  &           'calendar',TRIM(str30))
 !-
-    iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid, &
+    iret = NF90_PUT_ATT (nfid,W_F(idf)%W_V(itx)%tdimid, &
  &           'title','Time')
 !-
-    iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid, &
+    iret = NF90_PUT_ATT (nfid,W_F(idf)%W_V(itx)%tdimid, &
  &           'long_name','Time axis')
 !-
@@ -1607,5 +1599,5 @@
  &   FMT='(" ",I4.4,"-",A3,"-",I2.2," ",I2.2,":",I2.2,":",I2.2)') &
  &    year,cal(month),day,hours,minutes,INT(sec)
-    iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid, &
+    iret = NF90_PUT_ATT (nfid,W_F(idf)%W_V(itx)%tdimid, &
  &           'time_origin',TRIM(str70))
   ENDDO
@@ -1615,18 +1607,18 @@
   IF (l_dbg) WRITE(*,*) "histend : 2.0"
 !-
-  DO iv=1,W_F(pfileid)%n_var
+  DO iv=1,W_F(idf)%n_var
 !---
-    itax = W_F(pfileid)%W_V(iv)%t_axid
+    itax = W_F(idf)%W_V(iv)%t_axid
 !---
-    IF (W_F(pfileid)%regular) THEN
-      dims(1:2) = (/ W_F(pfileid)%xid,W_F(pfileid)%yid /)
+    IF (W_F(idf)%regular) THEN
+      dims(1:2) = (/ W_F(idf)%xid,W_F(idf)%yid /)
       dim_cnt = 2
     ELSE
-      dims(1) = W_F(pfileid)%xid
+      dims(1) = W_F(idf)%xid
       dim_cnt = 1
     ENDIF
 !---
-    tmp_opp = W_F(pfileid)%W_V(iv)%topp
-    ziv = W_F(pfileid)%W_V(iv)%z_axid
+    tmp_opp = W_F(idf)%W_V(iv)%topp
+    ziv = W_F(idf)%W_V(iv)%z_axid
 !---
 !   2.1 dimension of field
@@ -1638,9 +1630,9 @@
         IF (ziv == -99) THEN
           ndim = dim_cnt+1
-          dims(dim_cnt+1:dim_cnt+2) = (/ W_F(pfileid)%tid,0 /)
+          dims(dim_cnt+1:dim_cnt+2) = (/ W_F(idf)%tid,0 /)
         ELSE
           ndim = dim_cnt+2
           dims(dim_cnt+1:dim_cnt+2) = &
- &         (/ W_F(pfileid)%zax_ids(ziv),W_F(pfileid)%tid /)
+ &         (/ W_F(idf)%zax_ids(ziv),W_F(idf)%tid /)
         ENDIF
       ELSE
@@ -1650,32 +1642,32 @@
         ELSE
           ndim = dim_cnt+1
-          dims(dim_cnt+1:dim_cnt+2) = (/ W_F(pfileid)%zax_ids(ziv),0 /)
+          dims(dim_cnt+1:dim_cnt+2) = (/ W_F(idf)%zax_ids(ziv),0 /)
         ENDIF
       ENDIF
 !-
-      iret = NF90_DEF_VAR (nfid,TRIM(W_F(pfileid)%W_V(iv)%v_name), &
- &             W_F(pfileid)%W_V(iv)%v_typ,dims(1:ABS(ndim)),nvid)
-!-
-      W_F(pfileid)%W_V(iv)%ncvid = nvid
-!-
-      IF (LEN_TRIM(W_F(pfileid)%W_V(iv)%unit_name) > 0) THEN
+      iret = NF90_DEF_VAR (nfid,TRIM(W_F(idf)%W_V(iv)%v_name), &
+ &             W_F(idf)%W_V(iv)%v_typ,dims(1:ABS(ndim)),nvid)
+!-
+      W_F(idf)%W_V(iv)%ncvid = nvid
+!-
+      IF (LEN_TRIM(W_F(idf)%W_V(iv)%unit_name) > 0) THEN
         iret = NF90_PUT_ATT (nfid,nvid,'units', &
- &                           TRIM(W_F(pfileid)%W_V(iv)%unit_name))
+ &                           TRIM(W_F(idf)%W_V(iv)%unit_name))
       ENDIF
       iret = NF90_PUT_ATT (nfid,nvid,'standard_name', &
- &                         TRIM(W_F(pfileid)%W_V(iv)%std_name))
+ &                         TRIM(W_F(idf)%W_V(iv)%std_name))
 !-
       iret = NF90_PUT_ATT (nfid,nvid,'_FillValue', &
  &                         REAL(missing_val,KIND=4))
-      IF (W_F(pfileid)%W_V(iv)%hist_wrt_rng) THEN
+      IF (W_F(idf)%W_V(iv)%hist_wrt_rng) THEN
         iret = NF90_PUT_ATT (nfid,nvid,'valid_min', &
- &               REAL(W_F(pfileid)%W_V(iv)%hist_minmax(1),KIND=4))
+ &               REAL(W_F(idf)%W_V(iv)%hist_minmax(1),KIND=4))
         iret = NF90_PUT_ATT (nfid,nvid,'valid_max', &
- &               REAL(W_F(pfileid)%W_V(iv)%hist_minmax(2),KIND=4))
+ &               REAL(W_F(idf)%W_V(iv)%hist_minmax(2),KIND=4))
       ENDIF
       iret = NF90_PUT_ATT (nfid,nvid,'long_name', &
- &                         TRIM(W_F(pfileid)%W_V(iv)%title))
+ &                         TRIM(W_F(idf)%W_V(iv)%title))
       iret = NF90_PUT_ATT (nfid,nvid,'online_operation', &
- &                         TRIM(W_F(pfileid)%W_V(iv)%fullop))
+ &                         TRIM(W_F(idf)%W_V(iv)%fullop))
 !-
       SELECT CASE(ndim)
@@ -1687,16 +1679,16 @@
       END SELECT
 !-
-      assoc=TRIM(W_F(pfileid)%hax_name(W_F(pfileid)%W_V(iv)%h_axid,2)) &
- &   //' '//TRIM(W_F(pfileid)%hax_name(W_F(pfileid)%W_V(iv)%h_axid,1))
-!-
-      ziv = W_F(pfileid)%W_V(iv)%z_axid
+      assoc=TRIM(W_F(idf)%hax_name(W_F(idf)%W_V(iv)%h_axid,2)) &
+ &   //' '//TRIM(W_F(idf)%hax_name(W_F(idf)%W_V(iv)%h_axid,1))
+!-
+      ziv = W_F(idf)%W_V(iv)%z_axid
       IF (ziv > 0) THEN
-        str30 = W_F(pfileid)%zax_name(ziv)
+        str30 = W_F(idf)%zax_name(ziv)
         assoc = TRIM(str30)//' '//TRIM(assoc)
       ENDIF
 !-
       IF (itax > 0) THEN
-        IF (W_F(pfileid)%n_tax > 1) THEN
-          str30 = "t_"//W_F(pfileid)%W_V(itax)%tax_name
+        IF (W_F(idf)%n_tax > 1) THEN
+          str30 = "t_"//W_F(idf)%W_V(itax)%tax_name
         ELSE
           str30 = "time_counter"
@@ -1706,11 +1698,11 @@
         IF (l_dbg) THEN
           WRITE(*,*) "histend : 2.0.n, freq_opp, freq_wrt", &
- &          W_F(pfileid)%W_V(iv)%freq_opp,W_F(pfileid)%W_V(iv)%freq_wrt
+ &          W_F(idf)%W_V(iv)%freq_opp,W_F(idf)%W_V(iv)%freq_wrt
         ENDIF
 !-
         iret = NF90_PUT_ATT (nfid,nvid,'interval_operation', &
- &                           REAL(W_F(pfileid)%W_V(iv)%freq_opp,KIND=4))
+ &                           REAL(W_F(idf)%W_V(iv)%freq_opp,KIND=4))
         iret = NF90_PUT_ATT (nfid,nvid,'interval_write', &
- &                           REAL(W_F(pfileid)%W_V(iv)%freq_wrt,KIND=4))
+ &                           REAL(W_F(idf)%W_V(iv)%freq_wrt,KIND=4))
       ENDIF
       iret = NF90_PUT_ATT (nfid,nvid,'coordinates',TRIM(assoc))
@@ -1720,6 +1712,6 @@
 ! 2.2 Add DOMAIN attributes if needed
 !-
-  IF (W_F(pfileid)%dom_id_svg >= 0) THEN
-    CALL flio_dom_att (nfid,W_F(pfileid)%dom_id_svg)
+  IF (W_F(idf)%dom_id_svg >= 0) THEN
+    CALL flio_dom_att (nfid,W_F(idf)%dom_id_svg)
   ENDIF
 !-
@@ -1734,54 +1726,54 @@
   IF (l_dbg) WRITE(*,*) "histend : 4.0"
 !-
-  WRITE(str70,'("All variables have been initialized on file :",I3)') pfileid
+  WRITE(str70,'("All variables have been initialized on file :",I3)') idf
   CALL ipslerr (1,'histend',str70,'',' ')
 !---------------------
 END SUBROUTINE histend
 !===
-SUBROUTINE histwrite_r1d (pfileid,pvarname,pitau,pdata,nbindex,nindex)
+SUBROUTINE histwrite_r1d (idf,pvarname,pitau,pdata,nbindex,nindex)
 !---------------------------------------------------------------------
   IMPLICIT NONE
 !-
-  INTEGER,INTENT(IN) :: pfileid,pitau,nbindex
+  INTEGER,INTENT(IN) :: idf,pitau,nbindex
   INTEGER,DIMENSION(nbindex),INTENT(IN) :: nindex
   REAL,DIMENSION(:),INTENT(IN) :: pdata
   CHARACTER(LEN=*),INTENT(IN) :: pvarname
 !---------------------------------------------------------------------
-  CALL histw_rnd (pfileid,pvarname,pitau,nbindex,nindex,pdata_1d=pdata)
+  CALL histw_rnd (idf,pvarname,pitau,nbindex,nindex,pdata_1d=pdata)
 !---------------------------
 END SUBROUTINE histwrite_r1d
 !===
-SUBROUTINE histwrite_r2d (pfileid,pvarname,pitau,pdata,nbindex,nindex)
+SUBROUTINE histwrite_r2d (idf,pvarname,pitau,pdata,nbindex,nindex)
 !---------------------------------------------------------------------
   IMPLICIT NONE
 !-
-  INTEGER,INTENT(IN) :: pfileid,pitau,nbindex
+  INTEGER,INTENT(IN) :: idf,pitau,nbindex
   INTEGER,DIMENSION(nbindex),INTENT(IN) :: nindex
   REAL,DIMENSION(:,:),INTENT(IN) :: pdata
   CHARACTER(LEN=*),INTENT(IN) :: pvarname
 !---------------------------------------------------------------------
-  CALL histw_rnd (pfileid,pvarname,pitau,nbindex,nindex,pdata_2d=pdata)
+  CALL histw_rnd (idf,pvarname,pitau,nbindex,nindex,pdata_2d=pdata)
 !---------------------------
 END SUBROUTINE histwrite_r2d
 !===
-SUBROUTINE histwrite_r3d (pfileid,pvarname,pitau,pdata,nbindex,nindex)
+SUBROUTINE histwrite_r3d (idf,pvarname,pitau,pdata,nbindex,nindex)
 !---------------------------------------------------------------------
   IMPLICIT NONE
 !-
-  INTEGER,INTENT(IN) :: pfileid,pitau,nbindex
+  INTEGER,INTENT(IN) :: idf,pitau,nbindex
   INTEGER,DIMENSION(nbindex),INTENT(IN) :: nindex
   REAL,DIMENSION(:,:,:),INTENT(IN) :: pdata
   CHARACTER(LEN=*),INTENT(IN) :: pvarname
 !---------------------------------------------------------------------
-  CALL histw_rnd (pfileid,pvarname,pitau,nbindex,nindex,pdata_3d=pdata)
+  CALL histw_rnd (idf,pvarname,pitau,nbindex,nindex,pdata_3d=pdata)
 !---------------------------
 END SUBROUTINE histwrite_r3d
 !===
-SUBROUTINE histw_rnd (pfileid,pvarname,pitau,nbindex,nindex, &
+SUBROUTINE histw_rnd (idf,pvarname,pitau,nbindex,nindex, &
   &                   pdata_1d,pdata_2d,pdata_3d)
 !---------------------------------------------------------------------
   IMPLICIT NONE
 !-
-  INTEGER,INTENT(IN) :: pfileid,pitau,nbindex
+  INTEGER,INTENT(IN) :: idf,pitau,nbindex
   INTEGER,DIMENSION(nbindex),INTENT(IN) :: nindex
   CHARACTER(LEN=*),INTENT(IN) :: pvarname
@@ -1791,10 +1783,9 @@
 !-
   LOGICAL :: do_oper,do_write,largebuf,l1d,l2d,l3d
-  INTEGER :: varid,io,nbpt_out
+  INTEGER :: iv,io,nbpt_out
   INTEGER              :: nbpt_in1
   INTEGER,DIMENSION(2) :: nbpt_in2
   INTEGER,DIMENSION(3) :: nbpt_in3
-  REAL,ALLOCATABLE,DIMENSION(:),SAVE :: buff_tmp
-  INTEGER,SAVE :: buff_tmp_sz
+  REAL,ALLOCATABLE,DIMENSION(:),SAVE :: tbf_1
   CHARACTER(LEN=7) :: tmp_opp
   CHARACTER(LEN=13) :: c_nam
@@ -1815,5 +1806,5 @@
 !     Thanks Marine for showing us what errors users can make !
 !-
-  IF ( (pfileid < 1).OR.(pfileid > nb_files) ) THEN
+  IF ( (idf < 1).OR.(idf > nb_files) ) THEN
     CALL ipslerr (3,"histwrite", &
  &    'Illegal file ID in the histwrite of variable',pvarname,' ')
@@ -1822,18 +1813,18 @@
 ! 1.1 Find the id of the variable to be written and the real time
 !-
-  CALL histvar_seq (pfileid,pvarname,varid)
+  CALL histvar_seq (idf,pvarname,iv)
 !-
 ! 2.0 do nothing for never operation
 !-
-  tmp_opp = W_F(pfileid)%W_V(varid)%topp
+  tmp_opp = W_F(idf)%W_V(iv)%topp
 !-
   IF (TRIM(tmp_opp) == "never") THEN
-    W_F(pfileid)%W_V(varid)%last_opp_chk = -99
-    W_F(pfileid)%W_V(varid)%last_wrt_chk = -99
+    W_F(idf)%W_V(iv)%last_opp_chk = -99
+    W_F(idf)%W_V(iv)%last_wrt_chk = -99
   ENDIF
 !-
 ! 3.0 We check if we need to do an operation
 !-
-  IF (W_F(pfileid)%W_V(varid)%last_opp_chk == pitau) THEN
+  IF (W_F(idf)%W_V(iv)%last_opp_chk == pitau) THEN
     CALL ipslerr (3,"histwrite", &
  &    'This variable has already been analysed at the present', &
@@ -1842,12 +1833,12 @@
 !-
   CALL isittime &
- &  (pitau,W_F(pfileid)%date0,W_F(pfileid)%deltat, &
- &   W_F(pfileid)%W_V(varid)%freq_opp, &
- &   W_F(pfileid)%W_V(varid)%last_opp, &
- &   W_F(pfileid)%W_V(varid)%last_opp_chk,do_oper)
+ &  (pitau,W_F(idf)%date0,W_F(idf)%deltat, &
+ &   W_F(idf)%W_V(iv)%freq_opp, &
+ &   W_F(idf)%W_V(iv)%last_opp, &
+ &   W_F(idf)%W_V(iv)%last_opp_chk,do_oper)
 !-
 ! 4.0 We check if we need to write the data
 !-
-  IF (W_F(pfileid)%W_V(varid)%last_wrt_chk == pitau) THEN
+  IF (W_F(idf)%W_V(iv)%last_wrt_chk == pitau) THEN
     CALL ipslerr (3,"histwrite", &
  &    'This variable as already been written for the present', &
@@ -1856,8 +1847,8 @@
 !-
   CALL isittime &
- &  (pitau,W_F(pfileid)%date0,W_F(pfileid)%deltat, &
- &   W_F(pfileid)%W_V(varid)%freq_wrt, &
- &   W_F(pfileid)%W_V(varid)%last_wrt, &
- &   W_F(pfileid)%W_V(varid)%last_wrt_chk,do_write)
+ &  (pitau,W_F(idf)%date0,W_F(idf)%deltat, &
+ &   W_F(idf)%W_V(iv)%freq_wrt, &
+ &   W_F(idf)%W_V(iv)%last_wrt, &
+ &   W_F(idf)%W_V(iv)%last_wrt_chk,do_write)
 !-
 ! 5.0 histwrite called
@@ -1867,19 +1858,19 @@
 !-- 5.1 Get the sizes of the data we will handle
 !-
-    IF (W_F(pfileid)%W_V(varid)%datasz_in(1) <= 0) THEN
+    IF (W_F(idf)%W_V(iv)%datasz_in(1) <= 0) THEN
 !---- There is the risk here that the user has over-sized the array.
 !---- But how can we catch this ?
 !---- In the worst case we will do impossible operations
 !---- on part of the data !
-      W_F(pfileid)%W_V(varid)%datasz_in(1:3) = -1
+      W_F(idf)%W_V(iv)%datasz_in(1:3) = -1
       IF      (l1d) THEN
-        W_F(pfileid)%W_V(varid)%datasz_in(1) = SIZE(pdata_1d)
+        W_F(idf)%W_V(iv)%datasz_in(1) = SIZE(pdata_1d)
       ELSE IF (l2d) THEN
-        W_F(pfileid)%W_V(varid)%datasz_in(1) = SIZE(pdata_2d,DIM=1)
-        W_F(pfileid)%W_V(varid)%datasz_in(2) = SIZE(pdata_2d,DIM=2)
+        W_F(idf)%W_V(iv)%datasz_in(1) = SIZE(pdata_2d,DIM=1)
+        W_F(idf)%W_V(iv)%datasz_in(2) = SIZE(pdata_2d,DIM=2)
       ELSE IF (l3d) THEN
-        W_F(pfileid)%W_V(varid)%datasz_in(1) = SIZE(pdata_3d,DIM=1)
-        W_F(pfileid)%W_V(varid)%datasz_in(2) = SIZE(pdata_3d,DIM=2)
-        W_F(pfileid)%W_V(varid)%datasz_in(3) = SIZE(pdata_3d,DIM=3)
+        W_F(idf)%W_V(iv)%datasz_in(1) = SIZE(pdata_3d,DIM=1)
+        W_F(idf)%W_V(iv)%datasz_in(2) = SIZE(pdata_3d,DIM=2)
+        W_F(idf)%W_V(iv)%datasz_in(3) = SIZE(pdata_3d,DIM=3)
       ENDIF
     ENDIF
@@ -1887,50 +1878,48 @@
 !-- 5.2 The maximum size of the data will give the size of the buffer
 !-
-    IF (W_F(pfileid)%W_V(varid)%datasz_max <= 0) THEN
+    IF (W_F(idf)%W_V(iv)%datasz_max <= 0) THEN
       largebuf = .FALSE.
-      DO io=1,W_F(pfileid)%W_V(varid)%nbopp
-        IF (INDEX(fuchnbout,W_F(pfileid)%W_V(varid)%sopp(io)) > 0) THEN
+      DO io=1,W_F(idf)%W_V(iv)%nbopp
+        IF (INDEX(fuchnbout,W_F(idf)%W_V(iv)%sopp(io)) > 0) THEN
           largebuf = .TRUE.
         ENDIF
       ENDDO
       IF (largebuf) THEN
-        W_F(pfileid)%W_V(varid)%datasz_max = &
- &        W_F(pfileid)%W_V(varid)%scsize(1) &
- &       *W_F(pfileid)%W_V(varid)%scsize(2) &
- &       *W_F(pfileid)%W_V(varid)%scsize(3)
+        W_F(idf)%W_V(iv)%datasz_max = &
+ &        W_F(idf)%W_V(iv)%scsize(1) &
+ &       *W_F(idf)%W_V(iv)%scsize(2) &
+ &       *W_F(idf)%W_V(iv)%scsize(3)
       ELSE
         IF      (l1d) THEN
-          W_F(pfileid)%W_V(varid)%datasz_max = &
- &          W_F(pfileid)%W_V(varid)%datasz_in(1)
+          W_F(idf)%W_V(iv)%datasz_max = &
+ &          W_F(idf)%W_V(iv)%datasz_in(1)
         ELSE IF (l2d) THEN
-          W_F(pfileid)%W_V(varid)%datasz_max = &
- &          W_F(pfileid)%W_V(varid)%datasz_in(1) &
- &         *W_F(pfileid)%W_V(varid)%datasz_in(2)
+          W_F(idf)%W_V(iv)%datasz_max = &
+ &          W_F(idf)%W_V(iv)%datasz_in(1) &
+ &         *W_F(idf)%W_V(iv)%datasz_in(2)
         ELSE IF (l3d) THEN
-          W_F(pfileid)%W_V(varid)%datasz_max = &
- &          W_F(pfileid)%W_V(varid)%datasz_in(1) &
- &         *W_F(pfileid)%W_V(varid)%datasz_in(2) &
- &         *W_F(pfileid)%W_V(varid)%datasz_in(3)
+          W_F(idf)%W_V(iv)%datasz_max = &
+ &          W_F(idf)%W_V(iv)%datasz_in(1) &
+ &         *W_F(idf)%W_V(iv)%datasz_in(2) &
+ &         *W_F(idf)%W_V(iv)%datasz_in(3)
         ENDIF
       ENDIF
     ENDIF
 !-
-    IF (.NOT.ALLOCATED(buff_tmp)) THEN
+    IF (.NOT.ALLOCATED(tbf_1)) THEN
       IF (l_dbg) THEN
         WRITE(*,*) &
- &       c_nam//" : allocate buff_tmp for buff_sz = ", &
- &       W_F(pfileid)%W_V(varid)%datasz_max
+ &       c_nam//" : allocate tbf_1 for size = ", &
+ &       W_F(idf)%W_V(iv)%datasz_max
       ENDIF
-      ALLOCATE(buff_tmp(W_F(pfileid)%W_V(varid)%datasz_max))
-      buff_tmp_sz = W_F(pfileid)%W_V(varid)%datasz_max
-    ELSE IF (W_F(pfileid)%W_V(varid)%datasz_max > buff_tmp_sz) THEN
+      ALLOCATE(tbf_1(W_F(idf)%W_V(iv)%datasz_max))
+    ELSE IF (W_F(idf)%W_V(iv)%datasz_max > SIZE(tbf_1)) THEN
       IF (l_dbg) THEN
         WRITE(*,*) &
- &       c_nam//" : re-allocate buff_tmp for buff_sz = ", &
- &       W_F(pfileid)%W_V(varid)%datasz_max
+ &       c_nam//" : re-allocate tbf_1 for size = ", &
+ &       W_F(idf)%W_V(iv)%datasz_max
       ENDIF
-      DEALLOCATE(buff_tmp)
-      ALLOCATE(buff_tmp(W_F(pfileid)%W_V(varid)%datasz_max))
-      buff_tmp_sz = W_F(pfileid)%W_V(varid)%datasz_max
+      DEALLOCATE(tbf_1)
+      ALLOCATE(tbf_1(W_F(idf)%W_V(iv)%datasz_max))
     ENDIF
 !-
@@ -1939,23 +1928,23 @@
 !-- of the data at the same time. This should speed up things.
 !-
-    nbpt_out = W_F(pfileid)%W_V(varid)%datasz_max
+    nbpt_out = W_F(idf)%W_V(iv)%datasz_max
     IF      (l1d) THEN
-      nbpt_in1 = W_F(pfileid)%W_V(varid)%datasz_in(1)
-      CALL mathop (W_F(pfileid)%W_V(varid)%sopp(1),nbpt_in1,pdata_1d, &
+      nbpt_in1 = W_F(idf)%W_V(iv)%datasz_in(1)
+      CALL mathop (W_F(idf)%W_V(iv)%sopp(1),nbpt_in1,pdata_1d, &
  &                 missing_val,nbindex,nindex, &
- &                 W_F(pfileid)%W_V(varid)%scal(1),nbpt_out,buff_tmp)
+ &                 W_F(idf)%W_V(iv)%scal(1),nbpt_out,tbf_1)
     ELSE IF (l2d) THEN
-      nbpt_in2(1:2) = W_F(pfileid)%W_V(varid)%datasz_in(1:2)
-      CALL mathop (W_F(pfileid)%W_V(varid)%sopp(1),nbpt_in2,pdata_2d, &
+      nbpt_in2(1:2) = W_F(idf)%W_V(iv)%datasz_in(1:2)
+      CALL mathop (W_F(idf)%W_V(iv)%sopp(1),nbpt_in2,pdata_2d, &
  &                 missing_val,nbindex,nindex, &
- &                 W_F(pfileid)%W_V(varid)%scal(1),nbpt_out,buff_tmp)
+ &                 W_F(idf)%W_V(iv)%scal(1),nbpt_out,tbf_1)
     ELSE IF (l3d) THEN
-      nbpt_in3(1:3) = W_F(pfileid)%W_V(varid)%datasz_in(1:3)
-      CALL mathop (W_F(pfileid)%W_V(varid)%sopp(1),nbpt_in3,pdata_3d, &
+      nbpt_in3(1:3) = W_F(idf)%W_V(iv)%datasz_in(1:3)
+      CALL mathop (W_F(idf)%W_V(iv)%sopp(1),nbpt_in3,pdata_3d, &
  &                 missing_val,nbindex,nindex, &
- &                 W_F(pfileid)%W_V(varid)%scal(1),nbpt_out,buff_tmp)
-    ENDIF
-    CALL histwrite_real (pfileid,varid,pitau,nbpt_out, &
- &            buff_tmp,nbindex,nindex,do_oper,do_write)
+ &                 W_F(idf)%W_V(iv)%scal(1),nbpt_out,tbf_1)
+    ENDIF
+    CALL histwrite_real (idf,iv,pitau,nbpt_out, &
+ &            tbf_1,nbindex,nindex,do_oper,do_write)
   ENDIF
 !-
@@ -1963,9 +1952,9 @@
 !-
   IF ((TRIM(tmp_opp) /= "once").AND.(TRIM(tmp_opp) /= "never")) THEN
-    W_F(pfileid)%W_V(varid)%last_opp_chk = pitau
-    W_F(pfileid)%W_V(varid)%last_wrt_chk = pitau
-  ELSE
-    W_F(pfileid)%W_V(varid)%last_opp_chk = -99
-    W_F(pfileid)%W_V(varid)%last_wrt_chk = -99
+    W_F(idf)%W_V(iv)%last_opp_chk = pitau
+    W_F(idf)%W_V(iv)%last_wrt_chk = pitau
+  ELSE
+    W_F(idf)%W_V(iv)%last_opp_chk = -99
+    W_F(idf)%W_V(iv)%last_wrt_chk = -99
   ENDIF
 !-----------------------
@@ -1973,5 +1962,5 @@
 !===
 SUBROUTINE histwrite_real &
- & (pfileid,varid,pitau,nbdpt,buff_tmp,nbindex,nindex,do_oper,do_write)
+ & (idf,iv,pitau,nbdpt,tbf_1,nbindex,nindex,do_oper,do_write)
 !---------------------------------------------------------------------
 !- This subroutine is internal and does the calculations and writing
@@ -1981,10 +1970,10 @@
   IMPLICIT NONE
 !-
-  INTEGER,INTENT(IN) :: pfileid,pitau,varid, &
+  INTEGER,INTENT(IN) :: idf,pitau,iv, &
  &                      nbindex,nindex(nbindex),nbdpt
-  REAL,DIMENSION(:)  :: buff_tmp
+  REAL,DIMENSION(:)  :: tbf_1
   LOGICAL,INTENT(IN) :: do_oper,do_write
 !-
-  INTEGER :: tsz,nfid,nvid,i,iret,ipt,itax,io,nbin,nbout
+  INTEGER :: tsz,nfid,nvid,iret,itax,io,nbin,nbout
   INTEGER :: nx,ny,nz,ky,kz,kt,kc
   INTEGER,DIMENSION(4) :: corner,edges
@@ -1993,6 +1982,5 @@
   REAL :: rtime
   CHARACTER(LEN=7) :: tmp_opp
-  REAL,ALLOCATABLE,DIMENSION(:),SAVE :: buff_tmp2,buffer_used
-  INTEGER,SAVE :: buff_tmp2_sz,buffer_sz
+  REAL,ALLOCATABLE,DIMENSION(:),SAVE :: tbf_2
   LOGICAL :: l_dbg
 !---------------------------------------------------------------------
@@ -2000,5 +1988,5 @@
 !-
   IF (l_dbg) THEN
-    WRITE(*,*) "histwrite 0.0 : VAR : ",W_F(pfileid)%W_V(varid)%v_name
+    WRITE(*,*) "histwrite 0.0 : VAR : ",W_F(idf)%W_V(iv)%v_name
     WRITE(*,*) "histwrite 0.0 : nbindex,nindex :", &
  &  nbindex,nindex(1:MIN(3,nbindex)),'...',nindex(MAX(1,nbindex-3):nbindex)
@@ -2007,73 +1995,38 @@
 ! The sizes which can be encoutered
 !-
-  tsz =  W_F(pfileid)%W_V(varid)%zsize(1) &
- &      *W_F(pfileid)%W_V(varid)%zsize(2) &
- &      *W_F(pfileid)%W_V(varid)%zsize(3)
-!-
-! 1.0 We allocate the memory needed to store the data between write
-!     and the temporary space needed for operations.
-!     We have to keep precedent buffer if needed
-!-
-  IF (.NOT. ALLOCATED(buffer)) THEN
-    IF (l_dbg) WRITE(*,*) "histwrite_real 1.0 allocate buffer ",buff_pos
-    ALLOCATE(buffer(buff_pos))
-    buffer_sz = buff_pos
-    buffer(:)=0.0
-  ELSE IF (buffer_sz < buff_pos) THEN
+  tsz =  W_F(idf)%W_V(iv)%zsize(1) &
+ &      *W_F(idf)%W_V(iv)%zsize(2) &
+ &      *W_F(idf)%W_V(iv)%zsize(3)
+!-
+! 1.0 We allocate and the temporary space needed for operations.
+!     The buffers are only deallocated when more space is needed.
+!     This reduces the umber of allocates but increases memory needs.
+!-
+  IF (.NOT.ALLOCATED(tbf_2)) THEN
     IF (l_dbg) THEN
-      WRITE(*,*) "histwrite_real 1.0.1 re-allocate buffer for ", &
- &      buff_pos," instead of ",SIZE(buffer)
-    ENDIF
-    IF (SUM(buffer)/=0.0) THEN
-      IF (l_dbg) WRITE (*,*) 'histwrite : buffer has been used. ', &
- &      'We have to save it before re-allocating.'
-      ALLOCATE(buffer_used(buffer_sz))
-      buffer_used(:)=buffer(:)
-      DEALLOCATE(buffer)
-      ALLOCATE(buffer(buff_pos))
-      buffer_sz = buff_pos
-      buffer(:)=0.0
-      buffer(:SIZE(buffer_used))=buffer_used
-      DEALLOCATE(buffer_used)
-    ELSE
-      IF (l_dbg) WRITE (*,*) 'histwrite : buffer has not been used. ', &
- &      'We have just to re-allocate it.'
-      DEALLOCATE(buffer)
-      ALLOCATE(buffer(buff_pos))
-      buffer_sz = buff_pos
-      buffer(:)=0.0
-    ENDIF
-  ENDIF
-!-
-! The buffers are only deallocated when more space is needed. This
-! reduces the umber of allocates but increases memory needs.
-!-
-  IF (.NOT.ALLOCATED(buff_tmp2)) THEN
+      WRITE(*,*) "histwrite_real 1.1 allocate tbf_2 ",SIZE(tbf_1)
+    ENDIF
+    ALLOCATE(tbf_2(W_F(idf)%W_V(iv)%datasz_max))
+  ELSE IF (W_F(idf)%W_V(iv)%datasz_max > SIZE(tbf_2)) THEN
     IF (l_dbg) THEN
-      WRITE(*,*) "histwrite_real 1.1 allocate buff_tmp2 ",SIZE(buff_tmp)
-    ENDIF
-    ALLOCATE(buff_tmp2(W_F(pfileid)%W_V(varid)%datasz_max))
-    buff_tmp2_sz = W_F(pfileid)%W_V(varid)%datasz_max
-  ELSE IF (W_F(pfileid)%W_V(varid)%datasz_max > buff_tmp2_sz) THEN
-    IF (l_dbg) THEN
-      WRITE(*,*) "histwrite_real 1.2 re-allocate buff_tmp2 : ", &
-     & SIZE(buff_tmp)," instead of ",SIZE(buff_tmp2)
-    ENDIF
-    DEALLOCATE(buff_tmp2)
-    ALLOCATE(buff_tmp2(W_F(pfileid)%W_V(varid)%datasz_max))
-    buff_tmp2_sz = W_F(pfileid)%W_V(varid)%datasz_max
-  ENDIF
-!-
-  rtime = pitau*W_F(pfileid)%deltat
-  tmp_opp = W_F(pfileid)%W_V(varid)%topp
-!-
-! 3.0 Do the operations or transfer the slab of data into buff_tmp
-!-
-  IF (l_dbg) WRITE(*,*) "histwrite: 3.0",pfileid
+      WRITE(*,*) "histwrite_real 1.2 re-allocate tbf_2 : ", &
+     & SIZE(tbf_1)," instead of ",SIZE(tbf_2)
+    ENDIF
+    DEALLOCATE(tbf_2)
+    ALLOCATE(tbf_2(W_F(idf)%W_V(iv)%datasz_max))
+  ENDIF
+!-
+  rtime = pitau*W_F(idf)%deltat
+  tmp_opp = W_F(idf)%W_V(iv)%topp
+!-
+! 3.0 Do the operations or transfer the slab of data into tbf_1
+!-
+  IF (l_dbg) THEN
+    WRITE(*,*) "histwrite: 3.0",idf
+  ENDIF
 !-
 ! 3.1 DO the Operations only if needed
 !-
   IF (do_oper) THEN
-    i = pfileid
     nbout = nbdpt
 !-
@@ -2081,23 +2034,23 @@
 !--     we started in the interface routine
 !-
-    DO io=2,W_F(i)%W_V(varid)%nbopp,2
+    DO io=2,W_F(idf)%W_V(iv)%nbopp,2
       nbin = nbout
-      nbout = W_F(i)%W_V(varid)%datasz_max
-      CALL mathop(W_F(i)%W_V(varid)%sopp(io),nbin,buff_tmp, &
- &      missing_val,nbindex,nindex,W_F(i)%W_V(varid)%scal(io), &
- &      nbout,buff_tmp2)
+      nbout = W_F(idf)%W_V(iv)%datasz_max
+      CALL mathop(W_F(idf)%W_V(iv)%sopp(io),nbin,tbf_1, &
+ &      missing_val,nbindex,nindex,W_F(idf)%W_V(iv)%scal(io), &
+ &      nbout,tbf_2)
       IF (l_dbg) THEN
         WRITE(*,*) &
- &       "histwrite: 3.4a nbout : ",nbin,nbout,W_F(i)%W_V(varid)%sopp(io)
+ &       "histwrite: 3.4a nbout : ",nbin,nbout,W_F(idf)%W_V(iv)%sopp(io)
       ENDIF
 !-
       nbin = nbout
-      nbout = W_F(i)%W_V(varid)%datasz_max
-      CALL mathop(W_F(i)%W_V(varid)%sopp(io+1),nbin,buff_tmp2, &
- &      missing_val,nbindex,nindex,W_F(i)%W_V(varid)%scal(io+1), &
- &      nbout,buff_tmp)
+      nbout = W_F(idf)%W_V(iv)%datasz_max
+      CALL mathop(W_F(idf)%W_V(iv)%sopp(io+1),nbin,tbf_2, &
+ &      missing_val,nbindex,nindex,W_F(idf)%W_V(iv)%scal(io+1), &
+ &      nbout,tbf_1)
       IF (l_dbg) THEN
         WRITE(*,*) &
- &     "histwrite: 3.4b nbout : ",nbin,nbout,W_F(i)%W_V(varid)%sopp(io+1)
+ &     "histwrite: 3.4b nbout : ",nbin,nbout,W_F(idf)%W_V(iv)%sopp(io+1)
       ENDIF
     ENDDO
@@ -2107,88 +2060,88 @@
     IF (l_dbg) THEN
       WRITE(*,*) &
- &     "histwrite: 3.5 size(buff_tmp) : ",SIZE(buff_tmp)
+ &     "histwrite: 3.5 size(tbf_1) : ",SIZE(tbf_1)
       WRITE(*,*) &
  &     "histwrite: 3.5 slab in X :", &
- &     W_F(i)%W_V(varid)%zorig(1),W_F(i)%W_V(varid)%zsize(1)
+ &     W_F(idf)%W_V(iv)%zorig(1),W_F(idf)%W_V(iv)%zsize(1)
       WRITE(*,*) &
  &     "histwrite: 3.5 slab in Y :", &
- &     W_F(i)%W_V(varid)%zorig(2),W_F(i)%W_V(varid)%zsize(2)
+ &     W_F(idf)%W_V(iv)%zorig(2),W_F(idf)%W_V(iv)%zsize(2)
       WRITE(*,*) &
  &     "histwrite: 3.5 slab in Z :", &
- &     W_F(i)%W_V(varid)%zorig(3),W_F(i)%W_V(varid)%zsize(3)
+ &     W_F(idf)%W_V(iv)%zorig(3),W_F(idf)%W_V(iv)%zsize(3)
       WRITE(*,*) &
  &     "histwrite: 3.5 slab of input:", &
- &     W_F(i)%W_V(varid)%scsize(1), &
- &     W_F(i)%W_V(varid)%scsize(2), &
- &     W_F(i)%W_V(varid)%scsize(3)
+ &     W_F(idf)%W_V(iv)%scsize(1), &
+ &     W_F(idf)%W_V(iv)%scsize(2), &
+ &     W_F(idf)%W_V(iv)%scsize(3)
     ENDIF
 !---
 !-- We have to consider blocks of contiguous data
 !---
-    nx=MAX(W_F(i)%W_V(varid)%zsize(1),1)
-    ny=MAX(W_F(i)%W_V(varid)%zsize(2),1)
-    nz=MAX(W_F(i)%W_V(varid)%zsize(3),1)
-    IF     (     (W_F(i)%W_V(varid)%zorig(1) == 1) &
- &          .AND.(   W_F(i)%W_V(varid)%zsize(1) &
- &                == W_F(i)%W_V(varid)%scsize(1)) &
- &          .AND.(W_F(i)%W_V(varid)%zorig(2) == 1) &
- &          .AND.(   W_F(i)%W_V(varid)%zsize(2) &
- &                == W_F(i)%W_V(varid)%scsize(2))) THEN
-      kt = (W_F(i)%W_V(varid)%zorig(3)-1)*nx*ny
-      buff_tmp2(1:nx*ny*nz) = buff_tmp(kt+1:kt+nx*ny*nz)
-    ELSEIF (     (W_F(i)%W_V(varid)%zorig(1) == 1) &
- &          .AND.(   W_F(i)%W_V(varid)%zsize(1) &
- &                == W_F(i)%W_V(varid)%scsize(1))) THEN
+    nx=MAX(W_F(idf)%W_V(iv)%zsize(1),1)
+    ny=MAX(W_F(idf)%W_V(iv)%zsize(2),1)
+    nz=MAX(W_F(idf)%W_V(iv)%zsize(3),1)
+    IF     (     (W_F(idf)%W_V(iv)%zorig(1) == 1) &
+ &          .AND.(   W_F(idf)%W_V(iv)%zsize(1) &
+ &                == W_F(idf)%W_V(iv)%scsize(1)) &
+ &          .AND.(W_F(idf)%W_V(iv)%zorig(2) == 1) &
+ &          .AND.(   W_F(idf)%W_V(iv)%zsize(2) &
+ &                == W_F(idf)%W_V(iv)%scsize(2))) THEN
+      kt = (W_F(idf)%W_V(iv)%zorig(3)-1)*nx*ny
+      tbf_2(1:nx*ny*nz) = tbf_1(kt+1:kt+nx*ny*nz)
+    ELSEIF (     (W_F(idf)%W_V(iv)%zorig(1) == 1) &
+ &          .AND.(   W_F(idf)%W_V(iv)%zsize(1) &
+ &                == W_F(idf)%W_V(iv)%scsize(1))) THEN
       kc = -nx*ny
-      DO kz=W_F(i)%W_V(varid)%zorig(3),W_F(i)%W_V(varid)%zorig(3)+nz-1
+      DO kz=W_F(idf)%W_V(iv)%zorig(3),W_F(idf)%W_V(iv)%zorig(3)+nz-1
         kc = kc+nx*ny
-        kt = ( (kz-1)*W_F(i)%W_V(varid)%scsize(2) &
- &            +W_F(i)%W_V(varid)%zorig(2)-1)*nx
-        buff_tmp2(kc+1:kc+nx*ny) = buff_tmp(kt+1:kt+nx*ny)
+        kt = ( (kz-1)*W_F(idf)%W_V(iv)%scsize(2) &
+ &            +W_F(idf)%W_V(iv)%zorig(2)-1)*nx
+        tbf_2(kc+1:kc+nx*ny) = tbf_1(kt+1:kt+nx*ny)
       ENDDO
     ELSE
       kc = -nx
-      DO kz=W_F(i)%W_V(varid)%zorig(3),W_F(i)%W_V(varid)%zorig(3)+nz-1
-        DO ky=W_F(i)%W_V(varid)%zorig(2),W_F(i)%W_V(varid)%zorig(2)+ny-1
+      DO kz=W_F(idf)%W_V(iv)%zorig(3),W_F(idf)%W_V(iv)%zorig(3)+nz-1
+        DO ky=W_F(idf)%W_V(iv)%zorig(2),W_F(idf)%W_V(iv)%zorig(2)+ny-1
           kc = kc+nx
-          kt = ((kz-1)*W_F(i)%W_V(varid)%scsize(2)+ky-1) &
- &            *W_F(i)%W_V(varid)%scsize(1) &
- &            +W_F(i)%W_V(varid)%zorig(1)-1
-          buff_tmp2(kc+1:kc+nx) = buff_tmp(kt+1:kt+nx)
+          kt = ((kz-1)*W_F(idf)%W_V(iv)%scsize(2)+ky-1) &
+ &            *W_F(idf)%W_V(iv)%scsize(1) &
+ &            +W_F(idf)%W_V(iv)%zorig(1)-1
+          tbf_2(kc+1:kc+nx) = tbf_1(kt+1:kt+nx)
         ENDDO
       ENDDO
     ENDIF
 !-
-!-- 4.0 Get the min and max of the field (buff_tmp)
-!-
-    IF (l_dbg) WRITE(*,*) "histwrite: 4.0 buff_tmp",pfileid,varid, &
- &    TRIM(tmp_opp),' ---- ',LEN_TRIM(tmp_opp),nbindex
-!-
-    IF (W_F(pfileid)%W_V(varid)%hist_calc_rng) THEN
-      W_F(pfileid)%W_V(varid)%hist_minmax(1) = &
- &      MIN(W_F(pfileid)%W_V(varid)%hist_minmax(1), &
- &      MINVAL(buff_tmp2(1:tsz),MASK=buff_tmp2(1:tsz) /= missing_val))
-      W_F(pfileid)%W_V(varid)%hist_minmax(2) = &
- &      MAX(W_F(pfileid)%W_V(varid)%hist_minmax(2), &
- &      MAXVAL(buff_tmp2(1:tsz),MASK=buff_tmp2(1:tsz) /= missing_val))
+!-- 4.0 Get the min and max of the field
+!-
+    IF (l_dbg) THEN
+      WRITE(*,*) "histwrite: 4.0 tbf_1",idf,iv, &
+ &      TRIM(tmp_opp),' ---- ',LEN_TRIM(tmp_opp),nbindex
+    ENDIF
+!-
+    IF (W_F(idf)%W_V(iv)%hist_calc_rng) THEN
+      W_F(idf)%W_V(iv)%hist_minmax(1) = &
+ &      MIN(W_F(idf)%W_V(iv)%hist_minmax(1), &
+ &      MINVAL(tbf_2(1:tsz),MASK=tbf_2(1:tsz) /= missing_val))
+      W_F(idf)%W_V(iv)%hist_minmax(2) = &
+ &      MAX(W_F(idf)%W_V(iv)%hist_minmax(2), &
+ &      MAXVAL(tbf_2(1:tsz),MASK=tbf_2(1:tsz) /= missing_val))
     ENDIF
 !-
 !-- 5.0 Do the operations if needed. In the case of instantaneous
-!--     output we do not transfer to the buffer.
-!-
-    IF (l_dbg) WRITE(*,*) "histwrite: 5.0",pfileid,"tsz :",tsz
-!-
-    ipt = W_F(pfileid)%W_V(varid)%point
-!-
-!   WRITE(*,*) 'OPE ipt, buffer :',pvarname,ipt,varid
+!--     output we do not transfer to the time_buffer.
+!-
+    IF (l_dbg) THEN
+      WRITE(*,*) "histwrite: 5.0 idf : ",idf," iv : ",iv," tsz : ",tsz
+    ENDIF
 !-
     IF (     (TRIM(tmp_opp) /= "inst") &
  &      .AND.(TRIM(tmp_opp) /= "once") ) THEN
-      CALL moycum(tmp_opp,tsz,buffer(ipt:), &
- &           buff_tmp2,W_F(pfileid)%W_V(varid)%nb_opp)
-    ENDIF
-!-
-    W_F(pfileid)%W_V(varid)%last_opp = pitau
-    W_F(pfileid)%W_V(varid)%nb_opp = W_F(pfileid)%W_V(varid)%nb_opp+1
+      CALL moycum(tmp_opp,tsz,W_F(idf)%W_V(iv)%t_bf, &
+ &           tbf_2,W_F(idf)%W_V(iv)%nb_opp)
+    ENDIF
+!-
+    W_F(idf)%W_V(iv)%last_opp = pitau
+    W_F(idf)%W_V(iv)%nb_opp = W_F(idf)%W_V(iv)%nb_opp+1
 !-
   ENDIF
@@ -2196,19 +2149,18 @@
 ! 6.0 Write to file if needed
 !-
-  IF (l_dbg) WRITE(*,*) "histwrite: 6.0",pfileid
+  IF (l_dbg) WRITE(*,*) "histwrite: 6.0",idf
 !-
   IF (do_write) THEN
 !-
-    nfid = W_F(pfileid)%ncfid
-    nvid = W_F(pfileid)%W_V(varid)%ncvid
+    nfid = W_F(idf)%ncfid
+    nvid = W_F(idf)%W_V(iv)%ncvid
 !-
 !-- 6.1 Do the operations that are needed before writting
 !-
-    IF (l_dbg) WRITE(*,*) "histwrite: 6.1",pfileid
+    IF (l_dbg) WRITE(*,*) "histwrite: 6.1",idf
 !-
     IF (     (TRIM(tmp_opp) /= "inst") &
  &      .AND.(TRIM(tmp_opp) /= "once") ) THEN
-      rtime = ( rtime &
- &             +W_F(pfileid)%W_V(varid)%last_wrt*W_F(pfileid)%deltat)/2.0
+      rtime = (rtime+W_F(idf)%W_V(iv)%last_wrt*W_F(idf)%deltat)/2.0
     ENDIF
 !-
@@ -2219,13 +2171,13 @@
  &      .AND.(TRIM(tmp_opp) /= "once") ) THEN
 !-
-      IF (l_dbg) WRITE(*,*) "histwrite: 6.2",pfileid
-!-
-      itax = W_F(pfileid)%W_V(varid)%t_axid
-      itime = W_F(pfileid)%W_V(varid)%nb_wrt+1
-!-
-      IF (W_F(pfileid)%W_V(itax)%tax_last < itime) THEN
-        iret = NF90_PUT_VAR (nfid,W_F(pfileid)%W_V(itax)%tdimid, &
+      IF (l_dbg) WRITE(*,*) "histwrite: 6.2",idf
+!-
+      itax  = W_F(idf)%W_V(iv)%t_axid
+      itime = W_F(idf)%W_V(iv)%nb_wrt+1
+!-
+      IF (W_F(idf)%W_V(itax)%tax_last < itime) THEN
+        iret = NF90_PUT_VAR (nfid,W_F(idf)%W_V(itax)%tdimid, &
  &               (/ rtime /),start=(/ itime /),count=(/ 1 /))
-        W_F(pfileid)%W_V(itax)%tax_last = itime
+        W_F(idf)%W_V(itax)%tax_last = itime
       ENDIF
     ELSE
@@ -2237,43 +2189,41 @@
 !-
     IF (l_dbg) THEN
-      WRITE(*,*) "histwrite: 6.3",pfileid,nfid,nvid,varid,itime
-    ENDIF
-!-
-    IF (W_F(pfileid)%W_V(varid)%scsize(3) == 1) THEN
-      IF (W_F(pfileid)%regular) THEN
+      WRITE(*,*) "histwrite: 6.3",idf,nfid,nvid,iv,itime
+    ENDIF
+!-
+    IF (W_F(idf)%W_V(iv)%scsize(3) == 1) THEN
+      IF (W_F(idf)%regular) THEN
         corner(1:4) = (/ 1,1,itime,0 /)
-        edges(1:4) = (/ W_F(pfileid)%W_V(varid)%zsize(1), &
- &                      W_F(pfileid)%W_V(varid)%zsize(2),1,0 /)
+        edges(1:4) = (/ W_F(idf)%W_V(iv)%zsize(1), &
+ &                      W_F(idf)%W_V(iv)%zsize(2),1,0 /)
       ELSE
         corner(1:4) = (/ 1,itime,0,0 /)
-        edges(1:4) = (/ W_F(pfileid)%W_V(varid)%zsize(1),1,0,0 /)
+        edges(1:4) = (/ W_F(idf)%W_V(iv)%zsize(1),1,0,0 /)
       ENDIF
     ELSE
-      IF (W_F(pfileid)%regular) THEN
+      IF (W_F(idf)%regular) THEN
         corner(1:4) = (/ 1,1,1,itime /)
-        edges(1:4) = (/ W_F(pfileid)%W_V(varid)%zsize(1), &
- &                      W_F(pfileid)%W_V(varid)%zsize(2), &
- &                      W_F(pfileid)%W_V(varid)%zsize(3),1 /)
+        edges(1:4) = (/ W_F(idf)%W_V(iv)%zsize(1), &
+ &                      W_F(idf)%W_V(iv)%zsize(2), &
+ &                      W_F(idf)%W_V(iv)%zsize(3),1 /)
       ELSE
         corner(1:4) = (/ 1,1,itime,0 /)
-        edges(1:4) = (/ W_F(pfileid)%W_V(varid)%zsize(1), &
- &                      W_F(pfileid)%W_V(varid)%zsize(3),1,0 /)
+        edges(1:4) = (/ W_F(idf)%W_V(iv)%zsize(1), &
+ &                      W_F(idf)%W_V(iv)%zsize(3),1,0 /)
       ENDIF
     ENDIF
-!-
-    ipt = W_F(pfileid)%W_V(varid)%point
 !-
     IF (     (TRIM(tmp_opp) /= "inst") &
  &      .AND.(TRIM(tmp_opp) /= "once") ) THEN
-      iret = NF90_PUT_VAR (nfid,nvid,buffer(ipt:), &
- &                       start=corner(1:4),count=edges(1:4))
+      iret = NF90_PUT_VAR (nfid,nvid,W_F(idf)%W_V(iv)%t_bf, &
+ &                         start=corner(1:4),count=edges(1:4))
     ELSE
-      iret = NF90_PUT_VAR (nfid,nvid,buff_tmp2, &
- &                       start=corner(1:4),count=edges(1:4))
-    ENDIF
-!-
-    W_F(pfileid)%W_V(varid)%last_wrt = pitau
-    W_F(pfileid)%W_V(varid)%nb_wrt = W_F(pfileid)%W_V(varid)%nb_wrt+1
-    W_F(pfileid)%W_V(varid)%nb_opp = 0
+      iret = NF90_PUT_VAR (nfid,nvid,tbf_2, &
+ &                         start=corner(1:4),count=edges(1:4))
+    ENDIF
+!-
+    W_F(idf)%W_V(iv)%last_wrt = pitau
+    W_F(idf)%W_V(iv)%nb_wrt = W_F(idf)%W_V(iv)%nb_wrt+1
+    W_F(idf)%W_V(iv)%nb_opp = 0
 !---
 !   After the write the file can be synchronized so that no data is
@@ -2288,7 +2238,7 @@
 END SUBROUTINE histwrite_real
 !===
-SUBROUTINE histvar_seq (pfid,pvarname,pvid)
-!---------------------------------------------------------------------
-!- This subroutine optimized the search for the variable in the table.
+SUBROUTINE histvar_seq (idf,pvarname,idv)
+!---------------------------------------------------------------------
+!- This subroutine optimize the search for the variable in the table.
 !- In a first phase it will learn the succession of the variables
 !- called and then it will use the table to guess what comes next.
@@ -2298,13 +2248,13 @@
 !- ARGUMENTS :
 !-
-!- pfid  : id of the file on which we work
+!- idf      : id of the file on which we work
 !- pvarname : The name of the variable we are looking for
-!- pvid     : The var id we found
+!- idv      : The var id we found
 !---------------------------------------------------------------------
   IMPLICIT NONE
 !-
-  INTEGER,INTENT(in)  :: pfid
+  INTEGER,INTENT(in)  :: idf
   CHARACTER(LEN=*),INTENT(IN) :: pvarname
-  INTEGER,INTENT(out) :: pvid
+  INTEGER,INTENT(out) :: idv
 !-
   LOGICAL,SAVE :: learning(nb_files_max)=.TRUE.
@@ -2321,17 +2271,17 @@
 !-
   IF (l_dbg) THEN
-    WRITE(*,*) 'histvar_seq, start of the subroutine :',learning(pfid)
-  ENDIF
-!-
-  IF (learning(pfid)) THEN
+    WRITE(*,*) 'histvar_seq, start of the subroutine :',learning(idf)
+  ENDIF
+!-
+  IF (learning(idf)) THEN
 !-
 !-- 1.0 We compute the length over which we are going
 !--     to check the overlap
 !-
-    IF (overlap(pfid) <= 0) THEN
-      IF (W_F(pfid)%n_var > 6) THEN
-        overlap(pfid) = W_F(pfid)%n_var/3*2
+    IF (overlap(idf) <= 0) THEN
+      IF (W_F(idf)%n_var > 6) THEN
+        overlap(idf) = W_F(idf)%n_var/3*2
       ELSE
-        overlap(pfid) = W_F(pfid)%n_var
+        overlap(idf) = W_F(idf)%n_var
       ENDIF
     ENDIF
@@ -2339,7 +2289,7 @@
 !-- 1.1 Find the position of this string
 !-
-    CALL find_str (W_F(pfid)%W_V(1:W_F(pfid)%n_var)%v_name,pvarname,pos)
+    CALL find_str (W_F(idf)%W_V(1:W_F(idf)%n_var)%v_name,pvarname,pos)
     IF (pos > 0) THEN
-      pvid = pos
+      idv = pos
     ELSE
       CALL ipslerr (3,"histvar_seq", &
@@ -2352,9 +2302,9 @@
 !--     in the sequence of calls
 !-
-    IF (varseq_err(pfid) >= 0) THEN
-      sp = varseq_len(pfid)+1
+    IF (varseq_err(idf) >= 0) THEN
+      sp = varseq_len(idf)+1
       IF (sp <= nb_var_max*3) THEN
-        varseq(pfid,sp) = pvid
-        varseq_len(pfid) = sp
+        varseq(idf,sp) = idv
+        varseq_len(idf) = sp
       ELSE
         CALL ipslerr (2,"histvar_seq",&
@@ -2366,24 +2316,24 @@
  &       ' contact the IOIPSL team. ')
         WRITE(*,*) 'The sequence we have found up to now :'
-        WRITE(*,*) varseq(pfid,1:sp-1)
-        varseq_err(pfid) = -1
+        WRITE(*,*) varseq(idf,1:sp-1)
+        varseq_err(idf) = -1
       ENDIF
 !-
 !---- 1.3 Check if we have found the right overlap
 !-
-      IF (varseq_len(pfid) >= overlap(pfid)*2) THEN
+      IF (varseq_len(idf) >= overlap(idf)*2) THEN
 !-
 !------ We skip a few variables if needed as they could come
 !------ from the initialisation of the model.
 !-
-        DO ib = 0,sp-overlap(pfid)*2
-          IF ( learning(pfid) .AND.&
-            & SUM(ABS(varseq(pfid,ib+1:ib+overlap(pfid)) -&
-            & varseq(pfid,sp-overlap(pfid)+1:sp))) == 0 ) THEN
-            learning(pfid) = .FALSE.
-            varseq_len(pfid) = sp-overlap(pfid)-ib
-            varseq_pos(pfid) = overlap(pfid)+ib
-            varseq(pfid,1:varseq_len(pfid)) = &
- &            varseq(pfid,ib+1:ib+varseq_len(pfid))
+        DO ib = 0,sp-overlap(idf)*2
+          IF ( learning(idf) .AND.&
+            & SUM(ABS(varseq(idf,ib+1:ib+overlap(idf)) -&
+            & varseq(idf,sp-overlap(idf)+1:sp))) == 0 ) THEN
+            learning(idf) = .FALSE.
+            varseq_len(idf) = sp-overlap(idf)-ib
+            varseq_pos(idf) = overlap(idf)+ib
+            varseq(idf,1:varseq_len(idf)) = &
+ &            varseq(idf,ib+1:ib+varseq_len(idf))
           ENDIF
         ENDDO
@@ -2395,13 +2345,13 @@
 !--     and we can get a guess at the var ID
 !-
-    nn = varseq_pos(pfid)+1
-    IF (nn > varseq_len(pfid)) nn = 1
-!-
-    pvid = varseq(pfid,nn)
-!-
-    IF (TRIM(W_F(pfid)%W_V(pvid)%v_name) /= TRIM(pvarname)) THEN
-      CALL find_str (W_F(pfid)%W_V(1:W_F(pfid)%n_var)%v_name,pvarname,pos)
+    nn = varseq_pos(idf)+1
+    IF (nn > varseq_len(idf)) nn = 1
+!-
+    idv = varseq(idf,nn)
+!-
+    IF (TRIM(W_F(idf)%W_V(idv)%v_name) /= TRIM(pvarname)) THEN
+      CALL find_str (W_F(idf)%W_V(1:W_F(idf)%n_var)%v_name,pvarname,pos)
       IF (pos > 0) THEN
-        pvid = pos
+        idv = pos
       ELSE
         CALL ipslerr (3,"histvar_seq", &
@@ -2410,5 +2360,5 @@
  &  TRIM(pvarname))
       ENDIF
-      varseq_err(pfid) = varseq_err(pfid)+1
+      varseq_err(idf) = varseq_err(idf)+1
     ELSE
 !-
@@ -2417,13 +2367,13 @@
 !---- not defeat the process.
 !-
-      varseq_pos(pfid) = nn
-    ENDIF
-!-
-    IF (varseq_err(pfid) >= 10) THEN
-      WRITE(str70,'("for file ",I3)') pfid
+      varseq_pos(idf) = nn
+    ENDIF
+!-
+    IF (varseq_err(idf) >= 10) THEN
+      WRITE(str70,'("for file ",I3)') idf
       CALL ipslerr (2,"histvar_seq", &
  &  'There were 10 errors in the learned sequence of variables',&
  &  str70,'This looks like a bug, please report it.')
-         varseq_err(pfid) = 0
+         varseq_err(idf) = 0
     ENDIF
   ENDIF
@@ -2431,5 +2381,5 @@
   IF (l_dbg) THEN
     WRITE(*,*) &
- &   'histvar_seq, end of the subroutine :',TRIM(pvarname),pvid
+ &   'histvar_seq, end of the subroutine :',TRIM(pvarname),idv
   ENDIF
 !-------------------------
@@ -2480,5 +2430,5 @@
 END SUBROUTINE histsync
 !===
-SUBROUTINE histclo (fid)
+SUBROUTINE histclo (idf)
 !---------------------------------------------------------------------
 !- This subroutine will close all (or one if defined) opened files
@@ -2489,6 +2439,6 @@
   IMPLICIT NONE
 !-
-! fid  : optional argument for fileid
-  INTEGER,INTENT(in),OPTIONAL :: fid
+! idf  : optional argument for fileid
+  INTEGER,INTENT(in),OPTIONAL :: idf
 !-
   INTEGER :: ifile,nfid,nvid,iret,iv
@@ -2501,7 +2451,7 @@
   IF (l_dbg) WRITE(*,*) 'Entering loop on files :',nb_files
 !-
-  IF (PRESENT(fid)) THEN
-    start_loop = fid
-    end_loop = fid
+  IF (PRESENT(idf)) THEN
+    start_loop = idf
+    end_loop = idf
   ELSE
     start_loop = 1
