forked from Sean-T-Moore/dqrws-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_dqr_timeranges.pro
78 lines (69 loc) · 2.91 KB
/
get_dqr_timeranges.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
pro get_dqr_timeranges, datastream=datastream, varname=varname, searchmetric=searchmetric, $
starttime=starttime, endtime=endtime, nranges=nranges, success=success
;
;+
; ROUTINE: get_dqr_timeranges
;
; PURPOSE: Provides array of start and end times for which caller could mark varname data as missing.
; These time values can be compared to values from an ARM file once base_time and time_offset have been combined.
; These arrays are either determined by calling the ARM DQR web service or by reading a local data store
; (perhaps local storage generated by perl front end in a '.anders' subdir).
; The metric used is decided by the user and can be DQR types: incorrect, suspect or both.
; program will stop if not able to connect to DQR webservice.
;
;
; KEYWORD INPUT:
; datastream valid ARM datastream name as encoded in filenames and DQR database
; varname valid ARM varname as stored in files and DQR database
; searchmetric either 'incorrect,suspect' or 'incorrect' or 'suspect'
;
; KEYWORD OUTPUT:
; starttime array of start times in seconds since 1970 (arm format) to be used for filtering
; endtime array of end times in seconds since 1970 (arm format) to be used for filtering
; nranges scalar indicating how many time ranges were found
; success If set true (1) then service was up and caller can trust results. If false (0), service wasn't working as expected.
;
; EXAMPLE:
; get_dqr_timeranges, datastream='nsamfrsrC2.b1',varname='direct_horizontal_broadband',searchmetric='suspect',starttime=starttime,endtime=endtime
;
; AUTHOR: Sean Moore, Ken Kehoe, June 2012, sean.moore@arm.gov
;
;-
query='datastream='+datastream
query=query+'&varname='+varname
query=query+'&searchmetric='+searchmetric
query=query+'&timeformat=armtime'
query=query+'&dqrfields=starttime,endtime'
query=query+'&responsetype=delimited'
success=1
oUrl = OBJ_NEW('IDLnetUrl')
oUrl->SetProperty, VERBOSE = 1, CONNECT_TIMEOUT = 10, TIMEOUT = 20, $
URL_SCHEME = 'http', URL_HOSTNAME='www.archive.arm.gov', $
URL_PATH='dqrws/ARMDQR',URL_QUERY=query
print, 'Query to DQR webservice: ',query
CATCH, errVal
IF errVal NE 0 THEN BEGIN
CATCH, /CANCEL
oUrl->GetProperty, RESPONSE_CODE=response_code,RESPONSE_HEADER=rspHeader
;PRINT, 'Response Code = ', response_code
;PRINT, 'Response Header = ', rspHeader
response = ''
if response_code NE 200 then success=0
ENDIF ELSE BEGIN
response = oUrl->Get(/STRING_ARRAY)
ENDELSE
oUrl->GetProperty, RESPONSE_CODE=response_code
OBJ_DESTROY, oUrl
;PRINT, 'Response Code = ', response_code
starttime=[]
endtime=[]
!NULL=STRSPLIT(response,'|',COUNT=count)
IF TOTAL(count) GT 0 THEN BEGIN
FOR ii=0, N_ELEMENTS(response)-1 DO BEGIN
rs = STRSPLIT(response[ii],'|',/EXTRACT)
starttime=[starttime,double(rs[0])]
endtime=[endtime,double(rs[1])]
ENDFOR ; ii
ENDIF ; response
nranges=n_elements(starttime)
end