Index: IOIPSL/trunk/src/fliocom.f90
===================================================================
--- IOIPSL/trunk/src/fliocom.f90	(revision 759)
+++ IOIPSL/trunk/src/fliocom.f90	(revision 760)
@@ -883,5 +883,7 @@
   IF (PRESENT(mode)) THEN
     SELECT CASE (TRIM(mode))
-    CASE('REPLACE','REP','REP32')
+    CASE('REPLACE','REP','REP64')
+      m_c = IOR(NF90_CLOBBER,NF90_64BIT_OFFSET)
+    CASE('REP32')
       m_c = NF90_CLOBBER
     CASE('32')
@@ -889,11 +891,9 @@
     CASE('64')
       m_c = IOR(NF90_NOCLOBBER,NF90_64BIT_OFFSET)
-    CASE('REP64')
-      m_c = IOR(NF90_CLOBBER,NF90_64BIT_OFFSET)
     CASE DEFAULT
-      m_c = NF90_NOCLOBBER
+      m_c = IOR(NF90_NOCLOBBER,NF90_64BIT_OFFSET)
     END SELECT
   ELSE
-    m_c = NF90_NOCLOBBER
+    m_c = IOR(NF90_NOCLOBBER,NF90_64BIT_OFFSET)
   ENDIF
 !-
Index: IOIPSL/trunk/src/histcom.f90
===================================================================
--- IOIPSL/trunk/src/histcom.f90	(revision 759)
+++ IOIPSL/trunk/src/histcom.f90	(revision 760)
@@ -35,4 +35,13 @@
 !- to describe the grid, just two vectors.
 !---------------------------------------------------------------------
+!-
+  INTERFACE histbeg
+    MODULE PROCEDURE histbeg_totreg,histbeg_regular,histbeg_irregular
+  END INTERFACE
+!-
+  INTERFACE histhori
+    MODULE PROCEDURE histhori_regular,histhori_irregular
+  END INTERFACE
+!-
   INTERFACE histwrite
 !---------------------------------------------------------------------
@@ -63,12 +72,4 @@
   END INTERFACE
 !-
-  INTERFACE histbeg
-    MODULE PROCEDURE histbeg_totreg,histbeg_regular,histbeg_irregular
-  END INTERFACE
-!-
-  INTERFACE histhori
-    MODULE PROCEDURE histhori_regular,histhori_irregular
-  END INTERFACE
-!-
 ! Fixed parameter
 !-
@@ -79,69 +80,71 @@
  &  hist_r4=nf90_real4, hist_r8=nf90_real8
 !-
-  INTEGER :: bufftmp_max(nb_files_max) = 1
-!-
-! Time variables
-!-
-  INTEGER,SAVE :: itau0(nb_files_max)=0
-  REAL,DIMENSION(nb_files_max),SAVE ::date0,deltat
+! Variable derived type
+!-
+TYPE T_D_V
+  INTEGER :: ncvid
+  INTEGER :: nbopp
+  CHARACTER(LEN=20) :: v_name,unit_name
+  CHARACTER(LEN=80) :: title,fullop
+  CHARACTER(LEN=7)  :: topp
+  CHARACTER(LEN=7),DIMENSION(nbopp_max) :: sopps
+  REAL,DIMENSION(nbopp_max) :: scal
+!-External type (for R4/R8)
+  INTEGER :: v_typ
+!-Sizes of the associated grid and zommed area
+  INTEGER,DIMENSION(3) :: scsize,zorig,zsize
+!-Sizes for the data as it goes through the various math operations
+  INTEGER,DIMENSION(3) :: datasz_in = -1
+  INTEGER :: datasz_max = -1
+!-
+  INTEGER :: h_axid,z_axid,t_axid
+!-
+  REAL,DIMENSION(2) :: hist_minmax
+  LOGICAL :: hist_calc_rng=.FALSE.,hist_wrt_rng=.FALSE.
+!-Book keeping of the axes
+  INTEGER :: tdimid,tax_last
+  CHARACTER(LEN=40) :: tax_name
+!-
+  REAL :: freq_opp,freq_wrt
+  INTEGER :: &
+ &  last_opp,last_wrt,last_opp_chk,last_wrt_chk,nb_opp,nb_wrt,point
+!- For future optimization
+!#  REAL,ALLOCATABLE,DIMENSION(:) :: V_1_D
+!#  REAL,ALLOCATABLE,DIMENSION(:,:) :: V_2_D
+!#  REAL,ALLOCATABLE,DIMENSION(:,:,:) :: V_3_D
+END TYPE T_D_V
+!-
+! File derived type
+!-
+TYPE :: T_D_F
+!-NETCDF IDs for file
+  INTEGER :: ncfid
+!-Time variables
+  INTEGER :: itau0=0
+  REAL :: date0,deltat
+!-Counter of elements (variables, time-horizontal-vertical axis
+  INTEGER :: n_var=0,n_tax=0,n_hax=0,n_zax=0
+!-NETCDF dimension IDs for time-longitude-latitude
+  INTEGER :: tid,xid,yid
+!-General definitions in the NETCDF file
+  INTEGER,DIMENSION(2) :: full_size=0,slab_ori,slab_sz
+!-The horizontal axes
+  CHARACTER(LEN=25),DIMENSION(nb_hax_max,2) :: hax_name
+!-The vertical axes
+  INTEGER,DIMENSION(nb_zax_max) :: zax_size,zax_ids
+  CHARACTER(LEN=20),DIMENSION(nb_zax_max) :: zax_name
+!-
+  LOGICAL :: regular=.TRUE.
+!-DOMAIN ID
+  INTEGER :: dom_id_svg=-1
+!-
+  TYPE(T_D_V),DIMENSION(nb_var_max) :: W_V
+END TYPE T_D_F
+!-
+TYPE(T_D_F),DIMENSION(nb_files_max),SAVE :: W_F
 !-
 ! Counter of elements
 !-
   INTEGER,SAVE :: nb_files=0
-  INTEGER,DIMENSION(nb_files_max),SAVE :: nb_var=0,nb_tax=0
-!-
-! DOMAIN IDs for files
-!-
-  INTEGER,DIMENSION(nb_files_max),SAVE :: dom_id_svg=-1
-!-
-! NETCDF IDs for files and axes
-!-
-  INTEGER,DIMENSION(nb_files_max),SAVE :: ncdf_ids,xid,yid,tid
-!-
-! General definitions in the NETCDF file
-!-
-  INTEGER,DIMENSION(nb_files_max,2),SAVE :: &
- &   full_size=0,slab_ori,slab_sz
-!-
-! The horizontal axes
-!-
-  INTEGER,SAVE :: nb_hax(nb_files_max)=0
-  CHARACTER(LEN=25),SAVE :: hax_name(nb_files_max,nb_hax_max,2)
-!-
-! The vertical axes
-!-
-  INTEGER,SAVE :: nb_zax(nb_files_max)=0
-  INTEGER,DIMENSION(nb_files_max,nb_zax_max),SAVE :: &
-  &  zax_size,zax_ids
-  CHARACTER(LEN=20),SAVE :: zax_name(nb_files_max,nb_zax_max)
-!-
-! Informations on each variable
-!-
-  INTEGER,DIMENSION(nb_files_max,nb_var_max),SAVE :: v_typ
-  CHARACTER(LEN=20),DIMENSION(nb_files_max,nb_var_max),SAVE :: &
- &  name,unit_name
-  CHARACTER(LEN=80),DIMENSION(nb_files_max,nb_var_max),SAVE :: &
- &  title,fullop
-  CHARACTER(LEN=7),SAVE :: topp(nb_files_max,nb_var_max)
-  CHARACTER(LEN=7),SAVE :: sopps(nb_files_max,nb_var_max,nbopp_max)
-  REAL,SAVE :: scal(nb_files_max,nb_var_max,nbopp_max)
-!- Sizes of the associated grid and zommed area
-  INTEGER,DIMENSION(nb_files_max,nb_var_max,3),SAVE :: &
- &   scsize,zorig,zsize
-!- Sizes for the data as it goes through the various math operations
-  INTEGER,SAVE :: datasz_in(nb_files_max,nb_var_max,3) = -1
-  INTEGER,SAVE :: datasz_max(nb_files_max,nb_var_max) = -1
-!-
-  INTEGER,DIMENSION(nb_files_max,nb_var_max),SAVE :: &
- &  var_haxid,var_zaxid,var_axid,ncvar_ids
-!-
-  REAL,DIMENSION(nb_files_max,nb_var_max,2),SAVE :: hist_minmax
-  LOGICAL,DIMENSION(nb_files_max,nb_var_max),SAVE :: &
- &  hist_calc_rng=.FALSE.,hist_wrt_rng=.FALSE.
-!-
-  REAL,DIMENSION(nb_files_max,nb_var_max),SAVE :: &
- &  freq_opp,freq_wrt
-  INTEGER,DIMENSION(nb_files_max,nb_var_max),SAVE :: &
- &  nbopp,last_opp,last_wrt,last_opp_chk,last_wrt_chk,nb_opp,nb_wrt,point
 !-
 ! Book keeping for the buffers
@@ -149,12 +152,4 @@
   INTEGER,SAVE :: buff_pos=0
   REAL,ALLOCATABLE,DIMENSION(:),SAVE :: buffer
-  LOGICAL,DIMENSION(nb_files_max),SAVE :: zoom=.FALSE.,regular=.TRUE.
-!-
-! Book keeping of the axes
-!-
-  INTEGER,DIMENSION(nb_files_max,nb_var_max),SAVE :: &
- &  tdimid,tax_last
-  CHARACTER(LEN=40),DIMENSION(nb_files_max,nb_var_max),SAVE :: &
- &  tax_name
 !-
 ! A list of functions which require special action
@@ -162,7 +157,5 @@
 !  but they are well located here)
 !-
-  CHARACTER(LEN=120),SAVE :: &
- &  indchfun = 'scatter, fill, gather, coll', &
- &  fuchnbout = 'scatter, fill'
+  CHARACTER(LEN=30),SAVE :: fuchnbout = 'scatter, fill'
 !- Some configurable variables with locks
   CHARACTER(LEN=80),SAVE :: model_name='An IPSL model'
@@ -176,5 +169,5 @@
  & (pfilename,pim,plon,pjm,plat,          &
  &  par_orix,par_szx,par_oriy,par_szy,    &
- &  pitau0,pdate0,pdeltat,phoriid,pfileid,domain_id)
+ &  pitau0,pdate0,pdeltat,phoriid,pfileid,domain_id,nb_bits)
 !---------------------------------------------------------------------
 !- This is just an interface for histbeg_regular in case when
@@ -202,5 +195,5 @@
 !- pitau0    : time step at which the history tape starts
 !- pdate0    : The Julian date at which the itau was equal to 0
-!- pdeltat   : Time step in seconds. Time step of the counter itau
+!- pdeltat   : Time step, in seconds, of the counter itau
 !-             used in histwrite for instance
 !-
@@ -235,5 +228,5 @@
   REAL,INTENT(IN) :: pdate0,pdeltat
   INTEGER,INTENT(OUT) :: pfileid,phoriid
-  INTEGER,INTENT(IN),OPTIONAL :: domain_id
+  INTEGER,INTENT(IN),OPTIONAL :: domain_id,nb_bits
 !-
   REAL,ALLOCATABLE,DIMENSION(:,:) :: lon_tmp,lat_tmp
@@ -253,5 +246,5 @@
  &   par_orix,par_szx,par_oriy,par_szy, &
  &   pitau0,pdate0,pdeltat,phoriid,pfileid, &
- &   .TRUE.,domain_id)
+ &   .TRUE.,domain_id,nb_bits)
 !-
   DEALLOCATE(lon_tmp,lat_tmp)
@@ -263,5 +256,5 @@
  &  par_orix,par_szx,par_oriy,par_szy,     &
  &  pitau0,pdate0,pdeltat,phoriid,pfileid, &
- &  opt_rectilinear,domain_id)
+ &  opt_rectilinear,domain_id,nb_bits)
 !---------------------------------------------------------------------
 !- This subroutine initializes a netcdf file and returns the ID.
@@ -290,5 +283,5 @@
 !- pitau0    : time step at which the history tape starts
 !- pdate0    : The Julian date at which the itau was equal to 0
-!- pdeltat   : Time step in seconds. Time step of the counter itau
+!- pdeltat   : Time step, in seconds, of the counter itau
 !-             used in histwrite for instance
 !-
@@ -324,7 +317,7 @@
   INTEGER,INTENT(OUT) :: pfileid,phoriid
   LOGICAL,INTENT(IN),OPTIONAL :: opt_rectilinear
-  INTEGER,INTENT(IN),OPTIONAL :: domain_id
-!-
-  INTEGER :: ncid,iret
+  INTEGER,INTENT(IN),OPTIONAL :: domain_id,nb_bits
+!-
+  INTEGER :: nfid,iret,m_c
   CHARACTER(LEN=120) :: file
   CHARACTER(LEN=30) :: timenow
