Subversion Repositories lagranto.um

Rev

Rev 7 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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