<div dir="ltr">To get the max index out of a 2D array, you need to use a combination of ndtooned, maxind, and ind_resolve.<div><br></div><div>If "qi" is the variable you want the maximum from, then here's a three-step process. </div>
<div><br></div><div> dims = dimsizes(qi) ; 1D array containing the three dimension sizes </div><div><br></div><div><div> qi1d = ndtooned(qi(it,:,:)) ; convert to one-dimensional array</div></div><div><div> ii = maxind(qi1d) ; get index where first maximum value occurs</div>
</div><div><div> ij= ind_resolve(ii,dims) ; resolve back to original 2D array index locations</div></div><div><br></div><div>The "ij" should be a 1 x 2 array, where ij(0,0) is the index of the middle dimension, and ij(0,1) is the index of the rightmost dimension of "qi"</div>
<div><br></div><div>Here's one-step process you can use:</div><div><br></div><div><div> ij= ind_resolve(maxind(ndtooned(qi(it,:,:))),dims(1:2))</div></div><div><br></div><div>You can print the results with:</div><div>
<br></div><div> print("max qi = " + qi(it,ij(0,0),ij(0,1)) + " at indexes " + ij(0,0) + "," + ij(0,1))</div><div><br></div><div>To then get the lat,lon location of this ij location, use wrf_user_ij_to_ll</div>
<div><br></div><div>
<p class=""> latlon = wrf_user_ij_to_ll(a, ij(0,0), ij(0,1), True)</p><p class=""> print("lon location is: " + latlon(0))</p><p class=""> print("lat location is: " + latlon(1))<br><br></p><p class="">
--Mary</p></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 1, 2014 at 2:25 AM, grace <span dir="ltr"><<a href="mailto:313695096@qq.com" target="_blank">313695096@qq.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><font size="3"><span style="line-height:24px">Hi,all</span></font><div><font size="3"><span style="line-height:24px"> I have calculated the max Qgraup of each time from the wrfout data with the following program,</span></font></div>
<div><font size="3"><span style="line-height:24px">but how can I know the (i,j)or (lat,lon) of the max <span style="line-height:0px"></span></span></font><span style="font-size:medium;line-height:24px">Qgraup of each time?<span style="line-height:0px"></span></span></div>
<div><span style="font-size:medium;line-height:24px">any information will be appreciated!</span></div><div><font size="3"><span style="line-height:24px"><br></span></font></div><div><font size="3"><div> ascii_file = "shishidataGRAUP1B333.txt"</div>
<div> str = new(ntimes, "string")</div><div><span style="line-height:0px"></span> do it =0, ntimes-1,1 ; TIME LOOP</div><div style="line-height:24px"><br></div><div style="line-height:24px"> print("Working on time: " + times(it) )</div>
<div style="line-height:24px"> res@TimeLabel = times(it) ; Set Valid time to use on plots</div><div style="line-height:24px"><br></div><div style="line-height:24px">;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</div>
<div style="line-height:24px">; First get the variables we will need </div><div style="line-height:24px"> if(isfilevar(a,"QGRAUP"))</div><div style="line-height:24px"> qi = wrf_user_getvar(a,"QGRAUP",it)</div>
<div style="line-height:24px"> qi = qi*1000.</div><div style="line-height:24px"> qi@units = "g/kg" </div><div style="line-height:24px"><span style="white-space:pre-wrap">        </span> qis=dim_max_n_Wrap(qi(13:15,:,:),0)</div>
<div style="line-height:24px"> end if</div><div style="line-height:24px"><span style="white-space:pre-wrap">        </span>;print(qis)</div><div style="line-height:24px"><span style="white-space:pre-wrap">        </span>printVarSummary(qis)</div>
<div style="line-height:24px"> wmax1 = dim_max_n_Wrap(qis(:,:),0)</div><div style="line-height:24px"><span style="white-space:pre-wrap">        </span>;print(wmax1)</div><div style="line-height:24px"><span style="white-space:pre-wrap">        </span>printVarSummary(wmax1)</div>
<div style="line-height:24px"> wmax2 = dim_max_n_Wrap(qis,0)</div><div style="line-height:24px"><span style="white-space:pre-wrap">        </span>;print(wmax2)</div><div style="line-height:24px"><span style="white-space:pre-wrap">        </span>printVarSummary(wmax2)</div>
<div style="line-height:24px"> wmax=max(wmax2)<span style="line-height:0px"></span></div><div> str(it) = sprintf("%12.8f", wmax)<span style="line-height:0px"></span></div></font></div><br>_______________________________________________<br>
ncl-talk mailing list<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>