Igor Procedures - if statements and variable creation

I am trying to write an Igor Procedure for a project that I am working on, but am having some trouble with the if statements. For the project I use the Multi Peak Fit tool to fit Gaussian curves to some data. Then through a series of Igor procedures I calculate the value of the Gaussian and write those values to a csv file. I have working procedures to do this. However in order to write multiple waves to the same csv file I either need to know that all the names fit a certain pattern or I need to type in the full path to each wave. For example: I expect that each csv file will contain 6 waves with a defined naming convention.

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>
In a function, variables are defined at compile time and used at run time.

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