OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
VcstTerrainCorrect.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * NAME: VcstTerrainCorrect
4  *
5  * DESCRIPTION: This is the header file for the VcstTerrainCorrect class for
6  * Terrain Correction.
7  *
8  *****************************************************************************/
9 
10 #ifndef VCSTTERRAINCORRECT_h
11 #define VCSTTERRAINCORRECT_h
12 
13 #include <VcstPolarTileDatabase.h>
15 #include <VcstGeoAncInputItem.h>
16 #include <VcstMath.h>
17 //#include <Typedefs.h>
18 //#include <tereco.h>
19 #include <map>
20 #include <sstream>
21 
22 class VcstCmnGeo;
23 
24 
25 const int MIN_LOS_PTS = 3;
26 const int MAX_LOS_PTS = 70;
27 const double MAX_CRCT = 10.e+0; // meters
28 const double MIN_EARTH_CTR_ANGLE = 1.0e-8;
29 const double NUM_BI_INTERP_PTS = 4.e+0;
30 const double BOTTOM_LOS = -600.0e+0; // meters
31 const double KM2METERS = 1.0e+3;
32 const double HORIZ_LIMIT = 20.e+0; // meters
33 const double FILL_AZM = -10.e+0;
34 const double PAD_VAL = 1.03e+0;
35 
36 const int NORTH_KEY = 1000;
37 const int SOUTH_KEY = 3000;
38 const int MAX_TILE_ID = 5000;
39 
40 const int TERRCORR_NOCRCT = 20;
41 const int TERRCORR_OCEAN_CRCT = 25;
42 const int TERRCORR_ERR = 15;
43 
44 /****************************************************************************
45 number of rows and columns in one terrain DB box
46  ***************************************/
47 
48 const int TEBOX_ROWS = 1664;
49 const int TEBOX_COLS = 1664;
50 
51 //***************************************************************************
52 // number of DB box rows and DB box columns in one hemisphere.
53 //*************************************
54 
55 const int TEDB_ROWS_OF_BOXES = 32;
56 const int TEDB_COLS_OF_BOXES = 32;
57 
58 //
59 // length of string containing box file name
60 const int BOX_FILE_STR = 32;
61 
62 /******************************************************************************
63 NOTE: "No data by design" points are points that are more than 2 KM outside the
64 Equator. They never get valid data in them. Code which finds a "NOFILL"
65 flag as the data value has something wrong with it.
66 
67  TE_USGS_OCEAN - In GTOPO30 Terrain Data, ocean or ocean connected sea
68  TE_BATHY_LAND - A land point in the bathymetric depth data
69  TE_NOFILL_BIG - 16 bit number for point with no data by design
70  TE_NOFILL_SML - 8 bit number for point with no data by design
71  TE_INIT_BIG - point that should be filled by some other value
72  TE_INIT_SML - point that should be filled by some other value
73  TE_ZERO - a constant used to set variables to zero
74  ******************************************************************************/
75 
76 const int TE_USGS_OCEAN = -9999;
77 const int TE_BATHY_LAND = 1;
78 const int TE_NOFILL_BIG = -20000;
79 const int TE_NOFILL_SML = 120;
80 const int TE_INIT_BIG = -19999;
81 const int TE_INIT_SML = 119;
82 const int TE_ZERO = 0;
83 
84 /****************************************************************************
85 These are the contents of one DB box
86  mslhgt - Mean Sea Level surface height above NIMA GEOID, in meters
87  TE_USGS_OCEAN, -9999, is deep ocean
88  TE_NOFILL_BIG, -20000, is a point with no data
89  maxhgt - Maximum terrain height within radius of MH_RADIUS kilometers
90  minhgt - Minimum terrain height within radius of MH_RADIUS kilometers
91  bathy - ETOPO2 Bathymetric depth of water, in meters
92  TE_BATHY_LAND, +1, is a land or glacier point
93  TE_NOFILL_BIG, -20000, is a point with no data
94  sfcgp - Surface geopotential height
95  egSep - Separation, NIMA 95 (Geoid - Ellipsoid) in meters
96  TE_NOFILL_SML, +120, is a point with no data
97  qst - QST-LWM (Quarterly Surface Type-Land Water Mask) data, 0 thru 20
98  upIET_mslhgt - time SRTM30 height in the DB box was updated
99  upIET_mmhgt - time max height within radius was determined
100  upIET_bathy - time ETOPO2 depth in the DB box was updated
101  upIET_sfcgp - time surface geopotential height was updated
102  upIET_egs - time EG separation in the DB box was updated
103  upIET_qst - time QST-LWM data updated.
104  upIET_resolv - time that conflict resolution was done on this box
105  updated_IET - time, in IET microseconds, that the DB box was Stored
106  boxnum - DB box number
107  boxrow - the row of boxes that this box is in
108  boxcol - the column of boxes that this box is in
109  ulrow_offset - DB grid row of the upper left corner pixel in the box
110  ulcol_offset - DB grid column of the upper left corner pixel in the box
111  num_nofill - number of points well outside Equator, never filled by data
112  nOrS - character "N" for Northern hemisphere box, character "S" for
113  Southern hemisphere box
114  ***************************************/
115 
116 typedef struct {
117  short mslhgt[TEBOX_ROWS][TEBOX_COLS];
118  short maxhgt[TEBOX_ROWS][TEBOX_COLS];
119  short minhgt[TEBOX_ROWS][TEBOX_COLS];
120  short bathy[TEBOX_ROWS][TEBOX_COLS];
121  short sfcgp[TEBOX_ROWS][TEBOX_COLS];
122  char egSep[TEBOX_ROWS][TEBOX_COLS];
123  unsigned char qst[TEBOX_ROWS][TEBOX_COLS];
124  long long upIET_mslhgt;
125  long long upIET_mmhgt;
126  long long upIET_bathy;
127  long long upIET_sfcgp;
128  long long upIET_egs;
129  long long upIET_qst;
130  long long upIET_resolv;
131  long long updated_IET;
132  char boxfile[BOX_FILE_STR];
133  int boxnum;
134  int boxrow;
135  int boxcol;
136  int ulrow_offset;
137  int ulcol_offset;
138  int num_nofill;
139  char nOrS;
141 
142 
143 
144 int target_pt(double clat,
145  double clon,
146  double side_b,
147  double azimuth,
148  double *alat,
149  double *alon);
150 
151 //-------------------------------------------------------------------
152 
153 typedef struct LOSPointType {
154  double lat; // Latitude
155  double lon; // Longitude
156  double gRow; // Grid row
157  double gCol; // Grid col
158  double losHgt; // Line-Of-Sight(LOS) height
159  double mslHgt; // Mean Sea Lvl Height
160  double egsHgt; // Ellipsoid/Geoid separation height
161  double eesHgt; // Ellipsoid to Earth Surface height
162  double maxHgt; // Maximum height 32km around this point
163  double minHgt; // Minimum height 32km around this point
164  Hemisphere hem; // Hemisphere for this point
165 } LOS_POINT_TYPE;
166 
167 typedef struct TerrainCorrectDataType {
168  LOSPointType interpPts[2]; // Array w/ 2 points to interpolate
169  double ellipLat; // Input ellipsoid latitude
170  double ellipLon; // Input ellipsoid longitude
171  double ellipSatAzm; // Input ellipsoid satellite azimuth
172  double ellipSatZen; // Input ellipsoid satellite zenith
173  double ellipEarthRad; // Geodetic Earth radius at ellipsoid
174  double startDistAng; // Starting distance angle
175  double endDistAng; // Ending distance angle
176  double pntDistAng; // Distance angle between points
177  int lowIdx; // Index of LOS point below terrain
178  int upIdx; // Index of LOS point above terrain
179  int numPts; // Number of LOS points calculated
180 } TERRAIN_CORRECT_DATA_TYPE;
181 
182 typedef struct TerrainCorrectTerecoType {
184  bool tileErr;
185 } TERRAIN_CORRECT_TERECO_TYPE;
186 
187 // class ProCmnDataItemEnv;
188 
189 //------------------------------------------------------------------
190 
192 public:
193 
199 
200 
204  virtual ~VcstTerrainCorrect();
205 
206 
228  int terrainCorrection(
229  const float inLat,
230  const float inLon,
231  const float inSatAzm,
232  const float inSatZen,
233  const double inRPos[VEC_SIZE],
234  VcstCmnGeo *cmnGeoPtr,
235  float& outEgs,
236  float& outLat,
237  float& outLon,
238  float& outHgt,
239  float& outSatAzm,
240  float& outSatZen,
241  float& outRange);
242 
243 
255  int getTerrainInfo(const float inLat,
256  const float inLon,
257  VcstCmnGeo *cmnGeoPtr,
258  LOSPointType& outPoint);
259 
260 
261 private:
262 
266  TERRAIN_CORRECT_TERECO_TYPE tileArr_[MAX_TILE_ID];
267 
271  VcstPolarTileDatabase* tileDB_;
272 
277  TerecoTileType* tileTypeArr_[MAX_TILE_ID];
278 
279 
283  TerrainCorrectDataType tcData_;
284 
288  std::ostringstream tileId_;
289 
294  int dbgMsgThrottle1_;
295  int dbgMsgThrottle2_;
296  int dbgMsgThrottle3_;
297 
304  int setupLOSPoints(const LOSPointType startPt);
305 
317  int calcGridFromLatLon(double inAzm,
318  double& ioDistAng,
319  LOSPointType& point);
320 
329  int fillTerrainPoint(LOSPointType& point);
330 
340  int fillTerrainPointBiInterp(LOSPointType& point);
341 
342 
357  int findTerrain(
358  const double inRPos[VEC_SIZE],
359  VcstCmnGeo *cmnGeoPtr,
360  double& outLat,
361  double& outLon,
362  double& outMslHgt,
363  double& outAzm,
364  double& outZen);
365 
376  int determineIntersectBelowEndPt(const LOSPointType& inStartPt);
377 
385  int determineIntersectAboveEndPt();
386 
397  int calcAndFillPoint(const int idx,
398  LOSPointType& outPoint);
399 
409  int calcStartPoint(LOSPointType& outPoint);
410 
419  void calcLOSHgt(const int idx,
420  LOSPointType& outPoint);
421 
422 
438  void calcTCSatAzmZen(
439  const double inLat,
440  const double inLon,
441  const double inMsl,
442  const double inEgs,
443  const double inRPos[VEC_SIZE],
444  VcstCmnGeo *cmnGeoPtr,
445  double& outAzm,
446  double& outZen);
447 
448 
463  void applyOceanCorrection(
464  const LOSPointType& inPt,
465  const double inRPos[VEC_SIZE],
466  VcstCmnGeo *cmnGeoPtr,
467  float& outLat,
468  float& outLon,
469  float& outHt,
470  float& outAzm,
471  float& outZen);
472 
473 
482  int convertLatLonToGrid(LOSPointType& point);
483 
484 private:
485 
486 };
487 
488 
489 #endif
const int TERRCORR_ERR
const double HORIZ_LIMIT
const int TE_INIT_SML
const int TE_INIT_BIG
const int TEDB_COLS_OF_BOXES
int terrainCorrection(const float inLat, const float inLon, const float inSatAzm, const float inSatZen, const double inRPos[VEC_SIZE], VcstCmnGeo *cmnGeoPtr, float &outEgs, float &outLat, float &outLon, float &outHgt, float &outSatAzm, float &outSatZen, float &outRange)
const double NUM_BI_INTERP_PTS
const int MAX_LOS_PTS
int target_pt(double clat, double clon, double side_b, double azimuth, double *alat, double *alon)
const int TE_ZERO
const int TERRCORR_NOCRCT
const int TE_NOFILL_BIG
VcstGeoAncInputItem * ptr
const int TE_USGS_OCEAN
const double FILL_AZM
const int VEC_SIZE
const double BOTTOM_LOS
virtual ~VcstTerrainCorrect()
Hemisphere
const int NORTH_KEY
const int TE_NOFILL_SML
const int TERRCORR_OCEAN_CRCT
const double KM2METERS
const int TE_BATHY_LAND
const double MIN_EARTH_CTR_ANGLE
const int TEDB_ROWS_OF_BOXES
const int SOUTH_KEY
const int MAX_TILE_ID
const int TEBOX_ROWS
const double PAD_VAL
int getTerrainInfo(const float inLat, const float inLon, VcstCmnGeo *cmnGeoPtr, LOSPointType &outPoint)
const int TEBOX_COLS
const double MAX_CRCT
const int BOX_FILE_STR
const int MIN_LOS_PTS