@@ -334,25 +327,7 @@
   CALL ipsldbg (old_status=l_dbg)
 !-
+  IF (l_dbg) WRITE(*,*) "histbeg_regular 0.0"
+!-
   nb_files = nb_files+1
-  pfileid  = nb_files
-!-
-! 1.0 Transfering into the common for future use
-!-
-  IF (l_dbg) WRITE(*,*) "histbeg_regular 1.0"
-!-
-  itau0(pfileid) = pitau0
-  date0(pfileid) = pdate0
-  deltat(pfileid) = pdeltat
-!-
-  IF (PRESENT(opt_rectilinear)) THEN
-    rectilinear = opt_rectilinear
-  ELSE
-    rectilinear = .FALSE.
-  ENDIF
-!-
-! 2.0 Initializes all variables for this file
-!-
-  IF (l_dbg) WRITE(*,*) "histbeg_regular 2.0"
-!-
   IF (nb_files > nb_files_max) THEN
     CALL ipslerr (3,"histbeg", &
@@ -360,12 +335,31 @@
    &  'in histcom.f90 in order to accomodate all these files',' ')
   ENDIF
-!-
-  nb_var(pfileid) = 0
-  nb_tax(pfileid) = 0
-  nb_hax(pfileid) = 0
-  nb_zax(pfileid) = 0
-!-
-  slab_ori(pfileid,1:2) = (/ par_orix,par_oriy /)
-  slab_sz(pfileid,1:2)  = (/ par_szx, par_szy  /)
+  pfileid  = nb_files
+!-
+! 1.0 Transfering into the common for future use
+!-
+  IF (l_dbg) WRITE(*,*) "histbeg_regular 1.0"
+!-
+  W_F(pfileid)%itau0  = pitau0
+  W_F(pfileid)%date0  = pdate0
+  W_F(pfileid)%deltat = pdeltat
+!-
+  IF (PRESENT(opt_rectilinear)) THEN
+    rectilinear = opt_rectilinear
+  ELSE
+    rectilinear = .FALSE.
+  ENDIF
+!-
+! 2.0 Initializes all variables for this file
+!-
+  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  /)
 !-
 ! 3.0 Opening netcdf file and defining dimensions
@@ -378,12 +372,29 @@
   CALL flio_dom_file (file,domain_id)
 !-
-  iret = NF90_CREATE (file,NF90_CLOBBER,ncid)
+! Check the mode
+  IF (PRESENT(nb_bits)) THEN
+    SELECT CASE (nb_bits)
+    CASE(32)
+      m_c = NF90_CLOBBER
+    CASE(64)
+      m_c = IOR(NF90_CLOBBER,NF90_64BIT_OFFSET)
+    CASE DEFAULT
+      CALL ipslerr (3,"histbeg", &
+ &      'Invalid argument nb_bits for file :',TRIM(file), &
+ &      'Supported values are 32 or 64')
+    END SELECT
+  ELSE
+    m_c = IOR(NF90_CLOBBER,NF90_64BIT_OFFSET)
+  ENDIF
+!-
+! Create file
+  iret = NF90_CREATE (file,m_c,nfid)
 !-
   IF (rectilinear) THEN
-    iret = NF90_DEF_DIM (ncid,'lon',par_szx,xid(nb_files))
-    iret = NF90_DEF_DIM (ncid,'lat',par_szy,yid(nb_files))
-  ELSE
-    iret = NF90_DEF_DIM (ncid,'x',par_szx,xid(nb_files))
-    iret = NF90_DEF_DIM (ncid,'y',par_szy,yid(nb_files))
+    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)
   ENDIF
 !-
@@ -394,10 +405,10 @@
 ! 4.3 Global attributes
 !-
-  iret = NF90_PUT_ATT (ncid,NF90_GLOBAL,'Conventions','CF-1.1')
-  iret = NF90_PUT_ATT (ncid,NF90_GLOBAL,'file_name',TRIM(file))
-  iret = NF90_PUT_ATT (ncid,NF90_GLOBAL,'production',TRIM(model_name))
+  iret = NF90_PUT_ATT (nfid,NF90_GLOBAL,'Conventions','CF-1.1')
+  iret = NF90_PUT_ATT (nfid,NF90_GLOBAL,'file_name',TRIM(file))
+  iret = NF90_PUT_ATT (nfid,NF90_GLOBAL,'production',TRIM(model_name))
   lock_modname = .TRUE.
   CALL ioget_timestamp (timenow)
-  iret = NF90_PUT_ATT (ncid,NF90_GLOBAL,'TimeStamp',TRIM(timenow))
+  iret = NF90_PUT_ATT (nfid,NF90_GLOBAL,'TimeStamp',TRIM(timenow))
 !-
 ! 5.0 Saving some important information on this file in the common
@@ -406,16 +417,15 @@
 !-
   IF (PRESENT(domain_id)) THEN
-    dom_id_svg(pfileid) = domain_id
-  ENDIF
-  ncdf_ids(pfileid) = ncid
-  full_size(pfileid,1:2) = (/ pim,pjm /)
+    W_F(pfileid)%dom_id_svg = domain_id
+  ENDIF
+  W_F(pfileid)%ncfid = nfid
+  W_F(pfileid)%full_size(1:2) = (/ pim,pjm /)
 !-
 ! 6.0 storing the geographical coordinates
 !-
-  zoom(pfileid) = (pim /= par_szx).OR.(pjm /= par_szy)
-  regular(pfileid)=.TRUE.
+  W_F(pfileid)%regular=.TRUE.
 !-
   CALL histhori_regular (pfileid,pim,plon,pjm,plat, &
- &  ' ' ,'Default grid',phoriid,rectilinear)
+ &  ' ','Default grid',phoriid,rectilinear)
 !-----------------------------
 END SUBROUTINE histbeg_regular
@@ -423,5 +433,5 @@
 SUBROUTINE histbeg_irregular &
  &  (pfilename,pim,plon,plon_bounds,plat,plat_bounds,   &
- &   pitau0,pdate0,pdeltat,phoriid,pfileid,domain_id)
+ &   pitau0,pdate0,pdeltat,phoriid,pfileid,domain_id,nb_bits)
 !---------------------------------------------------------------------
 !- This subroutine initializes a netcdf file and returns the ID.
@@ -442,5 +452,5 @@
 !- pitau0    : time step at which the history tape starts
 !- pdate0    : The Julian date at which the itau was equal to 0
-!- pdeltat   : Time step in seconds. Time step of the counter itau
+!- pdeltat   : Time step, in seconds, of the counter itau
 !-             used in histwrite for instance
 !-
@@ -474,7 +484,7 @@
   REAL,INTENT(IN) :: pdate0,pdeltat
   INTEGER,INTENT(OUT) :: pfileid,phoriid
-  INTEGER,INTENT(IN),OPTIONAL :: domain_id
-!-
-  INTEGER :: ncid,iret
+  INTEGER,INTENT(IN),OPTIONAL :: domain_id,nb_bits
+!-
+  INTEGER :: nfid,iret,m_c
   CHARACTER(LEN=120) :: file
   CHARACTER(LEN=30) :: timenow
@@ -483,32 +493,33 @@
   CALL ipsldbg (old_status=l_dbg)
 !-
+  IF (l_dbg) WRITE(*,*) "histbeg_irregular 0.0"
+!-
   nb_files = nb_files+1
-  pfileid  = nb_files
-!-
-! 1.0 Transfering into the common for future use
-!-
-  IF (l_dbg) WRITE(*,*) "histbeg_irregular 1.0"
-!-
-  itau0(pfileid) = pitau0
-  date0(pfileid) = pdate0
-  deltat(pfileid) = pdeltat
-!-
-! 2.0 Initializes all variables for this file
-!-
-  IF (l_dbg) WRITE(*,*) "histbeg_irregular 2.0"
-!-
   IF (nb_files > nb_files_max) THEN
     CALL ipslerr (3,"histbeg", &
-   &  'Table of files too small. You should increase nb_files_max', &
-   &  'in histcom.f90 in order to accomodate all these files',' ')
-  ENDIF
-!-
-  nb_var(pfileid) = 0
-  nb_tax(pfileid) = 0
-  nb_hax(pfileid) = 0
-  nb_zax(pfileid) = 0
-!-
-  slab_ori(pfileid,1:2) = (/ 1,1 /)
-  slab_sz(pfileid,1:2)  = (/ pim,1 /)
+ &    'Table of files too small. You should increase nb_files_max', &
+ &    'in histcom.f90 in order to accomodate all these files',' ')
+  ENDIF
+  pfileid  = nb_files
+!-
+! 1.0 Transfering into the common for future use
+!-
+  IF (l_dbg) WRITE(*,*) "histbeg_irregular 1.0"
+!-
+  W_F(pfileid)%itau0  = pitau0
+  W_F(pfileid)%date0  = pdate0
+  W_F(pfileid)%deltat = pdeltat
+!-
+! 2.0 Initializes all variables for this file
+!-
+  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 /)
 !-
 ! 3.0 Opening netcdf file and defining dimensions
@@ -521,8 +532,25 @@
   CALL flio_dom_file (file,domain_id)
 !-
-  iret = NF90_CREATE (file,NF90_CLOBBER,ncid)
-!-
-  iret = NF90_DEF_DIM (ncid,'x',pim,xid(nb_files))
-  yid(nb_files) = 0
+! Check the mode
+  IF (PRESENT(nb_bits)) THEN
+    SELECT CASE (nb_bits)
+    CASE(32)
+      m_c = NF90_CLOBBER
+    CASE(64)
+      m_c = IOR(NF90_CLOBBER,NF90_64BIT_OFFSET)
+    CASE DEFAULT
+      CALL ipslerr (3,"histbeg", &
+ &      'Invalid argument nb_bits for file :',TRIM(file), &
+ &      'Supported values are 32 or 64')
+    END SELECT
+  ELSE
+    m_c = IOR(NF90_CLOBBER,NF90_64BIT_OFFSET)
+  ENDIF
+!-
+! Create file
+  iret = NF90_CREATE (file,m_c,nfid)
+!-
+  iret = NF90_DEF_DIM (nfid,'x',pim,W_F(pfileid)%xid)
+  W_F(pfileid)%yid = 0
 !-
 ! 4.0 Declaring the geographical coordinates and other attributes
@@ -532,10 +560,10 @@
 ! 4.3 Global attributes
 !-
-  iret = NF90_PUT_ATT (ncid,NF90_GLOBAL,'Conventions','CF-1.1')
-  iret = NF90_PUT_ATT (ncid,NF90_GLOBAL,'file_name',TRIM(file))
-  iret = NF90_PUT_ATT (ncid,NF90_GLOBAL,'production',TRIM(model_name))
+  iret = NF90_PUT_ATT (nfid,NF90_GLOBAL,'Conventions','CF-1.1')
+  iret = NF90_PUT_ATT (nfid,NF90_GLOBAL,'file_name',TRIM(file))
+  iret = NF90_PUT_ATT (nfid,NF90_GLOBAL,'production',TRIM(model_name))
   lock_modname = .TRUE.
   CALL ioget_timestamp (timenow)
-  iret = NF90_PUT_ATT (ncid,NF90_GLOBAL,'TimeStamp',TRIM(timenow))
+  iret = NF90_PUT_ATT (nfid,NF90_GLOBAL,'TimeStamp',TRIM(timenow))
 !-
 ! 5.0 Saving some important information on this file in the common
@@ -544,17 +572,16 @@
 !-
   IF (PRESENT(domain_id)) THEN
-    dom_id_svg(pfileid) = domain_id
-  ENDIF
-  ncdf_ids(pfileid) = ncid
-  full_size(pfileid,1:2) = (/ pim,1 /)
+    W_F(pfileid)%dom_id_svg = domain_id
+  ENDIF
+  W_F(pfileid)%ncfid = nfid
+  W_F(pfileid)%full_size(1:2) = (/ pim,1 /)
 !-
 ! 6.0 storing the geographical coordinates
 !-
-  zoom(pfileid)=.FALSE.
-  regular(pfileid)=.FALSE.
+  W_F(pfileid)%regular=.FALSE.
 !-
   CALL histhori_irregular &
  &  (pfileid,pim,plon,plon_bounds,plat,plat_bounds, &
- &   ' ' ,'Default grid',phoriid)
+ &   ' ','Default grid',phoriid)
 !-------------------------------
 END SUBROUTINE histbeg_irregular
@@ -604,5 +631,5 @@
   INTEGER :: nlonid,nlatid
   INTEGER :: orix,oriy,par_szx,par_szy
-  INTEGER :: iret,ncid
+  INTEGER :: iret,nfid
   LOGICAL :: rectilinear
   LOGICAL :: l_dbg
@@ -612,10 +639,10 @@
 ! 1.0 Check that all fits in the buffers
 !-
