Commit 5f43dd45 authored by Ian Boyd's avatar Ian Boyd

Replace cds_tools.pro

parent 6969cbc6
;Main Program Version: cds_tools.pro Release v2.0b61, 20190824
;Main Program Version: cds_tools.pro Release v2.0b62, 20191112
; Written by Ian Boyd for the AVDC/EVDC - iboyd@astro.umass.edu
;Sub-versions:
; 20090828: Initial Release for testing - v0.1
......@@ -160,6 +160,9 @@
; 20190514, Update due to fix in idlcr8ascii - v2.0b59
; 20190807, Update due to modifications to idlcr8ascii and idlcr8hdf - v2.0b60
; 20190824, Update due to fix in idlcr8hdf - v2.0b61
; 20191112, Add support for v6 SHADOZ measurements. Include checks to differentiate
; between the 3 different Costa Rica SHADOZ sites and make latitude and longitude
; dependent on DATETIME rather than constant - v2.0b62
;Program to read in a file or string array created by CDS_Match (or equivalent) and,
;based on the input information, convert NDACC NASA/AMES, WOUDC CSV, SHADOZ, NOAA-ESRL or
......@@ -1479,6 +1482,8 @@ PRO update_global_attributes, stid, ndacc, mv_meta, ga, sectionb, nw, metaok, fi
; 20120913: Allow for 2 or more differences in Archive label names (separated by '|')
; - v2.0b24
; 20121127: Add support for NOAA-ESRL format files - v2.0b26
; 20191112: Add support for v6 SHADOZ measurements. Include checks to differentiate
; between the 3 different Costa Rica SHADOZ sites - v2.0b62
;
; Input: stid - station identifier of WOUDC/netCDF file, or time of measurement for NDACC measurement
; ndacc - string array holding contents of the NDACC/WOUDC file
......@@ -1581,6 +1586,26 @@ IF gcnt NE 0 THEN BEGIN
;Make array of specific station data if present
idlen=STRLEN(stid)
si=WHERE(STRUPCASE(STRMID(sectionb[gi[0]:nsb-1L],0,idlen)) EQ stid,scnt)
IF (scnt GT 1) AND (nw EQ 'S') THEN BEGIN
;can occur for SHADOZ Costa Rica files (can be 1 of 3 sites)
;Get latitude and longitude information from the SHADOZ file
lati=WHERE(STRMID(STRUPCASE(ndacc),0,8) EQ 'LATITUDE')
loni=WHERE(STRMID(STRUPCASE(ndacc),0,9) EQ 'LONGITUDE')
res=STRSPLIT(ndacc[lati[0]],' ',/EXTRACT,COUNT=cres)
slat=FLOAT(res[cres-1])
res=STRSPLIT(ndacc[loni[0]],' ',/EXTRACT,COUNT=cres)
slon=FLOAT(res[cres-1])
latdiff=FLTARR(scnt)
FOR i=0,scnt-1 DO BEGIN
res=STRSPLIT(sectionb[gi[0]+si[i]],' ;',/EXTRACT,COUNT=cres)
clat=FLOAT(res[cres-2]) & clon=FLOAT(res[cres-1])
latdiff[i]=ABS(slat-clat)
ENDFOR
;Determine site with closest latitude to that given in the SHADOZ file
lres=MIN(latdiff,li)
si[0]=si[li]
ENDIF
IF scnt NE 0 THEN BEGIN ;Station Global Attribute data is present
si=gi[0]+si[0]+1L
ei=WHERE(STRMID(STRTRIM(sectionb[si:nsb-1L],2),0,1) NE '[',ecnt)
......@@ -1969,6 +1994,8 @@ PRO write_data, si, dv_arr, ndhse, holddata, vat, res, sectionb, ndacc, dyear, d
; this version - v2.0b55
; 20190314: Add 'LON360E TO GEOMS' to conv_chk array so that program can convert longitude
; values using the 0-360E convention to GEOMS convention - v2.0b57
; 20191112: Add support for v6 SHADOZ measurements. Add check for negative Current values
; and change to fill values - v2.0b62
;
; Input: si - index (or indices) of NDACC/WOUDC header line describing the data being searched for
; dv_arr - string array holding the DATA_VARIABLE values
......@@ -2538,6 +2565,12 @@ IF STRPOS(STRUPCASE(res[0]),'WIND.DIRECTION') NE -1 THEN BEGIN
ENDIF
ENDIF
IF (nw EQ 'S') AND (res[0] EQ 'CURRENT.RAW.INSTRUMENT') THEN BEGIN
;check for negative current values and change to fill value
fi=WHERE(dsize LT 0.0,fcnt)
IF fcnt NE 0 THEN dsize[fi]=fv
ENDIF
;Apply conversions or scale factor to the NDACC/WOUDC/SHADOZ/NOAA data
IF STRPOS(res[3],'MJD2000') NE -1 THEN BEGIN
mjd2000=0.d
......@@ -2718,7 +2751,10 @@ PRO convert, ftest, dataformat, o3, exit_code
; 20130326: Account for DATETIME issues in NDACC datasets similar to those
; applied to other datasets - v2.0b27
; 20180622: Fix to read SHADOZ station name (stid) from file when there is an extra comment
; in the entry (e.g. Hanoi, Vietnam (...))
; in the entry (e.g. Hanoi, Vietnam (...)) - v2.0b53
; 20191112: Add support for v6 SHADOZ measurements. Include checks to differentiate
; between the 3 different Costa Rica SHADOZ sites and make latitude and longitude
; dependent on DATETIME rather than constant - v2.0b62
;
; Input: ftest - A String array of size 4, where the first 3 index values hold the
; matched file names
......@@ -3115,8 +3151,8 @@ IF metaok EQ '' THEN BEGIN
IF nw EQ 'W' THEN BEGIN
col_desp=STRSPLIT(resx[0],',',/EXTRACT) & col_desp=STRUPCASE(STRTRIM(col_desp,2))
ENDIF ELSE BEGIN ;separate out SHADOZ/NOAA column names and units
col_desp=STRSPLIT(resx[0],' ',/EXTRACT,/REGEX) & col_desp=STRTRIM(col_desp,2)+'-'
cd2=STRSPLIT(resx[1],' ',/EXTRACT,/REGEX)
col_desp=STRSPLIT(resx[0],' ',/EXTRACT) & col_desp=STRTRIM(col_desp,2)+'-'
cd2=STRSPLIT(resx[1],' ',/EXTRACT)
col_desp=STRUPCASE(col_desp+STRTRIM(cd2,2))
ENDELSE
holddata=STRARR(nx,n_sds)+mv
......@@ -3155,12 +3191,36 @@ IF metaok EQ '' THEN BEGIN
ENDIF
;Determine location of required dataset (divide into Section Header and Column Name components)
lres=STRSPLIT(res[1],'_',/EXTRACT,COUNT=nlres) & lres=STRUPCASE(STRTRIM(lres,2))
IF nlres GT 2 THEN BEGIN ;need to append all but the last sub-value to the first value
IF (nlres GT 2) AND (nw NE 'S') THEN BEGIN
;need to append all but the last sub-value to the first value
FOR m=1,nlres-2 DO lres[0]=lres[0]+'_'+lres[m]
lres=[lres[0],lres[nlres-1]] & nlres=2
ENDIF ELSE IF (nlres GT 2) AND (nw EQ 'S') THEN BEGIN
;need to append all but the first sub-value to the 2nd sub-value
FOR m=2,nlres-1 DO lres[1]=lres[1]+'_'+lres[m]
lres=[lres[0],lres[1]] & nlres=2
ENDIF
;Find Section
sltln=-999.
;STOP,lres[0]
IF (nw EQ 'S') AND (STRPOS(lres[0],'|') NE -1) THEN BEGIN
vres=STRSPLIT(lres[0],'|',/EXTRACT,COUNT=cres)
IF res[0] EQ 'AUXILIARY.PARAMETERS' THEN BEGIN
;check which text is present in the SHADOZ file
FOR m=0,cres-1 DO BEGIN
si=WHERE(STRMID(STRUPCASE(ndacc),0,STRLEN(vres[m])) EQ vres[m],scnt)
IF scnt NE 0 THEN lres[0]=vres[m]
ENDFOR
ENDIF ELSE BEGIN
;used to get surface lat lon information for profile if required
lres[0]=vres[1] ;now will just be #PROFILE
ltlni=WHERE(STRMID(STRUPCASE(ndacc),0,STRLEN(vres[0])) EQ vres[0])
vres=STRSPLIT(ndacc[ltlni[0]],' ',/EXTRACT,COUNT=cres)
sltln=FLOAT(vres[cres-1])
ENDELSE
ENDIF
IF ((nw EQ 'S') OR (nw EQ 'E')) AND (lres[0] EQ '#PROFILE') THEN scnt=1 $
ELSE si=WHERE(STRMID(STRUPCASE(ndacc),0,STRLEN(lres[0])) EQ lres[0],scnt)
IF (scnt NE 0) OR ((lc EQ sccnt) AND (sccnt GT 1)) OR (aplabel[0] NE '-1') THEN BEGIN
......@@ -3207,10 +3267,12 @@ IF metaok EQ '' THEN BEGIN
ENDIF ELSE aplabel[lc-1,1]=''
ENDIF
ENDIF
ENDIF ELSE IF (aplabel[0] NE '-1') AND ((nw EQ 'S') OR (nw EQ 'E')) THEN $
;STOP,aplabel[lc,*]
ENDIF ELSE IF (aplabel[0] NE '-1') AND ((nw EQ 'S') OR (nw EQ 'E')) THEN BEGIN
IF STRUPCASE(STRMID(aplabel[lc,0],0,29)) EQ 'CORRECTION FACTOR (COL2/COL1)' THEN $
;special case for correction factor - change to -9 to indicate no correction applied
aplabel[lc,1]='-9.0000'
ENDIF
ENDIF
ENDELSE
IF N_ELEMENTS(resy) EQ 1 THEN BEGIN ;No accompanying info to the header so add values
......@@ -3290,9 +3352,17 @@ IF metaok EQ '' THEN BEGIN
ENDFOR
ENDIF
ENDIF
;Add station latitude and longitude if no GPS values are available for SHADOZ
IF ((res[0] EQ 'LATITUDE') OR (res[0] EQ 'LONGITUDE')) AND (nw EQ 'S') THEN BEGIN
IF (FLOAT(holddata[0,j]) EQ FLOAT(mv)) AND (sltln NE -999.) THEN $
holddata[0,j]=STRTRIM(sltln,2)
ENDIF
;Do check for missing DATETIME values - if so add comment to VAR_NOTES
IF res[0] EQ 'DATETIME' THEN BEGIN
fi=WHERE(holddata[*,j] EQ mv,fcnt)
IF nw EQ 'S' THEN fi=WHERE(DOUBLE(holddata[*,j]) EQ DOUBLE(mv),fcnt) $
ELSE fi=WHERE(holddata[*,j] EQ mv,fcnt)
IF fcnt GT 1 THEN BEGIN
add_dt_comm=j & nmissing=fcnt
ENDIF
......@@ -3491,7 +3561,7 @@ IF metaok EQ '' THEN BEGIN
IF STRUPCASE(res[1]) NE 'N/A' THEN BEGIN ;data present in the file
;Search for Corresponding String in NDACC/WOUDC file
scnt=1
IF STRPOS(res[1],'|') NE -1 THEN BEGIN ;more than one possible option to search for
IF (STRPOS(res[1],'|') NE -1) AND (nw NE 'S') THEN BEGIN ;more than one possible option to search for
ss=STRSPLIT(res[1],'|',/EXTRACT,count=sscnt) & ss=STRTRIM(ss,2)
m=0 & scnt=0
WHILE (m LE sscnt-1) AND (scnt EQ 0) DO BEGIN
......@@ -3691,7 +3761,7 @@ FUNCTION cds_tools, listf, tav, outdir, dataformat, DATETIME=o1
;Initialize statusflag, and exit_code
statusflag='' & dum='' & exit_code=3
cdver='cds_tools version 2.0b61, 2019-08-24'
cdver='cds_tools version 2.0b62, 2019-11-12'
;Check input parameters
IF N_PARAMS() LT 3 THEN $
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment