;+ ; NAME: ; read_omniweb ; ; ; PURPOSE: ; read an omniweb data file into an idl structre ; http://omniweb.gsfc.nasa.gov/form/dx1.html ; ; CATEGORY: ; data io ; ; ; INPUTS: ; data: name of the omniweb data file ; fmt: format file from omniweb ; ; ; ; OUTPUTS: ; structre array with data from omniweb file ; ; KEYWORD PARAMETERS: ; JD: compute and add julian date to the structure ; ; RESTRICTIONS: ; tested in general so far, breakable I am sure ; ; ; PROCEDURE: ; parse the fmt file into the structre definition then read in the ; data file ; ; ; EXAMPLE: ; see: http://people.bu.edu/balarsen/Home/IDL/Entries/2007/12/19_Read_an_Omniweb_file.html ; IDL> data = 'omni2_daily_19015.lst' ; IDL> fmt = 'omni2_daily_19015.fmt' ; IDL> str = read_omniweb(data, fmt) ; IDL> print, tag_names(str) ; YEAR DOY HOUR ID_FOR_IMF_SPACECRAFT ID_FOR_SW_PLASMA_SPACECRAFT ; FIELD_MAGNITUDE_AVERAGE_NT BZ_NT_GSM RMS_SD_MAGNITUDE_NT SW_PLASMA_TEMPERATURE_K SW_PROTON_DENSITY_NCM3 SW_PLASMA_SPEED_KMS FLOW_PRESSURE_NPA ELECTRIC_FIELD_MVM ; ; ; ; MODIFICATION HISTORY: ; ; Wed Dec 19 18:04:12 2007, Brian Larsen ; ; written and tested ; ;- FUNCTION read_omniweb, data, fmt, JD = jd ;;;;;;;;;;;;;;;;; input checking ;;;;;;;;;;;;;;;;;;; IF n_elements(data) EQ 0 THEN $ message, /ioerror, 'Must enter an omniweb data file (*.lst)' IF n_elements(fmt) EQ 0 THEN $ messgae, /ioerror, 'Must enter an omniweb format file (*.fmt)' ;; first read in the fmt file to get ther format fmt_lines = file_lines(fmt) openr, fmt_lun, fmt, /get_lun in ='' ;; header info FOR i=0l, 4-1 DO readf, fmt_lun, in fmt_data = strarr(fmt_lines - 3 - 3, 3) FOR i=4l, fmt_lines-3 DO BEGIN readf, fmt_lun, in fmt_data[i-4,*] =trim( [strmid(in,0,3), $ strmid(in, 3, 30), $ strmid(in, 33, 6) ] ) ENDFOR ;; done with the format file free_lun, fmt_lun ;; we need to setup a data structure to hold things dat = create_struct(make_tag_valid(fmt_data[0,1]), $ (strcmp(fmt_data[0,2], 'I', 1, /fold_case) ? 0 : 0.) ) FOR i=1l, (size(fmt_data, /dim))[0]-1 DO BEGIN dat = create_struct(dat, make_tag_valid(fmt_data[i,1]), $ (strcmp(fmt_data[i,2], 'I', 1, /fold_case) ? 0 : 0.) ) ENDFOR ;; now that we have the structre, replicate it to the number of lines ;; in the data file dat = replicate(dat, file_lines(data)) ;; open and read the data file openr, data_lun, data, /get_lun readf, data_lun, dat ;; done with data file free_lun, data_lun ;; compute the JD IF keyword_set(JD) THEN BEGIN IF (tag_names(dat))[0] eq 'YEAR' THEN BEGIN IF (tag_names(dat))[1] EQ 'DOY' THEN BEGIN md = doy2md(dat.doy, dat.year) jd = julday(md[*, 0], md[*, 1], dat.year, $ intarr(n_elements(dat.year)), $ intarr(n_elements(dat.year)), $ intarr(n_elements(dat.year))) dat = add_tag(dat,jd, jd) ENDIF ENDIF ENDIF return, dat END
Disclaimer