Index: IOIPSL/trunk/src/flincom.f90
===================================================================
--- IOIPSL/trunk/src/flincom.f90	(revision 1574)
+++ IOIPSL/trunk/src/flincom.f90	(revision 1660)
@@ -9,5 +9,5 @@
 !-
   USE calendar,  ONLY : ju2ymds, ymds2ju, ioconf_calendar
-  USE errioipsl, ONLY : histerr, ipslout
+  USE errioipsl, ONLY : histerr, ipslout,ipslerr,ipsldbg
   USE stringop,  ONLY : strlowercase
 !-
@@ -175,6 +175,8 @@
   CHARACTER(LEN=250):: name
 !-
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+
   lll = LEN_TRIM(filename)
   IF (filename(lll-2:lll) /= '.nc') THEN
@@ -193,5 +195,5 @@
 ! Vertical axis
 !-
-  IF (check) WRITE(ipslout,*) 'flincre Vertical axis'
+  IF (l_dbg) WRITE(ipslout,*) 'flincre Vertical axis'
 !-
   iret = NF90_DEF_VAR (fid, 'lev', NF90_FLOAT, zdimid1, levid)
@@ -202,5 +204,5 @@
 ! Time axis
 !-
-  IF (check) WRITE(ipslout,*) 'flincre time axis'
+  IF (l_dbg) WRITE(ipslout,*) 'flincre time axis'
 !-
   iret = NF90_DEF_VAR (fid, 'tstep', NF90_FLOAT, tdimid1, timeid)
@@ -211,5 +213,5 @@
 ! The longitude
 !-
