OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
VcstCmnGeo.h
Go to the documentation of this file.
1 /******************************************************************************
2  * NAME: VcstCmnGeo.h
3  *
4  * DESCRIPTION: Object class that serves as the intermediary between the NASA
5  * L1A file format and the IDPS Common Geolocation interfaces. It reads L1A
6  * navigation data and stores it into lists of spacecraft diary records
7  * compatible with the VcstCmnGeo object class. It initializes common
8  * geolocation for use by other functions.
9  *
10  * Created on: December 15, 2014
11  * Author: Sam Anderson, VCST
12  *
13  ******************************************************************************/
14 
15 #ifndef VcstCmnGeo_H_
16 #define VcstCmnGeo_H_
17 
18 #include <cmath>
19 #include <novas.h>
20 #include <VcstTime.h>
21 #include <VcstCmnGeoStructs.h>
22 #include <VcstCmnLutInputItem.h>
23 
24 #include <hdf5.h>
25 #include <netcdf>
26 
27 using namespace std;
28 using namespace netCDF;
29 using namespace netCDF::exceptions;
30 
32  // Pointers to LUT data structures
39 };
40 
41 // Structure of LUT pointers used by Common Geolocation
42 
43 class VcstCmnGeo {
44 public:
45 
46  // numeric constants
47  static constexpr double MSECPERDAY = 86400000000.0; //24*60*60=86400 million
48  static constexpr double TAI93_TAI58_SEC = 1104537627.0;
49  static constexpr double RAD_TO_DEG = 180.0 / M_PI;
50 
51  static const std::string SN_APID_0; // = "CRITICAL";
52  static const std::string SN_APID_8; // = "ADCS_HKH";
53  static constexpr int ADSTATE_BYTE = 169;
54  static constexpr int ADSTATE_BITS = 3;
55  static constexpr int ADSTATE_NUM_OF_BITS = 3;
56  static constexpr int ADMANDONE_BYTE = 255;
57  static constexpr int ADMANDONE_BIT = 7;
58  static constexpr int ADFFTID_BYTE = 339;
59  static constexpr int SCAN_ALL = -1;
60 
61  static constexpr bool MEAN_SID = true; // Flag for getting Mean Sidereal Time.
62  static constexpr bool APP_SID = false; // Flag for getting Apparent Sidereal Time.
63 
69 
76 
77  int scan_number_[VIIRS_SCANS];
78  unsigned char ham_side_[VIIRS_SCANS];
79  unsigned char sensor_mode_[VIIRS_SCANS];
80  unsigned char se_a_anlg_pwr_on_[VIIRS_SCANS];
81  unsigned char se_b_anlg_pwr_on_[VIIRS_SCANS];
82  unsigned char dp_servo_in_use_[VIIRS_SCANS];
83  unsigned char se_a_tele_pos_known_[VIIRS_SCANS];
84  unsigned char se_b_tele_pos_known_[VIIRS_SCANS];
85  unsigned char se_a_mtrs_stopped_[VIIRS_SCANS];
86  unsigned char se_b_mtrs_stopped_[VIIRS_SCANS];
87  unsigned char encoderFlag_[VIIRS_SCANS];
88  unsigned char es_se_a_teleham_scansyn_[VIIRS_SCANS];
89  unsigned char es_se_b_teleham_scansyn_[VIIRS_SCANS];
90  unsigned char cp_blk_pwr_sel_[VIIRS_SCANS];
91  unsigned char dp_nonrdt_fpie_pwr_[VIIRS_SCANS];
92  unsigned short ham_start_enc_[VIIRS_SCANS];
93  unsigned short tel_start_enc_[VIIRS_SCANS];
94 
95  unsigned short ham_encoder_[VIIRS_SCANS][Encoder_Reading];
96  unsigned short tel_encoder_[VIIRS_SCANS][Encoder_Reading];
97 
98  short electronics_side_[VIIRS_SCANS];
99  bool scan_sync_failure_[VIIRS_SCANS];
100  bool tel_start_not_nominal_[VIIRS_SCANS];
101  bool sensor_not_nominal_[VIIRS_SCANS];
102  bool scan_data_missing_[VIIRS_SCANS];
105 
106  double start_TAI93sec_[VIIRS_SCANS];
107  double end_TAI93sec_[VIIRS_SCANS];
108  double ev_mid_TAI93sec_[VIIRS_SCANS];
109  double sv_mid_TAI93sec_[VIIRS_SCANS];
110  double bb_mid_TAI93sec_[VIIRS_SCANS];
111  double sd_mid_TAI93sec_[VIIRS_SCANS];
112 
113  double start_TAI58sec_[VIIRS_SCANS];
114  double end_TAI58sec_[VIIRS_SCANS];
115  double mid_TAI58sec_[VIIRS_SCANS];
117 
118  float sc_solar_zenith_[VIIRS_SCANS];
119  float sc_solar_azimuth_[VIIRS_SCANS];
120 
121  float solar_zenith_[VIIRS_SCANS];
122  float solar_azimuth_[VIIRS_SCANS];
123  float earth_sun_distance_[VIIRS_SCANS];
124  float solar_j2000_[VIIRS_SCANS][VEC_SIZE];
125  float solar_inst_[VIIRS_SCANS][VEC_SIZE];
126 
127  float att_quat_ev_[VIIRS_SCANS][QUAT_SIZE];
128  float att_ang_[VIIRS_SCANS][VEC_SIZE];
129  float orb_pos_ev_[VIIRS_SCANS][VEC_SIZE];
130  float orb_vel_ev_[VIIRS_SCANS][VEC_SIZE];
131 
132  float att_quat_sd_[VIIRS_SCANS][QUAT_SIZE];
133  float orb_pos_sd_[VIIRS_SCANS][VEC_SIZE];
134  float orb_vel_sd_[VIIRS_SCANS][VEC_SIZE];
135 
136  float earth_moon_distance_[VIIRS_SCANS];
137  float lunar_j2000_[VIIRS_SCANS][VEC_SIZE];
138  float lunar_inst_[VIIRS_SCANS][VEC_SIZE];
139  bool moon_in_sv_kob_[VCST_BANDS][VIIRS_SCANS];
140 
142 
143  // Pointer to structure of LUT pointer
144 
146  /*
147  * Constructor
148  */
149 
150  VcstCmnGeo();
151 
152  /*
153  * Destructor
154  */
155 
156  ~VcstCmnGeo();
157 
162  int initialize(GRAN_SEQ_ENUM gran_seq);
163 
169  static const std::string getManeuverStr(const BusCritTlmType * busCritTlm,
170  const AdcsHskTlmType * adcsHskTlm);
171 
179  int satPosAtt(const double inTAI, CmnGeoEAPointType& outPt,
180  bool performOrbitCheck = false);
181 
187  int vectorAtSat(const CmnGeoEAPointType& inPt, const int vecFlag,
188  double vecSat[VEC_SIZE]);
189 
195  void calcSatAzmZen(const double inDLat, const double inLon,
196  const double inSamp2Sat[VEC_SIZE], double& outSatAzm,
197  double& outSatZen);
198 
205  int ellipIntersect(const CmnGeoEAPointType& inPt,
206  const double inRotMat[VEC_SIZE][VEC_SIZE],
207  const double viewVec[VEC_SIZE], double& dLat, double& lon,
208  double& satAzm, double& satZen, double& range);
209 
214  int sunMoonAngles(const double inTAI, const double inLat,
215  const double inLon, const int smFlag, double& sunAzm,
216  double& sunZen, double& moonAzm, double& moonZen, double& moonPhase,
217  double& moonIFrac);
218 
224  int sunAngles(const double inTAI, const float inLat, const float inLon,
225  float& sunAzm, float& sunZen);
226 
227  int sunAngles(const double inTAI, const double inLat, const double inLon,
228  double& sunAzm, double& sunZen);
229 
236  int moonAngles(const double inTAI, const float inLat, const float inLon,
237  float& moonAzm, float& moonZen, float& moonPhase, float& moonIFrac);
238 
247  int getSAAIntensity(const float inLat, const float inLon,
248  float& outIntensity);
249 
256  int checkSolarEclipse(const double inTAI, const double inLat,
257  const double inLon, bool& outEclipseOccurring);
258 
263  int writeNavigation();
264 
269  int writeCmnGeo();
270 
271 
272 private:
273 
274  CmnGeoScEAType ephemAtt_;
275  CmnGeoEAPointType sdPoint_[VIIRS_SCANS];
276  CmnGeoEAPointType evPoint_[VIIRS_SCANS];
277  CmnGeoEphAttType ephatt_;
278 
279  site_info locPixel_;
280  body sun_;
281  body earth_;
282  body moon_;
283 
284  VcstTime* timeAPI_;
285  polarWanderDataType *polarWanderDataPtr_;
286 
287  // Map to store LUT input item objects.
288 
289  std::map<std::string, VcstLutInputItem*> cmnGeoLutItems_;
290 
296  int dbgMsgThrottle_;
297 
302  int initialize_novas();
303 
308  int initialize_LUT_data();
309 
314  int initialize_L1A_data(GRAN_SEQ_ENUM gran_seq);
315 
321 
326  int check_scan_sync();
327 
332  int setPolarWander(const double a_tai);
333 
339  int setupEphAtt(const CmnGeoScEAType * const sceaPtr);
340 
346  int initPointsMap(const CmnGeoScEAType* inPtr);
347 
353  int fillEphAttPoint(CmnGeoEAPointType& pntNode);
354 
362  int quadraticInterpEph(const CmnGeoEAPointType* firstPt,
363  const CmnGeoEAPointType* secondPt, const CmnGeoEAPointType* thirdPt,
364  CmnGeoEAPointType* outputPt);
365 
371  int convCoordSys(const double inTAI, const double inPos[VEC_SIZE],
372  const double inVel[VEC_SIZE], const int convFlag,
373  double outPos[VEC_SIZE], double outVel[VEC_SIZE]);
374 
380  void convVec2LatLon(const double inVec[VEC_SIZE], double& dLat,
381  double& cLat, double& lon);
382 
389  void calculateAccel(CmnGeoEAPointType& pntNode);
390 
395  void buildQuatMatrix(const double Qw, const double Qi, const double Qj,
396  const double Qk, double qMat2eci[VEC_SIZE][VEC_SIZE]);
397 
405  int buildECIOrbFrame(const CmnGeoEAPointType& inPt,
406  double outOrb[VEC_SIZE][VEC_SIZE]);
407 
413  int calcGDRollPitchYaw(CmnGeoEAPointType& pntNode);
414 
422  int getPolarUT1UTC(const double inTAI, double& outTDTmUT1,
423  double& outUT1mUTC, double& outXWander, double& outYWander,
424  double& outTJD, bool bForceCalc = false) const;
425 
432  int appSiderealTime(const double inTAI, const bool getmean, double& gast,
433  double& xWander, double& yWander, double& tjd);
434 
439  double earth_radius_C(double rlat);
440 
445  double earth_radius_D(double rlat);
446 
452  void invPNSW(const double inTDT, const double gast, const double Xpole,
453  const double Ypole, double eciVect[VEC_SIZE],
454  double ecfVect[VEC_SIZE]);
455 
461  void invWobble(const double x, const double y, const double rotEq[VEC_SIZE],
462  double geoEq[VEC_SIZE]);
463 
468  int computeSolarVectors();
469 
474  int computeLunarVectors();
475 
480  int computeEarthViewVectors();
481 
486  int check_moon_in_sv();
487 
492  inline bool validLat(const double inLat) {
493  return ((inLat < -PIO2) || (inLat > PIO2) || std::isnan(inLat)) ?
494  false : true;
495  }
496 
497  inline bool validLon(const double inLon) {
498  return ((inLon < (-PI)) || (inLon > PI) || std::isnan(inLon)) ? false : true;
499  }
500 
505  short convert14To16bit(short value14bit);
506 
511  bool isPlatformLittleEndian();
512 
513 };
514 
515 #endif /* VcstCmnGeo_H_ */
proSdrViirsCalQALUT * QALUT
Definition: VcstCmnGeo.h:38
static const std::string SN_APID_0
Definition: VcstCmnGeo.h:51
const int VCST_BANDS
Definition: VcstCmnConsts.h:62
SAALutType * saaCoeff
Definition: VcstCmnGeo.h:36
#define RAD_TO_DEG
Definition: get_zenaz.c:7
#define Encoder_Reading
void initialize(int pixref_flag, int blkref_flag)
Definition: Usds.c:1371
const double TAI93_TAI58_SEC
short scan_sync_failure_cnt_
Definition: VcstCmnGeo.h:103
@ string
Definition: novas.h:66
double earth_radius_C(double clat)
#define PI
Definition: l3_get_org.c:6
double earth_sun_distance_avg_
Definition: VcstCmnGeo.h:141
CmnGeoParamLutType * paramLut
Definition: VcstCmnGeo.h:37
int scanSyncFailCt_
Definition: VcstCmnGeo.h:104
const int VEC_SIZE
std::string platform_
Definition: VcstCmnGeo.h:68
double earth_radius_D(double rlat)
GRAN_SEQ_ENUM
#define M_PI
Definition: pml_iop.h:15
int Check_Tel_Start_Not_Nominal(viirsSdrGeoPtrs *ptrs)
double midGranTAI58sec_
Definition: VcstCmnGeo.h:116
viirsCmnLutPtrs pLut_
Definition: VcstCmnGeo.h:145
const int QUAT_SIZE
static const std::string SN_APID_8
Definition: VcstCmnGeo.h:52
int act_scans_
Definition: VcstCmnGeo.h:74
const double PIO2
const int VIIRS_SCANS
Definition: VcstCmnConsts.h:58
float * lon
InstrumentLutType * scDataLut
Definition: VcstCmnGeo.h:33
int sc_diary_records_
Definition: VcstCmnGeo.h:75
JPLEphemLutType * jplEphemPtr
Definition: VcstCmnGeo.h:35
CmnGeoPolarUT1Type * pwUT1Ptr
Definition: VcstCmnGeo.h:34