-  IF (    (pim /= full_size(pfileid,1)) &
-    & .OR.(pjm /= full_size(pfileid,2)) ) THEN
+  IF (    (pim /= W_F(pfileid)%full_size(1)) &
+ &    .OR.(pjm /= W_F(pfileid)%full_size(2)) ) THEN
     CALL ipslerr (3,"histhori", &
-   &  'The new horizontal grid does not have the same size', &
-   &  'as the one provided to histbeg. This is not yet ', &
-   &  'possible in the hist package.')
+ &   'The new horizontal grid does not have the same size', &
+ &   'as the one provided to histbeg. This is not yet ', &
+ &   'possible in the hist package.')
   ENDIF
 !-
@@ -630,12 +657,12 @@
   IF (l_dbg) WRITE(*,*) "histhori_regular 1.0"
 !-
-  ncid = ncdf_ids(pfileid)
+  nfid = W_F(pfileid)%ncfid
 !-
   ndim = 2
-  dims(1:2) = (/ xid(pfileid),yid(pfileid) /)
+  dims(1:2) = (/ W_F(pfileid)%xid,W_F(pfileid)%yid /)
 !-
   tmp_name = phname
   IF (rectilinear) THEN
-    IF (nb_hax(pfileid) == 0) THEN
+    IF (W_F(pfileid)%n_hax == 0) THEN
       lon_name = 'lon'
       lat_name = 'lat'
@@ -645,5 +672,5 @@
     ENDIF
   ELSE
-    IF (nb_hax(pfileid) == 0) THEN
+    IF (W_F(pfileid)%n_hax == 0) THEN
       lon_name = 'nav_lon'
       lat_name = 'nav_lat'
@@ -656,8 +683,7 @@
 ! 1.2 Save the informations
 !-
-  phid =  nb_hax(pfileid)+1
-  nb_hax(pfileid) = phid
-!-
-  hax_name(pfileid,phid,1:2) = (/ lon_name,lat_name /)
+  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 /)
   tmp_title = phtitle
 !-
@@ -668,18 +694,18 @@
   IF (rectilinear) THEN
     ndim = 1
-    dims(1:1) = (/ xid(pfileid) /)
-  ENDIF
-  iret = NF90_DEF_VAR (ncid,lon_name,NF90_FLOAT,dims(1:ndim),nlonid)
+    dims(1:1) = (/ W_F(pfileid)%xid /)
+  ENDIF
+  iret = NF90_DEF_VAR (nfid,lon_name,NF90_FLOAT,dims(1:ndim),nlonid)
   IF (rectilinear) THEN
