<div>Hi!</div><div><br></div><div>I&#39;ve been trying to create my very first GrADS-script. The script should compute values of the bulk Richardson number in a specific grid point between predefined model levels and then find the minimum value of Ri and probably the model level associated with it.</div>
<div><br></div><div>I tried to do this using while and if loops, but for some reason it&#39;s not working as I expected. Maybe I can&#39;t understand handling variables in GrADS?</div><div><br></div><div>In this script the top and the bottom model layers are set to 40 and 50. Ri is computed and I get a list of the Ri at different levels, and they seem to be ok. However the variable &quot;minri&quot; gets always the value of ri at the lowest model level (here: ri at level 50). Variable &quot;minlevel&quot; is always the highest model level (here: level 40)!</div>
<div><br></div><div>When count is 40 at the first step of the while-loop, the value of ri should be saved into variable minri and the model level at minlev. After that, if ri &lt; minri at lower levels (count &gt; 40), values of minri and minlev should be varied by the second if-loop...</div>
<div><br></div><div>Is there a more simple or more correct way to do this? I thought max() can&#39;t make it...</div><div><br></div><div>Any help is much appreciated! </div><div><br></div><div>Best regards, Lippo</div><div>
<br></div><div>(version of GrADS 2.0.a1)</div><div><br></div><div><div>&#39;set lat 50.00&#39;</div><div>&#39;set lon 10.00&#39;</div><div>botlevel=50</div><div>toplevel=40</div><div><br></div><div>count=toplevel</div><div>
<br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>while (count &lt;= botlevel)</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&#39;set lev &#39;count</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>&#39;define th1 = temp * (pow(100000 / press , (0.286)))&#39;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&#39;define u1 = u&#39;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>&#39;define v1 = v&#39;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&#39;define z1 = geopot/9.81&#39;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&#39;set lev &#39;count - 1</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>&#39;define th2 = temp * (pow(100000 / press , (0.286)))&#39;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&#39;define u2 = u&#39;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>&#39;define v2 = v&#39;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&#39;define z2 = geopot/9.81&#39;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&#39;define ri=9.81/(0.5*th1+th2)*(th2-th1)/(pow((u2-u1),2)+pow((v2-v1),2))*(z2-z1)&#39;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&#39;d &#39;ri</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>say result <span class="Apple-tab-span" style="white-space:pre">                        </span>*THIS SEEMS TO WORK AS I GET 10 DIFFERENT VALUES OF RI</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (count = toplevel) <span class="Apple-tab-span" style="white-space:pre">        </span>*THESE IF-LOOPS AREN&#39;T OKAY, BUT WHY?</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>minri = ri</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>minlevel = count</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>endif</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>if (ri &lt; minri)</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>minri = ri</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>minlevel = count</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>endif</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>count = count+1</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>endwhile</div><div><br></div><div>&#39;d &#39;minri</div>
<div>say &quot;Min Ri &quot; result<span class="Apple-tab-span" style="white-space:pre">                        </span>*ALWAYS THE VALUE OF RI AT LEVEL 50 (AT THE BOTTOM LEVEL)</div><div>&#39;d &#39;minlevel<span class="Apple-tab-span" style="white-space:pre">                                </span></div>
<div>say &quot;Model level &quot; result<span class="Apple-tab-span" style="white-space:pre">                </span>*ALWAYS LEVEL 40 (TOP LEVEL)</div></div><div><br></div><div><br></div><div><br></div>