[ncl-talk] Array initialization question

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Mon Jul 2 14:57:30 MDT 2018


Dave V,

Here is one possible approach which I have used in similar applications.

function data_read(rfile[1]:string,var[1]:string)
  begin
    recon_data := asciiread(rfile,-1,"string")
    if (var .eq. "lat") then
      return (stringtofloat(str_get_cols(recon_data, 9,15)))
    end if
    if (var .eq. "lon") then
      return (stringtofloat(str_get_cols(recon_data, 23,29)))
    end if
    ; optional handling here for "unknown variable name"
  end

Main script:

  lat = data_read(file,"lat")
  lon = data_read(file,"lon")

This might seem klunky, but it avoids predefinition tricks and is fairly
simple, given the constraints of NCL procedure calling.

--Dave


On Mon, Jul 2, 2018 at 2:10 PM, Vollaro, David <dvollaro at albany.edu> wrote:

> Hi,
>
>
> I have created a procedure to read an ASCII dataset.  The procedure will
> fill several 1D variable arrays and pass them back to the main NCL script.
> My problem is that the call statement contains several variables that have
> not been previously defined.  The length of these arrays will be determined
> in the procedure and is dataset dependent.  Is there a way to predefine a
> variable array w/o knowing its size?  Attached is a snippet of code:
>
>
> Dave Vollaro
>
> ...
>
> main script...
>
>
> data_read(file,lat,lon)
>
> ....
>
>  procedure data_read(rfile:string,rlat[*]:float,rlon[*]:float)
>  begin
>
>   recon_data   := asciiread(rfile,-1,"string")
>   rlat = stringtofloat(str_get_cols(recon_data, 9,15))
>   rlon = stringtofloat(str_get_cols(recon_data, 23,29))
>   return
>
>  end
> fatal:Variable (lat) is undefined
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180702/a39d3361/attachment.html>


More information about the ncl-talk mailing list