Igor Procedures - if statements and variable creation
ddileona
However, sometimes I encounter a situation where there are only 5 waves to write to the csv file (or some number other than 6). In this case I'm stuck with typing out the full path to each wave. This is clearly not an ideal situation for automating a task.
I have tried to delineate different cases using an if statement, but get an error on compile: Name already exists as a variable for wavelist0. I don't understand why this happens because only one instance of wavelist0 will actually be created when running the procedure.
I am new to Igor, but have experience with coding in Matlab and Python.
Can someone explain to me what I'm doing wrong? Thanks.
<br />
String pathname<br />
Variable peaknum<br />
//Variable peaknum<br />
<br />
//SaveWavesDelimited("LISST_PeakFit","LISST_Fits","L2720228_fit.csv","root:Grain_Size;L2720228_01_P0;L2720228_01_P1;L2720228_05_P0;L2720228_05_P1;L2720228_09_P0;L2720228_09_P1",",",1,2)<br />
<br />
<br />
String savefilename = castName + "_fit.csv"<br />
<br />
//Concatenate cast name with other bits to make input to SaveWaves Delimited<br />
if (peaknum==222)<br />
String wavelist0 = "root:Grain_Size;root:" + castName + ":" +castName+ "_01_P0;root:" + castName + ":" +castName+ "_01_P1;root:" + castName + ":" +castName+ "_05_P0;root:" + castName + ":" +castName+ "_05_P1;root:" + castName + ":" +castName+ "_09_P0;root:" + castName + ":" +castName+ "_09_P1"<br />
<br />
<br />
elseif(peaknum==122)<br />
String wavelist0 = "root:Grain_Size;root:" + castName + ":" +castName+ "_01_P0;root:" + castName + ":" +castName+ "_05_P0;root:" + castName + ":" +castName+ "_05_P1;root:" + castName + ":" +castName+ "_09_P0;root:" + castName + ":" +castName+ "_09_P1"<br />
<br />
<br />
elseif(peaknum==212)<br />
String wavelist0 = "root:Grain_Size;root:" + castName + ":" +castName+ "_01_P0;root:" + castName + ":" +castName+ "_01_P1;root:" + castName + ":" +castName+ "_05_P0;root:" + castName + ":" +castName+ "_09_P0;root:" + castName + ":" +castName+ "_09_P1"<br />
<br />
elseif(peaknum==221)<br />
String wavelist0 = "root:Grain_Size;root:" + castName + ":" +castName+ "_01_P0;root:" + castName + ":" +castName+ "_01_P1;root:" + castName + ":" +castName+ "_05_P0;root:" + castName + ":" +castName+ "_05_P1;root:" + castName + ":" +castName+ "_09_P0" <br />
<br />
<br />
endif<br />
<br />
String wavelistFinal = "root:Grain_Size;" + wavelist0 <br />
SaveWavesDelimited(pathname,savefilename, wavelistFinal , ",",1,2)<br />
<br />
<br />
End<br />
<br />
<br />
<br />
<br />
</span>
String pathname<br />
Variable peaknum<br />
//Variable peaknum<br />
<br />
//SaveWavesDelimited("LISST_PeakFit","LISST_Fits","L2720228_fit.csv","root:Grain_Size;L2720228_01_P0;L2720228_01_P1;L2720228_05_P0;L2720228_05_P1;L2720228_09_P0;L2720228_09_P1",",",1,2)<br />
<br />
<br />
String savefilename = castName + "_fit.csv"<br />
<br />
//Concatenate cast name with other bits to make input to SaveWaves Delimited<br />
if (peaknum==222)<br />
String wavelist0 = "root:Grain_Size;root:" + castName + ":" +castName+ "_01_P0;root:" + castName + ":" +castName+ "_01_P1;root:" + castName + ":" +castName+ "_05_P0;root:" + castName + ":" +castName+ "_05_P1;root:" + castName + ":" +castName+ "_09_P0;root:" + castName + ":" +castName+ "_09_P1"<br />
<br />
<br />
elseif(peaknum==122)<br />
String wavelist0 = "root:Grain_Size;root:" + castName + ":" +castName+ "_01_P0;root:" + castName + ":" +castName+ "_05_P0;root:" + castName + ":" +castName+ "_05_P1;root:" + castName + ":" +castName+ "_09_P0;root:" + castName + ":" +castName+ "_09_P1"<br />
<br />
<br />
elseif(peaknum==212)<br />
String wavelist0 = "root:Grain_Size;root:" + castName + ":" +castName+ "_01_P0;root:" + castName + ":" +castName+ "_01_P1;root:" + castName + ":" +castName+ "_05_P0;root:" + castName + ":" +castName+ "_09_P0;root:" + castName + ":" +castName+ "_09_P1"<br />
<br />
elseif(peaknum==221)<br />
String wavelist0 = "root:Grain_Size;root:" + castName + ":" +castName+ "_01_P0;root:" + castName + ":" +castName+ "_01_P1;root:" + castName + ":" +castName+ "_05_P0;root:" + castName + ":" +castName+ "_05_P1;root:" + castName + ":" +castName+ "_09_P0" <br />
<br />
<br />
endif<br />
<br />
String wavelistFinal = "root:Grain_Size;" + wavelist0 <br />
SaveWavesDelimited(pathname,savefilename, wavelistFinal , ",",1,2)<br />
<br />
<br />
End<br />
<br />
<br />
<br />
<br />
</span>
Unlike other languages, there is no scoping so there are four attempts to define the same variable.
Just move the String wavelist0 declaration before the if.
Larry Hutchinson
WaveMetrics
support@WaveMetrics.com
February 1, 2016 at 01:11 pm - Permalink
February 1, 2016 at 02:41 pm - Permalink