File: createGeoidGrid

package info (click to toggle)
gpsbabel 1.7.0%2Bds-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 100,408 kB
  • sloc: cpp: 104,725; xml: 14,055; sh: 4,699; ansic: 2,062; makefile: 960; perl: 681; tcl: 138; javascript: 9
file content (101 lines) | stat: -rwxr-xr-x 2,840 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
#
# this is used to generate heightgrid.h
# which is used by height.c to compute the EMG96 geoid height
# relative to the WGS84 ellipsoid.
# It requires the GeographicLib utility GeoidEval.
#
if [ $# != 2 ]; then
	echo "Usage: $0 grid_spacing_degrees gbint8|gbint16" >&2
	exit 1
fi
geoidgrid=$1 # grid spacing in degrees
geoidtype=$2
case $geoidtype in
gbint8 | int8_t)
	geoidscale=1.0
	geoidformat1="%4.0f"
	geoidformat2="%4.0f"
	;;
gbint16)
	geoidscale=100.0
	geoidformat1="%6.1f"
	geoidformat2="%6.0f"
	;;
*)
	echo "invalid type" >&2
	exit 1
	;;
esac
geoidmodel="egm96-5"
lats=$(seq -s' ' -90 $geoidgrid 90)
lons=$(seq -s' ' -180 $geoidgrid 180)
latarray=($lats)
lonarray=($lons)
echo "/*"
echo "    Copyright (C) 2013  Robert Lipe, robertlipe+source@gpsbabel.org"
echo ""
echo "    This program is free software; you can redistribute it and/or modify"
echo "    it under the terms of the GNU General Public License as published by"
echo "    the Free Software Foundation; either version 2 of the License, or"
echo "    (at your option) any later version."
echo ""
echo "    This program is distributed in the hope that it will be useful,"
echo "    but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the"
echo "    GNU General Public License for more details."
echo ""
echo "    You should have received a copy of the GNU General Public License"
echo "    along with this program; if not, write to the Free Software"
echo "    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA."
echo ""
echo " */"
echo "#ifndef HEIGHTGRID_H_INCLUDED_"
echo "#define HEIGHTGRID_H_INCLUDED_"
echo ""
echo "/* Created by \"$0 $1 $2\" using GeographicLib utility GeoidEval with $geoidmodel. */"
echo ""
echo "static constexpr double geoid_grid_deg = $geoidgrid;"
echo "static constexpr double geoid_scale = $geoidscale;"
echo "static constexpr int geoid_row = ${#latarray[@]};"
echo "static constexpr int geoid_col = ${#lonarray[@]};"
echo "static constexpr $geoidtype geoid_delta[geoid_row][geoid_col] = {"
idx=1
echo -n "  /*           "
for lon in $lons
do
	echo -n $geoidformat1 $lon | awk '{printf $1,$2}'
	if [ $idx -lt ${#lonarray[@]} ]; then
		echo -n ","
	fi
	let idx++
done
echo " */"

latidx=1
for lat in $lats
do
	echo -n "  /* "
	echo -n $lat | awk '{printf "%5.1f",$1}'
	echo -n " */ {"
	lonidx=1
	for lon in $lons
	do
		fullheight=$(echo "$lat $lon" | GeoidEval -n $geoidmodel -l)
		echo -n $geoidformat2 $fullheight $geoidscale | awk '{printf $1,$2*$3}'
		if [ $lonidx -lt ${#lonarray[@]} ]; then
			echo -n ","
    else
		  if [ $latidx -lt ${#latarray[@]} ]; then
        echo "},"
      else
        echo "}"
      fi
		fi
		let lonidx++
	done
	let latidx++
done
echo "};"
echo "#endif  // HEIGHTGRID_H_INCLUDED_"