File: script.html

package info (click to toggle)
grads 3%3A2.2.1-4
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 17,336 kB
  • sloc: ansic: 61,642; sh: 10,612; makefile: 201; python: 3
file content (1313 lines) | stat: -rw-r--r-- 44,447 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
<!--Copyright (C) 1988-2005 by the Institute of Global Environment and Society (IGES). See file COPYRIGHT for more information.-->

<html>
<title>GrADS Scripting Language</title>
<style type="text/css">
.red {
	color: #900;
}
</style>
<body bgcolor="e0f0ff" text="#000000">
<h1>GrADS Scripting Language</h1>
<p>
<a href="#intro">Introduction to GrADS scripts</a><br>
<a href="#elements">Elements of the Language:</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#comment">comment</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#statement">statement</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#assignment">assignment</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#standardio">say / prompt / pull</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#ifendif">if / else / endif</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#while">while / endwhile</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#variables">variables</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#operators">operators</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#expressions">expressions</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#functions">Functions</a><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#intrinsic">Intrinsic Functions</a><br>
<a href="#commands">Commands that complement the scripting language</a><br>
<a href="#widgets">Widgets</a> (N.B. The Cairo graphics display inteface in <span class="red">version 2.1+</span> does not support widgets) <br>
<a href="library.html">Script Library</a><br>
<a href="reference_card_scl.pdf">Scripting Language Reference Card</a>
<font size=-1>
(Requires <a href="http://www.adobe.com/products/acrobat/readstep.html">
Adobe Acrobat Reader</a>)</font>

<p>
<hr>
<p>

<h2><a name="intro"><u>Introduction to GrADS Scripts</u></a></h2>

<p>
Scripts offer users the facility to program GrADS operations.
Although it is relatively easy for users to produce sophisticated
GrADS graphics without ever writing a script, there are occasions
where the programming capability makes things even easier. This
section explains the general capabilities of scripts, how to run them,
and suggests a strategy for users who may wish to write their own.

<p>
<i><b>What scripts can do</b></i>

<p>
The GrADS scripting language, used via the GrADS <code><a
href="gradcomdrun.html">run</a></code> command, provides a similar
capability to the <code><a href="gradcomdexec.html">exec</a></code>
command, except that scripts also have flow control, defined
variables, and access to GrADS command output. Scripts may be written
to perform a variety of functions, such as allowing a user to interact
with Grads via point and click interface, animating any desired
quantities, and annotating plots with information obtained from GrADS
query commands.

<p>
The scripting language is similar to REXX in implementation. All
variables are of type STRING. Mathematical operations are supported on
script variables. Flow control is achieved via
<code>if/else/endif</code> and <code>while/endwhile</code>
constructs. Loop flow may be modified by the <code>continue</code> or
<code>break</code> commands. Strings contained in variables or
generated via an expression may be issued to GrADS as commands. The
output from those commands (i.e., the text that GrADS would have
output to the terminal) is put into a variable and made available to
the script. The language includes support for functions.

<p>
Before writing your own scripts, it is recommended that you read the
rest of this section and then try to run some of the scripts in the <a
href="library.html">library</a>. Study these example
scripts, referring to this page for information on syntax etc., and
you will soon be equipped to write scripts of your own.<p>

<p>
<i><b>Running scripts</b></i>

<p>
The command to execute a script is the 
<code><a href="gradcomdrun.html">run</a></code> command:

<p>
<ul><code>
<a href="gradcomdrun.html">run</a> <i>filename &ltarguments&gt</i>
</code></ul>

<p>
This command runs the script contained in the named file, which
generally has a <code>".gs"</code> tag at the end. Optional
<code><i>arguments</i></code> are passed to the script as a string
variable. You may issue any GrADS command from a script, including the
<code>run</code> command. When calling scripts recursively, be sure
that you can back out of the recursion and return to your main script.


<p>
<i><b>Automatic script execution</b></i>

<p>
You may have a simple script automatically executed before every
<code><a href="gradcomddisplay.html">display</a></code> command:

<p>
<ul><code>
<a href="gradcomdsetimprun.html">set imprun</a> <i>script-name</i>
</code></ul>

<p>
This script would typically be used to set an option that by
default gets reset after each <code><a href="gradcomddisplay.html">display</a></code> 
command, for example:

<p>
<ul><code><a href="gradcomdsetgrads.html">set grads</a> off</code></ul>

<p>
You can issue any GrADS command from this script, but the interactions
are not always clear.  For example, if you issued a <code><a
href="gradcomddisplay.html">display</a></code> command from this
script, you could easily enter an infinite recursion loop.

<p>
The argument to the script is the expression from the <code><a
href="gradcomddisplay.html">display</a></code>
command.

<p>
<i><b><a name="storing">Storing GrADS scripts</a></b></i>

<p>
It is convenient to put all your GrADS "utility" scripts in one
directory (e.g., <code>/usr/local/grads/lib/scripts</code>).

<p>
To simplify running these scripts, GrADS first looks in the
current directory for the script and then, if it can't find it,
appends the "<code>.gs</code>" extension and tries again.  For example,
suppose you are working on a test script called <code>t.gs</code>.  You would
run it in GrADS by,

<p>
<ul><code>run t</code></ul>

<p>
If after the first two tries, the script still can't be located,
then GrADS looks in the directory defined by the environment
variable <code>GASCRP</code>.  In the <code>t(csh)</code>, for example,

<p>
<ul><code>setenv GASCRP /home1/grads/lib</code></ul>

<p>
or in <code>ksh</code>,

<p>
<ul><code>export GASCRP=/home1/grads/lib</code></ul>

<p>
Note the if the <code>/</code> is not added to the end of the
directory name, it is automatically added by UNIX. However, it'll
still work if you type<p>

