; parse_waveform, 'test2_sc_sh_log.txt' ;pro parse_waveform, filename BSPACE = (byte(' '))[0] BZERO = (byte('0'))[0] BCOMMA = (byte(','))[0] ;path = '../../data/' ;filename = path+filename f = file_info(filename) if ~f.exists then message, 'File not found.' ; Open file for readingw openr, lun, filename, /get_lun temp = 'temp' ; Get the horizontal scale header: readf, lun, temp horString = strsplit(temp, /extract) hscale = float(horString[3]) ;btemp = byte(temp) ;spaces = where(btemp eq BSPACE) ;hScale = float(string(btemp[spaces[3]:spaces[4]-1])) hIndex = findgen(1000) * hscale * 1e6 ; Now get the vertical scale readf, lun, temp vertString = strsplit(temp, /extract) vScale = float(vertString[3]) ;stop ;btemp = byte(temp) ;spaces = where(btemp eq BSPACE) ;vScale = float(string(btemp[spaces[3]:spaces[4]-1])) npixels = 32 ^ 2. vals = fltarr(32, 32, 1000) for n = 0, npixels - 1 do begin ; print, n readf, lun, temp first = strsplit(temp, /extract) xcell = fix(first[1]) ycell = fix(first[2]) readf, lun, temp second = strsplit(temp, ',', /extract) nentries = n_elements(second) info = fstat(lun) ; print, nentries, info.cur_ptr if nentries lt 1000 then begin print, second ; stop endif vals[xCell, yCell, *] = float(second) ;; stop ;; btemp = byte(temp) ;; commas = where(btemp eq BCOMMA, nfound) ;; ; Parse the values ;; last = 0 ;; for i = 0, nfound -1 do begin ;; vals[xCell, yCell, i] = float(string(btemp[last:commas[i]-1])) ;; last = commas[i]+1 ;; endfor endfor close, lun free_lun, lun !p.multi = [0, 8, 8] !y.range = yrange !y.style = 1 !p.charsize=0.8 slope = fltarr(32, 32) amp = fltarr(32, 32) for i = 0, 15 do begin ;if not keyword_set(set_ps_plot) then window, xsize = 1200*1.5, ysize = 1200 for y0 = 0, 7 do begin for x0= 0, 7 do begin x1=x0+((i mod 4)*8) y1=y0+(i/4)*8 thisval = reform(vals[x1, y1, *])*vscale plot, hindex, thisval, $ title = 'X '+num2str(x1) + ', Y '+num2str(y1),$ xtitle = 'Microseconds', ytitle = 'Volts' ; Find the peak: peakVal = max(thisval, peakind) tend = hindex[peakind] - 0.1e3 ; avoid the center inrange = where(hindex lt tend, nin) if nin eq 0 then continue testval = thisval[inrange] ; Take a derivative: ; Note, ts_diff does x[i] - x[i+1]. We want the other way, ; hence the negative sign. testDiff = -ts_diff(testval, 1, /Double) testresult = moment(testdiff) ave = testresult[0] sig = sqrt(testresult[1]) goodones = where(abs(testdiff - testresult[0]) lt 2*sig) testresult = moment(testdiff[goodones]) * (hindex[1] - hindex[0]) slope[x1, y1] = testresult[0] amp[x1, y1] = max(testval) - min(testval) endfor endfor endfor !p.multi = [0, 0, 0] slope *= 1e3 amp *= 1e3 bmin = min(slope) bmax = max(slope) res = (bmax - bmin) / 100. slopeh = histogram(slope, min = bmin, max = bmax, binsize = res) slopeInd = findgen(n_elements(slopeh)) * res + bmin stp2=findgen(256)/256*(bmax-bmin)+bmin bar2=fltarr(n_elements(stp2),2) bar2[*,0]=stp2 bar2[*,1]=stp2 slopeb = bytscl(slope, min = bmin, max = bmax) plotimage,slopeb,yr=[32,0],/xst,/yst,$ pixel_aspect_ratio=1.0,position=[0.14,0.12,0.48,0.75],$ charsize=csize1,xtit="Column",ytit="Row", title = 'Slope of Sawtooth (mV / us)' plotimage,bytscl(bar2),position=[0.14,0.77,0.48,0.80],$ yticks=1,ytickname=[' ',' '],charsize=csize1, /noerase,$ xthick=tsize, ythick=tsize, charthick=tsize,$ imgxrange=[bmin,bmax] xr1 = [bmin, bmax] yr1 = [0, max(slopeh)*1.1] plot, slopeInd, slopeh, psym = 10, position = [0.65,0.18,0.95,0.8], $ xtitle = 'Slope of Sawtooth (mV / us)', $ ytitle = 'Number of pixels', $ charsize=csize1, /noerase, $ xrange = xr1, yrange=yr1, /xst, /yst bmin = min(amp) bmax = max(amp) res = (bmax - bmin) / 20. amph = histogram(amp, min = bmin, max = bmax, binsize = res) ampInd = findgen(n_elements(amph)) * res + bmin stp2=findgen(256)/256*(bmax-bmin)+bmin bar2=fltarr(n_elements(stp2),2) bar2[*,0]=stp2 bar2[*,1]=stp2 ampb = bytscl(amp, min = bmin, max = bmax) plotimage,ampb,yr=[32,0],/xst,/yst,$ pixel_aspect_ratio=1.0,position=[0.14,0.12,0.48,0.75],$ charsize=csize1,xtit="Column",ytit="Row", title = 'Amplitude of Sawtooth (mV)' plotimage,bytscl(bar2),position=[0.14,0.77,0.48,0.80],$ yticks=1,ytickname=[' ',' '],charsize=csize1, /noerase,$ xthick=tsize, ythick=tsize, charthick=tsize,$ imgxrange=[bmin,bmax] xr1 = [bmin, bmax] yr1 = [0, max(amph)*1.1] plot, ampInd, amph, psym = 10, position = [0.65,0.18,0.95,0.8], $ xtitle = 'Amplitude of Sawtooth (mV)', $ ytitle = 'Number of pixels', $ charsize=csize1, /noerase, $ xrange = xr1, yrange=yr1, /xst, /yst end