| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# Copyright (C) 2010 Francesco P. Lovergine <[email protected]> |
| 4 |
# |
| 5 |
# This script shamely predates my previous GMT coast lines download script. |
| 6 |
# |
| 7 |
# This program is free software; you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License version 3, |
| 9 |
# as published by the Free Software Foundation. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program; if not, write to the Free Software |
| 18 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 |
# |
| 20 |
|
| 21 |
usage() { |
| 22 |
cat <<EOF |
| 23 |
usage: $0 [egm84_30|egm84_15|egm96_15|egm96_5|egm2k8_5|egm2k8_2.5|egm2k8_1|all] |
| 24 |
|
| 25 |
This program can be used to download the earth Geoid models used by |
| 26 |
GeographicLib and the GeoidEval tool to compute the EGM geoid heights by |
| 27 |
interpolation at different grid size. Note that by default the EGM96 |
| 28 |
Geoid is used with a 5' grid, but you can use any of the following |
| 29 |
models and resolutions, with different resolts in approximation errors: |
| 30 |
|
| 31 |
bilinear error cubic error |
| 32 |
name geoid grid max rms max rms |
| 33 |
egm84-30 EGM84 30' 1.546m 70mm 0.274m 14mm |
| 34 |
egm84-15 EGM84 15' 0.413m 18mm 0.020m 1mm |
| 35 |
egm96-15 EGM96 15' 1.152m 40mm 0.169m 7mm |
| 36 |
egm96-5 EGM96 5' 0.140m 5mm 0.003m 1mm |
| 37 |
egm2008-5 EGM2008 5' 0.478m 12mm 0.294m 5mm |
| 38 |
egm2008-2_5 EGM2008 2.5' 0.135m 3mm 0.031m 1mm |
| 39 |
egm2008-1 EGM2008 1' 0.025m 1mm 0.003m 1mm |
| 40 |
|
| 41 |
EOF |
| 42 |
} |
| 43 |
|
| 44 |
set -e |
| 45 |
|
| 46 |
if [ $(id -u) -ne 0 ]; then |
| 47 |
echo "Run this script as root" |
| 48 |
exit 1 |
| 49 |
fi |
| 50 |
|
| 51 |
if [ $(which bunzip2|wc -l) -eq 0 ]; then |
| 52 |
echo "Please install bzip2 before using this script" |
| 53 |
exit 6 |
| 54 |
fi |
| 55 |
|
| 56 |
# List of currently available data grids |
| 57 |
ALL="egm96-5 egm96-15 egm84-30 egm84-15 egm2008-5 egm2008-2_5 egm2008-1" |
| 58 |
|
| 59 |
# Default is downloading EGM96 geoid with 5' grid |
| 60 |
if [ $# -eq 0 ]; then |
| 61 |
FILE=egm96-5 |
| 62 |
else |
| 63 |
case "$1" in |
| 64 |
egm84_30) |
| 65 |
FILE=egm84-30 |
| 66 |
;; |
| 67 |
egm84_15) |
| 68 |
FILE=egm84-15 |
| 69 |
;; |
| 70 |
egm96_15) |
| 71 |
FILE=egm96-15 |
| 72 |
;; |
| 73 |
egm96_5) |
| 74 |
FILE=egm96-5 |
| 75 |
;; |
| 76 |
egm2k8_5) |
| 77 |
FILE=egm2008-5 |
| 78 |
;; |
| 79 |
egm2k8_2.5) |
| 80 |
FILE=egm2008-2_5 |
| 81 |
;; |
| 82 |
egm2k8_1) |
| 83 |
FILE=egm2008-1 |
| 84 |
;; |
| 85 |
all) |
| 86 |
FILE=all |
| 87 |
;; |
| 88 |
help|-h|--help) |
| 89 |
usage |
| 90 |
exit 5 |
| 91 |
;; |
| 92 |
*) |
| 93 |
echo "Unknown argument '$1'" && usage |
| 94 |
exit 4 |
| 95 |
;; |
| 96 |
esac |
| 97 |
fi |
| 98 |
|
| 99 |
SHARE_DIR=/usr/share/GeographicLib |
| 100 |
if [ ! -d $SHARE_DIR ]; then |
| 101 |
echo "Geographiclib target directory $SHARE_DIR not found" |
| 102 |
exit 2 |
| 103 |
fi |
| 104 |
TMPDIR=`mktemp -t -d geographiclib-geoid.XXXXXXXX` || exit 3 |
| 105 |
|
| 106 |
get_file() { |
| 107 |
URL="https://downloads.sourceforge.net/project/geographiclib/geoids-distrib/$1.tar.bz2?use_mirror=autoselect" |
| 108 |
ARCHIVE=$TMPDIR/$1.tar.bz2 |
| 109 |
if [ -x /usr/bin/wget ]; then |
| 110 |
GET_IT="wget --progress=bar -O$ARCHIVE $URL" |
| 111 |
else if [ -x /usr/bin/curl ]; then |
| 112 |
GET_IT="curl --progress-bar -o$ARCHIVE $URL" |
| 113 |
fi |
| 114 |
fi |
| 115 |
echo $GET_IT && $GET_IT && tar xojvf $ARCHIVE -C $SHARE_DIR |
| 116 |
} |
| 117 |
|
| 118 |
if [ "$FILE" != "all" ]; then |
| 119 |
get_file $FILE |
| 120 |
else |
| 121 |
for f in $ALL |
| 122 |
do |
| 123 |
get_file $f |
| 124 |
done |
| 125 |
fi |
| 126 |
|
| 127 |
rm -rf $TMPDIR |
| 128 |
|
| 129 |
cat <<EOF |
| 130 |
|
| 131 |
Geoid grid(s) downloaded and installed under $SHARE_DIR/geoids. |
| 132 |
|
| 133 |
EOF |
| 134 |
|
| 135 |
exit 0 |