GeoidToGTX.cpp
Go to the documentation of this file.
1 // Write out a gtx file of geoid heights above the ellipsoid. For egm2008 at
2 // 1' resolution this takes about 40 mins on a 8-processor Intel 2.66 GHz
3 // machine using OpenMP.
4 //
5 // For the format of gtx files, see
6 // http://vdatum.noaa.gov/dev/gtx_info.html#dev_gtx_binary
7 //
8 // data is binary big-endian:
9 // south latitude edge (degrees double)
10 // west longitude edge (degrees double)
11 // delta latitude (degrees double)
12 // delta longitude (degrees double)
13 // nlat = number of latitude rows (integer)
14 // nlong = number of longitude columns (integer)
15 // nlat * nlong geoid heights (meters float)
16 
17 #include <vector>
18 #include <iostream>
19 #include <fstream>
20 #include <string>
21 #include <algorithm>
22 
23 #if defined(_OPENMP)
24 #define HAVE_OPENMP 1
25 #else
26 #define HAVE_OPENMP 0
27 #endif
28 
29 #if HAVE_OPENMP
30 # include <omp.h>
31 #endif
32 
36 
37 using namespace std;
38 using namespace GeographicLib;
39 
40 int main(int argc, const char* const argv[]) {
41  // Hardwired for 3 args:
42  // 1 = the gravity model (e.g., egm2008)
43  // 2 = intervals per degree
44  // 3 = output GTX file
45  if (argc != 4) {
46  cerr << "Usage: " << argv[0]
47  << " gravity-model intervals-per-degree output.gtx\n";
48  return 1;
49  }
50  try {
51  // Will need to set the precision for each thread, so save return value
52  int ndigits = Utility::set_digits();
53  string model(argv[1]);
54  // Number of intervals per degree
55  int ndeg = Utility::val<int>(string(argv[2]));
56  string filename(argv[3]);
58  int
59  nlat = 180 * ndeg + 1,
60  nlon = 360 * ndeg;
62  delta = 1 / Math::real(ndeg), // Grid spacing
63  latorg = -90,
64  lonorg = -180;
65  // Write results as floats in binary mode
66  ofstream file(filename.c_str(), ios::binary);
67 
68  // Write header
69  {
70  Math::real transform[] = {latorg, lonorg, delta, delta};
71  unsigned sizes[] = {unsigned(nlat), unsigned(nlon)};
72  Utility::writearray<double, Math::real, true>(file, transform, 4);
73  Utility::writearray<unsigned, unsigned, true>(file, sizes, 2);
74  }
75 
76  // Compute and store results for nbatch latitudes at a time
77  const int nbatch = 64;
78  vector< vector<float> > N(nbatch, vector<float>(nlon));
79 
80  for (int ilat0 = 0; ilat0 < nlat; ilat0 += nbatch) { // Loop over batches
81  int nlat0 = min(nlat, ilat0 + nbatch);
82 
83 #if HAVE_OPENMP
84 # pragma omp parallel for
85 #endif
86  for (int ilat = ilat0; ilat < nlat0; ++ilat) { // Loop over latitudes
87  Utility::set_digits(ndigits); // Set the precision
89  lat = latorg + (ilat / ndeg) + delta * (ilat - ndeg * (ilat / ndeg)),
90  h = 0;
91  GravityCircle c(g.Circle(lat, h, GravityModel::GEOID_HEIGHT));
92  for (int ilon = 0; ilon < nlon; ++ilon) { // Loop over longitudes
93  Math::real lon = lonorg
94  + (ilon / ndeg) + delta * (ilon - ndeg * (ilon / ndeg));
95  N[ilat - ilat0][ilon] = float(c.GeoidHeight(lon));
96  } // longitude loop
97  } // latitude loop -- end of parallel section
98 
99  for (int ilat = ilat0; ilat < nlat0; ++ilat) // write out data
100  Utility::writearray<float, float, true>(file, N[ilat - ilat0]);
101  } // batch loop
102  }
103  catch (const exception& e) {
104  cerr << "Caught exception: " << e.what() << "\n";
105  return 1;
106  }
107  catch (...) {
108  cerr << "Caught unknown exception\n";
109  return 1;
110  }
111 }
GeographicLib::GravityCircle
Gravity on a circle of latitude.
Definition: GravityCircle.hpp:41
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
GeographicLib
Namespace for GeographicLib.
Definition: JacobiConformal.hpp:15
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
real
float real
Definition: datatypes.h:10
sizes
std::vector< Array2i > sizes
Definition: dense_solvers.cpp:12
h
const double h
Definition: testSimpleHelicopter.cpp:19
GravityModel.hpp
Header for GeographicLib::GravityModel class.
GeographicLib::Math::real
double real
Definition: Math.hpp:129
GravityCircle.hpp
Header for GeographicLib::GravityCircle class.
gtsam.examples.PlanarManipulatorExample.delta
def delta(g0, g1)
Definition: PlanarManipulatorExample.py:45
relicense.filename
filename
Definition: relicense.py:57
Utility.hpp
Header for GeographicLib::Utility class.
transform
EIGEN_DONT_INLINE void transform(const Transformation &t, Data &data)
Definition: geometry.cpp:25
model
noiseModel::Diagonal::shared_ptr model
Definition: doc/Code/Pose2SLAMExample.cpp:7
g
void g(const string &key, int i)
Definition: testBTree.cpp:41
std
Definition: BFloat16.h:88
min
#define min(a, b)
Definition: datatypes.h:19
gtsam.examples.DogLegOptimizerExample.float
float
Definition: DogLegOptimizerExample.py:113
N
#define N
Definition: igam.h:9
lon
static const double lon
Definition: testGeographicLib.cpp:34
main
int main(int argc, const char *const argv[])
Definition: GeoidToGTX.cpp:40
GeographicLib::GravityModel
Model of the earth's gravity field.
Definition: GravityModel.hpp:83
matlab_wrap.file
file
Definition: matlab_wrap.py:57
lat
static const double lat
Definition: testGeographicLib.cpp:34


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:22