Graph Names
Ken
Is it possible to control the method with which Igor names graphs? For example, when I create a graph called EGraph in the code and call that graph multiple times, what Igor does by default is name the first graph EGraph, the second EGraph_1, the third EGraph_2, and so on. Instead, can I make it so that Igor defaults to naming the first graph EGraph1, the second EGraph2, etc.?
Thanks.
do
WindowName = "EGraph" + Num2Str(i)
i = WinType(WindowName) > 0 ? i + 1 : -1
while (i > -1)
July 1, 2011 at 09:28 am - Permalink
No. But you can specify window names yourself. Use the /N= flag.
That's because you are running a Window macro named EGraph. Usually when writing a sophisticated package, we dispense with Window macros, which are intended to create one specific window, and change them to user-defined functions (Function CreateMyGraph()).
In the user-defined function you would call Display /N=$name after setting the string variable name to whatever you want.
You can use:
to determine the next available name.
July 1, 2011 at 09:35 am - Permalink
I originally had:
PauseUpdate; Silent 1 // building window...
variable/G Index
string FolderName = "FolderName_" + num2str(Index)
string GraphName = "GraphName_" + num2str(Index)
doWindow/F SGraph
doWindow/W=$WinName(0,1,1)/C $GraphName
string Title = "Trial " + num2str(Index)
SetDataFolder root:$FolderName
Display/W=(503.25,64.25,1049.25,374) Y_Axis vs X_Axis as Title
For some reason, the line "doWindow/W=$WinName(0,1,1)/C $GraphName" does not act on SGraph even though I call it to the front on the previous line. Am I using the WinName command incorrectly?
Also, what does the line "i = WinType(WindowName) > 0 ? i + 1 : -1" in chozo's code do? Where can I read more about this type of syntax, and where is it generally used?
July 1, 2011 at 11:20 am - Permalink
I'm not clear on what you are trying to do. It seems like you are trying to change the name of the graph window before it is created. The DoWindow calls occur before the Display call and Display is what creates the graph.
Also, putting SetDataFolder in a window macro is not a good idea. A procedure should not change the current data folder unless that is the point of the procedure. Otherwise it is a non-obvious side-effect that is likely to cause trouble and be hard to track down.
Here is a way to do this from a user-defined function without changing the current data folder:
Variable index
String dataFolderName = "F_" + num2str(index)
DFREF dfr = root:$dataFolderName // Create data folder reference
SVAR title = dfr:title
Wave yWave = dfr:Y_Axis, xWave = dfr:X_Axis
// . . .
Display yWave vs xWave as title
// . . .
End
Note that index is passed in as a parameter, not accessed via a global variable. Use of global variables makes programs difficult to understand and debug because it is not obvious from an invocation of a function what it depends on. Instead, as much as possible, pass the information needed by the function via parameters.
In this case it is likely that title should also be a parameter. Probably also xWave and yWave.
To read about data folder references:
July 1, 2011 at 03:19 pm - Permalink
The expression "test ? true : false" is a shorthand of a If-Else-Endif statement (for numerical expressions) like:
true
else
false
endif
But it's only one line of code and when you are finally able to read it it's very convenient and can also be expanded into multiple branches. You can read about it in the command help (look for '? :').
I'm amazed that there is a function like this. It's really astounding that there is a function already implemented in Igor for every workaround I write. I thought I went trough all the functions already. Now, where is the function to round arbitrary numbers to 'nice' numbers (e.g. 129930 -> 100000, 0.0345 -> 0.03)? :)
July 4, 2011 at 02:35 am - Permalink
When I want to do something like this I normally use sprintf/prinf, etc to create formatted text. e.g.
For the other rounding thing you probably want to use a log.
July 4, 2011 at 05:05 am - Permalink
Display ...
EndMacro
the graph name appears to be defined as Win_Name even before the display line.
I'll keep in mind to use parameters more often when creating functions rather than relying on global variables.
Thanks for explaining the unique syntax, chozo. I found it in the manual under logic operators, and may test it out in the future.
July 6, 2011 at 09:26 am - Permalink