<div dir="ltr">Hi Mary,<div><br></div><div>Thanks for looking at this. Unfortunately the idea you put forth doesn't work.</div><div>I played around with it and it was my thought to play around with the "where" statement, but the problem is that I need to find all the points in <span style="font-family:monospace,monospace;font-size:13px">mhs5_2d = a single value in </span><span style="font-family:monospace,monospace;font-size:13px">char AND all the points </span><span style="font-family:monospace,monospace;font-size:13px">tb5m4_2d = to a single value in darr. The way you did it doesn't work for the intended purpose, which is to produce an output similar to PDFXY, but returning the counts (sum) instead of a procent or fraction.</span></div><div><font face="monospace, monospace">Originally, mhm(4,:,:) doesn't have the same dimensions as darr and char, but I can easily change this. However, this doesn't solve the problem.</font></div><div><font face="monospace, monospace">If we take PDFXY as a template, how do I get PDFXY to return the counts?</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">/M </font></div><div><span style="font-family:monospace,monospace;font-size:13px"><br></span></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><font color="#0000ff">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</font></div><div><font color="#0000ff">Marston S. Johnston, PhD</font></div><div><font color="#0000ff">Department of Earth Sciences</font></div><div><font color="#0000ff">University of Gothenburg</font><span style="color:rgb(0,0,255)">, Sweden</span></div><div><font color="#0000ff">Email: <a href="mailto:marston.johnston@gu.se" target="_blank">marston.johnston@gu.se</a> </font></div><div><font color="#0000ff">Phone: +46-31-7864901 <br></font></div><div><font color="#0000ff">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</font></div><div><font color="#0000ff">Only the fruitful thing is true!</font></div></div></div></div></div></div>
<br><div class="gmail_quote">On Tue, Jul 26, 2016 at 6:55 PM, Mary Haley <span dir="ltr"><<a href="mailto:haley@ucar.edu" target="_blank">haley@ucar.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-size:small">Marston,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">In general, I recommend trying to use array arithmetic over looping, even if it means using extra memory to create 2D versions of 1D arrays.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">If you have enough memory to create 2D arrays of your various 1D arrays, then I recommend replacing all of the code after the last "copy_VarMeta" call with the following (UNTESTED) code:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">I'm not exactly sure I have all the dimensions of your various arrays correct, so this code may need some correction. For example, I don't know what the dimensions of "mhs" are, so I'm not sure that I have that part right. If mhs is already dimensioned ndarr x nchar, then the mhsx_2d lines should look simply like this:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><div class="gmail_default"><font face="monospace, monospace"> mhs5_2d := round(mhs(4,:,:),0)</font></div><div><font face="monospace, monospace"><br></font></div></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default"><font face="monospace, monospace">; Create 2D versions of these arrays for faster (?) calculations later </font></div><div class="gmail_default"><font face="monospace, monospace">dims_2d = (/ndarr,nchar/) </font></div><div class="gmail_default"><font face="monospace, monospace">mhs5_2d = conform_dims(</font><span style="font-family:monospace,monospace">dims_2d</span><font face="monospace, monospace">,round(ndtooned(mhs(4,:,:)),0),1)</font></div><div class="gmail_default"><font face="monospace, monospace">mhs4_2d = conform_dims(</font><span style="font-family:monospace,monospace">dims_2d</span><font face="monospace, monospace">,round(ndtooned(mhs(3,:,:)),0),1)</font></div><div class="gmail_default"><font face="monospace, monospace">mhs3_2d = conform_dims(</font><span style="font-family:monospace,monospace">dims_2d</span><font face="monospace, monospace">,round(ndtooned(mhs(2,:,:)),0),1)</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">tb5m4_2d = conform_dims(</font><span style="font-family:monospace,monospace">dims_2d</span><font face="monospace, monospace">,round(ndtooned(tb5m4),0),0)</font></div><div class="gmail_default"><font face="monospace, monospace">tb5m3_2d = conform_dims(</font><span style="font-family:monospace,monospace">dims_2d</span><font face="monospace, monospace">,round(ndtooned(tb5m3),0),0)</font></div><div class="gmail_default"><font face="monospace, monospace">tb4m3_2d = conform_dims(</font><span style="font-family:monospace,monospace">dims_2d</span><font face="monospace, monospace">,round(ndtooned(tb4m3),0),0)</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">darr_2d = conform_dims(</font><span style="font-family:monospace,monospace">dims_2d</span><font face="monospace, monospace">,darr,0)</font></div><div class="gmail_default"><font face="monospace, monospace">char_2d = conform_dims(</font><span style="font-family:monospace,monospace">dims_2d</span><font face="monospace, monospace">,char,1)</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">; This creates a 2D logical array of Trues/Falses</font></div><div class="gmail_default"><font face="monospace, monospace">mhs5_eq_char = </font><span style="font-family:monospace,monospace">mhs5_2d .eq. char_2d</span></div><div class="gmail_default"><span style="font-family:monospace,monospace"><br></span></div><div class="gmail_default"><font face="monospace, monospace">; Create 2D arrays containing 1s and 0s</font></div><div class="gmail_default"><font face="monospace, monospace">tmp5 = where(mhs5_eq_char .and. tb5m4_2d .eq. darr_2d, 1, 0)</font></div><div class="gmail_default"><font face="monospace, monospace">tmp4 = where(mhs5_eq_char .and. tb5m3_2d .eq. darr_2d, 1, 0)</font></div><div class="gmail_default"><font face="monospace, monospace">tmp3 = where(</font><span style="font-family:monospace,monospace">mhs5_eq_char</span><font face="monospace, monospace"> .and. tb4m3_2d .eq. darr_2d, 1, 0)</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">hist5m4 = hist5m4 + tmp5</font></div><div class="gmail_default"><font face="monospace, monospace">hist5m3 = hist5m3 + tmp4</font></div><div class="gmail_default"><font face="monospace, monospace">hist4m3 = hist4m3 + tmp3<span style="font-size:small"></span></font></div><div class="gmail_default"><span style="font-size:small"><br></span></div><div class="gmail_default"><span style="font-size:small"><font face="monospace, monospace">delete([/</font></span><span style="font-family:monospace,monospace">mhs5_eq_char,</span><span style="font-family:monospace,monospace">mhs5_2d,mhs4_2d,mhs3_2d,darr_2d,char_2d,tmp5,tmp4,tmp3/])</span></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Tue, Jul 26, 2016 at 6:05 AM, Marston Johnston <span dir="ltr"><<a href="mailto:shejo284@gmail.com" target="_blank">shejo284@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div><div>Hi,<br><br></div>I'm wondering if there is a way to speed up the do loops in the code below?<br></div>I'm not sure it can be done, but I'm not an expert. <br><div><br></div><div>;***** 2D histogram ******<br></div><div>; x and y axis<br></div><div>darr = ispan(-80,80,1)<br>sarr = new(dimsizes(darr),string)<br>sarr = " "<br>char = ispan(150,300,1)<br><br></div><div>; histogram bins<br></div><div>hist5m4 = new((/dimsizes(darr),dimsizes(char)/),float)<br>hist5m4@_FillValue = default_fillvalue("float")<br>hist5m4!0 = "diff"<br>hist5m4!1 = "Tb"<br>hist5m4&diff = darr<br>hist5m4&Tb = char<br>ndarr = dimsizes(darr)<br>nchar = dimsizes(char)<br>hist5m4 = 0.0<br>hist5m3 = hist5m4<br>hist5m3 = 0.0<br>hist4m3 = hist5m4<br>hist4m3 = 0.0<br><br>tb5m4 = mhs(4,:,:) - mhs(3,:,:)<br>copy_VarMeta(mhs(3,:,:),tb5m4)<br>tb5m3 = mhs(4,:,:) - mhs(2,:,:)<br>copy_VarMeta(mhs(2,:,:),tb5m3)<br>tb4m3 = mhs(3,:,:) - mhs(2,:,:)<br>copy_VarMeta(mhs(2,:,:),tb5m3)<br><br>mhs5 := round(ndtooned(mhs(4,:,:)),0)<br>mhs4 := round(ndtooned(mhs(3,:,:)),0)<br>mhs3 := round(ndtooned(mhs(2,:,:)),0)<br><br>tb5m4 := round(ndtooned(tb5m4),0)<br>tb5m3 := round(ndtooned(tb5m3),0)<br>tb4m3 := round(ndtooned(tb4m3),0)<br><br>; print(darr(y)+" <= DARR:CH5AR => "+ch5ar(x))<br></div><div>; Fill the bins<br></div><div>do x = 0, nchar - 1<br> do y = 0, ndarr - 1<br> tmp := ind(mhs5.eq.char(x) .and. tb5m4.eq.darr(y))<br> if(dimsizes(tmp).gt.1) then<br> hist5m4(y,x) = hist5m4(y,x) + (dimsizes(tmp) - 1)<br> end if<br> tmp := ind(mhs5.eq.char(x) .and. tb5m3.eq.darr(y))<br> if(dimsizes(tmp).gt.1) then<br> hist5m3(y,x) = hist5m3(y,x) + (dimsizes(tmp) - 1)<br> end if<br> tmp := ind(mhs4.eq.char(x) .and. tb4m3.eq.darr(y))<br> if(dimsizes(tmp).gt.1) then<br> hist4m3(y,x) = hist4m3(y,x) + (dimsizes(tmp) - 1)<br> end if<br> end do<br>end do<br><div><div><br></div><div>Appreciate your help with this,<br></div><div>/M<br clear="all"></div><div><div><div><div dir="ltr"><div><div dir="ltr"><div><font color="#0000ff">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</font></div><div><font color="#0000ff">Marston S. Johnston, PhD</font></div><div><font color="#0000ff">Department of Earth Sciences</font></div><div><font color="#0000ff">University of Gothenburg</font><span style="color:rgb(0,0,255)">, Sweden</span></div><div><font color="#0000ff">Email: <a href="mailto:marston.johnston@gu.se" target="_blank">marston.johnston@gu.se</a> </font></div><div><font color="#0000ff">Phone: <a href="tel:%2B46-31-7864901" value="+46317864901" target="_blank">+46-31-7864901</a> <br></font></div><div><font color="#0000ff">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</font></div><div><font color="#0000ff">Only the fruitful thing is true!</font></div></div></div></div></div></div>
</div></div></div></div>
<br></div></div>_______________________________________________<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" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>