reading the last point of 300 waves

I want to read 300*7 waves from delimited files and, for some of them, create a new wave consisting of 300 points. For example, LC consists of 300 points, which are the last point of LC_001 through LC_300. LC_nnn is currently 10001 points long. I think I'm almost there, but I haven't succeeded in reading a point from a wave whose name is in a string variable. Here is the current code, where the 2 commented-out lines are causing syntax errors. The tempX variables are just to break things into small steps that are easier to debug.

    NVAR maxWavesIn=root:maxWavesIn;
    SVAR pathName=root:pathName;
    String strNum="";
    String fileName="";
    String wName="";
    Variable tempCount=0;
    Variable tempVar =0;
    Variable countIn=1;
    WAVE LC;
    countIn=1;
    do
        sprintf strNum, "%3.3d", countIn;
        fileName = "TFC." + strNum + ".csv";
        fileName = pathName + fileName;
        LoadWave/J/O/W/A/D/L={0,0,0,0,4} fileName; //read first 4 columns of time course
        LoadWave/J/O/W/A/D/L={0,0,0,24,3} fileName; //read last 3 columns of time course
        wName="LC_" + strNum;
        tempCount = numpnts($wName)-1;
        //tempVar=wName[tempCount];
        //tempVar=$wName[tempCount];
        LC[countIn]=tempVar;
        countIn = countIn+1;
    while (countIn <= maxWavesIn);


Thanks for any comments,
Tom
I (all powerful administrator:) added formatting to format your code as Igor code. See http://www.igorexchange.com/node/3221.

Here is a solution to your issue. The changes are marked with ***.
Function Test()
    NVAR maxWavesIn=root:maxWavesIn;
    SVAR pathName=root:pathName;
    String strNum="";
    String fileName="";
    String wName="";
    Variable tempCount=0;
    Variable tempVar =0;
    Variable countIn=1;
    WAVE LC;
    countIn=1;
    do
        sprintf strNum, "%3.3d", countIn;
        fileName = "TFC." + strNum + ".csv";
        fileName = pathName + fileName;
        LoadWave/J/O/W/A/D/L={0,0,0,0,4} fileName; //read first 4 columns of time course
        LoadWave/J/O/W/A/D/L={0,0,0,24,3} fileName; //read last 3 columns of time course
        wName="LC_" + strNum;
        Wave w = $wName                 // *** Create wave reference
        tempCount = numpnts(w)-1;           // ***
        tempVar=w[tempCount];               // ***
        LC[countIn]=tempVar;
        countIn = countIn+1;
    while (countIn <= maxWavesIn)
End


For details, execute:
DisplayHelpTopic "Accessing Global Variables And Waves"

Instead of using the tempCount and TempVar variables, you can directly enter the value into LC by using [inf-1] to access the last point of a wave, regardless of length.
LC[countIn]=w[inf-1];

Hello Howard,

thanks!! That works beautifully. And, after looking at it in the debugger, I changed it to
        Wave w = $wName                 // *** Create wave reference
        LC[countIn]=w[numpnts(w)-1];            // *** add last point of LC_nnn to LC


Tom
proland wrote:
Instead of using the tempCount and TempVar variables, you can directly enter the value into LC by using [inf-1] to access the last point of a wave, regardless of length.
LC[countIn]=w[inf-1];


inf-1 equals inf.

The technique of using inf to index a wave is not recommended. It will raise an error when running with rtGlobals=3.
hrodstein wrote:

The technique of using inf to index a wave is not recommended. It will raise an error when running with rtGlobals=3.


Thanks for the heads up. As my procedure files have rtGlobas=1 I was not aware of this.