'script searches for bursts and detects burst beginning and end and measures burstduration and copies them to clipboard/saves to file var n,x,a,b,c,d,e,f,g,h,i; var minint,minnumber,burstdura,log%,logfilename$,mainwin%, ok%, yes$, stimchanname$,spikechanname$, wavename$,spikeanzahl,frequenz; 'variables: 'a 'b channel with spike events 'c channel with trigger events 'd memchannel for bursts (level channel) 'e memchannel for burstbeginning (event) 'f memchannel for burst end (event) 'g time of stimulus 'h time of burstbeginning immediately before stimulus 'i time of burstend after burstbeginning (var h) 'n find next burstbeginning / end 'minint 'minnumber 'burstdura 'mainwin% 'ok% minint:=0.5; minnumber:=5; b:=10; c:=12; DlgCreate ("search bursts"); 'dialog window DlgChan (1,"Channel with spike events?",6); 'DlgChan (2,"Channel with stimulus events?",6); DlgReal (2,"min. interval for burst detection (sec)?",0,50000); DlgReal (3,"min. number of spikes for burst?",0,50000); ok%:=DlgShow(b, minint, minnumber); if ok%=0 then halt; endif; 'make memchannels d:=Memchan(4); 'create memchan for bursts e:=Memchan(2); 'create memchan for burstbeginning f:=Memchan(2); 'create memchan for burst end 'and name them Chantitle$(d,"bursts"); Chantitle$(e,"burstbeg"); Chantitle$(f,"burstend"); 'and show them chanshow(d); chanshow(e); chanshow(f); 'get names of original channels and file spikechanname$:=Chantitle$(b); stimchanname$:=Chantitle$(c); wavename$:=Filename$(); Burstmake(d,b,0,Maxtime(),minint,minint,minnumber); 'write bursts to memchan 'now find beginning and end of each burst Repeat n:=nexttime(d,n); memsetitem(e,0,n); if n>0 then n:=nexttime(d,n); memsetitem(f,0,n); endif; UNTIL n<0; 'first delete logfile and write filename and channelnames mainwin%:=View(); log%:=LogHandle(); 'get the logfile handle View(log%); 'go to logfile editselectall(); editclear(); Printlog("Filename:"," ",wavename$," ","Spikechannel"," ",spikechanname$); View(mainwin%); 'and back to main window 'now measure burstduration interact("please use Cursor1 and Cursor2 to set range for measurement",1023); h:=Cursor(1); REPEAT h:=nexttime(e,h); 'find next burstbeginning (first is immediately after Cursor1 i:=nexttime(f,h); 'find next burstend after burstbeginning burstdura:=i-h; if i>0 and h>0 then spikeanzahl:=count(b,h,i); frequenz:=spikeanzahl/burstdura; if hCursor(2) or h<0; ' and save the file View(log%); ' show it editselectall(); editcopy(); yes$:=Input$("results were copied to clipboard, save file now? (y/n)","n",1); if yes$="y" then FileSaveAs(logfilename$,1); ' save it endif; View(mainwin%); 'and back to main window