Index: IOIPSL/trunk/src/histcom.f90
===================================================================
--- IOIPSL/trunk/src/histcom.f90	(revision 428)
+++ IOIPSL/trunk/src/histcom.f90	(revision 429)
@@ -12,5 +12,5 @@
   USE fliocom,  ONLY : flio_dom_file,flio_dom_att
   USE calendar
-  USE errioipsl, ONLY : ipslerr
+  USE errioipsl, ONLY : ipslerr,ipsldbg
 !-
   IMPLICIT NONE
@@ -236,9 +236,10 @@
   INTEGER,INTENT(IN),OPTIONAL :: domain_id
 !-
-  LOGICAL :: check = .FALSE.
-!-
   REAL,ALLOCATABLE,DIMENSION(:,:) :: lon_tmp,lat_tmp
-!---------------------------------------------------------------------
-  IF (check) WRITE(*,*) "histbeg_totreg"
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+!-
+  IF (l_dbg) WRITE(*,*) "histbeg_totreg"
 !-
   ALLOCATE (lon_tmp(pim,pjm),lat_tmp(pim,pjm))
@@ -328,7 +329,8 @@
   CHARACTER(LEN=30) :: timenow
   LOGICAL :: rectilinear
-!-
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+!-
   nb_files = nb_files+1
   pfileid  = nb_files
@@ -336,5 +338,5 @@
 ! 1.0 Transfering into the common for future use
 !-
-  IF (check) WRITE(*,*) "histbeg_regular 1.0"
+  IF (l_dbg) WRITE(*,*) "histbeg_regular 1.0"
 !-
   itau0(pfileid) = pitau0
@@ -350,5 +352,5 @@
 ! 2.0 Initializes all variables for this file
 !-
-  IF (check) WRITE(*,*) "histbeg_regular 2.0"
+  IF (l_dbg) WRITE(*,*) "histbeg_regular 2.0"
 !-
   IF (nb_files > nb_files_max) THEN
@@ -368,5 +370,5 @@
 ! 3.0 Opening netcdf file and defining dimensions
 !-
-  IF (check) WRITE(*,*) "histbeg_regular 3.0"
+  IF (l_dbg) WRITE(*,*) "histbeg_regular 3.0"
 !-
 ! Add DOMAIN number and ".nc" suffix in file name if needed
@@ -387,5 +389,5 @@
 ! 4.0 Declaring the geographical coordinates and other attributes
 !-
-  IF (check) WRITE(*,*) "histbeg_regular 4.0"
+  IF (l_dbg) WRITE(*,*) "histbeg_regular 4.0"
 !-
 ! 4.3 Global attributes
@@ -400,5 +402,5 @@
 ! 5.0 Saving some important information on this file in the common
 !-
-  IF (check) WRITE(*,*) "histbeg_regular 5.0"
+  IF (l_dbg) WRITE(*,*) "histbeg_regular 5.0"
 !-
   IF (PRESENT(domain_id)) THEN
@@ -476,7 +478,8 @@
   CHARACTER(LEN=120) :: file
   CHARACTER(LEN=30) :: timenow
-!-
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+!-
   nb_files = nb_files+1
   pfileid  = nb_files
@@ -484,5 +487,5 @@
 ! 1.0 Transfering into the common for future use
 !-
-  IF (check) WRITE(*,*) "histbeg_irregular 1.0"
+  IF (l_dbg) WRITE(*,*) "histbeg_irregular 1.0"
 !-
   itau0(pfileid) = pitau0
@@ -492,5 +495,5 @@
 ! 2.0 Initializes all variables for this file
 !-
-  IF (check) WRITE(*,*) "histbeg_irregular 2.0"
+  IF (l_dbg) WRITE(*,*) "histbeg_irregular 2.0"
 !-
   IF (nb_files > nb_files_max) THEN
@@ -510,5 +513,5 @@
 ! 3.0 Opening netcdf file and defining dimensions
 !-
-  IF (check) WRITE(*,*) "histbeg_irregular 3.0"
+  IF (l_dbg) WRITE(*,*) "histbeg_irregular 3.0"
 !-
 ! Add DOMAIN number and ".nc" suffix in file name if needed
