<div dir="ltr"><div><div><div><div><div><div>Will, Walt<br><br></div>To my knowledge there is no &#39;simple&#39; way to do what Will originally posted.<br><br></div><div>Walt&#39;s &#39;flattening&#39; suggestion would be &#39;clean&#39; 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 &#39;flat&#39; array. <br></div>--<br><br></div>re: WH&#39;s comment: &quot;particularly &#39;clean&#39; or efficient code&quot;<br><br></div>The nested &#39;if&#39; approach is certainly cumbersome <br><br>if (rankx.eq.1) then<br>    ...<br></div>end if <br>if (rankx.eq.2) then<br>    ...<br>end if <br>if (rankx.eq.3) then<br>    ...<br>end if <br>if (rankx.eq.4) then<br>    ...<br>end if <br><br></div>but I don&#39;t think it is particularly inefficient. <br><div> <br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 2, 2015 at 11:09 AM, Walter Kolczynski <span dir="ltr">&lt;<a href="mailto:walter.kolczynski@noaa.gov" target="_blank">walter.kolczynski@noaa.gov</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    Will,<br>
    <br>
    Depending on what you are doing, you might be able to flatten into a
    lower dimensional array, do whatever operation, then convert back.
    I&#39;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:<br>
    <br>
    <tt>[user@machine ~]$ ncl</tt><tt><br>
    </tt><tt> Copyright (C) 1995-2014 - All Rights Reserved</tt><tt><br>
    </tt><tt> University Corporation for Atmospheric Research</tt><tt><br>
    </tt><tt> NCAR Command Language Version 6.2.0</tt><tt><br>
    </tt><tt> The use of this software is governed by a License
      Agreement.</tt><tt><br>
    </tt><tt> See <a href="http://www.ncl.ucar.edu/" target="_blank">http://www.ncl.ucar.edu/</a> for more details.</tt><tt><br>
    </tt><tt>ncl 0&gt; load &quot;takeSample.ncl&quot;</tt><tt><br>
    </tt><tt>ncl 1&gt; test_takeSample()</tt><br>
    <br>
    - Walter<div><div class="h5"><br>
    <br>
    <div>On 02-Jun-15 02:43, Will Hobbs wrote:<br>
    </div>
    </div></div><blockquote type="cite"><div><div class="h5">
      
      <div>Hi all</div>
      <div><br>
      </div>
      <div>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.</div>
      <div><br>
      </div>
      <div><span style="white-space:pre-wrap"></span>function

        generic_example(input:numeric)</div>
      <div><br>
      </div>
      <div><span style="white-space:pre-wrap"></span>begin</div>
      <div><span style="white-space:pre-wrap"></span></div>
      <div><span style="white-space:pre-wrap"></span> 
        output = some_subset_of_(input)</div>
      <div><span style="white-space:pre-wrap"></span>  </div>
      <div><span style="white-space:pre-wrap"></span>  return(output)<span style="white-space:pre-wrap"> </span></div>
      <div>        end</div>
      <div><br>
      </div>
      <div>where input/output might be 1, 2, 3, 4 or more dimensions,
        and so a different line is needed to do the subsetting step.</div>
      <div><br>
      </div>
      <div>At the moment I just use nested &#39;if&#39; 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 &#39;clean&#39; or efficient code, so I wonder
        if anyone has any nicer ways of doing this.</div>
      <div><br>
      </div>
      <div>Many thanks</div>
      <div><br>
      </div>
      <div>Will</div>
      <p><br>
        <br>
        University of Tasmania Electronic Communications Policy
        (December, 2014). <br>
        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. </p>
      <br>
      <fieldset></fieldset>
      <br>
      </div></div><pre>_______________________________________________
ncl-talk mailing list
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>
List instructions, subscriber options, unsubscribe:
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><span class="HOEnZb"><font color="#888888">
</font></span></pre><span class="HOEnZb"><font color="#888888">
    </font></span></blockquote><span class="HOEnZb"><font color="#888888">
    <br>
    <pre cols="72">-- 
Walter Kolczynski, Jr.
Global Ensemble Team
NOAA/NWS/NCEP/EMC (via I.M. Systems Group)
<a href="tel:%28301%29%20683-3781" value="+13016833781" target="_blank">(301) 683-3781</a></pre>
  </font></span></div>

<br>_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>