Changeset 856 for IOIPSL/trunk


Ignore:
Timestamp:
12/16/09 11:30:32 (15 years ago)
Author:
bellier
Message:

New handling of the time_buffer : one buffer for each variable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • IOIPSL/trunk/src/histcom.f90

    r845 r856  
    5555!- 
    5656!- INPUT 
    57 !- pfileid  : The ID of the file on which this variable is to be, 
     57!- idf      : The ID of the file on which this variable is to be, 
    5858!-            written. The variable should have been defined in 
    5959!-            this file before. 
     
    108108  REAL :: freq_opp,freq_wrt 
    109109  INTEGER :: & 
    110  &  last_opp,last_wrt,last_opp_chk,last_wrt_chk,nb_opp,nb_wrt,point 
     110 &  last_opp,last_wrt,last_opp_chk,last_wrt_chk,nb_opp,nb_wrt 
    111111!- For future optimization 
     112  REAL,ALLOCATABLE,DIMENSION(:) :: t_bf 
    112113!#  REAL,ALLOCATABLE,DIMENSION(:) :: V_1_D 
    113114!#  REAL,ALLOCATABLE,DIMENSION(:,:) :: V_2_D 
     
    148149  INTEGER,SAVE :: nb_files=0 
    149150!- 
    150 ! Book keeping for the buffers 
    151 !- 
    152   INTEGER,SAVE :: buff_pos=0 
    153   REAL,ALLOCATABLE,DIMENSION(:),SAVE :: buffer 
    154 !- 
    155151! A list of functions which require special action 
    156152! (Needs to be updated when functions are added 
     
    169165 & (pfilename,pim,plon,pjm,plat,          & 
    170166 &  par_orix,par_szx,par_oriy,par_szy,    & 
    171  &  pitau0,pdate0,pdeltat,phoriid,pfileid,domain_id,nb_bits) 
     167 &  pitau0,pdate0,pdeltat,phoriid,idf,domain_id,nb_bits) 
    172168!--------------------------------------------------------------------- 
    173169!- This is just an interface for histbeg_regular in case when 
     
    201197!- 
    202198!- phoriid   : ID of the horizontal grid 
    203 !- pfileid   : ID of the netcdf file 
     199!- idf       : ID of the netcdf file 
    204200!- 
    205201!- Optional INPUT arguments 
     
    227223  INTEGER,INTENT(IN) :: pitau0 
    228224  REAL,INTENT(IN) :: pdate0,pdeltat 
    229   INTEGER,INTENT(OUT) :: pfileid,phoriid 
     225  INTEGER,INTENT(OUT) :: idf,phoriid 
    230226  INTEGER,INTENT(IN),OPTIONAL :: domain_id,nb_bits 
    231227!- 
     
    245241 &  (pfilename,pim,lon_tmp,pjm,lat_tmp, & 
    246242 &   par_orix,par_szx,par_oriy,par_szy, & 
    247  &   pitau0,pdate0,pdeltat,phoriid,pfileid, & 
     243 &   pitau0,pdate0,pdeltat,phoriid,idf, & 
    248244 &   .TRUE.,domain_id,nb_bits) 
    249245!- 
     
    255251 & (pfilename,pim,plon,pjm,plat,           & 
    256252 &  par_orix,par_szx,par_oriy,par_szy,     & 
    257  &  pitau0,pdate0,pdeltat,phoriid,pfileid, & 
     253 &  pitau0,pdate0,pdeltat,phoriid,idf, & 
    258254 &  opt_rectilinear,domain_id,nb_bits) 
    259255!--------------------------------------------------------------------- 
     
    289285!- 
    290286!- phoriid   : ID of the horizontal grid 
    291 !- pfileid   : ID of the netcdf file 
     287!- idf       : ID of the netcdf file 
    292288!- 
    293289!- Optional INPUT arguments 
     
    315311  INTEGER,INTENT(IN) :: pitau0 
    316312  REAL,INTENT(IN) :: pdate0,pdeltat 
    317   INTEGER,INTENT(OUT) :: pfileid,phoriid 
     313  INTEGER,INTENT(OUT) :: idf,phoriid 
    318314  LOGICAL,INTENT(IN),OPTIONAL :: opt_rectilinear 
    319315  INTEGER,INTENT(IN),OPTIONAL :: domain_id,nb_bits 
     
    335331   &  'in histcom.f90 in order to accomodate all these files',' ') 
    336332  ENDIF 
    337   pfileid = nb_files 
     333  idf = nb_files 
    338334!- 
    339335! 1.0 Transfering into the common for future use 
     
    341337  IF (l_dbg) WRITE(*,*) "histbeg_regular 1.0" 
    342338!- 
    343   W_F(pfileid)%itau0  = pitau0 
    344   W_F(pfileid)%date0  = pdate0 
    345   W_F(pfileid)%deltat = pdeltat 
     339  W_F(idf)%itau0  = pitau0 
     340  W_F(idf)%date0  = pdate0 
     341  W_F(idf)%deltat = pdeltat 
    346342!- 
    347343  IF (PRESENT(opt_rectilinear)) THEN 
     
    355351  IF (l_dbg) WRITE(*,*) "histbeg_regular 2.0" 
    356352!- 
    357   W_F(pfileid)%n_var = 0 
    358   W_F(pfileid)%n_tax = 0 
    359   W_F(pfileid)%n_hax = 0 
    360   W_F(pfileid)%n_zax = 0 
    361 !- 
    362   W_F(pfileid)%slab_ori(1:2) = (/ par_orix,par_oriy /) 
    363   W_F(pfileid)%slab_sz(1:2)  = (/ par_szx, par_szy  /) 
     353  W_F(idf)%n_var = 0 
     354  W_F(idf)%n_tax = 0 
     355  W_F(idf)%n_hax = 0 
     356  W_F(idf)%n_zax = 0 
     357!- 
     358  W_F(idf)%slab_ori(1:2) = (/ par_orix,par_oriy /) 
     359  W_F(idf)%slab_sz(1:2)  = (/ par_szx, par_szy  /) 
    364360!- 
    365361! 3.0 Opening netcdf file and defining dimensions 
     
    392388!- 
    393389  IF (rectilinear) THEN 
    394     iret = NF90_DEF_DIM (nfid,'lon',par_szx,W_F(pfileid)%xid) 
    395     iret = NF90_DEF_DIM (nfid,'lat',par_szy,W_F(pfileid)%yid) 
    396   ELSE 
    397     iret = NF90_DEF_DIM (nfid,'x',par_szx,W_F(pfileid)%xid) 
    398     iret = NF90_DEF_DIM (nfid,'y',par_szy,W_F(pfileid)%yid) 
     390    iret = NF90_DEF_DIM (nfid,'lon',par_szx,W_F(idf)%xid) 
     391    iret = NF90_DEF_DIM (nfid,'lat',par_szy,W_F(idf)%yid) 
     392  ELSE 
     393    iret = NF90_DEF_DIM (nfid,'x',par_szx,W_F(idf)%xid) 
     394    iret = NF90_DEF_DIM (nfid,'y',par_szy,W_F(idf)%yid) 
    399395  ENDIF 
    400396!- 
     
    417413!- 
    418414  IF (PRESENT(domain_id)) THEN 
    419     W_F(pfileid)%dom_id_svg = domain_id 
    420   ENDIF 
    421   W_F(pfileid)%ncfid = nfid 
    422   W_F(pfileid)%full_size(1:2) = (/ pim,pjm /) 
     415    W_F(idf)%dom_id_svg = domain_id 
     416  ENDIF 
     417  W_F(idf)%ncfid = nfid 
     418  W_F(idf)%full_size(1:2) = (/ pim,pjm /) 
    423419!- 
    424420! 6.0 storing the geographical coordinates 
    425421!- 
    426   W_F(pfileid)%regular=.TRUE. 
    427 !- 
    428   CALL histhori_regular (pfileid,pim,plon,pjm,plat, & 
     422  W_F(idf)%regular=.TRUE. 
     423!- 
     424  CALL histhori_regular (idf,pim,plon,pjm,plat, & 
    429425 &  ' ','Default grid',phoriid,rectilinear) 
    430426!----------------------------- 
     
    433429SUBROUTINE histbeg_irregular & 
    434430 &  (pfilename,pim,plon,plon_bounds,plat,plat_bounds,   & 
    435  &   pitau0,pdate0,pdeltat,phoriid,pfileid,domain_id,nb_bits) 
     431 &   pitau0,pdate0,pdeltat,phoriid,idf,domain_id,nb_bits) 
    436432!--------------------------------------------------------------------- 
    437433!- This subroutine initializes a netcdf file and returns the ID. 
     
    458454!- 
    459455!- phoriid   : ID of the horizontal grid 
    460 !- pfileid   : ID of the netcdf file 
     456!- idf       : ID of the netcdf file 
    461457!- 
    462458!- Optional INPUT arguments 
     
    483479  INTEGER,INTENT(IN) :: pitau0 
    484480  REAL,INTENT(IN) :: pdate0,pdeltat 
    485   INTEGER,INTENT(OUT) :: pfileid,phoriid 
     481  INTEGER,INTENT(OUT) :: idf,phoriid 
    486482  INTEGER,INTENT(IN),OPTIONAL :: domain_id,nb_bits 
    487483!- 
     
    501497 &    'in histcom.f90 in order to accomodate all these files',' ') 
    502498  ENDIF 
    503   pfileid = nb_files 
     499  idf = nb_files 
    504500!- 
    505501! 1.0 Transfering into the common for future use 
     
    507503  IF (l_dbg) WRITE(*,*) "histbeg_irregular 1.0" 
    508504!- 
    509   W_F(pfileid)%itau0  = pitau0 
    510   W_F(pfileid)%date0  = pdate0 
    511   W_F(pfileid)%deltat = pdeltat 
     505  W_F(idf)%itau0  = pitau0 
     506  W_F(idf)%date0  = pdate0 
     507  W_F(idf)%deltat = pdeltat 
    512508!- 
    513509! 2.0 Initializes all variables for this file 
     
    515511  IF (l_dbg) WRITE(*,*) "histbeg_irregular 2.0" 
    516512!- 
    517   W_F(pfileid)%n_var = 0 
    518   W_F(pfileid)%n_tax = 0 
    519   W_F(pfileid)%n_hax = 0 
    520   W_F(pfileid)%n_zax = 0 
    521 !- 
    522   W_F(pfileid)%slab_ori(1:2) = (/ 1,1 /) 
    523   W_F(pfileid)%slab_sz(1:2)  = (/ pim,1 /) 
     513  W_F(idf)%n_var = 0 
     514  W_F(idf)%n_tax = 0 
     515  W_F(idf)%n_hax = 0 
     516  W_F(idf)%n_zax = 0 
     517!- 
     518  W_F(idf)%slab_ori(1:2) = (/ 1,1 /) 
     519  W_F(idf)%slab_sz(1:2)  = (/ pim,1 /) 
    524520!- 
    525521! 3.0 Opening netcdf file and defining dimensions 
     
    551547  iret = NF90_CREATE (file,m_c,nfid) 
    552548!- 
    553   iret = NF90_DEF_DIM (nfid,'x',pim,W_F(pfileid)%xid) 
    554   W_F(pfileid)%yid = 0 
     549  iret = NF90_DEF_DIM (nfid,'x',pim,W_F(idf)%xid) 
     550  W_F(idf)%yid = 0 
    555551!- 
    556552! 4.0 Declaring the geographical coordinates and other attributes 
     
    572568!- 
    573569  IF (PRESENT(domain_id)) THEN 
    574     W_F(pfileid)%dom_id_svg = domain_id 
    575   ENDIF 
    576   W_F(pfileid)%ncfid = nfid 
    577   W_F(pfileid)%full_size(1:2) = (/ pim,1 /) 
     570    W_F(idf)%dom_id_svg = domain_id 
     571  ENDIF 
     572  W_F(idf)%ncfid = nfid 
     573  W_F(idf)%full_size(1:2) = (/ pim,1 /) 
    578574!- 
    579575! 6.0 storing the geographical coordinates 
    580576!- 
    581   W_F(pfileid)%regular=.FALSE. 
     577  W_F(idf)%regular=.FALSE. 
    582578!- 
    583579  CALL histhori_irregular & 
    584  &  (pfileid,pim,plon,plon_bounds,plat,plat_bounds, & 
     580 &  (idf,pim,plon,plon_bounds,plat,plat_bounds, & 
    585581 &   ' ','Default grid',phoriid) 
    586582!------------------------------- 
     
    588584!=== 
    589585SUBROUTINE histhori_regular & 
    590  &  (pfileid,pim,plon,pjm,plat,phname,phtitle,phid,opt_rectilinear) 
     586 &  (idf,pim,plon,pjm,plat,phname,phtitle,phid,opt_rectilinear) 
    591587!--------------------------------------------------------------------- 
    592588!- This subroutine is made to declare a new horizontale grid. 
     
    600596!- INPUT 
    601597!- 
    602 !- pfileid : The id of the file to which the grid should be added 
     598!- idf    : The id of the file to which the grid should be added 
    603599!- pim     : Size in the longitude direction 
    604600!- plon    : The longitudes 
     
    619615  IMPLICIT NONE 
    620616!- 
    621   INTEGER,INTENT(IN) :: pfileid,pim,pjm 
     617  INTEGER,INTENT(IN) :: idf,pim,pjm 
    622618  REAL,INTENT(IN),DIMENSION(pim,pjm) :: plon,plat 
    623619  CHARACTER(LEN=*),INTENT(IN) :: phname,phtitle 
     
    639635! 1.0 Check that all fits in the buffers 
    640636!- 
    641   IF (    (pim /= W_F(pfileid)%full_size(1)) & 
    642  &    .OR.(pjm /= W_F(pfileid)%full_size(2)) ) THEN 
     637  IF (    (pim /= W_F(idf)%full_size(1)) & 
     638 &    .OR.(pjm /= W_F(idf)%full_size(2)) ) THEN 
    643639    CALL ipslerr (3,"histhori", & 
    644640 &   'The new horizontal grid does not have the same size', & 
     
    657653  IF (l_dbg) WRITE(*,*) "histhori_regular 1.0" 
    658654!- 
    659   nfid = W_F(pfileid)%ncfid 
     655  nfid = W_F(idf)%ncfid 
    660656!- 
    661657  ndim = 2 
    662   dims(1:2) = (/ W_F(pfileid)%xid,W_F(pfileid)%yid /) 
     658  dims(1:2) = (/ W_F(idf)%xid,W_F(idf)%yid /) 
    663659!- 
    664660  tmp_name = phname 
    665661  IF (rectilinear) THEN 
    666     IF (W_F(pfileid)%n_hax == 0) THEN 
     662    IF (W_F(idf)%n_hax == 0) THEN 
    667663      lon_name = 'lon' 
    668664      lat_name = 'lat' 
     
    672668    ENDIF 
    673669  ELSE 
    674     IF (W_F(pfileid)%n_hax == 0) THEN 
     670    IF (W_F(idf)%n_hax == 0) THEN 
    675671      lon_name = 'nav_lon' 
    676672      lat_name = 'nav_lat' 
     
    683679! 1.2 Save the informations 
    684680!- 
    685   phid = W_F(pfileid)%n_hax+1 
    686   W_F(pfileid)%n_hax = phid 
    687   W_F(pfileid)%hax_name(phid,1:2) = (/ lon_name,lat_name /) 
     681  phid = W_F(idf)%n_hax+1 
     682  W_F(idf)%n_hax = phid 
     683  W_F(idf)%hax_name(phid,1:2) = (/ lon_name,lat_name /) 
    688684  tmp_title = phtitle 
    689685!- 
     
    694690  IF (rectilinear) THEN 
    695691    ndim = 1 
    696     dims(1:1) = (/ W_F(pfileid)%xid /) 
     692    dims(1:1) = (/ W_F(idf)%xid /) 
    697693  ENDIF 
    698694  iret = NF90_DEF_VAR (nfid,lon_name,NF90_FLOAT,dims(1:ndim),nlonid) 
     
    715711  IF (rectilinear) THEN 
    716712    ndim = 1 
    717     dims(1:1) = (/ W_F(pfileid)%yid /) 
     713    dims(1:1) = (/ W_F(idf)%yid /) 
    718714  ENDIF 
    719715  iret = NF90_DEF_VAR (nfid,lat_name,NF90_FLOAT,dims(1:ndim),nlatid) 
     
    736732  IF (l_dbg) WRITE(*,*) "histhori_regular 4.0" 
    737733!- 
    738   orix = W_F(pfileid)%slab_ori(1) 
    739   oriy = W_F(pfileid)%slab_ori(2) 
    740   par_szx = W_F(pfileid)%slab_sz(1) 
    741   par_szy = W_F(pfileid)%slab_sz(2) 
     734  orix = W_F(idf)%slab_ori(1) 
     735  oriy = W_F(idf)%slab_ori(2) 
     736  par_szx = W_F(idf)%slab_sz(1) 
     737  par_szy = W_F(idf)%slab_sz(2) 
    742738!- 
    743739! Transfer the longitude 
     
    764760!=== 
    765761SUBROUTINE histhori_irregular & 
    766  &  (pfileid,pim,plon,plon_bounds,plat,plat_bounds, & 
     762 &  (idf,pim,plon,plon_bounds,plat,plat_bounds, & 
    767763 &   phname,phtitle,phid) 
    768764!--------------------------------------------------------------------- 
     
    777773!- INPUT 
    778774!- 
    779 !- pfileid     : The id of the file to which the grid should be added 
     775!- idf         : The id of the file to which the grid should be added 
    780776!- pim         : Size in the longitude direction 
    781777!- plon        : The longitudes 
     
    792788  IMPLICIT NONE 
    793789!- 
    794   INTEGER,INTENT(IN) :: pfileid,pim 
     790  INTEGER,INTENT(IN) :: idf,pim 
    795791  REAL,DIMENSION(pim),INTENT(IN) :: plon,plat 
    796792  REAL,DIMENSION(:,:),INTENT(IN) :: plon_bounds,plat_bounds 
     
    814810! 1.0 Check that all fits in the buffers 
    815811!- 
    816   IF (    (pim /= W_F(pfileid)%full_size(1)) & 
    817  &    .OR.(W_F(pfileid)%full_size(2) /= 1) ) THEN 
     812  IF (    (pim /= W_F(idf)%full_size(1)) & 
     813 &    .OR.(W_F(idf)%full_size(2) /= 1) ) THEN 
    818814    CALL ipslerr (3,"histhori", & 
    819815 &   'The new horizontal grid does not have the same size', & 
     
    826822  IF (l_dbg) WRITE(*,*) 'histhori_irregular 1.0' 
    827823!- 
    828   nfid = W_F(pfileid)%ncfid 
     824  nfid = W_F(idf)%ncfid 
    829825!- 
    830826  IF     (SIZE(plon_bounds,DIM=1) == pim) THEN 
     
    845841  iret = NF90_DEF_DIM (nfid,'nbnd',nbbounds,twoid) 
    846842  ndim = 1 
    847   dims(1) = W_F(pfileid)%xid 
     843  dims(1) = W_F(idf)%xid 
    848844  ndimb = 2 
    849   dimsb(1:2) = (/ twoid,W_F(pfileid)%xid /) 
     845  dimsb(1:2) = (/ twoid,W_F(idf)%xid /) 
    850846!- 
    851847  tmp_name = phname 
    852   IF (W_F(pfileid)%n_hax == 0) THEN 
     848  IF (W_F(idf)%n_hax == 0) THEN 
    853849    lon_name = 'nav_lon' 
    854850    lat_name = 'nav_lat' 
     
    862858! 1.2 Save the informations 
    863859!- 
    864   phid = W_F(pfileid)%n_hax+1 
    865   W_F(pfileid)%n_hax = phid 
    866   W_F(pfileid)%hax_name(phid,1:2) = (/ lon_name,lat_name /) 
     860  phid = W_F(idf)%n_hax+1 
     861  W_F(idf)%n_hax = phid 
     862  W_F(idf)%hax_name(phid,1:2) = (/ lon_name,lat_name /) 
    867863  tmp_title = phtitle 
    868864!- 
     
    949945END SUBROUTINE histhori_irregular 
    950946!=== 
    951 SUBROUTINE histvert (pfileid,pzaxname,pzaxtitle,pzaxunit, & 
     947SUBROUTINE histvert (idf,pzaxname,pzaxtitle,pzaxunit, & 
    952948 &                   pzsize,pzvalues,pzaxid,pdirect) 
    953949!--------------------------------------------------------------------- 
     
    959955!- INPUT 
    960956!- 
    961 !- pfileid  : ID of the file the variable should be archived in 
     957!- idf      : ID of the file the variable should be archived in 
    962958!- pzaxname : Name of the vertical axis 
    963959!- pzaxtitle: title of the vertical axis 
     
    978974  IMPLICIT NONE 
    979975!- 
    980   INTEGER,INTENT(IN) :: pfileid,pzsize 
     976  INTEGER,INTENT(IN) :: idf,pzsize 
    981977  CHARACTER(LEN=*),INTENT(IN) :: pzaxname,pzaxunit,pzaxtitle 
    982978  REAL,INTENT(IN) :: pzvalues(pzsize) 
     
    10221018  ENDIF 
    10231019!- 
    1024   IF (W_F(pfileid)%n_zax+1 > nb_zax_max) THEN 
     1020  IF (W_F(idf)%n_zax+1 > nb_zax_max) THEN 
    10251021    CALL ipslerr (3,"histvert", & 
    10261022   &  'Table of vertical axes too small. You should increase ',& 
     
    10291025  ENDIF 
    10301026!- 
    1031   iv = W_F(pfileid)%n_zax 
     1027  iv = W_F(idf)%n_zax 
    10321028  IF (iv > 1) THEN 
    1033     CALL find_str (W_F(pfileid)%zax_name(1:iv-1),pzaxname,pos) 
     1029    CALL find_str (W_F(idf)%zax_name(1:iv-1),pzaxname,pos) 
    10341030  ELSE 
    10351031    pos = 0 
     
    10381034  IF (pos > 0) THEN 
    10391035    WRITE(str71,'("Check variable ",A," in file",I3)') & 
    1040  &    TRIM(pzaxname),pfileid 
     1036 &    TRIM(pzaxname),idf 
    10411037    CALL ipslerr (3,"histvert", & 
    10421038 &    "Vertical axis already exists",TRIM(str71), & 
     
    10441040  ENDIF 
    10451041!- 
    1046   iv = W_F(pfileid)%n_zax+1 
     1042  iv = W_F(idf)%n_zax+1 
    10471043!- 
    10481044! 2.0 Add the information to the file 
     
    10511047 &  WRITE(*,*) "histvert : 2.0 Add the information to the file" 
    10521048!- 
    1053   nfid = W_F(pfileid)%ncfid 
     1049  nfid = W_F(idf)%ncfid 
    10541050!- 
    10551051  leng = MIN(LEN_TRIM(pzaxname),20) 
     
    10841080  &  WRITE(*,*) "histvert : 3.0 add the information to the common" 
    10851081!- 
    1086   W_F(pfileid)%n_zax = iv 
    1087   W_F(pfileid)%zax_size(iv) = pzsize 
    1088   W_F(pfileid)%zax_name(iv) = pzaxname 
    1089   W_F(pfileid)%zax_ids(iv) = zaxid_tmp 
     1082  W_F(idf)%n_zax = iv 
     1083  W_F(idf)%zax_size(iv) = pzsize 
     1084  W_F(idf)%zax_name(iv) = pzaxname 
     1085  W_F(idf)%zax_ids(iv) = zaxid_tmp 
    10901086  pzaxid = iv 
    10911087!---------------------- 
     
    10931089!=== 
    10941090SUBROUTINE histdef & 
    1095  &  (pfileid,pvarname,ptitle,punit, & 
     1091 &  (idf,pvarname,ptitle,punit, & 
    10961092 &   pxsize,pysize,phoriid,pzsize,par_oriz,par_szz,pzid, & 
    10971093 &   xtype,popp,pfreq_opp,pfreq_wrt,var_range,standard_name) 
     
    11061102!- INPUT 
    11071103!- 
    1108 !- pfileid  : ID of the file the variable should be archived in 
     1104!- idf      : ID of the file the variable should be archived in 
    11091105!- pvarname : Name of the variable, short and easy to remember 
    11101106!- ptitle   : Full name of the variable 
     
    11461142  IMPLICIT NONE 
    11471143!- 
    1148   INTEGER,INTENT(IN) :: pfileid,pxsize,pysize,pzsize,pzid 
     1144  INTEGER,INTENT(IN) :: idf,pxsize,pysize,pzsize,pzid 
    11491145  INTEGER,INTENT(IN) :: par_oriz,par_szz,xtype,phoriid 
    11501146  CHARACTER(LEN=*),INTENT(IN) :: pvarname,punit,popp,ptitle 
     
    11531149  CHARACTER(LEN=*),OPTIONAL,INTENT(IN) :: standard_name 
    11541150!- 
    1155   INTEGER :: iv,i 
     1151  INTEGER :: iv 
    11561152  CHARACTER(LEN=70) :: str70,str71,str72 
    11571153  CHARACTER(LEN=20) :: tmp_name 
     
    11671163  ex_topps = 'ave, inst, t_min, t_max, t_sum, once, never, l_max, l_min' 
    11681164!- 
    1169   W_F(pfileid)%n_var = W_F(pfileid)%n_var+1 
    1170   iv = W_F(pfileid)%n_var 
     1165  W_F(idf)%n_var = W_F(idf)%n_var+1 
     1166  iv = W_F(idf)%n_var 
    11711167!- 
    11721168  IF (iv > nb_var_max) THEN 
     
    11831179!- 
    11841180  IF (iv > 1) THEN 
    1185     CALL find_str (W_F(pfileid)%W_V(1:iv-1)%v_name,pvarname,pos) 
     1181    CALL find_str (W_F(idf)%W_V(1:iv-1)%v_name,pvarname,pos) 
    11861182  ELSE 
    11871183    pos = 0 
     
    11911187    str70 = "Variable already exists" 
    11921188    WRITE(str71,'("Check variable  ",a," in file",I3)') & 
    1193  &    TRIM(pvarname),pfileid 
     1189 &    TRIM(pvarname),idf 
    11941190    str72 = "Can also be a wrong file ID in another declaration" 
    11951191    CALL ipslerr (3,"histdef",str70,str71,str72) 
    11961192  ENDIF 
    11971193!- 
    1198   W_F(pfileid)%W_V(iv)%v_name = pvarname 
    1199   W_F(pfileid)%W_V(iv)%title = ptitle 
    1200   W_F(pfileid)%W_V(iv)%unit_name = punit 
     1194  W_F(idf)%W_V(iv)%v_name = pvarname 
     1195  W_F(idf)%W_V(iv)%title = ptitle 
     1196  W_F(idf)%W_V(iv)%unit_name = punit 
    12011197  IF (PRESENT(standard_name)) THEN 
    1202     W_F(pfileid)%W_V(iv)%std_name = standard_name 
    1203   ELSE 
    1204     W_F(pfileid)%W_V(iv)%std_name = ptitle 
    1205   ENDIF 
    1206   tmp_name = W_F(pfileid)%W_V(iv)%v_name 
     1198    W_F(idf)%W_V(iv)%std_name = standard_name 
     1199  ELSE 
     1200    W_F(idf)%W_V(iv)%std_name = ptitle 
     1201  ENDIF 
     1202  tmp_name = W_F(idf)%W_V(iv)%v_name 
    12071203!- 
    12081204! 1.1 decode the operations 
    12091205!- 
    1210   W_F(pfileid)%W_V(iv)%fullop = popp 
     1206  W_F(idf)%W_V(iv)%fullop = popp 
    12111207  CALL buildop & 
    1212  &  (TRIM(popp),ex_topps,W_F(pfileid)%W_V(iv)%topp,missing_val, & 
    1213  &   W_F(pfileid)%W_V(iv)%sopp,W_F(pfileid)%W_V(iv)%scal, & 
    1214  &   W_F(pfileid)%W_V(iv)%nbopp) 
     1208 &  (TRIM(popp),ex_topps,W_F(idf)%W_V(iv)%topp,missing_val, & 
     1209 &   W_F(idf)%W_V(iv)%sopp,W_F(idf)%W_V(iv)%scal, & 
     1210 &   W_F(idf)%W_V(iv)%nbopp) 
    12151211!- 
    12161212! 1.2 If we have an even number of operations 
    12171213!     then we need to add identity 
    12181214!- 
    1219   IF ( MOD(W_F(pfileid)%W_V(iv)%nbopp,2) == 0) THEN 
    1220     W_F(pfileid)%W_V(iv)%nbopp = W_F(pfileid)%W_V(iv)%nbopp+1 
    1221     W_F(pfileid)%W_V(iv)%sopp(W_F(pfileid)%W_V(iv)%nbopp) = 'ident' 
    1222     W_F(pfileid)%W_V(iv)%scal(W_F(pfileid)%W_V(iv)%nbopp) = missing_val 
     1215  IF ( MOD(W_F(idf)%W_V(iv)%nbopp,2) == 0) THEN 
     1216    W_F(idf)%W_V(iv)%nbopp = W_F(idf)%W_V(iv)%nbopp+1 
     1217    W_F(idf)%W_V(iv)%sopp(W_F(idf)%W_V(iv)%nbopp) = 'ident' 
     1218    W_F(idf)%W_V(iv)%scal(W_F(idf)%W_V(iv)%nbopp) = missing_val 
    12231219  ENDIF 
    12241220!- 
     
    12261222!- 
    12271223  IF (xtype == hist_r8) THEN 
    1228     W_F(pfileid)%W_V(iv)%v_typ = hist_r8 
    1229   ELSE 
    1230     W_F(pfileid)%W_V(iv)%v_typ = hist_r4 
     1224    W_F(idf)%W_V(iv)%v_typ = hist_r8 
     1225  ELSE 
     1226    W_F(idf)%W_V(iv)%v_typ = hist_r4 
    12311227  ENDIF 
    12321228!- 
     
    12341230!- 
    12351231  IF (l_dbg) THEN 
    1236     WRITE(*,*) "histdef : 2.0",pfileid,iv,W_F(pfileid)%W_V(iv)%nbopp, & 
    1237  &    W_F(pfileid)%W_V(iv)%sopp(1:W_F(pfileid)%W_V(iv)%nbopp), & 
    1238  &    W_F(pfileid)%W_V(iv)%scal(1:W_F(pfileid)%W_V(iv)%nbopp) 
    1239   ENDIF 
    1240 !- 
    1241   W_F(pfileid)%W_V(iv)%scsize(1:3) = (/ pxsize,pysize,pzsize /) 
    1242   W_F(pfileid)%W_V(iv)%zorig(1:3) = & 
    1243  &  (/ W_F(pfileid)%slab_ori(1),W_F(pfileid)%slab_ori(2),par_oriz /) 
    1244   W_F(pfileid)%W_V(iv)%zsize(1:3) = & 
    1245  &  (/ W_F(pfileid)%slab_sz(1),W_F(pfileid)%slab_sz(2),par_szz /) 
     1232    WRITE(*,*) "histdef : 2.0",idf,iv,W_F(idf)%W_V(iv)%nbopp, & 
     1233 &    W_F(idf)%W_V(iv)%sopp(1:W_F(idf)%W_V(iv)%nbopp), & 
     1234 &    W_F(idf)%W_V(iv)%scal(1:W_F(idf)%W_V(iv)%nbopp) 
     1235  ENDIF 
     1236!- 
     1237  W_F(idf)%W_V(iv)%scsize(1:3) = (/ pxsize,pysize,pzsize /) 
     1238  W_F(idf)%W_V(iv)%zorig(1:3) = & 
     1239 &  (/ W_F(idf)%slab_ori(1),W_F(idf)%slab_ori(2),par_oriz /) 
     1240  W_F(idf)%W_V(iv)%zsize(1:3) = & 
     1241 &  (/ W_F(idf)%slab_sz(1),W_F(idf)%slab_sz(2),par_szz /) 
    12461242!- 
    12471243! Is the size of the full array the same as that of the coordinates ? 
    12481244!- 
    1249   IF (    (pxsize > W_F(pfileid)%full_size(1)) & 
    1250  &    .OR.(pysize > W_F(pfileid)%full_size(2)) ) THEN 
     1245  IF (    (pxsize > W_F(idf)%full_size(1)) & 
     1246 &    .OR.(pysize > W_F(idf)%full_size(2)) ) THEN 
    12511247!- 
    12521248    str70 = "The size of the variable is different "// & 
    12531249 &          "from the one of the coordinates" 
    12541250    WRITE(str71,'("Size of coordinates :",2I4)') & 
    1255  &   W_F(pfileid)%full_size(1),W_F(pfileid)%full_size(2) 
     1251 &   W_F(idf)%full_size(1),W_F(idf)%full_size(2) 
    12561252    WRITE(str72,'("Size declared for variable ",a," :",2I4)') & 
    12571253 &   TRIM(tmp_name),pxsize,pysize 
     
    12611257! Is the size of the zoom smaller than the coordinates ? 
    12621258!- 
    1263   IF (    (W_F(pfileid)%full_size(1) < W_F(pfileid)%slab_sz(1)) & 
    1264  &    .OR.(W_F(pfileid)%full_size(2) < W_F(pfileid)%slab_sz(2)) ) THEN 
     1259  IF (    (W_F(idf)%full_size(1) < W_F(idf)%slab_sz(1)) & 
     1260 &    .OR.(W_F(idf)%full_size(2) < W_F(idf)%slab_sz(2)) ) THEN 
    12651261    str70 = & 
    12661262 &   "Size of variable should be greater or equal to those of the zoom" 
    12671263    WRITE(str71,'("Size of XY zoom :",2I4)') & 
    1268  &   W_F(pfileid)%slab_sz(1),W_F(pfileid)%slab_sz(2) 
     1264 &   W_F(idf)%slab_sz(1),W_F(idf)%slab_sz(2) 
    12691265    WRITE(str72,'("Size declared for variable ",A," :",2I4)') & 
    12701266 &   TRIM(tmp_name),pxsize,pysize 
     
    12751271!     and a fall back onto the default grid 
    12761272!- 
    1277   IF ( (phoriid > 0).AND.(phoriid <= W_F(pfileid)%n_hax) ) THEN 
    1278     W_F(pfileid)%W_V(iv)%h_axid = phoriid 
    1279   ELSE 
    1280     W_F(pfileid)%W_V(iv)%h_axid = 1 
     1273  IF ( (phoriid > 0).AND.(phoriid <= W_F(idf)%n_hax) ) THEN 
     1274    W_F(idf)%W_V(iv)%h_axid = phoriid 
     1275  ELSE 
     1276    W_F(idf)%W_V(iv)%h_axid = 1 
    12811277    CALL ipslerr (2,"histdef", & 
    12821278   &  'We use the default grid for variable as an invalide',& 
     
    12901286!-- Does the vertical coordinate exist ? 
    12911287!- 
    1292     IF (pzid > W_F(pfileid)%n_zax) THEN 
     1288    IF (pzid > W_F(idf)%n_zax) THEN 
    12931289      WRITE(str70, & 
    12941290 &    '("The vertical coordinate chosen for variable ",a)') & 
     
    13001296!-- Is the vertical size of the variable equal to that of the axis ? 
    13011297!- 
    1302     IF (par_szz /= W_F(pfileid)%zax_size(pzid)) THEN 
     1298    IF (par_szz /= W_F(idf)%zax_size(pzid)) THEN 
    13031299      str70 = "The size of the zoom does not correspond "// & 
    13041300 &            "to the size of the chosen vertical axis" 
    13051301      WRITE(str71,'("Size of zoom in z :",I4)') par_szz 
    13061302      WRITE(str72,'("Size declared for axis ",A," :",I4)') & 
    1307  &     TRIM(W_F(pfileid)%zax_name(pzid)),W_F(pfileid)%zax_size(pzid) 
     1303 &     TRIM(W_F(idf)%zax_name(pzid)),W_F(idf)%zax_size(pzid) 
    13081304      CALL ipslerr (3,"histdef",str70,str71,str72) 
    13091305    ENDIF 
     
    13191315      CALL ipslerr (3,"histdef",str70,str71,str72) 
    13201316    ENDIF 
    1321     W_F(pfileid)%W_V(iv)%z_axid = pzid 
    1322   ELSE 
    1323     W_F(pfileid)%W_V(iv)%z_axid = -99 
    1324   ENDIF 
    1325 !- 
    1326 ! 3.0 Determine the position of the variable in the buffer 
    1327 !     If it is instantaneous output then we do not use the buffer 
    1328 !- 
    1329   IF (l_dbg) WRITE(*,*) "histdef : 3.0" 
    1330 !- 
    1331 ! 3.1 We get the size of the arrays histwrite will get and check 
    1332 !     that they fit into the tmp_buffer 
    1333 !- 
    1334   buff_sz = W_F(pfileid)%W_V(iv)%zsize(1) & 
    1335  &         *W_F(pfileid)%W_V(iv)%zsize(2) & 
    1336  &         *W_F(pfileid)%W_V(iv)%zsize(3) 
    1337 !- 
    1338 ! 3.2 move the pointer of the buffer array for operation 
    1339 !     which need bufferisation 
    1340 !- 
    1341   IF (     (TRIM(W_F(pfileid)%W_V(iv)%topp) /= "inst") & 
    1342  &    .AND.(TRIM(W_F(pfileid)%W_V(iv)%topp) /= "once") & 
    1343  &    .AND.(TRIM(W_F(pfileid)%W_V(iv)%topp) /= "never") )THEN 
    1344     W_F(pfileid)%W_V(iv)%point = buff_pos+1 
    1345     buff_pos = buff_pos+buff_sz 
     1317    W_F(idf)%W_V(iv)%z_axid = pzid 
     1318  ELSE 
     1319    W_F(idf)%W_V(iv)%z_axid = -99 
     1320  ENDIF 
     1321!- 
     1322! 3.0 We get the size of the arrays histwrite will get 
     1323!     and eventually allocate the time_buffer 
     1324!- 
     1325  IF (l_dbg) THEN 
     1326    WRITE(*,*) "histdef : 3.0" 
     1327  ENDIF 
     1328!- 
     1329  buff_sz = W_F(idf)%W_V(iv)%zsize(1) & 
     1330 &         *W_F(idf)%W_V(iv)%zsize(2) & 
     1331 &         *W_F(idf)%W_V(iv)%zsize(3) 
     1332!- 
     1333  IF (     (TRIM(W_F(idf)%W_V(iv)%topp) /= "inst") & 
     1334 &    .AND.(TRIM(W_F(idf)%W_V(iv)%topp) /= "once") & 
     1335 &    .AND.(TRIM(W_F(idf)%W_V(iv)%topp) /= "never") )THEN 
     1336    ALLOCATE(W_F(idf)%W_V(iv)%t_bf(buff_sz)) 
     1337    W_F(idf)%W_V(iv)%t_bf(:) = 0. 
    13461338    IF (l_dbg) THEN 
    1347       WRITE(*,*) "histdef : 3.2 bufpos for iv = ",iv, & 
    1348  &      " pfileid = ",pfileid," is = ",W_F(pfileid)%W_V(iv)%point 
     1339      WRITE(*,*) "histdef : 3.0 allocating time_buffer for", & 
     1340 &      " idf = ",idf," iv = ",iv," size = ",buff_sz 
    13491341    ENDIF 
    13501342  ENDIF 
     
    13571349  IF (l_dbg) WRITE(*,*) "histdef : 4.0" 
    13581350!- 
    1359   W_F(pfileid)%W_V(iv)%freq_opp = pfreq_opp 
    1360   W_F(pfileid)%W_V(iv)%freq_wrt = pfreq_wrt 
     1351  W_F(idf)%W_V(iv)%freq_opp = pfreq_opp 
     1352  W_F(idf)%W_V(iv)%freq_wrt = pfreq_wrt 
    13611353!- 
    13621354  CALL ioget_calendar(un_an,un_jour) 
     
    13761368! 4.1 Frequency of operations and output should be larger than deltat ! 
    13771369!- 
    1378   IF (test_fopp < W_F(pfileid)%deltat) THEN 
     1370  IF (test_fopp < W_F(idf)%deltat) THEN 
    13791371    str70 = 'Frequency of operations should be larger than deltat' 
    13801372    WRITE(str71,'("It is not the case for variable ",a," :",F10.4)') & 
     
    13841376    CALL ipslerr (2,"histdef",str70,str71,str72) 
    13851377!- 
    1386     W_F(pfileid)%W_V(iv)%freq_opp = W_F(pfileid)%deltat 
    1387   ENDIF 
    1388 !- 
    1389   IF (test_fwrt < W_F(pfileid)%deltat) THEN 
     1378    W_F(idf)%W_V(iv)%freq_opp = W_F(idf)%deltat 
     1379  ENDIF 
     1380!- 
     1381  IF (test_fwrt < W_F(idf)%deltat) THEN 
    13901382    str70 = 'Frequency of output should be larger than deltat' 
    13911383    WRITE(str71,'("It is not the case for variable ",a," :",F10.4)') & 
     
    13951387    CALL ipslerr (2,"histdef",str70,str71,str72) 
    13961388!- 
    1397     W_F(pfileid)%W_V(iv)%freq_wrt = W_F(pfileid)%deltat 
     1389    W_F(idf)%W_V(iv)%freq_wrt = W_F(idf)%deltat 
    13981390  ENDIF 
    13991391!- 
     
    14011393!     its compaticility with the choice of frequencies 
    14021394!- 
    1403   IF (TRIM(W_F(pfileid)%W_V(iv)%topp) == "inst") THEN 
     1395  IF (TRIM(W_F(idf)%W_V(iv)%topp) == "inst") THEN 
    14041396    IF (test_fopp /= test_fwrt) THEN 
    14051397      str70 = 'For instantaneous output the frequency '// & 
     
    14111403      CALL ipslerr (2,"histdef",str70,str71,str72) 
    14121404      IF (test_fopp < test_fwrt) THEN 
    1413         W_F(pfileid)%W_V(iv)%freq_opp = pfreq_opp 
    1414         W_F(pfileid)%W_V(iv)%freq_wrt = pfreq_opp 
     1405        W_F(idf)%W_V(iv)%freq_opp = pfreq_opp 
     1406        W_F(idf)%W_V(iv)%freq_wrt = pfreq_opp 
    14151407      ELSE 
    1416         W_F(pfileid)%W_V(iv)%freq_opp = pfreq_wrt 
    1417         W_F(pfileid)%W_V(iv)%freq_wrt = pfreq_wrt 
     1408        W_F(idf)%W_V(iv)%freq_opp = pfreq_wrt 
     1409        W_F(idf)%W_V(iv)%freq_wrt = pfreq_wrt 
    14181410      ENDIF 
    14191411    ENDIF 
    1420   ELSE IF (INDEX(ex_topps,TRIM(W_F(pfileid)%W_V(iv)%topp)) > 0) THEN 
     1412  ELSE IF (INDEX(ex_topps,TRIM(W_F(idf)%W_V(iv)%topp)) > 0) THEN 
    14211413    IF (test_fopp > test_fwrt) THEN 
    14221414      str70 = 'For averages the frequency of operations '// & 
     
    14271419      str72 = 'PATCH : The output frequency is used for both' 
    14281420      CALL ipslerr (2,"histdef",str70,str71,str72) 
    1429       W_F(pfileid)%W_V(iv)%freq_opp = pfreq_wrt 
     1421      W_F(idf)%W_V(iv)%freq_opp = pfreq_wrt 
    14301422    ENDIF 
    14311423  ELSE 
     
    14331425 &   TRIM(tmp_name) 
    14341426    WRITE (str71,'("operation requested is :",A)') & 
    1435  &   W_F(pfileid)%W_V(iv)%topp 
    1436     WRITE (str72,'("File ID :",I3)') pfileid 
     1427 &   W_F(idf)%W_V(iv)%topp 
     1428    WRITE (str72,'("File ID :",I3)') idf 
    14371429    CALL ipslerr (3,"histdef",str70,str71,str72) 
    14381430  ENDIF 
     
    14421434  IF (l_dbg) WRITE(*,*) "histdef : 5.0" 
    14431435!- 
    1444   W_F(pfileid)%W_V(iv)%hist_wrt_rng = (PRESENT(var_range)) 
    1445   IF (W_F(pfileid)%W_V(iv)%hist_wrt_rng) THEN 
    1446     W_F(pfileid)%W_V(iv)%hist_calc_rng = (var_range(1) > var_range(2)) 
    1447     IF (W_F(pfileid)%W_V(iv)%hist_calc_rng) THEN 
    1448       W_F(pfileid)%W_V(iv)%hist_minmax(1:2) = & 
     1436  W_F(idf)%W_V(iv)%hist_wrt_rng = (PRESENT(var_range)) 
     1437  IF (W_F(idf)%W_V(iv)%hist_wrt_rng) THEN 
     1438    W_F(idf)%W_V(iv)%hist_calc_rng = (var_range(1) > var_range(2)) 
     1439    IF (W_F(idf)%W_V(iv)%hist_calc_rng) THEN 
     1440      W_F(idf)%W_V(iv)%hist_minmax(1:2) = & 
    14491441 &      (/ ABS(missing_val),-ABS(missing_val) /) 
    14501442    ELSE 
    1451       W_F(pfileid)%W_V(iv)%hist_minmax(1:2) = var_range(1:2) 
    1452     ENDIF 
    1453   ENDIF 
    1454 !- 
    1455 ! - freq_opp(pfileid,iv)/2./deltat(pfileid) 
    1456   W_F(pfileid)%W_V(iv)%last_opp = W_F(pfileid)%itau0 
    1457 ! - freq_wrt(pfileid,iv)/2./deltat(pfileid) 
    1458   W_F(pfileid)%W_V(iv)%last_wrt = W_F(pfileid)%itau0 
    1459 ! - freq_opp(pfileid,iv)/2./deltat(pfileid) 
    1460   W_F(pfileid)%W_V(iv)%last_opp_chk = W_F(pfileid)%itau0 
    1461 ! - freq_wrt(pfileid,iv)/2./deltat(pfileid) 
    1462   W_F(pfileid)%W_V(iv)%last_wrt_chk = W_F(pfileid)%itau0 
    1463   W_F(pfileid)%W_V(iv)%nb_opp = 0 
    1464   W_F(pfileid)%W_V(iv)%nb_wrt = 0 
     1443      W_F(idf)%W_V(iv)%hist_minmax(1:2) = var_range(1:2) 
     1444    ENDIF 
     1445  ENDIF 
     1446!- 
     1447! - freq_opp(idf,iv)/2./deltat(idf) 
     1448  W_F(idf)%W_V(iv)%last_opp = W_F(idf)%itau0 
     1449! - freq_wrt(idf,iv)/2./deltat(idf) 
     1450  W_F(idf)%W_V(iv)%last_wrt = W_F(idf)%itau0 
     1451! - freq_opp(idf,iv)/2./deltat(idf) 
     1452  W_F(idf)%W_V(iv)%last_opp_chk = W_F(idf)%itau0 
     1453! - freq_wrt(idf,iv)/2./deltat(idf) 
     1454  W_F(idf)%W_V(iv)%last_wrt_chk = W_F(idf)%itau0 
     1455  W_F(idf)%W_V(iv)%nb_opp = 0 
     1456  W_F(idf)%W_V(iv)%nb_wrt = 0 
    14651457!- 
    14661458! 6.0 Get the time axis for this variable 
     
    14681460  IF (l_dbg) WRITE(*,*) "histdef : 6.0" 
    14691461!- 
    1470   IF (W_F(pfileid)%W_V(iv)%freq_wrt > 0) THEN 
    1471     WRITE(str10,'(I8.8)') INT(W_F(pfileid)%W_V(iv)%freq_wrt) 
    1472     str40 = TRIM(W_F(pfileid)%W_V(iv)%topp)//"_"//TRIM(str10) 
    1473   ELSE 
    1474     WRITE(str10,'(I2.2,"month")') ABS(INT(W_F(pfileid)%W_V(iv)%freq_wrt)) 
    1475     str40 = TRIM(W_F(pfileid)%W_V(iv)%topp)//"_"//TRIM(str10) 
    1476   ENDIF 
    1477   CALL find_str (W_F(pfileid)%W_V(1:W_F(pfileid)%n_tax)%tax_name,str40,pos) 
     1462  IF (W_F(idf)%W_V(iv)%freq_wrt > 0) THEN 
     1463    WRITE(str10,'(I8.8)') INT(W_F(idf)%W_V(iv)%freq_wrt) 
     1464    str40 = TRIM(W_F(idf)%W_V(iv)%topp)//"_"//TRIM(str10) 
     1465  ELSE 
     1466    WRITE(str10,'(I2.2,"month")') ABS(INT(W_F(idf)%W_V(iv)%freq_wrt)) 
     1467    str40 = TRIM(W_F(idf)%W_V(iv)%topp)//"_"//TRIM(str10) 
     1468  ENDIF 
     1469  CALL find_str (W_F(idf)%W_V(1:W_F(idf)%n_tax)%tax_name,str40,pos) 
    14781470!- 
    14791471! No time axis for once, l_max, l_min or never operation 
    14801472!- 
    1481   IF (     (TRIM(W_F(pfileid)%W_V(iv)%topp) /= 'once')  & 
    1482  &    .AND.(TRIM(W_F(pfileid)%W_V(iv)%topp) /= 'never') & 
    1483  &    .AND.(TRIM(W_F(pfileid)%W_V(iv)%topp) /= 'l_max') & 
    1484  &    .AND.(TRIM(W_F(pfileid)%W_V(iv)%topp) /= 'l_min') ) THEN 
     1473  IF (     (TRIM(W_F(idf)%W_V(iv)%topp) /= 'once')  & 
     1474 &    .AND.(TRIM(W_F(idf)%W_V(iv)%topp) /= 'never') & 
     1475 &    .AND.(TRIM(W_F(idf)%W_V(iv)%topp) /= 'l_max') & 
     1476 &    .AND.(TRIM(W_F(idf)%W_V(iv)%topp) /= 'l_min') ) THEN 
    14851477    IF (pos < 0) THEN 
    1486       W_F(pfileid)%n_tax = W_F(pfileid)%n_tax+1 
    1487       W_F(pfileid)%W_V(W_F(pfileid)%n_tax)%tax_name = str40 
    1488       W_F(pfileid)%W_V(W_F(pfileid)%n_tax)%tax_last = 0 
    1489       W_F(pfileid)%W_V(iv)%t_axid = W_F(pfileid)%n_tax 
     1478      W_F(idf)%n_tax = W_F(idf)%n_tax+1 
     1479      W_F(idf)%W_V(W_F(idf)%n_tax)%tax_name = str40 
     1480      W_F(idf)%W_V(W_F(idf)%n_tax)%tax_last = 0 
     1481      W_F(idf)%W_V(iv)%t_axid = W_F(idf)%n_tax 
    14901482    ELSE 
    1491       W_F(pfileid)%W_V(iv)%t_axid = pos 
     1483      W_F(idf)%W_V(iv)%t_axid = pos 
    14921484    ENDIF 
    14931485  ELSE 
    14941486    IF (l_dbg) THEN 
    1495       WRITE(*,*) "histdef : 7.0 ",TRIM(W_F(pfileid)%W_V(iv)%topp),'----' 
    1496     ENDIF 
    1497     W_F(pfileid)%W_V(iv)%t_axid = -99 
     1487      WRITE(*,*) "histdef : 7.0 ",TRIM(W_F(idf)%W_V(iv)%topp),'----' 
     1488    ENDIF 
     1489    W_F(idf)%W_V(iv)%t_axid = -99 
    14981490  ENDIF 
    14991491!- 
     
    15011493!     for never or once operation 
    15021494!- 
    1503   IF (    (TRIM(W_F(pfileid)%W_V(iv)%topp) == 'once')  & 
    1504  &    .OR.(TRIM(W_F(pfileid)%W_V(iv)%topp) == 'never') ) THEN 
    1505     W_F(pfileid)%W_V(iv)%freq_opp = 0. 
    1506     W_F(pfileid)%W_V(iv)%freq_wrt = 0. 
     1495  IF (    (TRIM(W_F(idf)%W_V(iv)%topp) == 'once')  & 
     1496 &    .OR.(TRIM(W_F(idf)%W_V(iv)%topp) == 'never') ) THEN 
     1497    W_F(idf)%W_V(iv)%freq_opp = 0. 
     1498    W_F(idf)%W_V(iv)%freq_wrt = 0. 
    15071499  ENDIF 
    15081500!--------------------- 
    15091501END SUBROUTINE histdef 
    15101502!=== 
    1511 SUBROUTINE histend (pfileid) 
     1503SUBROUTINE histend (idf) 
    15121504!--------------------------------------------------------------------- 
    15131505!- This subroutine end the decalaration of variables and sets the 
     
    15161508!- INPUT 
    15171509!- 
    1518 !- pfileid : ID of the file to be worked on 
     1510!- idf : ID of the file to be worked on 
    15191511!- 
    15201512!- VERSION 
     
    15231515  IMPLICIT NONE 
    15241516!- 
    1525   INTEGER,INTENT(IN) :: pfileid 
     1517  INTEGER,INTENT(IN) :: idf 
    15261518!- 
    15271519  INTEGER :: nfid,nvid,iret,ndim,iv,itx,ziv,itax,dim_cnt 
     
    15411533  CALL ipsldbg (old_status=l_dbg) 
    15421534!- 
    1543   nfid = W_F(pfileid)%ncfid 
     1535  nfid = W_F(idf)%ncfid 
    15441536!- 
    15451537! 1.0 Create the time axes 
     
    15481540!--- 
    15491541  iret = NF90_DEF_DIM (nfid,'time_counter', & 
    1550  &                     NF90_UNLIMITED,W_F(pfileid)%tid) 
     1542 &                     NF90_UNLIMITED,W_F(idf)%tid) 
    15511543!- 
    15521544! 1.1 Define all the time axes needed for this file 
    15531545!- 
    1554   DO itx=1,W_F(pfileid)%n_tax 
    1555     dims(1) = W_F(pfileid)%tid 
    1556     IF (W_F(pfileid)%n_tax > 1) THEN 
    1557       str30 = "t_"//W_F(pfileid)%W_V(itx)%tax_name 
     1546  DO itx=1,W_F(idf)%n_tax 
     1547    dims(1) = W_F(idf)%tid 
     1548    IF (W_F(idf)%n_tax > 1) THEN 
     1549      str30 = "t_"//W_F(idf)%W_V(itx)%tax_name 
    15581550    ELSE 
    15591551      str30 = "time_counter" 
    15601552    ENDIF 
    15611553    iret = NF90_DEF_VAR (nfid,str30,NF90_DOUBLE, & 
    1562  &           dims(1),W_F(pfileid)%W_V(itx)%tdimid) 
    1563     IF (W_F(pfileid)%n_tax <= 1) THEN 
    1564       iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid,'axis',"T") 
    1565     ENDIF 
    1566     iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid, & 
     1554 &           dims(1),W_F(idf)%W_V(itx)%tdimid) 
     1555    IF (W_F(idf)%n_tax <= 1) THEN 
     1556      iret = NF90_PUT_ATT (nfid,W_F(idf)%W_V(itx)%tdimid,'axis',"T") 
     1557    ENDIF 
     1558    iret = NF90_PUT_ATT (nfid,W_F(idf)%W_V(itx)%tdimid, & 
    15671559 &           'standard_name',"time") 
    15681560!--- 
     
    15731565!   if there is a ioconf routine to control it. 
    15741566!--- 
    1575 !-- rtime0 = itau2date(itau0(pfileid),date0(pfileid),deltat(pfileid)) 
    1576     rtime0 = W_F(pfileid)%date0 
     1567!-- rtime0 = itau2date(itau0(idf),date0(idf),deltat(idf)) 
     1568    rtime0 = W_F(idf)%date0 
    15771569!- 
    15781570    CALL ju2ymds(rtime0,year,month,day,sec) 
     
    15911583 &   FMT='(A,I4.4,"-",I2.2,"-",I2.2," ",I2.2,":",I2.2,":",I2.2)') & 
    15921584 &    'seconds since ',year,month,day,hours,minutes,INT(sec) 
    1593     iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid, & 
     1585    iret = NF90_PUT_ATT (nfid,W_F(idf)%W_V(itx)%tdimid, & 
    15941586 &           'units',TRIM(str70)) 
    15951587!- 
    15961588    CALL ioget_calendar (str30) 
    1597     iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid, & 
     1589    iret = NF90_PUT_ATT (nfid,W_F(idf)%W_V(itx)%tdimid, & 
    15981590 &           'calendar',TRIM(str30)) 
    15991591!- 
    1600     iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid, & 
     1592    iret = NF90_PUT_ATT (nfid,W_F(idf)%W_V(itx)%tdimid, & 
    16011593 &           'title','Time') 
    16021594!- 
    1603     iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid, & 
     1595    iret = NF90_PUT_ATT (nfid,W_F(idf)%W_V(itx)%tdimid, & 
    16041596 &           'long_name','Time axis') 
    16051597!- 
     
    16071599 &   FMT='(" ",I4.4,"-",A3,"-",I2.2," ",I2.2,":",I2.2,":",I2.2)') & 
    16081600 &    year,cal(month),day,hours,minutes,INT(sec) 
    1609     iret = NF90_PUT_ATT (nfid,W_F(pfileid)%W_V(itx)%tdimid, & 
     1601    iret = NF90_PUT_ATT (nfid,W_F(idf)%W_V(itx)%tdimid, & 
    16101602 &           'time_origin',TRIM(str70)) 
    16111603  ENDDO 
     
    16151607  IF (l_dbg) WRITE(*,*) "histend : 2.0" 
    16161608!- 
    1617   DO iv=1,W_F(pfileid)%n_var 
     1609  DO iv=1,W_F(idf)%n_var 
    16181610!--- 
    1619     itax = W_F(pfileid)%W_V(iv)%t_axid 
     1611    itax = W_F(idf)%W_V(iv)%t_axid 
    16201612!--- 
    1621     IF (W_F(pfileid)%regular) THEN 
    1622       dims(1:2) = (/ W_F(pfileid)%xid,W_F(pfileid)%yid /) 
     1613    IF (W_F(idf)%regular) THEN 
     1614      dims(1:2) = (/ W_F(idf)%xid,W_F(idf)%yid /) 
    16231615      dim_cnt = 2 
    16241616    ELSE 
    1625       dims(1) = W_F(pfileid)%xid 
     1617      dims(1) = W_F(idf)%xid 
    16261618      dim_cnt = 1 
    16271619    ENDIF 
    16281620!--- 
    1629     tmp_opp = W_F(pfileid)%W_V(iv)%topp 
    1630     ziv = W_F(pfileid)%W_V(iv)%z_axid 
     1621    tmp_opp = W_F(idf)%W_V(iv)%topp 
     1622    ziv = W_F(idf)%W_V(iv)%z_axid 
    16311623!--- 
    16321624!   2.1 dimension of field 
     
    16381630        IF (ziv == -99) THEN 
    16391631          ndim = dim_cnt+1 
    1640           dims(dim_cnt+1:dim_cnt+2) = (/ W_F(pfileid)%tid,0 /) 
     1632          dims(dim_cnt+1:dim_cnt+2) = (/ W_F(idf)%tid,0 /) 
    16411633        ELSE 
    16421634          ndim = dim_cnt+2 
    16431635          dims(dim_cnt+1:dim_cnt+2) = & 
    1644  &         (/ W_F(pfileid)%zax_ids(ziv),W_F(pfileid)%tid /) 
     1636 &         (/ W_F(idf)%zax_ids(ziv),W_F(idf)%tid /) 
    16451637        ENDIF 
    16461638      ELSE 
     
    16501642        ELSE 
    16511643          ndim = dim_cnt+1 
    1652           dims(dim_cnt+1:dim_cnt+2) = (/ W_F(pfileid)%zax_ids(ziv),0 /) 
     1644          dims(dim_cnt+1:dim_cnt+2) = (/ W_F(idf)%zax_ids(ziv),0 /) 
    16531645        ENDIF 
    16541646      ENDIF 
    16551647!- 
    1656       iret = NF90_DEF_VAR (nfid,TRIM(W_F(pfileid)%W_V(iv)%v_name), & 
    1657  &             W_F(pfileid)%W_V(iv)%v_typ,dims(1:ABS(ndim)),nvid) 
    1658 !- 
    1659       W_F(pfileid)%W_V(iv)%ncvid = nvid 
    1660 !- 
    1661       IF (LEN_TRIM(W_F(pfileid)%W_V(iv)%unit_name) > 0) THEN 
     1648      iret = NF90_DEF_VAR (nfid,TRIM(W_F(idf)%W_V(iv)%v_name), & 
     1649 &             W_F(idf)%W_V(iv)%v_typ,dims(1:ABS(ndim)),nvid) 
     1650!- 
     1651      W_F(idf)%W_V(iv)%ncvid = nvid 
     1652!- 
     1653      IF (LEN_TRIM(W_F(idf)%W_V(iv)%unit_name) > 0) THEN 
    16621654        iret = NF90_PUT_ATT (nfid,nvid,'units', & 
    1663  &                           TRIM(W_F(pfileid)%W_V(iv)%unit_name)) 
     1655 &                           TRIM(W_F(idf)%W_V(iv)%unit_name)) 
    16641656      ENDIF 
    16651657      iret = NF90_PUT_ATT (nfid,nvid,'standard_name', & 
    1666  &                         TRIM(W_F(pfileid)%W_V(iv)%std_name)) 
     1658 &                         TRIM(W_F(idf)%W_V(iv)%std_name)) 
    16671659!- 
    16681660      iret = NF90_PUT_ATT (nfid,nvid,'_FillValue', & 
    16691661 &                         REAL(missing_val,KIND=4)) 
    1670       IF (W_F(pfileid)%W_V(iv)%hist_wrt_rng) THEN 
     1662      IF (W_F(idf)%W_V(iv)%hist_wrt_rng) THEN 
    16711663        iret = NF90_PUT_ATT (nfid,nvid,'valid_min', & 
    1672  &               REAL(W_F(pfileid)%W_V(iv)%hist_minmax(1),KIND=4)) 
     1664 &               REAL(W_F(idf)%W_V(iv)%hist_minmax(1),KIND=4)) 
    16731665        iret = NF90_PUT_ATT (nfid,nvid,'valid_max', & 
    1674  &               REAL(W_F(pfileid)%W_V(iv)%hist_minmax(2),KIND=4)) 
     1666 &               REAL(W_F(idf)%W_V(iv)%hist_minmax(2),KIND=4)) 
    16751667      ENDIF 
    16761668      iret = NF90_PUT_ATT (nfid,nvid,'long_name', & 
    1677  &                         TRIM(W_F(pfileid)%W_V(iv)%title)) 
     1669 &                         TRIM(W_F(idf)%W_V(iv)%title)) 
    16781670      iret = NF90_PUT_ATT (nfid,nvid,'online_operation', & 
    1679  &                         TRIM(W_F(pfileid)%W_V(iv)%fullop)) 
     1671 &                         TRIM(W_F(idf)%W_V(iv)%fullop)) 
    16801672!- 
    16811673      SELECT CASE(ndim) 
     
    16871679      END SELECT 
    16881680!- 
    1689       assoc=TRIM(W_F(pfileid)%hax_name(W_F(pfileid)%W_V(iv)%h_axid,2)) & 
    1690  &   //' '//TRIM(W_F(pfileid)%hax_name(W_F(pfileid)%W_V(iv)%h_axid,1)) 
    1691 !- 
    1692       ziv = W_F(pfileid)%W_V(iv)%z_axid 
     1681      assoc=TRIM(W_F(idf)%hax_name(W_F(idf)%W_V(iv)%h_axid,2)) & 
     1682 &   //' '//TRIM(W_F(idf)%hax_name(W_F(idf)%W_V(iv)%h_axid,1)) 
     1683!- 
     1684      ziv = W_F(idf)%W_V(iv)%z_axid 
    16931685      IF (ziv > 0) THEN 
    1694         str30 = W_F(pfileid)%zax_name(ziv) 
     1686        str30 = W_F(idf)%zax_name(ziv) 
    16951687        assoc = TRIM(str30)//' '//TRIM(assoc) 
    16961688      ENDIF 
    16971689!- 
    16981690      IF (itax > 0) THEN 
    1699         IF (W_F(pfileid)%n_tax > 1) THEN 
    1700           str30 = "t_"//W_F(pfileid)%W_V(itax)%tax_name 
     1691        IF (W_F(idf)%n_tax > 1) THEN 
     1692          str30 = "t_"//W_F(idf)%W_V(itax)%tax_name 
    17011693        ELSE 
    17021694          str30 = "time_counter" 
     
    17061698        IF (l_dbg) THEN 
    17071699          WRITE(*,*) "histend : 2.0.n, freq_opp, freq_wrt", & 
    1708  &          W_F(pfileid)%W_V(iv)%freq_opp,W_F(pfileid)%W_V(iv)%freq_wrt 
     1700 &          W_F(idf)%W_V(iv)%freq_opp,W_F(idf)%W_V(iv)%freq_wrt 
    17091701        ENDIF 
    17101702!- 
    17111703        iret = NF90_PUT_ATT (nfid,nvid,'interval_operation', & 
    1712  &                           REAL(W_F(pfileid)%W_V(iv)%freq_opp,KIND=4)) 
     1704 &                           REAL(W_F(idf)%W_V(iv)%freq_opp,KIND=4)) 
    17131705        iret = NF90_PUT_ATT (nfid,nvid,'interval_write', & 
    1714  &                           REAL(W_F(pfileid)%W_V(iv)%freq_wrt,KIND=4)) 
     1706 &                           REAL(W_F(idf)%W_V(iv)%freq_wrt,KIND=4)) 
    17151707      ENDIF 
    17161708      iret = NF90_PUT_ATT (nfid,nvid,'coordinates',TRIM(assoc)) 
     
    17201712! 2.2 Add DOMAIN attributes if needed 
    17211713!- 
    1722   IF (W_F(pfileid)%dom_id_svg >= 0) THEN 
    1723     CALL flio_dom_att (nfid,W_F(pfileid)%dom_id_svg) 
     1714  IF (W_F(idf)%dom_id_svg >= 0) THEN 
     1715    CALL flio_dom_att (nfid,W_F(idf)%dom_id_svg) 
    17241716  ENDIF 
    17251717!- 
     
    17341726  IF (l_dbg) WRITE(*,*) "histend : 4.0" 
    17351727!- 
    1736   WRITE(str70,'("All variables have been initialized on file :",I3)') pfileid 
     1728  WRITE(str70,'("All variables have been initialized on file :",I3)') idf 
    17371729  CALL ipslerr (1,'histend',str70,'',' ') 
    17381730!--------------------- 
    17391731END SUBROUTINE histend 
    17401732!=== 
    1741 SUBROUTINE histwrite_r1d (pfileid,pvarname,pitau,pdata,nbindex,nindex) 
     1733SUBROUTINE histwrite_r1d (idf,pvarname,pitau,pdata,nbindex,nindex) 
    17421734!--------------------------------------------------------------------- 
    17431735  IMPLICIT NONE 
    17441736!- 
    1745   INTEGER,INTENT(IN) :: pfileid,pitau,nbindex 
     1737  INTEGER,INTENT(IN) :: idf,pitau,nbindex 
    17461738  INTEGER,DIMENSION(nbindex),INTENT(IN) :: nindex 
    17471739  REAL,DIMENSION(:),INTENT(IN) :: pdata 
    17481740  CHARACTER(LEN=*),INTENT(IN) :: pvarname 
    17491741!--------------------------------------------------------------------- 
    1750   CALL histw_rnd (pfileid,pvarname,pitau,nbindex,nindex,pdata_1d=pdata) 
     1742  CALL histw_rnd (idf,pvarname,pitau,nbindex,nindex,pdata_1d=pdata) 
    17511743!--------------------------- 
    17521744END SUBROUTINE histwrite_r1d 
    17531745!=== 
    1754 SUBROUTINE histwrite_r2d (pfileid,pvarname,pitau,pdata,nbindex,nindex) 
     1746SUBROUTINE histwrite_r2d (idf,pvarname,pitau,pdata,nbindex,nindex) 
    17551747!--------------------------------------------------------------------- 
    17561748  IMPLICIT NONE 
    17571749!- 
    1758   INTEGER,INTENT(IN) :: pfileid,pitau,nbindex 
     1750  INTEGER,INTENT(IN) :: idf,pitau,nbindex 
    17591751  INTEGER,DIMENSION(nbindex),INTENT(IN) :: nindex 
    17601752  REAL,DIMENSION(:,:),INTENT(IN) :: pdata 
    17611753  CHARACTER(LEN=*),INTENT(IN) :: pvarname 
    17621754!--------------------------------------------------------------------- 
    1763   CALL histw_rnd (pfileid,pvarname,pitau,nbindex,nindex,pdata_2d=pdata) 
     1755  CALL histw_rnd (idf,pvarname,pitau,nbindex,nindex,pdata_2d=pdata) 
    17641756!--------------------------- 
    17651757END SUBROUTINE histwrite_r2d 
    17661758!=== 
    1767 SUBROUTINE histwrite_r3d (pfileid,pvarname,pitau,pdata,nbindex,nindex) 
     1759SUBROUTINE histwrite_r3d (idf,pvarname,pitau,pdata,nbindex,nindex) 
    17681760!--------------------------------------------------------------------- 
    17691761  IMPLICIT NONE 
    17701762!- 
    1771   INTEGER,INTENT(IN) :: pfileid,pitau,nbindex 
     1763  INTEGER,INTENT(IN) :: idf,pitau,nbindex 
    17721764  INTEGER,DIMENSION(nbindex),INTENT(IN) :: nindex 
    17731765  REAL,DIMENSION(:,:,:),INTENT(IN) :: pdata 
    17741766  CHARACTER(LEN=*),INTENT(IN) :: pvarname 
    17751767!--------------------------------------------------------------------- 
    1776   CALL histw_rnd (pfileid,pvarname,pitau,nbindex,nindex,pdata_3d=pdata) 
     1768  CALL histw_rnd (idf,pvarname,pitau,nbindex,nindex,pdata_3d=pdata) 
    17771769!--------------------------- 
    17781770END SUBROUTINE histwrite_r3d 
    17791771!=== 
    1780 SUBROUTINE histw_rnd (pfileid,pvarname,pitau,nbindex,nindex, & 
     1772SUBROUTINE histw_rnd (idf,pvarname,pitau,nbindex,nindex, & 
    17811773  &                   pdata_1d,pdata_2d,pdata_3d) 
    17821774!--------------------------------------------------------------------- 
    17831775  IMPLICIT NONE 
    17841776!- 
    1785   INTEGER,INTENT(IN) :: pfileid,pitau,nbindex 
     1777  INTEGER,INTENT(IN) :: idf,pitau,nbindex 
    17861778  INTEGER,DIMENSION(nbindex),INTENT(IN) :: nindex 
    17871779  CHARACTER(LEN=*),INTENT(IN) :: pvarname 
     
    17911783!- 
    17921784  LOGICAL :: do_oper,do_write,largebuf,l1d,l2d,l3d 
    1793   INTEGER :: varid,io,nbpt_out 
     1785  INTEGER :: iv,io,nbpt_out 
    17941786  INTEGER              :: nbpt_in1 
    17951787  INTEGER,DIMENSION(2) :: nbpt_in2 
    17961788  INTEGER,DIMENSION(3) :: nbpt_in3 
    1797   REAL,ALLOCATABLE,DIMENSION(:),SAVE :: buff_tmp 
    1798   INTEGER,SAVE :: buff_tmp_sz 
     1789  REAL,ALLOCATABLE,DIMENSION(:),SAVE :: tbf_1 
    17991790  CHARACTER(LEN=7) :: tmp_opp 
    18001791  CHARACTER(LEN=13) :: c_nam 
     
    18151806!     Thanks Marine for showing us what errors users can make ! 
    18161807!- 
    1817   IF ( (pfileid < 1).OR.(pfileid > nb_files) ) THEN 
     1808  IF ( (idf < 1).OR.(idf > nb_files) ) THEN 
    18181809    CALL ipslerr (3,"histwrite", & 
    18191810 &    'Illegal file ID in the histwrite of variable',pvarname,' ') 
     
    18221813! 1.1 Find the id of the variable to be written and the real time 
    18231814!- 
    1824   CALL histvar_seq (pfileid,pvarname,varid) 
     1815  CALL histvar_seq (idf,pvarname,iv) 
    18251816!- 
    18261817! 2.0 do nothing for never operation 
    18271818!- 
    1828   tmp_opp = W_F(pfileid)%W_V(varid)%topp 
     1819  tmp_opp = W_F(idf)%W_V(iv)%topp 
    18291820!- 
    18301821  IF (TRIM(tmp_opp) == "never") THEN 
    1831     W_F(pfileid)%W_V(varid)%last_opp_chk = -99 
    1832     W_F(pfileid)%W_V(varid)%last_wrt_chk = -99 
     1822    W_F(idf)%W_V(iv)%last_opp_chk = -99 
     1823    W_F(idf)%W_V(iv)%last_wrt_chk = -99 
    18331824  ENDIF 
    18341825!- 
    18351826! 3.0 We check if we need to do an operation 
    18361827!- 
    1837   IF (W_F(pfileid)%W_V(varid)%last_opp_chk == pitau) THEN 
     1828  IF (W_F(idf)%W_V(iv)%last_opp_chk == pitau) THEN 
    18381829    CALL ipslerr (3,"histwrite", & 
    18391830 &    'This variable has already been analysed at the present', & 
     
    18421833!- 
    18431834  CALL isittime & 
    1844  &  (pitau,W_F(pfileid)%date0,W_F(pfileid)%deltat, & 
    1845  &   W_F(pfileid)%W_V(varid)%freq_opp, & 
    1846  &   W_F(pfileid)%W_V(varid)%last_opp, & 
    1847  &   W_F(pfileid)%W_V(varid)%last_opp_chk,do_oper) 
     1835 &  (pitau,W_F(idf)%date0,W_F(idf)%deltat, & 
     1836 &   W_F(idf)%W_V(iv)%freq_opp, & 
     1837 &   W_F(idf)%W_V(iv)%last_opp, & 
     1838 &   W_F(idf)%W_V(iv)%last_opp_chk,do_oper) 
    18481839!- 
    18491840! 4.0 We check if we need to write the data 
    18501841!- 
    1851   IF (W_F(pfileid)%W_V(varid)%last_wrt_chk == pitau) THEN 
     1842  IF (W_F(idf)%W_V(iv)%last_wrt_chk == pitau) THEN 
    18521843    CALL ipslerr (3,"histwrite", & 
    18531844 &    'This variable as already been written for the present', & 
     
    18561847!- 
    18571848  CALL isittime & 
    1858  &  (pitau,W_F(pfileid)%date0,W_F(pfileid)%deltat, & 
    1859  &   W_F(pfileid)%W_V(varid)%freq_wrt, & 
    1860  &   W_F(pfileid)%W_V(varid)%last_wrt, & 
    1861  &   W_F(pfileid)%W_V(varid)%last_wrt_chk,do_write) 
     1849 &  (pitau,W_F(idf)%date0,W_F(idf)%deltat, & 
     1850 &   W_F(idf)%W_V(iv)%freq_wrt, & 
     1851 &   W_F(idf)%W_V(iv)%last_wrt, & 
     1852 &   W_F(idf)%W_V(iv)%last_wrt_chk,do_write) 
    18621853!- 
    18631854! 5.0 histwrite called 
     
    18671858!-- 5.1 Get the sizes of the data we will handle 
    18681859!- 
    1869     IF (W_F(pfileid)%W_V(varid)%datasz_in(1) <= 0) THEN 
     1860    IF (W_F(idf)%W_V(iv)%datasz_in(1) <= 0) THEN 
    18701861!---- There is the risk here that the user has over-sized the array. 
    18711862!---- But how can we catch this ? 
    18721863!---- In the worst case we will do impossible operations 
    18731864!---- on part of the data ! 
    1874       W_F(pfileid)%W_V(varid)%datasz_in(1:3) = -1 
     1865      W_F(idf)%W_V(iv)%datasz_in(1:3) = -1 
    18751866      IF      (l1d) THEN 
    1876         W_F(pfileid)%W_V(varid)%datasz_in(1) = SIZE(pdata_1d) 
     1867        W_F(idf)%W_V(iv)%datasz_in(1) = SIZE(pdata_1d) 
    18771868      ELSE IF (l2d) THEN 
    1878         W_F(pfileid)%W_V(varid)%datasz_in(1) = SIZE(pdata_2d,DIM=1) 
    1879         W_F(pfileid)%W_V(varid)%datasz_in(2) = SIZE(pdata_2d,DIM=2) 
     1869        W_F(idf)%W_V(iv)%datasz_in(1) = SIZE(pdata_2d,DIM=1) 
     1870        W_F(idf)%W_V(iv)%datasz_in(2) = SIZE(pdata_2d,DIM=2) 
    18801871      ELSE IF (l3d) THEN 
    1881         W_F(pfileid)%W_V(varid)%datasz_in(1) = SIZE(pdata_3d,DIM=1) 
    1882         W_F(pfileid)%W_V(varid)%datasz_in(2) = SIZE(pdata_3d,DIM=2) 
    1883         W_F(pfileid)%W_V(varid)%datasz_in(3) = SIZE(pdata_3d,DIM=3) 
     1872        W_F(idf)%W_V(iv)%datasz_in(1) = SIZE(pdata_3d,DIM=1) 
     1873        W_F(idf)%W_V(iv)%datasz_in(2) = SIZE(pdata_3d,DIM=2) 
     1874        W_F(idf)%W_V(iv)%datasz_in(3) = SIZE(pdata_3d,DIM=3) 
    18841875      ENDIF 
    18851876    ENDIF 
     
    18871878!-- 5.2 The maximum size of the data will give the size of the buffer 
    18881879!- 
    1889     IF (W_F(pfileid)%W_V(varid)%datasz_max <= 0) THEN 
     1880    IF (W_F(idf)%W_V(iv)%datasz_max <= 0) THEN 
    18901881      largebuf = .FALSE. 
    1891       DO io=1,W_F(pfileid)%W_V(varid)%nbopp 
    1892         IF (INDEX(fuchnbout,W_F(pfileid)%W_V(varid)%sopp(io)) > 0) THEN 
     1882      DO io=1,W_F(idf)%W_V(iv)%nbopp 
     1883        IF (INDEX(fuchnbout,W_F(idf)%W_V(iv)%sopp(io)) > 0) THEN 
    18931884          largebuf = .TRUE. 
    18941885        ENDIF 
    18951886      ENDDO 
    18961887      IF (largebuf) THEN 
    1897         W_F(pfileid)%W_V(varid)%datasz_max = & 
    1898  &        W_F(pfileid)%W_V(varid)%scsize(1) & 
    1899  &       *W_F(pfileid)%W_V(varid)%scsize(2) & 
    1900  &       *W_F(pfileid)%W_V(varid)%scsize(3) 
     1888        W_F(idf)%W_V(iv)%datasz_max = & 
     1889 &        W_F(idf)%W_V(iv)%scsize(1) & 
     1890 &       *W_F(idf)%W_V(iv)%scsize(2) & 
     1891 &       *W_F(idf)%W_V(iv)%scsize(3) 
    19011892      ELSE 
    19021893        IF      (l1d) THEN 
    1903           W_F(pfileid)%W_V(varid)%datasz_max = & 
    1904  &          W_F(pfileid)%W_V(varid)%datasz_in(1) 
     1894          W_F(idf)%W_V(iv)%datasz_max = & 
     1895 &          W_F(idf)%W_V(iv)%datasz_in(1) 
    19051896        ELSE IF (l2d) THEN 
    1906           W_F(pfileid)%W_V(varid)%datasz_max = & 
    1907  &          W_F(pfileid)%W_V(varid)%datasz_in(1) & 
    1908  &         *W_F(pfileid)%W_V(varid)%datasz_in(2) 
     1897          W_F(idf)%W_V(iv)%datasz_max = & 
     1898 &          W_F(idf)%W_V(iv)%datasz_in(1) & 
     1899 &         *W_F(idf)%W_V(iv)%datasz_in(2) 
    19091900        ELSE IF (l3d) THEN 
    1910           W_F(pfileid)%W_V(varid)%datasz_max = & 
    1911  &          W_F(pfileid)%W_V(varid)%datasz_in(1) & 
    1912  &         *W_F(pfileid)%W_V(varid)%datasz_in(2) & 
    1913  &         *W_F(pfileid)%W_V(varid)%datasz_in(3) 
     1901          W_F(idf)%W_V(iv)%datasz_max = & 
     1902 &          W_F(idf)%W_V(iv)%datasz_in(1) & 
     1903 &         *W_F(idf)%W_V(iv)%datasz_in(2) & 
     1904 &         *W_F(idf)%W_V(iv)%datasz_in(3) 
    19141905        ENDIF 
    19151906      ENDIF 
    19161907    ENDIF 
    19171908!- 
    1918     IF (.NOT.ALLOCATED(buff_tmp)) THEN 
     1909    IF (.NOT.ALLOCATED(tbf_1)) THEN 
    19191910      IF (l_dbg) THEN 
    19201911        WRITE(*,*) & 
    1921  &       c_nam//" : allocate buff_tmp for buff_sz = ", & 
    1922  &       W_F(pfileid)%W_V(varid)%datasz_max 
     1912 &       c_nam//" : allocate tbf_1 for size = ", & 
     1913 &       W_F(idf)%W_V(iv)%datasz_max 
    19231914      ENDIF 
    1924       ALLOCATE(buff_tmp(W_F(pfileid)%W_V(varid)%datasz_max)) 
    1925       buff_tmp_sz = W_F(pfileid)%W_V(varid)%datasz_max 
    1926     ELSE IF (W_F(pfileid)%W_V(varid)%datasz_max > buff_tmp_sz) THEN 
     1915      ALLOCATE(tbf_1(W_F(idf)%W_V(iv)%datasz_max)) 
     1916    ELSE IF (W_F(idf)%W_V(iv)%datasz_max > SIZE(tbf_1)) THEN 
    19271917      IF (l_dbg) THEN 
    19281918        WRITE(*,*) & 
    1929  &       c_nam//" : re-allocate buff_tmp for buff_sz = ", & 
    1930  &       W_F(pfileid)%W_V(varid)%datasz_max 
     1919 &       c_nam//" : re-allocate tbf_1 for size = ", & 
     1920 &       W_F(idf)%W_V(iv)%datasz_max 
    19311921      ENDIF 
    1932       DEALLOCATE(buff_tmp) 
    1933       ALLOCATE(buff_tmp(W_F(pfileid)%W_V(varid)%datasz_max)) 
    1934       buff_tmp_sz = W_F(pfileid)%W_V(varid)%datasz_max 
     1922      DEALLOCATE(tbf_1) 
     1923      ALLOCATE(tbf_1(W_F(idf)%W_V(iv)%datasz_max)) 
    19351924    ENDIF 
    19361925!- 
     
    19391928!-- of the data at the same time. This should speed up things. 
    19401929!- 
    1941     nbpt_out = W_F(pfileid)%W_V(varid)%datasz_max 
     1930    nbpt_out = W_F(idf)%W_V(iv)%datasz_max 
    19421931    IF      (l1d) THEN 
    1943       nbpt_in1 = W_F(pfileid)%W_V(varid)%datasz_in(1) 
    1944       CALL mathop (W_F(pfileid)%W_V(varid)%sopp(1),nbpt_in1,pdata_1d, & 
     1932      nbpt_in1 = W_F(idf)%W_V(iv)%datasz_in(1) 
     1933      CALL mathop (W_F(idf)%W_V(iv)%sopp(1),nbpt_in1,pdata_1d, & 
    19451934 &                 missing_val,nbindex,nindex, & 
    1946  &                 W_F(pfileid)%W_V(varid)%scal(1),nbpt_out,buff_tmp) 
     1935 &                 W_F(idf)%W_V(iv)%scal(1),nbpt_out,tbf_1) 
    19471936    ELSE IF (l2d) THEN 
    1948       nbpt_in2(1:2) = W_F(pfileid)%W_V(varid)%datasz_in(1:2) 
    1949       CALL mathop (W_F(pfileid)%W_V(varid)%sopp(1),nbpt_in2,pdata_2d, & 
     1937      nbpt_in2(1:2) = W_F(idf)%W_V(iv)%datasz_in(1:2) 
     1938      CALL mathop (W_F(idf)%W_V(iv)%sopp(1),nbpt_in2,pdata_2d, & 
    19501939 &                 missing_val,nbindex,nindex, & 
    1951  &                 W_F(pfileid)%W_V(varid)%scal(1),nbpt_out,buff_tmp) 
     1940 &                 W_F(idf)%W_V(iv)%scal(1),nbpt_out,tbf_1) 
    19521941    ELSE IF (l3d) THEN 
    1953       nbpt_in3(1:3) = W_F(pfileid)%W_V(varid)%datasz_in(1:3) 
    1954       CALL mathop (W_F(pfileid)%W_V(varid)%sopp(1),nbpt_in3,pdata_3d, & 
     1942      nbpt_in3(1:3) = W_F(idf)%W_V(iv)%datasz_in(1:3) 
     1943      CALL mathop (W_F(idf)%W_V(iv)%sopp(1),nbpt_in3,pdata_3d, & 
    19551944 &                 missing_val,nbindex,nindex, & 
    1956  &                 W_F(pfileid)%W_V(varid)%scal(1),nbpt_out,buff_tmp) 
    1957     ENDIF 
    1958     CALL histwrite_real (pfileid,varid,pitau,nbpt_out, & 
    1959  &            buff_tmp,nbindex,nindex,do_oper,do_write) 
     1945 &                 W_F(idf)%W_V(iv)%scal(1),nbpt_out,tbf_1) 
     1946    ENDIF 
     1947    CALL histwrite_real (idf,iv,pitau,nbpt_out, & 
     1948 &            tbf_1,nbindex,nindex,do_oper,do_write) 
    19601949  ENDIF 
    19611950!- 
     
    19631952!- 
    19641953  IF ((TRIM(tmp_opp) /= "once").AND.(TRIM(tmp_opp) /= "never")) THEN 
    1965     W_F(pfileid)%W_V(varid)%last_opp_chk = pitau 
    1966     W_F(pfileid)%W_V(varid)%last_wrt_chk = pitau 
    1967   ELSE 
    1968     W_F(pfileid)%W_V(varid)%last_opp_chk = -99 
    1969     W_F(pfileid)%W_V(varid)%last_wrt_chk = -99 
     1954    W_F(idf)%W_V(iv)%last_opp_chk = pitau 
     1955    W_F(idf)%W_V(iv)%last_wrt_chk = pitau 
     1956  ELSE 
     1957    W_F(idf)%W_V(iv)%last_opp_chk = -99 
     1958    W_F(idf)%W_V(iv)%last_wrt_chk = -99 
    19701959  ENDIF 
    19711960!----------------------- 
     
    19731962!=== 
    19741963SUBROUTINE histwrite_real & 
    1975  & (pfileid,varid,pitau,nbdpt,buff_tmp,nbindex,nindex,do_oper,do_write) 
     1964 & (idf,iv,pitau,nbdpt,tbf_1,nbindex,nindex,do_oper,do_write) 
    19761965!--------------------------------------------------------------------- 
    19771966!- This subroutine is internal and does the calculations and writing 
     
    19811970  IMPLICIT NONE 
    19821971!- 
    1983   INTEGER,INTENT(IN) :: pfileid,pitau,varid, & 
     1972  INTEGER,INTENT(IN) :: idf,pitau,iv, & 
    19841973 &                      nbindex,nindex(nbindex),nbdpt 
    1985   REAL,DIMENSION(:)  :: buff_tmp 
     1974  REAL,DIMENSION(:)  :: tbf_1 
    19861975  LOGICAL,INTENT(IN) :: do_oper,do_write 
    19871976!- 
    1988   INTEGER :: tsz,nfid,nvid,i,iret,ipt,itax,io,nbin,nbout 
     1977  INTEGER :: tsz,nfid,nvid,iret,itax,io,nbin,nbout 
    19891978  INTEGER :: nx,ny,nz,ky,kz,kt,kc 
    19901979  INTEGER,DIMENSION(4) :: corner,edges 
     
    19931982  REAL :: rtime 
    19941983  CHARACTER(LEN=7) :: tmp_opp 
    1995   REAL,ALLOCATABLE,DIMENSION(:),SAVE :: buff_tmp2,buffer_used 
    1996   INTEGER,SAVE :: buff_tmp2_sz,buffer_sz 
     1984  REAL,ALLOCATABLE,DIMENSION(:),SAVE :: tbf_2 
    19971985  LOGICAL :: l_dbg 
    19981986!--------------------------------------------------------------------- 
     
    20001988!- 
    20011989  IF (l_dbg) THEN 
    2002     WRITE(*,*) "histwrite 0.0 : VAR : ",W_F(pfileid)%W_V(varid)%v_name 
     1990    WRITE(*,*) "histwrite 0.0 : VAR : ",W_F(idf)%W_V(iv)%v_name 
    20031991    WRITE(*,*) "histwrite 0.0 : nbindex,nindex :", & 
    20041992 &  nbindex,nindex(1:MIN(3,nbindex)),'...',nindex(MAX(1,nbindex-3):nbindex) 
     
    20071995! The sizes which can be encoutered 
    20081996!- 
    2009   tsz =  W_F(pfileid)%W_V(varid)%zsize(1) & 
    2010  &      *W_F(pfileid)%W_V(varid)%zsize(2) & 
    2011  &      *W_F(pfileid)%W_V(varid)%zsize(3) 
    2012 !- 
    2013 ! 1.0 We allocate the memory needed to store the data between write 
    2014 !     and the temporary space needed for operations. 
    2015 !     We have to keep precedent buffer if needed 
    2016 !- 
    2017   IF (.NOT. ALLOCATED(buffer)) THEN 
    2018     IF (l_dbg) WRITE(*,*) "histwrite_real 1.0 allocate buffer ",buff_pos 
    2019     ALLOCATE(buffer(buff_pos)) 
    2020     buffer_sz = buff_pos 
    2021     buffer(:)=0.0 
    2022   ELSE IF (buffer_sz < buff_pos) THEN 
     1997  tsz =  W_F(idf)%W_V(iv)%zsize(1) & 
     1998 &      *W_F(idf)%W_V(iv)%zsize(2) & 
     1999 &      *W_F(idf)%W_V(iv)%zsize(3) 
     2000!- 
     2001! 1.0 We allocate and the temporary space needed for operations. 
     2002!     The buffers are only deallocated when more space is needed. 
     2003!     This reduces the umber of allocates but increases memory needs. 
     2004!- 
     2005  IF (.NOT.ALLOCATED(tbf_2)) THEN 
    20232006    IF (l_dbg) THEN 
    2024       WRITE(*,*) "histwrite_real 1.0.1 re-allocate buffer for ", & 
    2025  &      buff_pos," instead of ",SIZE(buffer) 
    2026     ENDIF 
    2027     IF (SUM(buffer)/=0.0) THEN 
    2028       IF (l_dbg) WRITE (*,*) 'histwrite : buffer has been used. ', & 
    2029  &      'We have to save it before re-allocating.' 
    2030       ALLOCATE(buffer_used(buffer_sz)) 
    2031       buffer_used(:)=buffer(:) 
    2032       DEALLOCATE(buffer) 
    2033       ALLOCATE(buffer(buff_pos)) 
    2034       buffer_sz = buff_pos 
    2035       buffer(:)=0.0 
    2036       buffer(:SIZE(buffer_used))=buffer_used 
    2037       DEALLOCATE(buffer_used) 
    2038     ELSE 
    2039       IF (l_dbg) WRITE (*,*) 'histwrite : buffer has not been used. ', & 
    2040  &      'We have just to re-allocate it.' 
    2041       DEALLOCATE(buffer) 
    2042       ALLOCATE(buffer(buff_pos)) 
    2043       buffer_sz = buff_pos 
    2044       buffer(:)=0.0 
    2045     ENDIF 
    2046   ENDIF 
    2047 !- 
    2048 ! The buffers are only deallocated when more space is needed. This 
    2049 ! reduces the umber of allocates but increases memory needs. 
    2050 !- 
    2051   IF (.NOT.ALLOCATED(buff_tmp2)) THEN 
     2007      WRITE(*,*) "histwrite_real 1.1 allocate tbf_2 ",SIZE(tbf_1) 
     2008    ENDIF 
     2009    ALLOCATE(tbf_2(W_F(idf)%W_V(iv)%datasz_max)) 
     2010  ELSE IF (W_F(idf)%W_V(iv)%datasz_max > SIZE(tbf_2)) THEN 
    20522011    IF (l_dbg) THEN 
    2053       WRITE(*,*) "histwrite_real 1.1 allocate buff_tmp2 ",SIZE(buff_tmp) 
    2054     ENDIF 
    2055     ALLOCATE(buff_tmp2(W_F(pfileid)%W_V(varid)%datasz_max)) 
    2056     buff_tmp2_sz = W_F(pfileid)%W_V(varid)%datasz_max 
    2057   ELSE IF (W_F(pfileid)%W_V(varid)%datasz_max > buff_tmp2_sz) THEN 
    2058     IF (l_dbg) THEN 
    2059       WRITE(*,*) "histwrite_real 1.2 re-allocate buff_tmp2 : ", & 
    2060      & SIZE(buff_tmp)," instead of ",SIZE(buff_tmp2) 
    2061     ENDIF 
    2062     DEALLOCATE(buff_tmp2) 
    2063     ALLOCATE(buff_tmp2(W_F(pfileid)%W_V(varid)%datasz_max)) 
    2064     buff_tmp2_sz = W_F(pfileid)%W_V(varid)%datasz_max 
    2065   ENDIF 
    2066 !- 
    2067   rtime = pitau*W_F(pfileid)%deltat 
    2068   tmp_opp = W_F(pfileid)%W_V(varid)%topp 
    2069 !- 
    2070 ! 3.0 Do the operations or transfer the slab of data into buff_tmp 
    2071 !- 
    2072   IF (l_dbg) WRITE(*,*) "histwrite: 3.0",pfileid 
     2012      WRITE(*,*) "histwrite_real 1.2 re-allocate tbf_2 : ", & 
     2013     & SIZE(tbf_1)," instead of ",SIZE(tbf_2) 
     2014    ENDIF 
     2015    DEALLOCATE(tbf_2) 
     2016    ALLOCATE(tbf_2(W_F(idf)%W_V(iv)%datasz_max)) 
     2017  ENDIF 
     2018!- 
     2019  rtime = pitau*W_F(idf)%deltat 
     2020  tmp_opp = W_F(idf)%W_V(iv)%topp 
     2021!- 
     2022! 3.0 Do the operations or transfer the slab of data into tbf_1 
     2023!- 
     2024  IF (l_dbg) THEN 
     2025    WRITE(*,*) "histwrite: 3.0",idf 
     2026  ENDIF 
    20732027!- 
    20742028! 3.1 DO the Operations only if needed 
    20752029!- 
    20762030  IF (do_oper) THEN 
    2077     i = pfileid 
    20782031    nbout = nbdpt 
    20792032!- 
     
    20812034!--     we started in the interface routine 
    20822035!- 
    2083     DO io=2,W_F(i)%W_V(varid)%nbopp,2 
     2036    DO io=2,W_F(idf)%W_V(iv)%nbopp,2 
    20842037      nbin = nbout 
    2085       nbout = W_F(i)%W_V(varid)%datasz_max 
    2086       CALL mathop(W_F(i)%W_V(varid)%sopp(io),nbin,buff_tmp, & 
    2087  &      missing_val,nbindex,nindex,W_F(i)%W_V(varid)%scal(io), & 
    2088  &      nbout,buff_tmp2) 
     2038      nbout = W_F(idf)%W_V(iv)%datasz_max 
     2039      CALL mathop(W_F(idf)%W_V(iv)%sopp(io),nbin,tbf_1, & 
     2040 &      missing_val,nbindex,nindex,W_F(idf)%W_V(iv)%scal(io), & 
     2041 &      nbout,tbf_2) 
    20892042      IF (l_dbg) THEN 
    20902043        WRITE(*,*) & 
    2091  &       "histwrite: 3.4a nbout : ",nbin,nbout,W_F(i)%W_V(varid)%sopp(io) 
     2044 &       "histwrite: 3.4a nbout : ",nbin,nbout,W_F(idf)%W_V(iv)%sopp(io) 
    20922045      ENDIF 
    20932046!- 
    20942047      nbin = nbout 
    2095       nbout = W_F(i)%W_V(varid)%datasz_max 
    2096       CALL mathop(W_F(i)%W_V(varid)%sopp(io+1),nbin,buff_tmp2, & 
    2097  &      missing_val,nbindex,nindex,W_F(i)%W_V(varid)%scal(io+1), & 
    2098  &      nbout,buff_tmp) 
     2048      nbout = W_F(idf)%W_V(iv)%datasz_max 
     2049      CALL mathop(W_F(idf)%W_V(iv)%sopp(io+1),nbin,tbf_2, & 
     2050 &      missing_val,nbindex,nindex,W_F(idf)%W_V(iv)%scal(io+1), & 
     2051 &      nbout,tbf_1) 
    20992052      IF (l_dbg) THEN 
    21002053        WRITE(*,*) & 
    2101  &     "histwrite: 3.4b nbout : ",nbin,nbout,W_F(i)%W_V(varid)%sopp(io+1) 
     2054 &     "histwrite: 3.4b nbout : ",nbin,nbout,W_F(idf)%W_V(iv)%sopp(io+1) 
    21022055      ENDIF 
    21032056    ENDDO 
     
    21072060    IF (l_dbg) THEN 
    21082061      WRITE(*,*) & 
    2109  &     "histwrite: 3.5 size(buff_tmp) : ",SIZE(buff_tmp) 
     2062 &     "histwrite: 3.5 size(tbf_1) : ",SIZE(tbf_1) 
    21102063      WRITE(*,*) & 
    21112064 &     "histwrite: 3.5 slab in X :", & 
    2112  &     W_F(i)%W_V(varid)%zorig(1),W_F(i)%W_V(varid)%zsize(1) 
     2065 &     W_F(idf)%W_V(iv)%zorig(1),W_F(idf)%W_V(iv)%zsize(1) 
    21132066      WRITE(*,*) & 
    21142067 &     "histwrite: 3.5 slab in Y :", & 
    2115  &     W_F(i)%W_V(varid)%zorig(2),W_F(i)%W_V(varid)%zsize(2) 
     2068 &     W_F(idf)%W_V(iv)%zorig(2),W_F(idf)%W_V(iv)%zsize(2) 
    21162069      WRITE(*,*) & 
    21172070 &     "histwrite: 3.5 slab in Z :", & 
    2118  &     W_F(i)%W_V(varid)%zorig(3),W_F(i)%W_V(varid)%zsize(3) 
     2071 &     W_F(idf)%W_V(iv)%zorig(3),W_F(idf)%W_V(iv)%zsize(3) 
    21192072      WRITE(*,*) & 
    21202073 &     "histwrite: 3.5 slab of input:", & 
    2121  &     W_F(i)%W_V(varid)%scsize(1), & 
    2122  &     W_F(i)%W_V(varid)%scsize(2), & 
    2123  &     W_F(i)%W_V(varid)%scsize(3) 
     2074 &     W_F(idf)%W_V(iv)%scsize(1), & 
     2075 &     W_F(idf)%W_V(iv)%scsize(2), & 
     2076 &     W_F(idf)%W_V(iv)%scsize(3) 
    21242077    ENDIF 
    21252078!--- 
    21262079!-- We have to consider blocks of contiguous data 
    21272080!--- 
    2128     nx=MAX(W_F(i)%W_V(varid)%zsize(1),1) 
    2129     ny=MAX(W_F(i)%W_V(varid)%zsize(2),1) 
    2130     nz=MAX(W_F(i)%W_V(varid)%zsize(3),1) 
    2131     IF     (     (W_F(i)%W_V(varid)%zorig(1) == 1) & 
    2132  &          .AND.(   W_F(i)%W_V(varid)%zsize(1) & 
    2133  &                == W_F(i)%W_V(varid)%scsize(1)) & 
    2134  &          .AND.(W_F(i)%W_V(varid)%zorig(2) == 1) & 
    2135  &          .AND.(   W_F(i)%W_V(varid)%zsize(2) & 
    2136  &                == W_F(i)%W_V(varid)%scsize(2))) THEN 
    2137       kt = (W_F(i)%W_V(varid)%zorig(3)-1)*nx*ny 
    2138       buff_tmp2(1:nx*ny*nz) = buff_tmp(kt+1:kt+nx*ny*nz) 
    2139     ELSEIF (     (W_F(i)%W_V(varid)%zorig(1) == 1) & 
    2140  &          .AND.(   W_F(i)%W_V(varid)%zsize(1) & 
    2141  &                == W_F(i)%W_V(varid)%scsize(1))) THEN 
     2081    nx=MAX(W_F(idf)%W_V(iv)%zsize(1),1) 
     2082    ny=MAX(W_F(idf)%W_V(iv)%zsize(2),1) 
     2083    nz=MAX(W_F(idf)%W_V(iv)%zsize(3),1) 
     2084    IF     (     (W_F(idf)%W_V(iv)%zorig(1) == 1) & 
     2085 &          .AND.(   W_F(idf)%W_V(iv)%zsize(1) & 
     2086 &                == W_F(idf)%W_V(iv)%scsize(1)) & 
     2087 &          .AND.(W_F(idf)%W_V(iv)%zorig(2) == 1) & 
     2088 &          .AND.(   W_F(idf)%W_V(iv)%zsize(2) & 
     2089 &                == W_F(idf)%W_V(iv)%scsize(2))) THEN 
     2090      kt = (W_F(idf)%W_V(iv)%zorig(3)-1)*nx*ny 
     2091      tbf_2(1:nx*ny*nz) = tbf_1(kt+1:kt+nx*ny*nz) 
     2092    ELSEIF (     (W_F(idf)%W_V(iv)%zorig(1) == 1) & 
     2093 &          .AND.(   W_F(idf)%W_V(iv)%zsize(1) & 
     2094 &                == W_F(idf)%W_V(iv)%scsize(1))) THEN 
    21422095      kc = -nx*ny 
    2143       DO kz=W_F(i)%W_V(varid)%zorig(3),W_F(i)%W_V(varid)%zorig(3)+nz-1 
     2096      DO kz=W_F(idf)%W_V(iv)%zorig(3),W_F(idf)%W_V(iv)%zorig(3)+nz-1 
    21442097        kc = kc+nx*ny 
    2145         kt = ( (kz-1)*W_F(i)%W_V(varid)%scsize(2) & 
    2146  &            +W_F(i)%W_V(varid)%zorig(2)-1)*nx 
    2147         buff_tmp2(kc+1:kc+nx*ny) = buff_tmp(kt+1:kt+nx*ny) 
     2098        kt = ( (kz-1)*W_F(idf)%W_V(iv)%scsize(2) & 
     2099 &            +W_F(idf)%W_V(iv)%zorig(2)-1)*nx 
     2100        tbf_2(kc+1:kc+nx*ny) = tbf_1(kt+1:kt+nx*ny) 
    21482101      ENDDO 
    21492102    ELSE 
    21502103      kc = -nx 
    2151       DO kz=W_F(i)%W_V(varid)%zorig(3),W_F(i)%W_V(varid)%zorig(3)+nz-1 
    2152         DO ky=W_F(i)%W_V(varid)%zorig(2),W_F(i)%W_V(varid)%zorig(2)+ny-1 
     2104      DO kz=W_F(idf)%W_V(iv)%zorig(3),W_F(idf)%W_V(iv)%zorig(3)+nz-1 
     2105        DO ky=W_F(idf)%W_V(iv)%zorig(2),W_F(idf)%W_V(iv)%zorig(2)+ny-1 
    21532106          kc = kc+nx 
    2154           kt = ((kz-1)*W_F(i)%W_V(varid)%scsize(2)+ky-1) & 
    2155  &            *W_F(i)%W_V(varid)%scsize(1) & 
    2156  &            +W_F(i)%W_V(varid)%zorig(1)-1 
    2157           buff_tmp2(kc+1:kc+nx) = buff_tmp(kt+1:kt+nx) 
     2107          kt = ((kz-1)*W_F(idf)%W_V(iv)%scsize(2)+ky-1) & 
     2108 &            *W_F(idf)%W_V(iv)%scsize(1) & 
     2109 &            +W_F(idf)%W_V(iv)%zorig(1)-1 
     2110          tbf_2(kc+1:kc+nx) = tbf_1(kt+1:kt+nx) 
    21582111        ENDDO 
    21592112      ENDDO 
    21602113    ENDIF 
    21612114!- 
    2162 !-- 4.0 Get the min and max of the field (buff_tmp) 
    2163 !- 
    2164     IF (l_dbg) WRITE(*,*) "histwrite: 4.0 buff_tmp",pfileid,varid, & 
    2165  &    TRIM(tmp_opp),' ---- ',LEN_TRIM(tmp_opp),nbindex 
    2166 !- 
    2167     IF (W_F(pfileid)%W_V(varid)%hist_calc_rng) THEN 
    2168       W_F(pfileid)%W_V(varid)%hist_minmax(1) = & 
    2169  &      MIN(W_F(pfileid)%W_V(varid)%hist_minmax(1), & 
    2170  &      MINVAL(buff_tmp2(1:tsz),MASK=buff_tmp2(1:tsz) /= missing_val)) 
    2171       W_F(pfileid)%W_V(varid)%hist_minmax(2) = & 
    2172  &      MAX(W_F(pfileid)%W_V(varid)%hist_minmax(2), & 
    2173  &      MAXVAL(buff_tmp2(1:tsz),MASK=buff_tmp2(1:tsz) /= missing_val)) 
     2115!-- 4.0 Get the min and max of the field 
     2116!- 
     2117    IF (l_dbg) THEN 
     2118      WRITE(*,*) "histwrite: 4.0 tbf_1",idf,iv, & 
     2119 &      TRIM(tmp_opp),' ---- ',LEN_TRIM(tmp_opp),nbindex 
     2120    ENDIF 
     2121!- 
     2122    IF (W_F(idf)%W_V(iv)%hist_calc_rng) THEN 
     2123      W_F(idf)%W_V(iv)%hist_minmax(1) = & 
     2124 &      MIN(W_F(idf)%W_V(iv)%hist_minmax(1), & 
     2125 &      MINVAL(tbf_2(1:tsz),MASK=tbf_2(1:tsz) /= missing_val)) 
     2126      W_F(idf)%W_V(iv)%hist_minmax(2) = & 
     2127 &      MAX(W_F(idf)%W_V(iv)%hist_minmax(2), & 
     2128 &      MAXVAL(tbf_2(1:tsz),MASK=tbf_2(1:tsz) /= missing_val)) 
    21742129    ENDIF 
    21752130!- 
    21762131!-- 5.0 Do the operations if needed. In the case of instantaneous 
    2177 !--     output we do not transfer to the buffer. 
    2178 !- 
    2179     IF (l_dbg) WRITE(*,*) "histwrite: 5.0",pfileid,"tsz :",tsz 
    2180 !- 
    2181     ipt = W_F(pfileid)%W_V(varid)%point 
    2182 !- 
    2183 !   WRITE(*,*) 'OPE ipt, buffer :',pvarname,ipt,varid 
     2132!--     output we do not transfer to the time_buffer. 
     2133!- 
     2134    IF (l_dbg) THEN 
     2135      WRITE(*,*) "histwrite: 5.0 idf : ",idf," iv : ",iv," tsz : ",tsz 
     2136    ENDIF 
    21842137!- 
    21852138    IF (     (TRIM(tmp_opp) /= "inst") & 
    21862139 &      .AND.(TRIM(tmp_opp) /= "once") ) THEN 
    2187       CALL moycum(tmp_opp,tsz,buffer(ipt:), & 
    2188  &           buff_tmp2,W_F(pfileid)%W_V(varid)%nb_opp) 
    2189     ENDIF 
    2190 !- 
    2191     W_F(pfileid)%W_V(varid)%last_opp = pitau 
    2192     W_F(pfileid)%W_V(varid)%nb_opp = W_F(pfileid)%W_V(varid)%nb_opp+1 
     2140      CALL moycum(tmp_opp,tsz,W_F(idf)%W_V(iv)%t_bf, & 
     2141 &           tbf_2,W_F(idf)%W_V(iv)%nb_opp) 
     2142    ENDIF 
     2143!- 
     2144    W_F(idf)%W_V(iv)%last_opp = pitau 
     2145    W_F(idf)%W_V(iv)%nb_opp = W_F(idf)%W_V(iv)%nb_opp+1 
    21932146!- 
    21942147  ENDIF 
     
    21962149! 6.0 Write to file if needed 
    21972150!- 
    2198   IF (l_dbg) WRITE(*,*) "histwrite: 6.0",pfileid 
     2151  IF (l_dbg) WRITE(*,*) "histwrite: 6.0",idf 
    21992152!- 
    22002153  IF (do_write) THEN 
    22012154!- 
    2202     nfid = W_F(pfileid)%ncfid 
    2203     nvid = W_F(pfileid)%W_V(varid)%ncvid 
     2155    nfid = W_F(idf)%ncfid 
     2156    nvid = W_F(idf)%W_V(iv)%ncvid 
    22042157!- 
    22052158!-- 6.1 Do the operations that are needed before writting 
    22062159!- 
    2207     IF (l_dbg) WRITE(*,*) "histwrite: 6.1",pfileid 
     2160    IF (l_dbg) WRITE(*,*) "histwrite: 6.1",idf 
    22082161!- 
    22092162    IF (     (TRIM(tmp_opp) /= "inst") & 
    22102163 &      .AND.(TRIM(tmp_opp) /= "once") ) THEN 
    2211       rtime = ( rtime & 
    2212  &             +W_F(pfileid)%W_V(varid)%last_wrt*W_F(pfileid)%deltat)/2.0 
     2164      rtime = (rtime+W_F(idf)%W_V(iv)%last_wrt*W_F(idf)%deltat)/2.0 
    22132165    ENDIF 
    22142166!- 
     
    22192171 &      .AND.(TRIM(tmp_opp) /= "once") ) THEN 
    22202172!- 
    2221       IF (l_dbg) WRITE(*,*) "histwrite: 6.2",pfileid 
    2222 !- 
    2223       itax = W_F(pfileid)%W_V(varid)%t_axid 
    2224       itime = W_F(pfileid)%W_V(varid)%nb_wrt+1 
    2225 !- 
    2226       IF (W_F(pfileid)%W_V(itax)%tax_last < itime) THEN 
    2227         iret = NF90_PUT_VAR (nfid,W_F(pfileid)%W_V(itax)%tdimid, & 
     2173      IF (l_dbg) WRITE(*,*) "histwrite: 6.2",idf 
     2174!- 
     2175      itax  = W_F(idf)%W_V(iv)%t_axid 
     2176      itime = W_F(idf)%W_V(iv)%nb_wrt+1 
     2177!- 
     2178      IF (W_F(idf)%W_V(itax)%tax_last < itime) THEN 
     2179        iret = NF90_PUT_VAR (nfid,W_F(idf)%W_V(itax)%tdimid, & 
    22282180 &               (/ rtime /),start=(/ itime /),count=(/ 1 /)) 
    2229         W_F(pfileid)%W_V(itax)%tax_last = itime 
     2181        W_F(idf)%W_V(itax)%tax_last = itime 
    22302182      ENDIF 
    22312183    ELSE 
     
    22372189!- 
    22382190    IF (l_dbg) THEN 
    2239       WRITE(*,*) "histwrite: 6.3",pfileid,nfid,nvid,varid,itime 
    2240     ENDIF 
    2241 !- 
    2242     IF (W_F(pfileid)%W_V(varid)%scsize(3) == 1) THEN 
    2243       IF (W_F(pfileid)%regular) THEN 
     2191      WRITE(*,*) "histwrite: 6.3",idf,nfid,nvid,iv,itime 
     2192    ENDIF 
     2193!- 
     2194    IF (W_F(idf)%W_V(iv)%scsize(3) == 1) THEN 
     2195      IF (W_F(idf)%regular) THEN 
    22442196        corner(1:4) = (/ 1,1,itime,0 /) 
    2245         edges(1:4) = (/ W_F(pfileid)%W_V(varid)%zsize(1), & 
    2246  &                      W_F(pfileid)%W_V(varid)%zsize(2),1,0 /) 
     2197        edges(1:4) = (/ W_F(idf)%W_V(iv)%zsize(1), & 
     2198 &                      W_F(idf)%W_V(iv)%zsize(2),1,0 /) 
    22472199      ELSE 
    22482200        corner(1:4) = (/ 1,itime,0,0 /) 
    2249         edges(1:4) = (/ W_F(pfileid)%W_V(varid)%zsize(1),1,0,0 /) 
     2201        edges(1:4) = (/ W_F(idf)%W_V(iv)%zsize(1),1,0,0 /) 
    22502202      ENDIF 
    22512203    ELSE 
    2252       IF (W_F(pfileid)%regular) THEN 
     2204      IF (W_F(idf)%regular) THEN 
    22532205        corner(1:4) = (/ 1,1,1,itime /) 
    2254         edges(1:4) = (/ W_F(pfileid)%W_V(varid)%zsize(1), & 
    2255  &                      W_F(pfileid)%W_V(varid)%zsize(2), & 
    2256  &                      W_F(pfileid)%W_V(varid)%zsize(3),1 /) 
     2206        edges(1:4) = (/ W_F(idf)%W_V(iv)%zsize(1), & 
     2207 &                      W_F(idf)%W_V(iv)%zsize(2), & 
     2208 &                      W_F(idf)%W_V(iv)%zsize(3),1 /) 
    22572209      ELSE 
    22582210        corner(1:4) = (/ 1,1,itime,0 /) 
    2259         edges(1:4) = (/ W_F(pfileid)%W_V(varid)%zsize(1), & 
    2260  &                      W_F(pfileid)%W_V(varid)%zsize(3),1,0 /) 
     2211        edges(1:4) = (/ W_F(idf)%W_V(iv)%zsize(1), & 
     2212 &                      W_F(idf)%W_V(iv)%zsize(3),1,0 /) 
    22612213      ENDIF 
    22622214    ENDIF 
    2263 !- 
    2264     ipt = W_F(pfileid)%W_V(varid)%point 
    22652215!- 
    22662216    IF (     (TRIM(tmp_opp) /= "inst") & 
    22672217 &      .AND.(TRIM(tmp_opp) /= "once") ) THEN 
    2268       iret = NF90_PUT_VAR (nfid,nvid,buffer(ipt:), & 
    2269  &                       start=corner(1:4),count=edges(1:4)) 
     2218      iret = NF90_PUT_VAR (nfid,nvid,W_F(idf)%W_V(iv)%t_bf, & 
     2219 &                         start=corner(1:4),count=edges(1:4)) 
    22702220    ELSE 
    2271       iret = NF90_PUT_VAR (nfid,nvid,buff_tmp2, & 
    2272  &                       start=corner(1:4),count=edges(1:4)) 
    2273     ENDIF 
    2274 !- 
    2275     W_F(pfileid)%W_V(varid)%last_wrt = pitau 
    2276     W_F(pfileid)%W_V(varid)%nb_wrt = W_F(pfileid)%W_V(varid)%nb_wrt+1 
    2277     W_F(pfileid)%W_V(varid)%nb_opp = 0 
     2221      iret = NF90_PUT_VAR (nfid,nvid,tbf_2, & 
     2222 &                         start=corner(1:4),count=edges(1:4)) 
     2223    ENDIF 
     2224!- 
     2225    W_F(idf)%W_V(iv)%last_wrt = pitau 
     2226    W_F(idf)%W_V(iv)%nb_wrt = W_F(idf)%W_V(iv)%nb_wrt+1 
     2227    W_F(idf)%W_V(iv)%nb_opp = 0 
    22782228!--- 
    22792229!   After the write the file can be synchronized so that no data is 
     
    22882238END SUBROUTINE histwrite_real 
    22892239!=== 
    2290 SUBROUTINE histvar_seq (pfid,pvarname,pvid) 
    2291 !--------------------------------------------------------------------- 
    2292 !- This subroutine optimized the search for the variable in the table. 
     2240SUBROUTINE histvar_seq (idf,pvarname,idv) 
     2241!--------------------------------------------------------------------- 
     2242!- This subroutine optimize the search for the variable in the table. 
    22932243!- In a first phase it will learn the succession of the variables 
    22942244!- called and then it will use the table to guess what comes next. 
     
    22982248!- ARGUMENTS : 
    22992249!- 
    2300 !- pfid  : id of the file on which we work 
     2250!- idf      : id of the file on which we work 
    23012251!- pvarname : The name of the variable we are looking for 
    2302 !- pvid     : The var id we found 
     2252!- idv      : The var id we found 
    23032253!--------------------------------------------------------------------- 
    23042254  IMPLICIT NONE 
    23052255!- 
    2306   INTEGER,INTENT(in)  :: pfid 
     2256  INTEGER,INTENT(in)  :: idf 
    23072257  CHARACTER(LEN=*),INTENT(IN) :: pvarname 
    2308   INTEGER,INTENT(out) :: pvid 
     2258  INTEGER,INTENT(out) :: idv 
    23092259!- 
    23102260  LOGICAL,SAVE :: learning(nb_files_max)=.TRUE. 
     
    23212271!- 
    23222272  IF (l_dbg) THEN 
    2323     WRITE(*,*) 'histvar_seq, start of the subroutine :',learning(pfid) 
    2324   ENDIF 
    2325 !- 
    2326   IF (learning(pfid)) THEN 
     2273    WRITE(*,*) 'histvar_seq, start of the subroutine :',learning(idf) 
     2274  ENDIF 
     2275!- 
     2276  IF (learning(idf)) THEN 
    23272277!- 
    23282278!-- 1.0 We compute the length over which we are going 
    23292279!--     to check the overlap 
    23302280!- 
    2331     IF (overlap(pfid) <= 0) THEN 
    2332       IF (W_F(pfid)%n_var > 6) THEN 
    2333         overlap(pfid) = W_F(pfid)%n_var/3*2 
     2281    IF (overlap(idf) <= 0) THEN 
     2282      IF (W_F(idf)%n_var > 6) THEN 
     2283        overlap(idf) = W_F(idf)%n_var/3*2 
    23342284      ELSE 
    2335         overlap(pfid) = W_F(pfid)%n_var 
     2285        overlap(idf) = W_F(idf)%n_var 
    23362286      ENDIF 
    23372287    ENDIF 
     
    23392289!-- 1.1 Find the position of this string 
    23402290!- 
    2341     CALL find_str (W_F(pfid)%W_V(1:W_F(pfid)%n_var)%v_name,pvarname,pos) 
     2291    CALL find_str (W_F(idf)%W_V(1:W_F(idf)%n_var)%v_name,pvarname,pos) 
    23422292    IF (pos > 0) THEN 
    2343       pvid = pos 
     2293      idv = pos 
    23442294    ELSE 
    23452295      CALL ipslerr (3,"histvar_seq", & 
     
    23522302!--     in the sequence of calls 
    23532303!- 
    2354     IF (varseq_err(pfid) >= 0) THEN 
    2355       sp = varseq_len(pfid)+1 
     2304    IF (varseq_err(idf) >= 0) THEN 
     2305      sp = varseq_len(idf)+1 
    23562306      IF (sp <= nb_var_max*3) THEN 
    2357         varseq(pfid,sp) = pvid 
    2358         varseq_len(pfid) = sp 
     2307        varseq(idf,sp) = idv 
     2308        varseq_len(idf) = sp 
    23592309      ELSE 
    23602310        CALL ipslerr (2,"histvar_seq",& 
     
    23662316 &       ' contact the IOIPSL team. ') 
    23672317        WRITE(*,*) 'The sequence we have found up to now :' 
    2368         WRITE(*,*) varseq(pfid,1:sp-1) 
    2369         varseq_err(pfid) = -1 
     2318        WRITE(*,*) varseq(idf,1:sp-1) 
     2319        varseq_err(idf) = -1 
    23702320      ENDIF 
    23712321!- 
    23722322!---- 1.3 Check if we have found the right overlap 
    23732323!- 
    2374       IF (varseq_len(pfid) >= overlap(pfid)*2) THEN 
     2324      IF (varseq_len(idf) >= overlap(idf)*2) THEN 
    23752325!- 
    23762326!------ We skip a few variables if needed as they could come 
    23772327!------ from the initialisation of the model. 
    23782328!- 
    2379         DO ib = 0,sp-overlap(pfid)*2 
    2380           IF ( learning(pfid) .AND.& 
    2381             & SUM(ABS(varseq(pfid,ib+1:ib+overlap(pfid)) -& 
    2382             & varseq(pfid,sp-overlap(pfid)+1:sp))) == 0 ) THEN 
    2383             learning(pfid) = .FALSE. 
    2384             varseq_len(pfid) = sp-overlap(pfid)-ib 
    2385             varseq_pos(pfid) = overlap(pfid)+ib 
    2386             varseq(pfid,1:varseq_len(pfid)) = & 
    2387  &            varseq(pfid,ib+1:ib+varseq_len(pfid)) 
     2329        DO ib = 0,sp-overlap(idf)*2 
     2330          IF ( learning(idf) .AND.& 
     2331            & SUM(ABS(varseq(idf,ib+1:ib+overlap(idf)) -& 
     2332            & varseq(idf,sp-overlap(idf)+1:sp))) == 0 ) THEN 
     2333            learning(idf) = .FALSE. 
     2334            varseq_len(idf) = sp-overlap(idf)-ib 
     2335            varseq_pos(idf) = overlap(idf)+ib 
     2336            varseq(idf,1:varseq_len(idf)) = & 
     2337 &            varseq(idf,ib+1:ib+varseq_len(idf)) 
    23882338          ENDIF 
    23892339        ENDDO 
     
    23952345!--     and we can get a guess at the var ID 
    23962346!- 
    2397     nn = varseq_pos(pfid)+1 
    2398     IF (nn > varseq_len(pfid)) nn = 1 
    2399 !- 
    2400     pvid = varseq(pfid,nn) 
    2401 !- 
    2402     IF (TRIM(W_F(pfid)%W_V(pvid)%v_name) /= TRIM(pvarname)) THEN 
    2403       CALL find_str (W_F(pfid)%W_V(1:W_F(pfid)%n_var)%v_name,pvarname,pos) 
     2347    nn = varseq_pos(idf)+1 
     2348    IF (nn > varseq_len(idf)) nn = 1 
     2349!- 
     2350    idv = varseq(idf,nn) 
     2351!- 
     2352    IF (TRIM(W_F(idf)%W_V(idv)%v_name) /= TRIM(pvarname)) THEN 
     2353      CALL find_str (W_F(idf)%W_V(1:W_F(idf)%n_var)%v_name,pvarname,pos) 
    24042354      IF (pos > 0) THEN 
    2405         pvid = pos 
     2355        idv = pos 
    24062356      ELSE 
    24072357        CALL ipslerr (3,"histvar_seq", & 
     
    24102360 &  TRIM(pvarname)) 
    24112361      ENDIF 
    2412       varseq_err(pfid) = varseq_err(pfid)+1 
     2362      varseq_err(idf) = varseq_err(idf)+1 
    24132363    ELSE 
    24142364!- 
     
    24172367!---- not defeat the process. 
    24182368!- 
    2419       varseq_pos(pfid) = nn 
    2420     ENDIF 
    2421 !- 
    2422     IF (varseq_err(pfid) >= 10) THEN 
    2423       WRITE(str70,'("for file ",I3)') pfid 
     2369      varseq_pos(idf) = nn 
     2370    ENDIF 
     2371!- 
     2372    IF (varseq_err(idf) >= 10) THEN 
     2373      WRITE(str70,'("for file ",I3)') idf 
    24242374      CALL ipslerr (2,"histvar_seq", & 
    24252375 &  'There were 10 errors in the learned sequence of variables',& 
    24262376 &  str70,'This looks like a bug, please report it.') 
    2427          varseq_err(pfid) = 0 
     2377         varseq_err(idf) = 0 
    24282378    ENDIF 
    24292379  ENDIF 
     
    24312381  IF (l_dbg) THEN 
    24322382    WRITE(*,*) & 
    2433  &   'histvar_seq, end of the subroutine :',TRIM(pvarname),pvid 
     2383 &   'histvar_seq, end of the subroutine :',TRIM(pvarname),idv 
    24342384  ENDIF 
    24352385!------------------------- 
     
    24802430END SUBROUTINE histsync 
    24812431!=== 
    2482 SUBROUTINE histclo (fid) 
     2432SUBROUTINE histclo (idf) 
    24832433!--------------------------------------------------------------------- 
    24842434!- This subroutine will close all (or one if defined) opened files 
     
    24892439  IMPLICIT NONE 
    24902440!- 
    2491 ! fid  : optional argument for fileid 
    2492   INTEGER,INTENT(in),OPTIONAL :: fid 
     2441! idf  : optional argument for fileid 
     2442  INTEGER,INTENT(in),OPTIONAL :: idf 
    24932443!- 
    24942444  INTEGER :: ifile,nfid,nvid,iret,iv 
     
    25012451  IF (l_dbg) WRITE(*,*) 'Entering loop on files :',nb_files 
    25022452!- 
    2503   IF (PRESENT(fid)) THEN 
    2504     start_loop = fid 
    2505     end_loop = fid 
     2453  IF (PRESENT(idf)) THEN 
     2454    start_loop = idf 
     2455    end_loop = idf 
    25062456  ELSE 
    25072457    start_loop = 1 
Note: See TracChangeset for help on using the changeset viewer.