<ul><code>setenv GASCRP /home1/grads/lib/</code></ul>

<p>
If the script cannot be found, then <code>.gs</code> is appended and GrADS
tries yet again.  Thus,

<p>
<ul><code>d slp <br> run /home1/grads/lib/cbarn.gs</code></ul>

<p>
simplifies to,

<p>
<ul><code>d slp <br> run cbarn</code></ul>


<hr>

<h2><a name="elements"><u>Elements of the Language</u></a></h2>

<p>
A script file is made up of records. The end of a script record is
determined by either a newline character or a semicolon (where the
semicolon is not contained within a constant string).<p>

Each script record may be one of the following types:<p>
<ul>
<li>comment<br>
<li>statement<br>
<li>assignment<br>
<li>say / prompt / pull<br>
<li>if / else / endif<br>
<li>while / endwhile / break / continue<br>
<li>function header / return<br>
</ul>

<p>
Many of the above record types will contain expressions.  Script
expressions are composed of operands and operators. Operands
are strings constants, variables, or function calls; operators
are mathematical, logical, or concatenation operations. Further
discussion of these record types and the expressions they may
contain is given below.

<p>
<i><b><a name="comment">Comment</a></b></i>

<p>
Comments in GrADS scripts must contain an asterisk (*) in the first column. 

<p>
<i><b><a name="statement">Statement</a></b></i>

<p>
The statement record consists only of an expression:
<p>
<ul><code><i>expression</i></code></ul>

<p>
The expression is evaluated, and the resulting string is then
submitted to GrADS as a command for execution. The script variable
<code>rc</code> will contain the return code from the GrADS command
(this will always be an integer value). In addition, any text output
from GrADS in response to the command is put in the variable
<code>result</code> for examination by the script. A GrADS error
resulting from an invalid command WILL NOT terminate execution of the
script.

<p>
The simplest type of expression is a string constant, which is just a
character string enclosed in single or double quotes. Here's an
example of simple script containing a comment plus statements
comprised of string constants:

<p>
<ul>
<code>
* this is a sample script <br>
'open my_sst_dataset.ctl' <br>
'set lat -30 30' <br>
'set lon 90 300' <br>
'display sst' <br>
</code>
</ul>


<p>
<i><b><a name="assignment">Assignment</a></b></i>

<p>
Assignment records are used to define variables and assign them
values. The format of the assignment record is:
<p>
<ul><code>variable = <i>expression</i></code></ul>

<p>
The expression is evaluated, and the result is assigned to be the
value of the indicated variable. The same example from above can be
rewritten to include assignment statements. Note the use of explicit
and implied concatenation:

<p>
<ul>
<code>
'open my_sst_dataset.ctl' <br>
minlat = -30 <br>
maxlat = minlat + 60 <br>
minlon =  90 <br>
maxlon = 300 <br>
'set lat 'minlat%' '%maxlat <br>
'set lon 'minlon' 'maxlon <br>
'display sst' <br>
</code>
</ul>

<p>
<i><b><a name="standardio">say / prompt</a></b></i>

<p>
To present information or questions to the GrADS user via the terminal
(standard output), use the <code>say</code> or <code>prompt</code>
commands:
<p>
<ul><code>
say <i>expression</i><br>
prompt <i>expression</i><br>
</code></ul>
<p>
The result of the <code><i>expression</i></code> is written to the
terminal. The <code>prompt</code> command works the same way as the
<code>say</code> command but does not append a carriage return. It is
possible to combine variables and string constants when writing to
standard output:
<p>
For example:<p>
<ul><code>
line = "Peter Pan, the flying one" <br>
say line<br>
say `She said it is `line<br>
</code></ul>
<p>
gives:
<p>
<ul><code>
Peter Pan, the flying one<br>
She said it is Peter Pan, the flying one
</code></ul>


<p>
<i><b>pull</b></i>

<p>
To retrieve information provided by the GrADS user via the terminal
(standard input), use the <code>pull</code> command:<p>
<ul><code>pull <i>variable</i></code></ul>
<p>
The script will pause for user input from the keyboard (ending with
the carriage return), and then the string entered by the user is
assigned to the indicated variable name. To elaborate on a
previous example:

<p>
<ul><code>
'open my_sst_dataset.ctl' <br>
prompt 'Enter min and max latitudes: ' <br>
pull minlat maxlat <br>
prompt 'Enter min and max longitudes: ' <br>
pull minlon maxlon <br>
'set lat 'minlat%' '%maxlat <br>
'set lon 'minlon' 'maxlon <br>
'display sst' <br>
</code></ul>


<p>
<i><b><a name="ifendif">if / else / endif</a></b></i>

<p>
One way to control the flow of script execution is via the <code>if/else/endif</code> 
construct. The format is as follows:<p>
<ul>
<code>
if expression<br>
&nbsp;&nbsp;&nbsp;script record<br>
&nbsp;&nbsp;&nbsp;script record<br>
&nbsp;&nbsp;&nbsp;. <br>
&nbsp;&nbsp;&nbsp;. <br>
else<br>
&nbsp;&nbsp;&nbsp;script record<br>
&nbsp;&nbsp;&nbsp;. <br> 
&nbsp;&nbsp;&nbsp;. <br>
endif<br>
</code>
</ul>

