'Script to plot multiple sweeps of waveform data with fixed delay and duration from a trigger. You need an event channel holding 'trigger times and one or two waveform channels to process. 'In the dialog, assign channels and define the sweep duration and a pretrigger time. A maximum of 256 sweeps can be plotted. You 'will get an error message if your analysis window contains more than 256 trigger signals. Limit by setting cursor 1 and cursor 2. 'Dirk Bucher, May 2002. 'updated December 2002. Now the error messages are correct and there's no empty xy-plot created anymore if you cancel the script. 'updated January 2004. Extended to a second (optional) channel. The xy view window name will now identify the channel. The time view, 'both xyviews and the log window will be displayed in the front. The log window will display file name, channel names and number of sweeps. 'updated January 2005. Extended option of adding incremental y-offset to channel 1 between sweeps. 'updated Feb 2007. Now allows to use two channels sampled at different rates. if ViewKind() <> 0 then 'checks if the associated window is a time view... Message("This isn't a time view!"); FrontView (App (3)); 'brings script to front... FileClose (0); '...and closes it endif WindowVisible (3); 'sets the time view to the front var ok%, cur1, cur2, title$, xy%; 'sets variable expressions title$:= WindowTitle$(); var fname$,fend$; fname$:=FileName$(3); fend$:=FileName$(4); fname$:=fname$+fend$+".smr"; 'gets the filename of the time view if Cursor (2)1 then FrontView (App (3)); 'brings script to front... FileClose (0); '...and closes it else if check2%=1 then DlgCreate ("Add incremental offset"); DlgReal (1,"channel 1 offset [mV]",-100,100); voltoffset:=10; okOffset% := DlgShow(voltoffset); endif chanName$:=ChanTitle$(wavech%); units$:=ChanUnits$(wavech%); wintitle$:="multisweep 1 of "+chanName$; var nViews%, vlist%[100], counter%, counter$, n%, windummy$; var foundMatch%; nViews%:=Viewlist(vlist%[], 4096); counter%:=0; repeat counter%:=counter%+1; counter$ := Str$(counter%); wintitle$:="multisweep "+counter$+" of "+chanName$; ' test whether the new wintitle$ is distinct foundMatch% := 0; ' this is a boolean n% := 1; while n% <= nViews% and not foundMatch% do Frontview (vlist%[n%]); windummy$:=WindowTitle$(); if windummy$=wintitle$ then foundMatch% := 1; endif; n% := n%+1; wend; ' if we get here and we found a match, we need to loop until not foundMatch%; Frontview (ViewFind(title$)); if check%=1 then var wavech2%, ok2%,chanName2$,wintitle2$; DlgCreate ("select channel 2:"); DlgChan (1,"Waveform channel",513); ok2%:=DlgShow(wavech2%); chanName2$:=ChanTitle$(wavech2%); units2$:=ChanUnits$(wavech2%); wintitle2$:="multisweep 1 of "+chanName2$; counter%:=0; repeat counter%:=counter%+1; counter$ := Str$(counter%); wintitle2$:="multisweep "+counter$+" of "+chanName2$; ' test whether the new wintitle$ is distinct foundMatch% := 0; ' this is a boolean n% := 1; while n% <= nViews% and not foundMatch% do Frontview (vlist%[n%]); windummy$:=WindowTitle$(); if windummy$=wintitle2$ then foundMatch% := 1; endif; n% := n%+1; wend; ' if we get here and we found a match, we need to loop until not foundMatch%; endif Frontview (ViewFind(title$)); trigger%:=ChanData(triggerch%, dummy [], cur1, cur2); if trigger%>256 then Message ("Too many trigger signals! Limit: 256 sweeps. Set cursors!"); FrontView (App (3)); 'brings script to front... FileClose (0); '...and closes it else xy%:=FileNew(12); 'creates xy-view Windowtitle$(wintitle$); Frontview (ViewFind(title$)); 'returns time view to the front var i%,k%, wavechunk [1000000], timebase [1000000], npts%, dt; dt:=BinSize(wavech%); 'returns the sampling interval of the waveform channel for i% := 0 to trigger%-1 step 1 do 'sweep loop npts%:=ChanData (wavech%, wavechunk[], dummy[i%]-(offset/1000), (dummy[i%]-(offset/1000))+(duration/1000)); 'dumps voltage values for one sweep into an array if okOffset%=1 then ArrAdd(wavechunk[],i%*voltoffset); endif for k% := 0 to npts%-1 step 1 do 'data point loop timebase[k%]:= (k%*dt)-(offset/1000); 'generates an array with the appropriate time value for every data point next FrontView(xy%); ' brings xy-view to the front if i% <> 0 then XYSetChan(0); endif ArrMul(timebase[:npts%], 1000); XYAddData((i%+1),timebase[:npts%],wavechunk[:npts%]); 'plots xy-values XYDrawMode((i%+1),2,0); XYColour((i%+1),0); XYJoin((i%+1),1); FrontView (ViewFind(title$)); next '---------------------- if check%=1 then var h%,dt2,npts2%,xy2%, timebase2 [1000000],wavechunk2[1000000]; xy2%:=FileNew(12); 'creates xy-view Windowtitle$(wintitle2$); Frontview (ViewFind(title$)); 'returns time view to the front dt2:=BinSize(wavech2%); for h%:=0 to trigger%-1 step 1 do npts2%:=ChanData (wavech2%, wavechunk2[], dummy[h%]-(offset/1000), (dummy[h%]-(offset/1000))+(duration/1000)); k%:=0; for k% := 0 to npts2%-1 step 1 do 'data point loop timebase2[k%]:= (k%*dt2)-(offset/1000); 'generates an array with the appropriate time value for every data point next FrontView(xy2%); 'brings xy-view to the front if h% <> 0 then XYSetChan(0); endif ArrMul(timebase2[:npts2%], 1000); XYAddData((h%+1),timebase2[:npts2%],wavechunk2[:npts2%]); 'plots xy-values XYDrawMode((h%+1),2,0); XYColour((h%+1),0); XYJoin((h%+1),1); FrontView (ViewFind(title$)); next endif '---------------------- FrontView(xy%); XRange(offset*-1,offset*-1+duration); Optimise(-1); Xtitle$("time"); XUnits$("ms"); ChanTitle$(0,chanName$); ChanUnits$(0, units$); Draw(); WindowSize(50,50); Window(50,0); if check%=1 then FrontView(xy2%); XRange(offset*-1,offset*-1+duration); Optimise(-1); Xtitle$("time"); XUnits$("ms"); ChanTitle$(0,chanName2$); ChanUnits$(0, units2$); Draw(); WindowSize(50,50); Window(50,50); endif Frontview (ViewFind(title$)); WindowSize(50,80); Window(0,0); Frontview (LogHandle ()); Windowsize(50,20); Window(0,80); PrintLog("DATAFILE: ",fname$); FrontView (ViewFind(title$)); PrintLog("CHANNEL 1: ",ChanTitle$(wavech%)); if check%=1 then PrintLog("CHANNEL 2: ",ChanTitle$(wavech2%)); endif Printlog("TRIGGER: ",ChanTitle$(triggerch%)); Printlog("START= ",cur1," / ","END= ",cur2); PrintLog ("# OF SWEEPS: ", i%); PrintLog("\n"); 'new line FrontView (App (3)); 'brings script to front... FileClose (0); '...and closes it endif endif halt