From 5f0a9cafdb1788d5537d3c92b913f7e9168696ed Mon Sep 17 00:00:00 2001 From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr> Date: Fri, 16 Mar 2018 15:36:16 +0100 Subject: [PATCH] Philippe 16/03/2018: lfi2cdf: remove file suffix from hinfile and houtfile to manage more cleanly filenames --- LIBTOOLS/tools/lfi2cdf/src/lfi2cdf.f90 | 4 +-- LIBTOOLS/tools/lfi2cdf/src/mode_options.f90 | 30 ++++++++++++++++++++- LIBTOOLS/tools/lfi2cdf/src/mode_util.f90 | 14 +++++----- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/LIBTOOLS/tools/lfi2cdf/src/lfi2cdf.f90 b/LIBTOOLS/tools/lfi2cdf/src/lfi2cdf.f90 index fd61b5533..cc67f8565 100644 --- a/LIBTOOLS/tools/lfi2cdf/src/lfi2cdf.f90 +++ b/LIBTOOLS/tools/lfi2cdf/src/lfi2cdf.f90 @@ -99,7 +99,7 @@ program LFI2CDF !Treat several LFI files and merge into 1 NC file !Determine first level (eg needed to find suffix of the variable name) - read( hinfile(len(hinfile)-6:len(hinfile)-4) , "(I3)" ) first_level + read( hinfile(len(hinfile)-2:len(hinfile)) , "(I3)" ) first_level nb_levels = options(OPTMERGE)%ivalue current_level = first_level last_level = first_level + nb_levels - 1 @@ -134,7 +134,7 @@ program LFI2CDF !Treat several NC files and merge into 1 NC file !Determine first level (eg needed to find suffix of the variable name) - read( hinfile(len(hinfile)-5:len(hinfile)-3) , "(I3)" ) first_level + read( hinfile(len(hinfile)-2:len(hinfile)) , "(I3)" ) first_level nb_levels = options(OPTMERGE)%ivalue current_level = first_level last_level = first_level + nb_levels - 1 diff --git a/LIBTOOLS/tools/lfi2cdf/src/mode_options.f90 b/LIBTOOLS/tools/lfi2cdf/src/mode_options.f90 index 06105bee0..56fc9afce 100644 --- a/LIBTOOLS/tools/lfi2cdf/src/mode_options.f90 +++ b/LIBTOOLS/tools/lfi2cdf/src/mode_options.f90 @@ -82,10 +82,13 @@ subroutine read_commandline(options,hinfile,houtfile,runmode) houtfile = options(OPTOUTPUT)%cvalue + call remove_suffix(hinfile) + call remove_suffix(houtfile) + !Remove level in the filename if merging LFI splitted files and output name not set by option if (.NOT.options(OPTOUTPUT)%set) then if (options(OPTMERGE)%set) then - houtfile=hinfile(1:len(hinfile)-9) + houtfile=hinfile(1:len(hinfile)-5) end if end if @@ -260,6 +263,31 @@ subroutine check_options(options,infile,runmode) end subroutine check_options + +subroutine remove_suffix(hfile) +character(len=:),allocatable,intent(inout) :: hfile + +integer :: idx1, idx2 +character(len=:),allocatable :: yfile + +idx1 = index(hfile,'.lfi',back=.true.) +idx2 = index(hfile,'.nc', back=.true.) + +if (idx1>0) then + yfile=hfile(1:idx1-1) +else if (idx2>0) then + yfile=hfile(1:idx2-1) +else + yfile=trim(hfile) +endif + +deallocate(hfile) +hfile = trim(yfile) +deallocate(yfile) + +end subroutine remove_suffix + + subroutine help() implicit none diff --git a/LIBTOOLS/tools/lfi2cdf/src/mode_util.f90 b/LIBTOOLS/tools/lfi2cdf/src/mode_util.f90 index 7a5ec9a23..49b9fd935 100644 --- a/LIBTOOLS/tools/lfi2cdf/src/mode_util.f90 +++ b/LIBTOOLS/tools/lfi2cdf/src/mode_util.f90 @@ -1291,7 +1291,7 @@ stop ! infiles%nbfiles = infiles%nbfiles + 1 idx = infiles%nbfiles - CALL IO_FILE_ADD2LIST(INFILES%TFILES(idx)%TFILE,HINFILE(1:LEN_TRIM(HINFILE)-4),'UNKNOWN','READ', & + CALL IO_FILE_ADD2LIST(INFILES%TFILES(idx)%TFILE,HINFILE,'UNKNOWN','READ', & HFORMAT='LFI',KLFIVERB=0) CALL IO_FILE_OPEN_ll(INFILES%TFILES(idx)%TFILE) infiles%files(idx)%lun_id = INFILES%TFILES(idx)%TFILE%NLFIFLU @@ -1362,7 +1362,7 @@ stop idx = outfiles%nbfiles CALL IO_FILE_ADD2LIST(OUTFILES%TFILES(idx)%TFILE,HOUTFILE,'UNKNOWN','WRITE', & - HFORMAT='NETCDF4') + HFORMAT='NETCDF4',OOLD=.TRUE.) CALL IO_FILE_OPEN_ll(OUTFILES%TFILES(idx)%TFILE,HPROGRAM_ORIG=CPROGRAM_ORIG) outfiles%files(idx)%lun_id = OUTFILES%TFILES(idx)%TFILE%NNCID outfiles%files(idx)%format = NETCDF_FORMAT @@ -1387,8 +1387,8 @@ stop ! outfiles%nbfiles = outfiles%nbfiles + 1 idx = outfiles%nbfiles - CALL IO_FILE_ADD2LIST(OUTFILES%TFILES(idx)%TFILE,TRIM(houtfile)//'.lfi','UNKNOWN','WRITE', & - HFORMAT='LFI',KLFIVERB=0) + CALL IO_FILE_ADD2LIST(OUTFILES%TFILES(idx)%TFILE,houtfile,'UNKNOWN','WRITE', & + HFORMAT='LFI',KLFIVERB=0,OOLD=.TRUE.) LIOCDF4 = .FALSE. !Necessary to open correctly the LFI file CALL IO_FILE_OPEN_ll(OUTFILES%TFILES(idx)%TFILE) LIOCDF4 = .TRUE. @@ -1420,7 +1420,7 @@ stop ilu = infiles%files(1)%lun_id !We assume only 1 infile write(suffix,'(I3.3)') current_level - filename=hinfile(1:len(hinfile)-7)//suffix//'.lfi' + filename=hinfile(1:len(hinfile)-4)//suffix CALL LFIOUV(iresp,ilu,ltrue,filename,'OLD',lfalse,lfalse,iverb,inap,nbvar) infiles%files(1)%opened = .TRUE. @@ -1440,7 +1440,7 @@ stop ALLOCATE(character(len=len(hinfile)) :: filename) write(suffix,'(I3.3)') current_level - filename=hinfile(1:len(hinfile)-6)//suffix//'.nc' + filename=hinfile(1:len(hinfile)-4)//suffix status = NF90_OPEN(filename,NF90_NOWRITE,infiles%files(1)%lun_id) IF (status /= NF90_NOERR) CALL HANDLE_ERR(status,__LINE__) infiles%files(1)%opened = .TRUE. @@ -1472,7 +1472,7 @@ stop IF (.NOT.tpreclist(ji)%tbw) CYCLE outfiles%files(idx)%var_id = ji - filename = trim(houtfile)//'.'//trim(tpreclist(ji)%name)//'.nc' + filename = trim(houtfile)//'.'//trim(tpreclist(ji)%name) CALL IO_FILE_ADD2LIST(OUTFILES%TFILES(idx)%TFILE,filename,'UNKNOWN','WRITE', & HFORMAT='NETCDF4') CALL IO_FILE_OPEN_ll(OUTFILES%TFILES(idx)%TFILE,HPROGRAM_ORIG=CPROGRAM_ORIG) -- GitLab