'script searches for bursts and detects burst beginning and end and copies them to clipboard/saves to file ' if burst is detected during stimulus -> calculates burstduration and time between burst ' beginning and stimulus var n,x,a,b,c,d,e,f,g,h,i; var minint,minnumber,burstdura,log%,logfilename$,mainwin%, ok%, yes$, stimchanname$,spikechanname$, wavename$; '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.15; minnumber:=10; b:=5; c:=4; DlgCreate ("search bursts"); 'dialog window DlgChan (1,"Channel with spike events?",6); DlgChan (2,"Channel with stimulus events?",6); DlgReal (3,"min. interval for burst detection (sec)?",0,50000); DlgReal (4,"min. number of spikes for burst?",0,50000); ok%:=DlgShow(b, c, 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$," ","Stimuluschannel"," ",stimchanname$); View(mainwin%); 'and back to main window 'now find stimulus events and look if they are in a burst REPEAT g:=nexttime(c,g); 'find next stimulus h:=lasttime(e,g); 'find last burstbeginning before stimulus i:=nexttime(f,h); 'find next burstend after burstbeginning burstdura:=i-h; if i>g and h>0 then Printlog("stimulustime"," ",g," ","burstbeginning"," ",h," ","burstend"," ",i," ","Burstduration"," ",burstdura," ","time_of_burstbeg_before_stim"," ",g-h); endif; UNTIL g<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