OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
L3Shape.cpp
Go to the documentation of this file.
1 #include <L3Shape.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <math.h>
5 
6 namespace l3 {
7 
13 double constrainLat(double lat) {
14  if (lat > 90.0)
15  return 90.0;
16  if (lat < -90.0)
17  return -90.0;
18  return lat;
19 }
20 
26 double constrainLon(double lon) {
27  if(lon > 180.0 || lon <= -180.0) {
28  lon = fmod(lon, 360.0);
29  if(lon > 180.0)
30  lon -= 360.0;
31  }
32  return lon;
33 }
34 
39 L3Shape::L3Shape(int32_t numRows) {
40  seamLon = -180.0; /* this value should be passed in */
41  totalRows = numRows;
42  totalBins = 0;
43 }
44 
49 }
50 
55 int32_t L3Shape::getNumRows() const {
56  return totalRows;
57 }
58 
63 int64_t L3Shape::getNumBins() const {
64  return totalBins;
65 }
66 
71 void L3Shape::constrainRow(int32_t &row) const {
72  if (row < 0)
73  row = 0;
74  else if (row >= totalRows)
75  row = totalRows - 1;
76 }
77 
85 void L3Shape::rowcol2latlon(int32_t row, int32_t col,
86  float &lat, float &lon) const {
87  double lat1, lon1;
88  rowcol2latlon(row, col, lat1, lon1);
89  lat = lat1;
90  lon = lon1;
91 };
92 
99 void L3Shape::bin2latlon(int64_t bin, double &lat, double &lon) {
100  int32_t row, col;
101 
102  bin2rowcol(bin, row, col);
103  rowcol2latlon(row, col, lat, lon);
104 }
105 
112 void L3Shape::bin2latlon(int64_t bin, float &lat, float &lon) {
113  double lat1, lon1;
114  bin2latlon(bin, lat1, lon1);
115  lat = lat1;
116  lon = lon1;
117 }
118 
128 void L3Shape::rowcol2bounds(int32_t row, int32_t col,
129  float &north, float &south,
130  float &east, float &west) const {
131  double n, s, e, w;
132  rowcol2bounds(row, col, n, s, e, w);
133  north = n;
134  south = s;
135  east = e;
136  west = w;
137 }
138 
139 
148 void L3Shape::bin2bounds(int64_t bin,
149  double &north, double &south,
150  double &east, double &west) {
151  int32_t row, col;
152  bin2rowcol(bin, row, col);
153  rowcol2bounds(row, col, north, south, east, west);
154 }
155 
164 void L3Shape::bin2bounds(int64_t bin,
165  float &north, float &south,
166  float &east, float &west) {
167  double n, s, e, w;
168  bin2bounds(bin, n, s, e, w);
169  north = n;
170  south = s;
171  east = e;
172  west = w;
173 }
174 
175 }
virtual int64_t getNumBins() const
Definition: L3Shape.cpp:63
double constrainLat(double lat)
Definition: L3Shape.cpp:13
virtual void bin2rowcol(int64_t bin, int32_t &row, int32_t &col)=0
float * lat
virtual void rowcol2bounds(int32_t row, int32_t col, double &north, double &south, double &east, double &west) const =0
double constrainLon(double lon)
Definition: L3Shape.cpp:26
virtual void constrainRow(int32_t &row) const
Definition: L3Shape.cpp:71
double seamLon
Definition: L3Shape.h:22
virtual void rowcol2latlon(int32_t row, int32_t col, double &lat, double &lon) const =0
virtual void bin2latlon(int64_t bin, double &lat, double &lon)
Definition: L3Shape.cpp:99
L3Shape(int32_t numRows)
Definition: L3Shape.cpp:39
virtual int32_t getNumRows() const
Definition: L3Shape.cpp:55
virtual void bin2bounds(int64_t bin, double &north, double &south, double &east, double &west)
Definition: L3Shape.cpp:148
float * lon
data_t s[NROOTS]
Definition: decode_rs.h:75
Definition: L3File.cpp:10
int64_t totalBins
Definition: L3Shape.h:20
virtual ~L3Shape()
Definition: L3Shape.cpp:48
int32_t totalRows
Definition: L3Shape.h:21