take name of old wave and make new one out of it

How do I take the name of the original wave and make a new wave with this name plus a suffix, e.g., compoundA to compoundA_calculated. And then assign A_calculated.

I tried

string a
a=nameofstring (compoundA)
string b
b = a +"_calculated"

Duplicate $a $b

then I tried to use

$b = $a/wave2/wave3*wave4 to assign my $b wave.

but always get an error in "cannot use $ this way in a function".

What is this error? How did it happen? What I should do to achieve my purpose then?

Thank you!
You need to reference the wave.
e.g.

Function RenameIt(w0)
   Wave w0
   String wName, newName
   wName = NameOfWave(w0)
   newName = wName + "_calculated"
   Duplicate/O w0 $newName
   Wave w1 = $newName // this is making a reference to the wave
   w1 = w0 * 10 // or whatever you want to do.
End


Completely untested, but should work if you call with RenameIt(compoundA).
The error arises because Igor doesn't allow $ to be used in an assignment. You have to inform Igor what type those objects "$a" and "$b" are, using this sort of declaration:

wave wa=$a, wb=$b


This can sometimes seem confusing. For example, Igor fully expects the arguments in a Duplicate statement to be waves, so you don't have to declare its arguments, and you can use the $. That is not the case for an assignment, though. Assignments can potentially apply to variables, strings, or waves, so you have to inform the function what type each argument is. The statement above tells Igor, whenever I use "wa", what I really mean is that wave that has the name in string a (at the time of declaration). If the string a changes, and you want wa to change with it, then you have to declare it again.
To do the operation, you then do:

wb = wa/wave2/wave3*wave4


The same thing should go for wave2, wave3, and wave4. That is, they need to be declared as waves for Igor to know how to handle them.
Look up the $ operator in the help.

-mxf
Ah I see. Thank you sjr51 and xufriedman, I had the function pass the compile now. It did confuse me. One thing interesting is that I previously tried declaring the wave like wa, wb, w1 at the same time when I declare other variables/waves/strings right after I start the function, like in

function ()
wave ...
variable ...
string ...
wave wa, wb, w1

.....

and then try to assign $a to wa directly like
wa = $a

but did not pass. It seems the wave reference needs to be immediately ahead of where you use it or want to assign it, declaring the waves up front didn't help. Or maybe I am mixing the function declaration up with wave reference...

But Thanks!
That's not right. You can declare a wave anywhere, but you need to reference a wave the right way.

// this won't work
Wave wa
wa = $a // asking Igor to assign a string to every point of numeric wave
// this will
Wave wa = $a
// whereas this will work
Variable nWaves
nWaves = 12
// or
String wName
wName = "a"

mwpro wrote:
Ah I see. Thank you sjr51 and xufriedman, I had the function pass the compile now. It did confuse me. One thing interesting is that I previously tried declaring the wave like wa, wb, w1 at the same time when I declare other variables/waves/strings right after I start the function, like in

function ()
wave ...
variable ...
string ...
wave wa, wb, w1

.....

and then try to assign $a to wa directly like
wa = $a

but did not pass. It seems the wave reference needs to be immediately ahead of where you use it or want to assign it, declaring the waves up front didn't help. Or maybe I am mixing the function declaration up with wave reference...

But Thanks!


People forget that the WAVE w=$something is not only a declaration about the relationship, but is is also an assignment. That is, at runtime something (a pointer) actually gets copied at that point in the program execution, so placement matters.

--Jim Prouty
Software Engineer, WaveMetrics, Inc.