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 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???
July 28, 2020 at 03:01 pm - Permalink
"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
July 28, 2020 at 03:26 pm - Permalink
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.
July 28, 2020 at 05:29 pm - Permalink
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
SetDimLabel 0, 11, mycEvent, foo
foo=$(statsFoldername +":"+ myParam[p])
July 28, 2020 at 11:50 pm - Permalink
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
July 29, 2020 at 02:09 am - Permalink
In reply to Thanks. No problem with… by Mike German
foo=$(statsFoldername +":"+ myParam[p])
sets all of the wave references in one line.
so foo[11] is the wave reference to wave with name myParam[11] in data folder named in statsfoldername, etc.
July 29, 2020 at 02:14 am - Permalink
In reply to foo=$(statsFoldername +":"+… by tony
you can also set up 'magic numbers' as constants:
function doSomething(folder, myParam)
string folder
wave /T myParam
make /wave/free foo=$(folder+":"+myParam[p])
display foo[mycEvent]
end
July 29, 2020 at 02:54 am - Permalink
In reply to you can also set up 'magic… by tony
And you can set the wave refs in a function:
make /free/wave/n=(numpnts(wavenames)) w_refs
w_refs=$(folder + ":" + wavenames[p])
return w_refs
end
July 29, 2020 at 04:30 am - Permalink
Thanks Guys,
I am still trying to find time to play with these ideas
August 14, 2020 at 05:18 am - Permalink