<div dir="ltr"><div>You are probably not accurately converting degrees to radians in your dx definition. The correct formula for degrees to radians is radians = degrees * pi/180. You seem to be missing the "/180" part.</div><div><br></div><div>Jeff Duda<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 16, 2020 at 10:26 PM Ricardo Hallak <<a href="mailto:ricardo.hallak@iag.usp.br">ricardo.hallak@iag.usp.br</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hy, Mano. Follow the instructions below, from the GrADS homepage. It will fix your mistake.<br clear="all"><div><div dir="ltr"><div dir="ltr"><h2 style="color:rgb(0,0,0);font-family:"Times New Roman""><b>cdiff</b></h2><p style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"><code>cdiff(<i>expr,dim</i>)</code></p><p style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Performs a centered difference operation on <code><i>expr</i></code> in the direction specified by <code><i>dim</i></code>. The difference is done in the grid space, and no adjustment is performed for unequally spaced grids. The result value at each grid point is the value at the grid point plus one minus the value at the grid point minus one. The <code><i>dim</i></code> argument specifies the dimension over which the difference is to be taken, and is a single character: X, Y, Z, or T.</p><p style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium">Result values at the grid boundaries are set to missing.</p><p style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"></p><h3 style="color:rgb(0,0,0);font-family:"Times New Roman"">Usage Notes</h3><p style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"></p><h3 style="color:rgb(0,0,0);font-family:"Times New Roman"">Examples</h3><p style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"></p><ol style="color:rgb(0,0,0);font-family:"Times New Roman";font-size:medium"><li>The <code>cdiff</code> function may be used to duplicate the calculation done by the <a href="http://cola.gmu.edu/grads/gadoc/gradfunchcurl.html" target="_blank"><code>hcurl</code></a> function:<p></p><dl><dd><code>define dv = cdiff(v,x)</code></dd><dd><code>define dx = cdiff(lon,x)*3.1416/180</code></dd><dd><code>define du = cdiff(u*cos(lat*3.1416/180),y)</code></dd><dd><code>define dy = cdiff(lat,y)*3.1416/180</code></dd><dd><code>display (dv/dx-du/dy)/(6.37e6*cos(lat*3.1416/180))</code><p>The above example assumes an X-Y varying dimension environment. Note that the intrinsic variables <code>lat</code> and <code>lon</code> give results in degrees and must be converted to radians in the calaculation. Also note the radius of the earth is assumed to be <code>6.37e6</code> meters thus the U and V winds are assumed to have units of <code>m/sec</code>.</p><p></p><li>Temperature advection can be calculated using the <code>cdiff</code> function as follows:<p></p><dd><code>define dtx = cdiff(t,x)</code></dd><dd><code>define dty = cdiff(t,y)</code></dd><dd><code>define dx = cdiff(lon,x)*3.1416/180</code></dd><dd><code>define dy = cdiff(lat,y)*3.1416/180</code></dd><dd><code>display -1*( (u*dtx)/(cos(lat*3.1416/180)*dx) + v*dty/dy )/6.37e6</code><p>where the variable <code>t</code> is temperature, <code>u</code> is the U component of the wind, and <code>v</code> is the V component of the wind.</p></dd></li></dd></dl></li></ol><span style="color:rgb(0,0,0);font-family:"times new roman","new york",times,serif;font-size:16px">-- </span><br style="color:rgb(0,0,0);font-family:"times new roman","new york",times,serif;font-size:16px"><div style="color:rgb(0,0,0);font-family:"times new roman","new york",times,serif;font-size:16px"><span name="x"></span>Prof. Ricardo Hallak<br>Laboratório de Meteorologia de Mesoescala - LMM<br>Departamento de Ciências Atmosféricas<br>Instituto de Astronomia, Geofísica e Ciências Atmosféricas<br>Universidade de São Paulo<br><br>Phone: +55(11)3091-4698</div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Em ter., 16 de jun. de 2020 às 23:25, lpasmanoranjan <<a href="mailto:lpasmanoranjan@gmail.com" target="_blank">lpasmanoranjan@gmail.com</a>> escreveu:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div dir="ltr">Dear Users,<br>I would like to calculate horizontal temperature gradient. The following script plots strange values. Perhaps I am making some mistake, would anyone please check the script. <br><br>dtx = cdiff(t,x)<br>dx = cdiff(lon,x)*3.1416*6.37e6*cos(lat*3.1416)</div><div dir="ltr">d dtx/dx<br><br>Thank you.</div>
</div>-- <br><div dir="ltr"><div dir="ltr"><div>Kind Regards,<br></div>Mano<br></div></div>
_______________________________________________<br>
gradsusr mailing list<br>
<a href="mailto:gradsusr@gradsusr.org" target="_blank">gradsusr@gradsusr.org</a><br>
<a href="http://gradsusr.org/mailman/listinfo/gradsusr" rel="noreferrer" target="_blank">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>
</blockquote></div>
_______________________________________________<br>
gradsusr mailing list<br>
<a href="mailto:gradsusr@gradsusr.org" target="_blank">gradsusr@gradsusr.org</a><br>
<a href="http://gradsusr.org/mailman/listinfo/gradsusr" rel="noreferrer" target="_blank">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><font size="2"><span>Jeff Duda, Research Scientist</span></font></div><div dir="ltr"><font size="2"><span></span></font>University of Colorado Boulder</div><div dir="ltr"><font size="2"><span></span></font>Cooperative Institute for Research in Environmental Sciences</div><div dir="ltr">NOAA/OAR/ESRL/Global Systems Laboratory<br><font size="2"><span>

<span>Boulder, CO<br></span></span></font>



</div></div></div></div></div></div></div></div></div></div>