| 1 |
#!/usr/bin/env python3 |
| 2 |
# |
| 3 |
# Copyright 2007 European Centre for Medium-Range Weather Forecasts (ECMWF) |
| 4 |
# |
| 5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
# you may not use this file except in compliance with the License. |
| 7 |
# You may obtain a copy of the License at |
| 8 |
# |
| 9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
# |
| 11 |
# Unless required by applicable law or agreed to in writing, software |
| 12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
# See the License for the specific language governing permissions and |
| 15 |
# limitations under the License. |
| 16 |
# |
| 17 |
# |
| 18 |
# This script is provided as help to clip / reduce size of mapgen data files. |
| 19 |
# |
| 20 |
import sys |
| 21 |
|
| 22 |
if len(sys.argv) < 6: |
| 23 |
print ("Not enough parameters!") |
| 24 |
print ("mapgen_clip in.mapgen out.mapgen lon_min lon_max lat_min lat_max") |
| 25 |
sys.exit() |
| 26 |
|
| 27 |
lon_min = float(sys.argv[3]) |
| 28 |
lon_max = float(sys.argv[4]) |
| 29 |
lat_min = float(sys.argv[5]) |
| 30 |
lat_max = float(sys.argv[6]) |
| 31 |
|
| 32 |
fin = open(sys.argv[1], 'r') |
| 33 |
fou = open(sys.argv[2], 'w') |
| 34 |
|
| 35 |
begin = "" |
| 36 |
|
| 37 |
for line in fin: |
| 38 |
if line == "# -b\n": |
| 39 |
begin=line |
| 40 |
else: |
| 41 |
s = line.split() |
| 42 |
if float(s[0]) > lon_min and float(s[0]) < lon_max: |
| 43 |
if float(s[1]) > lat_min and float(s[1]) < lat_max: |
| 44 |
if begin != "": |
| 45 |
fou.write(begin) |
| 46 |
begin = "" |
| 47 |
fou.write(line) |
| 48 |
|
| 49 |
fin.close() |
| 50 |
fou.close() |