[gradsusr] writing results and variables to a text file
Anil acharya
acharya_anil at yahoo.com
Wed Nov 23 12:55:56 EST 2011
Hi
While writing variables to a text, you can create a loop for related variables and use 'gxout' command. As an example you can look at the following simple example to write precipitation in the text file for 200 time steps.
However before using this example, you have to create .ctl file based on your grib files. You can use wgrib to open a grib file, and use grib2ctl to make a .ctl file from the grib files (you can also make .ctl file manually, for some variables it is not a big deal. But you need to get information from the grib files using wgrib). Then, use gribmap to create .idx file from the .ctl file. After creating all of these files, run the following script.
(For documentation on all of the above commands, look the tutorials and online documentation available in the link http://grads.iges.org/grads/gadoc/). I hope this is helpful.
'open c:\dummy.ctl'
'set gxout print'
'set lat 38 42'
'set lon -105 -96'
lat = 38.5625
lon = -104.1875
'set t 1'
count = 1
while (count <= 200)
'set t' count
'd apcp'
pcp=subwrd(result,20)
dummy = write('data'',count""pcp)
count = count + 1
endwhile
Sincerely,
Anil Acharya
Research Associate
Idaho Water Center, University of Idaho
322 E Front Street, Suite 324F
Boise, Idaho, 83702
________________________________
From: "gradsusr-request at gradsusr.org" <gradsusr-request at gradsusr.org>
To: gradsusr at gradsusr.org
Sent: Wednesday, November 23, 2011 10:22 AM
Subject: gradsusr Digest, Vol 21, Issue 66
Send gradsusr mailing list submissions to
gradsusr at gradsusr.org
To subscribe or unsubscribe via the World Wide Web, visit
http://gradsusr.org/mailman/listinfo/gradsusr
or, via email, send a message with subject or body 'help' to
gradsusr-request at gradsusr.org
You can reach the person managing the list at
gradsusr-owner at gradsusr.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of gradsusr digest..."
Today's Topics:
1. (no subject) (Alireza Azargoun)
2. writing results & variables to a text file (Alireza Azargoun)
3. Re: Specialized Display Question (Jeff Duda)
4. Re: Specialized Display Question (Jeff Duda)
----------------------------------------------------------------------
Message: 1
Date: Wed, 23 Nov 2011 20:25:27 +0330
From: Alireza Azargoun <alireza.azargoun at gmail.com>
Subject: [gradsusr] (no subject)
To: gradsusr at gradsusr.org
Message-ID:
<CAKuuxT4OhrFz40sbjnuWCUbJBMH55fnmJh3geTJLT5XQz3=03g at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Dear GrADS users
Hi everybody
I have about 200 grib2 files ( 1.grb2 ~ 200.grb ) . i need to read a
temperature of a city (lat, lon, lev, time are constant in all files) . how
i can read this files using a while loop!? ( I receive this error when i
write a while. Unknown Command: while )
and how can i write these data to a text file!? I've searched all grads
option for a command that writes variables in a text file! but i couldn't
find it!
Thanks in advance,
Alireza
Sharif University of Technology
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20111123/3f4a31b4/attachment-0001.html
------------------------------
Message: 2
Date: Wed, 23 Nov 2011 20:33:25 +0330
From: Alireza Azargoun <alireza.azargoun at gmail.com>
Subject: [gradsusr] writing results & variables to a text file
To: GrADS Users Forum <gradsusr at gradsusr.org>
Message-ID:
<CAKuuxT6WpbvCRhmwu+8QhzgytddHWGHYVtmh4sNV7FCE=+X0cA at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Dear GrADS users
Hi everybody
I have about 200 grib2 files ( 1.grb2 ~ 200.grb ) . i need to read a
temperature of a city (lat, lon, lev, time are constant in all files) . how
i can read this files using a while loop!? ( I receive this error when i
write a while. Unknown Command: while )
and how can i write these data to a text file!? I've searched all grads
option for a command that writes variables in a text file! but i couldn't
find it!
Thanks in advance,
Alireza
Sharif University of Technology
--
Alireza Azargoun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20111123/230c6444/attachment-0001.html
------------------------------
Message: 3
Date: Wed, 23 Nov 2011 11:17:20 -0600
From: Jeff Duda <jeffduda319 at gmail.com>
Subject: Re: [gradsusr] Specialized Display Question
To: GrADS Users Forum <gradsusr at gradsusr.org>
Message-ID:
<CAAig09B2+7mFXvdFHCwEj7ogt3z5OmckfDKVtNHerEJ_u6CVgw at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Mason,
I haven't looked at your script, but here are the answers to your questions.
You got the error from CDIFF when setting lev statically because it needs
the vertical dimension to be varying in order to work. On the other hand,
typing the expression in manually does not require the vertical dimension
to vary. To see why this works, look through the top section of the
variables page <http://www.iges.org/grads/gadoc/variable.html#names> on the
Grads site. Basically, you can use parentheses to tag a field with a
spatiotemporal (and/or ensemble) offset or specification. For example, 'd
tmpprs(z+1)' tells Grads to plot tmpprs one vertical level away from where
the current vertical dimension is set (this works for both fixed and
varying vertical dimension settings). So if you have two pressure levels
at 850 and 800 mb, if your lev is set to 850, 'd tmpprs(z+1)' will plot
temperatures at 800 mb. 'd tmpprs(z-1)' plots tmpprs one level down. You
can specify the level, too. Say you want to plot 500 mb heights and MSLP.
The following lines of code to do that are equivalent:
'set lev 500'
'd hgtprs'
'set lev 1000'
'd mslmamsl'
OR
'set lev 500'
'd hgtprs'
'd mslmamsl(lev=1000)'
OR
(assume lev is set to something other than 500 or 1000)
'd hgtprs(lev=500)'
'd mslmamsl(lev=1000)'
Thus, this command: 'd (theta(z+1)-theta(z-1)) /
(hgtprs(z+1)-hgtprs(z-1))', tells grads to plot an approximation of the
vertical derivative of theta in the same way that CDIFF would do it. It's
just that CDIFF requires a varying vertical dimension if you use Z as the
argument, which means you pretty much can't use it to display a vertical
derivative on a single pressure surface in a horizontal cross section
(sorry, that just came to me, so I apologize for the confusion).
To compute potential temperature using the formula you have, use the pow()
function instead of the carrot. Thus, potprs = tmpprs*pow(1000/lev,2/7)
(with your vertical dimension varying over all the levels you want to have
potential temperature defined) will give you a grid of potential
temperatures.
Here's my suggestion for how to plot the vertical temperature gradient at
850 mb given NARR data (assuming I remember the variable names):
'set x 1 (whatever last index is)'
'set y 1 (whatever last index is)'
'set lev 1000 (however high you want, but make sure it includes the level
above the one you want to view the gradient on)'
'define theta = tmpprs*pow(1000/lev,2/7)'
'set lev 850'
'd (theta(z+1)-theta(z-1)) / (hgtprs(z+1)-hgtprs(z-1))'
Jeff
On Wed, Nov 23, 2011 at 12:44 AM, Rowell, Mason D.
<Mason.D.Rowell-1 at ou.edu>wrote:
> All,
>
> Well I appear to still have issues. I can define theta like I discovered
> I can, but then I can't just use this in Jeff's vertical derivative
> expression (the one that will work), given that its value at z+1 and z-1 is
> not defined. I thought I was being clever getting around that, but it
> claims I am not setting lev right, and I don't know why. Script is
> attached. Any ideas?
>
> Mason
> ------------------------------
> *From:* gradsusr-bounces at gradsusr.org [gradsusr-bounces at gradsusr.org] on
> behalf of Rowell, Mason D. [Mason.D.Rowell-1 at ou.edu]
> *Sent:* Tuesday, November 22, 2011 11:21 PM
>
> *To:* GrADS Users Forum
> *Subject:* Re: [gradsusr] Specialized Display Question
>
> Apparently it won't take lev in my potential temp expression, even
> though it is set to the right lev I need, but If I define hgt = 850 for
> example, use that to set lev, then use hgt in my expression, it takes it.
> The issue with defining potential temp. from NARR data is solved then (I
> knew it shouldn't have been challenging). Now I just need to confirm that
> Jeff's second method for cdiff (given it still doesn't take the first
> method provided) does indeed approximate the vertical deriv. for the
> central level, as I would assume it does if I know the method like I think
> I do.
>
> Mason
> ------------------------------
> *From:* gradsusr-bounces at gradsusr.org [gradsusr-bounces at gradsusr.org] on
> behalf of Rowell, Mason D. [Mason.D.Rowell-1 at ou.edu]
> *Sent:* Tuesday, November 22, 2011 10:58 PM
> *To:* GrADS Users Forum
> *Subject:* Re: [gradsusr] Specialized Display Question
>
> Jeff,
>
> Well the expression given second will work with lev set statically
> before entering the command (doesn't make sense to me to enter it after
> given the level about which to compute a central difference would have to
> be known first), but the first expression (w/ lev first set) gives 'Error
> from CDIFF: Specified dimension non varying', which is what I thought I
> would get out of cdiff given lev is set statically. Though the second
> command may suffice for my purposes. As I said I was able to get it to
> work, after having set lev, so I assume the display is appropriate for the
> lev I choose and no other (I'd imagine it would have to be if the
> expression is working as it appears, that is the central difference about
> the set lev, with this approximation valid for the state of the derivative
> at the center, ie the level about which the central difference is
> computed). The syntax is new to me so it is good to learn. Now I just need
> to get a potential temperature expression to display for me.
>
> Mason
> ------------------------------
> *From:* gradsusr-bounces at gradsusr.org [gradsusr-bounces at gradsusr.org] on
> behalf of Jeff Duda [jeffduda319 at gmail.com]
> *Sent:* Tuesday, November 22, 2011 8:41 PM
> *To:* GrADS Users Forum
> *Subject:* Re: [gradsusr] Specialized Display Question
>
> Mason,
> You can use the cdiff command in the z direction to display variables
> (unfortunately, you can't use it to define variables). However, you can
> approximate the vertical derivative by copying the method that cdiff uses.
> If you have geopotential height, then you have all you need to compute a
> vertical derivative with respect to height coordinates. You can display
> the vertical derivative of theta by either of the following:
>
> 'd cdiff(theta,z)'
> 'd (theta(z+1)-theta(z-1)) / (hgtprs(z+1)-hgtprs(z-1))
>
> If you want to just view the gradient on one pressure surface, set the
> level that surface, then enter the command.
>
> Jeff
>
> On Tue, Nov 22, 2011 at 7:54 PM, Rowell, Mason D. <Mason.D.Rowell-1 at ou.edu
> > wrote:
>
>> All,
>>
>> Is it possible to display the vertical derivative of some quantity (like
>> say temp or potential temp) on a pressure surface? I know I have height in
>> my NARR data, but it is specific to a pressure level (i.e. HGTprs). What I
>> would need is the height just above the current pressure level and below it
>> in order to get cdiff of say theta and z. I'm not sure how to set the
>> dimensions to do this...I would be okay with just getting this quantity for
>> display at some level height, it doesn't have to be on a pressure surface.
>>
>> Mason
>> _______________________________________________
>> gradsusr mailing list
>> gradsusr at gradsusr.org
>> http://gradsusr.org/mailman/listinfo/gradsusr
>>
>
>
>
> --
> Jeff Duda
> Grad student - PhD, Meteorology
> University of Oklahoma School of Meteorology - Center for Analysis and
> Prediction of Storms
>
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>
>
--
Jeff Duda
Grad student - PhD, Meteorology
University of Oklahoma School of Meteorology - Center for Analysis and
Prediction of Storms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20111123/5301872c/attachment-0001.html
------------------------------
Message: 4
Date: Wed, 23 Nov 2011 11:22:14 -0600
From: Jeff Duda <jeffduda319 at gmail.com>
Subject: Re: [gradsusr] Specialized Display Question
To: GrADS Users Forum <gradsusr at gradsusr.org>
Message-ID:
<CAAig09DhoBAqCSWBLySCc+fN+iO=n8gWY_zvZuA0WV4o10uQOA at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Mason,
I "corrected" your script file and reattached it here. Basically you were
a little quote-happy with your definitions in the first half of the
script. Other than that you coded it in a way that would work. Hopefully
you understand why certain variables don't need to be in quotes.
Jeff
On Wed, Nov 23, 2011 at 11:17 AM, Jeff Duda <jeffduda319 at gmail.com> wrote:
> Mason,
> I haven't looked at your script, but here are the answers to your
> questions.
>
> You got the error from CDIFF when setting lev statically because it needs
> the vertical dimension to be varying in order to work. On the other hand,
> typing the expression in manually does not require the vertical dimension
> to vary. To see why this works, look through the top section of the
> variables page <http://www.iges.org/grads/gadoc/variable.html#names> on
> the Grads site. Basically, you can use parentheses to tag a field with a
> spatiotemporal (and/or ensemble) offset or specification. For example, 'd
> tmpprs(z+1)' tells Grads to plot tmpprs one vertical level away from where
> the current vertical dimension is set (this works for both fixed and
> varying vertical dimension settings). So if you have two pressure levels
> at 850 and 800 mb, if your lev is set to 850, 'd tmpprs(z+1)' will plot
> temperatures at 800 mb. 'd tmpprs(z-1)' plots tmpprs one level down. You
> can specify the level, too. Say you want to plot 500 mb heights and MSLP.
> The following lines of code to do that are equivalent:
> 'set lev 500'
> 'd hgtprs'
> 'set lev 1000'
> 'd mslmamsl'
>
> OR
>
> 'set lev 500'
> 'd hgtprs'
> 'd mslmamsl(lev=1000)'
>
> OR
> (assume lev is set to something other than 500 or 1000)
> 'd hgtprs(lev=500)'
> 'd mslmamsl(lev=1000)'
>
> Thus, this command: 'd (theta(z+1)-theta(z-1)) /
> (hgtprs(z+1)-hgtprs(z-1))', tells grads to plot an approximation of the
> vertical derivative of theta in the same way that CDIFF would do it. It's
> just that CDIFF requires a varying vertical dimension if you use Z as the
> argument, which means you pretty much can't use it to display a vertical
> derivative on a single pressure surface in a horizontal cross section
> (sorry, that just came to me, so I apologize for the confusion).
>
> To compute potential temperature using the formula you have, use the pow()
> function instead of the carrot. Thus, potprs = tmpprs*pow(1000/lev,2/7)
> (with your vertical dimension varying over all the levels you want to have
> potential temperature defined) will give you a grid of potential
> temperatures.
>
> Here's my suggestion for how to plot the vertical temperature gradient at
> 850 mb given NARR data (assuming I remember the variable names):
>
> 'set x 1 (whatever last index is)'
> 'set y 1 (whatever last index is)'
> 'set lev 1000 (however high you want, but make sure it includes the level
> above the one you want to view the gradient on)'
> 'define theta = tmpprs*pow(1000/lev,2/7)'
> 'set lev 850'
> 'd (theta(z+1)-theta(z-1)) / (hgtprs(z+1)-hgtprs(z-1))'
>
> Jeff
>
>
> On Wed, Nov 23, 2011 at 12:44 AM, Rowell, Mason D. <
> Mason.D.Rowell-1 at ou.edu> wrote:
>
>> All,
>>
>> Well I appear to still have issues. I can define theta like I
>> discovered I can, but then I can't just use this in Jeff's vertical
>> derivative expression (the one that will work), given that its value at z+1
>> and z-1 is not defined. I thought I was being clever getting around that,
>> but it claims I am not setting lev right, and I don't know why. Script is
>> attached. Any ideas?
>>
>> Mason
>> ------------------------------
>> *From:* gradsusr-bounces at gradsusr.org [gradsusr-bounces at gradsusr.org] on
>> behalf of Rowell, Mason D. [Mason.D.Rowell-1 at ou.edu]
>> *Sent:* Tuesday, November 22, 2011 11:21 PM
>>
>> *To:* GrADS Users Forum
>> *Subject:* Re: [gradsusr] Specialized Display Question
>>
>> Apparently it won't take lev in my potential temp expression, even
>> though it is set to the right lev I need, but If I define hgt = 850 for
>> example, use that to set lev, then use hgt in my expression, it takes it.
>> The issue with defining potential temp. from NARR data is solved then (I
>> knew it shouldn't have been challenging). Now I just need to confirm that
>> Jeff's second method for cdiff (given it still doesn't take the first
>> method provided) does indeed approximate the vertical deriv. for the
>> central level, as I would assume it does if I know the method like I think
>> I do.
>>
>> Mason
>> ------------------------------
>> *From:* gradsusr-bounces at gradsusr.org [gradsusr-bounces at gradsusr.org] on
>> behalf of Rowell, Mason D. [Mason.D.Rowell-1 at ou.edu]
>> *Sent:* Tuesday, November 22, 2011 10:58 PM
>> *To:* GrADS Users Forum
>> *Subject:* Re: [gradsusr] Specialized Display Question
>>
>> Jeff,
>>
>> Well the expression given second will work with lev set statically
>> before entering the command (doesn't make sense to me to enter it after
>> given the level about which to compute a central difference would have to
>> be known first), but the first expression (w/ lev first set) gives 'Error
>> from CDIFF: Specified dimension non varying', which is what I thought I
>> would get out of cdiff given lev is set statically. Though the second
>> command may suffice for my purposes. As I said I was able to get it to
>> work, after having set lev, so I assume the display is appropriate for the
>> lev I choose and no other (I'd imagine it would have to be if the
>> expression is working as it appears, that is the central difference about
>> the set lev, with this approximation valid for the state of the derivative
>> at the center, ie the level about which the central difference is
>> computed). The syntax is new to me so it is good to learn. Now I just need
>> to get a potential temperature expression to display for me.
>>
>> Mason
>> ------------------------------
>> *From:* gradsusr-bounces at gradsusr.org [gradsusr-bounces at gradsusr.org] on
>> behalf of Jeff Duda [jeffduda319 at gmail.com]
>> *Sent:* Tuesday, November 22, 2011 8:41 PM
>> *To:* GrADS Users Forum
>> *Subject:* Re: [gradsusr] Specialized Display Question
>>
>> Mason,
>> You can use the cdiff command in the z direction to display variables
>> (unfortunately, you can't use it to define variables). However, you can
>> approximate the vertical derivative by copying the method that cdiff uses.
>> If you have geopotential height, then you have all you need to compute a
>> vertical derivative with respect to height coordinates. You can display
>> the vertical derivative of theta by either of the following:
>>
>> 'd cdiff(theta,z)'
>> 'd (theta(z+1)-theta(z-1)) / (hgtprs(z+1)-hgtprs(z-1))
>>
>> If you want to just view the gradient on one pressure surface, set the
>> level that surface, then enter the command.
>>
>> Jeff
>>
>> On Tue, Nov 22, 2011 at 7:54 PM, Rowell, Mason D. <
>> Mason.D.Rowell-1 at ou.edu> wrote:
>>
>>> All,
>>>
>>> Is it possible to display the vertical derivative of some quantity (like
>>> say temp or potential temp) on a pressure surface? I know I have height in
>>> my NARR data, but it is specific to a pressure level (i.e. HGTprs). What I
>>> would need is the height just above the current pressure level and below it
>>> in order to get cdiff of say theta and z. I'm not sure how to set the
>>> dimensions to do this...I would be okay with just getting this quantity for
>>> display at some level height, it doesn't have to be on a pressure surface.
>>>
>>> Mason
>>> _______________________________________________
>>> gradsusr mailing list
>>> gradsusr at gradsusr.org
>>> http://gradsusr.org/mailman/listinfo/gradsusr
>>>
>>
>>
>>
>> --
>> Jeff Duda
>> Grad student - PhD, Meteorology
>> University of Oklahoma School of Meteorology - Center for Analysis and
>> Prediction of Storms
>>
>>
>> _______________________________________________
>> gradsusr mailing list
>> gradsusr at gradsusr.org
>> http://gradsusr.org/mailman/listinfo/gradsusr
>>
>>
>
>
> --
> Jeff Duda
> Grad student - PhD, Meteorology
> University of Oklahoma School of Meteorology - Center for Analysis and
> Prediction of Storms
>
>
--
Jeff Duda
Grad student - PhD, Meteorology
University of Oklahoma School of Meteorology - Center for Analysis and
Prediction of Storms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20111123/27bbe0c1/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: meso_proj_ms_fr_jdduda.gs
Type: application/octet-stream
Size: 874 bytes
Desc: not available
Url : http://gradsusr.org/pipermail/gradsusr/attachments/20111123/27bbe0c1/attachment.obj
------------------------------
_______________________________________________
gradsusr mailing list
gradsusr at gradsusr.org
http://gradsusr.org/mailman/listinfo/gradsusr
End of gradsusr Digest, Vol 21, Issue 66
****************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20111123/989bb2d9/attachment-0003.html
More information about the gradsusr
mailing list