Accessing two colum from two table (or two graph) and subtract them and plot a new graph

I have two table and corresponding two graph (2nd column vs 1st column) that I created programmatically (by each time running a procedure file that import data and create a table , does some calculation and plot a graph of 2nd column vs 1st column ). Each table have 2 column with names that also created programmatically (so specially the 1st column=x column can be random like wave0, wave3 etc while the 2nd column name is is based on first column as because I rename so if the first column is wave0 then the 2nd column will be wave0Int etc)

Now what I want to do (programmatically) is

1) Take the 2nd column of first table and subtract it from the 2nd column of 2nd table and make a new column entry in any one of the table and plot the diff wave (2nd columa-2nd column) wrt 1st column of any one of the table.

2) Is there any way to cursor access the 2nd column of 1st table and then hold it in memory and then click on the 2nd column of the 2nd table to get the 2nd column name(wave name) and then subtract that two column (wave) and add it to one of the table and then plot it (diff of two 2nd column wave) wrt the 1st column.

3) Can it be done on the graph itself without accessing the table. Then first I need to add both the graphs in one graph programmatically ?


Is there any function that return the wave name once I click and highlight a column of a table
I thought various ways ...but none of them yet successful for example

I can get the wave name from the graph by WaveRefCursors()

Function
WAVE/Z w = CsrWaveRef(A)
if (!WaveExists(w)) // Cursor is not on any wave.
return NaN
endif
Variable xA = xcsr(A)
Variable xB = xcsr(B)
return xB
End

the question how I hold xb from first graph when I move to next graph.

Then if I can add two graph in one graph then probably I can also have wave reference function to operate on the waves displayed in a graph...I saw this function...then how to add two graph ( drag drop) in one. There is a ipd file in Igor exchange that does it ...but I dont have Igor6.2 ( mine is Igor 6.0 and that ipf file does not work).

Function SmoothWavesInGraph()
String list = TraceNameList("", ";", 1)
String traceName
Variable index = 0
do
traceName = StringFromList(index, list)
if (strlen(traceName) == 0)
break // No more traces.
endif
WAVE w = TraceNameToWaveRef("", traceName)
Smooth 5, w
index += 1
while(1)
End

I would really appreciate if somebody can give me a clue.
You are going down a path that will lead you to having many tables with two waves per table. You may find this cumbersome in the long run. However, the technique in the attached procedure file will allow to you select an A XY pair and a B XY pair from any table, whether the waves are in the same table or not. So it does not lock you in to the one-table-per-XY-pair rule.

The code in the attached procedure file should give you some ideas but it is very simplified. When you try to create a slick user interface, you find that the UI takes far, far, far more time than the actual functional code because validating all of the input and keeping all the data straight is time consuming.

For a fully-worked out example of something similar to what you are doing, choose File->Example Experiments->Analysis->Wave Arithmetic Panel Demo. Read the notebook and do the tutorial. The Wave Arithmetic Panel might do what you need, in which case you won't need to do further programming.


SupraTableUI.ipf
Thank you so much for your reply. I tried to use the code and it seems works great ...but I have some problem also. ( because of the fact that i am pretty ignorant about igor programming)

2) Since I need to select 2 column ( x and Y ) each time ...so after the import data wave get loaded in the table ....and calculations are done ...my table has 3 column ( x1, y1, y2) and 2 graph ( Graph 1=y1 vs x1 and Graph 2:y2 vs x1 ) ..( see Fig attch ) then I have to select manually by cursor the (x1, y2) which are not side by side ....so I thought to swap the position of (x1, y1, y2) to (x1, y2, y1) in Table 1..so that I can select (x1, y2) but dont know how to do it. Other option is just to delete the y1 but then I first have to delete the graph 1 also and I want to still keep them. So how can I swap to have (x1, y1, y2) to (x1, y2, y1) in Table 1 ?

3) also as I am not using x1 at all ..so I thought why not use have option only to select y2 etc ...so I tried ( just removed the x wave save path, waves etc) and then....but it does not give proper y wave ( dont know why ? ) and since I also want to plot dif wave wrt x so I need a x wave ...so I tried to extract x wave from Table 2 ( 2nd data set : Top Table) but fails ..Other options that I used and work is that just to use the xwave from the saved path and use it to plot the "dif" vs xwave. So if I want to use only to select one column and to creat a x wave from top table ...

How usally a certain x wave is extracted from a Table ( Top Table) that has 3 column.. programmatically (using StringFromList(index, list) ?

//--------------------
/ if (numColumnsSelected != 1)
Abort "Select only one Y column"
endif

String yName = StringFromList(1, columnNameList)
yName = RemoveEnding(yName, ".d") // Convert column name to wave name

String yDF = StringFromList(1, dataFolderNameList)
String yPath = yDF + yName

if (AorB == 0)

String/G root:gSupraYWaveAPath=yPath // Save for future use
Printf "Y set to: %s", yPath

else
String/G root:gSupraYWaveBPath = yPath // Save for future use
Printf "Y set to: %s", yPath

endif
End

------------------------------------------------------------------------------------------


3) I am still looking in the Arithmetic panel..but it seems I still I need to learn more and will need more time to incorporate in my code.


table1.jpg
Quote:
I thought to swap the position of (x1, y1, y2) to (x1, y2, y1) in Table 1..so that I can select (x1, y2) but dont know how to do it.


Manually, press the Alt key and drag the column label.

Programmatically you must remove the columns and append them in the right order.

However, I would revise the procedure to use the order that you have. I have attached a revised procedure that does this. Hopefully this will give you an idea of how you might approach this task.
SupraTableUI2.ipf
Thank you so much . I tried various options but eventually used your code more or less intact with small changes as it became the best possible option for the purpose I am looking for. Thank you so much again for your kind help.

I want to ask you another thing. I have a procedure file (testimport1.ipf --attached) that have some parameter variable (lamda, alpha etc ) inside that I need to change time to time depend upon the type of experimental import file.

Is is possible to write a another procedure file that will pass that value /or will modify the values of "lamda" , "alpha" etc in the first procedure file. How can I write a small window where it will allow me to type value of "lamda" and "alpha and whenever I click some button it will pass/modify that value in the first procedure file (testimport1.ipf). { may be will open, pass new values of lamda and alpha and recompile testimport1.ipf to get ready)
Easy, useful for things that hardly ever change, because you have to edit the file:
constant lamda= 803.506 //3508.61 is theoritical value of peak. Changes depeding upon region
constant alpha =652.3 // 652.3 is practical value of peak taken from spectrum. Depend on optical setting and changes often

Then in your code, refer to "lamda" and "alpha" just as if they were variables.

The most obvious thing is to add them as function parameters:
Function LoadAndGraphXYa(fileName, pathName, lamda, alpha)
    String fileName // Name of file to load or "" to get dialog
    String pathName // Name of path or "" to get dialog
    Variable lamda
    Variable alpha

You can change them every time you run the function now. But you have to remember them and type them every time.

If they almost always have the same values, but sometimes you need something a bit different, you could make them optional parameters:
Function LoadAndGraphXYa(fileName, pathName [, lamda, alpha])
    String fileName // Name of file to load or "" to get dialog
    String pathName // Name of path or "" to get dialog
    Variable lamda
    Variable alpha

    if (ParamIsDefault(lamda))
        lambda = 803.506
    endif
    if (ParamIsDefault(alpha))
        alpha = 652.3
    endif

Now, if you simply leave out lambda and alpha they will get default values. If you include values in the function invocation they will override the defaults

Finally, you can create a Simple Input Dialog to make it easy to enter values. You can establish default values for the dialog. Read about Simple Input Dialog:

DisplayHelpTopic "The Simple Input Dialog"

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Thank you so much. Now I am now working on a gui and will come again once I finish it. Then I need to ask you some other problems that I have. Thanks again