https://github.com/latereshko/mEPSC_scripts
Tip revision: 4f77b23d5f94e6e8c5e1a76a059cae4f1811659a authored by latereshko on 08 December 2020, 22:49:32 UTC
Delete e
Delete e
Tip revision: 4f77b23
measureWaves6_5.ipf
#pragma rtGlobals=1 // Use modern global access method.
// MeasureWaves-- a collection of routines for intracellular data analysis v. 1 8/7/95
// This is measureWave v. 4.75 4/97--in the process of adding functionality needed for nonstationary noise analysis
// v. 4.8--increasing user friendliness by adding balloon help.
// v. 4.9 fixing interface for ANALGRAPH to allow looping through waves
// In order to compile this set of procedures you need the files in <> to be in the wavemetrics procedures folder in
// the IGOR pro folder, and the files in "" to be in the User procedures folder (in the IGOR pro folder). You also need the
// IGOR extensions: Statfuncs and Statfuncs Help to be in the IGOR EXTENSIONS folder.
#include <Strings as Lists>
#Include <Concatenate waves> //this also Includes <Strings as Lists>
//#Include <Keyword-Value>
#Include <Remove Points>
#Include "wormdisk:Users:Lauren:Desktop:IGOR_Procs:MiniAnalysis:SNUtilities2_5"
//abb
//This file is lost in newer versions of Igor, for backward compatibility just put it in UserProcedures
#Include "wormdisk:Users:Lauren:Desktop:IGOR_Procs:MiniAnalysis:NoteUtilities"
|*******************************************************************************
*
Window analysisparams() : Panel
PauseUpdate; Silent 1 // building window...
NewPanel /W=(123,196,763,377) as "Wave Analysis Parameters"
//abb, put in nicer location
// NewPanel /W=(584.25,211.25,1224,392) as "Wave Analysis Parameters"
ShowTools
SetDrawLayer UserBack
SetDrawEnv fillfgc= (3,52428,1)
DrawRect 183,83,180,83
SetDrawEnv fillfgc= (0,0,65535)
DrawRect 0,0,612,46
DrawText 233,97,"Extract"
SetDrawEnv fillfgc= (32768,32770,65535)
DrawRect 612,45,0,102
DrawRect 2,101,-3,102
SetDrawEnv fillfgc= (16385,65535,65535)
DrawRect 613,101,0,152
SetDrawEnv linefgc= (1,52428,26586),linebgc= (1,52428,26586),fillfgc= (1,52428,26586)
DrawRect 615,151,-1,182
DrawRect 1,182,-1,182
SetDrawEnv fstyle= 1,textrgb= (65535,65535,65535)
DrawText 407,22,"Move Cursors"
CheckBox chkSaveFiles,pos={6,107},size={94,20},title="Save Files"
CheckBox chkSaveFiles,help={"If checked, wave arithmetic operations will not alter the operated waves, but rather copies of original waves."},value=0
SetVariable setPkWid,pos={160,48},size={109,17},title="Width (ms)"
SetVariable setPkWid,limits={0.01,Inf,0},value= gPkWid
CheckBox chkAvg,pos={4,68},size={64,16},title="Mean"
CheckBox chkAvg,help={"Calculates the mean of the selected waves between the cursors when wave measurement is selected. Results are stored in a wave that contains the letters \"Mn\" "},value=1
CheckBox chkpeak,pos={4,49},size={64,17},title="Peak"
CheckBox chkpeak,help={"Find + or - peak between cursors. If width > 0 it returns the mean of the peak period (not just single point). If Use template enabled, the peak period is found only in the template wave and then the mean of the same period is returned for all other wave"},value=0
CheckBox chkArea,pos={73,68},size={50,16},title="Area",value=0
CheckBox chkwName,pos={4,86},size={64,13},title="Names",value=0
CheckBox chkSlope,pos={126,68},size={55,15},title="Slope",value=0
SetVariable setFile,pos={236,156},size={311,17},title="Folder for results "
SetVariable setFile,help={"This contains the name of the folder in which any new files generated by the analysis will be stored. This includes results of wave arithmetic and peak measurement."}
SetVariable setFile,limits={-Inf,Inf,0},value= gResPath
SetVariable setResName,pos={10,157},size={223,17},title="Result base Name"
SetVariable setResName,help={"A base name used to generate names of waves containing analysis results. For concatenation this is the name of the concatenated wave."}
SetVariable setResName,limits={-Inf,Inf,0},value= gResname
Button btnDo,pos={10,10},size={39,28},proc=doWaveOp,title="DO"
PopupMenu popOp,pos={63,14},size={81,19}
PopupMenu popOp,help={"Measure: get peaks, means... --purple section\rBaseline Subtract/Restore: (-)/(+) mean between cursors\rWave Arith.: using constants or waves--light blue section\rAverage: mean of waves is avgW \rConcatenate: make one big wave from a list of small ones"}
PopupMenu popOp,mode=1,value= #"\"Measure;Measure Multiple;Baseline Subtract;WaveArithmetic;Restore Baseline;Average;Smooth;Concatenate\""
PopupMenu popOpList,pos={267,4},size={126,19},title="Waves in"
PopupMenu popOpList,help={"Determines whether wave operation is performed on all waves in the top graph, or all waves in memory."}
PopupMenu popOpList,mode=1,value= #"\"Graph;All\""
PopupMenu popPktype,pos={72,47},size={81,19}
PopupMenu popPktype,mode=2,value= #"\"Positive;Negative\""
CheckBox chkCell,pos={408,82},size={58,17},title="Cell #",value=0
CheckBox chktest,pos={545,81},size={62,17},title="Test #",value=0
CheckBox chkwave,pos={471,82},size={67,16},title="Wave #",value=0
CheckBox chktime,pos={298,84},size={49,15},title="Time",value=0
CheckBox chkAmp,pos={354,83},size={47,16},title="Amp",value=0
CheckBox chkPkTemplate,pos={475,47},size={129,16},title="Use Pktemplate",value=1
PopupMenu popTimeUnits,pos={266,26},size={118,19},title="Time Units"
PopupMenu popTimeUnits,help={"Data files are assumed to have X scaling either in seconds or msec. Use Browse waves in Data menu to determine which your waves are and set accordingly. This insures that times (e.g. peak width) match your data."}
PopupMenu popTimeUnits,mode=2,value= #"\"Msec;Sec\""
Button btnSetFolder,pos={558,155},size={32,17},proc=setResPath,title="SET"
PopupMenu popNotebook,pos={115,82},size={122,19},proc=setNotebook,title="Notebook"
PopupMenu popNotebook,help={"Use this to open a new or existing notebook file or edit one already open. See Igor manual for descriptions of notebooks."}
PopupMenu popNotebook,mode=1,value= #"WinList(\"*\", \";\",\"WIN:16\")+\";NONE;OPEN EXISTING;OPEN NEW\" "
PopupMenu pop2ndWave,pos={120,109},size={187,19},title="Arithmetic Wave"
PopupMenu pop2ndWave,help={"Use this to select the wave you wish to add, subtract, divide or multiply with the rest of the waves."}
PopupMenu pop2ndWave,mode=1,value= #"\"avgmini;\"+\"NONE;\"+WaveList(\"*\", \";\", \"\")"
PopupMenu popArithOp,pos={322,108},size={42,19}
PopupMenu popArithOp,mode=2,value= #"\"(+);(-);(X);(/)\""
SetVariable setConstant,pos={382,109},size={78,17},title="K="
SetVariable setConstant,limits={-Inf,Inf,0},value= K19
CheckBox chkScale2Pk,pos={475,109},size={129,16},title="Scale to Peak",value=1
CheckBox chkNewWaves,pos={172,129},size={145,18},title="Create New Waves",value=0
SetVariable setNewName,pos={334,130},size={272,17},title="New File base Name"
SetVariable setNewName,limits={-Inf,Inf,0},value= gOutBase
CheckBox chkOverwrite,pos={6,130},size={86,18},title="Overwrite",value=0
CheckBox chkDisplay,pos={100,130},size={67,17},title="Display",value=0
PopupMenu popTemplate,pos={281,48},size={179,19},title="Template Wave"
PopupMenu popTemplate,help={"Use this to select the wave which will be used to set the window for measuring peaks."}
PopupMenu popTemplate,mode=1,value= #"WaveList(\"*\", \";\",\"\")+\"avgmini;\""
CheckBox chkRise,pos={184,68},size={55,15},title="Rise",value=0
SetVariable setIntvl,pos={509,26},size={91,17},title=" "
SetVariable setIntvl,limits={0.01,Inf,0},value= gMoveInc
Button btnMoveLeft,pos={507,4},size={45,20},proc=MoveCrsr,title="<-"
Button btnMoveRight,pos={559,3},size={45,20},proc=MoveCrsr,title="->"
Button btnGetInc,pos={454,24},size={46,18},proc=getInc,title="Get"
PopupMenu popNreps,pos={172,15},size={54,19},title="#",mode=1,value= #"g1to99"
EndMacro
|********************************************************************************Window analysisChooserPan() : Panel PauseUpdate; Silent 1 | building window
...
NewPanel /W=(2,42,615,130) as "Analysis Options"
SetDrawLayer UserBack
SetDrawEnv fillfgc= (3,52428,1)
DrawRect 183,83,180,83
SetDrawEnv fillfgc= (0,0,65535)
DrawRect 2,6,604,49
SetDrawEnv fillfgc= (0,13107,6646)
DrawRect 604,50,217,82
SetDrawEnv fillfgc= (13102,26214,0)
DrawRect 216,82,3,50
Button
btnLoadMultiple,pos={439,57},size={97,20},proc=LoadIgorBin,title="Load
Waves"
Button btnKill,pos={539,56},size={62,20},proc=killem,title="Kill"
Button btnStats,pos={10,54},size={43,22},proc=showplotpan,title="Stats"
PopupMenu
popGraph,pos={11,11},size={63,19},proc=ShowWindow,title="Graph"
PopupMenu popGraph,mode=1,value= #"WinList(\"*\", \";\",\"WIN: 1\")"
PopupMenu
popTable,pos={164,12},size={59,19},proc=ShowWindow,title="Table"
PopupMenu popTable,mode=1,value= #"WinList(\"*\", \";\",\"WIN: 2\")"
PopupMenu
popNotes,pos={233,12},size={88,19},proc=ShowWindow,title="NoteBook"
PopupMenu popNotes,mode=1,value= #"WinList(\"*\", \";\",\"WIN: 16\")"
Button btnPlot,pos={57,54},size={39,22},proc=showplotpan,title="Plot"
Button
btnEvents,pos={463,14},size={117,24},proc=showplotpan,title="Event
Detection"
Button
btnParams,pos={330,13},size={125,22},proc=showplotpan,title="Analysis
Params"
Button
btnGraph,pos={102,54},size={44,23},proc=showWaveTable,title="Graph"
EndMacro
|*******************************************************************
Macro showNotebook(ctrlName) : ButtonControl
string ctrlName
string currNotebk
// The window name of the current notebook
controlInfo popNotebook
currNotebk = S_Value
if ((cmpstr(currNotebk,"none")!=0)%&(cmpstr(currNotebk,"")!=0)))
// executes if NOT "none" and not null string
doWindow /F currNotebk
else
doAlert 0,"First use the Notebook popup menu to open or
create a Notebook"
endif
End
|*******************************************************************
Macro showWaveTable(ctrlName) : ButtonControl
string ctrlName
//* This routine displays the table of text waves which contain lists of
waves to be operated upon
//* Only one such table may exist at a time.
//* I have forgotten exactly what the idea was here. I think the idea is to
allow 2 or more sets of waves e.g.
//* for calculating an IV curve, one would want a set of voltage and a set
of current waves. But how exactly this
//* was to interface with the rest of measureWaves, I can no longer recall.
doWindow /F waveTablePan // bring the control panel to the
front--this is created at initialization
doWindow/F waveTable // bring the wave table window to
the front
End
|*******************************************************************************
*
Window waveTablePan() : Panel
PauseUpdate; Silent 1 // building window...
NewPanel /W=(60,78,626,192) as "Display and Load Options"
//abb put in nicer location
// NewPanel /W=(660,440.75,1226.25,554.75) as "Display and Load Options"
SetDrawLayer UserBack
SetDrawEnv fillfgc= (21845,21845,21845),fillbgc= (52428,1,1)
DrawRect 0,1,538,114
PopupMenu popWave,pos={86,34},size={169,19},title="WAVES"
PopupMenu popWave,mode=1,value= #"WaveList(\"*\", \";\", \"\")"
PopupMenu popListMode,pos={86,12},size={118,19}
PopupMenu popListMode,help={"Selected Wave: only one wave is displayed\rAll with BaseName: all waves that have the same basename as the selected wave are displayed\rAll: all waves currently in memory are displayed"}
PopupMenu popListMode,mode=1,value= #"\"Selected Wave;All with basename;All\""
Button btnLoadMultiple,pos={6,85},size={120,20},proc=LoadIgorBin,title="Load Waves"
Button btnKill,pos={133,85},size={120,20},proc=killem,title="Kill"
Button btnDisplay,pos={7,13},size={72,36},proc=DisplayWaves,title="DISPLAY"
SetVariable setBaseSep,pos={391,12},size={139,17},title=" "
SetVariable setBaseSep,help={"Enter the basename or basename separator here.\rBasename: all waves with names containing these characters are selected. Basename separator: As above but gets the basename from the selected wave (all characters preceding the separator character)."}
SetVariable setBaseSep,limits={-Inf,Inf,0},value= gBaseNameSep
PopupMenu popBaseorSep,pos={436,33},size={92,19}
PopupMenu popBaseorSep,mode=1,value= #"\"basename;basename separator\""
PopupMenu popGraph,pos={236,11},size={144,19},title="Graphs"
PopupMenu popGraph,help={"Select an existing graph to add waves to, or select new graph to create a new graph."}
PopupMenu popGraph,mode=1,value= #"WinList(\"*\", \";\",\"WIN:1\")+\";NEW Graph\" "
PopupMenu popNumCopies,pos={8,59},size={161,19}
PopupMenu popNumCopies,mode=1,value= #"\"Allow multiple copies;One copy per graph\""
Button btnLoadAndAvg,pos={179,59},size={120,20},proc=callLoadAndAvg,title="Load and Average"
EndMacro
|*******************************************************************
Function analgraph(gType,gName)
variable gType // type of analysis graph requested
string gName // a unique name for the window
PauseUpdate; Silent 1 // building window...
Display /W=(130,111,788,488) as gName
if (gType==1)
ShowInfo
ControlBar 80
PopupMenu popDispMode,pos={10,6},size={72,19}
PopupMenu popDispMode,mode=4,value=#"\"Replace;Append;Remove;Display\""
PopupMenu popAll,pos={27,59},size={206,19},proc=PopSelProc,title="All Waves "
PopupMenu popAll,mode=19,value= #"WaveList(\"*\", \";\", \"\")+\"ALL\""
Button btnNxt,pos={93,2},size={38,16},proc=dsplayGraph,title="Next"
Button btnPrev,pos={93,21},size={37,17},proc=dsplayGraph,title="Prev"
Button btnKill,pos={410,5},size={66,19},proc=dsplayGraph,title="Kill"
CheckBox chkKillFile,pos={414,24},size={79,18},title="File",value=0
CheckBox chkKillRow,pos={414,39},size={89,18},title="Table Row",value=0
PopupMenu popSelected,pos={28,39},size={206,19},proc=PopSelProc,title="Selected Waves"
PopupMenu popSelected,mode=1,value= #"gWlist+\"ALL\""
Button btnSetDelWList,pos={505,39},size={118,18},proc=showplotpan,title="Set Table Waves"
CheckBox chkKillWave,pos={414,54},size={84,19},title="KillWave",value=1
SetVariable setCurrWaveNum_1,pos={144,10},size={124,17},title="Wave Number "
SetVariable setCurrWaveNum_1,limits={-INF,INF,0},value= gWaveNum
Button butUpdateList,pos={239,38},size={134,23},proc=upDateWList,title="Update From Graph"
CheckBox chkSelected,pos={7,36},size={20,19},title="",value=0
CheckBox chkAll,pos={7,57},size={20,19},title="",value=1
endif
EndMacro
|*******************************************************************
Window plotpanel() : Panel
PauseUpdate; Silent 1 | building window...
NewPanel /W=(9,59,381,333) as "Plotting"
ShowTools
PopupMenu
popTableX,pos={14,50},size={112,19},proc=SwitchTable,title="X axis"
PopupMenu popTableX,mode=1,value= #"WinList(\"*\", \";\",\"WIN: 2\")"
PopupMenu
popTableY,pos={13,24},size={112,19},proc=SwitchTable,title="Y axis"
PopupMenu popTableY,mode=1,value= #"WinList(\"*\", \";\",\"WIN: 2\")"
PopupMenu popVarX,pos={134,50},size={78,19}
PopupMenu popVarX,mode=1,value= #"WaveList(\"*\", \";\", \"\")"
PopupMenu popVarY,pos={133,23},size={78,19}
PopupMenu popVarY,mode=1,value= #"WaveList(\"*\", \";\",
\"WIN:\"+S_Value)"
Button btnplot,pos={17,77},size={67,33},proc=plotproc,title="NEW PLOT"
Button
btnAppend,pos={94,78},size={71,31},proc=plotproc,title="APPEND TO"
PopupMenu popGraph,pos={176,83},size={91,19}
PopupMenu popGraph,mode=1,value= #"WinList(\"*\", \";\",\"WIN: 1\")"
PopupMenu popTableSort,pos={78,127},size={67,19},proc=SwitchTable
PopupMenu popTableSort,mode=1,value= #"WinList(\"*\", \";\",\"WIN:
2\")"
Button btnsort,pos={7,119},size={67,33},proc=plotproc,title="Sort"
PopupMenu popVarSort,pos={150,128},size={140,19},title="by wave"
PopupMenu popVarSort,mode=1,value= #"WaveList(\"*\", \";\",
\"WIN:\"+S_Value)"
EndMacro
|*******************************************************************
Window statpanel() : Panel
variable /g gRowStart=1, gRowEnd=9
PauseUpdate; Silent 1 | building window...
NewPanel /W=(9,59,478,384) as "Statistics and Histograms"
ShowTools
SetDrawLayer UserBack
SetDrawEnv fsize= 16,fstyle= 1
DrawText 5,24,"TABLE OPERATIONS"
SetDrawEnv fsize= 16,fstyle= 1
DrawText 2,169,"WAVE OPERATIONS"
SetDrawEnv fillfgc= (65535,0,0)
DrawRect 441,23,-1,146
SetDrawEnv fillfgc= (44253,29492,58982)
DrawRect 440,168,3,325
PopupMenu
popTable,pos={191,34},size={124,19},proc=SwitchTable,title="Table"
PopupMenu popTable,mode=1,value= #"WinList(\"*\", \";\",\"WIN: 2\")"
PopupMenu popVar,pos={145,175},size={176,19},title="Waves in Table"
PopupMenu popVar,mode=1,value= #"WaveList(\"*\", \";\",
\"WIN:\"+gtable)"
CheckBox chkSave pos={356,92},size={50,20}, title="Save",value=1
SetVariable setFile,pos={2,125},size={385,17},title="Result Folder"
SetVariable setFile,limits={-INF,INF,0},value= gResPath
Button
btnSetFolder,pos={390,120},size={37,22},proc=setResPath,title="SET"
Button
btnHisto,pos={13,298},size={118,23},proc=statproc,title="Histogram"
Button btnsort,pos={5,61},size={83,28},proc=statproc,title="Sort"
PopupMenu popVarSort,pos={95,66},size={81,19},title="by wave"
PopupMenu popVarSort,mode=1,value= #"WaveList(\"*\", \";\",
\"WIN:\"+S_Value)"
Button btnSave,pos={6,95},size={83,28},proc=statproc,title="SAVE"
Button btnRStat,pos={190,95},size={83,28},proc=statproc,title="Row
Stats"
SetVariable setRstart,pos={280,85},size={70,15},title="from"
SetVariable setRstart,limits={0,INF,1},value=gRowStart
SetVariable setRend,pos={280,105},size={70,15},title="to"
SetVariable setRend,limits={0,INF,1},value=gRowEnd
Button
btnintvl,pos={14,242},size={119,24},proc=statproc,title="Extract Intervals"
Button
btncompress,pos={13,271},size={119,20},proc=statproc,title="Compress"
PopupMenu popAllWaves,pos={144,200},size={151,19},title="All Waves"
PopupMenu popAllWaves,mode=2,value= #"WaveList(\"*\", \";\",\"\")"
Button btnStats,pos={5,29},size={83,28},proc=statproc,title="Stats"
CheckBox
check0,pos={117,173},size={19,20},proc=CheckRadioProc,title="",value=1
CheckBox
check1,pos={117,199},size={19,20},proc=CheckRadioProc,title="",value=0
EndMacro
//*******************************************************************
Window killpanel() : Panel
PauseUpdate; Silent 1 // building window...
NewPanel /W=(336,238,797,315) as "Waves to Delete Points from"
PopupMenu popTable,pos={7,4},size={163,19},proc=SwitchTable,title="Use Waves in:"
PopupMenu popTable,mode=1,value= #"WinList(\"*\", \";\",\"WIN: 2\")"
PopupMenu popAllWaves,pos={8,28},size={148,19},proc=ModifyKillList,title="or All Waves"
PopupMenu popAllWaves,mode=12,value= #"WaveList(\"*\", \";\",\"\")+\"ALL\""
SetVariable setWList,pos={9,55},size={448,14},title=" ",fSize=10
SetVariable setWList,limits={-INF,INF,0},value= gDelWList
PopupMenu popListOp,pos={284,26},size={49,19},mode=1,value=#"\"add;remove\""
PopupMenu popVar,pos={192,4},size={75,19},proc=ModifyKillList
PopupMenu popVar,mode=13,value= #"WaveList(\"*\", \";\",\"WIN:\"+gtable)+\"ALL\""
EndMacro
//*******************************************************************
Macro showplotpan(ctrl) : ButtonControl
String ctrl
PauseUpdate; Silent 1 // building window...
if (cmpstr(ctrl,"btnPlot")==0)
controlInfo /W=plotpanel btnSort
if (V_Flag) // it exists
doWindow /F plotpanel
else
plotpanel() // recreate it
endif
endif
if (cmpstr(ctrl,"btnStats")==0)
controlInfo /W=statpanel btnpath
if (V_Flag) // it exist
doWindow /F statpanel
else // it doesn't exist
statpanel() // recreate it
endif
endif
if (cmpstr(ctrl,"btnEvents")==0)
controlInfo /W=spikeDetectParams btnAnalyze
if (V_Flag) // it exists
doWindow /F spikeDetectParams
else
initSpikes() // recreate it
endif
endif
if (cmpstr(ctrl,"btnSetDelWList")==0)
controlInfo /W=killpanel btnRemove
if (V_Flag) // it exists
doWindow /F killpanel
else
killpanel() // recreate it
endif
endif
End
//*******************************************************************
Function ShowWindow(ctrlName,popNum,popStr) : PopupMenuControl
String ctrlName
Variable popNum
String popStr
doWindow /F $popStr
End
//*******************************************************************
Macro showKillpan(ctrlName) : ButtonControl
String ctrlName
PauseUpdate; Silent 1 | building window...
Killpanel()
End
//*******************************************************************
Function setResPath(ctrlName) : ButtonControl
String ctrlName
SVAR gResPath=gResPath
newpath /C /M="select or create a path for results" /O /Q resPath
pathInfo resPath
gResPath = S_path
End
//*******************************************************************
Function plotproc(ctrlName) : ButtonControl
String ctrlName
String varx,vary, graphname, wavlist,wliststr,sortwave
string /G gtable, gtablex, gtabley, gtablesort
ControlInfo popVarX
wave wx = $S_Value
ControlInfo popVarY
wave wy = $S_Value
ControlInfo popGraph
graphname = S_Value
if (cmpstr(CtrlName,"btnplot")==0)
Display wy vs wx
endif
if (cmpstr(CtrlName,"btnAppend")==0)
doWindow /F $graphname
AppendToGraph wy vs wx
endif
if (cmpstr(CtrlName,"btnSort")==0)
controlInfo popTableSort
graphname = S_Value
ControlInfo popVarSort
sortwave = S_Value
doWindow /F $graphname
wavlist = wavelist("*",";","WIN:")
wavList = PossiblyQuoteList(wavList, ";")
wliststr = ReplaceListSeparator(wavlist, ";",",")
Execute "Sort"+sortwave+","+wliststr[0,strlen(wliststr)-1] // strip trailing comma
endif
End
//*******************************************************************
Function statproc(ctrlName) : ButtonControl
String ctrlName
String tabname, wavlist,wliststr,sortwave, wavestr, wname, iwname,sdstr, mnstr, numstr
variable iwave, numNANs
string /g gtable, gtablex, gtabley, gtablesort
variable rStart, rEnd, maxEnd, nrows, ncols, ir, ncless1, ncratio,bSave
string rMeanStr, RSDstr
ControlInfo popTable // get the selected table
tabname = S_Value // and the list of waves in the table
wavlist = wavelist("*",";","WIN:"+tabname) // and convert the list to a comma-delimited
wavList = PossiblyQuoteList(wavList, ";")
wliststr = ReplaceListSeparator(wavlist, ";",",") // list for use with "execute"
ControlInfo check0
if (V_value) // if checked, get the table wave
ControlInfo popVar
else // otherwise, get the wave from the list of all waves
ControlInfo popAllWaves
endif
wname = S_Value
wave w = $wname
ControlInfo chkSave
bSave = V_Value
if (cmpstr(CtrlName,"btnhisto")==0)
endif
//
// Save the waves in the table
//
if (cmpstr(CtrlName,"btnSave")==0)
do
wavestr = GetStrFromList(wavlist, iwave,";")
if (strlen(wavestr)== 0)
break
endif
Save /P=resPath $wavestr
iwave +=1
while (1)
endif
if (cmpstr(CtrlName,"btnSort")==0)
ControlInfo popVarSort
sortwave = S_Value
Execute "Sort"+sortwave+","+wliststr[0,strlen(wliststr)-1] // strip trailing comma
endif
if (cmpstr(CtrlName,"btnintvl")==0)
if (strlen(wname)<18)
iwname = "i"+wname
else
iwname = "i"+wname[1,strlen(wname)]
endif
duplicate /O /D /R=[0,numpnts(w)-2] w, $iwname
wave iw = $iwname
iw = w[p+1]-w[p]
endif
//
//Compute mean and s.dev across rows (i.e. within a column)
//
if (cmpstr(CtrlName,"btnstats")==0) // loop through waves in table, fill in
sdstr = "SD"+tabname
mnstr = "MN"+tabname
numstr = "NUM"+tabname
make /D/N=30 $sdstr, $mnstr, $numstr
wave /D sdw = $sdstr; wave /D mnw = $mnstr; wave /D numw = $numstr
do
wavestr = GetStrFromList(wavlist, iwave,";")
if (strlen(wavestr)== 0)
break
endif
wavestats $wavestr
sdw[iwave] = V_sdev
mnw[iwave] = V_avg
numw[iwave] = V_npnts
iwave +=1
while (1)
note sdw wavlist
note mnw wavlist
note numw wavlist
edit sdw, mnw, numw
if (bSave)
save /J /P=resPath /O sdw,mnw,numw
endif
endif // points in waves: SD_tablename, MN_tablename etc.
//
//Compute mean and s.dev across columns (i.e. within a row)
// NOTE: all waves in table must have same # of rows for this to work properly
//
if (cmpstr(CtrlName,"btnRStat")==0)
controlInfo setRstart
rStart = V_Value
controlInfo setREnd
rEnd = V_Value
iwave = rStart
maxEnd = NumItemsInList (wavList, ";")-1; rEnd =min(maxEnd,rEnd)
if (rStart > rEnd)
abort "starting row must be < ending row and < last row in table"
endif
wavestr = GetStrFromList(wavlist, iwave,";")
rMeanStr = uniqueName("RMean"+tabname,1,0)
RSDstr = uniqueName("RSD"+tabname,1,0)
// make 2 temp waves with #points of 1st wave
nrows = numpnts($wavestr)
ncols = rEnd-rStart+1
make /O/N=(nrows) tmp1=0, tmp2=0, $rMeanStr=0,$RSDstr=0 // will hold means and sdev when done
wave tmp1 = tmp1
wave tmp2 = tmp2
wave rMean = $rMeanStr
wave RSD = $RSDstr
do
wavestr = GetStrFromList(wavlist, iwave,";")
print "doing wave",wavestr
if (cmpstr(wavestr,"")==0)
break
endif
wave w = $waveStr
tmp1 += w
// accumulate sum of elements
tmp2 += w^2
// accumulate sum of squares of elements
iwave +=1
while (iwave <=rEnd)
rMean = tmp1/ncols
ncless1 = ncols-1
ncratio = ncols/(ncols-1)
RSD =sqrt(((tmp2)/ncless1)-((rMean^2)*ncratio))
note rMean wavlist
note RSD wavlist
appendToTable rMean, RSD
if (bSave)
save /J /P=resPath /O rMean
save /J /P=resPath /O RSD
endif
doWindow /F $tabname
endif
//
// Compress rows by Removing NANs
//
if (cmpstr(CtrlName,"btnCompress")==0)
numNANs = RemoveNANs(w) //Wavemetrics version
endif
End
//*******************************************************************
Function CheckRadioProc(ctrlName,checked) : CheckBoxControl
String ctrlName
Variable checked
if (cmpstr(ctrlName,"check0")==0)
checkbox check1, value=0
else
checkbox check0, value=0
endif
End
//*******************************************************************
Function killem(ctrlName) : ButtonControl
String ctrlName
killwaves /A/Z
End
//*******************************************************************
Function SwitchTable (CtrlName,popNum,popStr) : PopupMenuControl
String ctrlName
Variable popNum
String popStr
string /g gtable, gtablex, gtabley, gtablesort
if (cmpstr(CtrlName,"popTable")==0)
ControlInfo popTable
gtable = S_value
PopupMenu popVar,mode=1,value= #"WaveList(\"*\", \";\",\"WIN:\"+gtable)+\"ALL\""
endif
if (cmpstr(CtrlName,"popTableX")==0)
ControlInfo popTableX
gtableX = S_value
PopupMenu popVarX,mode=1,value= #"WaveList(\"*\", \";\",\"WIN:\"+gtableX)"
endif
if (cmpstr(CtrlName,"popTableY")==0)
ControlInfo popTableY
gtableY = S_value
PopupMenu popVarY,mode=1,value= #"WaveList(\"*\", \";\",\"WIN:\"+gtableY)"
endif
if (cmpstr(CtrlName,"popTableSort")==0)
ControlInfo popTableSort
gtablesort = S_value
PopupMenu popVarSort,mode=1,value= #"WaveList(\"*\", \";\",\"WIN:\"+gtablesort)"
endif
End
//*******************************************************************
Function DisplayWaves (ctrlName) : ButtonControl
String ctrlName
//abb so we can display waves in subfolder
SVAR gBaseStr = root:gBaseStr
SVAR gBaseNameSep = root:gBaseNameSep
SVAR gCurrWave = root:gCurrWave
NVAR gWaveNum=root:gWaveNum
variable listMode, wavenum, iwave, ibase, baseOrSep, iErr
variable iok, onlyOneCopyAllowed
string currWave, basenm, biglist = WaveList("*", ";", ""), wavestr
string graphName, graphBaseName="rawGraph"
//Find out which graph we are displaying on
ControlInfo popGraph
graphName = S_Value
//d print "trying to display on graph",graphName
ControlInfo popWave
currWave = S_value
//d print "trying to display",currWave
ControlInfo popBaseorSep // 1 = base name, 2 = basename separator
baseorSep = V_value
ControlInfo PopListMode
listMode=V_value // 1 = selectedwave, 2= all waves with basename, 3=all waves
ControlInfo PopNumCopies
onlyOneCopyAllowed=V_value-1 // 0 = false, 1 = true
if (cmpstr(graphName,"NEW graph")==0)
graphName = uniqueName(graphBaseName,6,0)
iok = analGraph(1,graphName)
//d print "going to use graph",graphName
endif
// Adding to graph
doWindow /F $graphName
do
// case selection
//d print "listmode=",listMode
if (listMode == 1) // justselected wave
if (onlyOneCopyAllowed)
CheckDisplayed $currWave
if (V_Flag==0)
appendtoGraph $currWave
wavestr = currWave
endif
else
appendtoGraph $currWave
wavestr = currWave
endif
break
endif
if (listMode==2) // use allwaves with basename
// we only need to figure this stuff out if we are adding more than onewave, but not all
if (baseOrSep==1) //base name specified
basenm = gBaseNameSep
else
// base name separator specified
ibase = strsearch(currWave, gBaseNameSep, 0)
if (ibase > 0) // if base name separator found
basenm = currWave[0,ibase-1]
else
basenm = currWave
endif
//print "basenm=",basenm
endif
iwave = 0
do
wavestr = GetStrFromList(biglist, iwave,";")
if (strlen(wavestr) == 0)
break
endif
ibase = strSearch(wavestr, basenm, 0)
if (ibase != -1)
if (onlyOneCopyAllowed)
CheckDisplayed $wavestr
if (V_Flag==0)
appendtoGraph $wavestr
endif
else
appendtoGraph $wavestr
endif
endif
iwave +=1
while (1)
break
endif
if (listMode==3) // use allwaves
iwave = 0
do
wavestr = GetStrFromList(biglist, iwave,";")
if (strlen(wavestr) == 0)
break
endif
if (onlyOneCopyAllowed)
CheckDisplayed $wavestr
if (V_Flag==0)
appendtoGraph $wavestr
endif
else
appendtoGraph $wavestr
endif
iwave +=1
while (1)
break
endif
while (1)
iErr = GetBaseName(wavestr)
End
//*******************************************************************
Function ModifyKillList (ctrlName,popNum,popStr) : PopupMenuControl
string ctrlName
variable popNum
string popStr
string /G gDelWlist, gTable
string listOp
ControlInfo popTable
// Get currentlyselected table and
gTable = S_Value
ControlInfo popListOp
listOp = S_Value
// add orremove
if (cmpstr(listOp,"add")==0)
if (cmpstr(popStr,"ALL")==0)
//adding all waves
if (cmpstr(ctrlName,"popAllWaves")==0)
// using list of all waves
gDelwlist = WaveList("*", ";", "")
else
// using list of waves in table
gDelwlist = WaveList("*", ";", "WIN:"+gTable)
endif
else
// adding one
if (FindItemInList(popStr, gDelwlist, ";",0)==-1)
// if its not already in the kill list
gDelwlist += (popStr + ";")
endif
endif
else
// remove
if (cmpstr(popStr,"ALL")==0)
// all waves
gDelwlist = ""
else
// adding one
gDelwlist = RemoveItemFromList(popstr, gDelwlist, ";")
endif
endif
controlUpdate /A
End
//*******************************************************************
Function PopSelProc(ctrlName,popNum,wStr) : PopupMenuControl
String ctrlName
Variable popNum
String wStr
Variable iErr
string listmode
NVAR gWaveNum = gWaveNum // 1-basedindex of the wave in the list of all waves
if (cmpstr(ctrlName,"popAll")==0)
Checkbox chkAll value=1
Checkbox chkSelected value=0
else
if (cmpstr(ctrlName,"popSelected")==0)
Checkbox chkAll value=0
Checkbox chkSelected value=1
endif
endif
gWaveNum = popNum
// index into the list of waves NOTE this is 1-based
dsplaygraph("pop")
return 0
End
// *******************************************************************
Function GetBaseName(waveStr)
String waveStr
//abb to work in subfolder
SVAR gBaseStr=root:gBaseStr
SVAR gBaseNameSep = root:gBaseNameSep
SVAR gCurrWave = root:gCurrWave
Variable ibase
gCurrWave = waveStr
ibase = strsearch(waveStr, gBaseNameSep, 0)
if (ibase > 0) //if base name separator found
gbaseStr = waveStr[0,ibase-1]
else
return -1
endif
return 0
End
// *******************************************************************
Function dsplayGraph (ctrlName) : ButtonControl
String ctrlName
//
// Removes specified wave from display, or removes all but specified wavefrom display
//
Variable iwave = 0, ibase, bKillFile, bKillRow, bKillWave, wnum,wknum, ktrace, loopcount, maxWaves
String wGraphList = TraceNameList("",";",1)
String wstr, delWlist, wkstr
SVAR gbasestr=gbasestr
SVAR gBaseNameSep = gBaseNameSep
SVAR gDelWList=gDelWList
SVAR gCurrWave=gCurrWave
SVAR gWList=gWList
String dispmode, wlist, selStr, listmode=""
NVAR gWaveNum = gWaveNum
variable bAll
//
// First find out whether we are using selected waves or all waves
//
controlInfo chkAll // we are using all waves
if (V_Value)
wList = WaveList("*",";","")
bAll = 1
else //we are using aselection of waves
wList = removeItemFromList("ALL",gWList,";") //get rid of the "ALL" so we get the right number of waves
bAll = 0
endif
maxWaves = NumItemsInList (wList, ";") // need to subtractone because last element is "ALL"
//print "maxwaves=",maxwaves
gCurrWave = getStrFromList(wlist,gWavenum-1,";")
controlInfo popDispMode
dispmode = S_value
// append, replace, display, remove
do
// switch
if (cmpstr(ctrlName,"btnNxt") == 0)
gWaveNum +=1
gWaveNum = mod(gWaveNum-1,maxWaves)+1
if (bAll)
popupmenu popAll mode=(gWaveNum)
else
popupmenu popSelected mode=(gWaveNum)
endif
gCurrWave = getStrFromList(wlist,gWavenum-1,";")
break
endif
if (cmpstr(ctrlName,"btnPrev") == 0)
gWaveNum -=1
if (gWaveNum < 1)
gWaveNum = maxWaves
endif
gCurrWave = getStrFromList(wlist,gWavenum-1,";")
if (bAll)
popupmenu popAll mode=(gWaveNum)
// should already be 1-based
else
popupmenu popSelected mode=(gWaveNum)
endif
break
endif
if (cmpstr(ctrlName,"btnKill") == 0)
controlInfo chkKillFile; bkillFile = V_Value
controlInfo chkKillRow; bkillRow = V_Value
controlInfo chkKillWave; bkillWave = V_Value
delWlist = ReplaceListSeparator(gDelWlist, ";",",")
RemoveFromGraph $gCurrWave
if (bkillWave)
if (bkillFile)
KillWaves /F/Z $gCurrWave
// get rid of underlying Igor binary files
else
KillWaves /Z $gCurrWave
endif
endif
//
// The list of waves to delete waves from is specified in a separate panel
//
//
//!!!!!!NOTE in its present form this works only if the waves in the tablescontain entries for each of the displayed
// waves (i.e. have points whose indices correspond to the trace #s of thewaves being killed)
// this could be made to work more generally if I either 1) create awavelist in the same order as that used to
// generate the measurement points in the waves in the table. (then when wewant to delete a point associated with
// a wave, we find out the position in the list and this tells us the pointnumber to delete) OR 2) if we can somehow
// access the trace numbers in the graph--though this could change withoutchanges in the table.
if (bKillRow) // Note: instead of deleting points, wewill set to NANs
do
wkstr = GetStrFromList(gDelWlist,wknum,";")
wknum+= 1
if ((strlen(wkstr) == 0)%|(exists(wkstr)!=1))
break // We hit the end
endif
wave wkill = $wkstr
wkill[gWaveNum-1]=NAN //convert to 0-based from 1-based
while (1)
endif
// now display the next wave if there is one
// gWaveNum += 1
// if(gWaveNum <=maxWaves)
if (bAll==0)
gWList =removeItemFromList(gCurrWave,gWList,";") // get rid of thewaves from the selected list
endif
dsplaygraph("")
return 0
// gCurrWave = getStrFromList(wlist,gWavenum-1,";")
// endif
controlUpdate /A
endif
// if killing
break
// in case it was some other control, likethe popups
while (1)
Do
// switch
if (cmpstr(dispmode,"display")==0)
do
// first loop through and get ridof the other waves
wstr = GetStrFromList(wGraphList, iwave,";")
if ((strlen(wstr) == 0)%|(exists(wstr)!=1))
// if we hit the end or a nonexistant wave exit the loop
break
endif
RemoveFromGraph $wstr
iwave += 1
while (1)
AppendToGraph $gCurrWave
break
endif
if (cmpstr(dispmode,"Append")==0)
CheckDisplayed $gCurrWave
if (V_Flag==0) // not displayedalready
AppendToGraph $gCurrWave
endif
break
endif
if (cmpstr(dispmode,"Remove")==0)
CheckDisplayed $gCurrWave
if (V_flag)
RemoveFromGraph $gCurrWave
endif
break
endif
while (1)
End
//*******************************************************************
Function upDateWList(ctrlName) : ButtonControl
String ctrlName
SVAR gWList = gWList
gWList = RemoveQuotesFromList(TraceNameList("",";",1),";")
End
//***************************************************************************
Function doWaveOp (ctrlName) : ButtonControl
String ctrlName
NVAR gPkwid=gPkwid
variable timeFactor
//*** should these be NVARs ?
//abb to work in sub datafolder
SVAR gResName=root:gResName
SVAR gResPath=root:gResPath
SVAR gBaseStr=root:gBaseStr
SVAR gOutBase=root:gOutBase
variable curposA, curposB, iwave=0, iw=0
variable bmean, bpeak, barea, bslope, strtpk, endpk, pkmode,bUseTemplate, bSave
variable bCell, bTest, bWave, bTime, bAmp, ibase, ic, it, pkwid,pkloc, bwName, bScaleWave2, bNewFiles, bDisplay
variable iabort, bOverwrite, ipop, brise
variable /D baseval, lcsr, rcsr,lowlevel, highlevel, startRise, endRise
String wavList, notestr, outCode, waveInGraphList
String waveOp, wavestr, listmode, template
string wstr,uwstr, tabName, secondWave, arithOp, noteText
string currNotebk // the nameof the currently opened notebook
variable nstatus, maxWaves, arithK, templatePk
controlInfo popNotebook
currNotebk = S_Value
//
// First find out what waves we are operating on and make the wavelist
//
controlInfo popOpList
listmode = S_value
if (cmpstr(listmode,"Graph")==0)
wavList = TraceNameList("",";",1)
wavList = RemoveQuotesFromList(wavList,";")
outCode = "G"
endif
if (cmpstr(listmode,"All")==0)
wavList = WaveList("*",";","")
outCode = "A"
endif
maxWaves = NumItemsInList (wavList, ";")
//
// Find out what operation we're doing.
//
controlInfo popOp
waveOp = S_value
if (cmpstr(waveOp,"Wave Arithmetic")==0)
controlInfo pop2ndWave; secondWave = S_value
if (cmpstr(secondWave,"NONE")!=0)
wave w2 = $secondWave
duplicate w2, w2Scaled
endif
controlInfo setConstant; arithK = V_Value
controlInfo popArithOp; arithOp = S_value
ControlInfo chkScale2Pk
bScaleWave2 = V_value
// 0 if no, 1 if yes
ControlInfo chkNewWaves
// 0 if no, 1 if yes
bNewFiles = V_value
ControlInfo chkDisplay
// 0 if no, 1 if yes
bDisplay = V_value
endif
// Enter into log
if ((cmpstr(currNotebk,"none")!=0)%&(cmpstr(currNotebk,"")!=0))
// executes if NOT "none" and not null string
nstatus = notes(currNotebk,"text",waveOp)
// log the operation
nstatus = notes(currNotebk,"list",wavList)
// and the wave list into the current notebook
endif
//
// Error check to make sure the wave list exists and the cursors arepresent (unless we are just averaging)
//
If ((cmpstr(waveOp,"Average")!= 0) %& (cmpstr(waveOp,"Concatenate")!= 0)) // if not avg or concat
If ((cmpstr(csrwave(a),"")==0) %|(cmpstr(csrwave(b),"")==0)) // if either cursor not ona wave
doAlert 0, "Please make sure both cursors are on the graph"
return iw
endif
endif
//
// We do average separately because we need to accumulate sum and sumof squares
//
if (cmpstr(waveOp,"Average")==0)
wavestr = GetStrFromList(wavlist, 0,";")
duplicate /O /D $wavestr, sumW //accumulate the sum
duplicate /O /D $wavestr, sumSqW
// accumulate the sum of the squares
sumSqW = sumW^2
print "doing averaging on waves: ",wavlist
iw = 1
// since we already did the zeroth wave
Do
wavestr = GetStrFromList(wavlist, iw,";")
if ((strlen(wavestr) == 0)%|(exists(wavestr)!=1))
break
endif
wave w = $wavestr
sumW += w
sumSqW += w^2
iw += 1
while (1)
// NOTE: we are using var = (Sum(X - Xavg)^2)/n-1, not (Sum(X -Xavg)^2)/n, this is the same form used by wavestats
duplicate /O /D sumSqW, varW
duplicate /O/D sumW, avgW
varW = (sumSqW-(sumW^2)/iw)/(iw-1)
duplicate /O /D varW, SDW
SDW = sqrt(varW[p])
avgW = sumW/ iw
// divide by # waves to get average
note avgw, "average of"+wavlist
waveInGraphList = WaveList("*", ";","WIN:")
ipop = FindItemIndexInList("avgW", waveInGraphList, ";")
// the idea here is to automatically set the template wave, the mean waveand the variance wave
// popupMenu popTemplate mode=(ipop)
// popupMenu popTemplate mode=(ipop)
// popupMenu popTemplate mode=(ipop)
doUpdate
appendToGraph avgW
ModifyGraph rgb(avgW)=(0,0,0) // make it black,and thicker line
ModifyGraph lsize(avgW)= 2
Return iw
endif
if (cmpstr(waveOp,"Concatenate")==0)
if (cmpstr(gResName,"")==0) //Checkthat we have an output name
doAlert 0, "Enter the output waveName in the space marked RESULTS BASE NAME"
return iw
endif
ConcatenateWavesInList(gResName, wavlist)
note $gResName wavlist
print "Concatenated ",wavlist,"as",gResName
return iw
endif
//
// The 2nd group of operations use built in fnxns and operations--these operate wave by wave
// First make output names and see what we're doing--convert a bunchf check boxes into flags
//
controlInfo chkAvg; bMean = V_value; controlInfo chkPeak; bPeak =V_value
controlInfo PopPkType
if (V_value==1) //positive peak
pkmode = 1
else
pkmode = -1
endif
controlInfo chkArea; bArea = V_value; controlInfo chkSlope; bslope= V_value
controlInfo chkCell; bCell = V_value; controlInfo chkTest; bTest =V_value
controlInfo chkWave; bWave = V_value; controlInfo chkTime; bTime =V_value
controlInfo chkAmp; bAmp = V_value; controlInfo chkwName; bwName =V_value
controlInfo chkRise; bRise = V_value
controlInfo chkSaveFiles; bSave = V_value
controlInfo chkOverwrite; bOverwrite = V_value
//
// Make the names for the waves holding the results
//
if (cmpstr(gBaseStr,"")==0) // first make surewe know a basename
endif
if (cmpstr(gResName,"")==0) // if we haven'talready entered an output name use the basename
gResName = gBaseStr
endif
if (strlen(gResName) > 13)
gResName = gResName[0,12]
endif
if (bMean)
wstr = gResName + "Mn"+outCode; uwstr = UniqueName(wstr, 1, 0 )
make /D /N=(maxWaves) /O $uwstr; wave /D wMn = $uwstr
endif
if (bPeak)
wstr = gResName + "Pk"+outCode; uwstr = UniqueName(wstr,1, 0 )
make /D/N=(maxWaves) /O $uwstr; wave /D wPk = $uwstr
wstr = gResName + "TTP"+outCode; uwstr = UniqueName(wstr,1, 0 )
make /D/N=(maxWaves) /O $uwstr; wave /D wTTP = $uwstr
endif
if (bArea)
wstr = gResName + "Ar"+outCode; uwstr = UniqueName(wstr,1, 0 )
make /D/N=(maxWaves) /O $uwstr; wave /D wAr = $uwstr
endif
if (bSlope)
wstr = gResName + "Sl"+outCode; uwstr = UniqueName(wstr,1, 0 )
make /D /N=(maxWaves) /O $uwstr; wave /D wSl = $uwstr
endif
if (bRise)
wstr = gResName + "Ri"+outCode; uwstr = UniqueName(wstr,1, 0 )
make /D /N=(maxWaves) /O $uwstr; wave /D wRi = $uwstr
endif
if (bCell)
wstr = gResName + "Cell"+outCode; uwstr = UniqueName(wstr,1, 0 )
make /D /N=(maxWaves) /O $uwstr; wave /D wCell = $uwstr
endif
if (bTest)
wstr = gResName + "Test"+outCode; uwstr = UniqueName(wstr,1, 0 )
make /D /N=(maxWaves) /O $uwstr; wave /D wTest = $uwstr
endif
if (bWave)
wstr = gResName + "Wave"+outCode; uwstr = UniqueName(wstr,1, 0 )
make /D /N=(maxWaves) /O $uwstr; wave /D wWave = $uwstr
endif
if (bTime)
wstr = gResName + "Time"+outCode; uwstr = UniqueName(wstr,1, 0 )
make /D /N=(maxWaves) /O $uwstr; wave /D wTime = $uwstr
endif
if (bAmp)
wstr = gResName + "Amp"+outCode; uwstr = UniqueName(wstr,1, 0 )
make /D /N=(maxWaves) /O $uwstr; wave /D wAmp = $uwstr
endif
if (bwName)
wstr = gResName + "wName"+outCode; uwstr =UniqueName(wstr, 1, 0 )
make /T /N=(maxWaves) /O $uwstr; wave /T wwName = $uwstr
endif
controlInfo popTimeUnits
if (cmpstr(S_Value,"Sec")==0)
timeFactor = 1000 //Convert entered times (e.g. pkWidth) to seconds, from ms.
else
// timeunits is "msec", no conversion needed
timeFactor = 1
endif
lcsr = min(xcsr(A),xcsr(B)) // Find thepositions of the left- and right-most cursors
rcsr= max(xcsr(A),xcsr(B))
if (bPeak)
pkwid = gPkWid/timeFactor
controlInfo chkPkTemplate
bUseTemplate=V_Value
if (bUseTemplate)
// If we are finding pks, and using a template, first find tmplate
controlInfo popTemplate
template = S_value
pkloc = findMaxBox($template,pkwid, pkmode, lcsr, rcsr)
templatePk = fAverage($template,pkloc,pkloc+pkwid)
if (pkLoc < 0)
doAlert 0,"Cant find a peak in template wave, try again"
endif
endif
endif
do
wavestr = GetStrFromList(wavlist, iwave,";")
if ((strlen(wavestr) == 0)%|(exists(wavestr)!=1))
break
endif
wave w = $wavestr
notestr = note (w)
print "doing wave #",iwave
do
//switch
if ((cmpstr(waveOp,"Measure")==0) %|(cmpstr(waveOp,"Wave Arithmetic")==0))
if (bwName)
wwName[iwave] = wavestr
endif
//********
if (bMean)
wMn[iwave] = faverage(w,lcsr,rcsr)
endif
//********
if (bPeak)
//
// We use two different methods, depending on the flag bUseTemplate.If true, the peak of the template wave is first
// found (see above) and then this window is used to calculate thepeak for each other wave. If false, we
// find the peak in each wave individually.
//
if (!bUseTemplate)
//if we are not using the template, we
pkloc = findMaxBox(w,pkwid,pkmode, lcsr, rcsr) // must refind the pk
endif
//!!! need to deal with pkloc+/-pkwid/2 overrunning wave bounds
wPk[iwave] = faverage(w,pkloc,pkloc+pkwid)
wTTP[iwave] = pkloc
print "peak for wave",iwave,"=",wPk[iwave]
endif
//*****
if (bArea)
wAr[iwave] = area(w,lcsr,rcsr)
endif
//********
if (bSlope)
duplicate /O /R=(xcsr(A),xcsr(B)) w wd
differentiate wd
wavestats /Q wd
wSl[iwave] =V_avg
//wSl[iwave] =(w(rcsr)-w(lcsr))/(rcsr-lcsr) // in pA or mV / sec.
endif
//********
if (bRise)
/// note we will assume baseline=0
lowlevel = wpk[iwave]*0.1
// compute 10%-90% rise time
highlevel = wpk[iwave]*0.9
findLevel /Q /R=(lcsr,rcsr) w, lowlevel
startRise = V_LevelX
findLevel /Q /R=(lcsr,rcsr) w,highlevel
endRise = V_LevelX
wRi[iwave] = endRise-startRise
//
endif
//
// Extract info from wave name and wave note
//
ibase = strsearch(wavestr,"_", 0)+1 //start ofwave number (can be 1 or 2 digits)
ic = 5
// start of cell number (can be 1 or 2digits)
it = strsearch(wavestr,"T", 6)+1
// start of test number (can be 1-3 digits)
if (bCell)
wCell[iwave] =str2num(wavestr[ic,it-2])
endif
if (bTest)
wTest[iwave] = str2num(wavestr[it,ibase-2])
endif
if (bWave)
if (ibase > 0)
// if base name separator found
wWave[iwave] =str2num(wavestr[ibase, strlen(wavestr)])
endif
endif
if (bTime)
// Currently use the modification date of the wave !DOESNT WORK! sincebaseline subtracting modifies
//-- should really get it from the wave note and convert
wTime[iwave] = modDate(w)
endif
if (bAmp)
wAmp[iwave] = NumberByKey("CELL",notestr)
endif
endif
// ifmeasuring"
//************************************
if (cmpstr(waveOp,"Wave Arithmetic")==0)
// if necessary, scale the second wave; we assume we already found the peakof both waves
if (bScaleWave2)
w2Scaled = w2*(wpk[iwave]/templatePk)
endif
// if we are creating new files, duplicate the input wave
if (bNewFiles)
wstr = gOutBase + wavestr
if (!bOverwrite)
uwstr = UniqueName(wstr, 1, 0 )
else
uwstr = wstr
endif
Duplicate /O w, $uwstr; wave /D wOut = $uwstr
else
wave /D wOut = w
endif
if (cmpstr(arithOp,"(+)")==0)
if (cmpstr(secondWave,"NONE")==0)
wOut = w + arithK
else
wOut = w + w2Scaled
endif
endif
if (cmpstr(arithOp,"(-)")==0)
if (cmpstr(secondWave,"NONE")==0)
wOut = w - arithK
else
wOut = w - w2Scaled
endif
endif
if (cmpstr(arithOp,"(X)")==0)
if (cmpstr(secondWave,"NONE")==0)
wOut = w * arithK
else
wOut = w * w2Scaled
endif
endif
if (cmpstr(arithOp,"(/)")==0)
if (cmpstr(secondWave,"NONE")==0)
wOut = w / arithK
else
wOut = w / w2Scaled
endif
endif
if (!bNewFiles)
w = wOut
else
// i f we are generating new files,
if (bSave)
// then, if requested, save them
Save /P=resPath wOut
endif
if (bDisplay)
// if requested display the new waves
if(cmpstr(secondWave,"NONE")==0) //could append something to graphindicating arithk
display w,wOut
noteText=uwstr+"="+wavestr+arithOp+num2str(arithK)
else
display w,wOut,w2
noteText=uwstr+"="+wavestr+arithOp+secondWave
endif
TextBox/N=graphNote noteText
endif
endif
break
endif
//********
if (cmpstr(waveOp,"Baseline Subtract")==0)
baseval = faverage(w,xcsr(A),xcsr(B))
w -= baseval
// need to set the wave note baseline
notestr = note (w)
notestr=ReplaceNumberByKey(notestr,"BASELINE",baseval)
note /K w; note w, notestr
break
endif
if (cmpstr(waveOp,"Restore Baseline")==0)
baseval = NumberByKey ("BASELINE",notestr)
w += baseval
// need to set the wave note baseline
notestr= ReplaceNumberByKey(notestr,"BASELINE",0)
note /K w; note w, notestr
break
endif
//********
if (cmpstr(waveOp,"Smooth")==0)
doAlert 0, "Sorry, Smoth not implemented yet"
break
endif
break
while (1)
// switch
iwave += 1
while (1)
// Now display the tables and save the waves
if(cmpstr(WinList("*", ";","WIN:2"),"")==0)
// if there are no tables (type2 windows)
edit
// make a new one, otherwise things areappended to top table
endif
if (bwName)
Redimension/N=(iwave) wwName; appendtotable wwName.d
if (bSave)
Save /P=resPath wwName
endif
endif
if (bMean)
Redimension/N=(iwave) wMn; appendtotable wMn.d
if (bSave)
Save /P=resPath wMn
endif
endif
if (bPeak)
Redimension/N=(iwave) wPk; appendtotable wPk.d
Redimension/N=(iwave) wTTP; appendtotable wTTP.d
if (bSave)
Save /P=resPath wPk
Save /P=resPath wTTP
endif
endif
if (bArea)
Redimension/N=(iwave) wAr; appendtotable wAr.d
if (bSave)
Save /P=resPath wAr
endif
endif
if (bSlope)
Redimension/N=(iwave) wSl; appendtotable wSl.d
if (bSave)
Save /P=resPath wSl
endif
endif
if (bRise)
Redimension/N=(iwave) wRi; appendtotable wRi.d
if (bSave)
Save /P=resPath wRi
endif
endif
if (bCell)
Redimension/N=(iwave) wCell; appendtotable wCell.d
if (bSave)
Save /P=resPath wCell
endif
endif
if (bTest)
Redimension/N=(iwave) wTest; appendtotable wTest.d
if (bSave)
Save /P=resPath wTest
endif
endif
if (bWave)
Redimension/N=(iwave) wWave; appendtotable wWave.d
if (bSave)
Save /P=resPath wWave
endif
endif
if (bAmp)
Redimension/N=(iwave) wAmp; appendtotable wAmp.d
if (bSave)
Save /P=resPath wAmp
endif
endif
if (bTime)
Redimension/N=(iwave) wTime; appendtotable wTime.d
if (bSave)
Save /P=resPath wTime
endif
endif
// get the name of the current table
tabName = WinName(0,2) //returns the name of the top table
// Enter into log
if ((cmpstr(currNotebk,"none")!=0)%&(cmpstr(currNotebk,"")!=0))
// executes if NOT "none" and not null string
// nstatus = notes(currNotebk,"object",tabName)
// log the table into the current notebook
endif
//* this is currently disabled, what we should do is have a button (or menuitem) that allows copying a table, graph etc.
//* to the notebook
//doAlert 0,"have I hit the error yet"
Return 0
End
//*******************************************************************
Function chkOverWriteWave(wstr)
String wstr
if (exists(wstr))
doAlert 2,"This wave exists, do you wish to overwrite its contents?"
if (V_Flag > 1) //no=2 or cancel=3 was selected
abort "Use the results basename control to create a new name for the results wave"
endif
endif
end
//*******************************************************************
Function MoveCrsr(ctrlName) : ButtonControl
String ctrlName
NVAR gMoveInc = gMoveInc
variable curposA, curposB
curposA = xcsr(A)
curposB = xcsr (B)
if (cmpstr(ctrlName,"btnMoveleft") == 0) // move left
curposA -= gMoveInc
curposB -= gMoveInc
else // move right
curposA += gMoveInc
curposB += gMoveInc
endif
Cursor A, $CsrWave (A), curposA
Cursor B, $CsrWave (B), curposB
End
//*******************************************************************
Function getInc(ctrlName) : ButtonControl
String ctrlName
NVAR gMoveInc = gMoveInc
gMoveInc = abs(xcsr(A)-xcsr(B))
End
//*******************************************************************
Function LoadIgorBin(ctrlName) : ButtonControl
String ctrlName
//****************************************************************
//*
//*This routine loads all of the igor binary waves in a user selectedfolder. This is used by
//* other routines in MeasureWaves and in DetectMinis
//*
//***************************************************************
string fList, currFile, filpath, dataPathStr, currNotebk
variable filenum=0, istrt = 0, fvar, ipos, nstatus
controlInfo /W=analysisparams popNotebook
currNotebk = S_Value
//abb, didn't change but will sometimes present problems
Open /D/M="To select this folder, select any file" /R/T="IGBW" fvar
filpath = S_fileName
if (cmpstr(filpath,"")==0) //user canceled
abort
endif
do
ipos = strsearch(filpath,":",istrt)
if (ipos != -1)
istrt = ipos+1
else
break
endif
while (1)
dataPathStr = filpath[0,istrt-2] // istrtcurrently points to character after last colon
NewPath /O dataPath, dataPathStr
//abb, didn't change but will sometimes present problems
fList = IndexedFile(dataPath,-1,".IBW") // gets a list of all wavesin folder
do
currFile = GetStrFromList(fList,filenum,";")
if (strlen(currFile) == 0)
break
endif
filenum += 1
loadWave /P=dataPath /Q /O currFile
while (1)
if ((cmpstr(currNotebk,"none")!=0)%&(cmpstr(currNotebk,"")!=0))
// executes if NOT "none" and not null string
nstatus = notes(currNotebk,"text","opening files from"+dataPathStr) // write the data folder into the current notebook
nstatus = notes(currNotebk,"list",fList)
// write the file list into the current notebook
endif
End
//*******************************************************************
Macro InitMeasure ()
print "Initializing..."
PauseUpdate; Silent 1
Variable /G gPkWid = 0.2, gWaveNum
variable /G gMoveInc = .1
string /G g1To99 = "01;02;03;04;05;06;07;08;09;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30;31;32;33;34;35;36;37;38;39;40;41;42;43;44;45;46;47;48;49;50;51;52;53;54;55;56;57;58;59;60;61;62;63;64;65;66;67;68;69;70;71;72;73;74;75;76;77;78;79;80;81;82;83;84;85;86;87;88;89;90;91;92;93;93;95;96;97;98;99"
String /G gBaseNameSep = "_", gBaseStr="", gOutBase="noise", gCurrWave
String /G gMeasFile = "Junk", gResName = "", gResPath = "", gWList=WaveList("*", ";", "")
analysisparams()
// analysisChooserPan()
waveTablePan()
EndMacro
//*******************************************************************
Function findMaxBox(w,pkwid, pkmode, lcsr, rcsr)
//
// Returns the BEGINNING of the maximum pkwid length period in w
// between lcsr and rcsr-pkwid.
wave w
variable pkwid // in sec, or msec
//appropriate to the scaling of w
variable pkmode, lcsr, rcsr // lcsr and rcsr are also
//in X values
variable strtx, endx, pkloc
variable /G gPk_Value
strtX = lcsr
endX = rcsr-pkwid
Duplicate /D /O /R=(strtx,endX) w, wdup
wdup = faverage(w,X,X+pkwid)
//display w,wdup
//doUpdate
WaveStats /Q wdup
if (pkmode==1) // Positive peaks, look for max
pkloc = V_MaxLoc
gPk_Value = V_Max
else // Negative peaks, look formin
pkloc = V_MinLoc
gPk_Value = V_Min
endif
Return pkloc
End
//*******************************************************************************
Function callLoadAndAvg(ctrl) : buttonControl
string ctrl
variable bSaveElsewhere, bDisplay
doAlert 2,"do you wish to save the results in the data folders?"
if (V_flag==3)
abort
else
bSaveElsewhere = v_Flag - 1
endif
doAlert 2,"do you wish to display the waves as you go?"
if (V_flag==3)
abort
else
bDisplay = (2-v_flag) // turns 1=yes, 2=no to 1 = yes, 0 = no
endif
loadAndAvg(bSaveElsewhere,bDisplay)
End
|*******************************************************************************
*
Function loadAndAvg(bSaveElsewhere,bDisplay)
variable bSaveElsewhere // 1: prompt for a separate
//folder to save results in, 0: store in parent folder
variable bDisplay // 0: dontdisplay, 1: display and allow abort
//
// This routine loads all of the igor binary files in each folderwithin a chosen folder, calculates the mean and SEM waves
// writes these waves and kills the loaded waves.
//
string fList, currFile, currFolder, currFolderName
string parentFolderStr, oldparentFolderStr="",wavestr
string avgWstr, semWstr, gName, resultsPathStr
variable ifolder, istrt, fvar, iw, semFactor,saveMode, err
if (bSaveElsewhere==1)
// save to separateresults folder
newPath /O/M="Select or create a folder for results" resultsPath
pathInfo resultsPath
resultsPathStr = S_path
endif
do
KillWaves/A/Z
NewPath /M="select a folder of folders to average"/O parentFolder
pathInfo parentFolder
parentFolderStr = S_Path
if (cmpstr(parentFolderStr,oldparentFolderStr)==0)
// user canceled
abort "aborting as requested"
else
oldparentFolderStr = parentFolderStr
endif
if (bSaveElsewhere==0)
// save results within averages folder inparent folder
newPath /O/C resultsPath, parentFolderStr+"AvgAndSEM:"
else
newPath /O/C resultsPath,resultsPathStr+parentFolderStr
endif
pathInfo resultsPath
resultsPathStr = S_path
ifolder = 0
do
// loopthru the folders in the parent folder
currFolder = IndexedDir(parentFolder,iFolder, 1)
// this is the full path
currFolderName = IndexedDir(parentFolder,iFolder,0) // this is just the folder name
if (strlen(currFolder) == 0)
break
// No more folders
endif
if((cmpstr("AvgAndSEM",currFolderName)!=0)%&(cmpstr("junk",currFolderName)!=0))
newPath /O/Q dataPath,currFolder
avgWstr =cleanUpName("avg"+currFolderName,0) //use cleaned up foldername for avg and sem wave names
semWstr = cleanUpName("sem"+currFolderName,0)
fList = IndexedFile(dataPath,-1,"IGBW")
//gets a list of all waves in folder
currFile = GetStrFromList(flist, 0,";")
// get the first wave (so we can make avg,sem waves)
iw = 1
// the waveounter starts at 1 because we got the first (zeroth)
print currFile
loadWave /P=dataPath /Q /O currFile
wavestr = GetStrFromList(S_waveNames, 0,";")
wave currw = $wavestr
duplicate /O currw, sumW, sumSqW // accumulate the sum andsum of the squares
duplicate /O currw, varW, $semWstr; wave semW = $semWstr
duplicate /O currw, $avgWstr; wave avgW =$avgwStr
sumSqW = currw^2
// NOTE: we are using var = (Sum(X - Xavg)^2)/n-1, not (Sum(X -Xavg)^2)/n, this is the same form used by wavestats
if (bDisplay)
Display /W=(5,42,750,431) currw as avgWstr
doWindow /C avgGraph
endif
do
// loop through the waves in this folder
//print "currw=",currw[0],"sumW=",sumW[0],"sumSqW=",sumSqW[0]
currFile =GetStrFromList(fList,iw,";")
if (strlen(currFile) == 0)
// no more waves left
break
else
iw += 1
print currFile
endif
loadWave /P=dataPath /Q /O currFile
wavestr =GetStrFromList(S_waveNames, 0,";")
wave currw = $wavestr
if (bDisplay)
appendToGraph currw
doUpdate
endif
duplicate currw,sqw
// sumW += currw
FastOp sumW = sumW + currw // these fastops replace the statements above them
// sumSqW += currw^2
fastOp sqw = currw*currw
FastOp sumSqW = sumSqW + sqw
killwaves /Z currw,sqW
while (1) // while there arestill waves in the folder
varW = (sumSqW-(sumW^2)/iw)/(iw-1)
semFactor = sqrt(iw)
semW = sqrt(varW[p])/semFactor
avgW = sumW/ iw
// divide by # waves to get average
//print "dividing by",iw
//edit varW, semW, avgW, sumSqW
if (bDisplay)
appendToGraph avgW
ModifyGraph rgb ($avgwStr)=(0,0,0)
endif
doUpdate
doAlert 1, "Say no to abort, yes to keep going"
if (V_Flag==2)
abort "aborting"
endif
note avgw, "average of"+flist
note semw, "SEM of"+flist
save /O/P=resultspath avgw
save /O/P=resultspath semw
dowindow /K avgGraph
KillWaves/A/Z
endif
// if this isnt a junk or results folder
iFolder += 1
while (1)
// while there are still folders in theparent folder
while (1)
End
//*******************************************************************************
//******************************************************************************
Function KSstat (inw1,inw2,pVal)
//
// Performs a Komogoroff-Smirnoff test for homogeneity on two waves
// These are first copied, so that messing them up is ok.
//
wave inw1,inw2
variable pVal // this is an index into the array of pVals
variable F1, F2, Fmax, ialpha, dalpha, rejectSame, w2Index
duplicate /O inw1, w1
duplicate /O inw2, w2
sort w1, w1
sort w2, w2
variable n1 = numpnts(w1); variable n2 = numpnts(w2)
//print "#points=",n1,n2,"for waves",nameOfWave(w1),nameOfWave(w2)
variable k = 0
Make /O /N=(n1+n2) Fdiff
do
F1 = (k+1)/n1
// add one to convert from zero-based to one-based
w2Index = binarySearch(w2,w1[k]) //find the # of values of w2 <= w1[k]
do
if (w2Index == -1)
// if no values in w2 are small enough
F2 = 0
break
endif
if (w2Index == -2)
// if no values in w2 are big enough
F2 = 1
break
endif
F2 = (w2Index+1)/ n2
// w2Index must be >= 0
break
while (1)
//print "F1=",F1," F2=",F2
Fdiff[k] = abs(F1-F2)
k+=1
while (k<n1)
if (w2Index+1 < n2)
w2Index = max(0,w2Index)
do
// if there are more values of w2
Fdiff[k] = 1-((k+1)/n2) //F1 = 1 since all values of w1 are less
k+=1
w2Index+=1
while (w2Index<n2)
endif
WaveStats /Q /R=[0,k-1] Fdiff
Fmax = V_max
make /O kAlpha = {1.07,1.14,1.22,1.36,1.63,1.95}
// These correspond to p = .2, .15, .1, .05, .01, .001
make /O alphas = {0.2, 0.15, 0.1, 0.05, 0.01, 0.001}
ialpha = alphas(pVal-1)
print "using p-value of ",ialpha
if ((n1+n2)>35)
// the approx. is ok, see Lothar Sachs, Applied Statistics
dAlpha = kAlpha[ialpha]*sqrt((n1+n2)/(n1*n2)) //QA 276 .S213 1984 pp 290, 702.
else
doAlert 0,"sorry only implemented for N1+N2 > 35"
endif
Make /O/N=(20,20) KS
if (Fmax >=dAlpha)
rejectSame = 1
else
rejectSame = 0
endif
return rejectSame
End
|*******************************************************************************
*
Window statpan() : Panel
PauseUpdate; Silent 1 | building window...
NewPanel /W=(314,130,701,452)
ShowTools
PopupMenu popWave1,pos={1,5},size={124,19},title="WAVE1"
PopupMenu popWave1,mode=4,value= #"WaveList(\"*\", \";\", \"\")"
PopupMenu popWave2,pos={3,30},size={121,19},title="WAVE2"
PopupMenu popWave2,mode=1,value= #"WaveList(\"*\", \";\", \"\")"
Button
doKS,pos={8,102},size={167,28},proc=doStats,title="Kolmogoroff-Smirnoff"
PopupMenu popTail,pos={173,65},size={97,19}
PopupMenu popTail,mode=2,value= #"\"one tailed; two tailed\""
Button
describe,pos={136,14},size={117,26},proc=ShowDescriptions,title="Test
Descriptions"
PopupMenu popP,pos={1,67},size={160,19},title="criterion p value"
PopupMenu popP,mode=1,value= #"\"0.2;0.15;0.1;0.05;0.01;0.001\""
Button doT,pos={8,137},size={167,28},proc=doStats,title="T test"
Button doF,pos={7,171},size={167,28},proc=doStats,title="F test"
PopupMenu poptType,pos={184,143},size={149,19}
PopupMenu poptType,mode=2,value= #"\"expect equal means; unequal
variances; paired\""
Button doChi,pos={6,205},size={167,28},proc=doStats,title="Chi test"
Button
doPearson,pos={5,240},size={167,28},proc=doStats,title="Linear Correlation"
EndMacro
Function ShowDescriptions (ctrlName) : ButtonControl
String ctrlName
End