Skip to content
Snippets Groups Projects
Commit 3f044c08 authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

Remove ossim dependencies from aeronet file reader

parent 9f182e71
Branches
Tags
No related merge requests found
...@@ -23,44 +23,46 @@ ...@@ -23,44 +23,46 @@
#include "otbMath.h" #include "otbMath.h"
#include "otbAeronetData.h" #include "otbAeronetData.h"
#include "ossim/base/ossimDate.h"
namespace otb namespace otb
{ {
namespace internal namespace internal
{ {
/**
* Generate date method typedef struct
*/ {
ossimLocalTm int year;
ParseDate(const std::string& date, const std::string& time) int month;
int day;
int hour;
int minute;
int second;
} Date;
double GetJulian(const Date& date)
{
// From
// http://en.wikipedia.org/wiki/Julian_day#Converting_Julian_or_Gregorian_calendar_date_to_Julian_Day_Number
// the value is slightly different than the one provided by the ossim
// method, but this is now correct according to
// http://aa.usno.navy.mil/data/docs/JulianDate.php
int a = (14-date.month)/12.0;
int y = date.year + 4800 - a;
int m = date.month + 12 * a - 3;
int jdn = date.day + (153 * m +2)/5 + 365*y + y/4 - y/100 + y/400 - 32045;
return jdn + (date.hour-12)/24. + date.minute/1440. + date.second/86400.;
}
Date ParseDate(const std::string& d, const std::string& t)
{ {
ossimLocalTm currentDate; Date date;
ossimString word(""); date.day = atoi(d.substr(0,2).c_str());
word = date[0]; date.month = atoi(d.substr(3,2).c_str());
word += date[1]; date.year = atoi(d.substr(6,4).c_str());
currentDate.setDay(word.toInt()); date.hour = atoi(t.substr(0,2).c_str());
word = date[3]; date.minute = atoi(t.substr(3,2).c_str());
word += date[4]; date.second = atoi(t.substr(6,2).c_str());
currentDate.setMonth(word.toInt()); return date;
word = date[6];
word += date[7];
word += date[8];
word += date[9];
currentDate.setYear(word.toInt());
word = time[0];
word += time[1];
currentDate.setHour(word.toInt());
word = time[3];
word += time[4];
currentDate.setMin(word.toInt());
word = time[6];
word += time[7];
currentDate.setSec(word.toInt());
return currentDate;
} }
} }
...@@ -157,8 +159,8 @@ AeronetFileReader ...@@ -157,8 +159,8 @@ AeronetFileReader
unsigned int col_vapor = 19; unsigned int col_vapor = 19;
unsigned int col_solarZenithAngle = 44; unsigned int col_solarZenithAngle = 44;
ossimLocalTm current_date = internal::ParseDate(line[col_date], line[col_time]); internal::Date current_date = internal::ParseDate(line[col_date], line[col_time]);
double dcurrent_date = current_date.getJulian(); double dcurrent_date = GetJulian(current_date);
// Check hour +/- epsilon // Check hour +/- epsilon
if (vcl_abs(dcurrent_date - ref_date) < epsilon) if (vcl_abs(dcurrent_date - ref_date) < epsilon)
{ {
...@@ -271,14 +273,8 @@ AeronetFileReader ...@@ -271,14 +273,8 @@ AeronetFileReader
} }
//Compute input date //Compute input date
ossimLocalTm inputDate; internal::Date date = {m_Year, m_Month, m_Day, m_Hour, m_Minute, 0};
inputDate.setDay(m_Day); double dinputDate = internal::GetJulian(date);
inputDate.setMonth(m_Month);
inputDate.setYear(m_Year);
inputDate.setHour(m_Hour);
inputDate.setMin(m_Minute);
inputDate.setSec(0);
double dinputDate = inputDate.getJulian();
MatrixString tabStr; MatrixString tabStr;
// if so, parse it and select only valid lines for the input date // if so, parse it and select only valid lines for the input date
...@@ -292,10 +288,10 @@ AeronetFileReader ...@@ -292,10 +288,10 @@ AeronetFileReader
// Select only valid lines: good day // Select only valid lines: good day
if (listStr.size() > 0) if (listStr.size() > 0)
{ {
ossimLocalTm currentDate = internal::ParseDate(listStr[col_date], listStr[col_time]); internal::Date currentDate = internal::ParseDate(listStr[col_date], listStr[col_time]);
if ((listStr[col_670] != "N/A") && if ((listStr[col_670] != "N/A") &&
(listStr[col_440] != "N/A") && (listStr[col_440] != "N/A") &&
(static_cast<int>(currentDate.getJulian()) == static_cast<int>(dinputDate)) (static_cast<int>(GetJulian(currentDate)) == static_cast<int>(dinputDate))
) )
{ {
tabStr.push_back(listStr); tabStr.push_back(listStr);
...@@ -312,17 +308,10 @@ AeronetFileReader ...@@ -312,17 +308,10 @@ AeronetFileReader
} }
//Compute time for one hour //Compute time for one hour
ossimLocalTm temp; internal::Date temp = {m_Year, m_Month, m_Day, 10, 0, 0};
temp.setDay(m_Day); double dhour1 = internal::GetJulian(temp);
temp.setMonth(m_Month); temp.hour = 11;
temp.setYear(m_Year); double dhour2 = internal::GetJulian(temp);
temp.setMin(0);
temp.setSec(0);
temp.setHour(10);
double dhour1 = temp.getJulian();
temp.setHour(11);
double dhour2 = temp.getJulian();
// Update epsilon for one hour // Update epsilon for one hour
double epsilon = m_Epsilon * (dhour2 - dhour1); double epsilon = m_Epsilon * (dhour2 - dhour1);
...@@ -333,7 +322,6 @@ AeronetFileReader ...@@ -333,7 +322,6 @@ AeronetFileReader
for (unsigned int idCurrentLine = 0; idCurrentLine < tabStr.size(); idCurrentLine++) for (unsigned int idCurrentLine = 0; idCurrentLine < tabStr.size(); idCurrentLine++)
{ {
VectorString current_line2 = tabStr[idCurrentLine]; VectorString current_line2 = tabStr[idCurrentLine];
ossimLocalTm currentDate = internal::ParseDate(current_line2[col_date], current_line2[col_time]);
ParseValidLine(dinputDate, current_line2, epsilon, water, angst, tau_day, solarZenithAngle); ParseValidLine(dinputDate, current_line2, epsilon, water, angst, tau_day, solarZenithAngle);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment