3 |
michaesp |
1 |
#!/usr/bin/perl
|
|
|
2 |
|
|
|
3 |
# --------------------------------------------------------
|
|
|
4 |
# Separate different commands out (delimiter @)
|
|
|
5 |
# --------------------------------------------------------
|
|
|
6 |
|
|
|
7 |
# Get input command and remove all spaces
|
|
|
8 |
$cmd = $ARGV[0];
|
|
|
9 |
$_ = $cmd;s/\s+//g;$cmd=$_;
|
|
|
10 |
$len = length $cmd;
|
|
|
11 |
|
|
|
12 |
# Split the command string according to logical operators
|
|
|
13 |
$nline = 0;
|
|
|
14 |
while ( $len > 0 )
|
|
|
15 |
{
|
|
|
16 |
# Get the length of the (remaining) command string
|
|
|
17 |
$len = length $cmd;
|
|
|
18 |
|
|
|
19 |
# Get the position of the next command separator
|
|
|
20 |
$at = index($cmd,'@');
|
|
|
21 |
if ( $at == -1 )
|
|
|
22 |
{ $next = $len+1; }
|
|
|
23 |
elsif ( $at >= 0 )
|
|
|
24 |
{ $next = $at; }
|
|
|
25 |
|
|
|
26 |
# A logical operator is not allowed to be at position 0
|
|
|
27 |
if ( $next == 0)
|
|
|
28 |
{
|
|
|
29 |
die('Invalid expression... Check @ separator position ');
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
# Extract the next substring
|
|
|
33 |
$sub = substr($cmd,0,$next);
|
|
|
34 |
$cmd = substr($cmd,$next+1,$len-$next-1);
|
|
|
35 |
$len = length $cmd;
|
|
|
36 |
|
|
|
37 |
# Save the command in a new line
|
|
|
38 |
@field[$nline] = $sub;
|
|
|
39 |
$nline = $nline + 1;
|
|
|
40 |
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
# Number of lines ist too large by 1
|
|
|
44 |
$nline = $nline - 1;
|
|
|
45 |
|
|
|
46 |
# Set some defaults
|
|
|
47 |
if ( $nline == 2 )
|
|
|
48 |
{
|
|
|
49 |
$nline = 3;
|
|
|
50 |
@field[3] = 'nil';
|
|
|
51 |
}
|
|
|
52 |
if ( $nline == 1 )
|
|
|
53 |
{
|
|
|
54 |
$nline = 3;
|
|
|
55 |
@field[2] = 'hPa';
|
|
|
56 |
@field[3] = 'nil';
|
|
|
57 |
}
|
|
|
58 |
if ( $nline == 0 )
|
|
|
59 |
{
|
|
|
60 |
$nline = 3;
|
|
|
61 |
@field[1] = 'nil()';
|
|
|
62 |
@field[2] = 'hPa';
|
|
|
63 |
@field[3] = 'nil';
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
# --------------------------------------------------------
|
|
|
67 |
# Handle each command line separately
|
|
|
68 |
# --------------------------------------------------------
|
|
|
69 |
|
|
|
70 |
# ----- Horizontal grid ----------------------------------
|
|
|
71 |
|
|
|
72 |
# Now looking at the horizontal grid specifier
|
|
|
73 |
$entry = @field[0];
|
|
|
74 |
|
|
|
75 |
# Extract the command and the parameter list
|
|
|
76 |
$left = index($entry,'(');
|
|
|
77 |
$right = index($entry,')');
|
|
|
78 |
if ( ($left != -1) && ($right != -1) )
|
|
|
79 |
{
|
|
|
80 |
$cmd = substr($entry,0,$left);
|
|
|
81 |
$list = substr($entry,$left+1,$right-$left-1);
|
|
|
82 |
$len = length $list;
|
|
|
83 |
}
|
|
|
84 |
else
|
|
|
85 |
{
|
|
|
86 |
die('Invalid expression... Check horizontal [] separator position ');
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
# Now building the parametr list
|
|
|
90 |
$len = length $list;
|
|
|
91 |
$npar = 0;
|
|
|
92 |
while ( $len > 0 )
|
|
|
93 |
{
|
|
|
94 |
$next = index($list,',');
|
|
|
95 |
if ( $next != -1 )
|
|
|
96 |
{
|
|
|
97 |
@param[$npar] = substr($list,0,$next);
|
|
|
98 |
$list = substr($list,$next+1,$len-$next-1);
|
|
|
99 |
$len = length $list;
|
|
|
100 |
$npar = $npar + 1;
|
|
|
101 |
}
|
|
|
102 |
else
|
|
|
103 |
{
|
|
|
104 |
@param[$npar] = substr($list,0,$len);
|
|
|
105 |
$len = 0;
|
|
|
106 |
$npar = $npar + 1;
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
# Check for syntax (needed number of parameters)
|
|
|
111 |
if ( ($cmd eq "file") && ($npar != 1) )
|
|
|
112 |
{ die('Invalid horizontal mode[file]... Check number of parameters '); }
|
|
|
113 |
if ( ($cmd eq "line") && ($npar != 5) )
|
|
|
114 |
{ die('Invalid horizontal mode[line]... Check number of parameters '); }
|
|
|
115 |
if ( ($cmd eq "box.eqd") && ($npar != 5) )
|
|
|
116 |
{ die('Invalid horizontal mode[box.eqd]... Check number of parameters '); }
|
|
|
117 |
if ( ($cmd eq "box.grid") && ($npar != 4) )
|
|
|
118 |
{ die('Invalid horizontal mode[box.grid]... Check number of parameters '); }
|
|
|
119 |
if ( ($cmd eq "point") && ($npar != 2) )
|
|
|
120 |
{ die('Invalid horizontal mode[point]... Check number of parameters '); }
|
|
|
121 |
if ( ($cmd eq "shift") && ($npar != 4) )
|
|
|
122 |
{ die('Invalid horizontal mode[shift]... Check number of parameters '); }
|
|
|
123 |
if ( ($cmd eq "poly.eqd") && ($npar != 2) )
|
|
|
124 |
{ die('Invalid horizontal mode[poly.eqd]... Check number of parameters '); }
|
|
|
125 |
if ( ($cmd eq "poly.grid") && ($npar != 1) )
|
|
|
126 |
{ die('Invalid horizontal mode[poly.grid]... Check number of parameters ');}
|
|
|
127 |
|
|
|
128 |
# Write parameters
|
|
|
129 |
print "\"$cmd\"\n";
|
|
|
130 |
print "@param\n";
|
|
|
131 |
|
|
|
132 |
# ----- Vertical grid ----------------------------------------
|
|
|
133 |
|
|
|
134 |
# Now looking at the vertical grid specifier
|
|
|
135 |
$entry = @field[1];
|
|
|
136 |
|
|
|
137 |
# Extract the command and the parameter list
|
|
|
138 |
$left = index($entry,'(');
|
|
|
139 |
$right = index($entry,')');
|
|
|
140 |
if ( ($left != -1) && ($right != -1) )
|
|
|
141 |
{
|
|
|
142 |
$cmd = substr($entry,0,$left);
|
|
|
143 |
$list = substr($entry,$left+1,$right-$left-1);
|
|
|
144 |
$len = length $list;
|
|
|
145 |
}
|
|
|
146 |
else
|
|
|
147 |
{
|
|
|
148 |
die('Invalid expression... Check vertical [] separator position ');
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
# Now building the parametr list
|
|
|
152 |
$len = length $list;
|
|
|
153 |
$npar = 0;
|
|
|
154 |
while ( $len > 0 )
|
|
|
155 |
{
|
|
|
156 |
$next = index($list,',');
|
|
|
157 |
if ( $next != -1 )
|
|
|
158 |
{
|
|
|
159 |
@param[$npar] = substr($list,0,$next);
|
|
|
160 |
$list = substr($list,$next+1,$len-$next-1);
|
|
|
161 |
$len = length $list;
|
|
|
162 |
$npar = $npar + 1;
|
|
|
163 |
}
|
|
|
164 |
else
|
|
|
165 |
{
|
|
|
166 |
@param[$npar] = substr($list,0,$len);
|
|
|
167 |
$len = 0;
|
|
|
168 |
$npar = $npar + 1;
|
|
|
169 |
}
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
# Check for syntax (needed number of parameters)
|
|
|
173 |
if ( ($cmd eq "file") && ($npar != 1) )
|
|
|
174 |
{ die('Invalid vertical mode[file]... Check number of parameters '); }
|
|
|
175 |
if ( ($cmd eq "level") && ($npar != 1) )
|
|
|
176 |
{ die('Invalid vertical mode[level]... Check number of parameters '); }
|
|
|
177 |
if ( ($cmd eq "list") && ($npar == 0) )
|
|
|
178 |
{ die('Invalid vertical mode[list]... Check number of parameters '); }
|
|
|
179 |
if ( ($cmd eq "profile") && ($npar != 3) )
|
|
|
180 |
{ die('Invalid vertical mode[profile]... Check number of parameters '); }
|
|
|
181 |
if ( ($cmd eq "grid") && ($npar != 2) )
|
|
|
182 |
{ die('Invalid vertical mode[grid]... Check number of parameters '); }
|
|
|
183 |
|
|
|
184 |
# Write parameters
|
|
|
185 |
print "\"$cmd\"\n";
|
|
|
186 |
if ( $cmd eq "list") { print "$npar\n"; }
|
|
|
187 |
if ( $npar > 0 )
|
|
|
188 |
{ print "@param\n"; }
|
|
|
189 |
|
|
|
190 |
# ----- Vertical coordinate system ----------------------------------
|
|
|
191 |
|
|
|
192 |
# Now looking at the vertical grid specifier
|
|
|
193 |
$cmd = @field[2];
|
|
|
194 |
|
|
|
195 |
# Check for allowed coordinate axes
|
10 |
michaesp |
196 |
if ( ($cmd ne "m") && ($cmd ne "m,agl") && ($cmd ne "hPa") && ($cmd ne "hPa,agl") && ($cmd ne "K") && ($cmd ne "PVU") && ($cmd ne "INDEX") )
|
3 |
michaesp |
197 |
{ die('Invalid vertical axis [allowed: m / m,agl / hPa / hPa / K / PVU / INDEX] '); }
|
|
|
198 |
|
|
|
199 |
# Write command
|
|
|
200 |
print "\"$cmd\"\n";
|
|
|
201 |
|
|
|
202 |
# ----- Selection criteria --------------------------------------------
|
|
|
203 |
|
|
|
204 |
# Now looking at the selection specifier
|
|
|
205 |
$cmd = @field[3];
|
|
|
206 |
|
|
|
207 |
# Write command
|
|
|
208 |
print "$cmd\n";
|