-    iret = NF90_PUT_ATT (ncid,nlonid,'axis',"X")
-  ENDIF
-  iret = NF90_PUT_ATT (ncid,nlonid,'standard_name',"longitude")
-  iret = NF90_PUT_ATT (ncid,nlonid,'units',"degrees_east")
-  iret = NF90_PUT_ATT (ncid,nlonid,'valid_min', &
+    iret = NF90_PUT_ATT (nfid,nlonid,'axis',"X")
+  ENDIF
+  iret = NF90_PUT_ATT (nfid,nlonid,'standard_name',"longitude")
+  iret = NF90_PUT_ATT (nfid,nlonid,'units',"degrees_east")
+  iret = NF90_PUT_ATT (nfid,nlonid,'valid_min', &
  &                     REAL(MINVAL(plon),KIND=4))
-  iret = NF90_PUT_ATT (ncid,nlonid,'valid_max', &
+  iret = NF90_PUT_ATT (nfid,nlonid,'valid_max', &
  &                     REAL(MAXVAL(plon),KIND=4))
-  iret = NF90_PUT_ATT (ncid,nlonid,'long_name',"Longitude")
-  iret = NF90_PUT_ATT (ncid,nlonid,'nav_model',TRIM(tmp_title))
+  iret = NF90_PUT_ATT (nfid,nlonid,'long_name',"Longitude")
+  iret = NF90_PUT_ATT (nfid,nlonid,'nav_model',TRIM(tmp_title))
 !-
 ! 3.0 Latitude
@@ -689,20 +715,20 @@
   IF (rectilinear) THEN
     ndim = 1
-    dims(1:1) = (/ yid(pfileid) /)
-  ENDIF
-  iret = NF90_DEF_VAR (ncid,lat_name,NF90_FLOAT,dims(1:ndim),nlatid)
+    dims(1:1) = (/ W_F(pfileid)%yid /)
+  ENDIF
+  iret = NF90_DEF_VAR (nfid,lat_name,NF90_FLOAT,dims(1:ndim),nlatid)
   IF (rectilinear) THEN
-    iret = NF90_PUT_ATT (ncid,nlatid,'axis',"Y")
-  ENDIF
-  iret = NF90_PUT_ATT (ncid,nlatid,'standard_name',"latitude")
-  iret = NF90_PUT_ATT (ncid,nlatid,'units',"degrees_north")
-  iret = NF90_PUT_ATT (ncid,nlatid,'valid_min', &
+    iret = NF90_PUT_ATT (nfid,nlatid,'axis',"Y")
+  ENDIF
+  iret = NF90_PUT_ATT (nfid,nlatid,'standard_name',"latitude")
+  iret = NF90_PUT_ATT (nfid,nlatid,'units',"degrees_north")
+  iret = NF90_PUT_ATT (nfid,nlatid,'valid_min', &
  &                     REAL(MINVAL(plat),KIND=4))
-  iret = NF90_PUT_ATT (ncid,nlatid,'valid_max', &
+  iret = NF90_PUT_ATT (nfid,nlatid,'valid_max', &
  &                     REAL(MAXVAL(plat),KIND=4))
-  iret = NF90_PUT_ATT (ncid,nlatid,'long_name',"Latitude")
-  iret = NF90_PUT_ATT (ncid,nlatid,'nav_model',TRIM(tmp_title))
-!-
-  iret = NF90_ENDDEF (ncid)
+  iret = NF90_PUT_ATT (nfid,nlatid,'long_name',"Latitude")
+  iret = NF90_PUT_ATT (nfid,nlatid,'nav_model',TRIM(tmp_title))
+!-
+  iret = NF90_ENDDEF (nfid)
 !-
 ! 4.0 storing the geographical coordinates
@@ -710,15 +736,15 @@
   IF (l_dbg) WRITE(*,*) "histhori_regular 4.0"
 !-
-  orix = slab_ori(pfileid,1)
-  oriy = slab_ori(pfileid,2)
-  par_szx = slab_sz(pfileid,1)
-  par_szy = slab_sz(pfileid,2)
+  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)
 !-
 ! Transfer the longitude
 !-
   IF (rectilinear) THEN
-    iret = NF90_PUT_VAR (ncid,nlonid,plon(orix:orix+par_szx-1,1))
-  ELSE
-    iret = NF90_PUT_VAR (ncid,nlonid, &
+    iret = NF90_PUT_VAR (nfid,nlonid,plon(orix:orix+par_szx-1,1))
+  ELSE
+    iret = NF90_PUT_VAR (nfid,nlonid, &
  &           plon(orix:orix+par_szx-1,oriy:oriy+par_szy-1))
   ENDIF
@@ -727,11 +753,11 @@
 !-
   IF (rectilinear) THEN
-    iret = NF90_PUT_VAR (ncid,nlatid,plat(1,oriy:oriy+par_szy-1))
-  ELSE
-    iret = NF90_PUT_VAR (ncid,nlatid, &
+    iret = NF90_PUT_VAR (nfid,nlatid,plat(1,oriy:oriy+par_szy-1))
+  ELSE
+    iret = NF90_PUT_VAR (nfid,nlatid, &
  &           plat(orix:orix+par_szx-1,oriy:oriy+par_szy-1))
   ENDIF
 !-
-  iret = NF90_REDEF (ncid)
+  iret = NF90_REDEF (nfid)
 !------------------------------
 END SUBROUTINE histhori_regular
@@ -779,5 +805,5 @@
   INTEGER :: nbbounds
   INTEGER :: nlonid,nlatid,nlonidb,nlatidb
-  INTEGER :: iret,ncid,twoid
+  INTEGER :: iret,nfid,twoid
   LOGICAL :: transp = .FALSE.
   REAL,ALLOCATABLE,DIMENSION(:,:) :: bounds_trans
@@ -788,10 +814,10 @@
 ! 1.0 Check that all fits in the buffers
 !-
-  IF (    (pim /= full_size(pfileid,1)) &
-    & .OR.(full_size(pfileid,2) /= 1) ) THEN
+  IF (    (pim /= W_F(pfileid)%full_size(1)) &
+ &    .OR.(W_F(pfileid)%full_size(2) /= 1) ) THEN
     CALL ipslerr (3,"histhori", &
-   &  'The new horizontal grid does not have the same size', &
-   &  'as the one provided to histbeg. This is not yet ', &
-   &  'possible in the hist package.')
+ &   'The new horizontal grid does not have the same size', &
+ &   'as the one provided to histbeg. This is not yet ', &
+ &   'possible in the hist package.')
   ENDIF
 !-
@@ -800,5 +826,5 @@
   IF (l_dbg) WRITE(*,*) 'histhori_irregular 1.0'
 !-
-  ncid = ncdf_ids(pfileid)
+  nfid = W_F(pfileid)%ncfid
 !-
   IF     (SIZE(plon_bounds,DIM=1) == pim) THEN
@@ -817,12 +843,12 @@
   ALLOCATE(bounds_trans(nbbounds,pim))
 !-
-  iret = NF90_DEF_DIM (ncid,'nbnd',nbbounds,twoid)
+  iret = NF90_DEF_DIM (nfid,'nbnd',nbbounds,twoid)
   ndim = 1
-  dims(1) = xid(pfileid)
+  dims(1) = W_F(pfileid)%xid
   ndimb = 2
-  dimsb(1:2) = (/ twoid,xid(pfileid) /)
+  dimsb(1:2) = (/ twoid,W_F(pfileid)%xid /)
 !-
   tmp_name = phname
-  IF (nb_hax(pfileid) == 0) THEN
+  IF (W_F(pfileid)%n_hax == 0) THEN
     lon_name = 'nav_lon'
     lat_name = 'nav_lat'
@@ -836,8 +862,7 @@
 ! 1.2 Save the informations
 !-
-  phid =  nb_hax(pfileid)+1
-  nb_hax(pfileid) = phid
-!-
-  hax_name(pfileid,phid,1:2) = (/ lon_name,lat_name /)
+  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 /)
   tmp_title = phtitle
 !-
@@ -846,21 +871,21 @@
   IF (l_dbg) WRITE(*,*) "histhori_irregular 2.0"
 !-
-  iret = NF90_DEF_VAR (ncid,lon_name,NF90_FLOAT,dims(1:ndim),nlonid)
-  iret = NF90_PUT_ATT (ncid,nlonid,'standard_name',"longitude")
-  iret = NF90_PUT_ATT (ncid,nlonid,'units',"degrees_east")
-  iret = NF90_PUT_ATT (ncid,nlonid,'valid_min', &
+  iret = NF90_DEF_VAR (nfid,lon_name,NF90_FLOAT,dims(1:ndim),nlonid)
+  iret = NF90_PUT_ATT (nfid,nlonid,'standard_name',"longitude")
+  iret = NF90_PUT_ATT (nfid,nlonid,'units',"degrees_east")
+  iret = NF90_PUT_ATT (nfid,nlonid,'valid_min', &
  &                     REAL(MINVAL(plon),KIND=4))
-  iret = NF90_PUT_ATT (ncid,nlonid,'valid_max', &
+  iret = NF90_PUT_ATT (nfid,nlonid,'valid_max', &
  &                     REAL(MAXVAL(plon),KIND=4))
-  iret = NF90_PUT_ATT (ncid,nlonid,'long_name',"Longitude")
-  iret = NF90_PUT_ATT (ncid,nlonid,'nav_model',TRIM(tmp_title))
+  iret = NF90_PUT_ATT (nfid,nlonid,'long_name',"Longitude")
+  iret = NF90_PUT_ATT (nfid,nlonid,'nav_model',TRIM(tmp_title))
 !-
 ! 2.1 Longitude bounds
 !-
-  iret = NF90_PUT_ATT (ncid,nlonid,'bounds',TRIM(lonbound_name))
-  iret = NF90_DEF_VAR (ncid,lonbound_name,NF90_FLOAT, &
+  iret = NF90_PUT_ATT (nfid,nlonid,'bounds',TRIM(lonbound_name))
+  iret = NF90_DEF_VAR (nfid,lonbound_name,NF90_FLOAT, &
  &                     dimsb(1:ndimb),nlonidb)
   longname = 'Boundaries for coordinate variable '//TRIM(lon_name)
-  iret = NF90_PUT_ATT (ncid,nlonidb,'long_name',TRIM(longname))
+  iret = NF90_PUT_ATT (nfid,nlonidb,'long_name',TRIM(longname))
 !-
 ! 3.0 Latitude
@@ -868,23 +893,23 @@
   IF (l_dbg) WRITE(*,*) "histhori_irregular 3.0"
 !-
-  iret = NF90_DEF_VAR (ncid,lat_name,NF90_FLOAT,dims(1:ndim),nlatid)
-  iret = NF90_PUT_ATT (ncid,nlatid,'standard_name',"latitude")
-  iret = NF90_PUT_ATT (ncid,nlatid,'units',"degrees_north")
-  iret = NF90_PUT_ATT (ncid,nlatid,'valid_min', &
+  iret = NF90_DEF_VAR (nfid,lat_name,NF90_FLOAT,dims(1:ndim),nlatid)
+  iret = NF90_PUT_ATT (nfid,nlatid,'standard_name',"latitude")
+  iret = NF90_PUT_ATT (nfid,nlatid,'units',"degrees_north")
+  iret = NF90_PUT_ATT (nfid,nlatid,'valid_min', &
  &                     REAL(MINVAL(plat),KIND=4))
-  iret = NF90_PUT_ATT (ncid,nlatid,'valid_max', &
+  iret = NF90_PUT_ATT (nfid,nlatid,'valid_max', &
  &                     REAL(MAXVAL(plat),KIND=4))
-  iret = NF90_PUT_ATT (ncid,nlatid,'long_name',"Latitude")
-  iret = NF90_PUT_ATT (ncid,nlatid,'nav_model',TRIM(tmp_title))
+  iret = NF90_PUT_ATT (nfid,nlatid,'long_name',"Latitude")
+  iret = NF90_PUT_ATT (nfid,nlatid,'nav_model',TRIM(tmp_title))
 !-
 ! 3.1 Latitude bounds
 !-
-  iret = NF90_PUT_ATT (ncid,nlatid,'bounds',TRIM(latbound_name))
-  iret = NF90_DEF_VAR (ncid,latbound_name,NF90_FLOAT, &
+  iret = NF90_PUT_ATT (nfid,nlatid,'bounds',TRIM(latbound_name))
+  iret = NF90_DEF_VAR (nfid,latbound_name,NF90_FLOAT, &
  &                     dimsb(1:ndimb),nlatidb)
   longname = 'Boundaries for coordinate variable '//TRIM(lat_name)
-  iret = NF90_PUT_ATT (ncid,nlatidb,'long_name',TRIM(longname))
-!-
-  iret = NF90_ENDDEF (ncid)
+  iret = NF90_PUT_ATT (nfid,nlatidb,'long_name',TRIM(longname))
+!-
+  iret = NF90_ENDDEF (nfid)
 !-
 ! 4.0 storing the geographical coordinates
@@ -894,5 +919,5 @@
 ! 4.1 Write the longitude
 !-
-  iret = NF90_PUT_VAR (ncid,nlonid,plon(1:pim))
+  iret = NF90_PUT_VAR (nfid,nlonid,plon(1:pim))
 !-
 ! 4.2 Write the longitude bounds
@@ -903,9 +928,9 @@
     bounds_trans = plon_bounds
   ENDIF
-  iret = NF90_PUT_VAR (ncid,nlonidb,bounds_trans(1:nbbounds,1:pim))
+  iret = NF90_PUT_VAR (nfid,nlonidb,bounds_trans(1:nbbounds,1:pim))
 !-
 ! 4.3 Write the latitude
 !-
-  iret = NF90_PUT_VAR (ncid,nlatid,plat(1:pim))
+  iret = NF90_PUT_VAR (nfid,nlatid,plat(1:pim))
 !-
 ! 4.4 Write the latitude bounds
@@ -916,9 +941,9 @@
     bounds_trans = plat_bounds
   ENDIF
-  iret = NF90_PUT_VAR (ncid,nlatidb,bounds_trans(1:nbbounds,1:pim))
+  iret = NF90_PUT_VAR (nfid,nlatidb,bounds_trans(1:nbbounds,1:pim))
 !-
   DEALLOCATE(bounds_trans)
 !-
-  iret = NF90_REDEF (ncid)
+  iret = NF90_REDEF (nfid)
 !--------------------------------
 END SUBROUTINE histhori_irregular
@@ -963,5 +988,5 @@
   CHARACTER(LEN=80) :: str80
   CHARACTER(LEN=20) :: direction
-  INTEGER :: iret,leng,ncid
+  INTEGER :: iret,leng,nfid
   LOGICAL :: l_dbg
 !---------------------------------------------------------------------
@@ -997,5 +1022,5 @@
   ENDIF
 !-
-  IF (nb_zax(pfileid)+1 > nb_zax_max) THEN
+  IF (W_F(pfileid)%n_zax+1 > nb_zax_max) THEN
     CALL ipslerr (3,"histvert", &
    &  'Table of vertical axes too small. You should increase ',&
@@ -1004,7 +1029,7 @@
   ENDIF
 !-
-  iv = nb_zax(pfileid)
+  iv = W_F(pfileid)%n_zax
   IF (iv > 1) THEN
-    CALL find_str (zax_name(pfileid,1:iv-1),pzaxname,pos)
+    CALL find_str (W_F(pfileid)%zax_name(1:iv-1),pzaxname,pos)
   ELSE
     pos = 0
@@ -1019,5 +1044,5 @@
   ENDIF
 !-
-  iv = nb_zax(pfileid)+1
+  iv = W_F(pfileid)%n_zax+1
 !-
 ! 2.0 Add the information to the file
@@ -1026,31 +1051,31 @@
  &  WRITE(*,*) "histvert : 2.0 Add the information to the file"
 !-
-  ncid = ncdf_ids(pfileid)
+  nfid = W_F(pfileid)%ncfid
 !-
   leng = MIN(LEN_TRIM(pzaxname),20)
-  iret = NF90_DEF_DIM (ncid,pzaxname(1:leng),pzsize,zaxid_tmp)
-  iret = NF90_DEF_VAR (ncid,pzaxname(1:leng),NF90_FLOAT, &
+  iret = NF90_DEF_DIM (nfid,pzaxname(1:leng),pzsize,zaxid_tmp)
+  iret = NF90_DEF_VAR (nfid,pzaxname(1:leng),NF90_FLOAT, &
  &                     zaxid_tmp,zdimid)
-  iret = NF90_PUT_ATT (ncid,zdimid,'axis',"Z")
-  iret = NF90_PUT_ATT (ncid,zdimid,'standard_name',"model_level_number")
+  iret = NF90_PUT_ATT (nfid,zdimid,'axis',"Z")
+  iret = NF90_PUT_ATT (nfid,zdimid,'standard_name',"model_level_number")
   leng = MIN(LEN_TRIM(pzaxunit),20)
   IF (leng > 0) THEN
-    iret = NF90_PUT_ATT (ncid,zdimid,'units',pzaxunit(1:leng))
-  ENDIF
-  iret = NF90_PUT_ATT (ncid,zdimid,'positive',TRIM(direction))
-  iret = NF90_PUT_ATT (ncid,zdimid,'valid_min', &
+    iret = NF90_PUT_ATT (nfid,zdimid,'units',pzaxunit(1:leng))
+  ENDIF
+  iret = NF90_PUT_ATT (nfid,zdimid,'positive',TRIM(direction))
+  iret = NF90_PUT_ATT (nfid,zdimid,'valid_min', &
  &                     REAL(MINVAL(pzvalues(1:pzsize)),KIND=4))
-  iret = NF90_PUT_ATT (ncid,zdimid,'valid_max', &
+  iret = NF90_PUT_ATT (nfid,zdimid,'valid_max', &
  &                     REAL(MAXVAL(pzvalues(1:pzsize)),KIND=4))
   leng = MIN(LEN_TRIM(pzaxname),20)
-  iret = NF90_PUT_ATT (ncid,zdimid,'title',pzaxname(1:leng))
+  iret = NF90_PUT_ATT (nfid,zdimid,'title',pzaxname(1:leng))
   leng = MIN(LEN_TRIM(pzaxtitle),80)
-  iret = NF90_PUT_ATT (ncid,zdimid,'long_name',pzaxtitle(1:leng))
-!-
-  iret = NF90_ENDDEF (ncid)
-!-
-  iret = NF90_PUT_VAR (ncid,zdimid,pzvalues(1:pzsize))
-!-
-  iret = NF90_REDEF (ncid)
+  iret = NF90_PUT_ATT (nfid,zdimid,'long_name',pzaxtitle(1:leng))
+!-
+  iret = NF90_ENDDEF (nfid)
+!-
+  iret = NF90_PUT_VAR (nfid,zdimid,pzvalues(1:pzsize))
+!-
+  iret = NF90_REDEF (nfid)
 !-
 !- 3.0 add the information to the common
@@ -1059,9 +1084,9 @@
   &  WRITE(*,*) "histvert : 3.0 add the information to the common"
 !-
-  nb_zax(pfileid) = iv
-  zax_size(pfileid,iv) = pzsize
-  zax_name(pfileid,iv) = pzaxname
-  zax_ids(pfileid,iv) = zaxid_tmp
-  pzaxid =  iv
+  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
+  pzaxid = iv
 !----------------------
 END SUBROUTINE histvert
@@ -1143,6 +1168,6 @@
   ex_topps = 'ave, inst, t_min, t_max, t_sum, once, never, l_max, l_min'
 !-
-  nb_var(pfileid) = nb_var(pfileid)+1
-  iv = nb_var(pfileid)
+  W_F(pfileid)%n_var = W_F(pfileid)%n_var+1
+  iv = W_F(pfileid)%n_var
 !-
   IF (iv > nb_var_max) THEN
@@ -1159,5 +1184,5 @@
 !-
   IF (iv > 1) THEN
-    CALL find_str (name(pfileid,1:iv-1),pvarname,pos)
+    CALL find_str (W_F(pfileid)%W_V(1:iv-1)%v_name,pvarname,pos)
   ELSE
     pos = 0
@@ -1172,21 +1197,21 @@
   ENDIF
 !-
-  name(pfileid,iv) = pvarname
-  title(pfileid,iv) = ptitle
-  unit_name(pfileid,iv) = punit
-  tmp_name =  name(pfileid,iv)
+  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
+  tmp_name = W_F(pfileid)%W_V(iv)%v_name
 !-
 ! 1.1 decode the operations
 !-
-  fullop(pfileid,iv) = popp
+  W_F(pfileid)%W_V(iv)%fullop = popp
   tmp_str80 = popp
   CALL buildop &
  &  (tmp_str80,ex_topps,tmp_topp,nbopp_max,missing_val, &
- &   tmp_sopp,tmp_scal,nbopp(pfileid,iv))
-!-
-  topp(pfileid,iv) = tmp_topp
-  DO i=1,nbopp(pfileid,iv)
-    sopps(pfileid,iv,i) = tmp_sopp(i)
-    scal(pfileid,iv,i) = tmp_scal(i)
+ &   tmp_sopp,tmp_scal,W_F(pfileid)%W_V(iv)%nbopp)
+!-
+  W_F(pfileid)%W_V(iv)%topp = tmp_topp
+  DO i=1,W_F(pfileid)%W_V(iv)%nbopp
+    W_F(pfileid)%W_V(iv)%sopps(i) = tmp_sopp(i)
+    W_F(pfileid)%W_V(iv)%scal(i) = tmp_scal(i)
   ENDDO
 !-
@@ -1194,8 +1219,9 @@
 !     then we need to add identity
 !-
-  IF (2*INT(nbopp(pfileid,iv)/2.0) == nbopp(pfileid,iv)) THEN
-    nbopp(pfileid,iv) = nbopp(pfileid,iv)+1
-    sopps(pfileid,iv,nbopp(pfileid,iv)) = 'ident'
-    scal(pfileid,iv,nbopp(pfileid,iv)) = missing_val
+  IF (    2*INT(W_F(pfileid)%W_V(iv)%nbopp/2.0) &
+ &     == W_F(pfileid)%W_V(iv)%nbopp) THEN
+    W_F(pfileid)%W_V(iv)%nbopp = W_F(pfileid)%W_V(iv)%nbopp+1
+    W_F(pfileid)%W_V(iv)%sopps(W_F(pfileid)%W_V(iv)%nbopp) = 'ident'
+    W_F(pfileid)%W_V(iv)%scal(W_F(pfileid)%W_V(iv)%nbopp) = missing_val
   ENDIF
 !-
@@ -1203,33 +1229,32 @@
 !-
   IF (pnbbyt == hist_r8) THEN
-    v_typ(pfileid,iv) = hist_r8
-  ELSE
-    v_typ(pfileid,iv) = hist_r4
+    W_F(pfileid)%W_V(iv)%v_typ = hist_r8
+  ELSE
+    W_F(pfileid)%W_V(iv)%v_typ = hist_r4
   ENDIF
 !-
 ! 2.0 Put the size of the variable in the common and check
 !-
-  IF (l_dbg) &
- &  WRITE(*,*) "histdef : 2.0",pfileid,iv,nbopp(pfileid,iv), &
- &    sopps(pfileid,iv,1:nbopp(pfileid,iv)), &
- &    scal(pfileid,iv,1:nbopp(pfileid,iv))
-!-
-  scsize(pfileid,iv,1:3) = (/ pxsize,pysize,pzsize /)
-!-
-  zorig(pfileid,iv,1:3) = &
- &  (/ slab_ori(pfileid,1),slab_ori(pfileid,2),par_oriz /)
-!-
-  zsize(pfileid,iv,1:3) = &
- &  (/ slab_sz(pfileid,1),slab_sz(pfileid,2),par_szz /)
-!-
-! Is the size of the full array the same as that of the coordinates  ?
-!-
-  IF (    (pxsize > full_size(pfileid,1)) &
- &    .OR.(pysize > full_size(pfileid,2)) ) THEN
+  IF (l_dbg) THEN
+    WRITE(*,*) "histdef : 2.0",pfileid,iv,W_F(pfileid)%W_V(iv)%nbopp, &
+ &    W_F(pfileid)%W_V(iv)%sopps(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 /)
+!-
+! 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
 !-
     str70 = "The size of the variable is different "// &
  &          "from the one of the coordinates"
     WRITE(str71,'("Size of coordinates :",2I4)') &
- &   full_size(pfileid,1),full_size(pfileid,2)
+ &   W_F(pfileid)%full_size(1),W_F(pfileid)%full_size(2)
     WRITE(str72,'("Size declared for variable ",a," :",2I4)') &
  &   TRIM(tmp_name),pxsize,pysize
@@ -1237,13 +1262,13 @@
   ENDIF
 !-
-! Is the size of the zoom smaler than the coordinates ?
-!-
-  IF (    (full_size(pfileid,1) < slab_sz(pfileid,1)) &
- &    .OR.(full_size(pfileid,2) < slab_sz(pfileid,2)) ) THEN
+! 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
     str70 = &
  &   "Size of variable should be greater or equal to those of the zoom"
     WRITE(str71,'("Size of XY zoom :",2I4)') &
- &   slab_sz(pfileid,1),slab_sz(pfileid,1)
-    WRITE(str72,'("Size declared for variable ",a," :",2I4)') &
+ &   W_F(pfileid)%slab_sz(1),W_F(pfileid)%slab_sz(2)
+    WRITE(str72,'("Size declared for variable ",A," :",2I4)') &
  &   TRIM(tmp_name),pxsize,pysize
     CALL ipslerr (3,"histdef",str70,str71,str72)
@@ -1253,8 +1278,8 @@
 !     and a fall back onto the default grid
 !-
-  IF ( (phoriid > 0).AND.(phoriid <= nb_hax(pfileid)) ) THEN
-    var_haxid(pfileid,iv) = phoriid
-  ELSE
-    var_haxid(pfileid,iv) = 1
+  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
     CALL ipslerr (2,"histdef", &
    &  'We use the default grid for variable as an invalide',&
@@ -1268,5 +1293,5 @@
 !-- Does the vertical coordinate exist ?
 !-
-    IF (pzid > nb_zax(pfileid)) THEN
+    IF (pzid > W_F(pfileid)%n_zax) THEN
       WRITE(str70, &
  &    '("The vertical coordinate chosen for variable ",a)') &
@@ -1278,14 +1303,14 @@
 !-- Is the vertical size of the variable equal to that of the axis ?
 !-
-    IF (par_szz /= zax_size(pfileid,pzid)) THEN
+    IF (par_szz /= W_F(pfileid)%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(zax_name(pfileid,pzid)),zax_size(pfileid,pzid)
+ &     TRIM(W_F(pfileid)%zax_name(pzid)),W_F(pfileid)%zax_size(pzid)
       CALL ipslerr (3,"histdef",str70,str71,str72)
     ENDIF
 !-
-!-- Is the zoom smaler that the total size of the variable ?
+!-- Is the zoom smaller that the total size of the variable ?
 !-
     IF (pzsize < par_szz) THEN
@@ -1297,7 +1322,7 @@
       CALL ipslerr (3,"histdef",str70,str71,str72)
     ENDIF
-    var_zaxid(pfileid,iv) = pzid
-  ELSE
-    var_zaxid(pfileid,iv) = -99
+    W_F(pfileid)%W_V(iv)%z_axid = pzid
+  ELSE
+    W_F(pfileid)%W_V(iv)%z_axid = -99
   ENDIF
 !-
@@ -1310,5 +1335,7 @@
 !     that they fit into the tmp_buffer
 !-
-  buff_sz = zsize(pfileid,iv,1)*zsize(pfileid,iv,2)*zsize(pfileid,iv,3)
+  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
@@ -1318,9 +1345,9 @@
  &    .AND.(TRIM(tmp_topp) /= "once") &
  &    .AND.(TRIM(tmp_topp) /= "never") )THEN
-    point(pfileid,iv) = buff_pos+1
+    W_F(pfileid)%W_V(iv)%point = buff_pos+1
     buff_pos = buff_pos+buff_sz
     IF (l_dbg) THEN
       WRITE(*,*) "histdef : 3.2 bufpos for iv = ",iv, &
- &               " pfileid = ",pfileid," is = ",point(pfileid,iv)
+ &      " pfileid = ",pfileid," is = ",W_F(pfileid)%W_V(iv)%point
     ENDIF
   ENDIF
@@ -1333,6 +1360,6 @@
   IF (l_dbg) WRITE(*,*) "histdef : 4.0"
 !-
-  freq_opp(pfileid,iv) = pfreq_opp
-  freq_wrt(pfileid,iv) = pfreq_wrt
+  W_F(pfileid)%W_V(iv)%freq_opp = pfreq_opp
+  W_F(pfileid)%W_V(iv)%freq_wrt = pfreq_wrt
 !-
   CALL ioget_calendar(un_an,un_jour)
@@ -1352,5 +1379,5 @@
 ! 4.1 Frequency of operations and output should be larger than deltat !
 !-
-  IF (test_fopp < deltat(pfileid)) THEN
+  IF (test_fopp < W_F(pfileid)%deltat) THEN
     str70 = 'Frequency of operations should be larger than deltat'
     WRITE(str71,'("It is not the case for variable ",a," :",F10.4)') &
@@ -1360,8 +1387,8 @@
     CALL ipslerr (2,"histdef",str70,str71,str72)
 !-
-    freq_opp(pfileid,iv) = deltat(pfileid)
-  ENDIF
-!-
-  IF (test_fwrt < deltat(pfileid)) THEN
+    W_F(pfileid)%W_V(iv)%freq_opp = W_F(pfileid)%deltat
+  ENDIF
+!-
+  IF (test_fwrt < W_F(pfileid)%deltat) THEN
     str70 = 'Frequency of output should be larger than deltat'
     WRITE(str71,'("It is not the case for variable ",a," :",F10.4)') &
@@ -1371,5 +1398,5 @@
     CALL ipslerr (2,"histdef",str70,str71,str72)
 !-
-    freq_wrt(pfileid,iv) = deltat(pfileid)
+    W_F(pfileid)%W_V(iv)%freq_wrt = W_F(pfileid)%deltat
   ENDIF
 !-
@@ -1387,9 +1414,9 @@
       CALL ipslerr (2,"histdef",str70,str71,str72)
       IF (test_fopp < test_fwrt) THEN
-        freq_opp(pfileid,iv) = pfreq_opp
-        freq_wrt(pfileid,iv) = pfreq_opp
+        W_F(pfileid)%W_V(iv)%freq_opp = pfreq_opp
+        W_F(pfileid)%W_V(iv)%freq_wrt = pfreq_opp
       ELSE
-        freq_opp(pfileid,iv) = pfreq_wrt
-        freq_wrt(pfileid,iv) = pfreq_wrt
+        W_F(pfileid)%W_V(iv)%freq_opp = pfreq_wrt
+        W_F(pfileid)%W_V(iv)%freq_wrt = pfreq_wrt
       ENDIF
     ENDIF
@@ -1403,5 +1430,5 @@
       str72 = 'PATCH : The output frequency is used for both'
       CALL ipslerr (2,"histdef",str70,str71,str72)
-      freq_opp(pfileid,iv) = pfreq_wrt
+      W_F(pfileid)%W_V(iv)%freq_opp = pfreq_wrt
     ENDIF
   ELSE
@@ -1417,25 +1444,25 @@
   IF (l_dbg) WRITE(*,*) "histdef : 5.0"
 !-
-  hist_wrt_rng(pfileid,iv) = (PRESENT(var_range))
-  IF (hist_wrt_rng(pfileid,iv)) THEN
-    hist_calc_rng(pfileid,iv) = (var_range(1) > var_range(2))
-    IF (hist_calc_rng(pfileid,iv)) THEN
-      hist_minmax(pfileid,iv,1:2) = &
+  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) = &
  &      (/ ABS(missing_val),-ABS(missing_val) /)
     ELSE
-      hist_minmax(pfileid,iv,1:2) = var_range(1:2)
+      W_F(pfileid)%W_V(iv)%hist_minmax(1:2) = var_range(1:2)
     ENDIF
   ENDIF
 !-
 ! - freq_opp(pfileid,iv)/2./deltat(pfileid)
-  last_opp(pfileid,iv) = itau0(pfileid)
+  W_F(pfileid)%W_V(iv)%last_opp = W_F(pfileid)%itau0
 ! - freq_wrt(pfileid,iv)/2./deltat(pfileid)
-  last_wrt(pfileid,iv) = itau0(pfileid)
+  W_F(pfileid)%W_V(iv)%last_wrt = W_F(pfileid)%itau0
 ! - freq_opp(pfileid,iv)/2./deltat(pfileid)
-  last_opp_chk(pfileid,iv) = itau0(pfileid)
+  W_F(pfileid)%W_V(iv)%last_opp_chk = W_F(pfileid)%itau0
 ! - freq_wrt(pfileid,iv)/2./deltat(pfileid)
-  last_wrt_chk(pfileid,iv) = itau0(pfileid)
-  nb_opp(pfileid,iv) = 0
-  nb_wrt(pfileid,iv) = 0
+  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
 !-
 ! 6.0 Get the time axis for this variable
@@ -1443,12 +1470,12 @@
   IF (l_dbg) WRITE(*,*) "histdef : 6.0"
 !-
-  IF (freq_wrt(pfileid,iv) > 0) THEN
-    WRITE(str10,'(I8.8)') INT(freq_wrt(pfileid,iv))
+  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(tmp_topp)//"_"//TRIM(str10)
   ELSE
-    WRITE(str10,'(I2.2,"month")') ABS(INT(freq_wrt(pfileid,iv)))
+    WRITE(str10,'(I2.2,"month")') ABS(INT(W_F(pfileid)%W_V(iv)%freq_wrt))
     str40 = TRIM(tmp_topp)//"_"//TRIM(str10)
   ENDIF
-  CALL find_str (tax_name(pfileid,1:nb_tax(pfileid)),str40,pos)
+  CALL find_str (W_F(pfileid)%W_V(1:W_F(pfileid)%n_tax)%tax_name,str40,pos)
 !-
 ! No time axis for once, l_max, l_min or never operation
@@ -1459,14 +1486,14 @@
  &    .AND.(TRIM(tmp_topp) /= 'l_min') ) THEN
     IF (pos < 0) THEN
-      nb_tax(pfileid) = nb_tax(pfileid)+1
-      tax_name(pfileid,nb_tax(pfileid)) = str40
-      tax_last(pfileid,nb_tax(pfileid)) = 0
-      var_axid(pfileid,iv) = nb_tax(pfileid)
+      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
     ELSE
-      var_axid(pfileid,iv) = pos
+      W_F(pfileid)%W_V(iv)%t_axid = pos
     ENDIF
   ELSE
     IF (l_dbg)   WRITE(*,*) "histdef : 7.0 ",TRIM(tmp_topp),'----'
-    var_axid(pfileid,iv) = -99
+    W_F(pfileid)%W_V(iv)%t_axid = -99
   ENDIF
 !-
@@ -1476,6 +1503,6 @@
   IF (    (TRIM(tmp_topp) == 'once')  &
  &    .OR.(TRIM(tmp_topp) == 'never') ) THEN
-    freq_opp(pfileid,iv) = 0.
-    freq_wrt(pfileid,iv) = 0.
+    W_F(pfileid)%W_V(iv)%freq_opp = 0.
+    W_F(pfileid)%W_V(iv)%freq_wrt = 0.
   ENDIF
 !---------------------
@@ -1498,5 +1525,5 @@
   INTEGER,INTENT(IN) :: pfileid
 !-
-  INTEGER :: ncid,ncvarid,iret,ndim,iv,itx,ziv,itax,dim_cnt
+  INTEGER :: nfid,nvid,iret,ndim,iv,itx,ziv,itax,dim_cnt
   INTEGER,DIMENSION(4) :: dims
   INTEGER :: year,month,day,hours,minutes
@@ -1514,5 +1541,5 @@
   CALL ipsldbg (old_status=l_dbg)
 !-
-  ncid = ncdf_ids(pfileid)
+  nfid = W_F(pfileid)%ncfid
 !-
 ! 1.0 Create the time axes
@@ -1520,21 +1547,23 @@
   IF (l_dbg) WRITE(*,*) "histend : 1.0"
 !---
-  iret = NF90_DEF_DIM (ncid,'time_counter',NF90_UNLIMITED,tid(pfileid))
+  iret = NF90_DEF_DIM (nfid,'time_counter', &
+ &                     NF90_UNLIMITED,W_F(pfileid)%tid)
 !-
 ! 1.1 Define all the time axes needed for this file
 !-
-  DO itx=1,nb_tax(pfileid)
-    dims(1) = tid(pfileid)
-    IF (nb_tax(pfileid) > 1) THEN
-      str30 = "t_"//tax_name(pfileid,itx)
+  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
     ELSE
       str30 = "time_counter"
     ENDIF
-    iret = NF90_DEF_VAR (ncid,str30,NF90_DOUBLE, &
- &                       dims(1),tdimid(pfileid,itx))
-    IF (nb_tax(pfileid) <= 1) THEN
-      iret = NF90_PUT_ATT (ncid,tdimid(pfileid,itx),'axis',"T")
-    ENDIF
-    iret = NF90_PUT_ATT (ncid,tdimid(pfileid,itx),'standard_name',"time")
+    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, &
+ &           'standard_name',"time")
 !---
 !   To transform the current itau into a real date and take it
@@ -1545,5 +1574,5 @@
 !---
 !-- rtime0 = itau2date(itau0(pfileid),date0(pfileid),deltat(pfileid))
-    rtime0 = date0(pfileid)
+    rtime0 = W_F(pfileid)%date0
 !-
     CALL ju2ymds(rtime0,year,month,day,sec)
@@ -1562,20 +1591,22 @@
  &   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 (ncid,tdimid(pfileid,itx),'units',TRIM(str70))
+    iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid, &
+ &           'units',TRIM(str70))
 !-
     CALL ioget_calendar (str30)
-    iret = NF90_PUT_ATT (ncid,tdimid(pfileid,itx), &
- &                       'calendar',TRIM(str30))
-!-
-    iret = NF90_PUT_ATT (ncid,tdimid(pfileid,itx),'title','Time')
-!-
-    iret = NF90_PUT_ATT (ncid,tdimid(pfileid,itx), &
- &                       'long_name','Time axis')
+    iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid, &
+ &           'calendar',TRIM(str30))
+!-
+    iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid, &
+ &           'title','Time')
+!-
+    iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid, &
+ &           'long_name','Time axis')
 !-
     WRITE (UNIT=str70, &
  &   FMT='(" ",I4.4,"-",A3,"-",I2.2," ",I2.2,":",I2.2,":",I2.2)') &
  &    year,cal(month),day,hours,minutes,INT(sec)
-    iret = NF90_PUT_ATT (ncid,tdimid(pfileid,itx), &
- &                       'time_origin',TRIM(str70))
+    iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid, &
+ &           'time_origin',TRIM(str70))
   ENDDO
 !-
@@ -1584,18 +1615,18 @@
   IF (l_dbg) WRITE(*,*) "histend : 2.0"
 !-
-  DO iv=1,nb_var(pfileid)
+  DO iv=1,W_F(pfileid)%n_var
 !---
-    itax = var_axid(pfileid,iv)
+    itax = W_F(pfileid)%W_V(iv)%t_axid
 !---
-    IF (regular(pfileid) ) THEN
-      dims(1:2) = (/ xid(pfileid),yid(pfileid) /)
+    IF (W_F(pfileid)%regular) THEN
+      dims(1:2) = (/ W_F(pfileid)%xid,W_F(pfileid)%yid /)
       dim_cnt = 2
     ELSE
-      dims(1) = xid(pfileid)
+      dims(1) = W_F(pfileid)%xid
       dim_cnt = 1
     ENDIF
 !---
-    tmp_opp = topp(pfileid,iv)
-    ziv = var_zaxid(pfileid,iv)
+    tmp_opp = W_F(pfileid)%W_V(iv)%topp
+    ziv = W_F(pfileid)%W_V(iv)%z_axid
 !---
 !   2.1 dimension of field
@@ -1607,8 +1638,9 @@
         IF (ziv == -99) THEN
           ndim = dim_cnt+1
-          dims(dim_cnt+1:dim_cnt+2) = (/ tid(pfileid),0 /)
+          dims(dim_cnt+1:dim_cnt+2) = (/ W_F(pfileid)%tid,0 /)
         ELSE
           ndim = dim_cnt+2
-          dims(dim_cnt+1:dim_cnt+2) = (/zax_ids(pfileid,ziv),tid(pfileid)/)
+          dims(dim_cnt+1:dim_cnt+2) = &
+ &         (/ W_F(pfileid)%zax_ids(ziv),W_F(pfileid)%tid /)
         ENDIF
       ELSE
@@ -1618,32 +1650,32 @@
         ELSE
           ndim = dim_cnt+1
-          dims(dim_cnt+1:dim_cnt+2) = (/ zax_ids(pfileid,ziv),0 /)
+          dims(dim_cnt+1:dim_cnt+2) = (/ W_F(pfileid)%zax_ids(ziv),0 /)
         ENDIF
       ENDIF
 !-
-      iret = NF90_DEF_VAR (ncid,TRIM(name(pfileid,iv)), &
- &                         v_typ(pfileid,iv),dims(1:ABS(ndim)),ncvarid)
-!-
-      ncvar_ids(pfileid,iv) = ncvarid
-!-
-      IF (LEN_TRIM(unit_name(pfileid,iv)) > 0) THEN
-        iret = NF90_PUT_ATT (ncid,ncvarid,'units', &
- &                           TRIM(unit_name(pfileid,iv)))
+      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_PUT_ATT (nfid,nvid,'units', &
+ &                           TRIM(W_F(pfileid)%W_V(iv)%unit_name))
       ENDIF
-      iret = NF90_PUT_ATT (ncid,ncvarid,'standard_name', &
- &                         TRIM(title(pfileid,iv)))
-!-
-      iret = NF90_PUT_ATT (ncid,ncvarid,'_FillValue', &
+      iret = NF90_PUT_ATT (nfid,nvid,'standard_name', &
+ &                         TRIM(W_F(pfileid)%W_V(iv)%title))
+!-
+      iret = NF90_PUT_ATT (nfid,nvid,'_FillValue', &
  &                         REAL(missing_val,KIND=4))
-      IF (hist_wrt_rng(pfileid,iv)) THEN
-        iret = NF90_PUT_ATT (ncid,ncvarid,'valid_min', &
- &                           REAL(hist_minmax(pfileid,iv,1),KIND=4))
-        iret = NF90_PUT_ATT (ncid,ncvarid,'valid_max', &
- &                           REAL(hist_minmax(pfileid,iv,2),KIND=4))
+      IF (W_F(pfileid)%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))
+        iret = NF90_PUT_ATT (nfid,nvid,'valid_max', &
+ &               REAL(W_F(pfileid)%W_V(iv)%hist_minmax(2),KIND=4))
       ENDIF
-      iret = NF90_PUT_ATT (ncid,ncvarid,'long_name', &
- &                         TRIM(title(pfileid,iv)))
-      iret = NF90_PUT_ATT (ncid,ncvarid,'online_operation', &
- &                         TRIM(fullop(pfileid,iv)))
+      iret = NF90_PUT_ATT (nfid,nvid,'long_name', &
+ &                         TRIM(W_F(pfileid)%W_V(iv)%title))
+      iret = NF90_PUT_ATT (nfid,nvid,'online_operation', &
+ &                         TRIM(W_F(pfileid)%W_V(iv)%fullop))
 !-
       SELECT CASE(ndim)
@@ -1655,16 +1687,16 @@
       END SELECT
 !-
-      assoc=TRIM(hax_name(pfileid,var_haxid(pfileid,iv),2))  &
- &   //' '//TRIM(hax_name(pfileid,var_haxid(pfileid,iv),1))
-!-
-      ziv = var_zaxid(pfileid,iv)
+      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
       IF (ziv > 0) THEN
-        str30 = zax_name(pfileid,ziv)
+        str30 = W_F(pfileid)%zax_name(ziv)
         assoc = TRIM(str30)//' '//TRIM(assoc)
       ENDIF
 !-
       IF (itax > 0) THEN
-        IF (nb_tax(pfileid) > 1) THEN
-          str30 = "t_"//tax_name(pfileid,itax)
+        IF (W_F(pfileid)%n_tax > 1) THEN
+          str30 = "t_"//W_F(pfileid)%W_V(itax)%tax_name
         ELSE
           str30 = "time_counter"
@@ -1674,13 +1706,13 @@
         IF (l_dbg) THEN
           WRITE(*,*) "histend : 2.0.n, freq_opp, freq_wrt", &
- &                   freq_opp(pfileid,iv),freq_wrt(pfileid,iv)
+ &          W_F(pfileid)%W_V(iv)%freq_opp,W_F(pfileid)%W_V(iv)%freq_wrt
         ENDIF
 !-
-        iret = NF90_PUT_ATT (ncid,ncvarid,'interval_operation', &
- &                           REAL(freq_opp(pfileid,iv),KIND=4))
-        iret = NF90_PUT_ATT (ncid,ncvarid,'interval_write', &
- &                           REAL(freq_wrt(pfileid,iv),KIND=4))
+        iret = NF90_PUT_ATT (nfid,nvid,'interval_operation', &
+ &                           REAL(W_F(pfileid)%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))
       ENDIF
-      iret = NF90_PUT_ATT (ncid,ncvarid,'coordinates',TRIM(assoc))
+      iret = NF90_PUT_ATT (nfid,nvid,'coordinates',TRIM(assoc))
     ENDIF
   ENDDO
@@ -1688,6 +1720,6 @@
 ! 2.2 Add DOMAIN attributes if needed
 !-
-  IF (dom_id_svg(pfileid) >= 0) THEN
-    CALL flio_dom_att (ncid,dom_id_svg(pfileid))
+  IF (W_F(pfileid)%dom_id_svg >= 0) THEN
+    CALL flio_dom_att (nfid,W_F(pfileid)%dom_id_svg)
   ENDIF
 !-
@@ -1696,5 +1728,5 @@
   IF (l_dbg) WRITE(*,*) "histend : 3.0"
 !-
-  iret = NF90_ENDDEF (ncid)
+  iret = NF90_ENDDEF (nfid)
 !-
 ! 4.0 Give some informations to the user
@@ -1794,14 +1826,14 @@
 ! 2.0 do nothing for never operation
 !-
-  tmp_opp = topp(pfileid,varid)
+  tmp_opp = W_F(pfileid)%W_V(varid)%topp
 !-
   IF (TRIM(tmp_opp) == "never") THEN
-    last_opp_chk(pfileid,varid) = -99
-    last_wrt_chk(pfileid,varid) = -99
+    W_F(pfileid)%W_V(varid)%last_opp_chk = -99
+    W_F(pfileid)%W_V(varid)%last_wrt_chk = -99
   ENDIF
 !-
 ! 3.0 We check if we need to do an operation
 !-
-  IF (last_opp_chk(pfileid,varid) == pitau) THEN
+  IF (W_F(pfileid)%W_V(varid)%last_opp_chk == pitau) THEN
     CALL ipslerr (3,"histwrite", &
  &    'This variable has already been analysed at the present', &
@@ -1810,18 +1842,22 @@
 !-
   CALL isittime &
- &  (pitau,date0(pfileid),deltat(pfileid),freq_opp(pfileid,varid), &
- &   last_opp(pfileid,varid),last_opp_chk(pfileid,varid),do_oper)
+ &  (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)
 !-
 ! 4.0 We check if we need to write the data
 !-
-  IF (last_wrt_chk(pfileid,varid) == pitau) THEN
+  IF (W_F(pfileid)%W_V(varid)%last_wrt_chk == pitau) THEN
     CALL ipslerr (3,"histwrite", &
- &    'This variable has already been written for the present', &
- &    'time step',TRIM(pvarname))
+ &    'This variable as already been written for the present', &
+ &    'time step',' ')
   ENDIF
 !-
   CALL isittime &
- &  (pitau,date0(pfileid),deltat(pfileid),freq_wrt(pfileid,varid), &
- &   last_wrt(pfileid,varid),last_wrt_chk(pfileid,varid),do_write)
+ &  (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)
 !-
 ! 5.0 histwrite called
@@ -1831,19 +1867,19 @@
 !-- 5.1 Get the sizes of the data we will handle
 !-
-    IF (datasz_in(pfileid,varid,1) <= 0) THEN
+    IF (W_F(pfileid)%W_V(varid)%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 !
-      datasz_in(pfileid,varid,1:3) = -1
+      W_F(pfileid)%W_V(varid)%datasz_in(1:3) = -1
       IF      (l1d) THEN
-        datasz_in(pfileid,varid,1) = SIZE(pdata_1d)
+        W_F(pfileid)%W_V(varid)%datasz_in(1) = SIZE(pdata_1d)
       ELSE IF (l2d) THEN
-        datasz_in(pfileid,varid,1) = SIZE(pdata_2d,DIM=1)
-        datasz_in(pfileid,varid,2) = SIZE(pdata_2d,DIM=2)
+        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)
       ELSE IF (l3d) THEN
-        datasz_in(pfileid,varid,1) = SIZE(pdata_3d,DIM=1)
-        datasz_in(pfileid,varid,2) = SIZE(pdata_3d,DIM=2)
-        datasz_in(pfileid,varid,3) = SIZE(pdata_3d,DIM=3)
+        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)
       ENDIF
     ENDIF
@@ -1851,29 +1887,29 @@
 !-- 5.2 The maximum size of the data will give the size of the buffer
 !-
-    IF (datasz_max(pfileid,varid) <= 0) THEN
+    IF (W_F(pfileid)%W_V(varid)%datasz_max <= 0) THEN
       largebuf = .FALSE.
-      DO io=1,nbopp(pfileid,varid)
-        IF (INDEX(fuchnbout,sopps(pfileid,varid,io)) > 0) THEN
+      DO io=1,W_F(pfileid)%W_V(varid)%nbopp
+        IF (INDEX(fuchnbout,W_F(pfileid)%W_V(varid)%sopps(io)) > 0) THEN
           largebuf = .TRUE.
         ENDIF
       ENDDO
       IF (largebuf) THEN
-        datasz_max(pfileid,varid) = &
- &        scsize(pfileid,varid,1) &
- &       *scsize(pfileid,varid,2) &
- &       *scsize(pfileid,varid,3)
+        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)
       ELSE
         IF      (l1d) THEN
-          datasz_max(pfileid,varid) = &
- &          datasz_in(pfileid,varid,1)
+          W_F(pfileid)%W_V(varid)%datasz_max = &
+ &          W_F(pfileid)%W_V(varid)%datasz_in(1)
         ELSE IF (l2d) THEN
-          datasz_max(pfileid,varid) = &
- &          datasz_in(pfileid,varid,1) &
- &         *datasz_in(pfileid,varid,2)
+          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)
         ELSE IF (l3d) THEN
-          datasz_max(pfileid,varid) = &
- &          datasz_in(pfileid,varid,1) &
- &         *datasz_in(pfileid,varid,2) &
- &         *datasz_in(pfileid,varid,3)
+          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)
         ENDIF
       ENDIF
@@ -1884,17 +1920,17 @@
         WRITE(*,*) &
  &       c_nam//" : allocate buff_tmp for buff_sz = ", &
- &       datasz_max(pfileid,varid)
+ &       W_F(pfileid)%W_V(varid)%datasz_max
       ENDIF
-      ALLOCATE(buff_tmp(datasz_max(pfileid,varid)))
-      buff_tmp_sz = datasz_max(pfileid,varid)
-    ELSE IF (datasz_max(pfileid,varid) > buff_tmp_sz) THEN
+      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
       IF (l_dbg) THEN
         WRITE(*,*) &
  &       c_nam//" : re-allocate buff_tmp for buff_sz = ", &
- &       datasz_max(pfileid,varid)
+ &       W_F(pfileid)%W_V(varid)%datasz_max
       ENDIF
       DEALLOCATE(buff_tmp)
-      ALLOCATE(buff_tmp(datasz_max(pfileid,varid)))
-      buff_tmp_sz = datasz_max(pfileid,varid)
+      ALLOCATE(buff_tmp(W_F(pfileid)%W_V(varid)%datasz_max))
+      buff_tmp_sz = W_F(pfileid)%W_V(varid)%datasz_max
     ENDIF
 !-
@@ -1903,20 +1939,20 @@
 !-- of the data at the same time. This should speed up things.
 !-
-    nbpt_out = datasz_max(pfileid,varid)
+    nbpt_out = W_F(pfileid)%W_V(varid)%datasz_max
     IF      (l1d) THEN
-      nbpt_in1 = datasz_in(pfileid,varid,1)
-      CALL mathop (sopps(pfileid,varid,1),nbpt_in1,pdata_1d, &
+      nbpt_in1 = W_F(pfileid)%W_V(varid)%datasz_in(1)
+      CALL mathop (W_F(pfileid)%W_V(varid)%sopps(1),nbpt_in1,pdata_1d, &
  &                 missing_val,nbindex,nindex, &
- &                 scal(pfileid,varid,1),nbpt_out,buff_tmp)
+ &                 W_F(pfileid)%W_V(varid)%scal(1),nbpt_out,buff_tmp)
     ELSE IF (l2d) THEN
-      nbpt_in2(1:2) = datasz_in(pfileid,varid,1:2)
-      CALL mathop (sopps(pfileid,varid,1),nbpt_in2,pdata_2d, &
+      nbpt_in2(1:2) = W_F(pfileid)%W_V(varid)%datasz_in(1:2)
+      CALL mathop (W_F(pfileid)%W_V(varid)%sopps(1),nbpt_in2,pdata_2d, &
  &                 missing_val,nbindex,nindex, &
- &                 scal(pfileid,varid,1),nbpt_out,buff_tmp)
+ &                 W_F(pfileid)%W_V(varid)%scal(1),nbpt_out,buff_tmp)
     ELSE IF (l3d) THEN
-      nbpt_in3(1:3) = datasz_in(pfileid,varid,1:3)
-      CALL mathop (sopps(pfileid,varid,1),nbpt_in3,pdata_3d, &
+      nbpt_in3(1:3) = W_F(pfileid)%W_V(varid)%datasz_in(1:3)
+      CALL mathop (W_F(pfileid)%W_V(varid)%sopps(1),nbpt_in3,pdata_3d, &
  &                 missing_val,nbindex,nindex, &
- &                 scal(pfileid,varid,1),nbpt_out,buff_tmp)
+ &                 W_F(pfileid)%W_V(varid)%scal(1),nbpt_out,buff_tmp)
     ENDIF
     CALL histwrite_real (pfileid,varid,pitau,nbpt_out, &
@@ -1927,9 +1963,9 @@
 !-
   IF ((TRIM(tmp_opp) /= "once").AND.(TRIM(tmp_opp) /= "never")) THEN
-    last_opp_chk(pfileid,varid) = pitau
-    last_wrt_chk(pfileid,varid) = pitau
-  ELSE
-    last_opp_chk(pfileid,varid) = -99
-    last_wrt_chk(pfileid,varid) = -99
+    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
   ENDIF
 !-----------------------
@@ -1950,5 +1986,5 @@
   LOGICAL,INTENT(IN) :: do_oper,do_write
 !-
-  INTEGER :: tsz,ncid,ncvarid,i,iret,ipt,itax,io,nbin,nbout
+  INTEGER :: tsz,nfid,nvid,i,iret,ipt,itax,io,nbin,nbout
   INTEGER :: nx,ny,nz,ky,kz,kt,kc
   INTEGER,DIMENSION(4) :: corner,edges
@@ -1964,5 +2000,5 @@
 !-
   IF (l_dbg) THEN
-    WRITE(*,*) "histwrite 0.0 : VAR : ",name(pfileid,varid)
+    WRITE(*,*) "histwrite 0.0 : VAR : ",W_F(pfileid)%W_V(varid)%v_name
     WRITE(*,*) "histwrite 0.0 : nbindex,nindex :", &
  &  nbindex,nindex(1:MIN(3,nbindex)),'...',nindex(MAX(1,nbindex-3):nbindex)
@@ -1971,7 +2007,7 @@
 ! The sizes which can be encoutered
 !-
-  tsz =  zsize(pfileid,varid,1) &
- &      *zsize(pfileid,varid,2) &
- &      *zsize(pfileid,varid,3)
+  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
@@ -2017,7 +2053,7 @@
       WRITE(*,*) "histwrite_real 1.1 allocate buff_tmp2 ",SIZE(buff_tmp)
     ENDIF
-    ALLOCATE(buff_tmp2(datasz_max(pfileid,varid)))
-    buff_tmp2_sz = datasz_max(pfileid,varid)
-  ELSE IF (datasz_max(pfileid,varid) > buff_tmp2_sz) THEN
+    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 : ", &
@@ -2025,10 +2061,10 @@
     ENDIF
     DEALLOCATE(buff_tmp2)
-    ALLOCATE(buff_tmp2(datasz_max(pfileid,varid)))
-    buff_tmp2_sz = datasz_max(pfileid,varid)
-  ENDIF
-!-
-  rtime = pitau * deltat(pfileid)
-  tmp_opp = topp(pfileid,varid)
+    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
@@ -2045,21 +2081,23 @@
 !--     we started in the interface routine
 !-
-    DO io = 2,nbopp(i,varid),2
+    DO io=2,W_F(i)%W_V(varid)%nbopp,2
       nbin = nbout
-      nbout = datasz_max(i,varid)
-      CALL mathop(sopps(i,varid,io),nbin,buff_tmp,missing_val, &
- &      nbindex,nindex,scal(i,varid,io),nbout,buff_tmp2)
+      nbout = W_F(i)%W_V(varid)%datasz_max
+      CALL mathop(W_F(i)%W_V(varid)%sopps(io),nbin,buff_tmp, &
+ &      missing_val,nbindex,nindex,W_F(i)%W_V(varid)%scal(io), &
+ &      nbout,buff_tmp2)
       IF (l_dbg) THEN
         WRITE(*,*) &
- &       "histwrite: 3.4a nbout : ",nbin,nbout,sopps(i,varid,io)
+ &       "histwrite: 3.4a nbout : ",nbin,nbout,W_F(i)%W_V(varid)%sopps(io)
       ENDIF
 !-
       nbin = nbout
-      nbout = datasz_max(i,varid)
-      CALL mathop(sopps(i,varid,io+1),nbin,buff_tmp2,missing_val, &
- &      nbindex,nindex,scal(i,varid,io+1),nbout,buff_tmp)
+      nbout = W_F(i)%W_V(varid)%datasz_max
+      CALL mathop(W_F(i)%W_V(varid)%sopps(io+1),nbin,buff_tmp2, &
+ &      missing_val,nbindex,nindex,W_F(i)%W_V(varid)%scal(io+1), &
+ &      nbout,buff_tmp)
       IF (l_dbg) THEN
         WRITE(*,*) &
- &       "histwrite: 3.4b nbout : ",nbin,nbout,sopps(i,varid,io+1)
+ &     "histwrite: 3.4b nbout : ",nbin,nbout,W_F(i)%W_V(varid)%sopps(io+1)
       ENDIF
     ENDDO
@@ -2071,40 +2109,50 @@
  &     "histwrite: 3.5 size(buff_tmp) : ",SIZE(buff_tmp)
       WRITE(*,*) &
- &     "histwrite: 3.5 slab in X :",zorig(i,varid,1),zsize(i,varid,1)
+ &     "histwrite: 3.5 slab in X :", &
+ &     W_F(i)%W_V(varid)%zorig(1),W_F(i)%W_V(varid)%zsize(1)
       WRITE(*,*) &
- &     "histwrite: 3.5 slab in Y :",zorig(i,varid,2),zsize(i,varid,2)
+ &     "histwrite: 3.5 slab in Y :", &
+ &     W_F(i)%W_V(varid)%zorig(2),W_F(i)%W_V(varid)%zsize(2)
       WRITE(*,*) &
- &     "histwrite: 3.5 slab in Z :",zorig(i,varid,3),zsize(i,varid,3)
+ &     "histwrite: 3.5 slab in Z :", &
+ &     W_F(i)%W_V(varid)%zorig(3),W_F(i)%W_V(varid)%zsize(3)
       WRITE(*,*) &
  &     "histwrite: 3.5 slab of input:", &
- &     scsize(i,varid,1),scsize(i,varid,2),scsize(i,varid,3)
+ &     W_F(i)%W_V(varid)%scsize(1), &
+ &     W_F(i)%W_V(varid)%scsize(2), &
+ &     W_F(i)%W_V(varid)%scsize(3)
     ENDIF
 !---
 !-- We have to consider blocks of contiguous data
 !---
-    nx=MAX(zsize(i,varid,1),1)
-    ny=MAX(zsize(i,varid,2),1)
-    nz=MAX(zsize(i,varid,3),1)
-    IF     (     (zorig(i,varid,1) == 1) &
-   &        .AND.(zsize(i,varid,1) == scsize(i,varid,1)) &
-   &        .AND.(zorig(i,varid,2) == 1) &
-   &        .AND.(zsize(i,varid,2) == scsize(i,varid,2))) THEN
-      kt = (zorig(i,varid,3)-1)*nx*ny
+    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 (     (zorig(i,varid,1) == 1) &
-   &        .AND.(zsize(i,varid,1) == scsize(i,varid,1))) THEN
+    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
       kc = -nx*ny
-      DO kz=zorig(i,varid,3),zorig(i,varid,3)+nz-1
+      DO kz=W_F(i)%W_V(varid)%zorig(3),W_F(i)%W_V(varid)%zorig(3)+nz-1
         kc = kc+nx*ny
-        kt = ((kz-1)*scsize(i,varid,2)+zorig(i,varid,2)-1)*nx
+        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)
       ENDDO
     ELSE
       kc = -nx
-      DO kz=zorig(i,varid,3),zorig(i,varid,3)+nz-1
-        DO ky=zorig(i,varid,2),zorig(i,varid,2)+ny-1
+      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
           kc = kc+nx
-          kt = ((kz-1)*scsize(i,varid,2)+ky-1)*scsize(i,varid,1) &
-   &          +zorig(i,varid,1)-1
+          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)
         ENDDO