@@ -524,5 +527,5 @@
 ! 4.0 Declaring the geographical coordinates and other attributes
 !-
-  IF (check) WRITE(*,*) "histbeg_irregular 4.0"
+  IF (l_dbg) WRITE(*,*) "histbeg_irregular 4.0"
 !-
 ! 4.3 Global attributes
@@ -537,5 +540,5 @@
 ! 5.0 Saving some important information on this file in the common
 !-
-  IF (check) WRITE(*,*) "histbeg_irregular 5.0"
+  IF (l_dbg) WRITE(*,*) "histbeg_irregular 5.0"
 !-
   IF (PRESENT(domain_id)) THEN
@@ -602,7 +605,7 @@
   INTEGER :: iret,ncid
   LOGICAL :: rectilinear
-!-
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
 !-
 ! 1.0 Check that all fits in the buffers
@@ -624,5 +627,5 @@
 ! 1.1 Create all the variables needed
 !-
-  IF (check) WRITE(*,*) "histhori_regular 1.0"
+  IF (l_dbg) WRITE(*,*) "histhori_regular 1.0"
 !-
   ncid = ncdf_ids(pfileid)
@@ -660,5 +663,5 @@
 ! 2.0 Longitude
 !-
-  IF (check) WRITE(*,*) "histhori_regular 2.0"
+  IF (l_dbg) WRITE(*,*) "histhori_regular 2.0"
 !-
   IF (rectilinear) THEN
@@ -681,5 +684,5 @@
 ! 3.0 Latitude
 !-
-  IF (check) WRITE(*,*) "histhori_regular 3.0"
+  IF (l_dbg) WRITE(*,*) "histhori_regular 3.0"
 !-
   IF (rectilinear) THEN
@@ -704,5 +707,5 @@
 ! 4.0 storing the geographical coordinates
 !-
-  IF (check) WRITE(*,*) "histhori_regular 4.0"
+  IF (l_dbg) WRITE(*,*) "histhori_regular 4.0"
 !-
   orix = slab_ori(pfileid,1)
@@ -778,7 +781,7 @@
   LOGICAL :: transp = .FALSE.
   REAL,ALLOCATABLE,DIMENSION(:,:) :: bounds_trans
-!-
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
 !-
 ! 1.0 Check that all fits in the buffers
@@ -794,5 +797,5 @@
 ! 1.1 Create all the variables needed
 !-
-  IF (check) WRITE(*,*) 'histhori_irregular 1.0'
+  IF (l_dbg) WRITE(*,*) 'histhori_irregular 1.0'
 !-
   ncid = ncdf_ids(pfileid)
@@ -842,5 +845,5 @@
 ! 2.0 Longitude
 !-
-  IF (check) WRITE(*,*) "histhori_irregular 2.0"
+  IF (l_dbg) WRITE(*,*) "histhori_irregular 2.0"
 !-
   iret = NF90_DEF_VAR (ncid,lon_name,NF90_FLOAT,dims(1:ndim),nlonid)
@@ -864,5 +867,5 @@
 ! 3.0 Latitude
 !-
-  IF (check) WRITE(*,*) "histhori_irregular 3.0"
+  IF (l_dbg) WRITE(*,*) "histhori_irregular 3.0"
 !-
   iret = NF90_DEF_VAR (ncid,lat_name,NF90_FLOAT,dims(1:ndim),nlatid)
@@ -888,5 +891,5 @@
 ! 4.0 storing the geographical coordinates
 !-
-  IF (check) WRITE(*,*) "histhori_irregular 4.0"
+  IF (l_dbg) WRITE(*,*) "histhori_irregular 4.0"
 !-
 ! 4.1 Write the longitude
@@ -960,6 +963,7 @@
   CHARACTER(LEN=20) :: direction
   INTEGER :: iret,leng,ncid
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
 !-
 ! 1.0 Verifications :
@@ -967,5 +971,5 @@
 !    Is the name already in use ?
 !-
-  IF (check) WRITE(*,*) "histvert : 1.0 Verifications", &
+  IF (l_dbg) WRITE(*,*) "histvert : 1.0 Verifications", &
  &                      pzaxname,'---',pzaxunit,'---',pzaxtitle
 !-
@@ -1018,5 +1022,5 @@
 ! 2.0 Add the information to the file
 !-
