lfi2cdf: open and close files in separate subroutines in all cases (cleaner)
authorPhilippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Mon, 21 Sep 2015 12:07:40 +0000 (14:07 +0200)
committerPhilippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Mon, 2 May 2016 10:23:53 +0000 (12:23 +0200)
tools/lfi2cdf/src/lfi2cdf.f90
tools/lfi2cdf/src/mode_util.f90

index 4b9ae94..ca153fb 100644 (file)
@@ -19,9 +19,6 @@ subroutine  LFI2CDFMAIN(hinfile,iiflen,ooutname,houtfile,ioflen,hvarlist,ivlen,o
   INTEGER :: nbvar_tbw  ! number of variables to be written
   INTEGER :: nbvar      ! number of defined variables
   INTEGER :: first_level, current_level, last_level
-  INTEGER(KIND=LFI_INT) :: iresp,iverb,inap
-  CHARACTER(LEN=3)      :: suffix
-  CHARACTER(LEN=iiflen) :: filename
   TYPE(cdf_files) :: cdffiles
   TYPE(workfield), DIMENSION(:), POINTER :: tzreclist
 
@@ -87,7 +84,6 @@ subroutine  LFI2CDFMAIN(hinfile,iiflen,ooutname,houtfile,ioflen,hvarlist,ivlen,o
 
      ELSE
      !Treat several LFI files and merge into 1 NC file
-       iverb = 0 !Verbosity level for LFI
 
        !Determine first level (eg needed to find suffix of the variable name)
        read( hinfile(len(hinfile)-6:len(hinfile)-4) , "(I3)" ) first_level
@@ -103,13 +99,11 @@ subroutine  LFI2CDFMAIN(hinfile,iiflen,ooutname,houtfile,ioflen,hvarlist,ivlen,o
        DO current_level = first_level,last_level
          print *,'Treating level ',current_level
          IF (current_level/=first_level) THEN
-           write(suffix,'(I3.3)') current_level
-           filename=hinfile(1:len(hinfile)-7)//suffix//'.lfi'
-           CALL LFIOUV(iresp,ilu,ltrue,filename,'OLD',lfalse,lfalse,iverb,inap,nbvar_lfi)
+           CALL open_split_lfifile(ilu,hinfile,current_level)
            CALL read_data_lfi(ilu,hvarlist,nbvar,tzreclist,ibuflen,current_level)
          END IF
          CALL fill_ncdf(ilu,tzreclist,nbvar,ibuflen,cdffiles,current_level)
-         IF (current_level/=last_level) CALL LFIFER(iresp,ilu,'KEEP')
+         IF (current_level/=last_level) CALL close_split_lfifile(ilu)
        END DO
      END IF
 
index 9a1b0dd..97b3710 100644 (file)
@@ -1006,6 +1006,27 @@ print *,'lowmem: not tested!!!!!' (to be compared with no low mem version)
 
   END SUBROUTINE OPEN_FILES
 
+  SUBROUTINE OPEN_SPLIT_LFIFILE(ilu,hinfile,current_level)
+    INTEGER,          INTENT(IN) :: ilu
+    CHARACTER(LEN=*), INTENT(IN) :: hinfile
+    INTEGER,          INTENT(IN) :: current_level
+
+    INTEGER(KIND=LFI_INT) :: iresp,iverb,inap,nbvar
+
+    CHARACTER(LEN=3)      :: suffix
+    CHARACTER(LEN=:),ALLOCATABLE :: filename
+
+    iverb = 0 !Verbosity level for LFI
+
+    ALLOCATE(character(len=len(hinfile)) :: filename)
+
+    write(suffix,'(I3.3)') current_level
+    filename=hinfile(1:len(hinfile)-7)//suffix//'.lfi'
+    CALL LFIOUV(iresp,ilu,ltrue,filename,'OLD',lfalse,lfalse,iverb,inap,nbvar)
+
+    DEALLOCATE(filename)
+  END SUBROUTINE OPEN_SPLIT_LFIFILE
+
   SUBROUTINE OPEN_SPLIT_NCFILES(houtfile,nbvar,tpreclist,cdffiles,ohdf5)
     CHARACTER(LEN=*),              INTENT(IN)    :: houtfile
     INTEGER,                       INTENT(IN)    :: nbvar
@@ -1073,4 +1094,12 @@ print *,'lowmem: not tested!!!!!' (to be compared with no low mem version)
     
   END SUBROUTINE CLOSE_files
 
+  SUBROUTINE CLOSE_SPLIT_LFIFILE(ilu)
+    INTEGER, INTENT(IN) :: ilu
+
+    INTEGER(KIND=LFI_INT) :: iresp
+
+    CALL LFIFER(iresp,ilu,'KEEP')
+  END SUBROUTINE CLOSE_SPLIT_LFIFILE
+
 END MODULE mode_util