<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I’ve had weird issues with bin_sum() and looping over arrays in the past. &nbsp;<div class="">My solution has usually been to pass a temporary variable to bin_sum() then set your GBIN array to that temp variable.&nbsp;</div><div class=""><br class=""></div><div class="">e.g. &nbsp;unchanged lines omitted for brevity.&nbsp;</div><div class=""><br class=""></div><div class="">&nbsp;do nf=0,nfil-1<br class=""><div class="gmail_quote"><div class="gmail_quote"><div class="gmail_extra"><div class="gmail_quote"><div dir="ltr" class=""><div class=""><div class="">&nbsp; &nbsp;do lev=0,nlev-1</div></div></div></div></div></div></div></div><div class=""><br class=""></div><div class="">….</div><div class="">tmp_var = GBIN(lev,:,:)<span class="Apple-tab-span" style="white-space:pre">                        </span>;; This could be defined outside of loop and just reset to zero for each loop.&nbsp;</div><div class="">tmp_var = 0</div><div class="">tmp_ct = toint(tmp_var)<span class="Apple-tab-span" style="white-space:pre">                        </span>;; as above doesn’t need to be redefined each loop just set to 0 each time.&nbsp;</div><div class=""><br class=""></div><div class="">bin_sum(tmp_var, tmp_ct, ,lon,lat , ndtooned(lon2d),ndtooned(lat2d),ndtooned(x) )</div><div class=""><br class=""></div><div class="">GBIN(lev,:,:) = tmp_var</div><div class="">GKNT(lev,:,:) = tmp_ct</div><div class="">…</div><div class="">end</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Alan</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">##############################<br class="">Alan Brammer,<div class="">Post-Doc Researcher</div><div class=""><br class=""></div><div class="">Department of Atmospheric and&nbsp;Environmental Sciences,<br class="">University at Albany,&nbsp;State University of New&nbsp;York,&nbsp;Albany, NY, 12222<div class=""><a href="mailto:abrammer@albany.edu" class="">abrammer@albany.edu</a><br class="">##############################</div></div></div></span></div></div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On 3 May 2016, at 04:43, AJILESH PP &lt;<a href="mailto:ajileshparolla@gmail.com" class="">ajileshparolla@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi all, I modified the loop, but still I'm getting same data values on all 20 levels. Can anybody please tell me where I went wrong?&nbsp;</div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Sat, 23 Apr 2016 at 02:41 AJILESH PP &lt;<a href="mailto:ajileshparolla@gmail.com" class="">ajileshparolla@gmail.com</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Hi,<div class="">Thank You for the prompt reply. Sorry for the mistake, Now loop is working output has 20 levels, but all the levels have the same data values (all levels are same).&nbsp;</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Thu, 21 Apr 2016 at 20:56 Rick Brownrigg &lt;<a href="mailto:brownrig@ucar.edu" target="_blank" class="">brownrig@ucar.edu</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class="">Hi,<br class=""><br class=""></div>I'm not totally sure, but I wonder if "level" in this line should be "lev"?</div></div></div></div><div dir="ltr" class=""><div class=""><div class=""><div class=""><br class=""><br class="">bin_sum(GBIN(level,:,:),GKNT(level,:,:),lon,lat \<br class=""><br class=""></div></div></div></div><div dir="ltr" class=""><div class=""><div class=""><div class=""></div>In any case, a few strategic print() statements on your indexing variables will show where/when thing go arwy.<br class=""><br class=""></div>HTH...<br class=""></div>Rick<br class=""><br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote"></div></div><div class="gmail_extra"><div class="gmail_quote">On Thu, Apr 21, 2016 at 7:10 AM, AJILESH PP <span dir="ltr" class="">&lt;<a href="mailto:ajileshparolla@gmail.com" target="_blank" class="">ajileshparolla@gmail.com</a>&gt;</span> wrote:<br class=""></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><span style="color:rgb(33,33,33);font-size:13px" class="">Dear all</span><br class=""><div class="">I want to bin MODIS level 2 products for a period of time. I modified an example script given in ncl HDF examples and it is giving me only output of a single level, where the desired output is for 20 levels. I tried to add a level loop and level dimension also as shown in the script below.&nbsp;</div><div class=""><div class="">--------------------------------------</div><div class=""><div class="">&nbsp; GBIN &nbsp;= new ( (/nlev,nlat,mlon/), float )</div><div class="">&nbsp; GKNT &nbsp;= new ( (/nlev,nlat,mlon/), integer )</div></div><div class=""><br class=""></div><div class="">snip</div><div class=""><br class=""></div><div class="">&nbsp;do nf=0,nfil-1</div><div class="">&nbsp; &nbsp;do lev=0,nlev-1</div><div class="">&nbsp; &nbsp; &nbsp;print(nf+" &nbsp; "+fili(nf))</div><div class="">&nbsp; &nbsp; &nbsp;f &nbsp; &nbsp; &nbsp; = addfile(diri+fili(nf), "r")</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; read data</div><div class="">&nbsp; &nbsp; &nbsp;x &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= short2flt_hdf( f-&gt;$vNam$ )</div><div class="">&nbsp; &nbsp; &nbsp;lat2d1 &nbsp; &nbsp; = f-&gt;Latitude</div><div class="">&nbsp; &nbsp; &nbsp;lon2d1 &nbsp; &nbsp; = f-&gt;Longitude</div><div class="">&nbsp; &nbsp; &nbsp;lat2d &nbsp; &nbsp; &nbsp;= conform(x,lat2d1,(/1,2/))</div><div class="">&nbsp; &nbsp; &nbsp;lon2d &nbsp; &nbsp; &nbsp;= conform(x,lon2d1,(/1,2/))</div><div class="">&nbsp; &nbsp; &nbsp;level &nbsp; &nbsp; &nbsp; &nbsp;= (/1000,950,920,850,700,620,500,400,300,250,200,100,150,100,70,50,30,20,10,5/)</div><div class="">&nbsp; &nbsp; &nbsp;x!0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= "level"</div><div class="">&nbsp; &nbsp; &nbsp;x&amp;level &nbsp; &nbsp; &nbsp;= level</div><div class="">&nbsp; &nbsp; &nbsp;nx &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = product(dimsizes(x))</div><div class="">&nbsp; &nbsp; bin_sum(GBIN(level,:,:),GKNT(level,:,:),lon,lat \</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;,ndtooned(lon2d),ndtooned(lat2d),ndtooned(x) )</div><div class="">printVarSummary(x)</div></div><div class="">---------------------------------------</div><div class=""><div class="">but it is giving this error:</div><div class="">fatal:Subscript out of range, error in subscript #0</div><div class="">fatal:An error occurred reading GBIN</div><div class=""><br class=""></div><div class="">Can anybody help me to resolve this issue?&nbsp;</div><div class="">Please find my script and data as follows&nbsp;</div></div><div class="">Data: &nbsp; MOD07_L2.A2012166.0*.hdf<br class=""></div><div class="">Script: &nbsp;bin.ncl</div><div class=""><br class=""></div><div class="">Any help would be appreciated</div><div class="">Thank You!</div></div>
<br class=""></blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">_______________________________________________<br class="">
ncl-talk mailing list<br class="">
<a href="mailto:ncl-talk@ucar.edu" target="_blank" class="">ncl-talk@ucar.edu</a><br class="">
List instructions, subscriber options, unsubscribe:<br class="">
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank" class="">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</blockquote></div></blockquote></div>
_______________________________________________<br class="">ncl-talk mailing list<br class=""><a href="mailto:ncl-talk@ucar.edu" class="">ncl-talk@ucar.edu</a><br class="">List instructions, subscriber options, unsubscribe:<br class="">http://mailman.ucar.edu/mailman/listinfo/ncl-talk<br class=""></div></blockquote></div><br class=""></div></body></html>