-  IF (check) &
+  IF (l_dbg) &
  &  WRITE(*,*) "histvert : 2.0 Add the information to the file"
 !-
@@ -1051,5 +1055,5 @@
 !- 3.0 add the information to the common
 !-
-  IF (check) &
+  IF (l_dbg) &
   &  WRITE(*,*) "histvert : 3.0 add the information to the common"
 !-
@@ -1132,7 +1136,8 @@
   REAL :: tmp_scal(nbopp_max),un_an,un_jour,test_fopp,test_fwrt
   INTEGER :: pos,buff_sz
-!-
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+!-
   ex_topps = 'ave, inst, t_min, t_max, t_sum, once, never, l_max, l_min'
 !-
@@ -1150,5 +1155,5 @@
 !     and verify that it does not already exist
 !-
-  IF (check) WRITE(*,*) "histdef : 1.0"
+  IF (l_dbg) WRITE(*,*) "histdef : 1.0"
 !-
   IF (iv > 1) THEN
@@ -1196,5 +1201,5 @@
 ! 2.0 Put the size of the variable in the common and check
 !-
-  IF (check) &
+  IF (l_dbg) &
  &  WRITE(*,*) "histdef : 2.0",pfileid,iv,nbopp(pfileid,iv), &
  &    sopps(pfileid,iv,1:nbopp(pfileid,iv)), &
@@ -1291,5 +1296,5 @@
 !     If it is instantaneous output then we do not use the buffer
 !-
-  IF (check) WRITE(*,*) "histdef : 3.0"
+  IF (l_dbg) WRITE(*,*) "histdef : 3.0"
 !-
 ! 3.1 We get the size of the arrays histwrite will get and check
@@ -1306,5 +1311,5 @@
     point(pfileid,iv) = buff_pos+1
     buff_pos = buff_pos+buff_sz
-    IF (check) THEN
+    IF (l_dbg) THEN
       WRITE(*,*) "histdef : 3.2 bufpos for iv = ",iv, &
  &               " pfileid = ",pfileid," is = ",point(pfileid,iv)
@@ -1317,5 +1322,5 @@
 !     The strategy is to bring it back to seconds for the tests
 !-
-  IF (check) WRITE(*,*) "histdef : 4.0"
+  IF (l_dbg) WRITE(*,*) "histdef : 4.0"
 !-
   freq_opp(pfileid,iv) = pfreq_opp
@@ -1401,5 +1406,5 @@
 ! 5.0 Initialize other variables of the common
 !-
-  IF (check) WRITE(*,*) "histdef : 5.0"
+  IF (l_dbg) WRITE(*,*) "histdef : 5.0"
 !-
   hist_wrt_rng(pfileid,iv) = (PRESENT(var_range))
@@ -1427,5 +1432,5 @@
 ! 6.0 Get the time axis for this variable
 !-
-  IF (check) WRITE(*,*) "histdef : 6.0"
+  IF (l_dbg) WRITE(*,*) "histdef : 6.0"
 !-
   IF (freq_wrt(pfileid,iv) > 0) THEN
@@ -1453,5 +1458,5 @@
     ENDIF
   ELSE
-    IF (check)   WRITE(*,*) "histdef : 7.0 ",TRIM(tmp_topp),'----'
+    IF (l_dbg)   WRITE(*,*) "histdef : 7.0 ",TRIM(tmp_topp),'----'
     var_axid(pfileid,iv) = -99
   ENDIF
@@ -1496,12 +1501,13 @@
  &     'JUL','AUG','SEP','OCT','NOV','DEC' /)
   CHARACTER(LEN=7) :: tmp_opp
-!-
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+!-
   ncid = ncdf_ids(pfileid)
 !-
 ! 1.0 Create the time axes
 !-
-  IF (check) WRITE(*,*) "histend : 1.0"
+  IF (l_dbg) WRITE(*,*) "histend : 1.0"
 !---
   iret = NF90_DEF_DIM (ncid,'time_counter',NF90_UNLIMITED,tid(pfileid))
@@ -1567,5 +1573,5 @@
 ! 2.0 declare the variables
 !-
