function get_ruc_sounding,site,SAVE_FILE=sav_file,snd_file COMMON misc,TRUE,FALSE !QUIET=1 ; ; *** First off, remove any old soundings from cwd. ; spawn,'rm sound.html tmp.csh' server = 'http://rucsoundings.noaa.gov/' ; ; *** Program to grab current sounding from RUC model output ; smonth = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] ; ; *** Use IDL systime to get the latest time ; the_time = systime(/utc) print,the_time a = strsplit(the_time,' ',/extract) mon = a[1] & day=a[2] & time = a[3] & year = a[4] b = strsplit(time,':',/extract) hour = b[0] & minute=b[1] c = where(smonth eq mon) month = string(c[0] + 1,format='(I2.2)') the_year = string(year,format='(I4.4)') the_month = string(month,format='(I2.2)') the_day = string(day,format='(I2.2)') jday = get_julday(the_year*1,the_month*1,the_day) the_jday = string(jday,format='(I3.3)') the_hour = string(hour,format='(I2.2)') snd_dir = '/data/Soundings/RUC_Soundings/' + the_year + '/' + $ the_month + the_day + '/' spawn,'mkdir -p ' + snd_dir file_base = snd_dir + site + '_' + the_year + '_' + the_month + the_day + '_' + $ the_jday + '_' + the_hour + 'UTC' ; ; *** Set up command to download file using wget. ; syear = strmid(year,2,2) CASE site of 'WFF': BEGIN c1 = 'gifs/reply-skewt.cgi?data_source=Bak40&year=' + syear + $ '&month_name=' + mon + '&mday=' + day + '&hour=' + hour + $ '&lon=-104.67&lat=39.87&airport=wal' END 'DVN': BEGIN c1 = 'gifs/reply-skewt.cgi?data_source=Bak40&year=' + syear + $ '&month_name=' + mon + '&mday=' + day + '&hour=' + hour + $ '&lon=-90.47&lat=41.43&airport=dvn' END ENDCASE print c = server + c1 command = "wget -O sound.html " + '"' + c + '"' ; ; *** Open a csh file to store command then spawn it. ; openw,unit,'tmp.csh',/get_lun printf,unit,"#!/bin/csh" printf,unit,command print,command close,unit free_lun,unit spawn,'chmod +x tmp.csh' spawn,'tmp.csh',result ; ; *** Now, open the sound.html file and strip only the ; *** data, ignoring HTML code. ; snd_file = file_base + '.txt' openw,snd_unit,snd_file,/get_lun ; ; *** Now parse the file for the sounding info only ; rec = '' & nr=200 openr,unit,'sound.html',/get_lun height = fltarr(nr) & pres = fltarr(nr) & dd = strarr(nr) wdir = fltarr(nr) & wspd = fltarr(nr) temp_f = fltarr(nr) & temp_c = fltarr(nr) & td=fltarr(nr) feet_2_meters = 3.28084D ifound = 0 & icnt=0 & the_pres = 999999. zeros = string(indgen(8)*0,format='(F3.1)') while(NOT EOF(unit)) do begin readf,unit,rec a = strsplit(rec,' ',/extract) if(a[0] eq 'Pressure_Alt') then begin ; print,'Found sounding data!' ; hdr1 = 'PRES HGHT TEMP DWPT RELH MIXR DRCT SKNT THTA THTE THTV' ; hdr2 = 'hPa m C C % g/kg deg knot K K K' ; print,hdr1 ; print,hdr2 ; printf,snd_unit,hdr1 ; printf,snd_unit,hdr2 ; ; *** Read two blank lines, then start ingesting data ; readf,unit,rec readf,unit,rec readf,unit,rec ifound = 1 endif if(ifound) then begin a = strsplit(rec,' ',/extract) ; print,rec the_pres = a[1]*1.0 if(the_pres lt 100) then break height[icnt] = a[0]*1.0 / feet_2_meters pres[icnt] = a[1]*1.0 dd[icnt] = a[2] wdir[icnt] = a[3]*1.0 wspd[icnt] = a[4]*1.0 temp_f[icnt] = a[5]*1.0 temp_c[icnt] = a[6]*1.0 td[icnt] = a[7]*1.0 ; ; *** Have to reorder the columns for Chandra's code ; line = ' ' + $ string(pres[icnt], format='(F8.1)') + ' ' + $ string(height[icnt],format='(F8.1)') + ' ' + $ string(temp_c[icnt],format='(F7.2)') print,line,zeros printf,snd_unit,line,zeros icnt++ endif endwhile close,unit free_lun,unit close,snd_unit free_lun,snd_unit ; ; *** Copy the current sounding to pwd and rename. ; c = 'cp ' + snd_file + ' ' + site + '_Sounding.txt' print,c spawn,c ; ; *** Trim arrays ; feet_per_meter = 3.28084D a = where(pres gt 0,c) if(c gt 0) then begin height = height[a]/feet_per_meter ; ft to m pres = pres[a] dd = dd[a] wdir = wdir[a] wspd = wspd[a] temp_f = temp_f[a] temp_c = temp_c[a] td = td[a] endif ; ; *** Save data to a structure ; snd = {site: site, year: year, month: month, day: day, hour: hour, $ height: height, pres: pres, dd: dd, wdir: wdir, wspd: wspd, $ temp_f: temp_f, temp_c: temp_c, td: td, flag: ifound} help,/str,snd ; ; *** Also save the structure in an IDL save file. ; sav_file = file_base + '.sav' save,snd,filename=sav_file,/compress print,' --> ' + sav_file print,' --> ' + snd_file ; ; *** Remove old soundings ; return,'OK' end