@@ -2117,10 +2165,10 @@
  &    TRIM(tmp_opp),' ---- ',LEN_TRIM(tmp_opp),nbindex
 !-
-    IF (hist_calc_rng(pfileid,varid)) THEN
-      hist_minmax(pfileid,varid,1) = &
- &      MIN(hist_minmax(pfileid,varid,1), &
+    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))
-      hist_minmax(pfileid,varid,2) = &
- &      MAX(hist_minmax(pfileid,varid,2), &
+      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))
     ENDIF
@@ -2131,16 +2179,16 @@
     IF (l_dbg) WRITE(*,*) "histwrite: 5.0",pfileid,"tsz :",tsz
 !-
-    ipt = point(pfileid,varid)
+    ipt = W_F(pfileid)%W_V(varid)%point
 !-
 !   WRITE(*,*) 'OPE ipt, buffer :',pvarname,ipt,varid
 !-
     IF (     (TRIM(tmp_opp) /= "inst") &
-   &    .AND.(TRIM(tmp_opp) /= "once") ) THEN
+ &      .AND.(TRIM(tmp_opp) /= "once") ) THEN
       CALL moycum(tmp_opp,tsz,buffer(ipt:), &
-     &       buff_tmp2,nb_opp(pfileid,varid))
-    ENDIF
-!-
-    last_opp(pfileid,varid) = pitau
-    nb_opp(pfileid,varid) = nb_opp(pfileid,varid)+1
+ &           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
 !-
   ENDIF
