Function to get an Axis Label
Posted April 15th, 2008 by johnweeks
This function, given the name of graph ("" uses the top graph window) and the name of an axis, returns the axis label.
Function/S GetAxisLabel(gname, axisname) String gname, axisname String grecreation = WinRecreation(gname, 0) String oneLine String labelStr = "" String part1, part2 Variable i=0 do oneLine = StringFromList(i, grecreation, "\r") if (stringmatch(oneLine, "\tLabel*")) String regexp = "^\\tLabel "+axisname+" \\\"(.*)\\\"" SplitString/E=regexp oneLine, labelStr break; endif i += 1 while(strlen(oneLine) > 0) return labelStr end
The regular expression works like this:
- ^
- match the beginning of the string
- \\t
- match a tab character. The double backslash is because Igor interprets the backslash first, so to get a single backslash all the way through to SplitString, you need two of them.
- Label
- matches the literal string "Label "
- +axisname+
- matches the axis name. We hope there are no special characters in the axis name! Note that the space after the next quote mark matches the space between the axis name and the beginning of the quoted string
- \\\"
- match the opening quote on the axis label itself
- (.*)
- match all characters, and the () make it a substring which will be pulled out and put into the string variable labelStr
- \\\"
- match the closing quote
