Re: Replacing type of dimension within subroutine (in NCL 5.2)

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Thu Apr 29 2010 - 10:41:00 MDT

Hi Oliver,
I haven't had a chance to look yet but I suspect this new bug is a
side effect of a fix I made awhile back
that involved coordinate variable names not being changed to match a
change made to a dimension name
within a subroutine. It may actually have been some of your code that
demonstrated that bug. Anyway,
I'll have to look at the code to learn what the new problem is. I
would certainly hope it's possible to get it
to work again.
  -dave

On Apr 29, 2010, at 10:25 AM, <Oliver.Fuhrer@meteoswiss.ch> <Oliver.Fuhrer@meteoswiss.ch
> wrote:

> Mary,
>
> Thanks for your help on this issue. I suppose there is some interest
> in
> actually having this functionality (modifying attributes in a
> subroutine). For example, we typically 1) load a variable from a file,
> 2) attach some attributes for geo-referencing, 3) attach some
> attributes
> for labelling, and 4) plot it. The subroutines performing these
> actions
> are at least 100 lines long and perform quite a lot of stuff...
>
>> v = get_var(f,"MYVAR")
>> get_grid(v)
>> get_meta(v)
>> p = plot_var(wks,v,res)
>
> The same code using the workaround would look...
>
>> v = get_var(f,"MYVAR")
>> tmp = get_grid(v)
>> delete(v)
>> v = tmp
>> delete(tmp)
>> tmp = get_meta(v)
>> delete(v)
>> v = tmp
>> delete(tmp)
>> p = plot_var(wks,v,res)
>
> I personally prefer the first - more elegant and readable - version.
> But
> I will leave it to the experts to tell me if modifying meta-data of a
> variable within a subroutine is should work or not.
>
> Thanks!
> Oli
>
>> -----Original Message-----
>> From: Mary Haley [mailto:haley@ucar.edu]
>> Sent: Donnerstag, 29. April 2010 14:30
>> To: Fuhrer Oliver
>> Cc: ncl-talk@ucar.edu
>> Subject: Re: Replacing type of dimension within
>> subroutine (in NCL 5.2)
>>
>> Hi Oli,
>>
>> This does look like a problem, although I'm never quite sure
>> what the
>> expected behavior is when you try to directly change the
>> metadata of a
>> variable that is passed in to a function or procedure.
>>
>> I produced a narrowed down version of your script that
>> doesn't require
>> a data file, and was able to see that it works with 5.1.1 and
>> not 5.2.0.
>>
>> I tried a function version of "replace_dim" that actually
>> makes a copy
>> of your variable, and that seems to work. If you have enough memory,
>> perhaps you can use this as a work-around?
>>
>> Unfortunately, you can't just replace your current "var" by calling
>> this function. You still have to assign it to a new variable, like I
>> did with "newvar".
>>
>> Meanwhile, I'll see what Dave says about this bug.
>>
>> undef("replace_dim")
>> function replace_dim( var1:numeric )
>> local s
>> begin
>> var2 = var1
>> print("replace_dim: start")
>> delete(var2&lv_ISBL0)
>> var2&lv_ISBL0 = fspan(0.,19.,20)
>> print("replace_dim: end")
>> return(var2)
>> end
>>
>> begin
>> print("main: start")
>>
>> ; read some data
>> ;f = addfile("../data/example/lfff00000000p.grb","r")
>> ;var = f->FI_GDS10_ISBL
>> var = fspan(1,20,20)
>> var!0= "lv_ISBL0"
>> var&lv_ISBL0 = ispan(1,20,1)
>> printVarSummary(var&lv_ISBL0)
>>
>> ; replace first named dimension from array of integers to array of
>> floats
>> if (True) then
>> newvar = replace_dim(var)
>> printVarSummary(newvar&lv_ISBL0)
>> else
>> delete(var&lv_ISBL0)
>> var&lv_ISBL0 = fspan(0.,19.,20)
>> printVarSummary(var&lv_ISBL0)
>> end if
>>
>>
>> print("main: end")
>>
>> end
>>
>>
>> On Apr 29, 2010, at 1:49 AM, <Oliver.Fuhrer@meteoswiss.ch>
>> <Oliver.Fuhrer@meteoswiss.ch
>>> wrote:
>>
>>> Hi NCL-team,
>>>
>>> I think I've stumbled over a bug. Since the introduction of
>> NCL 5.2 I
>>> get an error message if I change the type of a dimension within a
>>> subroutine. If not done within a subroutine (set True to False in
>>> example script below) everything works fine. Also, in
>> version 5.1 this
>>> also worked without problems. It seems that upon returning
>> NCL tries
>>> to
>>> replace the variable of the caller with the temporary
>> variable within
>>> the subroutine and runs into a type conflict.
>>>
>>> Cheers,
>>> Oli
>>>
>>> PS. Data file for script can be found here
>>>
>> https://twiki.cscs.ch/twiki/pub/Main/OliverFuhrerDownloads/lff
>> f00000000p
>>>
>>>
>>> ------------ example script ----------------------
>>>
>>> undef("replace_dim")
>>> procedure replace_dim( var:numeric )
>>> local s
>>> begin
>>> print("replace_dim: start")
>>> delete(var&lv_ISBL0)
>>> var&lv_ISBL0 = fspan(0.,19.,20)
>>> print("replace_dim: end")
>>> return
>>> end
>>>
>>> begin
>>> print("main: start")
>>>
>>> ; read some data
>>> f = addfile("../data/example/lfff00000000p.grb","r")
>>> var = f->FI_GDS10_ISBL
>>> printVarSummary(var&lv_ISBL0)
>>>
>>> ; replace first named dimension from array of integers to array of
>>> floats
>>> if (True) then
>>> replace_dim(var)
>>> else
>>> delete(var&lv_ISBL0)
>>> var&lv_ISBL0 = fspan(0.,19.,20)
>>> end if
>>>
>>> printVarSummary(var&lv_ISBL0)
>>>
>>> print("main: end")
>>>
>>> end
>>>
>>>
>>> ________________________________________
>>>
>>> Oliver Fuhrer
>>> Numerical Models
>>>
>>> Federal Departement of Home Affairs FDHA
>>> Federal Office of Meteorology and Climatology MeteoSwiss
>>>
>>> Kraehbuehlstrasse 58, P.O. Box 514, CH-8044 Zurich, Switzerland
>>>
>>> Tel. +41 44 256 93 59
>>> Fax +41 44 256 92 78
>>> oliver.fuhrer@meteoswiss.ch
>>> www.meteoswiss.ch - First-hand information
>>>
>>> _______________________________________________
>>> 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 Apr 29 10:41:14 2010

This archive was generated by hypermail 2.1.8 : Mon May 03 2010 - 14:51:26 MDT