Replace Waves In Table

//  ShowWavesInTable(tableName, title, waveNames)
//  Used to display a list of waves in a table which may or may not already exist.
//  The listed waves replace any waves already displayed in the table.
//  If the table does not already exist, it is created.
//  If the table does already exist, replaces the currently displayed waves in the table with the listed waves.
static Function ShowWavesInTable(tableName, title, waveNames)
    String tableName
    String title
    String waveNames            // Semicolon-separated list
   
    Variable numNewWaves = ItemsInList(waveNames)
    Variable i
    String name
   
    DoWindow $tableName
    if (V_flag == 0)
        Edit /N=$tableName /W=(25,60,1200,700) /K=3 as title
        for(i=0; i<numNewWaves; i+=1)
            name = StringFromList(i, waveNames)
            AppendToTable /W=$tableName $name
            Wave w = $name
            if (CmpStr(WaveUnits(w,-1),"dat")==0 && WaveType(w)==4)     // Is data wave?
                ModifyTable /W=$tableName format($name)=6               // Date format
            endif
        endfor
        ModifyTable /W=$tableName autosize={1, 0, -1, 0, 0}
    else
        String options = "WIN:" + tableName
        String tableWaveList = WaveList("*", ";", options)          // List of waves already in table
        if (CmpStr(tableWaveList,waveNames) != 0)               // Do nothing if table already contains the right waves in the right order
            Variable numOldWaves = ItemsInList(tableWaveList)
            for(i=0; i<numOldWaves; i+=1)                   // Remove all old waves
                name = StringFromList(i, tableWaveList)
                Wave w = $name
                RemoveFromTable /W=$tableName w.i, w.l, w.d
            endfor
            for(i=0; i<numNewWaves; i+=1)                       // Append all new waves
                name = StringFromList(i, waveNames)
                AppendToTable /W=$tableName $name
                Wave w = $name
                if (CmpStr(WaveUnits(w,-1),"dat")==0 && WaveType(w)==4)     // Is data wave?
                    ModifyTable /W=$tableName format($name)=6               // Date format
                endif
            endfor
            ModifyTable /W=$tableName autosize={1, 0, -1, 0, 0}
        endif  
    endif
End


If you want to use this code as a "ReplaceWave allincdf" for tables, you will need to do something like provide full paths in your wave name list, or otherwise distinguish the list of your waves from the list of waves already in the table, because the

if (CmpStr(tableWaveList,waveNames) != 0)

line will prevent anything from happening if the exisiting wave list and the new wave list match.
>If you want to use this code as a "ReplaceWave allincdf" for tables, you will need to do something like
>provide full paths in your wave name list, or otherwise distinguish the list of your waves from the list of
>waves already in the table, because the
>
>if (CmpStr(tableWaveList,waveNames) != 0)
>
>line will prevent anything from happening if the exisiting wave list and the new wave list match.

That's the intention so that, if you have displayed a wave in the table and the same wave is in the waveNames list, it will be left as is in the table to preserve any formatting changes that were made to the column.

waveNames is assumed to contain simple names of waves in the current data folder. I have not tested it with full paths and would not expect it to work with full paths.

How would you modify this to handle subframe tables?

 

I have a panel hosting a table and I would like to include a popup menu where the user selects a wave for editing.

Andy

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More