wave name into string

hi,

how I display the wavename of a wave as a string ??

I have a wave call "hello" and i want to create another one call "hello_everybody" with the same data points as the one wave call "hello".

example

"hello"=[1,2,3]

duplicate hello, hello2
rename hello2, hello+"_everybody"
killwave hello2
print "hello_everybody"
output: "hello_everybody"=[1,2,3]

* I know that my mistake is in: rename hello2, hello+"_everybody"; because hello is a wave a not a string.
In a function it would look something like
Function test()

    Wave hello
    Duplicate/O hello, $("hello"+"_everybody")/WAVE=hello2
    print hello2
end


•test()
hello_everybody[0]= {1,2,3}

The symbol "hello2" is a "wave reference" a local name for the global wave. The example is a little silly because the strings are all literal strings. It becomes a real solution to a real problem if the original name is entered via a string, for instance:
Function test(wname)
    string wname

    Wave w=$wname
    Duplicate/O w, $(wname+"_everybody")/WAVE=hello2
    print hello2
end

•test("hello")
hello_everybody[0]= {1,2,3}

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
I guess i did not explain me really well...

I have 100 waves that i need to duplicate and rename with the name of the wave plus "_everybody". That means:


"hello"=[1,2,3]
"jallo"=[1,2,3]
"hola"=[1,2,3]
...

i need to duplicate them and rename them as:

"hello_everybody"=[1,2,3]
"jallo_everybody"=[1,2,3]
"hola_everybody"=[1,2,3]
...

at the end i will end up with 200 waves

that means i have to takeduplicate every string, use the name of every wave as a string add "+everybody" and name the just duplicated wave with this name.
* every wave is different.

the function is defined like

Test(wave) // where the wave is hello=[1,2,3]

at the end i need something call:

Hello_everybody=[1,2,3]






carlosgarzonc wrote:
I have 100 waves that i need to duplicate and rename with the name of the wave plus "_everybody". ....


I think this should work ...

Function DuplicateSet(suffix,[lowaves])
   string suffix, lowaves

   variable ic, nt
   string theOne, theNewOne

   if (ParamIsDefault(lowaves))
      // default is all waves in current data folder
      lowaves = WaveList("*",";","")
   endif

   if (strlen(suffix)==0)
     // default suffix
     suffix = "_duplicate"
   endif

   nt = numpnts(lowaves)
   if (nt == 0)
      return 0
   endif

   for (ic=0;ic<nt;ic+=1)
     theOne = StringFromList(ic,lowaves)
     sprintf theNewOne, "%s%s", theOne, suffix
     duplicate/O $theOne $theNewOne
   endif

   return nt
end


Examples uses would be as follows:

Everything in Current Folder

DuplicateSet("_everybody")


Only Waves Starting with XYZ

DuplicateSet("_everybody",lowaves=WaveList("XYZ*",";",""))


HTH

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
One important function in this context that hasn't been mentioned so far is nameOfWave.
You can use it like this:
make/o hello={1,2,3}
duplicate hello $(nameOfWave(hello)+"_everybody")

A
Also see the help files that describe the $ operator and techniques for working with waves in functions:

DisplayHelpTopic "Accessing Global Variables And Waves"
DisplayHelpTopic "Accessing Waves In Functions"

The first is a general discussion of WAVE references and related topics, the second is a more specific discussion of common techniques. Note that the subsection "Wave Accessed Via String Calculated in Function" is similar to your situation.

Quote:
"hello"=[1,2,3]
"jallo"=[1,2,3]
"hola"=[1,2,3]


If your wave names are really different (that is, not really computable) you probably have them in a list. Then you might need to know about the StringFromList function.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
the "rename" function works as well.

//where string "oldname" is the string naming your old wave....

string newstring
newstring= (oldname) + "_Everybody"

rename oldname, $(newstring)
kperks wrote:
the "rename" function works as well.

//where string "oldname" is the string naming your old wave....

string newstring
newstring= (oldname) + "_Everybody"

rename oldname, $(newstring)


Be careful! In your example the string 'oldname' is renamed, not the wave.
In that case would the following work correctly?:

duplicate oldname, $(newstring); killwaves oldname



awirsing wrote:
kperks wrote:
the "rename" function works as well.

//where string "oldname" is the string naming your old wave....

string newstring
newstring= (oldname) + "_Everybody"

rename oldname, $(newstring)


Be careful! In your example the string 'oldname' is renamed, not the wave.

kperks wrote:
In that case would the following work correctly?:

duplicate oldname, $(newstring); killwaves oldname


If you work with string variables that contain wave names, you must use the $ operator in order to access the wave itself:
duplicate $oldname, $newstring; killwaves $oldname