<p>
The <code>else</code> block is optional, but the <code>endif</code>
record must be present. The script records following <code>if
expression</code> are executed if the expression evaluates to a string
containing the character 1. If the expression evaluates to 0, then the
script records in the <code>if</code> block are not executed and the
script continues with the <code>else</code> block (if it is present)
or the record following <code>endif</code>. The <code>if
expression</code> record must be separated from the script records
that follow it. For example, the following script record would be
invalid:
<p>
<ul><code>if (i = 10) j = 20 </code></ul>
<p>
The correct syntax requires three separate script records. This is
achieved by putting each record on one line:
<p> 
<ul><code> if (i = 10)<br> 
&nbsp;&nbsp;&nbsp;j = 20 <br> endif<br> </code></ul>
<p>
Alternatively, the three records could be on the same line separated 
by a semicolon:
<p>
<ul><code>if (i = 10) ; j = 20 ; endif</code></ul>
<p>
N.B. There is no <code>elseif</code> construct in GrADS.


<p>
<i><b><a name="while">while / endwhile</a></b></i>

<p>
Another method for controlling the flow of script execution is the <code>while/endwhile</code> construct. The format is as follows:
<p>
<ul>
<code>
while expression<br>
&nbsp;&nbsp;&nbsp;script record<br>
&nbsp;&nbsp;&nbsp;script record <br>
&nbsp;&nbsp;&nbsp;. <br>
&nbsp;&nbsp;&nbsp;. <br>
endwhile<br>
</code>
</ul>

<p>
The script records following <code>while expression</code> are
executed if the expression evaluates to a string containing the
character 1. If the expression evaluates to 0, then the script records
in the <code>while</code> block are not executed and the script continues
with the record following <code>endwhile</code>. The <code>while
expression</code> record must be separated from the script records
that follow it.

<p>
Two additional script commands may be used to modify the
<code>while</code> loop execution: <code><b>break</b></code> and
<code><b>continue</b></code>. Inserting the <code>break</code> statement will
immediately end execution of the loop and the script will move on to
the records following <code>endwhile</code>. The <code>continue</code>
statement will immediately end execution of the loop, but the script
will then branch immediately back to the top of the loop, and the
expression will be re-evaluated.<p>

While loops are often used as counters. For example:<p>
<ul>
  <code> count = 1 <br>
  while (count < 10) <br>
  &nbsp;&nbsp;&nbsp;'set t 'count <br>
  &nbsp;&nbsp;&nbsp;'display z' <br>
  &nbsp;&nbsp;&nbsp;if (rc != 0) ; break ; endif <br>
  &nbsp;&nbsp;&nbsp;count = count + 1 <br>
  endwhile<br>
  </code>
</ul>


<p>
<i><b><a name="variables">Variables</a></b></i>