-  IF (check) WRITE(*,*) "histend : 2.0"
+  IF (l_dbg) WRITE(*,*) "histend : 2.0"
 !-
   DO iv=1,nb_var(pfileid)
@@ -1595,5 +1601,5 @@
         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) = (/zax_ids(pfileid,ziv),tid(pfileid)/)
         ENDIF
       ELSE
@@ -1657,5 +1663,5 @@
         assoc = TRIM(str30)//' '//TRIM(assoc)
 !-
-        IF (check) THEN
+        IF (l_dbg) THEN
           WRITE(*,*) "histend : 2.0.n, freq_opp, freq_wrt", &
  &                   freq_opp(pfileid,iv),freq_wrt(pfileid,iv)
@@ -1679,5 +1685,5 @@
 ! 3.0 Put the netcdf file into write mode
 !-
-  IF (check) WRITE(*,*) "histend : 3.0"
+  IF (l_dbg) WRITE(*,*) "histend : 3.0"
 !-
   iret = NF90_ENDDEF (ncid)
@@ -1685,5 +1691,5 @@
 ! 4.0 Give some informations to the user
 !-
-  IF (check) WRITE(*,*) "histend : 4.0"
+  IF (l_dbg) WRITE(*,*) "histend : 4.0"
 !-
   WRITE(str70,'("All variables have been initialized on file :",I3)') pfileid
@@ -1752,7 +1758,8 @@
   CHARACTER(LEN=7) :: tmp_opp
   CHARACTER(LEN=13) :: c_nam
-!-
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+!-
   l1d=PRESENT(pdata_1d); l2d=PRESENT(pdata_2d); l3d=PRESENT(pdata_3d);
   IF      (l1d) THEN
@@ -1865,5 +1872,5 @@
 !-
     IF (.NOT.ALLOCATED(buff_tmp)) THEN
-      IF (check) THEN
+      IF (l_dbg) THEN
         WRITE(*,*) &
  &       c_nam//" : allocate buff_tmp for buff_sz = ", &
@@ -1873,5 +1880,5 @@
       buff_tmp_sz = datasz_max(pfileid,varid)
     ELSE IF (datasz_max(pfileid,varid) > buff_tmp_sz) THEN
-      IF (check) THEN
+      IF (l_dbg) THEN
         WRITE(*,*) &
  &       c_nam//" : re-allocate buff_tmp for buff_sz = ", &
@@ -1944,16 +1951,19 @@
   REAL,ALLOCATABLE,SAVE :: buffer_used(:)
   INTEGER,SAVE          :: buffer_sz
-!-
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
-  IF (check) THEN
-    WRITE(*,*) "histwrite 0.0 :  VAR : ",name(pfileid,varid)
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+!-
+  IF (l_dbg) THEN
+    WRITE(*,*) "histwrite 0.0 : VAR : ",name(pfileid,varid)
     WRITE(*,*) "histwrite 0.0 : nbindex,nindex :", &
-    &  nbindex,nindex(1:MIN(3,nbindex)),'...',nindex(MAX(1,nbindex-3):nbindex)
+ &  nbindex,nindex(1:MIN(3,nbindex)),'...',nindex(MAX(1,nbindex-3):nbindex)
   ENDIF
 !-
 ! The sizes which can be encoutered
 !-
-  tsz = zsize(pfileid,varid,1)*zsize(pfileid,varid,2)*zsize(pfileid,varid,3)
+  tsz =  zsize(pfileid,varid,1) &
+ &      *zsize(pfileid,varid,2) &
+ &      *zsize(pfileid,varid,3)
 !-
 ! 1.0 We allocate the memory needed to store the data between write
@@ -1962,12 +1972,16 @@
 !-
   IF (.NOT. ALLOCATED(buffer)) THEN
-    IF (check) WRITE(*,*) "histwrite_real 1.0 allocate buffer ",buff_pos
+    IF (l_dbg) WRITE(*,*) "histwrite_real 1.0 allocate buffer ",buff_pos
     ALLOCATE(buffer(buff_pos))
     buffer_sz = buff_pos
     buffer(:)=0.0
   ELSE IF (buffer_sz < buff_pos) THEN
