7 #include <boost/geometry.hpp>
8 #include <boost/geometry/geometries/point_xy.hpp>
9 #include <boost/geometry/geometries/polygon.hpp>
19 using namespace netCDF;
20 using namespace netCDF::exceptions;
23 typedef bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree>>
Point_t;
38 for (
size_t i = 0;
i < length;
i++){
39 double lat = boost::lexical_cast<double>(gRingLats[
i]);
40 double lon = boost::lexical_cast<double>(gRingLons[
i]);
43 gPolygon.outer().push_back(
Point_t{boost::lexical_cast<double>(gRingLons[0]),boost::lexical_cast<double>(gRingLats[0])});
51 softwareVersion +=
".";
53 softwareVersion +=
".";
55 softwareVersion +=
"-";
58 cout <<
"get_dataday " << softwareVersion << endl;
59 cout <<
"\nUsage: get_dataday ifile" << endl;
60 cout <<
"where:\n\tifile is an L2 file generated by l2gen\n" << endl;
61 cout <<
"Options:\n\t-h, --help: get this clever little usage statement" << endl;
68 float equatorialCrossingTime,
80 referenceTime = (time_t) (
starttime + (12 - (
double) equatorialCrossingTime)*3600);
81 referenceDay = referenceTime / 86400;
82 referenceHour = (referenceTime % 86400) / 3600.0;
85 *dataday1 = *dataday0 = referenceDay;
86 }
else if (referenceHour < 6) {
87 *dataday0 = referenceDay - 1;
88 *dataday1 = referenceDay;
89 }
else if (referenceHour > 18) {
90 *dataday0 = referenceDay;
91 *dataday1 = referenceDay + 1;
93 *dataday1 = *dataday0 = referenceDay;
95 float westOfDateline = 180 - west;
96 float eastOfDateline = east + 180;
98 if (westOfDateline > eastOfDateline) {
99 *dataday0 = referenceDay - 1;
100 *dataday1 = referenceDay;
102 *dataday0 = referenceDay;
103 *dataday1 = referenceDay + 1;
109 float *equatorialCrossingTime, int32_t *plusDay) {
113 *equatorialCrossingTime = 12.0;
118 *equatorialCrossingTime = 13.5;
123 *equatorialCrossingTime = 10.5;
127 *equatorialCrossingTime = 10.0;
130 *equatorialCrossingTime = 12.0;
133 *equatorialCrossingTime = 12.0;
140 int32_t d =
starttime / 86400.0 - 10957.0;
153 deg = 7.7517951e-10 * d * d * d
154 - 2.1692192e-06 * d * d
164 deg = -0.024285181 * d + 128.86093;
168 float hours = (
float) (deg / 15.);
170 *equatorialCrossingTime = 12.0 + hours;
175 *equatorialCrossingTime = 12.0;
178 cerr <<
"-W- Unknown equator crossing time for sensorID=" <<
sensorID << endl;
179 cerr <<
"-W- Assuming local noon crossing" << endl;
180 *equatorialCrossingTime = 12.0;
188 *equatorialCrossingTime = *equatorialCrossingTime - 12;
189 if (*equatorialCrossingTime < 0) {
190 *equatorialCrossingTime = *equatorialCrossingTime + 24;
199 double datatime = dataday * 86400.0;
204 int main(
int argc,
char** argv) {
209 bg::append(dateline,
Point_t(180.0, 89.9999));
210 bg::append(dateline,
Point_t(180.0, -89.9999));
212 Point_t southPole = {0, -90.0};
218 string inputFile = argv[1];
219 if (inputFile ==
"-h" || inputFile ==
"--help" ){
226 nc_input =
new NcFile(inputFile, NcFile::read );
228 catch( NcException& e) {
230 cerr <<
"\nFailure opening input file: " + inputFile +
"\n" << endl;
238 char day_night_flag[6];
241 char sceneStartTimeISO[30];
244 (
attributes.find(
"geospatial_lon_max")->second).getValues(&maxEast);
245 (
attributes.find(
"geospatial_lon_min")->second).getValues(&maxWest);
246 (
attributes.find(
"time_coverage_start")->second).getValues(sceneStartTimeISO);
249 (
attributes.find(
"day_night_flag")->second).getValues(day_night_flag);
253 double sceneStartTime =
isodate2unix(sceneStartTimeISO);
255 NcGroup navGroup = nc_input->getGroup(
"navigation_data");
260 size_t length = (
attributes.find(
"gringpointlatitude")->second).getAttLength();
262 gRingLats = (
float*) calloc(length,
sizeof(
float));
263 gRingLons = (
float*) calloc(length,
sizeof(
float));
265 (
attributes.find(
"gringpointlatitude")->second).getValues(gRingLats);
266 (
attributes.find(
"gringpointlongitude")->second).getValues(gRingLons);
274 std::vector<Point_t>
result;
275 bg::intersection(dateline,gPolygon,
result);
277 if (bg::within(northPole, gPolygon)) {
279 cout <<
"# Scene crossed North pole" << endl;
280 }
else if (bg::within(southPole, gPolygon)) {
281 cout <<
"# Scene crossed South pole" << endl;
284 cout <<
"# Scene crossed dateline" << endl;
289 int32_t dataday0, dataday1;
291 float equatorialCrossingTime;
292 bool nightScene =
false;
298 get_datadays(sceneStartTime, equatorialCrossingTime, dateLineCrossed,
299 maxWest, maxEast, &dataday0, &dataday1);
304 cout <<
"Day_Night_Flag=" << day_night_flag << endl;
306 if (dataday0 == dataday1) {
307 cout <<
"DataDay0=" << startDataDay.substr(0, 10) << endl;
310 cout <<
"DataDay0=" << startDataDay.substr(0, 10) <<
"\nDataDay1=" << stopDataDay.substr(0, 10) << endl;