@@ -2152,6 +2200,6 @@
   IF (do_write) THEN
 !-
-    ncvarid = ncvar_ids(pfileid,varid)
-    ncid = ncdf_ids(pfileid)
+    nfid = W_F(pfileid)%ncfid
+    nvid = W_F(pfileid)%W_V(varid)%ncvid
 !-
 !-- 6.1 Do the operations that are needed before writting
@@ -2160,6 +2208,7 @@
 !-
     IF (     (TRIM(tmp_opp) /= "inst") &
-   &    .AND.(TRIM(tmp_opp) /= "once") ) THEN
-      rtime = (rtime+last_wrt(pfileid,varid)*deltat(pfileid))/2.0
+ &      .AND.(TRIM(tmp_opp) /= "once") ) THEN
+      rtime = ( rtime &
+ &             +W_F(pfileid)%W_V(varid)%last_wrt*W_F(pfileid)%deltat)/2.0
     ENDIF
 !-
@@ -2167,16 +2216,16 @@
 !-
     IF (     (TRIM(tmp_opp) /= "l_max") &
-   &    .AND.(TRIM(tmp_opp) /= "l_min") &
-   &    .AND.(TRIM(tmp_opp) /= "once") ) THEN
+ &      .AND.(TRIM(tmp_opp) /= "l_min") &
+ &      .AND.(TRIM(tmp_opp) /= "once") ) THEN
 !-
       IF (l_dbg) WRITE(*,*) "histwrite: 6.2",pfileid
 !-
