Jpp 19.3.0
the software that should make you happy
Loading...
Searching...
No Matches
getGeographicalLocation.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <sstream>
4#include <iomanip>
5
6#include "JLang/JManip.hh"
7
10
12
13#include "JLang/JException.hh"
14
16
18
19#include "Jeep/JParser.hh"
20#include "Jeep/JMessage.hh"
21
22
23namespace {
24
25 using JUTM::JUTMGrid;
29
30
31 /**
32 * Get Earth's ellipsoid.
33 *
34 * \param grid UTM grid
35 * \return ellipsoid
36 */
37 inline const Ellipsoid& getEllipsoid(const JUTMGrid& grid)
38 {
39 using namespace std;
40
41 string buffer = grid.getWGS();
42 size_t pos = buffer.find_first_of("0123456789");
43
44 const string wgs = buffer.substr(0, pos);
45
46 int zone;
47
48 istringstream(buffer.substr(pos)) >> zone;
49
50 for (int i = 0; i != sizeof(ellipsoid)/sizeof(ellipsoid[0]); ++i) {
51
52 buffer = ellipsoid[i].ellipsoidName;
53 pos = buffer.find(wgs);
54
55 if (pos != string::npos) {
56
57 pos += wgs.size() + 1;
58
59 int val;
60
61 istringstream(buffer.substr(pos)) >> val;
62
63 if (zone == val) {
64 return ellipsoid[i];
65 }
66 }
67 }
68
69 THROW(JParseError, "Invalid UTM grid " << grid);
70 }
71
72
73 /**
74 * Get geographical location.
75 *
76 * \param grid UTM grid
77 * \param position UTM position
78 * \return geographical location
79 */
80 inline JGeographicalLocation getGeographicalLocation(const JUTMGrid& grid,
81 const JUTMPosition& position)
82 {
83 using namespace JPP;
84
85 const Ellipsoid& el = getEllipsoid(grid);
86
87 double lat, lon;
88
89 UTMtoLL(el.id, position.getUTMNorth(), position.getUTMEast(), grid.getUTMZone().c_str(), lat, lon);
90
92 }
93
94
95 /**
96 * Get Meridian convergence angle
97 *
98 * \param grid UTM grid
99 * \param position UTM position
100 * \return meridian convergence angle [rad]
101 */
102 inline double getMeridianConvergenceAngle(const JUTMGrid& grid,
103 const JUTMPosition& position)
104 {
105 const JGeographicalLocation location = getGeographicalLocation(grid, position);
106
107 const Ellipsoid& el = getEllipsoid(grid);
108
110 }
111}
112
113
114/**
115 * \file
116 *
117 * Example program to print geographical data for given detector.
118 * \author mdejong
119 */
120int main(int argc, char **argv)
121{
122 using namespace std;
123 using namespace JPP;
124
125 string detectorFile;
126 int debug;
127
128 try {
129
130 JParser<> zap("Example program to print geographical data for given detector.");
131
132 zap['a'] = make_field(detectorFile);
133 zap['d'] = make_field(debug) = 2;
134
135 zap(argc, argv);
136 }
137 catch(const exception &error) {
138 FATAL(error.what() << endl);
139 }
140
141
143
144 try {
145 load(detectorFile, detector);
146 }
147 catch(const JException& error) {
148 FATAL(error);
149 }
150
151
152 string name;
153 double meridian;
154 JGeographicalLocation location;
155
156 if (isORCADetector(detector)) {
157
158 name = "ORCA";
159 meridian = ORCA_MERIDIAN_CONVERGENCE_ANGLE_DEG;
160 location = ORCA;
161
162 } else if (isARCADetector(detector)) {
163
164 name = "ARCA";
165 meridian = ARCA_MERIDIAN_CONVERGENCE_ANGLE_DEG;
166 location = ARCA;
167
168 } else {
169
170 FATAL("No location" << endl);
171 }
172
173 cout << "Detector " << name << endl;
174 cout << detector.getUTMGrid() << endl;
175 cout << detector.getUTMPosition() << endl;
176
177 JGeographicalLocation geo = getGeographicalLocation(detector.getUTMGrid(), detector.getUTMPosition());
178
179 cout << "Latitude [deg]: " << FIXED(9,5) << getDegrees(location.getLatitude()) << " " << FIXED(9,5) << getDegrees(geo.getLatitude()) << endl;
180 cout << "Longitude [deg]: " << FIXED(9,5) << getDegrees(location.getLongitude()) << " " << FIXED(9,5) << getDegrees(geo.getLongitude()) << endl;
181 cout << "Latitude [rad]: " << FIXED(9,5) << location.getLatitude() << " " << FIXED(9,5) << geo.getLatitude() << endl;
182 cout << "Longitude [rad]: " << FIXED(9,5) << location.getLongitude() << " " << FIXED(9,5) << geo.getLongitude() << endl;
183
184 cout << "Zone: " << detector.getUTMZone() << " " << getUTMZone(geo.getLongitude()) << endl;
185
186 cout << "Meridian convergence angle [deg]: " << FIXED(9,5) << meridian << " " << FIXED(9,5) << getDegrees(getMeridianConvergenceAngle(detector.getUTMGrid(), detector.getUTMPosition())) << endl;
187 cout << "Meridian convergence angle [deg]: " << FIXED(9,5) << getDegrees(getMeridianConvergenceAngle(location)) << " (approximate)" << endl;
188}
189
Interface methods for SLALIB and auxiliary classes and methods for astronomy.
Meridian convergence angles for different sites.
Data structure for detector geometry and calibration.
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
I/O manipulators.
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
static Ellipsoid ellipsoid[]
void UTMtoLL(int ReferenceEllipsoid, const double UTMNorthing, const double UTMEasting, const char *UTMZone, double &Lat, double &Long)
const char * ellipsoidName
Detector data structure.
Definition JDetector.hh:96
General exception.
Definition JException.hh:24
Exception for parsing value.
Utility class to parse command line options.
Definition JParser.hh:1698
Data structure for UTM grid.
Definition JUTMGrid.hh:74
Data structure for UTM position.
int main(int argc, char **argv)
double getMeridianConvergenceAngle(const JGeographicalLocation &location)
Get Meridian convergence angle.
double getRadians(const double angle)
Convert angle to radians.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Detector file.
Definition JHead.hh:227
double getLongitude() const
Get longitude.
double getLatitude() const
Get latitude.