Adding graphs in a window embedded in a panel

Hi all,

Just a quick question, I am trying to embed a graph in a subwindow embedded in a panel. For the panel name, I am using $kPanelName. Why is it not working? If I use the exact name for the panel and the sub window, everything is fine. If I use the following code section, I get an error message which says there is no graph named on that. 

Thanks.

Display/W=(10,10,100,100)/K=3/HOST=$kPanelName/N=myGraph
AppendToGraph/W=$kPanelName#myGraph y vs x
 
 

 

Your code seems to suffer a bit from $-confusion. The following code snippet works here and hopefully illustrates how to do it:

Function Dostuff()

    string host, subPanel, subGraphInSubPanel
       
    NewPanel
    host = S_name
   
    NewPanel/HOST=$host
    subPanel = host + "#" + S_name

    Display/HOST=$subPanel
    subGraphInSubPanel = subPanel + "#" + S_name
End

You can also pass a custom name via /N. The idea is that you build the window path as you go with always the same pattern.

The problem is that subwindow paths do not support string constants. Assuming you have a string constant like this:

StrConstant kPanelName = "MyPanel"
// This gives a compiler error
AppendToGraph/W=$kPanelName#myGraph jack

// This works
String tmp = kPanelName
AppendToGraph/W=$tmp#myGraph jack

 

It seems to be a parsing issue- the compiler doesn't know where the string expression ends. This compiles:

StrConstant kPanelName = "MyPanel"

Function test()
    Wave jack
    AppendToGraph/W=$(kPanelName)#myGraph jack
end

I'm not really certain what the compiler is doing when it parses the expression, but I find it's pretty common that you need to help the compiler parse an expression by adding some parentheses. In this case, it makes it clear that the string expression that the $ operator applies to is just the string constant.

Thanks all for the information and suggestions.

Yes, I had a string constant (StrConstant kPanelName = "MyPanel") which I used to name the base panel and were trying to embed subwindows in it. It would be better if Igor could use a string constant to refer a subwindow in the way I was trying to do because that bit of code looks simple and potential to work.