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

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Thu Apr 29 2010 - 06:29:31 MDT

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/lfff00000000p
>
>
> ------------ 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
Received on Thu Apr 29 06:29:39 2010

This archive was generated by hypermail 2.1.8 : Thu Apr 29 2010 - 08:05:27 MDT