Skip to content
Snippets Groups Projects
Commit 96e39e21 authored by Ian Boyd's avatar Ian Boyd
Browse files

Replace cds_convert.pro

parent c2145a9d
No related branches found
No related tags found
No related merge requests found
......@@ -92,7 +92,9 @@
; that write file creation date in SYSTIME form instead of DD MONTHNAME, YYYY
; 2021-06-17, v2.0b66 Ian Boyd Update due to fixes in idlcr8hdf
; 2022-08-09, v2.0b67 Ian Boyd Update due to fixes and improvements to idlcr8hdf and idlcr8ascii
; 2023-12-18, v2.0b68 Ian Boyd Update due to fixes to idlc8hdf
; 2023-12-18, v2.0b68 Ian Boyd Update due to fixes to idlcr8hdf
; 2024-01-12, v2.0b69 Ian Boyd Update due to fix to idlcr8hdf
; 2024-09-08, v2.0b70 Ian Boyd Update due to fix to idlcr8hdf
;---------------------------------------------------------------------------------------------------
PRO cds_convert_common
;Procedure to define the COMMON blocks for this program
......@@ -161,7 +163,7 @@ PRO intro
;Subroutines Called: INTRO_EVENT (via XMANAGER)
nhdr=22 & errtxt=STRARR(nhdr)
vertxt=['cds_convert_Readme.pdf',' Release v2.0b68, December 2023']
vertxt=['cds_convert_Readme.pdf',' Release v2.0b70, September 2024']
errtxt[1]='Conversion Data Suite (CDS): cds_convert'
errtxt[2]=vertxt[1]
errtxt[3]=' Converts supported original data into GEOMS compliant HDF data.'
......@@ -218,191 +220,199 @@ END
;---------------------------------------------------------------------------------------------------
PRO cds_convert
COMMON WIDGET_WIN_CDS
args = command_line_args()
iNrArgs = size(args, /N_ELEMENTS)
CDS_error_code = 3
if ( iNrArgs ne 6 ) and ( iNrArgs ne 4 ) then begin
o3='CANCEL'
INTRO
if o3 eq 'CANCEL' then begin
status=CDS_error_code
endif else begin ;Open File and Directory Selection Windows
CD,CURRENT=path ;identify current working directory
if strmid(o3,strlen(o3)-1,1) eq 'S' then begin
iNrArgs=6
chFileGEOMSTE=DIALOG_PICKFILE(Filter=['GEOMS*.csv'], PATH=path, $
/MUST_EXIST,Title='Select GEOMS Template File')
if chFileGEOMSTE eq '' then stop, status=CDS_error_code
path=FILE_DIRNAME(chFileGEOMSTE,/MARK_DIRECTORY)
if strpos(STRUPCASE(chFileGEOMSTE),'LIDAR') ne -1 then begin
chFileTranslation=DIALOG_PICKFILE(/DIRECTORY, $
Title='Select Directory containing Lidar Translation File', PATH=path)
if chFileTranslation ne '' then path=chFileTranslation
endif else begin
chFileTranslation=DIALOG_PICKFILE(Filter=['*translation*.txt'], PATH=path, $
/MUST_EXIST,Title='Select Translation File')
if chFileTranslation ne '' then path=FILE_DIRNAME(chFileTranslation,/MARK_DIRECTORY)
endelse
if chFileTranslation eq '' then stop, status=CDS_error_code
path=FILE_DIRNAME(chFileTranslation,/MARK_DIRECTORY)
chFileOrig=DIALOG_PICKFILE(PATH=path,/MUST_EXIST,Title='Select Original File to be Converted')
if chFileOrig eq '' then stop, status=CDS_error_code
path=FILE_DIRNAME(chFileOrig,/MARK_DIRECTORY)
COMMON WIDGET_WIN_CDS
args = command_line_args()
iNrArgs = size(args, /N_ELEMENTS)
CDS_error_code = 3
if ( iNrArgs ne 6 ) and ( iNrArgs ne 4 ) then begin
o3='CANCEL'
INTRO
if o3 eq 'CANCEL' then begin
status=CDS_error_code
endif else begin ;Open File and Directory Selection Windows
CD,CURRENT=path ;identify current working directory
if strmid(o3,strlen(o3)-1,1) eq 'S' then begin
iNrArgs=6
chFileGEOMSTE=DIALOG_PICKFILE(Filter=['GEOMS*.csv'], PATH=path, $
/MUST_EXIST,Title='Select GEOMS Template File')
if chFileGEOMSTE eq '' then stop, status=CDS_error_code
path=FILE_DIRNAME(chFileGEOMSTE,/MARK_DIRECTORY)
if strpos(STRUPCASE(chFileGEOMSTE),'LIDAR') ne -1 then begin
chFileTranslation=DIALOG_PICKFILE(/DIRECTORY, $
Title='Select Directory containing Lidar Translation File', PATH=path)
if chFileTranslation ne '' then path=chFileTranslation
endif else begin
iNrArgs=4
chFilesList=DIALOG_PICKFILE(PATH=path, $
/MUST_EXIST,Title='Select output of cds_match with a list of Matching Files')
if chFilesList eq '' then stop, status=CDS_error_code
path=FILE_DIRNAME(chFilesList,/MARK_DIRECTORY)
chFileTranslation=DIALOG_PICKFILE(Filter=['*translation*.txt'], PATH=path, $
/MUST_EXIST,Title='Select Translation File')
if chFileTranslation ne '' then path=FILE_DIRNAME(chFileTranslation,/MARK_DIRECTORY)
endelse
;Select common files/directories
chFileTAV=DIALOG_PICKFILE(Filter=['tableattrvalue*.dat'], PATH=path, $
/MUST_EXIST,Title='Select GEOMS Table Attribute Values File')
if chFileTAV eq '' then stop, status=CDS_error_code
path=FILE_DIRNAME(chFileTAV,/MARK_DIRECTORY)
chDirOutput=DIALOG_PICKFILE(/DIRECTORY, $
Title='Select Output Directory of the Converted File', PATH=path)
if chDirOutput eq '' then stop, status=CDS_error_code
if strlen(o3) eq 3 then chDataFormat=strmid(o3,0,2) else chDataFormat=''
CDS_error_code = 0
endelse
endif else begin
CDS_error_code = 0
if iNrArgs eq 6 then begin ;Single File Option
chFileGEOMSTE = STRTRIM(args(0), 2)
chFileTranslation = STRTRIM(args(1), 2)
chFileTAV = STRTRIM(args(2), 2)
chDirOutput = STRTRIM(args(3), 2)
iDataFormat = STRTRIM(args(4), 2)
chFileOrig = STRTRIM(args(5), 2)
if ( file_test( chFileOrig ) eq 0 ) then begin
CDS_error_code = 3
print, 'ERROR: Original file not found.'
end
if ( file_test( chFileGEOMSTE ) eq 0 ) then begin
CDS_error_code = 3
print, 'ERROR: GEOMS template file not found.'
end
if ( file_test( chFileTranslation ) eq 0 ) then begin
CDS_error_code = 3
print, 'ERROR: CDS compliant translation file file not found.'
end
endif else begin ;Multiple file option
chFilesList = STRTRIM(args(0), 2)
chFileTAV = STRTRIM(args(1), 2)
chDirOutput = STRTRIM(args(2), 2)
iDataFormat = STRTRIM(args(3), 2)
if ( file_test( chFilesList ) eq 0 ) then begin
CDS_error_code = 3
print, 'ERROR: File with list of matching files not found.'
end
if chFileTranslation eq '' then stop, status=CDS_error_code
path=FILE_DIRNAME(chFileTranslation,/MARK_DIRECTORY)
chFileOrig=DIALOG_PICKFILE(PATH=path,/MUST_EXIST,Title='Select Original File to be Converted')
if chFileOrig eq '' then stop, status=CDS_error_code
path=FILE_DIRNAME(chFileOrig,/MARK_DIRECTORY)
endif else begin
iNrArgs=4
chFilesList=DIALOG_PICKFILE(PATH=path, $
/MUST_EXIST,Title='Select output of cds_match with a list of Matching Files')
if chFilesList eq '' then stop, status=CDS_error_code
path=FILE_DIRNAME(chFilesList,/MARK_DIRECTORY)
endelse
;Select common files/directories
chFileTAV=DIALOG_PICKFILE(Filter=['tableattrvalue*.dat'], PATH=path, $
/MUST_EXIST,Title='Select GEOMS Table Attribute Values File')
if chFileTAV eq '' then stop, status=CDS_error_code
path=FILE_DIRNAME(chFileTAV,/MARK_DIRECTORY)
chDirOutput=DIALOG_PICKFILE(/DIRECTORY, $
Title='Select Output Directory of the Converted File', PATH=path)
if chDirOutput eq '' then stop, status=CDS_error_code
if strlen(o3) eq 3 then chDataFormat=strmid(o3,0,2) else chDataFormat=''
;Do checks on common arguments
if ( file_test( chFileTAV ) eq 0 ) then begin
CDS_error_code = 3
print, 'ERROR: TAV file not found.'
end
CDS_error_code = 0
endelse
endif else begin
CDS_error_code = 0
if iNrArgs eq 6 then begin ;Single File Option
chFileGEOMSTE = STRTRIM(args(0), 2)
chFileTranslation = STRTRIM(args(1), 2)
chFileTAV = STRTRIM(args(2), 2)
chDirOutput = STRTRIM(args(3), 2)
iDataFormat = STRTRIM(args(4), 2)
chFileOrig = STRTRIM(args(5), 2)
if ( file_test( chFileOrig ) eq 0 ) then begin
CDS_error_code = 3
print, 'ERROR: Original file not found.'
end
if ( file_test( chDirOutput ) eq 0 ) then begin
CDS_error_code = 3
print, 'ERROR: Output directory not found.'
end
if ( file_test( chFileGEOMSTE ) eq 0 ) then begin
CDS_error_code = 3
print, 'ERROR: GEOMS template file not found.'
end
if not ( is_a_number( iDataFormat ) ) then begin
CDS_error_code = 3
print, 'ERROR: Data Format option must be numeric [0|1|2].'
end else begin
if ( ( iDataFormat lt 0 ) or ( iDataFormat gt 2 ) ) then begin
CDS_error_code = 3
print, 'ERROR: Data Format option must have values: [0|1|2].'
endif else begin
case fix(iDataFormat) of
0: chDataFormat=''
1: chDataFormat='h5'
2: chDataFormat='nc'
endcase
endelse
end
endelse
if ( file_test( chFileTranslation ) eq 0 ) then begin
CDS_error_code = 3
print, 'ERROR: CDS compliant translation file file not found.'
end
endif else begin ;Multiple file option
chFilesList = STRTRIM(args(0), 2)
chFileTAV = STRTRIM(args(1), 2)
chDirOutput = STRTRIM(args(2), 2)
iDataFormat = STRTRIM(args(3), 2)
if ( file_test( chFilesList ) eq 0 ) then begin
CDS_error_code = 3
print, 'ERROR: File with list of matching files not found.'
end
endelse
if ( CDS_error_code eq 0 ) then begin
if ( iNrArgs eq 6 ) then begin ;Single File Input
; check if files are LIDAR, then use Thierry LeBlanc's routines instead of generic AVDC routines
chFileOrigBase = file_basename( chFileOrig )
chFileOrigBaseArr= STRSPLIT(chFileOrigBase, '.', ESCAPE='\', /EXTRACT)
iSize1 = 1L
endif else begin ;Multiple File Input
; read intut matches list
statusflag='' & dum='' & exit_code=3
flist=[''] & n_el=0L & lfflag=''
TEST_INPUT,chFilesList,chFileTAV,chDirOutput,flist,n_el,statusflag,lfflag
iSize1Dim = size(flist, /DIMENSIONS)
iSize1NrDim = size(flist, /N_DIMENSIONS)
if (iSize1NrDim eq 1) then begin
iSize1 = 1L
end else begin
iSize1 = iSize1Dim(1)
end
;Do checks on common arguments
if ( file_test( chFileTAV ) eq 0 ) then begin
CDS_error_code = 3
print, 'ERROR: TAV file not found.'
end
;print, iSize1NrDim, iSize1Dim
endelse
if ( file_test( chDirOutput ) eq 0 ) then begin
CDS_error_code = 3
print, 'ERROR: Output directory not found.'
end
for iR1 = 0L, iSize1 - 1L do begin
if iNrArgs eq 4 then begin
chFileOrig = flist(0, iR1)
chFileGEOMSTE = flist(1, iR1)
chFileTranslation = flist(2, iR1)
endif
if not ( is_a_number( iDataFormat ) ) then begin
CDS_error_code = 3
print, 'ERROR: Data Format option must be numeric [0|1|2].'
end else begin
if ( ( iDataFormat lt 0 ) or ( iDataFormat gt 2 ) ) then begin
CDS_error_code = 3
print, 'ERROR: Data Format option must have values: [0|1|2].'
endif else begin
case fix(iDataFormat) of
0: chDataFormat=''
1: chDataFormat='h5'
2: chDataFormat='nc'
endcase
endelse
end
endelse
if ( CDS_error_code eq 0 ) then begin
if ( iNrArgs eq 6 ) then begin ;Single File Input
; check if files are LIDAR, then use Thierry LeBlanc's routines instead of generic AVDC routines
chFileOrigBase = file_basename( chFileOrig )
chFileOrigBaseArr= STRSPLIT(chFileOrigBase, '.', ESCAPE='\', /EXTRACT)
iSize1 = 1L
endif else begin ;Multiple File Input
; read intut matches list
statusflag='' & dum='' & exit_code=3
flist=[''] & n_el=0L & lfflag=''
TEST_INPUT,chFilesList,chFileTAV,chDirOutput,flist,n_el,statusflag,lfflag
iSize1Dim = size(flist, /DIMENSIONS)
iSize1NrDim = size(flist, /N_DIMENSIONS)
if (iSize1NrDim eq 1) then begin
iSize1 = 1L
end else begin
iSize1 = iSize1Dim(1)
end
if (FILE_TEST(chFileOrig) eq 1) and (FILE_TEST(chFileGEOMSTE) eq 1) and $
(FILE_TEST(chFileTranslation) eq 1) then begin
print, chFileOrig
;print, iSize1NrDim, iSize1Dim
endelse
;print, chFileOrig+' '+chFileGEOMSTE+' '+chFileTranslation
for iR1 = 0L, iSize1 - 1L do begin
if iNrArgs eq 4 then begin
chFileOrig = flist(0, iR1)
chFileGEOMSTE = flist(1, iR1)
chFileTranslation = flist(2, iR1)
endif
; check if files are LIDAR, then use Thierry LeBlanc's routines instead of generic AVDC routines
chFileOrigBase = file_basename( chFileOrig )
chFileOrigBaseArr= STRSPLIT(chFileOrigBase, '.', ESCAPE='\', /EXTRACT)
if (FILE_TEST(chFileOrig) eq 1) and (FILE_TEST(chFileGEOMSTE) eq 1) and $
(FILE_TEST(chFileTranslation) eq 1) then begin
print, chFileOrig
;print,chFileOrigBaseArr
;print, chFileOrig+' '+chFileGEOMSTE+' '+chFileTranslation
if (strlen(chFileOrigBaseArr(1)) eq 3) and (STRMID(strlowcase(chFileOrigBaseArr(1)), 2, 1) eq 'l' ) then begin
print, "CDS: LIDAR data processing"
; check if files are LIDAR, then use Thierry LeBlanc's routines instead of generic AVDC routines
chFileOrigBase = file_basename( chFileOrig )
chFileOrigBaseArr= STRSPLIT(chFileOrigBase, '.', ESCAPE='\', /EXTRACT)
CDS_error_code=cds_LIDAR( chFileOrig, chFileGEOMSTE, chFileTranslation, chFileTAV, $
chDirOutput, chDataFormat )
end else begin
chFilesList = STRARR(3)
;print,chFileOrigBaseArr
chFilesList(0) = chFileOrig
chFilesList(1) = chFileGEOMSTE
chFilesList(2) = chFileTranslation
if (strlen(chFileOrigBaseArr(1)) eq 3) and (STRMID(strlowcase(chFileOrigBaseArr(1)), 2, 1) eq 'l' ) then begin
print, "CDS: LIDAR data processing"
CDS_error_code=cds_LIDAR( chFileOrig, chFileGEOMSTE, chFileTranslation, chFileTAV, $
chDirOutput, chDataFormat )
end else begin
chFilesList = STRARR(3)
chFilesList(0) = chFileOrig
chFilesList(1) = chFileGEOMSTE
chFilesList(2) = chFileTranslation
if strpos(strupcase(chFileGEOMSTE),'GEOMS-TE-SONDE-O3-VA-003.CSV') ne -1 or $
strpos(strupcase(chFileGEOMSTE),'GEOMS-TE-SONDE-O3-003.CSV') ne -1 then begin
;call new version of cds_tools to handle v003 of the sonde template
if ( chDataFormat eq '' ) then begin
CDS_error_code=cds_tools_g2( chFilesList, chFileTAV, chDirOutput ) ;DATETIME=o1)
end else begin
CDS_error_code=cds_tools_g2( chFilesList, chFileTAV, chDirOutput, chDataFormat )
end
endif else begin
if ( chDataFormat eq '' ) then begin
CDS_error_code=cds_tools( chFilesList, chFileTAV, chDirOutput ) ;DATETIME=o1)
end else begin
CDS_error_code=cds_tools( chFilesList, chFileTAV, chDirOutput, chDataFormat )
end
end
end else begin
print, 'INFORMATION: One or more input files not valid.'
endelse
end
end else begin
print, 'INFORMATION: One or more input files not valid.'
end
end
end
print, CDS_error_code
print, CDS_error_code
END
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment