Copy wave and paste as new wave with arithmatic option
supra
I wanted to have a menu for "wave copy" from a existed table and then it will be pasted as a "new wave" in the same table where "new wave" = "old wave" +-x/ "new wave" and I should have GUI to select +,-,x, or /. Can anybody tell me
a) How I can add checkboxes in the GUI to select +-x/ .
b) How I can keep the GUI panel still visible even after I click "ok" and a option to "Undo" the operation that I have done.
#pragma rtGlobals=1 // Use modern global access method.
Menu "Column Math"
"Column MathA/1", copy22(0)
End
Function copy22(AorB)
Variable AorB // 0 for A, 1 for B
String tableName = WinName(0, 2,1)
if (strlen(tableName) == 0)
Abort "There are no tabels"
endif
GetSelection table, $tableName, 1 //Get selection row and column indices
Variable startColumn = V_startCol //Index of first selected column
Wave y2 = WaveRefindexed(tableName, startColumn, 1)
Duplicate/O y2, wave0_y2
Variable term=1
Prompt term, "Enter parameter: " // Set prompt for XRange param
DoPrompt "Enter parameter", term
if (V_Flag)
return -1 // User canceled
endif
wave0_y2 = wave0_y2 + term
AppendToTable wave0_y2
End
Menu "Column Math"
"Column MathA/1", copy22(0)
End
Function copy22(AorB)
Variable AorB // 0 for A, 1 for B
String tableName = WinName(0, 2,1)
if (strlen(tableName) == 0)
Abort "There are no tabels"
endif
GetSelection table, $tableName, 1 //Get selection row and column indices
Variable startColumn = V_startCol //Index of first selected column
Wave y2 = WaveRefindexed(tableName, startColumn, 1)
Duplicate/O y2, wave0_y2
Variable term=1
Prompt term, "Enter parameter: " // Set prompt for XRange param
DoPrompt "Enter parameter", term
if (V_Flag)
return -1 // User canceled
endif
wave0_y2 = wave0_y2 + term
AppendToTable wave0_y2
End
Have you looked at "Analysis -> Packages -> Wave Arithmetic" and the corresponding ipf, if this could be of any use?
May 16, 2012 at 12:56 am - Permalink
In regards to making a GUI, what you want is NewPanel.... not a prompt. Your GUI (Panel) would need the following:
Popupmenu, or Listbox, to select wave of interest
SetVariable to enter the X value
Checkboxes for Add, Subtract, Divide, etc.
Button to perform operation.
All of these are described in detail in the Manual.
May 16, 2012 at 06:22 am - Permalink
How should I do ..Can anybody help me ?
Function CheckProc_4(cba) : CheckBoxControl
STRUCT WMCheckboxAction &cba
switch( cba.eventCode )
case 2: // mouse up
Variable checked = cba.checked
break
case -1: // control being killed
break
endswitch
return 0
End
Function CheckProc_5(cba) : CheckBoxControl
STRUCT WMCheckboxAction &cba
switch( cba.eventCode )
case 2: // mouse up
Variable checked = cba.checked
break
case -1: // control being killed
break
endswitch
return 0
End
Function ButtonProc_1(ba) : ButtonControl
STRUCT WMButtonAction &ba
switch( ba.eventCode )
case 2: // mouse up
// click code here
break
case -1: // control being killed
break
endswitch
return 0
End
//Panel End Here
May 16, 2012 at 01:24 pm - Permalink
A typical control panel to do something like this would have various controls to set up the conditions for the action you want (your checkboxes, etc.) and a button labelled "Apply" or "Do It" or "OK" or something along those lines. The action procedure for that button would then use ControlInfo to read the state of each of the controls in the panel, and perform the action as specified by all the control settings.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
May 16, 2012 at 02:07 pm - Permalink
I tried to do something...but I have following problems
a) I tried to use the panel creation function
DoMyInputPanel()
inside main calculation functioncopy22(AorB)
and it gives error.a) I dont know how to define a procedure from a function ...I tried with the following but dont know whether it is logical to do it
copy22(0)
End
Then in the button click procedure
Button button0,proc=CopySum, title="OK"
it gives a error and says "even macro should have paranthesis".
(c) Also
wave0_y2 = wave0_y2 + term1
gives a error about Global variable..and does not workMain code
-------------
"Column MathA/1", copy22(0)
End
Proc CopySum
copy22(0)
End
Function DoMyInputPanel()
// DoWindow/K SumPanel
NewPanel /W=(150,50,358,239)
DrawText 33,23,"Enter data"
Variable/G term1=10
SetVariable setvar0,pos={27,49},size={126,17},limits={-Inf,Inf,1}
SetVariable setvar0,value=term1
Button button0,pos={52,120},size={92,20}
Button button0,proc=CopySum, title="OK"
End
Function copy22(AorB)
DoMyInputPanel()
Variable AorB // 0 for A, 1 for B
String tableName = WinName(0, 2,1)
if (strlen(tableName) == 0)
Abort "There are no tabels"
endif
GetSelection table, $tableName, 1 //Get selection row and column indices
Variable startColumn = V_startCol //Index of first selected column
Wave y2 = WaveRefindexed(tableName, startColumn, 1)
Duplicate/O y2, wave0_y2
wave0_y2 = wave0_y2 + term1
AppendToTable wave0_y2
End
May 17, 2012 at 10:52 am - Permalink
In general, "it gives error" isn't helpful. I copied your code into Igor and ran it- the error is "parameter not declared". That is because you put the call to DoMyInputPanel() before the declaration of AorB. Input parameters must be declared before anything else.
When I fixed that, there is still an error: term1 is never declared. It looks like the code isn't finished yet.
The correct way to do that would be "Proc CopySum()", but you don't want to do that. If you double-click the button (the panel must be in draw mode: Panel->Show Tools) you will get a Button Dialog. Click the New button next to the Procedure entry, a new dialog will appear with the skeleton of a button action procedure in correct form. Don't change the inputs to the skeleton function since action procedures must have the correct form for a given type of control. Now fill in the appropriate code inside the skeleton, like a call to your function copy22().
BUT- remove the call to DoMyInputPanel(). By the time the button is clicked, the panel already exists.
I mentioned above that term1 is never defined. You need to tell Igor what kind of object is in term1, make sure it exists before the function runs, and has valid contents.
Don't give up. I know it's being confusing and taking a lot of tries to get this going. But you're learning a lot, and the next time it will be a little easier.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
May 17, 2012 at 12:19 pm - Permalink
Your commands to create the panel look good. In regards to the button proc, change CopySum to the following.
String Control Name
//Enter code here that will do your duplication and math
End
While you do declare term1 to be a global variable, the other functions need to know what it is. Whenever term1 is used in another function of your procedure, it needs to be declared using
May 17, 2012 at 12:41 pm - Permalink
wave0_y2 = wave0_y2 + term1
accordingly i,e
wave0_y2 = wave0_y2 - term1
etc. Can you help me on that issue ?#pragma rtGlobals=1 // Use modern global access method.
NVAR term1= root:term1
Menu "Column Math"
"Column MathA/1", Panel0()
End
Window Panel0() : Panel
PauseUpdate; Silent 1
NewPanel /W=(150,50,358,239)
DrawText 33,23,"Enter data"
Variable/G term1=10
SetVariable setvar0,pos={27,49},size={126,17},limits={-Inf,Inf,1}
SetVariable setvar0,value=term1
Button button0, pos={52,110},size={92,20}, proc=OkButton, title="OK"
CheckBox Check1,pos={40,80},size={39,14},title="+",value= 1
CheckBox Check2,pos={80,80},size={39,14},title="-",value= 0
CheckBox Check3,pos={120,80},size={39,14},title="x",value= 0
CheckBox Check4,pos={160,80},size={39,14},title="/",value= 0
EndMacro
Function OkButton(cntl) : ButtonControl
String cntl
Button $cntl
copy22(0)
End
Function copy22(AorB)
Variable AorB // 0 for A, 1 for B
NVAR term1
String tableName = WinName(0, 2,1)
if (strlen(tableName) == 0)
Abort "There are no tabels"
endif
GetSelection table, $tableName, 1 //Get selection row and column indices
Variable startColumn = V_startCol //Index of first selected column
Wave y2 = WaveRefindexed(tableName, startColumn, 1)
Duplicate/O y2, wave0_y2
wave0_y2 = wave0_y2 + term1
AppendToTable wave0_y2
End
May 17, 2012 at 02:28 pm - Permalink
You don't need a checkbox action procedure. You just need to use ControlInfo to read the state of the checkbox, then make decisions based on that.
There is no simple way to substitute the right operation into your expression at run-time. You must have a series of if statements to choose the right expression. Something like this:
wave0_y2 += term1
elseif (check2)
wave0_y2 -= term1
elseif (check3)
wave0_y2 *= term1
else
wave0_y2 /= term1
endif
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
May 17, 2012 at 05:12 pm - Permalink
controls Check1, Check2 etc are not defined inside Function copy22(AorB). How to access those control values inside the Function ?
Variable AorB // 0 for A, 1 for B
NVAR term1
String tableName = WinName(0, 2,1)
if (strlen(tableName) == 0)
Abort "There are no tabels"
endif
GetSelection table, $tableName, 1 //Get selection row and column indices
Variable startColumn = V_startCol //Index of first selected column
Wave y2 = WaveRefindexed(tableName, startColumn, 1)
Duplicate/O y2, wave0_y2
if (check1)
wave0_y2 += term1
elseif (check2)
wave0_y2 -= term1
elseif (check3)
wave0_y2 *= term1
else
wave0_y2 /= term1
endif
AppendToTable wave0_y2
End
May 17, 2012 at 08:25 pm - Permalink
Use the ControlInfo operation.
May 17, 2012 at 10:39 pm - Permalink
May 18, 2012 at 06:10 am - Permalink
I really need little bit more help...I didnt find any example of controlinfo specially how to use it in loops...if I declare something like
it does not give any error ..but I cant use such condition inside the loop i,e
wave0_y2 += term1
elseif (check2)
wave0_y2 -= term1
endif
...as always it gives error..
Can you pl help ?
May 18, 2012 at 09:22 am - Permalink
To learn about Search Igor Files, execute this:
You will want to search procedure files in the Igor Pro folder for ControlInfo.
May 18, 2012 at 10:56 am - Permalink
a) How can I make checkbox tick option to be selected one at a time...means if the user choose * then all other checkbox will not have tick, currntly one can tick in all the boxes.
b) How can I make a random name or better a seqeuntial name for a new wave i,e in "Duplicate/O y2, wave0_y2" how can I make new wave ( wave0_y2) name something combining old wave "y2" and a random number or better a sequence of number like y2_a, y2_b etc.
Menu "Column Math"
"Column MathA/1", Panel0()
End
NVAR term1= root:term1
Window Panel0() : Panel
PauseUpdate; Silent 1
NewPanel /W=(150,50,458,239)
DrawText 33,23,"Enter data"
Variable/G term1=10
SetVariable setvar0,pos={27,49},size={126,17},limits={-Inf,Inf,1}
SetVariable setvar0,value=term1
Button button0, pos={52,110},size={92,20}, proc=OkButton, title="OK"
CheckBox Check1,pos={40,80},size={39,14},title="+",value= 1
CheckBox Check2,pos={80,80},size={39,14},title="-",value= 0
CheckBox Check3,pos={120,80},size={39,14},title="x",value= 0
CheckBox Check4,pos={160,80},size={39,14},title="/",value= 0
EndMacro
Function OkButton(cntl) : ButtonControl
String cntl
Button $cntl
copy22(0)
End
Function copy22(AorB)
Variable AorB // 0 for A, 1 for B
NVAR term1
String tableName = WinName(0, 2,1)
if (strlen(tableName) == 0)
Abort "There are no tabels"
endif
variable randomNUmber = abs(enoise(1))
GetSelection table, $tableName, 1 //Get selection row and column indices
Variable startColumn = V_startCol //Index of first selected column
Wave y2 = WaveRefindexed(tableName, startColumn, 1)
Duplicate/O y2, wave0_y2
Variable Conf1,Conf2, Conf3, Conf4
ControlInfo Check1
Conf1= V_value
ControlInfo Check2
Conf2 = V_value
ControlInfo Check3
Conf3 = V_value
ControlInfo Check4
Conf4 = V_value
if (Conf1)
wave0_y2 += term1
elseif (Conf2)
wave0_y2 -= term1
elseif (Conf3)
wave0_y2 *= term1
else
wave0_y2 /= term1
endif
AppendToTable wave0_y2
End
May 19, 2012 at 07:28 am - Permalink
Your control action procedure needs to uncheck all of the other checkboxes when one of them is checked by the user.
If you implement this behavior (only one checked at a time) I recommend that you give your checkboxes "radio button" appearance. See the Checkbox operation mode keyword.
Try the UniqueName function.
May 19, 2012 at 07:56 pm - Permalink