-
Notifications
You must be signed in to change notification settings - Fork 6
/
defval_demo.gs
65 lines (54 loc) · 1.43 KB
/
defval_demo.gs
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
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* defval_demo.gs
*
* Illustrates the use of the 'q defval' and 'set defval' commands
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
'open model.ctl'
* restrict the dimension environment to see things more clearly
xmin = 0.5
xmax = 15.5
ymin = 0.5
ymax = 10.5
'set x 'xmin' 'xmax
'set y 'ymin' 'ymax
* the "defval" commands will only work with 2-D defined variables
'define var = ps'
* Display the variable with colored grid cells and their values
'c'
'set grid off'
'set mproj off'
'set xaxis 'xmin' 'xmax
'set yaxis 'ymin' 'ymax
'set gxout grfill'
'd var'
'set gxout grid'
'set digsiz .14'
'd var'
* Use the mouse to click on a grid point to change
say 'Click on any grid point'
'q pos'
xscreen = subwrd(result,3)
yscreen = subwrd(result,4)
* Convert screen positions to grid coordinates
'q xy2gr 'xscreen' 'yscreen
xgrid = subwrd(result,3)
ygrid = subwrd(result,6)
* Round the grid values to the nearest integer
gx = math_nint(xgrid)
gy = math_nint(ygrid)
* Get the value of the defined variable
'q defval var 'gx' 'gy
val = subwrd(result,3)
say 'The value at grid point ('gx','gy') is --> 'val
* Ask for a new replacement value and assign it
prompt 'Enter a new value --> '
pull newval
'set defval var 'gx' 'gy' 'newval
* Display the newly updated variable
'c'
'set xaxis 'xmin' 'xmax
'set yaxis 'ymin' 'ymax
'set gxout grfill'
'd var'
'set gxout grid'
'd var'