Index: IOIPSL/trunk/src/restcom.f90
===================================================================
--- IOIPSL/trunk/src/restcom.f90	(revision 386)
+++ IOIPSL/trunk/src/restcom.f90	(revision 428)
@@ -8,5 +8,5 @@
 USE netcdf
 !-
-USE errioipsl, ONLY : ipslerr
+USE errioipsl, ONLY : ipslerr,ipsldbg
 USE stringop
 USE calendar
@@ -212,6 +212,4 @@
   INTEGER,INTENT(IN),OPTIONAL :: domain_id
 !-
-! LOCAL
-!-
   INTEGER :: ncfid
   REAL :: dt_tmp,date0_tmp
@@ -219,6 +217,7 @@
   LOGICAL :: overwrite_time
   CHARACTER(LEN=120) :: fname
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
 !-
 ! 0.0 Prepare the configuration before opening any files
@@ -230,5 +229,5 @@
   ENDIF
 !-
-  IF (check) THEN
+  IF (l_dbg) THEN
     WRITE(*,*) 'restini 0.0 : ',TRIM(fnamein),' , ',TRIM(fnameout)
   ENDIF
@@ -254,5 +253,5 @@
   l_rw = l_fi.AND.l_fo.AND.(TRIM(fnamein) == TRIM(fnameout))
 !-
-  IF (check) THEN
+  IF (l_dbg) THEN
     WRITE(*,*) 'restini 0.1 l_fi, l_fo, l_rw : ',l_fi,l_fo,l_rw
   ENDIF
@@ -262,5 +261,5 @@
   IF (l_fi) THEN
 !---
-    IF (check) WRITE(*,*) 'restini 1.0 : Open input file'
+    IF (l_dbg) WRITE(*,*) 'restini 1.0 : Open input file'
 !-- Add DOMAIN number and ".nc" suffix in file names if needed
     fname = fnamein
@@ -285,5 +284,5 @@
 !-- 2.0 The case of a missing restart file is dealt with
 !---