-    IF (check) WRITE(*,*) "histwrite_real 1.0.1 re-allocate buffer for ",buff_pos," instead of ",SIZE(buffer)
+    IF (l_dbg) THEN
+      WRITE(*,*) "histwrite_real 1.0.1 re-allocate buffer for ", &
+ &      buff_pos," instead of ",SIZE(buffer)
+    ENDIF
     IF (SUM(buffer)/=0.0) THEN
-      IF (check) WRITE (*,*) ' histwrite : buffer has been used. We have to save it before re-allocating it '
+      IF (l_dbg) WRITE (*,*) 'histwrite : buffer has been used. ', &
+ &      'We have to save it before re-allocating.'
       ALLOCATE (buffer_used(buffer_sz))
       buffer_used(:)=buffer(:)
@@ -1979,5 +1993,6 @@
       DEALLOCATE (buffer_used)
     ELSE
-      IF (check) WRITE (*,*) ' histwrite : buffer has not been used. We have just to re-allocating it '
+      IF (l_dbg) WRITE (*,*) 'histwrite : buffer has not been used. ', &
+ &      'We have just to re-allocate it.'
       DEALLOCATE (buffer)
       ALLOCATE (buffer(buff_pos))
@@ -1991,5 +2006,5 @@
 !-
   IF (.NOT.ALLOCATED(buff_tmp2)) THEN
-    IF (check) THEN
+    IF (l_dbg) THEN
       WRITE(*,*) "histwrite_real 1.1 allocate buff_tmp2 ",SIZE(buff_tmp)
     ENDIF
@@ -1997,5 +2012,5 @@
     buff_tmp2_sz = datasz_max(pfileid,varid)
   ELSE IF (datasz_max(pfileid,varid) > buff_tmp2_sz) THEN
-    IF (check) THEN
+    IF (l_dbg) THEN
       WRITE(*,*) "histwrite_real 1.2 re-allocate buff_tmp2 : ", &
      & SIZE(buff_tmp)," instead of ",SIZE(buff_tmp2)
@@ -2011,5 +2026,5 @@
 ! 3.0 Do the operations or transfer the slab of data into buff_tmp
 !-
-  IF (check) WRITE(*,*) "histwrite: 3.0",pfileid
+  IF (l_dbg) WRITE(*,*) "histwrite: 3.0",pfileid
 !-
 ! 3.1 DO the Operations only if needed
@@ -2027,5 +2042,5 @@
       CALL mathop(sopps(i,varid,io),nbin,buff_tmp,missing_val, &
  &      nbindex,nindex,scal(i,varid,io),nbout,buff_tmp2)
-      IF (check) THEN
+      IF (l_dbg) THEN
         WRITE(*,*) &
  &       "histwrite: 3.4a nbout : ",nbin,nbout,sopps(i,varid,io)
@@ -2036,5 +2051,5 @@
       CALL mathop(sopps(i,varid,io+1),nbin,buff_tmp2,missing_val, &
  &      nbindex,nindex,scal(i,varid,io+1),nbout,buff_tmp)
-      IF (check) THEN
+      IF (l_dbg) THEN
         WRITE(*,*) &
  &       "histwrite: 3.4b nbout : ",nbin,nbout,sopps(i,varid,io+1)
@@ -2044,5 +2059,5 @@
 !   3.5 Zoom into the data
 !-
-    IF (check) THEN
+    IF (l_dbg) THEN
       WRITE(*,*) &
  &     "histwrite: 3.5 size(buff_tmp) : ",SIZE(buff_tmp)
@@ -2066,6 +2081,6 @@
 !-- 4.0 Get the min and max of the field (buff_tmp)
 !-
-    IF (check) WRITE(*,*) "histwrite: 4.0 buff_tmp",pfileid,varid, &
- &    TRIM(tmp_opp),'----',LEN_TRIM(tmp_opp),nbindex
+    IF (l_dbg) WRITE(*,*) "histwrite: 4.0 buff_tmp",pfileid,varid, &
+ &    TRIM(tmp_opp),' ---- ',LEN_TRIM(tmp_opp),nbindex
 !-
     IF (hist_calc_rng(pfileid,varid)) THEN
@@ -2081,5 +2096,5 @@
 !--     output we do not transfer to the buffer.
 !-
