Jpp 20.0.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 const char* const calculated_t = "calculated"; //!< calulated values
114 const char* const fixed_t = "fixed"; //!< fixed values
115}
116
117
118/**
119 * \file
120 *
121 * Example program to print geographical data for given detector.
122 * \author mdejong
123 */
124int main(int argc, char **argv)
125{
126 using namespace std;
127 using namespace JPP;
128
129 string detectorFile;
130 string option;
131 int debug;
132
133 try {
134
135 JParser<> zap("Example program to print geographical data for given detector.");
136
137 zap['a'] = make_field(detectorFile);
138 zap['O'] = make_field(option) = calculated_t, fixed_t;
139 zap['d'] = make_field(debug) = 2;
140
141 zap(argc, argv);
142 }
143 catch(const exception &error) {
144 FATAL(error.what() << endl);
145 }
146
147
149
150 try {
151 load(detectorFile, detector);
152 }
153 catch(const JException& error) {
154 FATAL(error);
155 }
156
157
158 string name;
159 double meridian;
160 JGeographicalLocation location;
161
162 if (option == calculated_t) {
163
164 meridian = getDegrees(getMeridianConvergenceAngle(detector.getUTMGrid(), detector.getUTMPosition()));
165 location = getGeographicalLocation(detector.getUTMGrid(), detector.getUTMPosition());
166
167 } else if (option == fixed_t) {
168
169 if (isORCADetector(detector)) {
170
171 meridian = ORCA_MERIDIAN_CONVERGENCE_ANGLE_DEG;
172 location = ORCA;
173
174 } else if (isARCADetector(detector)) {
175
176 meridian = ARCA_MERIDIAN_CONVERGENCE_ANGLE_DEG;
177 location = ARCA;
178
179 } else {
180
181 FATAL("No location" << endl);
182 }
183
184 } else {
185
186 FATAL("Invalid option " << option << endl);
187 }
188
189 if (debug >= debug_t) {
190
191 cout << "grid: " << detector.getUTMGrid() << endl;
192 cout << "UTM: " << detector.getUTMPosition() << endl;
193 cout << "zone: " << detector.getUTMZone() << ' ' << getUTMZone(location.getLongitude()) << endl;
194
195 cout << "Meridian convergence angle [deg]: " << FIXED(9,5) << meridian << " (" << option << ")" << endl;
196 cout << "Meridian convergence angle [deg]: " << FIXED(9,5) << getDegrees(getMeridianConvergenceAngle(location)) << " (calculated)" << endl;
197 }
198
199 cout << "Latitude [deg]: " << FIXED(9,5) << getDegrees(location.getLatitude()) << endl;
200 cout << "Longitude [deg]: " << FIXED(9,5) << getDegrees(location.getLongitude()) << endl;
201 cout << "Latitude [rad]: " << FIXED(9,5) << location.getLatitude() << endl;
202 cout << "Longitude [rad]: " << FIXED(9,5) << location.getLongitude() << endl;
203 cout << "Meridian convergence angle [deg]: " << FIXED(9,5) << meridian << endl;
204 cout << "Meridian convergence angle [rad]: " << FIXED(9,5) << getRadians(meridian) << endl;
205}
206
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.