-    IF (check) WRITE(*,*) 'restini 2.0'
+    IF (l_dbg) WRITE(*,*) 'restini 2.0'
 !---
     IF (     (ALL(MINLOC(lon(:iim,:jjm)) == MAXLOC(lon(:iim,:jjm)))) &
@@ -312,5 +311,5 @@
 !---
     tax_size_in(nb_fi) = 1
-    CALL rest_atim (check,'restini')
+    CALL rest_atim (l_dbg,'restini')
     t_index(nb_fi,1) = itau
     t_julian(nb_fi,1) = date0
@@ -340,5 +339,5 @@
 !     (to be modified in ioconf_calendar)
 !-
-  IF (check) THEN
+  IF (l_dbg) THEN
     WRITE(*,*) 'restini 2.3 : Configure calendar if needed : ', &
                 calend_str
@@ -347,5 +346,5 @@
   IF (INDEX(calend_str,'unknown') < 1) THEN
     CALL ioconf_calendar (calend_str)
-    IF (check) THEN
+    IF (l_dbg) THEN
       WRITE(*,*) 'restini 2.3b : new calendar : ',calend_str
     ENDIF
@@ -359,5 +358,5 @@
 !-
   fid = nb_fi
-  IF (check) THEN
+  IF (l_dbg) THEN
     WRITE(*,*) 'SIZE of t_index :',SIZE(t_index), &
                SIZE(t_index,dim=1),SIZE(t_index,dim=2)
@@ -366,5 +365,5 @@
   itau = t_index(fid,1)
 !-
-  IF (check) WRITE(*,*) 'restini END'
+  IF (l_dbg) WRITE(*,*) 'restini END'
 !---------------------
 END SUBROUTINE restini
@@ -387,6 +386,4 @@
   LOGICAL,INTENT(IN) :: l_rw
   INTEGER,INTENT(OUT) :: ncfid
-!-
-! LOCAL
 !-
   INTEGER,DIMENSION(max_dim) :: var_dims,dimlen
@@ -399,6 +396,7 @@
   CHARACTER(LEN=80) :: units
   CHARACTER(LEN=NF90_max_name),DIMENSION(max_dim) :: dimname
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
 !-
 ! If we reuse the same file for input and output
@@ -411,5 +409,5 @@
   ENDIF
 !-
-  IF (check) WRITE (*,*) "restopenin 0.0 ",TRIM(fname)
+  IF (l_dbg) WRITE (*,*) "restopenin 0.0 ",TRIM(fname)
   iret = NF90_INQUIRE(ncfid,nDimensions=nb_dim, &
  &         nVariables=nb_var,unlimitedDimId=id_unl)
@@ -435,16 +433,16 @@
     iret = NF90_INQUIRE_DIMENSION(ncfid,id, &
  &           len=dimlen(id),name=dimname(id))
-    IF (check) THEN
+    IF (l_dbg) THEN
       WRITE (*,*) "restopenin 0.0 dimname",id,TRIM(dimname(id))
     ENDIF
     IF      (TRIM(dimname(id)) == 'x') THEN
       iread = dimlen(id)
-      IF (check) WRITE (*,*) "iread",iread
+      IF (l_dbg) WRITE (*,*) "iread",iread
     ELSE IF (TRIM(dimname(id)) == 'y') THEN
       jread = dimlen(id)
-      IF (check) WRITE (*,*) "jread",jread
+      IF (l_dbg) WRITE (*,*) "jread",jread
     ELSE IF (TRIM(dimname(id)) == 'z') THEN
       lread = dimlen(id)
-      IF (check) WRITE (*,*) "lread",lread
+      IF (l_dbg) WRITE (*,*) "lread",lread
     ENDIF
   ENDDO
@@ -460,5 +458,5 @@
       itau_out(fid) = -1
       tdimid_out(fid) =  tdimid_in(fid)
-      IF (check) THEN
+      IF (l_dbg) THEN
         WRITE (*,*) &
  &       "restopenin 0.0 unlimited axis dimname", &
@@ -504,5 +502,5 @@
 ! 2.0 Get the list of variables
 !-
-  IF (check) WRITE(*,*) 'restopenin 1.2'
+  IF (l_dbg) WRITE(*,*) 'restopenin 1.2'
 !-
   lat_vid = -1
@@ -549,8 +547,7 @@
 !-- 2.3 Catch longitude and latitude variables
 !---
-    IF (INDEX(units,'degrees_nort') >= 1) THEN
+    IF      (INDEX(units,'degrees_nort') > 0) THEN
       lat_vid = iv
-    ENDIF
-    IF (INDEX(units,'degrees_east') >= 1) THEN
+    ELSE IF (INDEX(units,'degrees_east') > 0) THEN
       lon_vid = iv
     ENDIF
@@ -635,6 +632,4 @@
   LOGICAL,OPTIONAL :: owrite_time_in
 !-
-! LOCAL
-!-
   INTEGER :: ncfid,iret,it,iax,iv
   CHARACTER(LEN=80) :: itau_orig,tax_orig,calendar
@@ -644,7 +639,8 @@
   CHARACTER :: strc
   LOGICAL :: ow_time
-!-
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+!-
   IF (PRESENT(owrite_time_in)) THEN
     ow_time = owrite_time_in
@@ -657,5 +653,5 @@
 ! Allocate the space we need for the time axes
 !-
-  CALL rest_atim (check,'restsett')
+  CALL rest_atim (l_dbg,'restsett')
 !-
 ! Get the calendar if possible. Else it will be gregorian.
@@ -665,5 +661,5 @@
     IF (iret == NF90_NOERR) THEN
       CALL ioconf_calendar (calendar)
-      IF (check) THEN
+      IF (l_dbg) THEN
         WRITE(*,*) 'restsett : calendar of the restart ',calendar
       ENDIF
@@ -671,5 +667,5 @@
   ENDIF
   CALL ioget_calendar (one_year,one_day)
-  IF (check) THEN
+  IF (l_dbg) THEN
     WRITE(*,*) 'one_year,one_day = ',one_year,one_day
   ENDIF
@@ -683,5 +679,5 @@
     IF (ow_time) THEN
       t_index(nb_fi,:) = itau
-      IF (check) THEN
+      IF (l_dbg) THEN
         WRITE(*,*) "nb_fi,t_index",nb_fi,t_index(nb_fi,:)
       ENDIF
@@ -693,5 +689,5 @@
       seci = NINT(sec0)
       strc=':'
-      IF (check) THEN
+      IF (l_dbg) THEN
         WRITE(*,*) date0
         WRITE (UNIT=itau_orig,FMT='(I4.4,5(A,I2.2))') &
@@ -701,5 +697,5 @@
     ELSE
       iret = NF90_GET_VAR(ncfid,tind_varid_in(nb_fi),t_index(nb_fi,:))
-      IF (check) THEN
+      IF (l_dbg) THEN
         WRITE(*,*) "restsett, time axis : ",t_index(nb_fi,:)
       ENDIF
@@ -728,10 +724,10 @@
     tax_orig = tax_orig(INDEX(tax_orig,'since')+6:LEN_TRIM(tax_orig))
     iret = NF90_GET_ATT(ncfid,tax_varid_in(nb_fi),'calendar',tmp_cal)
-    IF (check) THEN
+    IF (l_dbg) THEN
       WRITE(*,*) 'restsett : tmp_calendar of the restart ',tmp_cal
     ENDIF
 !---
     CALL strlowercase (tmp_cal)
-    IF (INDEX(calend_str,tmp_cal) < 0) THEN
+    IF (INDEX(calend_str,tmp_cal) < 1) THEN
       IF (INDEX(calend_str,'unknown') > 0) THEN
         calend_str = tmp_cal
@@ -746,5 +742,5 @@
 !-- to get ride of the intial date.
 !---
-    IF (check) WRITE(*,*) 'tax_orig : ',TRIM(tax_orig)
+    IF (l_dbg) WRITE(*,*) 'tax_orig : ',TRIM(tax_orig)
     READ (UNIT=tax_orig,FMT='(I4.4,5(a,I2.2))') &
       year0,strc,month0,strc,day0,strc, &
@@ -757,10 +753,10 @@
 !-
   IF (     (INDEX(itau_orig,'XXXXX') > 0) &
-      .AND.(INDEX(tax_orig,'XXXXX')  < 0) ) THEN
+      .AND.(INDEX(tax_orig,'XXXXX')  < 1) ) THEN
 !!- Compute the t_itau from the date read and the timestep in the input
   ENDIF
 !-
   IF (     (INDEX(tax_orig,'XXXXX')  > 0) &
-      .AND.(INDEX(itau_orig,'XXXXX') < 0) ) THEN
+      .AND.(INDEX(itau_orig,'XXXXX') < 1) ) THEN
     DO it=1,tax_size_in(nb_fi)
       t_julian(nb_fi,it) = itau2date(t_index(nb_fi,it),date0,timestep)