-  IF (check) WRITE(ipslout,*) 'flincre Longitude axis'
+  IF (l_dbg) WRITE(ipslout,*) 'flincre Longitude axis'
 !-
   iret = NF90_DEF_VAR (fid, "nav_lon", NF90_FLOAT, &
@@ -226,5 +228,5 @@
 ! The Latitude
 !-
-  IF (check) WRITE(ipslout,*) 'flincre Latitude axis'
+  IF (l_dbg) WRITE(ipslout,*) 'flincre Latitude axis'
 !-
   iret = NF90_DEF_VAR (fid, "nav_lat", NF90_FLOAT, &
@@ -253,17 +255,17 @@
   iret = NF90_ENDDEF (fid)
 !-
-  IF (check) WRITE(ipslout,*) 'flincre Variable'
+  IF (l_dbg) WRITE(ipslout,*) 'flincre Variable'
 !-
   iret = NF90_PUT_VAR (fid, levid, lev1(1:llm1))
 !-
-  IF (check) WRITE(ipslout,*) 'flincre Time Variable'
+  IF (l_dbg) WRITE(ipslout,*) 'flincre Time Variable'
 !-
   iret = NF90_PUT_VAR (fid, timeid, REAL(itaus(1:ttm1)))
 !-
-  IF (check) WRITE(ipslout,*) 'flincre Longitude'
+  IF (l_dbg) WRITE(ipslout,*) 'flincre Longitude'
 !-
   iret = NF90_PUT_VAR (fid, lonid, lon1(1:iim1,1:jjm1))
 !-
-  IF (check) WRITE(ipslout,*) 'flincre Latitude'
+  IF (l_dbg) WRITE(ipslout,*) 'flincre Latitude'
 !-
   iret = NF90_PUT_VAR (fid, latid, lat1(1:iim1,1:jjm1))
@@ -311,10 +313,12 @@
   INTEGER :: fid_out
 !-
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
-  IF (check) WRITE (*,*) ' iideb, iilen, jjdeb, jjlen, iim, jjm ', &
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+
+  IF (l_dbg) WRITE (*,*) ' iideb, iilen, jjdeb, jjlen, iim, jjm ', &
                            iideb, iilen, jjdeb, jjlen, iim, jjm
-  IF (check) WRITE (*,*) ' lon ', lon(1,1), lon(iilen,jjlen)
-  IF (check) WRITE (*,*) ' lat ', lat(1,1), lat(iilen,jjlen)
+  IF (l_dbg) WRITE (*,*) ' lon ', lon(1,1), lon(iilen,jjlen)
+  IF (l_dbg) WRITE (*,*) ' lat ', lat(1,1), lat(iilen,jjlen)
 !-
   CALL flinopen_work &
@@ -388,9 +392,11 @@
 !-
   LOGICAL :: open_file
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+
   iilast = iideb+iilen-1
   jjlast = jjdeb+jjlen-1
-  IF (check) WRITE (*,*) &
+  IF (l_dbg) WRITE (*,*) &
     ' flinopen_work zoom 2D information '// &
     ' iideb, iilen, iilast, jjdeb, jjlen, jjlast ', &
@@ -422,5 +428,5 @@
   ENDIF
 !-
-  IF (check) &
+  IF (l_dbg) &
     WRITE(ipslout,*) 'OUT OF flininfo :',tmp_iim,tmp_jjm,tmp_llm,tmp_ttm
 !-
@@ -432,5 +438,5 @@
 ! 2.2 We test the axis if we have to.
 !-
-  IF (check) &
+  IF (l_dbg) &
     WRITE(ipslout,*) 'flininfo 2.2 We test if we have to test : ',do_test
 !-
@@ -453,5 +459,5 @@
 !-- 2.3 Else the sizes of the axes are returned to the user
 !---
-    IF (check) WRITE(ipslout,*) 'flinopen 2.3 Else sizes are returned'
+    IF (l_dbg) WRITE(ipslout,*) 'flinopen 2.3 Else sizes are returned'
 !---
     iim = tmp_iim
@@ -465,5 +471,5 @@
 !     if not then we get the lon, lat and lev variables from the file
 !-
-  IF (check) WRITE(ipslout,*) 'flinopen 3.0 we are realy talking'
+  IF (l_dbg) WRITE(ipslout,*) 'flinopen 3.0 we are realy talking'
 !-
   IF (do_test) THEN
@@ -473,8 +479,8 @@
     iret = NF90_GET_VAR (fid, vid, x_last, start=(/ iilast, jjlast /))
 !---
-    IF (check) &
+    IF (l_dbg) &
       WRITE(ipslout,*) 'from file lon first and last, modulo 360. ', &
         x_first, x_last, MODULO(x_first,360.), MODULO(x_last,360.)
-    IF (check) &
+    IF (l_dbg) &
       WRITE(ipslout,*) 'from model lon first and last, modulo 360. ', &
         lon(1,1),lon(iilen,jjlen), &
@@ -494,7 +500,7 @@
     iret = NF90_GET_VAR (fid, vid, x_last, start=(/ iilast, jjlast /))
 !---
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       'from file lat first and last ',x_first,x_last
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       'from model lat first and last ',lat(1,1),lat(iilen,jjlen)
 !---
@@ -512,7 +518,7 @@
       iret = NF90_GET_VAR (fid, vid, x_last, start=(/ llm /))
 !-----
-      IF (check) WRITE(ipslout,*) &
+      IF (l_dbg) WRITE(ipslout,*) &
         'from file lev first and last ',x_first ,x_last
-      IF (check) WRITE(ipslout,*) &
+      IF (l_dbg) WRITE(ipslout,*) &
         'from model lev first and last ',lev(1),lev(llm)
 !-----
@@ -530,5 +536,5 @@
 !-- 4.0 extracting the coordinates if we do not check
 !---
-    IF (check) WRITE(ipslout,*) 'flinopen 4.0 extracting the coordinates'
+    IF (l_dbg) WRITE(ipslout,*) 'flinopen 4.0 extracting the coordinates'
 !---
     CALL flinfindcood (fid_out, 'lon', vid, nbdim)
@@ -575,5 +581,5 @@
 ! 5.0 Get all the details for the time if possible needed
 !-
-  IF (check) WRITE(ipslout,*) 'flinopen 5.0 Get time'
+  IF (l_dbg) WRITE(ipslout,*) 'flinopen 5.0 Get time'
 !-
   IF (ttm > 0) THEN
@@ -609,5 +615,5 @@
     DEALLOCATE(vec_tmp)
 !---
-    IF (check) WRITE(ipslout,*) 'flinopen 5.1 Times ',itaus
+    IF (l_dbg) WRITE(ipslout,*) 'flinopen 5.1 Times ',itaus
 !---
 !-- Getting all the details for the time axis
@@ -629,5 +635,5 @@
       sec0 = hours0*3600. + minutes0*60. + seci
       CALL ymds2ju (year0, month0, day0, sec0, date0)
-      IF (check) &
+      IF (l_dbg) &
         WRITE(ipslout,*) 'flinopen 5.1 gdtt_id year0 ... date0 ', &
                    year0, month0, day0, sec0, date0
@@ -642,5 +648,5 @@
       CALL ymds2ju (year0, month0, day0, sec0, date0)
 !-----
-      IF (check) &
+      IF (l_dbg) &
         WRITE(ipslout,*) 'flinopen 5.1 gdtmaf_id year0 ... date0 ', &
                    year0, month0, day0, sec0, date0
@@ -660,5 +666,5 @@
   ENDIF
 !-
-  IF (check) WRITE(ipslout,*) 'flinopen 6.0 File opened', date0, dt
+  IF (l_dbg) WRITE(ipslout,*) 'flinopen 6.0 File opened', date0, dt
 !---------------------------
 END SUBROUTINE flinopen_work
@@ -688,6 +694,8 @@
   CHARACTER(LEN=30) :: axname
 !-
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+
   lll = LEN_TRIM(filename)
   IF (filename(lll-2:lll) /= '.nc') THEN
@@ -716,5 +724,5 @@
     axname = ADJUSTL(axname)
 !---
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       'flininfo - getting axname',iv,axname,lll
 !---
@@ -778,7 +786,9 @@
 !-
   INTEGER :: fid, ncvarid, ndim, iret
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
-  IF (check) WRITE(ipslout,*) &
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+
+  IF (l_dbg) WRITE(ipslout,*) &
      "flinput_r1d : SIZE(var) = ",SIZE(var)
 !-
@@ -805,7 +815,9 @@
 !-
   INTEGER :: fid, ncvarid, ndim, iret
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
-  IF (check) WRITE(ipslout,*) &
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+
+  IF (l_dbg) WRITE(ipslout,*) &
      "flinput_r2d : SIZE(var) = ",SIZE(var)
 !-
@@ -832,7 +844,9 @@
 !-
   INTEGER :: fid, ncvarid, ndim, iret
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
-  IF (check) WRITE(ipslout,*) &
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+
+  IF (l_dbg) WRITE(ipslout,*) &
      "flinput_r3d : SIZE(var) = ",SIZE(var)
 !-
@@ -859,7 +873,9 @@
 !-
   INTEGER :: fid, ncvarid, ndim, iret
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
-  IF (check) WRITE(ipslout,*) &
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+
+  IF (l_dbg) WRITE(ipslout,*) &
      "flinput_r4d : SIZE(var) = ",SIZE(var)
 !-
@@ -958,12 +974,14 @@
   INTEGER :: jl, ji
   REAL,DIMENSION(:),ALLOCATABLE,SAVE :: buff_tmp
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+
   IF (.NOT.ALLOCATED(buff_tmp)) THEN
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       "flinget_r1d : allocate buff_tmp for buff_sz = ",SIZE(var)
     ALLOCATE (buff_tmp(SIZE(var)))
   ELSE IF (SIZE(var) > SIZE(buff_tmp)) THEN
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       "flinget_r1d : re-allocate buff_tmp for buff_sz = ",SIZE(var)
     DEALLOCATE (buff_tmp)
@@ -996,12 +1014,14 @@
   INTEGER :: jl, jj, ji
   REAL,DIMENSION(:),ALLOCATABLE,SAVE :: buff_tmp
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+
   IF (.NOT.ALLOCATED(buff_tmp)) THEN
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       "flinget_r2d : allocate buff_tmp for buff_sz = ",SIZE(var)
     ALLOCATE (buff_tmp(SIZE(var)))
   ELSE IF (SIZE(var) > SIZE(buff_tmp)) THEN
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       "flinget_r2d : re-allocate buff_tmp for buff_sz = ",SIZE(var)
     DEALLOCATE (buff_tmp)
@@ -1037,12 +1057,14 @@
   INTEGER :: jl, jj, ji
   REAL,DIMENSION(:),ALLOCATABLE,SAVE :: buff_tmp
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+
   IF (.NOT.ALLOCATED(buff_tmp)) THEN
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       "flinget_r2d_zoom : allocate buff_tmp for buff_sz = ",SIZE(var)
     ALLOCATE (buff_tmp(SIZE(var)))
   ELSE IF (SIZE(var) > SIZE(buff_tmp)) THEN
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       "flinget_r2d_zoom : re-allocate buff_tmp for buff_sz = ",SIZE(var)
     DEALLOCATE (buff_tmp)
@@ -1077,12 +1099,14 @@
   INTEGER :: jl, jk, jj, ji
   REAL,DIMENSION(:),ALLOCATABLE,SAVE :: buff_tmp
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+
   IF (.NOT.ALLOCATED(buff_tmp)) THEN
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       "flinget_r3d : allocate buff_tmp for buff_sz = ",SIZE(var)
     ALLOCATE (buff_tmp(SIZE(var)))
   ELSE IF (SIZE(var) > SIZE(buff_tmp)) THEN
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       "flinget_r3d : re-allocate buff_tmp for buff_sz = ",SIZE(var)
     DEALLOCATE (buff_tmp)
@@ -1120,12 +1144,14 @@
   INTEGER :: jl, jk, jj, ji
   REAL,DIMENSION(:),ALLOCATABLE,SAVE :: buff_tmp
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+
   IF (.NOT.ALLOCATED(buff_tmp)) THEN
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       "flinget_r3d_zoom : allocate buff_tmp for buff_sz = ",SIZE(var)
     ALLOCATE (buff_tmp(SIZE(var)))
   ELSE IF (SIZE(var) > SIZE(buff_tmp)) THEN
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       "flinget_r3d_zoom : re-allocate buff_tmp for buff_sz = ",SIZE(var)
     DEALLOCATE (buff_tmp)
@@ -1162,12 +1188,14 @@
   INTEGER :: jl, jk, jj, ji, jm
   REAL,DIMENSION(:),ALLOCATABLE,SAVE :: buff_tmp
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+
   IF (.NOT.ALLOCATED(buff_tmp)) THEN
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       "flinget_r4d : allocate buff_tmp for buff_sz = ",SIZE(var)
     ALLOCATE (buff_tmp(SIZE(var)))
   ELSE IF (SIZE(var) > SIZE(buff_tmp)) THEN
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       "flinget_r4d : re-allocate buff_tmp for buff_sz = ",SIZE(var)
     DEALLOCATE (buff_tmp)
@@ -1207,12 +1235,14 @@
   INTEGER :: jl, jk, jj, ji, jm
   REAL,DIMENSION(:),ALLOCATABLE,SAVE :: buff_tmp
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+
   IF (.NOT.ALLOCATED(buff_tmp)) THEN
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       "flinget_r4d_zoom : allocate buff_tmp for buff_sz = ",SIZE(var)
     ALLOCATE (buff_tmp(SIZE(var)))
   ELSE IF (SIZE(var) > SIZE(buff_tmp)) THEN
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       "flinget_r4d_zoom : re-allocate buff_tmp for buff_sz = ",SIZE(var)
     DEALLOCATE (buff_tmp)
@@ -1283,9 +1313,9 @@
 ! ARGUMENTS
 !-
-  INTEGER :: fid_in
-  CHARACTER(LEN=*) :: varname
-  INTEGER :: iim, jjm, llm, ttm
-  INTEGER :: itau_dep, itau_fin, iideb, iilen, jjdeb, jjlen
-  REAL :: var(:)
+  INTEGER, INTENT(IN) :: fid_in
+  CHARACTER(LEN=*), INTENT(IN) :: varname
+  INTEGER, INTENT(IN) :: iim, jjm, llm, ttm
+  INTEGER, INTENT(IN) :: itau_dep, itau_fin, iideb, iilen, jjdeb, jjlen
+  REAL, INTENT(OUT) :: var(:)
 !-
 ! LOCAL
@@ -1303,10 +1333,15 @@
   INTEGER :: i, nvars, i2d, cnd
   REAL,DIMENSION(:),ALLOCATABLE,SAVE :: var_tmp
+  INTEGER :: itau_len
   LOGICAL :: uncompress = .FALSE.
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
+  INTEGER :: il, ip, i2p, it
+  !-
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+  !-
   fid = ncids(fid_in)
 !-
-  IF (check) THEN
+  IF (l_dbg) THEN
     WRITE(ipslout,*) &
     'flinget_mat : fid_in, fid, varname :', fid_in, fid, TRIM(varname)
@@ -1335,5 +1370,5 @@
   iret = NF90_INQUIRE_VARIABLE (fid, vid, &
            ndims=ndims, dimids=dimids, nAtts=nb_atts)
-  IF (check) THEN
+  IF (l_dbg) THEN
     WRITE(ipslout,*) &
     'flinget_mat : fid, vid :', fid, vid
@@ -1347,5 +1382,5 @@
     iret  = NF90_INQUIRE_DIMENSION (fid, dimids(i), len=w_dim(i))
   ENDDO
-  IF (check) WRITE(ipslout,*) &
+  IF (l_dbg) WRITE(ipslout,*) &
     'flinget_mat : w_dim :', w_dim(1:ndims)
 !-
@@ -1353,5 +1388,5 @@
 !-
   IF (nb_atts > 0) THEN
-    IF (check) THEN
+     IF (l_dbg) THEN
       WRITE(ipslout,*) 'flinget_mat : attributes for variable :'
     ENDIF
@@ -1364,10 +1399,10 @@
              .OR.(x_typ == NF90_BYTE) ) THEN
       iret = NF90_GET_ATT (fid, vid, att_n, tmp_i)
-      IF (check) THEN
+        IF (l_dbg) THEN
         WRITE(ipslout,*) '   ',TRIM(att_n),' : ',tmp_i
       ENDIF
     ELSE IF ( (x_typ == NF90_FLOAT).OR.(x_typ == NF90_DOUBLE) ) THEN
       iret = NF90_GET_ATT (fid, vid, att_n, tmp_r)
-      IF (check) THEN
+        IF (l_dbg) THEN
         WRITE(ipslout,*) '   ',TRIM(att_n),' : ',tmp_r
       ENDIF
@@ -1378,5 +1413,5 @@
       tmp_n = ''
       iret = NF90_GET_ATT (fid, vid, att_n, tmp_n)
-      IF (check) THEN
+        IF (l_dbg) THEN
         WRITE(ipslout,*) '   ',TRIM(att_n),' : ',TRIM(tmp_n)
       ENDIF
@@ -1402,5 +1437,5 @@
     iret = NF90_INQ_VARID (fid, tmp_n, cvid)
 !---
-    IF (check) WRITE(ipslout,*) &
+    IF (l_dbg) WRITE(ipslout,*) &
       'Dimname, iret , NF90_NOERR : ',TRIM(tmp_n),iret,NF90_NOERR
 !---
@@ -1559,16 +1594,17 @@
 ! 3.0 Reading the data
 !-
-  IF (check) WRITE(ipslout,*) &
+  IF (l_dbg) WRITE(ipslout,*) &
     'flinget_mat 3.0 : ', uncompress, w_sta, w_len
 !---
+  var(:) = mis_v
   IF (uncompress) THEN
 !---
     IF (ALLOCATED(var_tmp)) THEN
-      IF (SIZE(var_tmp) < clen) THEN
-        DEALLOCATE(var_tmp)
-        ALLOCATE(var_tmp(clen))
+      IF (SIZE(var_tmp) < PRODUCT(w_len(:),mask=(w_len>1))) THEN
+         DEALLOCATE(var_tmp)
+         ALLOCATE(var_tmp(PRODUCT(w_len(:),mask=(w_len>1))))
       ENDIF
     ELSE
-      ALLOCATE(var_tmp(clen))
+      ALLOCATE(var_tmp(PRODUCT(w_len(:),mask=(w_len>1))))
     ENDIF
 !---
@@ -1576,6 +1612,18 @@
              start=w_sta(:), count=w_len(:))
 !---
