Looping through different waves of data
geologic
I'm writing software for my lab group and would like to post an outline of what I intend to do so that I can be sure I'm doing this in an intelligent and efficient way.
I think a simple example of the features I would like would be this:
1. I have say 10 time traces that I import into igor. The names would presumably be something like sample_1, sample_4p5 where 4p5 labels a temperature 4.5 .
2. I would like to write a function where I basically only input in the temperatures as strings, the sample name as a string, and run a function (after the waves have been loaded into igor). Like wavecompute("H2O","1","4p5").
3. Some experiments might result in 4 waves, some in 15, so I would like the option of inputting arbitrary numbers of waves without too much headache.
Some code/pseudocode that captures how I see the program going.
function wavecompute(sample,a,b,c,...) //I've worked briefly with optional inputs before, but I'm going to skip that portion in the pseudocode for brevity.
string sample
make/o/t textwave={"a","b","c",...} //These are the temperatures, listed as strings.
Here I think maybe I could do some loop where I load the wave named sample+_+"textwave[i]" (maybe no quotes, I'm not sure yet). I could input i as a variable, so the loop would know how many times to run. One difficulty I'm facing is that I'm not sure how to load a wave based on a string name. I can create a string and make the wave the object/wave associated with that name with the $ sign, but how can I create a string and then tell igor to look for a wave with the name of that string?
I'll sign off here, to get the ball rolling. Thanks for your help!
You might be better off having one string parameter for temperatures that expects a semicolon delimited list of temperatures. For example,
wavecompute("H2O", "1;4p5;5p6;")
Depending on how fancy you want to get, you could have the user enter the actual numerical values (eg. 4.5) and you would convert that to "4p5".
Igor does support optional parameters, but it does not support a variable number of optional parameters. I'm not sure, but there also might be a maximum number of parameters that a function can have, and if so that might be fewer than you need.
You can use
ItemsInList
andStringFromList
to go through the list to get the temperatures you want to analyze.If you wanted, you could use liberal wave names for your waves, so they would actually be named, for example, "sample_4.5". For more information on liberal wave names, execute the following commands in Igor:
DisplayHelpTopic "Programming with Liberal Names"
Here is some example code:
// Assume wave being looked up is in the current data folder
String wName = PossiblyQuoteName("sample_" + tempPart)
WAVE myWave1 = $(wName)
// Provide full path to wave to look up so that the wave can
// be looked up regardless of what the current data folder is
String fullWavePath = "root:" + PossiblyQuoteName("sample_" + tempPart)
WAVE myWave2 = $(fullWavePath)
How you assign the value of tempPart depends on where the input is coming from. In your example, you might actually have:
Or, if you use my suggestion of having the user provide a semicolon delimited list of temperatures, you might have:
Obviously, you don't need to separate tempPart variable in the actual code, I just wrote it that way to make it a bit simpler to read and debug.
The example code I wrote above should support liberal wave names, if you decide to go that way, though I didn't test it.
Adam
December 2, 2014 at 06:39 am - Permalink
I like this and think I'll do this...this will likely fix my option parameter problem, as I can count the number of strings in that list and execute my analysis only while I have a new string from that list. Nice tip!
This depends how kind I want to be to my labmates...but I'll consider it!
I'll look into this, but your suggestion from above might make this problem irrelevant.
This is scaring me away (I don't need the liberal names [i]that[/i] badly"): If you are willing to expend extra effort when you use liberal names in commands and waveform arithmetic expressions, you can use wave and data folder names containing almost any characters."
December 9, 2014 at 12:46 pm - Permalink
December 9, 2014 at 12:48 pm - Permalink