;getrdr.pro ;Modified 14APR2009 by Nathaniel A. Frissell ;GETRDR returns the velocity data for a SuperDARN radar. ;The returned value is a vector in the form of: ; [EpochTime, LOSVelocity] ;Where EpochTime is the time in seconds from 1JAN1970, and LOSVelocity is the ;line of sight velocity in m/s. Data is retrieved from a FITACF file that is ;located in the same directory as this function. The FITACF file must contain ;all of the data for the timespan specified. ; ;This function automatically creates an IDL sav file from the FITACF file for ;easy future access. If a save file for the specified FITACF file exists in the ;same working directory, then the data in the sav file will be used instead of ;the data in the FITACF file. If trouble occurs, remove the sav files and they ;will automatically be recreated on the next run of this funtion. ; ;Arguments: ; fileName$ is the name of the FITACF file to be used. The file should ; be in the same directory as this function, contain all of the data ; required for the specified timespan, and have a filename ending in ; '.fitacf'. ; ; beam is an integer identifying the radar beam number to be used. ; ; rangeGate is an integer identifying the radar rangeGate to be used. ; ; date$ is a THEMIS datestring in the form of 'YYYY-MM-DD/hh:mm:ss' ; ; ts is the timespan in minutes ; ; interp is the time resolution in seconds for data interpolation. ; This is an optional parameter. If it is set to 0 or undefined, ; no interpolation occurs and raw data is returned. ; THEMIS magnetometers are set to take date at a regular 0.5 second ; resolution, and therefore do not usually need interpolation. ;FUNCTION GETRDR,fileName$,beam,rangeGate,date$,ts FUNCTION FITACFLOAD,source_in$,date$,ts,INFO$=info$ source$ = STRSPLIT(source_in$,':',/EXTRACT) source_test$ = STRLOWCASE(source$[0]) CASE source_test$ OF 'query': retData = ['^fitacf'] ELSE : BEGIN params = LONG(STRSPLIT(source$[2],',',/EXTRACT)) beam = params[0] rangeGate = params[1] savFName$ = FILE_BASENAME(source$[1],'fitacf')+'sav' files = FINDFILE(savFName$, count=numFiles) IF numFiles EQ 0 THEN BEGIN PRINT,'No previous saveset file found; creating saveset file from FITACF file.' ; Open the FITACF file for read only inp=FITOPEN(source$[1],/READ) ;The following loop reads every line of the fitacf file and places certain data into dataarr. WHILE FITREAD(inp,prm,fit) NE -1 DO BEGIN PRINT,prm.time.hr,prm.time.mt,prm.time.sc prmvec = [prm.time.yr,prm.time.mo,prm.time.dy,prm.time.hr,prm.time.mt,prm.time.sc,prm.bmnum] prmarr = FINDGEN(N_ELEMENTS(prmvec),N_ELEMENTS(fit.v)) FOR kk = 0,N_ELEMENTS(fit.v)-1 DO prmarr(*,kk) = prmvec rg = INDGEN(1,N_ELEMENTS(fit.v)) + 1 tmp_dataarr = [prmarr,rg,TRANSPOSE(fit.v),TRANSPOSE(fit.v_e)] IF N_ELEMENTS(dataarr) EQ 0 THEN BEGIN dataarr = tmp_dataarr ENDIF ELSE BEGIN dataarr = [[dataarr],[tmp_dataarr]] ENDELSE ENDWHILE FREE_LUN,inp ;Converts normal date format into a Julian date format. This allows for easy plotting and ;ordering of data. See "? julday" for more information. julian = julday(dataarr(1,*),dataarr(2,*),dataarr(0,*),dataarr(3,*),dataarr(4,*),dataarr(5,*)) epochStart = TimeYMDHMStoEpoch( $ LONG(dataarr(0,0)), $ LONG(dataarr(1,0)), $ LONG(dataarr(2,0)), $ LONG(dataarr(3,0)), $ LONG(dataarr(4,0)), $ dataarr(5,0)) dataarr = [julian,dataarr] dataarr = TRANSPOSE(dataarr) dataarr[*,0] = (dataarr[*,0] - dataarr[0,0]) * 86400. dataarr[*,0] = (dataarr[*,0] + epochStart) SAVE,file=savFName$,dataarr ENDIF ELSE BEGIN RESTORE,file=savFName$ ENDELSE year = LONG(STRMID(date$, 0,4)) month= LONG(STRMID(date$, 5,2)) day = LONG(STRMID(date$, 8,2)) hour = LONG(STRMID(date$,11,2)) min = LONG(STRMID(date$,14,2)) sec = LONG(STRMID(date$,17,2)) startDate = TimeYMDHMStoEpoch(year,month,day,hour,min,sec) endDate = startDate + (ts * 60.) ;Return only data for the data range, rangegate, and beam specified. filt = WHERE(dataarr[*,0] GE startdate) dataarr = dataarr[filt,*] filt = WHERE(dataarr[*,0] LE enddate) dataarr = dataarr[filt,*] filt = WHERE(dataarr[*,7] EQ beam) dataarr = dataarr[filt,*] filt = WHERE(dataarr[*,8] EQ rangegate) dataarr = dataarr[filt,*] retData = [[dataarr[*,0]],[dataarr[*,9]]] ;Create Information Vector type$ = 'rdr' rdr$ = STRUPCASE(STRMID(source$[1],9,3,/REVERSE_OFFSET)) brgSource$ = source$[2] brgSource = LONG(STRSPLIT(brgSource$,',',/EXTRACT)) beam$ = STRTRIM(STRING(brgSource[0]),1) rg$ = STRTRIM(STRING(brgSource[1]),1) name$ = rdr$ + ' Radar (Bm ' + beam$ + ', RG ' + rg$ + ')' shortId$ = rdr$+':'+beam$+','+rg$ unit$ = 'm/s' info$ = [source_in$, type$, name$, unit$, shortId$] END ENDCASE RETURN,retData END