[gradsusr] Array Variable displaying as string not numbers

Jan Ising jising at aggies.ncat.edu
Sat Feb 15 15:33:56 EST 2020


Hello Jeff,

This makes a lot more sense now. Thank you for not only taking the time to
provide a solution but also to explain the solution in detail.

P.S
My data is a control file where the grid is interpolated, sorry for not
specifying.

On Fri, Feb 14, 2020 at 12:59 PM <gradsusr-request at gradsusr.org> wrote:

> 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. Array Variable displaying as string not numbers (Jan Ising)
>    2. Re: Array Variable displaying as string not numbers (Jeff Duda)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 13 Feb 2020 20:39:27 -0500
> From: Jan Ising <jising at aggies.ncat.edu>
> To: gradsusr at gradsusr.org
> Subject: [gradsusr] Array Variable displaying as string not numbers
> Message-ID:
>         <
> CACPEFkezsg2q8X4+9QWtjc+OsjcM12mwTCOvrf_Nij7Um+zmHA at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hello,
>
>     I am new to GrADS and came across an issue that has given me quite some
> frustration. I am writing a script that calculates the temperature
> difference between two levels at each point within a region and then
> displays the values in the terminal (my script is indented to do more than
> this but the root of my issue arises from here). The problem is that the
> terminal displays the literal value of T_Diff (i.e " 'tc(Lev = 800) -
> tc(Lev = 700)' ", and not 15,18,22,etc... (for example)). Here is my code:
>
> (open file and setup basic graphics output formatting)
>
> TheLat = 31
> while(TheLat >=31 & TheLat <=37.5)
> 'set Lat 'TheLat
> TheLong = -115
>     while (TheLong>=-115 & TheLong<=-108)
>         'set Lon 'TheLong
>         T_Diff = 'tc(Lev = 800) - tc(Lev = 700)'
>         say T_Diff
>         TheLong = TheLong + 0.5
>     endwhile
> TheLat = TheLat + 0.5
> endwhile
>
> Perhaps this issue is a simple syntax error, perhaps it is a logic error,
> either way I am here to figure that out, any help would be greatly
> appreciated!
>
>
> -Thank you,
> Jon
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://gradsusr.org/pipermail/gradsusr/attachments/20200213/5809b91d/attachment-0001.html
> >
>
> ------------------------------
>
> Message: 2
> Date: Thu, 13 Feb 2020 20:01:22 -0700
> From: Jeff Duda <jeffduda319 at gmail.com>
> To: GrADS Users Forum <gradsusr at gradsusr.org>
> Subject: Re: [gradsusr] Array Variable displaying as string not
>         numbers
> Message-ID:
>         <
> CAAig09BWDUAATV914VQkk4XhpRbRqP23XUZzbUQ4Pe4OYhcsfA at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> The difference between command line commands and scripting variables is
> biting you here. You cannot directly access values from the arrays in your
> data file in a single command in a GrADS script. You have to display the
> variable first, then use the sublin, subwrd, or substr script commands to
> capture the field value. For instance, let's say you have 850-mb
> temperature. You would have to do something like this:
>
> 'set lon -110'
> 'set lat 31'
> 'd tc(lev=850)'
> t1 = subwrd(result,4)
>
> Notice how only the last of those commands is a true internal-GrADS
> scripting command. The rest are just command line stuff.
>
> You may want to play around with your data and script at a base level
> before fully programming. There are complications depending on how you
> setup your displayed grid. You did not provide any information in your
> email, so I have to be generic.
>
> If used a control file to open the data and you have a PDEF line, you are
> likely going to be dealing with grid interpolation rather than exact grid
> point values. In that case, GrADS will output something like
> "Notice: plotting interpolated data"
> when you run any display command at the command line. I would test your own
> data to see if this is the case. If it is, then your script will need an
> additional line to capture the field value:
> line = sublin(result,2)
> t1 = subwrd(line,4)
>
> Notice the second argument of these functions. They indicate which line,
> inline word, or subword string to pull out from the input (the first
> argument). Your output may look different than what I have used in the past
> (usually the 4th word contains the value itself), so you may need to end up
> using a different index value. Also, 'result' is a fixed keyword. Pretty
> much any command you issue at the command line in GrADS will have some text
> output for you stored within *result*. So just adding
>
> say result
>
> after display commands will give you some information on what GrADS is
> doing, and this is the source of where you grab the field values. So run
> 'say result' after some of your display commands to see 1) how many lines
> are being out put (so you know how to use sublin()), 2) How many words
> there are in the line you want (for subwrd()), and 3) which specific word
> or substring within a word you want (if needed). Note that subwrd parses
> the input line using blank characters as a delimiter, so you don't need to
> specify spaces.
>
> Now, you want to pull out an array of values, so you'll need to loop this
> behavior. Ultimately, your code will need to look something like this:
>
> start_lat = 31
> end_lat = 37.5
> start_lon = -115
> end_lon = -108
> delta_lat = 0.5
> delta_lon = 0.5
> ln = start_lon
> while (ln <= end_lon)
>  'set lon 'ln
>  lt = start_lat
>  while (lt <= end_lat)
>   'set lat 'lt
>   'd tc(lev=800)-tc(lev=700)'
>   line = sublin(result,2)
>   T_Diff = subwrd(line,4)
>   lt = lt + delta_lat
>  endwhile
>  ln = ln + delta_lon
> endwhile
>
> in order to get what it appears you want.
>
> I know, GrADS scripting is a bit unintuitive, and has something of a
> learning curve, and the notion of mixed display and script commands fools a
> lot of people and can be a real turn off. But this is how this particular
> application works.
>
> Jeff Duda
>
> On Thu, Feb 13, 2020 at 7:09 PM Jan Ising <jising at aggies.ncat.edu> wrote:
>
> > Hello,
> >
> >     I am new to GrADS and came across an issue that has given me quite
> > some frustration. I am writing a script that calculates the temperature
> > difference between two levels at each point within a region and then
> > displays the values in the terminal (my script is indented to do more
> than
> > this but the root of my issue arises from here). The problem is that the
> > terminal displays the literal value of T_Diff (i.e " 'tc(Lev = 800) -
> > tc(Lev = 700)' ", and not 15,18,22,etc... (for example)). Here is my
> code:
> >
> > (open file and setup basic graphics output formatting)
> >
> > TheLat = 31
> > while(TheLat >=31 & TheLat <=37.5)
> > 'set Lat 'TheLat
> > TheLong = -115
> >     while (TheLong>=-115 & TheLong<=-108)
> >         'set Lon 'TheLong
> >         T_Diff = 'tc(Lev = 800) - tc(Lev = 700)'
> >         say T_Diff
> >         TheLong = TheLong + 0.5
> >     endwhile
> > TheLat = TheLat + 0.5
> > endwhile
> >
> > Perhaps this issue is a simple syntax error, perhaps it is a logic error,
> > either way I am here to figure that out, any help would be greatly
> > appreciated!
> >
> >
> > -Thank you,
> > Jon
> > _______________________________________________
> > gradsusr mailing list
> > gradsusr at gradsusr.org
> > http://gradsusr.org/mailman/listinfo/gradsusr
> >
>
>
> --
> Jeff Duda, Research Scientist
> University of Colorado Boulder
> Cooperative Institute for Research in Environmental Sciences
> NOAA/OAR/ESRL/Global Systems Division
> Boulder, CO
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://gradsusr.org/pipermail/gradsusr/attachments/20200213/e6f0237d/attachment-0001.html
> >
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>
>
> ------------------------------
>
> End of gradsusr Digest, Vol 120, Issue 9
> ****************************************
>


-- 
-From,
Jan Ising
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gradsusr.org/pipermail/gradsusr/attachments/20200215/1e8e86c7/attachment.html>


More information about the gradsusr mailing list