-      itax = var_axid(pfileid,varid)
-      itime = nb_wrt(pfileid,varid)+1
-!-
-      IF (tax_last(pfileid,itax) < itime) THEN
-        iret = NF90_PUT_VAR (ncid,tdimid(pfileid,itax),(/ rtime /), &
- &                            start=(/ itime /),count=(/ 1 /))
-        tax_last(pfileid,itax) = itime
+      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, &
+ &               (/ rtime /),start=(/ itime /),count=(/ 1 /))
+        W_F(pfileid)%W_V(itax)%tax_last = itime
       ENDIF
     ELSE
@@ -2188,43 +2237,43 @@
 !-
     IF (l_dbg) THEN
-      WRITE(*,*) "histwrite: 6.3",pfileid,ncid,ncvarid,varid,itime
-    ENDIF
-!-
-    IF (scsize(pfileid,varid,3) == 1) THEN
-      IF (regular(pfileid)) 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
         corner(1:4) = (/ 1,1,itime,0 /)
-        edges(1:4) = (/ zsize(pfileid,varid,1), &
- &                      zsize(pfileid,varid,2),1,0 /)
+        edges(1:4) = (/ W_F(pfileid)%W_V(varid)%zsize(1), &
+ &                      W_F(pfileid)%W_V(varid)%zsize(2),1,0 /)
       ELSE
         corner(1:4) = (/ 1,itime,0,0 /)
