1 //==============================================================================
2 //
3 // This file is part of GPSTk, the GPS Toolkit.
4 //
5 // The GPSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GPSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GPSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2020, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38
39 /**
40 * @file ElevationMask.cpp
41 * Implement an elevation mask function for program DDBase.
42 */
43
44 //------------------------------------------------------------------------------------
45 // system includes
46
47 // GPSTk
48 #include "GNSSconstants.hpp" // for DEG_TO_RAD
49 // geomatics
50 #include "SunEarthSatGeometry.hpp"
51 // DDBase
52 #include "DDBase.hpp"
53
54 //------------------------------------------------------------------------------------
55 using namespace std;
56 using namespace gpstk;
57
58 //------------------------------------------------------------------------------------
59 // prototypes -- this module only
60 bool DefaultElevationMask(double elevation, double azimuth, double ElevCutoff);
61 bool RotatedAntennaElevationMask(double elevation, double azimuth, double ElevCutoff);
62 double RotatedAntennaElevation(double elevation, double azimuth);
63
64 //------------------------------------------------------------------------------------
65 // return 'true' if satellite data at elevation and azimuth (both in degrees)
66 // is accepted.
ElevationMask(double elevation,double azimuth)67 bool ElevationMask(double elevation, double azimuth)
68 {
69 try {
70 if(DefaultElevationMask(elevation,azimuth,CI.MinElevation))
71 return RotatedAntennaElevationMask(elevation, azimuth,CI.MinElevation);
72 else
73 return false;
74 }
75 catch(Exception& e) { GPSTK_RETHROW(e); }
76 catch(std::exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }
77 catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }
78 } // end ElevationMask
79
80 //------------------------------------------------------------------------------------
DefaultElevationMask(double elevation,double azimuth,double ElevCutoff)81 inline bool DefaultElevationMask(double elevation, double azimuth, double ElevCutoff)
82 {
83 return (elevation >= ElevCutoff);
84 }
85
86 //------------------------------------------------------------------------------------
RotatedAntennaElevationMask(double elevation,double azimuth,double ElevCutoff)87 bool RotatedAntennaElevationMask(double elevation, double azimuth, double ElevCutoff)
88 {
89 try {
90 return ( RotatedAntennaElevation(elevation, azimuth) >= ElevCutoff );
91 }
92 catch(Exception& e) { GPSTK_RETHROW(e); }
93 catch(std::exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }
94 catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }
95 }
96
97 //------------------------------------------------------------------------------------
98 // Return the elevation of the input direction (elevation and azimuth) in a frame
99 // which is rotated by angles RotateElev and RotateAzimuth. All angles in degrees.
RotatedAntennaElevation(double elevation,double azimuth)100 double RotatedAntennaElevation(double elevation, double azimuth)
101 {
102 try {
103 if(CI.RotatedAntennaElevation > 0.0 || CI.RotatedAntennaAzimuth > 0.0) {
104 Matrix<double> R;
105 Vector<double> rhat(3),rotated_rhat;
106
107 elevation *= DEG_TO_RAD;
108 azimuth *= DEG_TO_RAD;
109 double RotateElev = CI.RotatedAntennaElevation * DEG_TO_RAD;
110 double RotateAzimuth = CI.RotatedAntennaAzimuth * DEG_TO_RAD;
111
112 // construct the rotation matrix
113 R = SingleAxisRotation(-RotateElev,2) * SingleAxisRotation(RotateAzimuth,3);
114
115 // unit vector, Rx to SV, in ordinary geodetic frame
116 rhat(0) = ::cos(azimuth) * ::cos(elevation);
117 rhat(1) = ::sin(azimuth) * ::cos(elevation);
118 rhat(2) = ::sin(elevation);
119
120 // rotate into the frame of the (rotated) antenna
121 rotated_rhat = R * rhat;
122
123 elevation = atan2(rotated_rhat(2),RSS(rotated_rhat(0),rotated_rhat(1)));
124 elevation *= RAD_TO_DEG;
125 }
126
127 return elevation;
128 }
129 catch(Exception& e) { GPSTK_RETHROW(e); }
130 catch(std::exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); }
131 catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); }
132 } // end RotatedAntennaElevation
133
134 //------------------------------------------------------------------------------------
135 //------------------------------------------------------------------------------------
136