<div dir="ltr"><div><div><div><div><div><div>[1] You should use print statements to discover the error. Then ... actually look at what is being printed out. Then see if your code is consistent with what is being printed; then carefully look at the function documentation. Look carefully at the content{ sizes, dimension ordering .... <br><br></div><div>[2] Look at <br> x = short2flt_hdf( f->$vNam$ ) <=== 3D (20,406,270)<br></div><div> printVarSummary(x)<br></div><br></div><div>[snip]<br><br></div> printVarSummary(GBIN(lev,:,:)) <=== 2D (406,270))<br><br></div> work = ndtooned(lon2d) <=== 1D (406*270) <br></div> printVarSummary(work)<br><br></div> WORK = ndtooned(x) <=== 1D (20*406*270)<br></div> printVarSummary(WORK)<br><br><div><div><div><div><div><div> bin_sum(GBIN(lev,:,:),GKNT(lev,:,:),lon,lat \</div><div> ,ndtooned(lon2d),ndtooned(lat2d),ndtooned(x) )<br><br></div><div>It should be <br><br> bin_sum(GBIN(lev,:,:),GKNT(lev,:,:),lon,lat \ <br> ,ndtooned(lon2d),ndtooned(lat2d),ndtooned(x(lev,:,:) )<br><br></div><div>The function has gbin and gknt as 2-D ===> gbin [*][*]<br><pre>        procedure bin_sum (
                gbin [*][*] : numeric ,
                gknt [*][*] : integer ,
                glon [*] : numeric ,
                glat [*] : numeric ,
                zlon [*] : numeric ,
                zlat [*] : numeric ,
                z [*] : numeric
        )
</pre>zlon, zlat and z MUST be the same length.<br><br></div><div>Also, ..... the original code could be substantially improved. NOTE that the code has<br>comments inserted next to each line. This helps debug!!!<br><br><br> do nf=0,nfil-1<br> print(nf+" "+fili(nf))<br> f = addfile(diri+fili(nf)+".he2", "r") ; add virtual attribute<br> x = short2flt_hdf( f->$vNam$ ) ; (level=20, latitude=270, longitude=406)<br> latx = ndtooned(f->Latitude_mod07) ; latx(406*270) <== (latitude=270, longitude=406)<br> lonx = ndtooned(f->Longitude_mod07) ; lonx " " "<br> ; lonx(109620)<br> if (nf.eq.0) then<br> printVarSummary(x)<br> printMinMax(x, 1)<br> print("nlatx="+dimsizes(latx)+" mlonx="+dimsizes(lonx))<br> end if<br><br> do lev=0,nlev-1<br> bin_sum(GBIN(lev,:,:),GKNT(lev,:,:),lon,lat, lonx,latx,ndtooned(x(lev,:,:)) )<br> end do<br> end do<br><br></div><div>I attached a code .. I suggest you look at it ... *carefully***<br><br><br></div><div><br></div></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 3, 2016 at 7:15 AM, 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 style="word-wrap:break-word">I’ve had weird issues with bin_sum() and looping over arrays in the past. <div>My solution has usually been to pass a temporary variable to bin_sum() then set your GBIN array to that temp variable. </div><div><br></div><div>e.g. unchanged lines omitted for brevity. </div><div><br></div><div> do nf=0,nfil-1<br><div class="gmail_quote"><div class="gmail_quote"><div class="gmail_extra"><div class="gmail_quote"><div dir="ltr"><div><div> do lev=0,nlev-1</div></div></div></div></div></div></div></div><div><br></div><div>….</div><div>tmp_var = GBIN(lev,:,:)<span style="white-space:pre-wrap">                        </span>;; This could be defined outside of loop and just reset to zero for each loop. </div><div>tmp_var = 0</div><div>tmp_ct = toint(tmp_var)<span style="white-space:pre-wrap">                        </span>;; as above doesn’t need to be redefined each loop just set to 0 each time. </div><div><br></div><div>bin_sum(tmp_var, tmp_ct, ,lon,lat , ndtooned(lon2d),ndtooned(lat2d),ndtooned(x) )</div><div><br></div><div>GBIN(lev,:,:) = tmp_var</div><div>GKNT(lev,:,:) = tmp_ct</div><div>…</div><div>end</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div>Alan</div><div><br></div><div><br></div><div><br><div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><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;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><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;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;border-spacing:0px"><div style="word-wrap:break-word">##############################<br>Alan Brammer,<div>Post-Doc Researcher</div><div><br></div><div>Department of Atmospheric and Environmental Sciences,<br>University at Albany, State University of New York, Albany, NY, 12222<div><a href="mailto:abrammer@albany.edu" target="_blank">abrammer@albany.edu</a><br>##############################</div></div></div></span></div></div>
</div><div><div class="h5">
<br><div><blockquote type="cite"><div>On 3 May 2016, at 04:43, AJILESH PP <<a href="mailto:ajileshparolla@gmail.com" target="_blank">ajileshparolla@gmail.com</a>> wrote:</div><br><div><div dir="ltr">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? </div><br><div class="gmail_quote"><div dir="ltr">On Sat, 23 Apr 2016 at 02:41 AJILESH PP <<a href="mailto:ajileshparolla@gmail.com" target="_blank">ajileshparolla@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div>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). </div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, 21 Apr 2016 at 20:56 Rick Brownrigg <<a href="mailto:brownrig@ucar.edu" target="_blank">brownrig@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Hi,<br><br></div>I'm not totally sure, but I wonder if "level" in this line should be "lev"?</div></div></div></div><div dir="ltr"><div><div><div><br><br>bin_sum(GBIN(level,:,:),GKNT(level,:,:),lon,lat \<br><br></div></div></div></div><div dir="ltr"><div><div><div></div>In any case, a few strategic print() statements on your indexing variables will show where/when thing go arwy.<br><br></div>HTH...<br></div>Rick<br><br></div><div class="gmail_extra"><br><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"><<a href="mailto:ajileshparolla@gmail.com" target="_blank">ajileshparolla@gmail.com</a>></span> wrote:<br></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"><span style="color:rgb(33,33,33);font-size:13px">Dear all</span><br><div>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. </div><div><div>--------------------------------------</div><div><div> GBIN = new ( (/nlev,nlat,mlon/), float )</div><div> GKNT = new ( (/nlev,nlat,mlon/), integer )</div></div><div><br></div><div>snip</div><div><br></div><div> do nf=0,nfil-1</div><div> do lev=0,nlev-1</div><div> print(nf+" "+fili(nf))</div><div> f = addfile(diri+fili(nf), "r")</div><div> ; read data</div><div> x = short2flt_hdf( f->$vNam$ )</div><div> lat2d1 = f->Latitude</div><div> lon2d1 = f->Longitude</div><div> lat2d = conform(x,lat2d1,(/1,2/))</div><div> lon2d = conform(x,lon2d1,(/1,2/))</div><div> level = (/1000,950,920,850,700,620,500,400,300,250,200,100,150,100,70,50,30,20,10,5/)</div><div> x!0 = "level"</div><div> x&level = level</div><div> nx = product(dimsizes(x))</div><div> bin_sum(GBIN(level,:,:),GKNT(level,:,:),lon,lat \</div><div> ,ndtooned(lon2d),ndtooned(lat2d),ndtooned(x) )</div><div>printVarSummary(x)</div></div><div>---------------------------------------</div><div><div>but it is giving this error:</div><div>fatal:Subscript out of range, error in subscript #0</div><div>fatal:An error occurred reading GBIN</div><div><br></div><div>Can anybody help me to resolve this issue? </div><div>Please find my script and data as follows </div></div><div>Data: MOD07_L2.A2012166.0*.hdf<br></div><div>Script: bin.ncl</div><div><br></div><div>Any help would be appreciated</div><div>Thank You!</div></div>
<br></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>
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></blockquote></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" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br></div></blockquote></div><br></div></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" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>