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