Eric is correct. I forgot that cdiff includes points surrounding a given grid point, and thus the "2dx" part is already included in the cdiff function. <br><br>Jeff<br><br><div class="gmail_quote">On Mon, Nov 14, 2011 at 3:00 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Mason,<br>
<br>
Yes, the expressions for dx and dy are correct.<br>
<br>
Eric<br>
<br>
----- Original Message -----<br>
From: "Mason D. Rowell" <<a href="mailto:Mason.D.Rowell-1@ou.edu">Mason.D.Rowell-1@ou.edu</a>><br>
To: "GrADS Users Forum" <<a href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a>><br>
Sent: Sunday, November 13, 2011 11:07:24 AM<br>
Subject: Re: [gradsusr] Diagnostics in Ctl File?<br>
<br>
Eric,<br>
<br>
You agree that dx and dy are defined right though?<br>
<br>
Mason<br>
________________________________________<br>
From: <a href="mailto:gradsusr-bounces@gradsusr.org">gradsusr-bounces@gradsusr.org</a> [<a href="mailto:gradsusr-bounces@gradsusr.org">gradsusr-bounces@gradsusr.org</a>] on behalf of Eric Altshuler [<a href="mailto:ela@cola.iges.org">ela@cola.iges.org</a>]<br>
Sent: Sunday, November 13, 2011 1:33 AM<br>
To: GrADS Users Forum<br>
Subject: Re: [gradsusr] Diagnostics in Ctl File?<br>
<br>
I believe the factor of 2 in the denominator of Jeff's expression for temperature advection should not be there. The expression should be:<br>
<br>
'define tadv = -ugrdprs*cdiff(tmpprs,x)/dx - vgrdprs*cdiff(tmpprs,y)/dy'<br>
<br>
because the cdiff function, when evaluated at a grid point (i,j), gives the difference of its argument between the grid points at (i+1) and (i-1) or (j+1) and (j-1), i.e. the distance the difference is taken across is two grid points. This is also true of dx and dy because they are themselves the results of using cdiff. Thus, if there is a factor of 2 in the denominator, then there must also be one in the numerator, and they would cancel.<br>
<br>
Eric<br>
<br>
----- Original Message -----<br>
From: "Mason D. Rowell" <<a href="mailto:Mason.D.Rowell-1@ou.edu">Mason.D.Rowell-1@ou.edu</a>><br>
To: "GrADS Users Forum" <<a href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a>><br>
Sent: Saturday, November 12, 2011 8:57:32 PM<br>
Subject: Re: [gradsusr] Diagnostics in Ctl File?<br>
<br>
<br>
<br>
Disregard. I am getting the script to use it now. Though I am curious about the discrepancy between Jeff's definition of temp. advection and that suggested by the cdiff documenation....<br>
<br>
Mason<br>
<br>
<br>
<br>
From: <a href="mailto:gradsusr-bounces@gradsusr.org">gradsusr-bounces@gradsusr.org</a> [<a href="mailto:gradsusr-bounces@gradsusr.org">gradsusr-bounces@gradsusr.org</a>] on behalf of Rowell, Mason D. [<a href="mailto:Mason.D.Rowell-1@ou.edu">Mason.D.Rowell-1@ou.edu</a>]<br>
Sent: Saturday, November 12, 2011 7:03 PM<br>
To: GrADS Users Forum<br>
Subject: Re: [gradsusr] Diagnostics in Ctl File?<br>
<br>
<br>
<br>
<br>
All,<br>
<br>
Interesting, I get a display when used at the command line, but when run within the script, I get,<br>
'Function not found: cdiff<br>
Error occurred on line 15'<br>
<br>
Why could this be? It is not syntax related..it just doesn't recognize it within the script...the only difference is that it is used in a definition (for defining dx) and not with a display command like when used at the command prompt...<br>
<br>
Mason<br>
<br>
<br>
<br>
From: <a href="mailto:gradsusr-bounces@gradsusr.org">gradsusr-bounces@gradsusr.org</a> [<a href="mailto:gradsusr-bounces@gradsusr.org">gradsusr-bounces@gradsusr.org</a>] on behalf of Jeff Duda [<a href="mailto:jeffduda319@gmail.com">jeffduda319@gmail.com</a>]<br>
Sent: Friday, November 11, 2011 11:07 PM<br>
To: GrADS Users Forum<br>
Subject: Re: [gradsusr] Diagnostics in Ctl File?<br>
<br>
<br>
<br>
Mason,<br>
What happens when you enter the command<br>
'd cdiff(tmpprs,x)' ?<br>
<br>
Does it display something that looks like the meridional gradient in temperature?<br>
<br>
Jeff<br>
<br>
<br>
On Fri, Nov 11, 2011 at 11:00 PM, Rowell, Mason D. < <a href="mailto:Mason.D.Rowell-1@ou.edu">Mason.D.Rowell-1@ou.edu</a> > wrote:<br>
<br>
<br>
<br>
<br>
Jeff,<br>
<br>
My problem comes in using cdiff. Everything else should be fine (it is practically verbatim from the webpage). I have a suspicion it is because it uses x and y as arguments on two different lines but I don't really have much of a way to know without more Grads experience. Could this be causing the problem?<br>
<br>
Mason<br>
<br>
<br>
<br>
<br>
From: <a href="mailto:gradsusr-bounces@gradsusr.org">gradsusr-bounces@gradsusr.org</a> [ <a href="mailto:gradsusr-bounces@gradsusr.org">gradsusr-bounces@gradsusr.org</a> ] on behalf of Jeff Duda [ <a href="mailto:jeffduda319@gmail.com">jeffduda319@gmail.com</a> ]<br>
Sent: Friday, November 11, 2011 3:17 PM<br>
<br>
<br>
<br>
To: GrADS Users Forum<br>
Subject: Re: [gradsusr] Diagnostics in Ctl File?<br>
<br>
<br>
<br>
<br>
<br>
<br>
Mason,<br>
I preferred to derive the formulas for spacings myself. Simple trigonometry reveals the following that you should use for dx and dy (i.e., meridional and zonal grid spacing):<br>
dx = Re*cos(phi)*d(theta)<br>
dy = Re*d(phi)<br>
<br>
where Re is the radius of the Earth (6371 to 6374 km), phi is latitude, theta is longitude, and the d operator means "change in". To convert this to Grads scripting code, you use the cdiff command. Also note that all angle measures need to be in radians, so you'll have to convert them as you do the operation. Here are the literal Grads command lines I use for this:<br>
<br>
re = 6.371e3<br>
'define dx = 're'*cos(lat*(3.1419/180))*cdiff(lon*(3.14159/180))'<br>
'define dy = 're'*cdiff(lon*(3.14159/180))'<br>
<br>
Obviously you can assign the conversion factor pi/180 to a script variable to simplify the symbolism there:<br>
<br>
conv_factor = 3.14159/180<br>
e.g., 'define dy = 're'*cdiff(lon*'conv_factor')'<br>
<br>
If you try to display dx or dy, you should get a nice little image that contours or colors dx and dy (dx should decrease towards the poles and not change along a line of constant latitude, and dy should only be a function of latitude as well). Now use this to define temperature advection (assuming the temperature variable is tmpprs and wind is ugrdprs/vgrdprs):<br>
<br>
'define tadv = -ugrdprs*cdiff(tmpprs,x)/(2*dx) - vgrdprs*cdiff(tmpprs,y)/(2*dy)'<br>
<br>
The <a href="http://98cbar.gs" target="_blank">98cbar.gs</a> is indeed just a script that defines color levels and sets a color scheme for when you plot temperature advection. Changing the color tables is rather easy in Grads. You only need to define a color using 'set rgb # R G B', where # is anything between 16 and 255 (just a reference number) and R, G, and B are between 0 and 255. Then you set the contour intervals manually using 'set clevs , , , , , ...' where you insert literally the levels you want to use (separated by SPACES, not COMMAS). Then set the colors for those levels using 'set ccols , , , , , , ,+1' again using the reference numbers for each color and separating by SPACES. The "+1" is for the fact that you need one additional color for the number of levls you put. You can consult the controlling colors page for full info on what I just said. Also, I have a number of very simple color bar scripts that I've used in the past. I can provide them to all if anyone is interested.<br>
<br>
You can also create a simple color bar using the <a href="http://cbar.gs" target="_blank">cbar.gs</a> script which is provided in the script library .<br>
<br>
Let me know if you need any more help.<br>
<br>
Jeff<br>
<br>
<br>
On Fri, Nov 11, 2011 at 2:50 PM, Rowell, Mason D. < <a href="mailto:Mason.D.Rowell-1@ou.edu">Mason.D.Rowell-1@ou.edu</a> > wrote:<br>
<br>
<br>
<br>
<br>
Jeff and others,<br>
<br>
Strange. This is exactly what was suggested in the ctl file near the comments at the bottom (that which I pulled from nomads). The only difference is that they have also the inclusion of a <a href="http://98cbar.gs" target="_blank">98cbar.gs</a> script right after the other expressions like that in this link you gave me, whose utility is a mystery since it is not necessary, at least suggested as so by the cdiff documenation given that it is not included. Perhaps it is just some coloring scheme. At any rate, the script fails at the first line (which attempts to define dtx), with each line coded exactly as it is shown (with the appropriate NARR temp as TMPprs and wind as UGRDprs and VGRDprs of course). I assume it will do so again at dty, and so forth. I originally didn't include define with these since I thought they weren't necessary but adding that in didn't solve the problem anyways. I suspect it is because cdiff calls x, and since I define my domain with lat long, it doesn't have a x variable to use? There definitely !<br>
isn't a spacing issue this time...<br>
<br>
Mason<br>
<br>
<br>
<br>
From: <a href="mailto:gradsusr-bounces@gradsusr.org">gradsusr-bounces@gradsusr.org</a> [ <a href="mailto:gradsusr-bounces@gradsusr.org">gradsusr-bounces@gradsusr.org</a> ] on behalf of Jeff Duda [ <a href="mailto:jeffduda319@gmail.com">jeffduda319@gmail.com</a> ]<br>
Sent: Thursday, November 10, 2011 11:11 AM<br>
To: GrADS Users Forum<br>
Subject: Re: [gradsusr] Diagnostics in Ctl File?<br>
<br>
<br>
<br>
Mason,<br>
There is a good example of how to code temperature advection in the page for the cdiff command: <a href="http://www.iges.org/grads/gadoc/gradfunccdiff.html" target="_blank">http://www.iges.org/grads/gadoc/gradfunccdiff.html</a><br>
The reason for all of the crazy manipulations is because the data points on your grid are not uniformly spaced on the globe. Thus corrections have to be made to get the correct distance between individual grid points.<br>
<br>
Jeff<br>
<br>
<br>
On Thu, Nov 10, 2011 at 11:00 AM, Wesley Ebisuzaki < <a href="mailto:Wesley.Ebisuzaki@noaa.gov">Wesley.Ebisuzaki@noaa.gov</a> > wrote:<br>
<br>
<br>
Mason,<br>
<br>
I think that you've discovered the "private" commands used by nomads<br>
plot software for defining new variables<br>
and custom plots. The nomads plot package is a wrapper for GrADS. It<br>
has the ability to run grads .gs files that<br>
are embedded within the ctl files.<br>
<br>
<br>
<a href="http://www.cpc.ncep.noaa.gov/products/wesley/ncep_data/plot_doc.htmlhttp://www.cpc.ncep.noaa.gov/products/wesley/ncep_data/plot_doc.html" target="_blank">http://www.cpc.ncep.noaa.gov/products/wesley/ncep_data/plot_doc.htmlhttp://www.cpc.ncep.noaa.gov/products/wesley/ncep_data/plot_doc.html</a><br>
<br>
Ask NCDC for a copy of the .gs files.<br>
<br>
<br>
> Has anyone done this before with grads?<br>
How do you expect the developers to debug the scripts?<br>
<br>
Wesley<br>
<br>
<br>
<br>
<br>
<br>
<br>
Rowell, Mason D. wrote:<br>
> All,<br>
><br>
> I noticed ample comments toward the end of the ctl files available on the nomads servers from the NARR page, with a description of how to implement these in grads scripting. I tried to take this to plot temperature advection but it didn't work, b/c the last line of the comments calls for some function never provided. Has anyone done this before with grads?<br>
><br>
> Mason<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>
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>
Grad student - PhD, Meteorology<br>
University of Oklahoma School of Meteorology - Center for Analysis and Prediction of Storms<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>
--<br>
Jeff Duda<br>
Grad student - PhD, Meteorology<br>
University of Oklahoma School of Meteorology - Center for Analysis and Prediction of Storms<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>
--<br>
Jeff Duda<br>
Grad student - PhD, Meteorology<br>
University of Oklahoma School of Meteorology - Center for Analysis and Prediction of Storms<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>
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>
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>
</blockquote></div><br><br clear="all"><br>-- <br>Jeff Duda<br>Grad student - PhD, Meteorology<br>University of Oklahoma School of Meteorology - Center for Analysis and Prediction of Storms<br><br>