; ; Quick and dirty script to read the tower data from the CR3000 ; data tables. Notice two table are saved - one for T and one for V. ; ; David Noone - Fri Nov 6 07:10:53 MST 2009 ; ; ; ------------------------------------------------------------------------ pro read_tower, filewind, filetemp, wdir, wind, temp, $ datestr=date, juld=juld, jzero=jzero, batt=batt ; ; Set base for julian date ; julzero = julday(1,1,2009,0,0,0.) if (keyword_set(jzero)) then julzero= jzero ; ; hard code number of levels ; nlev = 4 ; 4 levels ; ; Check to see if the files match (check the length is the same) ; nlines = file_lines(filewind) if (file_lines(filewind) ne file_lines(filetemp)) then begin print,'Wind and temperature files differ in length. Problem?' endif ; ; The length of the data is the number of lines in the file, minus the 4 ; header lines ; ntime = nlines - 4 ; 3 header lines in file ; ; Define the arrays ; temp = fltarr(nlev,ntime) wind = fltarr(nlev,ntime) wdir = fltarr(ntime) batt = fltarr(ntime) date = strarr(ntime) ; date string juld = dblarr(ntime) ; julian date relative to julzero samw = intarr(ntime) ; sample number samt = intarr(ntime) ; sample number cbuf = 'character buffer' ; ; Open files and read ; print,'Reading wind data...' openr,lu,filewind,/get_lun readf,lu,cbuf readf,lu,cbuf readf,lu,cbuf readf,lu,cbuf for i = 0, ntime-1 do begin readf,lu,cbuf cbits = strsplit(cbuf,',',/extract) date[i] = reform(strsplit(cbits[0],'"',/extract)) samw[i] = cbits[1] wdir[i] = cbits[3] wind[3,i] = cbits[2] wind[2,i] = cbits[4] wind[1,i] = cbits[5] wind[0,i] = cbits[6] endfor free_lun,lu print,'Reading temperature data...' openr,lu,filetemp,/get_lun readf,lu,cbuf readf,lu,cbuf readf,lu,cbuf readf,lu,cbuf for i = 0, ntime-1 do begin readf,lu,cbuf cbits = strsplit(cbuf,',',/extract) d = reform(strsplit(cbits[0],'"',/extract)) dt = strsplit(d,' ',/extract) dbits = strsplit(dt[0],'-',/extract) tbits = strsplit(dt[1],':',/extract) juld[i] = julday(dbits[1],dbits[2],dbits[0], $ tbits[0],tbits[1],tbits[2]) - julzero date[i] = d samt[i] = cbits[1] batt[i] = cbits[2] temp[3,i] = cbits[3] temp[2,i] = cbits[4] temp[1,i] = cbits[5] temp[0,i] = cbits[6] endfor free_lun,lu ; ; All done! ; return end