+    itau_len=itau_fin-itau_dep+1
+    IF (l_dbg) WRITE(ipslout,*) 'flinget_mat 3.0 : clen, itau_len ',clen,itau_len
     var(:) = mis_v
-    var(cindex(:)) = var_tmp(:)
+    IF (itau_len > 0) THEN
+       DO it=1,itau_len
+          DO il=1,clen
+             ip = il + (it-1)*clen
+             i2p = cindex(il)+(it-1)*iim*jjm
+             var(i2p) = var_tmp(ip)
+          ENDDO
+       ENDDO
+    ELSE
+       var(cindex(:)) = var_tmp(:)
+    ENDIF
 !---
   ELSE
@@ -1584,5 +1632,5 @@
   ENDIF
 !-
-  IF (check) WRITE(ipslout,*) 'flinget_mat 3.1 : ',NF90_STRERROR (iret)
+  IF (l_dbg) WRITE(ipslout,*) 'flinget_mat 3.1 : ',NF90_STRERROR (iret)
 !--------------------------
 END  SUBROUTINE flinget_mat
@@ -1632,7 +1680,9 @@
   INTEGER :: iret, fid
 !-
-  LOGICAL :: check = .FALSE.
-!---------------------------------------------------------------------
-  IF (check) THEN
+  LOGICAL :: l_dbg
+!---------------------------------------------------------------------
+  CALL ipsldbg (old_status=l_dbg)
+
+  IF (l_dbg) THEN
     WRITE (*,*) 'flinget_scal in file with id ',fid_in
   ENDIF