@@ -819,6 +815,4 @@
   INTEGER,INTENT(IN),OPTIONAL :: domain_id
 !-
-! LOCAL
-!-
   INTEGER :: iret
   CHARACTER(LEN=70) :: str_t
@@ -831,7 +825,9 @@
             'JUL','AUG','SEP','OCT','NOV','DEC'/)
   CHARACTER(LEN=30) :: timenow
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
-  IF (check) WRITE(*,*) "restopenout 0.0 ",TRIM(fname)
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+!-
+  IF (l_dbg) WRITE(*,*) "restopenout 0.0 ",TRIM(fname)
 !-
 !  If we use the same file for input and output
@@ -865,5 +861,5 @@
 ! 1.0 Longitude
 !-
-  IF (check) WRITE(*,*) "restopenout 1.0"
+  IF (l_dbg) WRITE(*,*) "restopenout 1.0"
 !-
   iret = NF90_DEF_VAR(ncfid,"nav_lon",NF90_FLOAT,(/x_id,y_id/),nlonid)
@@ -875,5 +871,5 @@
 ! 2.0 Latitude
 !-
-  IF (check) WRITE(*,*) "restopenout 2.0"
+  IF (l_dbg) WRITE(*,*) "restopenout 2.0"
 !-
   iret = NF90_DEF_VAR(ncfid,"nav_lat",NF90_FLOAT,(/x_id,y_id/),nlatid)
@@ -885,5 +881,5 @@
 ! 3.0 Levels
 !-
-  IF (check) WRITE(*,*) "restopenout 3.0"
+  IF (l_dbg) WRITE(*,*) "restopenout 3.0"
 !-
   iret = NF90_DEF_VAR(ncfid,"nav_lev",NF90_FLOAT,z_id,nlevid)
@@ -897,5 +893,5 @@
 ! 4.0 Time axis, this is the seconds since axis
 !-
