<div dir="ltr">Just in case if you need to return all values in A which exist in B (just a small modification from Alans)<div><br></div><div><div>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"</div><div><br></div><div>A = (/1990,1997,1999,2002,2002,2005,2010,2010/)</div><div>B = (/1993,1997,2002,2004/)</div><div>A_ind = get1Dindex(B,A) </div><div>i=ind(.not.ismissing(A_ind)) </div><div>r=A(i)</div><div>print(r)</div><div><br></div><div><div>Copyright (C) 1995-2015 - All Rights Reserved</div><div> University Corporation for Atmospheric Research</div><div> NCAR Command Language Version 6.3.0</div><div> The use of this software is governed by a License Agreement.</div><div> See <a href="http://www.ncl.ucar.edu/">http://www.ncl.ucar.edu/</a> for more details.</div><div><br></div><div><br></div><div>Variable: r</div><div>Type: integer</div><div>Total Size: 12 bytes</div><div> 3 values</div><div>Number of Dimensions: 1</div><div>Dimensions and sizes:<span class="" style="white-space:pre">        </span>[3]</div><div>Coordinates: </div><div>(0)<span class="" style="white-space:pre">        </span>1997</div><div>(1)<span class="" style="white-space:pre">        </span>2002</div><div>(2)<span class="" style="white-space:pre">        </span>2002</div></div><div><br></div><div style>Cheers,</div><div style>Thomas</div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 10, 2015 at 10:38 PM, Alan Brammer <span dir="ltr"><<a href="mailto:abrammer@albany.edu" target="_blank">abrammer@albany.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">I'm not sure which version of ncl you're using but those 3 lines work for me in 6.2.x and 6.3.0. </div><div class="gmail_default" style="font-family:verdana,sans-serif">The documentation for get1Dindex explicitly states that repeated values are allowed and the first occurrence is returned. </div><div class="gmail_default" style="font-family:verdana,sans-serif">That error usually means that A_ind already exists and has a different size to the return value. </div><div class="gmail_default" style="font-family:verdana,sans-serif">To be sure you can use the := operator to redefine the variable. </div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif"><p style="margin:0px;font-size:11px;font-family:Menlo">ncl </p>
<p style="margin:0px;font-size:11px;font-family:Menlo">ncl 0> A = (/1990,1997,1999,2002,2002,2005,2010,2010/)</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">ncl 1> B = (/1993,1997,2002,2004/) </p>
<p style="margin:0px;font-size:11px;font-family:Menlo">ncl 2> </p>
<p style="margin:0px;font-size:11px;font-family:Menlo">ncl 3> A_ind = get1Dindex(A,B) </p>
<p style="margin:0px;font-size:11px;font-family:Menlo">ncl 4> print(A_ind)</p>
<p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;font-family:Menlo;min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;font-family:Menlo">Variable: A_ind</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">Type: integer</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">Total Size: 16 bytes</p>
<p style="margin:0px;font-size:11px;font-family:Menlo"> 4 values</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">Number of Dimensions: 1</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">Dimensions and sizes:<span style="white-space:pre-wrap">        </span>[4]</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">Coordinates: </p>
<p style="margin:0px;font-size:11px;font-family:Menlo">Number Of Attributes: 3</p>
<p style="margin:0px;font-size:11px;font-family:Menlo"> _FillValue :<span style="white-space:pre-wrap">        </span>-<a href="tel:2147483647" value="+12147483647" target="_blank">2147483647</a></p>
<p style="margin:0px;font-size:11px;font-family:Menlo"> index_info :<span style="white-space:pre-wrap">        </span>Out of nWant=4 : multiple index occurrences=1</p>
<p style="margin:0px;font-size:11px;font-family:Menlo"> nMultInd :<span style="white-space:pre-wrap">        </span>1</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">(0)<span style="white-space:pre-wrap">        </span>-<a href="tel:2147483647" value="+12147483647" target="_blank">2147483647</a></p>
<p style="margin:0px;font-size:11px;font-family:Menlo">(1)<span style="white-space:pre-wrap">        </span>1</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">(2)<span style="white-space:pre-wrap">        </span>3</p>
<p style="margin:0px;font-size:11px;font-family:Menlo">(3)<span style="white-space:pre-wrap">        </span>-<a href="tel:2147483647" value="+12147483647" target="_blank">2147483647</a></p>
<p style="margin:0px;font-size:11px;font-family:Menlo">ncl 5> </p><div><br></div></div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On 10 June 2015 at 16:30, Xi Chang <span dir="ltr"><<a href="mailto:xi.chang01@gmail.com" target="_blank">xi.chang01@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><font face="georgia, serif">HI Alan,</font><div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif">Thanks, and I knew that. The problem is that I have file A containts repeatation years that make this function does not work properly, an example:</font></div><div><font face="georgia, serif"><br></font></div><div><p style="margin:0px"></p><p style="margin:0px"><font face="georgia, serif">ncl 7> A = (/1990,1997,1999,2002,2002,2005,2010,2010/)</font></p><p style="margin:0px"><font face="georgia, serif">ncl 8> B = (/1993,1997,2002,2004/) </font></p><p style="margin:0px"><font face="georgia, serif">ncl 9> </font></p><p style="margin:0px"><font face="georgia, serif">ncl 10> A_ind = get1Dindex(A,B) </font></p><p style="margin:0px"><font face="georgia, serif">fatal:Dimension sizes on right hand side of assignment do not match dimension sizes of left hand side</font></p><p style="margin:0px"><font face="georgia, serif">fatal:Execute: Error occurred at or near line 1242 in file $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl</font></p><p style="margin:0px"><font face="georgia, serif"><br></font></p><p style="margin:0px"><font face="georgia, serif">fatal:Execute: Error occurred at or near line 10</font></p><div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif">It seeems like this function does not allow repeatation of the year. any suggestion?></font></div><span><font color="#888888"><p></p></font></span></div><span><font color="#888888"><div class="gmail_extra"><font face="georgia, serif">Chang</font></div></font></span><div><div><div class="gmail_extra"><font face="georgia, serif"><br></font></div><div class="gmail_extra"><font face="georgia, serif"><br></font></div><div class="gmail_extra"><font face="georgia, serif"><br></font></div><div class="gmail_extra"><font face="georgia, serif"><br></font></div><div class="gmail_extra"><font face="georgia, serif"><br></font><div class="gmail_quote"><font face="georgia, serif">On Wed, Jun 10, 2015 at 10:18 PM, Alan Brammer <span dir="ltr"><<a href="mailto:abrammer@albany.edu" target="_blank">abrammer@albany.edu</a>></span> wrote:<br></font><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><font face="georgia, serif">Take look at get1Dindex linked below. It should do what you want. Below are a few quick example lines I threw together to get the matching indices for both A and B. </font></div><div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif"><a href="https://www.ncl.ucar.edu/Document/Functions/Contributed/get1Dindex.shtml" target="_blank">https://www.ncl.ucar.edu/Document/Functions/Contributed/get1Dindex.shtml</a><br></font></div><div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif">e.g.</font></div><div><p style="margin:0px"><font face="georgia, serif">A = (/1990,1997,1999,2002,2005,2010/)</font></p>
<p style="margin:0px"><font face="georgia, serif">B = (/1993,1997,2002,2004/) </font></p><div><p style="margin:0px"><font face="georgia, serif"><br></font></p></div><div><font face="georgia, serif">A_ind = get1Dindex(A,B) ;; array size B of where A is in B, Fill if not in B</font></div><div><font face="georgia, serif">A_ind_nm = A_ind(ind(.not.ismissing(A_ind))) ;; get rid of missing elements</font></div><div><font face="georgia, serif">Ca = A(A_ind_nm) ;; probably want an error check in case there are no overlaps. <br></font></div><div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif"> </font></div><div><div><font face="georgia, serif">B_ind = get1Dindex(B,A) ;; array size B of where A is in B, Fill if not in B</font></div><div><font face="georgia, serif">B_ind_nm = B_ind(ind(.not.ismissing(B_ind))) ;; get rid of missing elements</font></div><div><font face="georgia, serif">Cb = B(B_ind_nm) ;; probably want an error check in case there are no overlaps. </font></div></div><div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif">Gd Luck. </font></div><div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif">Alan. </font></div><div><font face="georgia, serif"><br></font></div></div></div><div class="gmail_extra"><font face="georgia, serif"><br></font><div class="gmail_quote"><div><div><font face="georgia, serif">On 10 June 2015 at 15:33, Xi Chang <span dir="ltr"><<a href="mailto:xi.chang01@gmail.com" target="_blank">xi.chang01@gmail.com</a>></span> wrote:<br></font></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr"><font face="georgia, serif">Hallo all,</font><div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif">Anyone can give me a hint how to get list of index for A which is associated with B,</font></div><div><font face="georgia, serif">for illustration:</font></div><div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif">file A containts :</font></div><div><font face="georgia, serif">-1990</font></div><div><font face="georgia, serif">-1997</font></div><div><font face="georgia, serif">-1999</font></div><div><font face="georgia, serif">-2002</font></div><div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif">file B</font></div><div><font face="georgia, serif">-1993</font></div><div><font face="georgia, serif">-1997</font></div><div><font face="georgia, serif">-2002</font></div><div><font face="georgia, serif">-2005</font></div><div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif">and in the end, will produce file C which only containts:</font></div><div><font face="georgia, serif">-1997</font></div><div><font face="georgia, serif">-2002</font></div><div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif">I cant do it mannually becaise the time series are too long..</font></div><div><font face="georgia, serif">any suggestion for a clean alogirhtm?</font></div><div><font face="georgia, serif"><br></font></div><div><font face="georgia, serif">Thanks</font></div><span><font color="#888888" face="georgia, serif"><div>Chang</div></font></span></div>
<font face="georgia, serif"><br></font></div></div><font face="georgia, serif">_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">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></font></blockquote></div><font face="georgia, serif"><br></font></div>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div>
</div></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>