Copy wave and paste as new wave with arithmatic option

Hi
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



Have you looked at "Analysis -> Packages -> Wave Arithmetic" and the corresponding ipf, if this could be of any use?
The wave arithmetic package does this feature with graphs. You should be able to modify this code for tables if you really want to.

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.
Thanks for reply. I indeed tried to make a panel with one "Button"(butto0), Two checkbox ( check0 and check1 : say + and - operation) and one value display ( that does not make code in procedure but visible in panel ..why ? ..but the problem is I dont know how to associate the panel with the procedure. Say the "term" is the value display and if check the first checkbox (check0) it should do "wave0_y2 = wave0_y2 + term"
How should I do ..Can anybody help me ?

// Panel Start Here

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
ValDisplay controls don't have action procedures because they are intended only for display. If you want something like ValDisplay, but user editable, use a SetVariable control.

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
Thanks for replying...

I tried to do something...but I have following problems

a) I tried to use the panel creation function  DoMyInputPanel() inside main calculation function  copy22(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
Proc CopySum
    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 work

Main code
-------------
Menu "Column Math"
      "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
supra wrote:
a) I tried to use the panel creation function  DoMyInputPanel() inside main calculation function  copy22(AorB) and it gives error.

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.
Quote:

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
Proc CopySum
    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".

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.
Quote:

(c) Also  wave0_y2 = wave0_y2 + term1 gives a error about Global variable..and does not work

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
supra wrote:

Menu "Column Math"
      "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


Your commands to create the panel look good. In regards to the button proc, change CopySum to the following.

Function CopySum(ControlName) : ButtonControl
      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

NVAR term1
Thank you for your encouragement. I did able to do most of the thing like the way you said....except I dont know how to choose the chekbox option ( what are the variaable..for checkbox). I mean I nned to choose +-x/ and have to modify  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
supra wrote:
Thank you for your encouragement. I did able to do most of the thing like the way you said....except I dont know how to choose the chekbox option ( what are the variaable..for checkbox). I mean I nned to choose +-x/ and have to modify  wave0_y2 = wave0_y2 + term1
accordingly i,e  wave0_y2 = wave0_y2 - term1 etc. Can you help me on that issue ?

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:
if (check1)
     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
Thank you so much.. now I has a new problem ...
controls Check1, Check2 etc are not defined inside Function copy22(AorB). How to access those control values inside the Function ?

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    
 
 if (check1)
     wave0_y2 += term1
elseif (check2)
     wave0_y2 -= term1
elseif (check3)
     wave0_y2 *= term1
else
     wave0_y2 /= term1
endif
 
AppendToTable wave0_y2
 
     End
Quote:
How to access those control values inside the Function

Use the ControlInfo operation.
Controls don't have to be defined in other functions. Since they exist as part of the panel, ControlInfo can return the information for any control within a panel. For checkboxes, the value will be returned in V_Value (a default variable used by ControlInfo so you don't have to declare this one either). The output for various controls is explained in the Manual.
Hi
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
ControlInfo CheckBox Check1 V_Value =0

it does not give any error ..but I cant use such condition inside the loop i,e
if (check1)
     wave0_y2 += term1
elseif (check2)
     wave0_y2 -= term1
endif

...as always it gives error..
Can you pl help ?

To find examples, choose Help->Search Igor Files to search procedure files in the Igor Pro Folder.

To learn about Search Igor Files, execute this:
DisplayHelpTopic "The Search Igor Files Tab"


You will want to search procedure files in the Igor Pro folder for ControlInfo.
Thanks a lot...Its working now with ControlInfo...thnaks to all of you ....Only I have two small problem...

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.


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


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
     
Quote:
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.


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.

Quote:
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.


Try the UniqueName function.