-  IF (check) WRITE(*,*) "restopenout 4.0"
+  IF (l_dbg) WRITE(*,*) "restopenout 4.0"
 !-
   iret = NF90_DEF_VAR(ncfid,"time",NF90_FLOAT, &
@@ -925,5 +921,5 @@
 ! 5.0 Time axis, this is the time steps since axis
 !-
-  IF (check) WRITE(*,*) "restopenout 5.0"
+  IF (l_dbg) WRITE(*,*) "restopenout 5.0"
 !-
   iret = NF90_DEF_VAR(ncfid,"time_steps",NF90_INT, &
@@ -986,5 +982,5 @@
   iret = NF90_REDEF(ncfid)
 !-
-  IF (check) WRITE(*,*) "restopenout END"
+  IF (l_dbg) WRITE(*,*) "restopenout END"
 !-------------------------
 END SUBROUTINE restopenout
@@ -1008,11 +1004,10 @@
   INTEGER :: nbindex,ijndex(nbindex)
 !-
-! LOCAL
-!-
   INTEGER :: req_sz,siz1
   REAL :: scal
   CHARACTER(LEN=7) :: topp
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
 !-
 ! 0.0 What size should be the data in the file
@@ -1033,6 +1028,6 @@
 !-
   siz1 = SIZE(var)
-  CALL rest_alloc (1,siz1,check,'restget_opp_r1d')
-  CALL rest_alloc (2,req_sz,check,'restget_opp_r1d')
+  CALL rest_alloc (1,siz1,l_dbg,'restget_opp_r1d')
+  CALL rest_alloc (2,req_sz,l_dbg,'restget_opp_r1d')
 !-
 ! 2.0 Here we get the variable from the restart file
@@ -1078,11 +1073,10 @@
   INTEGER :: nbindex,ijndex(nbindex)
 !-
-! LOCAL
-!-
   INTEGER :: jj,req_sz,ist,var_sz,siz1
   REAL :: scal
   CHARACTER(LEN=7) :: topp
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
 !-
 ! 0.0 What size should be the data in the file
@@ -1108,6 +1102,6 @@
 !-
   siz1 = SIZE(var,1)
-  CALL rest_alloc (1,siz1,check,'restget_opp_r2d')
-  CALL rest_alloc (2,req_sz*jjm,check,'restget_opp_r2d')
+  CALL rest_alloc (1,siz1,l_dbg,'restget_opp_r2d')
+  CALL rest_alloc (2,req_sz*jjm,l_dbg,'restget_opp_r2d')
 !-
 ! 2.0 Here we get the full variable from the restart file
@@ -1152,10 +1146,9 @@
   REAL :: var(:)
 !-
-! LOCAL
-!-
   INTEGER :: ji,jl,req_sz,var_sz,siz1
   CHARACTER(LEN=70) :: str,str2
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
 !-
 ! 1.0 Allocate the temporary buffer we need
@@ -1164,5 +1157,5 @@
   siz1 = SIZE(var)
   var_sz = siz1
-  CALL rest_alloc (1,var_sz,check,'restget_r1d')
+  CALL rest_alloc (1,var_sz,l_dbg,'restget_r1d')
 !-
 ! 2.0 Here we could check if the sizes specified agree
@@ -1216,10 +1209,9 @@
   REAL :: var(:,:)
 !-
-! LOCAL
-!-
   INTEGER :: ji,jj,jl,req_sz,var_sz,siz1,siz2
   CHARACTER(LEN=70) :: str,str2
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
 !-
 ! 1.0 Allocate the temporary buffer we need
@@ -1229,5 +1221,5 @@
   siz2 = SIZE(var,2)
   var_sz = siz1*siz2
-  CALL rest_alloc (1,var_sz,check,'restget_r2d')
+  CALL rest_alloc (1,var_sz,l_dbg,'restget_r2d')
 !-
 ! 2.0 Here we check if the sizes specified agree
@@ -1284,10 +1276,9 @@
   REAL :: var(:,:,:)
 !-
-! LOCAL
-!-
   INTEGER :: ji,jj,jk,jl,req_sz,var_sz,siz1,siz2,siz3
   CHARACTER(LEN=70) :: str,str2
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
 !-
 ! 1.0 Allocate the temporary buffer we need
@@ -1298,5 +1289,5 @@
   siz3 = SIZE(var,3)
   var_sz = siz1*siz2*siz3
-  CALL rest_alloc (1,var_sz,check,'restget_r3d')
+  CALL rest_alloc (1,var_sz,l_dbg,'restget_r3d')
 !-
 ! 2.0 Here we check if the sizes specified agree
@@ -1375,13 +1366,9 @@
   REAL :: var(:)
 !-
-! LOCAL
-!-
-  INTEGER :: vid,vnb,ncfid
-  INTEGER :: iret,index,it,ndim,ia
+  INTEGER :: vid,vnb,ncfid,iret,index,it,ndim,ia
   CHARACTER(LEN=70) str,str2
   CHARACTER(LEN=80) attname
   INTEGER,DIMENSION(4) :: corner,edge
 !---------------------------------------------------------------------
-!-
   ncfid = netcdf_id(fid,1)
 !-
@@ -1443,5 +1430,4 @@
       IF (t_index(fid,it) == itau)  index = it
     ENDDO
-!---
     IF (index < 0) THEN
       str = 'The time step requested for variable '//TRIM(vname_q)
@@ -1546,11 +1532,10 @@
   INTEGER :: nbindex,ijndex(nbindex)
 !-
-! LOCAL
-!-
   INTEGER :: req_sz,siz1
   REAL :: scal
   CHARACTER(LEN=7) :: topp
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
 !-
 ! 0.0 What size should be the data in the file
@@ -1571,6 +1556,6 @@
 !-
   siz1 = SIZE(var)
-  CALL rest_alloc (1,siz1,check,'restput_opp_r1d')
-  CALL rest_alloc (2,req_sz,check,'restput_opp_r1d')
+  CALL rest_alloc (1,siz1,l_dbg,'restput_opp_r1d')
+  CALL rest_alloc (2,req_sz,l_dbg,'restput_opp_r1d')
 !-
 ! 2.0 We do the operation needed.
@@ -1623,11 +1608,10 @@
   INTEGER :: nbindex,ijndex(nbindex)
 !-
-! LOCAL
-!-
   INTEGER :: jj,req_sz,ist,siz1
   REAL :: scal
   CHARACTER(LEN=7) :: topp
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
 !-
 ! 0.0 What size should be the data in the file
@@ -1653,6 +1637,6 @@
 !-
   siz1 = SIZE(var,1)
-  CALL rest_alloc (1,siz1,check,'restput_opp_r2d')
-  CALL rest_alloc (2,req_sz*jjm,check,'restput_opp_r2d')
+  CALL rest_alloc (1,siz1,l_dbg,'restput_opp_r2d')
+  CALL rest_alloc (2,req_sz*jjm,l_dbg,'restput_opp_r2d')
 !-
 ! 2.0 We do the operation needed.
@@ -1694,10 +1678,9 @@
   REAL :: var(:)
 !-
-! LOCAL
-!-
   INTEGER :: ji,jl,req_sz,var_sz,siz1
   CHARACTER(LEN=70) :: str,str2
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
 !-
 ! 1.0 Allocate the temporary buffer we need
@@ -1706,5 +1689,5 @@
   siz1 = SIZE(var)
   var_sz = siz1
-  CALL rest_alloc (1,var_sz,check,'restput_r1d')
+  CALL rest_alloc (1,var_sz,l_dbg,'restput_r1d')
 !-
 ! 2.0 Here we could check if the sizes specified agree
@@ -1753,10 +1736,9 @@
   REAL :: var(:,:)
 !-
-! LOCAL
-!-
   INTEGER :: ji,jj,jl,req_sz,var_sz,siz1,siz2
   CHARACTER(LEN=70) :: str,str2
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
 !-
 ! 1.0 Allocate the temporary buffer we need
@@ -1766,5 +1748,5 @@
   siz2 = SIZE(var,2)
   var_sz = siz1*siz2
-  CALL rest_alloc (1,var_sz,check,'restput_r2d')
+  CALL rest_alloc (1,var_sz,l_dbg,'restput_r2d')
 !-
 ! 2.0 Here we could check if the sizes specified agree
@@ -1814,10 +1796,9 @@
   REAL :: var(:,:,:)
 !-
-! LOCAL
-!-
   INTEGER :: ji,jj,jk,jl,req_sz,var_sz,siz1,siz2,siz3
   CHARACTER(LEN=70) :: str,str2
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
 !-
 ! 1.0 Allocate the temporary buffer we need
@@ -1828,5 +1809,5 @@
   siz3 = SIZE(var,3)
   var_sz = siz1*siz2*siz3
-  CALL rest_alloc (1,var_sz,check,'restput_r3d')
+  CALL rest_alloc (1,var_sz,l_dbg,'restput_r3d')
 !-
 ! 2.0 Here we could check if the sizes specified agree
@@ -1899,6 +1880,4 @@
   REAL :: var(:)
 !-
-! LOCAL
-!-
   INTEGER :: iret,vid,ncid,iv,vnb
   INTEGER :: ierr
@@ -1906,7 +1885,7 @@
   INTEGER :: ndims
   INTEGER,DIMENSION(4) :: corner,edge
-!-
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
 !-
 ! 0.0 Get some variables
@@ -1921,9 +1900,9 @@
 ! 1.0 Check if the variable is already present
 !-
-  IF (check) WRITE(*,*) 'RESTPUT 1.0 : ',TRIM(vname_q)
+  IF (l_dbg) WRITE(*,*) 'RESTPUT 1.0 : ',TRIM(vname_q)
 !-
   CALL find_str (varname_out(fid,1:nbvar_out(fid)),vname_q,vnb)
 !-
-  IF (check) THEN
+  IF (l_dbg) THEN
     WRITE(*,*) 'RESTPUT 1.1 : ',varname_out(fid,1:nbvar_out(fid)),vnb
   ENDIF
@@ -1938,5 +1917,5 @@
   vid = varid_out(fid,vnb)
 !-
-  IF (check) WRITE(*,*) 'RESTPUT 2.0 : ',vnb,vid
+  IF (l_dbg) WRITE(*,*) 'RESTPUT 2.0 : ',vnb,vid
 !-
 ! 2.1 Is this file already in write mode ?
@@ -1951,5 +1930,5 @@
 !     If not then check that all variables of previous time is OK.
 !-
-  IF (check) WRITE(*,*) 'RESTPUT 3.0 : ',itau,itau_out(fid)
+  IF (l_dbg) WRITE(*,*) 'RESTPUT 3.0 : ',itau,itau_out(fid)
 !-
   IF (itau /= itau_out(fid)) THEN
@@ -1989,5 +1968,5 @@
 !-- 3.1 Here we add the values to the time axes
 !---
-    IF (check) THEN
+    IF (l_dbg) THEN
       WRITE(*,*) 'RESTPUT 3.1 : ',itau,secsince,corner(1),edge(1)
     ENDIF
@@ -2052,12 +2031,11 @@
   LOGICAL :: write_att
 !-
-! Local
-!-
   INTEGER :: dims(4),ic,xloc,ndim,ncfid
   INTEGER :: iret,ax_id
   CHARACTER(LEN=3) :: str
-!-
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+!-
   ncfid = netcdf_id(fid,2)
   IF (nbvar_out(fid) >= max_var) THEN
@@ -2077,5 +2055,5 @@
 ! 1.0 Do we have all dimensions and can we go ahead
 !-
-  IF (check) THEN
+  IF (l_dbg) THEN
     WRITE(*,*) 'restdefv 1.0 :',TRIM(varname),nbvar_out(fid)
   ENDIF
@@ -2153,5 +2131,5 @@
 ! 2.0  Declare the variable
 !-
-  IF (check) THEN
+  IF (l_dbg) THEN
     WRITE(*,*) 'restdefv 2.0 :',ndim,' :: ',dims(1:ndim),tdimid_out(fid)
   ENDIF
@@ -2188,5 +2166,5 @@
   ENDIF
 !-
-  IF (check) THEN
+  IF (l_dbg) THEN
     WRITE(*,*) &
  &    'restdefv 3.0 : LIST OF VARS ',varname_out(fid,1:nbvar_out(fid))
@@ -2359,6 +2337,4 @@
 !-
   CHARACTER(LEN=*) :: attname,value
-!-
-! LOCAL
 !-
   CHARACTER(LEN=LEN_TRIM(attname)) :: tmp_str
@@ -2393,6 +2369,4 @@
   INTEGER,DIMENSION(varnbdim_max),INTENT(OUT) :: vardims
 !-
-! LOCAL
-!-
   INTEGER :: vnb
 !---------------------------------------------------------------------
@@ -2493,14 +2467,14 @@
   INTEGER,INTENT(in),OPTIONAL :: fid
 !-
-!- LOCAL
-!-
   INTEGER :: iret,ifnc
   CHARACTER(LEN=6) :: n_e
   CHARACTER(LEN=3) :: n_f
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+!-
   IF (PRESENT(fid)) THEN
 !---
-    IF (check) THEN
+    IF (l_dbg) THEN
       WRITE(*,*) &
         'restclo : Closing specified restart file number :', &
@@ -2535,5 +2509,5 @@
   ELSE
 !---
-    IF (check) WRITE(*,*) 'restclo : Closing all files'
+    IF (l_dbg) WRITE(*,*) 'restclo : Closing all files'
 !---
     DO ifnc=1,nb_fi