-    IF (check) WRITE(*,*) "histwrite: 5.0",pfileid,"tsz :",tsz
+    IF (l_dbg) WRITE(*,*) "histwrite: 5.0",pfileid,"tsz :",tsz
 !-
     ipt = point(pfileid,varid)
@@ -2100,5 +2115,5 @@
 ! 6.0 Write to file if needed
 !-
-  IF (check) WRITE(*,*) "histwrite: 6.0",pfileid
+  IF (l_dbg) WRITE(*,*) "histwrite: 6.0",pfileid
 !-
   IF (do_write) THEN
@@ -2109,5 +2124,5 @@
 !-- 6.1 Do the operations that are needed before writting
 !-
-    IF (check) WRITE(*,*) "histwrite: 6.1",pfileid
+    IF (l_dbg) WRITE(*,*) "histwrite: 6.1",pfileid
 !-
     IF (     (TRIM(tmp_opp) /= "inst") &
@@ -2122,5 +2137,5 @@
    &    .AND.(TRIM(tmp_opp) /= "once") ) THEN
 !-
-      IF (check) WRITE(*,*) "histwrite: 6.2",pfileid
+      IF (l_dbg) WRITE(*,*) "histwrite: 6.2",pfileid
 !-
       itax = var_axid(pfileid,varid)
@@ -2139,5 +2154,5 @@
 !       we do not write the buffer.
 !-
-    IF (check) THEN
+    IF (l_dbg) THEN
       WRITE(*,*) "histwrite: 6.3",pfileid,ncid,ncvarid,varid,itime
     ENDIF
@@ -2219,8 +2234,9 @@
   INTEGER      :: ib,sp,nx,pos
   CHARACTER(LEN=70) :: str70
-!-
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
-  IF (check) THEN
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+!-
+  IF (l_dbg) THEN
     WRITE(*,*) 'histvar_seq, start of the subroutine :',learning(pfid)
   ENDIF
@@ -2331,5 +2347,5 @@
   ENDIF
 !-
-  IF (check) THEN
+  IF (l_dbg) THEN
     WRITE(*,*) &
  &   'histvar_seq, end of the subroutine :',TRIM(pvarname),pvid
@@ -2354,7 +2370,9 @@
 !-
   LOGICAL :: file_exists
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
-  IF (check) WRITE(*,*) 'Entering loop on files :',nb_files
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+!-
+  IF (l_dbg) WRITE(*,*) 'Entering loop on files : ',nb_files
 !-
 ! 1.The loop on files to synchronise
@@ -2369,5 +2387,5 @@
 !-
     IF (file_exists) THEN
-      IF (check) THEN
+      IF (l_dbg) THEN
         WRITE(*,*) 'Synchronising specified file number :',file
       ENDIF
@@ -2395,8 +2413,9 @@
   INTEGER :: start_loop,end_loop
   CHARACTER(LEN=70) :: str70
-!-
-  LOGICAL :: check=.FALSE.
-!---------------------------------------------------------------------
-  IF (check) WRITE(*,*) 'Entering loop on files :',nb_files
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+!-
+  IF (l_dbg) WRITE(*,*) 'Entering loop on files :',nb_files
 !-
   IF (PRESENT(fid)) THEN
@@ -2409,5 +2428,5 @@
 !-
   DO ifile=start_loop,end_loop
-    IF (check) WRITE(*,*) 'Closing specified file number :',ifile
+    IF (l_dbg) WRITE(*,*) 'Closing specified file number :',ifile
     ncid = ncdf_ids(ifile)
     iret = NF90_REDEF (ncid)
@@ -2415,8 +2434,8 @@
 !-- 1. Loop on the number of variables to add some final information
 !---
-    IF (check) WRITE(*,*) 'Entering loop on vars : ',nb_var(ifile)
+    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 (check) THEN
+        IF (l_dbg) THEN
           WRITE(*,*) 'min value for file :',ifile,' var n. :',iv, &
          &           ' is : ',hist_minmax(ifile,iv,1)
@@ -2436,5 +2455,5 @@
 !-- 2. Close the file
 !---
-    IF (check) WRITE(*,*) 'close file :',ncid
+    IF (l_dbg) WRITE(*,*) 'close file :',ncid
     iret = NF90_CLOSE (ncid)
     IF (iret /= NF90_NOERR) THEN
