[ncl-talk] functions handling input of unknown dimension

Dennis Shea shea at ucar.edu
Wed Jun 3 10:12:41 MDT 2015


Will, Walt

To my knowledge there is no 'simple' way to do what Will originally posted.

Walt's 'flattening' suggestion would be 'clean' if it is general and hidden
with a simple interface. However, I am not sure that it would be more
efficient. More memory would be required for the 'flat' array.
--

re: WH's comment: "particularly 'clean' or efficient code"

The nested 'if' approach is certainly cumbersome

if (rankx.eq.1) then
    ...
end if
if (rankx.eq.2) then
    ...
end if
if (rankx.eq.3) then
    ...
end if
if (rankx.eq.4) then
    ...
end if

but I don't think it is particularly inefficient.


On Tue, Jun 2, 2015 at 11:09 AM, Walter Kolczynski <
walter.kolczynski at noaa.gov> wrote:

>  Will,
>
> Depending on what you are doing, you might be able to flatten into a lower
> dimensional array, do whatever operation, then convert back. I've attached
> an example to get you started: it returns a random sample in the left-most
> dimension of any 2+ dimensional array. To run it just go into an
> interactive NCL session, load the file, and run the test procedure:
>
> [user at machine ~]$ ncl
>  Copyright (C) 1995-2014 - All Rights Reserved
>  University Corporation for Atmospheric Research
>  NCAR Command Language Version 6.2.0
>  The use of this software is governed by a License Agreement.
>  See http://www.ncl.ucar.edu/ for more details.
> ncl 0> load "takeSample.ncl"
> ncl 1> test_takeSample()
>
> - Walter
>
>
> On 02-Jun-15 02:43, Will Hobbs wrote:
>
> Hi all
>
>  I wonder if anyone has any suggestions for a generic way of writing
> functions that deal with input/output arrays which may have different
> numbers of dimensions, e.g.
>
>  function generic_example(input:numeric)
>
>  begin
>    output = some_subset_of_(input)
>
>   return(output)
>         end
>
>  where input/output might be 1, 2, 3, 4 or more dimensions, and so a
> different line is needed to do the subsetting step.
>
>  At the moment I just use nested 'if' statements based on the rank of the
> array (where rank is the number of dimensions, i.e. dimsizes(dim
> sizes(input)), and this works fine. But, it does not make for particularly
> 'clean' or efficient code, so I wonder if anyone has any nicer ways of
> doing this.
>
>  Many thanks
>
>  Will
>
>
>
> University of Tasmania Electronic Communications Policy (December, 2014).
> This email is confidential, and is for the intended recipient only.
> Access, disclosure, copying, distribution, or reliance on any of it by
> anyone outside the intended recipient organisation is prohibited and may be
> a criminal offence. Please delete if obtained in error and email
> confirmation to the sender. The views expressed in this email are not
> necessarily the views of the University of Tasmania, unless clearly
> intended otherwise.
>
>
> _______________________________________________
> ncl-talk mailing listncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
> --
> Walter Kolczynski, Jr.
> Global Ensemble Team
> NOAA/NWS/NCEP/EMC (via I.M. Systems Group)(301) 683-3781
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150603/92a38701/attachment.html 


More information about the ncl-talk mailing list