ModifyImage problem when writing a procedure.
n.black
I'm having, I think, a similar problem that was on this thread. http://www.igorexchange.com/node/6419
So I have written something that will go through every wave in a data folder and create an image.
I then wanted to try to do something similar to an image macro but found it wasn't working. (I tired Execute command but failed at that). So I rewrote my macro commands as a function so after igor makes the new image it(he?) can then go on and modify it.
But I am having problem with the ModifyImage command, I've read up on it and I think I'm using it appropriately but I am clearly missing something. Here is the general gist of what I am doing minus my graph formatting preferences.
Function MacRamalan2()
Variable datafolder
String/G list = Wavelist("*",";","") // creates a list of all waves in current "datafolder" separated by a ;
Variable/G numItems = ItemsInList(list), i // counts how and indices the items(graph) broken by ;
for (i = 0; i<numItems; i+=1) // starts a loop to go through each wave data
String/G data //creates a string of ith data
data = StringFromList(i,list,";") //goes through list and extracts ith string
wave w=$data
newimage w
String/G win=WinName (0,1) //The name of the top visible graph
ModifyImage win, ctab= {*,*,YellowHot,0}
//Raman_IDIG() the modified macro function where everything under newimage will live once working
endfor
end
Variable datafolder
String/G list = Wavelist("*",";","") // creates a list of all waves in current "datafolder" separated by a ;
Variable/G numItems = ItemsInList(list), i // counts how and indices the items(graph) broken by ;
for (i = 0; i<numItems; i+=1) // starts a loop to go through each wave data
String/G data //creates a string of ith data
data = StringFromList(i,list,";") //goes through list and extracts ith string
wave w=$data
newimage w
String/G win=WinName (0,1) //The name of the top visible graph
ModifyImage win, ctab= {*,*,YellowHot,0}
//Raman_IDIG() the modified macro function where everything under newimage will live once working
endfor
end
So for simplicity I left out some other bits of code that are working. I keep getting the error that ModifyImage should be "expecting the name of an image in the top graph". But shouldn't the WinName function pick up the name of the window just made?
If anyone can explain what i'm doing wrong and/or direct me to the bit in the manual that can explain it better that would be great.
Thanks in advance!
N
You need to use
Also, there is probably no need to make your win string global. Just do
String win = WinName(0,1)
unless you actually need it to be global.For more information, execute the following commands on the command line. Only the first applies to this particular situation, but once you know about the $ operator, you're likely to try to use it elsewhere, and that's covered by the other help topics.
DisplayHelpTopic "Converting a String into a Reference Using $"
DisplayHelpTopic "Wave Accessed Via String Passed as Parameter"
DisplayHelpTopic "Wave Accessed Via String Calculated in Function"
July 9, 2015 at 05:36 am - Permalink
Thank you so much for your speedy reply.
I used the $ as you said which upon reading essentially operates on the string and should return a name. But I still get the same error as before. Any idea how to proceed?
Also, I used the global string purely to find it easily in the databrowser and check the information in the string to make sure my function is doing what I think it's doing but yes I will remove it once function is working.
I'm still reading through the manual references which are very helpful!
Thanks,
N
July 9, 2015 at 06:11 am - Permalink
-->
ModifyImage /W=$win, ctab= {*,*,YellowHot,0}
HJ
July 9, 2015 at 06:17 am - Permalink
Thanks for the input. I tried this but again got the same error. I believe ModifyImage only needs /W flag when you need to specify an image that is not the top graph.
Thanks,
N
July 9, 2015 at 06:30 am - Permalink
You should not use
WinName
at all in this caseAssuming your data waves have "nice" names, a change of
ModifyImage win, ctab= {*,*,YellowHot,0}
to
ModifyImage $data, ctab= {*,*,YellowHot,0}
should work.
HJ
July 9, 2015 at 06:47 am - Permalink
Thanks that did the trick!
To just verify I understand conceptually what is happening.
wave w=$data
Converts the name of ith string and turns it into a wave of data.
and
Takes the name of data which should incidentally be the name of the image from above statement and plug the image name into the command.
Thank you very much for your help! =)
Best wishes,
N
July 9, 2015 at 07:02 am - Permalink
"$str" creates a reference to the "object" named by a string "str". It can be a wave, variable, window, image, trace, and even a function (in some cases).
I also recommend to read
DisplayHelpTopic "Converting a String into a Reference Using $"
since it is one of the powerful features Igor provides.
By default traces and images share the name of the wave they were created from. Thus "$data" also works in the second case.
HJ
July 9, 2015 at 07:36 am - Permalink
You're better off using Igor's debugger in this situation. For more information, execute
DisplayHelpTopic "The Debugger"
July 9, 2015 at 09:14 am - Permalink