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 |
if ( ($cmd eq "mask.grid") && ($npar != 2) )
|
|
|
128 |
{ die('Invalid horizontal mode[mask.grid]... Check number of parameters ');}
|
|
|
129 |
if ( ($cmd eq "mask.eqd") && ($npar != 3) )
|
|
|
130 |
{ die('Invalid horizontal mode[mask.eqd]... Check number of parameters ');}
|
|
|
131 |
|
|
|
132 |
# Write parameters
|
|
|
133 |
print "\"$cmd\"\n";
|
|
|
134 |
print "@param\n";
|
|
|
135 |
|
|
|
136 |
# ----- Vertical grid ----------------------------------------
|
|
|
137 |
|
|
|
138 |
# Now looking at the vertical grid specifier
|
|
|
139 |
$entry = @field[1];
|
|
|
140 |
|
|
|
141 |
# Extract the command and the parameter list
|
|
|
142 |
$left = index($entry,'(');
|
|
|
143 |
$right = index($entry,')');
|
|
|
144 |
if ( ($left != -1) && ($right != -1) )
|
|
|
145 |
{
|
|
|
146 |
$cmd = substr($entry,0,$left);
|
|
|
147 |
$list = substr($entry,$left+1,$right-$left-1);
|
|
|
148 |
$len = length $list;
|
|
|
149 |
}
|
|
|
150 |
else
|
|
|
151 |
{
|
|
|
152 |
die('Invalid expression... Check vertical [] separator position ');
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
# Now building the parametr list
|
|
|
156 |
$len = length $list;
|
|
|
157 |
$npar = 0;
|
|
|
158 |
while ( $len > 0 )
|
|
|
159 |
{
|
|
|
160 |
$next = index($list,',');
|
|
|
161 |
if ( $next != -1 )
|
|
|
162 |
{
|
|
|
163 |
@param[$npar] = substr($list,0,$next);
|
|
|
164 |
$list = substr($list,$next+1,$len-$next-1);
|
|
|
165 |
$len = length $list;
|
|
|
166 |
$npar = $npar + 1;
|
|
|
167 |
}
|
|
|
168 |
else
|
|
|
169 |
{
|
|
|
170 |
@param[$npar] = substr($list,0,$len);
|
|
|
171 |
$len = 0;
|
|
|
172 |
$npar = $npar + 1;
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
# Check for syntax (needed number of parameters)
|
|
|
177 |
if ( ($cmd eq "file") && ($npar != 1) )
|
|
|
178 |
{ die('Invalid vertical mode[file]... Check number of parameters '); }
|
|
|
179 |
if ( ($cmd eq "level") && ($npar != 1) )
|
|
|
180 |
{ die('Invalid vertical mode[level]... Check number of parameters '); }
|
|
|
181 |
if ( ($cmd eq "list") && ($npar == 0) )
|
|
|
182 |
{ die('Invalid vertical mode[list]... Check number of parameters '); }
|
|
|
183 |
if ( ($cmd eq "profile") && ($npar != 3) )
|
|
|
184 |
{ die('Invalid vertical mode[profile]... Check number of parameters '); }
|
|
|
185 |
if ( ($cmd eq "grid") && ($npar != 2) )
|
|
|
186 |
{ die('Invalid vertical mode[grid]... Check number of parameters '); }
|
|
|
187 |
|
|
|
188 |
# Write parameters
|
|
|
189 |
print "\"$cmd\"\n";
|
|
|
190 |
if ( $cmd eq "list") { print "$npar\n"; }
|
|
|
191 |
if ( $npar > 0 )
|
|
|
192 |
{ print "@param\n"; }
|
|
|
193 |
|
|
|
194 |
# ----- Vertical coordinate system ----------------------------------
|
|
|
195 |
|
|
|
196 |
# Now looking at the vertical grid specifier
|
|
|
197 |
$cmd = @field[2];
|
|
|
198 |
|
|
|
199 |
# Check for allowed coordinate axes
|
|
|
200 |
if ( ($cmd ne "hPa") && ($cmd ne "hPa,agl") && ($cmd ne "K") && ($cmd ne "PVU") && ($cmd ne "INDEX") )
|
|
|
201 |
{ die('Invalid vertical axis [allowed: hPa / hPa,agl / K / PVU / INDEX] '); }
|
|
|
202 |
|
|
|
203 |
# Write command
|
|
|
204 |
print "\"$cmd\"\n";
|
|
|
205 |
|
|
|
206 |
# ----- Selection criteria --------------------------------------------
|
|
|
207 |
|
|
|
208 |
# Now looking at the selection specifier
|
|
|
209 |
$cmd = @field[3];
|
|
|
210 |
|
|
|
211 |
# Write command
|
|
|
212 |
print "$cmd\n";
|