Re: skewt_func()

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Thu Feb 16 2012 - 12:04:14 MST

Although I have not solved this problem, I have some further observations, and some simple workarounds.

Because the "wks" variable in the "sounding" procedure is a local variable, it gets deleted when the procedure exits. The gks_open_wks function attaches the id of the appClass parent of t
the workstation as an attribute of the workstation variable. When the wks variable is deleted, the appClass attribute also gets deleted because there are no references to it anywhere else. Since this is the "default" app, it causes problems when subsequent code tries to use the default app. The fix will probably be to make it impossible to delete the default app.
Using the low-level 'create' block to create the workstation does not have the same problem because the app id does not get attached as an attribute, and therefore it does not get deleted.

In the meantime, there are 2 simple ways to make your code work:
1) Make the wks into a global variable. Just put the line
    wks = new(1,graphic)
after the load statements.
2) Change the sounding procedure into a function that returns the variable wks.

Either way the point is simply to avoid having the workstation variable 'wks' deleted.
 -dave
 

On Feb 16, 2012, at 2:27 AM, Paul Scorer wrote:

> Well, Thank You for this; What it is to know the system!
>
> I await your further observations with interest.
>
> Thanks
>
> PaulS
>
>
> On Wed, 2012-02-15 at 14:27 -0700, David Brown wrote:
>> Hi Paul,
>>
>> I agree with Mary that this like has nothing to do with the skewt
>> code, and is more likely a problem in the NCL code itself.
>> I was able to duplicate your problem with a simplified version of your
>> code fragments, and unfortunately Mary's suggestion for a workaround
>> does not help.
>> I can also see that reversing the order of execution makes the problem
>> go away. I will investigate further.
>> FYI here is the runnable code that shows the problem:
>>
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/skewt_func.ncl"
>>
>> procedure sounding()
>> begin
>> wks = gsn_open_wks("x11","test")
>> skewt_bkgd = skewT_BackGround(wks, False)
>> draw(skewt_bkgd)
>> frame(wks)
>> end
>>
>> procedure plot_contour()
>> begin
>> appid = NhlAppGetDefaultParentId()
>> print(appid) ; if plot_contour is executed first this prints a valid object id -- if second it prints a missing value
>> x =create "name" imageWorkstationClass appid
>> end create
>> end
>>
>>
>> begin
>> sounding()
>> plot_contour()
>> end
>>
>>
>> On Feb 15, 2012, at 1:03 PM, Mary Haley wrote:
>>
>>> Hi Paul,
>>>
>>> I think this has to do with some weird parent/child stuff going on internally with the workstations.
>>>
>>> When you call gsn_open_wks, it creates a "default parent" for the workstations, of which I think only one can exist.
>>>
>>> Hence, when you call the "create" block to create an image workstation, the "defaultapp" that you are trying to use
>>> is invalid. I think Dave would have to explain this.
>>>
>>> Maybe this would work inside of plot_contour:
>>>
>>> begin
>>> appid = NhlAppGetDefaultParentId()
>>> wks2 = create "name" imageWorkstationClass appid
>>> …
>>> end create
>>> end
>>>
>>> --Mary
>>>
>>>
>>> On Feb 14, 2012, at 10:30 AM, Paul Scorer wrote:
>>>
>>>> Greetings,
>>>>
>>>> [Maybe this is one for Dennis Shea: his name is all over the code :-) ]
>>>>
>>>> I have an interesting issue with skewt_func() (admittedly slightly
>>>> modified)
>>>>
>>>> I hope the code outline below is enough to specify the problem.
>>>>
>>>>
>>>> procedure sounding(...)
>>>> begin
>>>> wks = gsn_open_wks(...)
>>>> skewt_bkgd = skewT_BackGround(wks, opts)
>>>> draw(skewt_bkgd)
>>>> skewt_data = skewT_PlotData(wks, skewt_bkgd, ...)
>>>> frame(wks)
>>>> end
>>>>
>>>> procedure plot_contour(...)
>>>> begin
>>>> create "name" imageWorkstationClass defaultapp
>>>> ; wkHeight, Width, etc
>>>> end create
>>>> ...
>>>> end
>>>>
>>>> If the above are called thus
>>>>
>>>> begin
>>>> ...
>>>> sounding(...)
>>>> plot_contour(...)
>>>> ...
>>>> end
>>>>
>>>> then it bombs with
>>>> fatal:_NclCreateHLUObjOp: Parent value is not an hlu object or is undefined
>>>>
>>>> Line number indicated is that of "end create". I get the same behaviour
>>>> with xWorkStationClass (Both "sounding" & "plot_contour" use the same
>>>> WorkStationClass).
>>>>
>>>> However, if called like this
>>>>
>>>> begin
>>>> ...
>>>> plot_contour(...)
>>>> sounding(...)
>>>> end
>>>>
>>>> Everything is OK (for both .png and X11)!
>>>>
>>>> Clearly the fix is obvious, but it would be nice to make the code fully
>>>> bulletproof.
>>>>
>>>> Any ideas?
>>>>
>>>> Thanks
>>>>
>>>> PaulS
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Feb 16 12:04:27 2012

This archive was generated by hypermail 2.1.8 : Thu Feb 23 2012 - 10:01:53 MST