-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathsetlabs.gs
143 lines (123 loc) · 2.87 KB
/
setlabs.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
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
function setlabs( args )
_version = '0.01b2'
rc = gsfallow("on")
if( args = '' )
help()
return
endif
***** Default value *****
axis = ''
int = 0
mul = '1'
add = '0'
opmax = 0
***** Arguement *****
i = 1
while( 1 )
arg = subwrd( args, i )
i = i + 1;
if( arg = '' ); break; endif
while( 1 )
*** option
if( arg = '-int' ) ; int=subwrd(args,i) ; i=i+1 ; break ; endif
if( arg = '-mul' | arg = '-add' )
opmax = opmax + 1
op.opmax = arg
opval.opmax = subwrd(args,i)
i=i+1
break
endif
*** dim
if( axis = '' )
axis = arg
break
endif
say 'syntax error: 'arg
return
endwhile
endwhile
type.1 = 'xtype' ; dim.1 = 'lon'
type.2 = 'ytype' ; dim.2 = 'lat'
type.3 = 'ztype' ; dim.3 = 'lev'
cnt = 0
i = 1
while( i <= 3 )
tmp = qdims( type.i )
if( tmp = 'varying' )
cnt = cnt + 1
if( ( cnt = 1 & axis = 'xl' ) | ( cnt = 2 & axis = 'yl' ) )
dim = dim.i
break
endif
endif
i = i + 1
endwhile
min = qdims( dim'min' )
max = qdims( dim'max' )
o = 1
while( o <= opmax )
if( op.o = '-mul' )
min = min * (opval.o)
max = max * (opval.o)
endif
if( op.o = '-add' )
min = min + (opval.o)
max = max + (opval.o)
endif
o = o + 1
endwhile
if( int > 0 )
num = ( max - min ) / int
if( valnum(num) != 1 )
say 'error in setlabs.gs: number of labels must be an integer.'
say 'min=' % min % ', max=' % max % ', int=' % int % ', num=' % num
return
endif
else
num = 10
int = ( max - min ) / num
endif
if( max < min )
num = -num
if( int > 0 ) ; int = -int ; endif
endif
n = 0
val = min
while( n <= num )
val_disp = val
if( n = 0 )
labs = val_disp
else
labs = labs % '|' % val_disp
endif
n = n + 1
val = val + int
endwhile
prex( 'set 'axis'abs 'labs )
return
*
* help
*
function help()
say ' Name:'
say ' setlabs '_version' - Set x/y labels.'
say ' '
say ' Usage:'
say ' setlabs ( xl | yl )'
say ' [ (-mul | -add) value1 [ (-mul | -add) value2 ... ]]'
say ' [-int interval]'
say ''
say ' ( xl | yl ) : Horizontal label or vertical label.'
say ' (-mul value1) : Label values are multiplied by value1.'
say ' (-add value1) : label values are added by value1.'
say ' Operations are performed by the order appeared in the -mul/-add options.'
say ' -int interval : interval of label values (after operator is applied).'
say ''
say ' Note:'
say ' [arg-name] : specify if needed'
say ' (arg1 | arg2) : arg1 or arg2 must be specified'
say ''
say ' Copyright (C) 2012-2015 Chihiro Kodama'
say ' Distributed under GNU GPL (http://www.gnu.org/licenses/gpl.html)'
say ''
return