Referencing waves in a function

I am trying to reference in a function, sets of existing waves in a data folder: They have names such as "Event" , "Tstart" and "Points" and there are some twenty of them.  Strings of these name waves are also in a text wave named "Param"  I would also want to select which of these parameter I use in the function - some or all. With my current programming skills with IGOR PRO I have to do this the hard way

    wave mycEvent = $(statsFoldername +":"+ myParam[11])
    wave mycTStart = $(statsFoldername +":"+ myParam[12])
    wave mycPoints = $(statsFoldername +":"+ myParam[13])

where myParam[11] = "Event", myParam[12] = "Tstart"  ...etc.  I would use a flag in another wave, say "ParamFlag"  to select which was referenced.  To complicate things a bit more there are two other datafolders with same named waves that I need to reference with names such as "myrEvent" and "myaEvent"

What I would like help on please is how to put this in a loop so that the name of wave I am referencing is taken from the string in Param text wave and prefixed with "myc" .  I feel there must be a way of doing it because the above is too tedious surely...

Mike

 

If you are asking if in "wave mycEvent" the name "mycEvent" can come from a string, the answer is no.  This has to be a literal name.

 

Maybe I answered the wrong question???

            "Maybe I answered the wrong question???"

Well, yes and know.   You've told me why I can't do what I was trying to do, which is good. But is there a way that waves can be referenced to achieve what I'm after or Is it necessary to code a separate literal name for each.  I have tried duplicating a literal name with a string $(newname) but this changes the original name.

if there is no way then I will do it the long way but it does seem clunky programming 😕

Mike

This will be easier using a wave/SDFR=... approach.

    wave/SDFR=$statsFolderName mycEvent = $(myParam[11])

I cannot vouch for whether $(myParam[11]) should work (if this is your question). I haven't used a text wave element as a wave reference (but it is a neat idea if it does work).

As to making this work in a for loop, I am a bit lost on your need.

Maybe take a look at wave reference waves.

You could use dimension labels for referencing within your function, and set up the wave references as an implicit loop.

something like

make /wave foo
SetDimLabel 0, 11, mycEvent, foo
foo=$(statsFoldername +":"+ myParam[p])

 

Thanks.  No problem with data folders.  The problem is, say in Tony's example, of programming for allotting names for 20 waves in a function to access 20 existing wave.  I am looking for a way of not writing 20 lines such as 

       wave foo1 = $(existingwave1)     

       Wave foo2  $(existingwave2)   .... etc

This may be a  case for using a Macro()  perhaps :-)

 

Mike

 

 

In reply to by tony

you can also set up 'magic numbers' as constants:

static constant mycEvent=11

function doSomething(folder, myParam)
  string folder  
  wave /T myParam
 
  make /wave/free foo=$(folder+":"+myParam[p])

  display  foo[mycEvent]
end

 

In reply to by tony

And you can set the wave refs in a function:

function /WAVE getWaveRefs(string folder, wave /T wavenames)
   
    make /free/wave/n=(numpnts(wavenames)) w_refs
    w_refs=$(folder + ":" + wavenames[p])
    return w_refs
end