<p>
The contents of a script variable is always a character string.
However, if the contents of a variable represent a number in the
correct format, certain operators may perform numeric operations on
that variable, giving a string result which will also be a number.
<p>
Variable names can have from 1 to 8 characters, beginning with an
alphabetic character and containing letters or numbers only. The name
is case sensitive. If a variable has not yet been assigned, its value
is its name.
<p>
String variables or string constants are enclosed in either single or
double quotes. An example of an assignment statement that defines a
string variable is as follows:
<p>
<ul><code>name = `Peter Pan' <br> name = "Peter Pan"</code></ul>
<p>
Numeric variables may be entered without quotes, but are still
considered strings.
<p>
<ul><code>number = -99.99</code></ul>


<p>
<i><b>Predefined script variables</b></i>
<p>
Some variable names are predefined; it is a good idea to avoid
assigning values to these variables. The following are predefined
script variables -- their values will change with every execution of a
GrADS command from the script:
<p>
<ul><code>rc <br> result </code></ul>

<p>
<code>lat, lon, and lev </code>are also used
as predefined internal variables in GrADS. Although using them within a script
is okay, in order to avoid confusion it is not recommended.

<p>
<i><b>Global string variables</b></i>
<p>
String variables are usually local to the functions they are contained
in. Global string variables are also available.  They are specified
via the variable name. Any variable name starting with an
underscore (_) will be assumed to be a global variable, and will keep
its value throughout an entire script file. An example of an
assignment statement that defines a global string variable is as
follows:
<p>
<ul><code>_var1 = "global variable 1"</code></ul>
<p>
<i>N.B.</i> Global variables cannot be used in function headers. For example:
<p>
<ul><code>function dostuff(_var)</code></ul>
<p>
wouldn't make sense, since <code>_var</code> is a global variable, and would
be invalid if it were the only argument.

<p>
<i><b>Compound string variables</b></i>
<p>
Compound variables are used to construct arrays in scripts. A compound
variable has a variable name with segments separated by periods. For
example:
<p>
<ul><code>varname.i.j</code></ul>
<p>
In this case, when the variable contents are accessed,
<code>i</code> and <code>j</code> will be looked up to see if they are
also variables (non-compound). If they are, the <code>i</code> and
<code>j</code> will be replaced by the string values of <code>i</code>
and <code>j</code>. For example:
<p>
<ul><code>i = 10 <br> j = 3 <br> varname.i.j = 343</code></ul>
<p>
In the above example, the assignment is equivalent to:
<p>
<ul><code>varname.10.3 = 343</code></ul>
<p>
Note that the string values of <code>i</code> and <code>j</code> may
be anything, but the variable name specification in the script must
follow the rules for variable names: letters or numbers, with a
leading letter. The variable name after substitution may be any
string:
<p>
<ul><code>i = 'a#$xx' <br> varname.i = 343</code></ul>
<p>
The above is valid.  However, we cannot refer to this variable
name directly:
<p>
<ul><code>varname.a#$xx = 343</code></ul>
<p>
would be invalid.
<p>
Variable names may <i>not</i> be longer than 16 characters, either
before or after substitution.
<p>
Note that the GrADS scripting language is not particularly
efficient in handling large numbers of variables.  Thus compound
variables should not be used to create large arrays:
<p>
<ul><code>
i = 1 <br> 
while (i < 10000) <br> 
&nbsp&nbsp&nbsp;var.i = i <br>
&nbsp&nbsp&nbsp;i = i + 1 <br>
endwhile
</code></ul>
<p>
The above loop will create 10000 distinct variable names. Such
a large number of variables in the variable chain will slow the
script down a lot. 
</ul>


<p>
<i><b><a name="operators">Operators</a></b></i>

<p>
The following operators are implemented in the scripting language:<p>
<ul>
<code>|      &nbsp;&nbsp;&nbsp;&nbsp;</code> logical OR <br>
<code>&amp;  &nbsp;&nbsp;&nbsp;&nbsp;</code> logical AND <br>
<code>!      &nbsp;&nbsp;&nbsp;&nbsp;</code> unary NOT <br>
<code>-      &nbsp;&nbsp;&nbsp;&nbsp;</code> unary minus <br>
<code>=      &nbsp;&nbsp;&nbsp;&nbsp;</code> equal <br>
<code>!=     &nbsp;&nbsp;&nbsp;</code> not equal <br>
<code>&gt;   &nbsp;&nbsp;&nbsp;&nbsp;</code> greater than <br>
<code>&gt;=  &nbsp;&nbsp;&nbsp;</code> greater than or equal <br>
<code>&lt;   &nbsp;&nbsp;&nbsp;&nbsp;</code> less than <br>
<code>&lt;=  &nbsp;&nbsp;&nbsp;</code> less than or equal <br> 
<code>%      &nbsp;&nbsp;&nbsp;&nbsp;</code> concatenation <br>
<code>+      &nbsp;&nbsp;&nbsp;&nbsp;</code> addition <br>
<code>-      &nbsp;&nbsp;&nbsp;&nbsp;</code> subtraction <br>
<code>*      &nbsp;&nbsp;&nbsp;&nbsp;</code> multiplication <br>
<code>/      &nbsp;&nbsp;&nbsp;&nbsp;</code> division<br>
</ul>

<p>
The following operators will perform a numeric operation if the
operands are numeric:<p>

<ul><code>=, !=, &gt;, &gt;=, &lt;, &lt;=, +, -, *, /</code></ul>

<p>
If any of the following operations are attempted with non-numeric
operands, an error will result:<p>

<ul><code>+, -, *, /</code></ul>

<p>
Arithmetical operations are done in floating point. If the result is
integral, the result string will be an integer. Logical operations
will give a character <code>0</code> (zero) if the result is FALSE,
and a character <code>1</code> (one) if the result is TRUE.


<p>
<i><b><a name="expressions">Expressions</a></b></i>

<p>
Script expressions consist of any combination of operands, operators,
and parentheses. Operands may be string constants, variables, 
or function calls. The precedence of the operators is:
<p>
<ul><code>
-, !  (Unary) <br>
/, * <br>
+, - <br>
% <br>
=, !=, >, >=, <, <= <br>
& <br>
| <br>
</code></ul>

<p>
Within the same precedence level, operations are performed left
to right. Parentheses modify the order of operation according to
standard convention.

<p>
All script expressions, including all function calls, etc. are
evaluated and the resulting string is what gets executed as a
command. For example:
<p>
<ul><code>
var1 = -1 ; var2 = 10 <br>
if (var1*var2 < 10 & var1 > 0) <br>
&nbsp;&nbsp;&nbsp;say 'both statements are true' <br>
else <br>
&nbsp;&nbsp;&nbsp;say 'it is not the case that both statements are true' <br>
endif <br>
</code></ul>
<p>
For the expression following <code>if</code>, both sides of the
logical operation must be evaluated before the entire expression can
be simplified into a true or false result. In this case, the
subexpression on the left is true, but the subexpression on the left
is not, so the whole expressions resolves to 0 (zero) and the script
will print:
<p>
<ul><code>it is not the case that both statements are true</code></ul>

<p>
<b><i>Concatenation</i></b>
<p>
In some espressions, the concatenation operator may be implied. The <code>%</code>
operator may be omitted whenever the two operands are a string
constant and a variable name. With implied concatentation, intervening
blanks will be ignored.
<p>
For example, the following expressions have the same effect:
<p>
<ul>
<code>'set lat 'minlat%' '%maxlat  &nbsp;&nbsp;&nbsp;&nbsp;</code>
uses the concatenation operator % <br>
<code>'set lat 'minlat' 'maxlat &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>
concatenation is implied <br>
</ul>

<p>
Assuming two previous statements, <code>minlat = -30 </code> and
<code> maxlat = 30</code>, the resulting expression would be:
<p>
<ul><code>'set lat -30 30'</code></ul>
<p>
Keep in mind the order of precedence when using the concatenation operator.

<p>
<i><b><a name="functions">Functions</a></b></i>
<p>
Function calls take the form of:
<p>
<ul><code>name(arg,arg,arg,...)</code></ul>

<p>
where the function name follows the same rules as for variable names, and
the arguments may be any expression.

Functions may either be contained within the script file itself,
or the may be intrinsic functions. Functions contained within
other script files are not supported as yet (other script files
may be executed via the GrADS run command).<p>

In either case, functions are invoked as a script expression is
being evaluated.  Script functions always have a single string
result, but may have one or more string arguments.  Functions are
invoked by:<p>

<dd><code>name(arg,arg,arg...)</code><p>

If the function has no arguments, you must still provide the
parentheses:<p>

<dd><code>name()</code><p>

You may provide your own functions from within your script file
by using the <code>function</code> definition record:<p>

<dd><code>function name(variable, variable, ...)</code><p>

To return from a function, use the <code>return</code> command:<p>

<dd><code>return <i>expression</i></code><p>

The <code><i>expression</i></code> is optional; if not provided, a NULL string will
be returned.  (A null string is: '')  The result of the function
is the result of the expression specified on the return command.<p>

When a function is invoked, the arguments are evaluated, then
flow of control is transferred to the function.  The variables
contained in the list within the function definition record are
initialized   to the values of the passed arguments.  If too few
arguments where passed for the variables specified, the trailing
variables are uninitialized.  If too many arguments are passed,
the extra arguments are discarded.<p>

You may modify the variables from the function definition record
without modifying the variables from the calling routine.<p>

Scope of variables is normally local to the function, but can be
global.<p>

When a script file is first invoked (via the <code>run</code> command), 
execution starts at the beginning of the file.  A function
definition record may optionally be provided at the beginning. 
If it is, it should specify one variable name.  This variable
will be initialized to any <code>run</code> command options.  If no options
were given, the variable will be initialized to NULL.<p>

<p>
<i><b><a name="intrinsic">Intrinsic Functions</a></b></i>
<p>
<ul>
<b><code>strlen (<i>string</i>)</code></b>
<br>
This function returns the length (number of characters) of  
<code><i>string</i></code>.

<p><b><code>sublin (<i>string, n</i>)</code></b>
<br>
This function gets a single line from a string containing several
lines. The result is the <code><i>nth</i></code> line of
<code><i>string</i></code>.  If the string has too few lines, the
result is NULL.  <code><i>n</i></code> must be an integer.

<p>
<b><code>subwrd (<i>string, n</i>)</code></b>
<br>
This functions gets a single word from a string. 
The result is the <code><i>nth</i></code> word of <code><i>string</i></code>.  
If the string is too short, the result is NULL. 
<code><i>n</i></code> must be an integer.

<p>
<b><code>substr (<i>string, start, length</i>)</code></b>
<br>
This function gets part of a string. 
The sub-string of <code><i>string</i></code> starting at location
<code><i>start</i></code> for length <code><i>length</i></code> will be returned.  
If the string is too short, the result will be short or NULL. 
<code><i>start</i></code> and <code><i>length</i></code> must be integers.

<p>
<b><code>read (<i>filename</i>)</code></b>
<br>
This functions reads individual records from file <code><i>filename</i></code>.
Repeated calls must be made to read consecutive records. The result is
a string containing two lines: the first line is the return code, the 
2nd line is the record read from the file. The record may be a maximum 
of 80 characters. Use the <code>sublin</code> function to separate the
result. Return codes are:

<ul>
<code>0 - </code>ok <br>
<code>1 - </code>open error <br>
<code>2 - </code>end of file <br>
<code>8 - </code>file open for write <br>
<code>9 - </code>I/O error<br>
<br>
</ul>

Files are opened when the first call to read is made for a 
particular file name. Files are closed when the execution of the
script file terminates (note that files remain open between
function calls, etc).

<p>
<b><code>write (<i>filename, record</i> &lt;, append&gt;)</code></b>
<br>
This functions writes records to output file <code>filename</code>.  

On the first call to write for a particular file, the file is opened
in write mode.  This will destroy an existing file!  If you use the
optional append flag, the file will be opened in append mode, and all
writes will be appended to the end of the file.  Return codes are:
<ul>
<code>0</code> - ok <br>
<code>1</code> - open error <br>
<code>8</code> - file open for read</ul>

<p>
<b><code>close (<i>name</i>)</code></b>
<br>
This function closes the named file.  This must be done if you wish to
read from a file you have been writing to.  This can also be used to
rewind a file.  Return codes are:
<ul>
<code>0</code> - ok <br>
<code>1</code> - file not open</ul>
<p><b><code>sys (<i>command</i>)</code></b><br>
  This function was added in <span class="red">version 2.1.1.b0. </span> It  submits the specified command to the shell and returns the resulting text stream that gets sent to standard output (stdout). The  command is passed to /bin/sh. There is no way to check if the command succeeded; the return code is not captured, and an empty result could mean that the command has no output or that the command failed. Any error notifications or text streams sent to standard error (stderr) will appear in the console window and not the returned text unless you explicitly include a capture of stderr in your command string. </p>
<p>Consider the following script test_sys.gs: 
<ul><code>
  cmd1=&quot;ls ./foo&quot;<br>
  cmd2=&quot;ls ./foo 2&gt;&amp;1&quot;<br>
  cmd3='echo Hello, world!'<br>
  res1=sys(cmd1); say 'cmd1 returned -&gt;'res1'&lt;-'<br>
  res2=sys(cmd2); say 'cmd2 returned -&gt;'res2'&lt;-'<br>
  res3=sys(cmd3); say 'cmd3 returned -&gt;'res3'&lt;-'<br>
  <br>
</code></ul>
The session in the GrADS command window when running test_sys.gs looks like this:<br>
<br>
<ul>
<code>
  ga-> test_sys<br>    
ls: ./foo: No such file or directory<br>
cmd1 returned -><-<br>
cmd2 returned ->ls: ./foo: No such file or directory<br>
<-<br>
cmd3 returned ->Hello, world!<br>
<-<br>
ga-> <br>
</code></ul>
</p>
</ul>


<h2><a name="commands"><u>Commands that complement the scripting language</u></a></h2>
<p>
There are some GrADS commands that, although not designed
exclusively for scripts, are most useful in script applications. 
These include:

<p>
<b><code><a href="gradcomdquery.html">query</a> &lt;<i>option</i>&gt;</code></b> or 
<b><code><a href="gradcomdquery.html">q</a> &lt;<i>option</i>&gt;</code></b>
<ul>
<p>
To see the list of available options, issue the <code><a
href="gradcomdquery.html">query</a></code> command by itself. A
description of the <code><a href="gradcomdquery.html">query</a></code>
options that are most useful for script applications follows.

<p>
<b><code><a href="gradcomdquery.html">q</a> define</code></b> --
Lists all defined variables

<p>
<b><code><a href="gradcomdquery.html">q</a> define <i>varname</i></code></b> --
(Added in <span class="red">version 2.1.1b0</span>) Lists information about a specific defined variable: grid dimensions, coordinate axis definitions, calendar type, and whether it has been modified to be a climatological variable. 

<p>
<b><code><a href="gradcomdquery.html">q</a> defval <i>ival
jval</i></code></b> -- Gives defined grid value at <i>ival, jval</i>
<p>
To interactively modify grid point values for a <code>defined</code>
variable, <code><a href="gradcomdquery.html">q</a> defval</code>
can be used in conjunction with <code><a
href="gradcomdsetdefval.html">set defval</a></code>. For example, the
code shown below queries the value of sst at gridpoint(i,j), then
tests to see if the value is less than -1.6, and if it is, sets the
sst to a bad value.
<ul>
<code>
'q defval sst 'i' 'j <br>
val = subwrd(result,3) <br>
if (val < -1.6)  <br>
&nbsp&nbsp'set defval sst 'i' 'j' 'bad_value <br>
endif <br>
</code>
</ul>

<p>
<b><code><a href="gradcomdquery.html">q</a> dims</code></b> --
Gives the current dimension environment

<p>
<b><code><a href="gradcomdquery.html">q</a> file
<i>n</i></code></b> -- Gives info on file number <i>n</i>

<p>
<b><code><a href="gradcomdquery.html">q</a> files</code></b> --
Lists open files

<p>
<b><code><a href="gradcomdquery.html">q</a> fwrite</code></b> --
Gives the name of the file used for fwrite operations

<p>
<b><code><a href="gradcomdquery.html">q</a> gxinfo</code></b> --
Lists graphics settings

<p>
This option is handy when trying to find the plot area. The output
from <code><a href="gradcomdquery.html">q</a> gxinfo</code> might
look like this:

<p>
<code>
<ul>
Last Graphic = Line <br>
Page Size = 11 by 8.5 <br>
X Limits = 2 to 10.5 <br>
Y Limits = 0.75 to 7.75 <br>
Xaxis = Lon  Yaxis = Val <br>
Mproj = 2<br>
</ul>
</code>

<p>
The first line indicates that the output is a line plot. The second line
gives the page dimensions -- in this case GrADS is in landscape
mode. The third and fourth lines give the x and y boundaries of the
plot. In this case the plot has 1-inch margins in the x direction and
0.75-inch margins in the y direction.  The fifth line tells what kind
of axes you have, and the sixth line identifies the map projection:
<br>
<ul>
<code>1&nbsp;&nbsp;&nbsp;&nbsp;</code>Scaled (no preservation of aspect ratio)<br>
<code>2&nbsp;&nbsp;&nbsp;&nbsp;</code>Latlon (2-D horizontal fields) <br>
<code>3&nbsp;&nbsp;&nbsp;&nbsp;</code>Northern polar stereographic <br>
<code>4&nbsp;&nbsp;&nbsp;&nbsp;</code>Southern polar stereographic <br>
<code>5&nbsp;&nbsp;&nbsp;&nbsp;</code>Robinson (lon range must be -180 to
180 and lat range must be -90 to 90)<br>
</ul>

<p>
<b><code><a href="gradcomdqpos.html">q pos</a></code></b> -- Waits for mouse click, returns position<br>

<p>
<b><code><a href="gradcomdquery.html">q</a> shades</code></b> -- Gives colors and levels of shaded contours<br>

<p>
<b><code><a href="gradcomdquery.html">q</a> time</code></b> - gives time range of current open file<br>

<p>
<b><code><a href="gradcomdquery.html">q</a> <i>transform coord1 coord2</i></code></b> -- Coordinate transformations 

<ul>
<p>
where <code><i>transform</i></code> is one of: <br>
<code>xy2w &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>XY coords to world coords <br>
<code>xy2gr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>XY coords to grid coords <br>
<code>w2xy &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>world coords to XY coords <br>
<code>w2gr &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>world coords to grid coords <br>
<code>gr2w &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>grid coords to world coords <br>
<code>gr2xy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>grid coords to XY coords <br>
</ul>

<p>
<i>XY coords</i> are inches on the page (screen) where the page is
11x8.5 inches or 8.5x11 inches, depending on how GrADS was started.

<p>
<i>World coords</i> are lat, lon, lev, time or val, depending on what
the dimension environment is when the grid was displayed. Note that
time is displayed (and must be specified) in GrADS absolute date/time
format. val is the value coordinate for a 1-D plot (linegraph).

<p>
<i>Grid coordinates</i> are the i,j indices the grid being
displayed. For station data sets, grid and world coordinates are
equivalent except for the time dimension. Note that if you display a
grid from a 'wrapped' data set, the grid numbers may be out of range
of the actual file grid numbers. (A 'wrapped' data set is a data set
that covers the earth in the longitude direction. Wrapping takes place
automatically). The conversions are done consistently, but you may
want to be sure you can handle the wrapping case if your data set is
global.

<p>
N.B. Coordinate transform queries are only valid after something has
been displayed, and the transformations apply only to the most recent
item that has been displayed.
</ul>

<p>
<b><code><a name="scriptfindstn">set gxout findstn</a></code></b>
<p>
When using the graphics output type <code><a href="gradcomdsetgxout.html">set gxout findstn</a></code>, three
arguments must be provided with the <a
href="gradcomddisplay.html"><code>display</code></a> command. The
first argument is a station data expression. The 2nd and 3rd arguments
are the X and Y screen coordinates of the of the desired search
location.  GrADS will find the station closest to the specified X and
Y position, and print its stid, lon, and lat.  This graphics output
type should only be used when X and Y are the varying dimensions and
AFTER a regular display command (that results in graphics output) is
entered.
<p>
<b><code>set dbuff on|off</code></b>
<p>
This command sets double buffer mode <code>on</code> or
<code>off</code>. This allows animation to be controlled from a
script. The <a href="gradcomdclear.html"><code>clear</code></a>
command also sets double buffer mode <code>off</code>.

<p>
<b><code>swap</code></b>

<p>
Swaps buffers, when double buffer mode is <code>on</code>. If double
buffer mode is <code>off</code>, this command has no effect.

<p>
The usual usage of these commands would be:<p>

<ul>
<code>
set dbuff on <br>
start looping <br>
&nbsp&nbsp&nbsp;display <i>something</i><br>
&nbsp&nbsp&nbsp;swap <br>
endloop <br>
set dbuff off<br>
</code>
</ul>

<p>
<a name="widgets"><h2><u>Widgets</u></h2></a>
<p>
GrADS has the capability to implement a graphical user interface. This
interface is used to draw widgets (buttons and pull down menus) that
allow a "point and click" interface between the Grads user and the
scripting language.

 (N.B. The Cairo graphics display inteface in <span class="red">version 2.1+</span> does not support widgets.) 
<p>
<h3>Buttons</h3>
<p>
Here is a sample from a script illustrating how to draw a button:

<p>
<ul>
<pre>
set rgb 90 100 100 100
set rgb 91  50  50  50
set rgb 92 200 200 200
set button 2 90 91 92 3 90 92 91 6
draw button 1 5.5 1 2 0.5 This is a Button
</pre>
</ul>

<p>
The reference pages for <a href="gradcomdsetbutton.html"><code>set
button</code></a> and <a href="gradcomddrawbutton.html"><code>draw
button</code></a> contain information on how to specify the button
characteristics and position.

<p>
A button's initial "state" is <code>ON</code>. If a user clicks on a
button following a <a href="gradcomdqpos.html"><code>q pos</code></a>
command, then the button state will switch from <code>ON (1)</code> to
<code>OFF (0)</code>. A second <a href="gradcomdqpos.html"><code>q
pos</code></a> followed by a mouse click on the button will return it
to the <code>ON</code> state. The button state may also be changed
with the <a href="gradcomdredrawbutton.html"><code>redraw
button</code></a> command.

<p>
The output from the <a href="gradcomdqpos.html"><code>q pos</code></a> command 
is what makes the button widgets so useful. Here is a template of what 
<a href="gradcomdqpos.html"><code>q pos</code></a> returns after a mouse click
on a button:

<p>
<code>
Position = <i>xpos ypos mousebutton widgetclass buttonnumber buttonstate </i></code>

<p>
where:
<ul>
<code><i>xpos, ypos</i>&nbsp&nbsp&nbsp&nbsp</code>
- coordinates of the mouse click in virtual page units <br>
<code><i>mousebutton</i>&nbsp&nbsp&nbsp</code>
- either 1, 2, or 3 for the left, center, or right mouse button <br>
<code><i>widgetclass</i>&nbsp&nbsp&nbsp</code>
- 1 is the widget class number for buttons  <br>
<code><i>buttonnumber</i>&nbsp&nbsp</code>
- the number assigned to the button when it was originally drawn <br>
<code><i>buttonstate</i>&nbsp&nbsp&nbsp</code>
- either 0 (meaning "off") or 1 (meaning "on")
</ul>

<p>
If the user did not click on a button, then <code><i>widgetclass</i></code>
will be 0 and there will be no output for
<code><i>buttonnumber</i></code> or <code><i>buttonstate</i></code>.


<p>
<h3>Drop Menus</h3>
<p>
As with button widgets, dropmenus provide a "point-and-click"
interface between scripts and the GrADS user. The reference pages for
<a href="gradcomdsetdropmenu.html"><code>set dropmenu</code></a> and
<a href="gradcomddrawdropmenu.html"><code>draw dropmenu</code></a>
contain information on how to specify the dropmenu characteristics and
position.
<p>
The output from <a href="gradcomdqpos.html"><code>q pos</code></a>
after a click on a dropmenu is similar to that described above for
buttons.  Here is a template of what is returned by <a
href="gradcomdqpos.html"><code>q pos</code></a> after a mouse click
on a dropmenu:

<p>
<code>Position = <i>xpos ypos mousebutton widgetclass menunumber inum</i></code>

<p>
where:
<ul>
<code><i>xpos, ypos</i>&nbsp&nbsp&nbsp&nbsp</code>
- coordinates of the mouse click in the menu base in virtual page units <br>
<code><i>mousebutton</i>&nbsp&nbsp&nbsp</code>
- either 1, 2, or 3 for the left, center, or right mouse button <br>
<code><i>widgetclass</i>&nbsp&nbsp&nbsp</code>
- 3 is the widget class number for dropmenus  <br>
<code><i>menunumber</i>&nbsp&nbsp&nbsp&nbsp</code>
- the number assigned to the dropmenu when it was originally drawn <br>
<code><i>inum</i>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</code>
-  the menu item number selected from the menu list
</ul>

<p>
If no menu item is selected, then <code><i>menunumber</i></code> and <code><i>inum</i></code> will
both be -1.


<p>
Here is a script sample illustrating how to use a dropmenu:

<p>
<pre>
'reset events'
'set rgb 90 100 100 100'
'set rgb 91 150 150 150'
'set rgb 92 200 200 200'
'set dropmenu 1 91 90 92 0 91 90 92 1 91 90 92 90 92 6'
'draw dropmenu 1 1 8 1.5 0.5 Select a Variable | Wind | Temperature | Height | SLP '
noselect = 1
while (noselect)
  'q pos'
  menunum  = subwrd(result,7)
  menuitem = subwrd(result,8)
  if (menunum = 1)
    if menuitem = 1 ; newbase = 'Variable = Wind'   ; endif
    if menuitem = 2 ; newbase = 'Variable = Temp'   ; endif
    if menuitem = 3 ; newbase = 'Variable = Height' ; endif
    if menuitem = 4 ; newbase = 'Variable = SLP'    ; endif
    'draw dropmenu 1 1 8 1.5 0.5 'newbase' | Wind | Temperature | Height | SLP '
    noselect = 0
  endif
endwhile
</pre>
<p>
Here is another script sample illustrating how to use cascading dropmenus:
<p>
<pre>
'clear'
'set rgb 90 100 100 100'
'set rgb 91 150 150 150'
'set rgb 92 200 200 200'
'set button 1 91 -1 -1 1 91 90 92 12'
'draw button 1 1 8 1 0.5 quit'
'set dropmenu 1 91 -1 -1 1 91 90 92 1 91 90 92 90 92 6'
'draw dropmenu 1 1.5 7.5 2 0.5  Menu Base | Space | Earth >05> | Sun | Moon'
'draw dropmenu 5 cascade Ocean | Land | Atmosphere >11> | Biosphere'
'draw dropmenu 11 cascade Snow | Rain | Mist | Tornado '

while (1)
  'q pos'
  say result
  ev = subwrd(result,6)
  if (ev!=3); break; endif;
endwhile
</pre>
<p>
It is left to the GrADS script writer (that means you!) to run the demo and 
interpret the output of <a href="gradcomdqpos.html"><code>q pos</code></a>
when clicking on all the options in the cascade of dropmenus. 

<p>
<h3>Rubber banding</h3>

<p>
GrADS has a widget type called <code>rband</code> for rubber banding.  There
are two <code>rband</code> modes: <code>box</code> and <code>line</code>.
To set up the <code>rband</code> widget, use the following command:
<p>
<ul><code>
<a href="gradcomdsetrband.html">set rband</a> <i>num mode x1 y1 x2 y2</i>
</code></ul>

<p>
where:
<p>
<ul>
<code><i>num</i>&nbsp;&nbsp;&nbsp;</code>
- widget number<br>
<code><i>mode</i>&nbsp;&nbsp;</code>
- may be either <code>box</code> or <code>line</code><br>
<code><i>x1</i>&nbsp;&nbsp;&nbsp;&nbsp;</code>
- lowest X point where the widget will be active (in virtual page units)<br>
<code><i>y1</i>&nbsp;&nbsp;&nbsp;&nbsp;</code>
- lowest Y point where the widget will be active (in virtual page units)<br>
<code><i>x2</i>&nbsp;&nbsp;&nbsp;&nbsp;</code>
- highest X point where the widget will be active (in virtual page units)<br> 
<code><i>y2</i>&nbsp;&nbsp;&nbsp;&nbsp;</code>
- highest Y point where the widget will be active (in virtual page units)<br>
</ul>

<p>
In <code>box</code> mode, as the user clicks and drags the mouse in
the active rband area a box is drawn with one corner located at the
initial click and the opposite corner located at the release point. In
<code>line</code> mode, a line is drawn between these two points.

<p>
For example, suppose you  want to set up a
<code>box</code> rubber band widget in the plot region only.

<p>
First, execute <a href="gradcomdquery.html"><code>q gxinfo</code></a>
to get the X and Y limits of the plot area. The result from <a
href="gradcomdquery.html"><code>q gxinfo</code></a> might look like
this:

<ul>
<pre>
Last Graphic = Line
Page Size = 11 by 8.5
X Limits = 2 to 10.5
Y Limits = 0.75 to 7.75
Xaxis = Lon  Yaxis = Val
Mproj = 2
</pre>
</ul>

<p>
Second, set up the widget with <a
href="gradcomdsetrband.html"><code>set rband</code></a> using the dimensions
grabbed from the result of <a href="gradcomdquery.html"><code>q gxinfo</code></a>:
<p>
<ul>
<pre>
xlims = sublin(result,3)
ylims = sublin(result,4)
x1 = subwrd(xlims,4)
x2 = subwrd(xlims,6)
y1 = subwrd(ylims,4)
y2 = subwrd(ylims,6)
'set rband 21 box 'x1' 'y1' 'x2' 'y2
</pre>
</ul>

<p>
Finally, use <a href="gradcomdqpos.html"><code>q pos</code></a> 
to activate the widget.

<p>
<ul><code>ga-> q pos</code></ul>

<p>
This freezes the system until the user clicks, drags, and 
then releases the mouse somewhere within the active rband area. 
Here is a template for the output you would get from GrADS after
a mouse click and drag in the rband area:<p>

<ul>
<code>Position = <i>xpos1 ypos1 mousebutton widgetclass widgetnumber xpos2 ypos2</i></code>
</ul>

<p>
where:
<ul>
<code><i>xpos1, ypos1</i>&nbsp&nbsp&nbsp</code>
- coordinates of the initial mouse click in virtual page units <br>
<code><i>mousebutton</i>&nbsp&nbsp&nbsp&nbsp</code>
- either 1, 2, or 3 for the left, center, or right mouse button <br>
<code><i>widgetclass</i>&nbsp&nbsp&nbsp&nbsp</code>
- 2 is the widget class number for rbands  <br>
<code><i>widgetnumber</i>&nbsp&nbsp&nbsp</code>
- the number assigned to the
rband widget when it was set up  <br>
<code><i>xpos2, ypos2</i>&nbsp&nbsp&nbsp</code>
- coordinates of the mouse release point in virtual page units <br>
</ul>

<p>
The page coordinates can be then be used to draw a box (or a line)
where the user specified, or parsed and used in the coordinate
transform <a href="gradcomdquery.html"><code>q xy2w</code></a> to
recover the lat/lon region selected by the user.

</body>
</html>