Updating Panel instead of creating a new one

I am kind of confused how I should program a Window to update instead of creating a new one. I have Labview sending a command that goes

Command(a,b)


And my procedure is

Macro Command(a,b)
    //bunch of stuff
    DataPanel()
End

Window DataPanel() : Panel
     PauseUpdate; Silent 1
    NewPanel/W=(500,100,1200,600) as "Data"
    //stuff such as
    Display/W=(70,270,320,450)/HOST=# a


How can I do this so that when I send Command(a,b), it only updates, not creates a newpanel.
Well, NewPanel creates a new panel and Display creates a new graph...

It depends on what aspect of the panel you want updated. If you have, for instance, a SetVariable control that needs an updated value, you would use the SetVariable command with the "value" keyword if you originally made it with value=_NUM:, or you would simply assign a new value to the global variable if your SetVariable is attached to a global variable.

What needs to be updated?

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
So what I want updated are graphs in the panel. Here is my panel code


Window PulseInfo() : Panel
	PauseUpdate; Silent 1
	NewPanel/W=(509,107,1183,569) as "PulseInfo"
	ShowTools/A

	Variable/G StartFreq=18
	Variable/G EndFreq = 25
	Variable/G startindex=1
	Variable/G endindex=3

	SetVariable setvar0, pos={20,31}, size = {156,14},bodywidth=77, title="Start Frequency", Value = StartFreq
	SetVariable setvar1, pos={19,54}, size={160,16}, bodywidth=84, title="End Frequency", Value = EndFreq
	SetVariable setvar2, pos={240,18}, size = {122,14},bodywidth=77, title="Start File", Value = startindex
	SetVariable setvar3, pos={245,44}, size={118,16}, bodywidth=84, title="End File", Value = endindex

	Button button0, pos={50,81},size{80,30}, proc=ButtonProc, title="Gaussian Fit"
	Button Button1, pos={274,15}, size={90,30}, proc=ButtonProc_average,tiele = "Average Pulse"

	ValDisplay valdisp0,pos={112,222}, size={124,14}, bodyWidth=60, title = "Pulse Center"
	ValDisplay valdisp0,limits={0,0,0},barmisc={0,1000}, value = centerfreqpulse 
	ValDisplay valdisp1,pos={443,222}, size={115,14}, bodyWidth=60, title = "Ref Center"
	ValDisplay valdisp1,limits={0,0,0},barmisc={0,1000}, value = centerfreqref

	Display/W=(68,266,320,445)/HOST=# $fftpulse
	ModifyGraph frameStyle=1
	SetAxis left 0,200; DelayUpdate
	SetAxis bottom 1.8E7,2.8E7
	RenameWindow #, G0
	SetActiveSubwindow ##

	Display/W=(375,266,627,445)/HOST=# $fftreference
	ModifyGraph frameStyle=1
	SetAxis left 0,200; DelayUpdate
	SetAxis bottom 1.8E7,2.8E7
	RenameWindow #, G1
	SetActiveSubwindow ##

	Display/W=(375,13,627,200)/HOST=# averagedwave
	ModifyGraph frameStyle=1
	SetAxis left 0,20; DelayUpdate
	SetAxis bottom 1.8E7,2.8E7
	RenameWindow #, G2
	SetActiveSubwindow ##
EndMacro
And my Macro is actually

Macro Pulse(file,timestamp,index,npoints)
	string file
	Variable timestamp, index, npoints
	Variable/G npoints1 = npoints

	string newpulse, newreference
	string/G fftpulse
	string/G fftreference
	string diff
	LoadDataset("PathSelfHet", file, "pulse")
	LoadDataset("PathSelfHet", file, "reference")

	sprintf newpulse, "%s%d" "pulse", index
	sprintf newreference, "%s%d" "reference", index

	duplicate /O pulse, $newpulse
	duplicate /O reference, $newreference

	SetScale/P x 0, timestamp, "", $newpulse
	SetScale/P x 0, timestamp, "", $newreference

	sprintf fftpulse, "%s%d" "fftpulse", index
	sprintf fftreference, "%s%d" "fftreference", index

	FFT/OUT=4/DEST= $fftpulse $newpulse
	FFT/OUT=4/DEST= $fftreference $newreference

	$fftpulse[0]=nan
	$fftreference[0]=nan

	sprintf diff, "%s%d","diffpulse", index
	Variable fftsize = npoints/2
	make/N=(fftsize) $diff
	$diff = $fftreference-$fftpulse

	PulseInfo()

End
First, I have a few recommendations.

* Learn to use Functions not Macros. I believe Macros are mostly considered obsolete except for backward compatibility.
* Learn to use DataFolderDFR functions to set or define locations of waves. These references to folders will help keep the code "transportable" as you move from one folder to another or one experiment to another and accidentally change the location of the current data folder.
* Put return values at the end of the Functions (e.g. return 0). This is good programming practice.
* Replace the Window PulseInfo() with a function call that is a bit more understandable, e.g. Function ShowPulseInfoPanel(). Again, good programming practice.
* Correspondingly remove all the unnecessary PauseUpdate, DelayUpdate, and Silent 1 commands in the ShowPulseInfoPanel() function. They are only there when the panel is being generated in a "one-step-at-a-time" approach as per a command line entree. They are useless in function calls.

Secondly, as for the question about updating graph displays, I have a suggestion and some observations.

* Suggestion: Display your graphs separately and debug their operation BEFORE you embed them in a panel. Graphs must operate independently of a panel anyway (as you have now learned).

* Observations: Your panel/graph display code has no definitions for the "$" waves that are to be displayed in the graphs. This means, they are basically non-existent references. Also, your Pulse code plays jostles around with "$" references to strings as wave names. This is confusing at best and potentially damage prone at worse. Any of these mistakes could leave the code "hanging" for lack of a proper reference point to wave, because that wave will not really exist at run time or it will exist somewhere in some location that is not the current data folder or it will not even be defined in the right way even when it does exist where it is supposed to exist.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
If you are modifying the waves that are already displayed in your graphs, you are done once you have computed new contents for the waves. Igor will automatically update the graphs.

If you are creating new waves, use AppendToGraph to add them to your graph:


WAVE newwave = <whatever>
AppendToGraph/W=$mygraph#G0 newwave

It will take a different function from the one that built the panel with the graphs. I have left some things that you will have to figure out. It is a good idea, when you create the panel to give it a name that isn't likely to be the same as someone else's name:

NewPanel/N=jmas340Panel ...


and then you can use a hardcoded name in the update function:

AppendToGraph/W=jmas340Panel#G0 ...


John Weeks
WaveMetrics, Inc.
support@wavemetrics.com