areaxy

I'm trying to figure out how to use the areaxy function to generate a list of values between a single x-series (time) and 1,000 different y-series. I only have 6 time points and a corresponding number of y-values. Using the print areaxy command, I can get the area values, however, I don't want to manually do this 1,000 times. How can I import the data sets from Excel into Igor, have it automatically calculate the areas and generate a new wave containing those values? Can anybody help.
Thanks,
Mark
mkeller3 wrote:
I'm trying to figure out how to use the areaxy function to generate a list of values between a single x-series (time) and 1,000 different y-series.


I have posted a snippet that does the area work here. Copy and paste it to your procedure window. Read the comments to see how it works. You will need to find a way to come up with a list of your 1000 Y wave names. If they are named systematically then you can use WaveList as shown in the example.

mkeller3 wrote:
How can I import the data sets from Excel into Igor, have it automatically calculate the areas and generate a new wave containing those values?


You can load Excel data using the XLLoadWave operation. Execute this:
DisplayHelpTopic "XLLoadWave XOP"

For a discussion of loading multiple waves from a user-defined function:
DisplayHelpTopic "Loading Waves Using Igor Procedures"

You will have to modify the procedures shown there to use XLLoadWave instead of the LoadWave operation and will no doubt need to make other modifications.


[Mark has a table where column 0 is a wave containing x values, and the other columns (about 500 of them) contain Y values. He want the average of those Y values using the X wave to provide X coordinates, all of those averages in one wave.]

Here's the macro and function I came up with:

#pragma rtGlobals=1     // Use modern global access method.

Macro AreaXYOfTableXinFirstCol(outputWaveName, showResultInTable)
    String outputWaveName="AreaOut"
    Variable showResultInTable= 1   // 1 == yes, 2 == No
    Prompt outputWaveName, "Choose name for output wave:"
    Prompt showResultInTable, "Show result in new table?",popup,"Yes;No;"
   
    String tableName= WinName(0,2)
    if( strlen(tableName) == 0 )
        DoAlert 0, "Expected a table to read waves from"
        return
    endif
   
    String pathToWave= fAreaXYOfTable(tableName,outputWaveName)
    if( strlen(pathToWave) && showResultInTable == 1 )
        Edit $pathToWave
    endif
End

Function/S fAreaXYOfTable(tableName,outputWaveName)
    String tableName,outputWaveName
   
    WAVE/Z wx= WaveRefIndexed("Table0",0,1)     // first wave contains X values

    if( !WaveExists(wx) )
        DoAlert 0, "Expected wave in first column of table "+tableName
        return ""   // failure
    endif
    // Figure out how many other waves are in the table
    String ListOfAllWaves= WaveList("*", ";", "WIN:"+tableName)
    Variable numOfYWaves= ItemsInList(ListOfAllWaves) -1
    if( numOfYWaves < 1 )
        DoAlert 0, "Expected wave in second and following columns of table "+tableName
        return ""   // failure
    endif
   
    WAVE output= $outputWaveName
    if( WaveExists(output) )
        DoAlert 1, "Wave "+outputWaveName+" exists. Overwrite?"
        if( V_Flag != 1 )
            return GetWavesDataFolder(output,2)
        endif
    endif
    Make/O/N=(numOfYWaves) $outputWaveName
    WAVE output= $outputWaveName
    Variable index= 1   // skip 0, that's X
    do
        WAVE/Z wy= WaveRefIndexed("Table0",index,1)
        if( !WaveExists(wy) )
            DoAlert 0, "Expected wave in column "+num2istr(index)+" of table "+tableName
            break
        endif
        if( WaveType(wy,1) != 1 )
            DoAlert 0, "Expected numeric wave in column "+num2istr(index)+" of table "+tableName
            break
        endif
        Variable theArea=areaxy(wx,wy)
        output[index-1] = theArea
        index += 1
    while( index <= numOfYWaves )

    return GetWavesDataFolder(output,2)
End



--Jim Prouty
Software Engineer, WaveMetrics, Inc.