-        edges(1:4) = (/ zsize(pfileid,varid,1),1,0,0 /)
+        edges(1:4) = (/ W_F(pfileid)%W_V(varid)%zsize(1),1,0,0 /)
       ENDIF
     ELSE
-      IF (regular(pfileid)) THEN
+      IF (W_F(pfileid)%regular) THEN
         corner(1:4) = (/ 1,1,1,itime /)
-        edges(1:4) = (/ zsize(pfileid,varid,1), &
- &                      zsize(pfileid,varid,2), &
- &                      zsize(pfileid,varid,3),1 /)
+        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 /)
       ELSE
         corner(1:4) = (/ 1,1,itime,0 /)
-        edges(1:4) = (/ zsize(pfileid,varid,1), &
- &                      zsize(pfileid,varid,3),1,0 /)
+        edges(1:4) = (/ W_F(pfileid)%W_V(varid)%zsize(1), &
+ &                      W_F(pfileid)%W_V(varid)%zsize(3),1,0 /)
       ENDIF
     ENDIF
 !-
-    ipt = point(pfileid,varid)
+    ipt = W_F(pfileid)%W_V(varid)%point
 !-
     IF (     (TRIM(tmp_opp) /= "inst") &
  &      .AND.(TRIM(tmp_opp) /= "once") ) THEN
-      iret = NF90_PUT_VAR (ncid,ncvarid,buffer(ipt:), &
+      iret = NF90_PUT_VAR (nfid,nvid,buffer(ipt:), &
  &                       start=corner(1:4),count=edges(1:4))
     ELSE
-      iret = NF90_PUT_VAR (ncid,ncvarid,buff_tmp2, &
+      iret = NF90_PUT_VAR (nfid,nvid,buff_tmp2, &
  &                       start=corner(1:4),count=edges(1:4))
     ENDIF
 !-
-    last_wrt(pfileid,varid) = pitau
-    nb_wrt(pfileid,varid) = nb_wrt(pfileid,varid)+1
-    nb_opp(pfileid,varid) = 0
+    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
 !---
 !   After the write the file can be synchronized so that no data is
@@ -2233,5 +2282,5 @@
 !   needed here to switch to this mode.
 !---
-!   iret = NF90_SYNC (ncid)
+!   iret = NF90_SYNC (nfid)
 !-
   ENDIF
@@ -2281,8 +2330,8 @@
 !-
     IF (overlap(pfid) <= 0) THEN
-      IF (nb_var(pfid) > 6) THEN
-        overlap(pfid) = nb_var(pfid)/3*2
+      IF (W_F(pfid)%n_var > 6) THEN
+        overlap(pfid) = W_F(pfid)%n_var/3*2
       ELSE
-        overlap(pfid) = nb_var(pfid)
+        overlap(pfid) = W_F(pfid)%n_var
       ENDIF
     ENDIF
@@ -2290,5 +2339,5 @@
 !-- 1.1 Find the position of this string
 !-
-    CALL find_str (name(pfid,1:nb_var(pfid)),pvarname,pos)
+    CALL find_str (W_F(pfid)%W_V(1:W_F(pfid)%n_var)%v_name,pvarname,pos)
     IF (pos > 0) THEN
       pvid = pos
@@ -2323,5 +2372,5 @@
 !---- 1.3 Check if we have found the right overlap
 !-
-      IF (varseq_len(pfid) .GE. overlap(pfid)*2) THEN
+      IF (varseq_len(pfid) >= overlap(pfid)*2) THEN
 !-
 !------ We skip a few variables if needed as they could come
@@ -2351,6 +2400,6 @@
     pvid = varseq(pfid,nn)
 !-
-    IF (TRIM(name(pfid,pvid)) /= TRIM(pvarname)) THEN
-      CALL find_str (name(pfid,1:nb_var(pfid)),pvarname,pos)
+    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)
       IF (pos > 0) THEN
         pvid = pos
@@ -2371,5 +2420,5 @@
     ENDIF
 !-
-    IF (varseq_err(pfid) .GE. 10) THEN
+    IF (varseq_err(pfid) >= 10) THEN
       WRITE(str70,'("for file ",I3)') pfid
       CALL ipslerr (2,"histvar_seq", &
@@ -2400,5 +2449,5 @@
   INTEGER,INTENT(in),OPTIONAL :: file
 !-
-  INTEGER :: ifile,ncid,iret
+  INTEGER :: ifile,nfid,iret
 !-
   LOGICAL :: file_exists
@@ -2411,5 +2460,5 @@
 ! 1.The loop on files to synchronise
 !-
-  DO ifile = 1,nb_files
+  DO ifile=1,nb_files
 !-
     IF (PRESENT(file)) THEN
@@ -2423,6 +2472,6 @@
         WRITE(*,*) 'Synchronising specified file number :',file
       ENDIF
-      ncid = ncdf_ids(ifile)
-      iret = NF90_SYNC (ncid)
+      nfid = W_F(ifile)%ncfid
+      iret = NF90_SYNC (nfid)
     ENDIF
 !-
@@ -2443,5 +2492,5 @@
   INTEGER,INTENT(in),OPTIONAL :: fid
 !-
-  INTEGER :: ifile,ncid,iret,iv
+  INTEGER :: ifile,nfid,nvid,iret,iv
   INTEGER :: start_loop,end_loop
   CHARACTER(LEN=70) :: str70
@@ -2462,24 +2511,25 @@
   DO ifile=start_loop,end_loop
     IF (l_dbg) WRITE(*,*) 'Closing specified file number :',ifile
-    ncid = ncdf_ids(ifile)
-    iret = NF90_REDEF (ncid)
+    nfid = W_F(ifile)%ncfid
+    iret = NF90_REDEF (nfid)
 !---
 !-- 1. Loop on the number of variables to add some final information
 !---
-    IF (l_dbg) WRITE(*,*) 'Entering loop on vars : ',nb_var(ifile)
-    DO iv=1,nb_var(ifile)
-      IF (hist_wrt_rng(ifile,iv)) THEN
+    IF (l_dbg) WRITE(*,*) 'Entering loop on vars : ',W_F(ifile)%n_var
+    DO iv=1,W_F(ifile)%n_var
+      IF (W_F(ifile)%W_V(iv)%hist_wrt_rng) THEN
         IF (l_dbg) THEN
           WRITE(*,*) 'min value for file :',ifile,' var n. :',iv, &
-         &           ' is : ',hist_minmax(ifile,iv,1)
+         &           ' is : ',W_F(ifile)%W_V(iv)%hist_minmax(1)
           WRITE(*,*) 'max value for file :',ifile,' var n. :',iv, &
-         &           ' is : ',hist_minmax(ifile,iv,2)
+         &           ' is : ',W_F(ifile)%W_V(iv)%hist_minmax(2)
         ENDIF
-        IF (hist_calc_rng(ifile,iv)) THEN
+        IF (W_F(ifile)%W_V(iv)%hist_calc_rng) THEN
 !-------- Put the min and max values on the file
-          iret = NF90_PUT_ATT (ncid,ncvar_ids(ifile,iv),'valid_min', &
- &                             REAL(hist_minmax(ifile,iv,1),KIND=4))
-          iret = NF90_PUT_ATT (ncid,ncvar_ids(ifile,iv),'valid_max', &
- &                             REAL(hist_minmax(ifile,iv,2),KIND=4))
+          nvid = W_F(ifile)%W_V(iv)%ncvid
+          iret = NF90_PUT_ATT (nfid,nvid,'valid_min', &
+ &                 REAL(W_F(ifile)%W_V(iv)%hist_minmax(1),KIND=4))
+          iret = NF90_PUT_ATT (nfid,nvid,'valid_max', &
+ &                 REAL(W_F(ifile)%W_V(iv)%hist_minmax(2),KIND=4))
         ENDIF
       ENDIF
@@ -2488,6 +2538,6 @@
 !-- 2. Close the file
 !---
-    IF (l_dbg) WRITE(*,*) 'close file :',ncid
-    iret = NF90_CLOSE (ncid)
+    IF (l_dbg) WRITE(*,*) 'close file :',nfid
+    iret = NF90_CLOSE (nfid)
     IF (iret /= NF90_NOERR) THEN
       WRITE(str70,'("This file has been already closed :",I3)') ifile
