Legends, Wave-by-Reference, and Igor 5.05A

Hey guys,

I'm using an old copy of 5.05A we have available at work (and currently strongly encouraging them to buy an updated version for our entire department), and I am running into an issue with some of my automation scripts.  

function MyFunction ("basename")
string basename

loadwave <loads the pretend wave xxx>
string wave2_name = basename + "_2"
rename xxx $wave2_name
wave wave2 = $wave2_name

I've got no problem using wave by reference as above, to rename and handle a bunch of poorly named data input files.   I can also graph these and modify the traces using wave by reference as below, however when trying to get the legend to load properly, the code breaks and no matter what I do, I can only get a ? in the annotation box instead of the graphic showing the type of line-font for the trace.  Obviously if I change the code to use the exact trace name given by <basename + "_2">, then it works, but that doesnt really help me for automatically producing a lot of graphs over a wide range of file names.  

string name_EFgraph = basename + "_graph"
display/N=$name_EFgraph Ywave1, Ywave2 vs Xwave

AppendToGraph/W=$name_EFgraph/Q Ywave3 vs Xwave
ModifyGraph/W=$name_EFgraph mode( Ywave3)=1
sprintf notetext, "%g at %g", amp_peak_3, freq_peak_3
TextBox/W=$name_EFgraph/N=$name_note_3/C/N=text1/Z=0/A=LB/X=(offset_x)/Y=(offset_y) notetext

//add the legend
Legend/W=$name_EFgraph/C/N=text0/A=RT/J "\s($Ywave2) center \r \s(Ywave3) edge"

 

This is kind of example code, I simplified some of the names without changing the syntactic context of the code, so if there is a name mismatch or something thats definitely not the problem.  As far as I can tell, I am running into problems as soon as I am trying to use  $ inside of either the \s( ) operator or inside of the "" string quotation operator.  Ive tried as well to use the sprintf method, which I can otherwise use just fine to make note boxes, just not the the \s() trace font.  

And yeah, I know I will (probably) need to name the legend box itself, just havent gotten that far because I can't get the required behavior for even a single instance, let alone multiple instances.  

Best regards,

Ian

Wow, this is some really ancient stuff you have here. I used Igor 5 the last time I had an experiment PC from the 2000s or so. ;)

Anyway, you cannot use $ inside a string declaration, as you already found out. You should construct the legend text by adding strings together. This may give you an idea:

string name1 = PossiblyQuoteName(NameOfWave(Ywave2))
string name2 = PossiblyQuoteName(NameOfWave(Ywave3))
Legend/W=$name_EFgraph/C/N=text0/A=RT/J "\s("+name1+") center \r \s("+name2+") edge"

I have no idea if these functions already exist in Igor 5 or whether this works in macros, but this is how you would do it in modern Igor versions.

Igor 5.05a was released 8/3/2006. That's less than 20 years old... But about a century in computer years :)

chozo is right- you need to compose the text for a legend as text. The wave reference syntax doesn't work there; a legend has particular ways to reference a trace name within the text. Note that it is a trace name- that is actually different from a wave name, though a trace is usually given the same name.

2006 was like yesterday you guys, stop joking around with me.  I'm just gonna go down and buy some coffee for a dollar and then see about flipping my house before 10 o'clock (psss, real estate is only going to go up its EASY money!), and then I'll invest the earnings into the stockmarket after I buy two more houses to flip, of course.  

Thanks tho, I will have a look at that.  I am curious however why you put +'s around the string, inside the quotes?  I had tried to use a string with the sprintf command but must have not done things quite as correctly contorted as that.  

Is this kind of thing "fixed" in later versions? It is burdensome to the user that the functionality changes so dramatically and I imagine this must come up a lot as its such a fundamental thing, labelling your graphs..

Can you buy some Apple stock for me before you come back to the future (also tell everybody they should work harder to make flying cars a reality)? ;)

I am not sure what you mean by +'s. Where do you see that? Do you mean \s? This is an escape sequence for legends which draws trace symbols, and still the same in the latest version. You can also use sprintf just fine for constructing a string. If you post you example we can have a look what might be wrong.

You can concatenate strings with +, so

string name1 = "foo"
legend "\s(" + name1 + ")"

is the same as

legend "\s(foo)"

 

Ah, that's fine. I started with Metroid 2, so it's been merely 33 years. ;)