Instead of doing strange differentials inside the divergence calculation, I just calculate each component separately beforehand if it is at all complicated. Thus I use:<br><br>dx = Re*cos(lat(3.14159/180))*cdiff(lon,x)*(3.14159/180)<br>
dy = Re*cdiff(lat,y)*(3.14159/180)<br><br>Then, divergence = cdiff(u,x)/dx + cdiff(v,y)/dy<br><br>Jeff Duda<br><br><div class="gmail_quote">On Mon, Nov 15, 2010 at 12:53 PM, Eric Altshuler <span dir="ltr"><<a href="mailto:ela@cola.iges.org">ela@cola.iges.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">This issue also came up about a month ago. For those of us who aren't C programmers and would have difficulty determining the formulas from the source code, I will say there are several incorrect formulas for hdivg(u,v) in this thread, and one correct formula (in Yaqiang Wang's most recent message). To make the correct answer perfectly clear, here it is again:<br>
<div class="im"><br>
dx = cdiff(lon,x)*3.1416/180<br>
</div><div class="im">dy = cdiff(lat,y)*3.1416/180<br>
<br>
</div>du = cdiff(u,x)<br>
<div class="im">dv = cdiff(v*cos(lat*3.1416/180),y)<br>
<br>
</div>div = (du/dx+dv/dy)/(6.37e6*cos(lat*3.1416/180))<br>
<br>
As an aside, I think it's possible to obtain more accurate approximations for divergence and vorticity than those given in the grads documentation, because the factor cos(lat) can be taken outside the derivative operator and differentiated analytically rather than using finite differencing. Using the product rule of differentiation and a bit of algebra, I have derived the following sequence of calculations for these quantities (my definitions of intermediate quantities are different, but the end result is the same):<br>
<br>
pi=3.14159265359<br>
dtr=pi/180<br>
a=6.371e6<br>
dx=a*cos(dtr*lat)*dtr*cdiff(lon,x)<br>
dy=a*dtr*cdiff(lat,y)<br>
div=cdiff(u,x)/dx+cdiff(v,y)/dy-v*tan(dtr*lat)/a<br>
vor=cdiff(v,x)/dx-cdiff(u,y)/dy+u*tan(dtr*lat)/a<br>
def1=cdiff(u,x)/dx-cdiff(v,y)/dy-v*tan(dtr*lat)/a<br>
def2=cdiff(v,x)/dx+cdiff(u,y)/dy+u*tan(dtr*lat)/a<br>
<br>
In these formulas, substitute your wind variable names for u and v. In addition to divergence and vorticity, there are also calculations of the components of deformation, def1 and def2, and total deformation is equal to mag(def1,def2). These formulas (in terms of continuous fields) can also be found in Bluestein (1992), "Synoptic-Dynamic Meteorology in Midlatitudes", Vol. I, p. 111.<br>
<br>
Best regards,<br>
<br>
Eric L. Altshuler<br>
Assistant Research Scientist<br>
Center for Ocean-Land-Atmosphere Studies<br>
4041 Powder Mill Road, Suite 302<br>
Calverton, MD 20705-3106<br>
USA<br>
<br>
E-mail: <a href="mailto:ela@cola.iges.org">ela@cola.iges.org</a><br>
Phone: (301) 902-1257<br>
Fax: (301) 595-9793<br>
<div><div></div><div class="h5"><br>
----- Original Message -----<br>
From: "Arlindo da Silva" <<a href="mailto:dasilva@alum.mit.edu">dasilva@alum.mit.edu</a>><br>
To: "GrADS Users Forum" <<a href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a>><br>
Sent: Monday, November 15, 2010 10:55:55 AM<br>
Subject: Re: [gradsusr] hdivg function<br>
<br>
<br>
All,<br>
<br>
<br>
The most authoritative documentation on the hdivg function can be found here:<br>
<br>
<br>
<a href="http://opengrads.cvs.sourceforge.net/viewvc/opengrads/cola/grads2/src/gafunc.c?revision=1.1.1.9&view=markup" target="_blank">http://opengrads.cvs.sourceforge.net/viewvc/opengrads/cola/grads2/src/gafunc.c?revision=1.1.1.9&view=markup</a><br>
<br>
<br>
That is, the source code :-). The hdivg() implementation can be found on line 2716. This file has the implementation of most grads functions.<br>
<br>
<br>
BTW, the link above is the web interface to the opengrads CVS repository. We keep in this particular directory the original releases from COLA, before any opengrads patches are applied:<br>
<br>
<br>
<a href="http://opengrads.cvs.sourceforge.net/viewvc/opengrads/cola/grads2/src/" target="_blank">http://opengrads.cvs.sourceforge.net/viewvc/opengrads/cola/grads2/src/</a><br>
<br>
<br>
There is a pulldown menu called "Sticky Tag" that you can use to select a particular grads version.<br>
<br>
<br>
Arlindo<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
On Mon, Nov 15, 2010 at 12:44 AM, Yaqiang Wang < <a href="mailto:yaqiang.wang@gmail.com">yaqiang.wang@gmail.com</a> > wrote:<br>
<br>
<br>
The correct one should be:<br>
<br>
define du = cdiff(u,x)<br>
<br>
define dx = cdiff(lon,x)*3.1416/180<br>
define dv = cdiff(v*cos(lat*3.1416/180),y)<br>
<br>
define dy = cdiff(lat,y)*3.1416/180<br>
display (du/dx+dv/dy)/(6.37e6*cos(lat*3.1416/180))<br>
<br>
Yaqiang<br>
<br>
<br>
Chinese Academy of Meteorological Sciences<br>
<a href="mailto:yaqiang.wang@gmail.com">yaqiang.wang@gmail.com</a><br>
<br>
<br>
<br>
<br>
On Mon, Nov 15, 2010 at 12:47 PM, Yaqiang Wang < <a href="mailto:yaqiang.wang@gmail.com">yaqiang.wang@gmail.com</a> > wrote:<br>
> Thanks for Jeff's reply! But it seems that in GrADS the hdivg function<br>
> was calculated as following. Please mention the last sentence.<br>
><br>
> define dv = cdiff(v,x)<br>
> define dx = cdiff(lon,x)*3.1416/180<br>
> define du = cdiff(u*cos(lat*3.1416/180),y)<br>
> define dy = cdiff(lat,y)*3.1416/180<br>
> display (du/dy+dv/dx)/(6.37e6*cos(lat*3.1416/180))<br>
><br>
> Yaqiang<br>
><br>
> Chinese Academy of Meteorological Sciences<br>
> <a href="mailto:yaqiang.wang@gmail.com">yaqiang.wang@gmail.com</a><br>
><br>
> On Mon, Nov 15, 2010 at 11:56 AM, Jeffrey Duda < <a href="mailto:jdduda@iastate.edu">jdduda@iastate.edu</a> > wrote:<br>
>> Yaqiang,<br>
>> You are exactly correct.<br>
>><br>
>> Jeff Duda<br>
>><br>
>> On Sun, Nov 14, 2010 at 9:22 PM, Yaqiang Wang < <a href="mailto:yaqiang.wang@gmail.com">yaqiang.wang@gmail.com</a> ><br>
>> wrote:<br>
>>><br>
>>> The GrADS documentation said that the cdiff function may be used to<br>
>>> duplicate the calculation done by the hcurl function:<br>
>>><br>
>>> define dv = cdiff(v,x)<br>
>>> define dx = cdiff(lon,x)*3.1416/180<br>
>>> define du = cdiff(u*cos(lat*3.1416/180),y)<br>
>>> define dy = cdiff(lat,y)*3.1416/180<br>
>>> display (dv/dx-du/dy)/(6.37e6*cos(lat*3.1416/180))<br>
>>><br>
>>> But there is no description of hdivg function. I guess hdivg function<br>
>>> could be duplicated using cdiff function as following. Please anybody<br>
>>> tell me if it is correct or not. Thanks!<br>
>>><br>
>>> define dv = cdiff(v,x)<br>
>>> define dx = cdiff(lon,x)*3.1416/180<br>
>>> define du = cdiff(u*cos(lat*3.1416/180),y)<br>
>>> define dy = cdiff(lat,y)*3.1416/180<br>
>>> display (du/dx+dv/dy)/(6.37e6*cos(lat*3.1416/180))<br>
>>><br>
>>> Yaqiang Wang<br>
>>><br>
>>> Chinese Academy of Meteorological Sciences<br>
>>> <a href="mailto:yaqiang.wang@gmail.com">yaqiang.wang@gmail.com</a><br>
>>> _______________________________________________<br>
>>> gradsusr mailing list<br>
>>> <a href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a><br>
>>> <a href="http://gradsusr.org/mailman/listinfo/gradsusr" target="_blank">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>
>><br>
>><br>
>><br>
>> --<br>
>> Jeff Duda<br>
>> Iowa State University<br>
>> Meteorology Graduate Student<br>
>> 3134 Agronomy Hall<br>
>> <a href="http://www.meteor.iastate.edu/%7Ejdduda" target="_blank">www.meteor.iastate.edu/~jdduda</a><br>
>><br>
>> _______________________________________________<br>
>> gradsusr mailing list<br>
>> <a href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a><br>
>> <a href="http://gradsusr.org/mailman/listinfo/gradsusr" target="_blank">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>
>><br>
>><br>
><br>
_______________________________________________<br>
gradsusr mailing list<br>
<a href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a><br>
<a href="http://gradsusr.org/mailman/listinfo/gradsusr" target="_blank">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>
<br>
<br>
<br>
--<br>
Arlindo da Silva<br>
<a href="mailto:dasilva@alum.mit.edu">dasilva@alum.mit.edu</a><br>
<br>
_______________________________________________<br>
gradsusr mailing list<br>
<a href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a><br>
<a href="http://gradsusr.org/mailman/listinfo/gradsusr" target="_blank">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>
_______________________________________________<br>
gradsusr mailing list<br>
<a href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a><br>
<a href="http://gradsusr.org/mailman/listinfo/gradsusr" target="_blank">http://gradsusr.org/mailman/listinfo/gradsusr</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Jeff Duda<br>Iowa State University<br>Meteorology Graduate Student<br>3134 Agronomy Hall<br><a href="http://www.meteor.iastate.edu/~jdduda">www.meteor.iastate.edu/~jdduda</a><br>