Rev 208 | Rev 210 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | |||
193 | werner | 2 | #ifndef CLIMATE_H |
3 | #define CLIMATE_H |
||
4 | |||
5 | #include <QtSql> |
||
6 | |||
7 | struct ClimateDay |
||
8 | { |
||
9 | int year; // year |
||
10 | int month; // month |
||
11 | int day; // day of year |
||
12 | double temperature; // average day °C |
||
198 | werner | 13 | double temp_delayed; // temperature delayed (after Maekela, 2008) for response calculations |
193 | werner | 14 | double preciptitation; // sum of day [mm] |
15 | double radiation; // sum of day (MJ/m2) |
||
16 | double vpd; // average of day [kPa] |
||
209 | werner | 17 | QString date() const { return QString("%1.%2.%3").arg(day).arg(month).arg(year); } |
18 | bool isValid() const { return (year>=0); } |
||
193 | werner | 19 | }; |
208 | werner | 20 | |
193 | werner | 21 | class Climate |
22 | { |
||
23 | public: |
||
24 | Climate(); |
||
25 | void setup(); ///< setup routine that opens database connection |
||
26 | // activity |
||
27 | void nextYear(); |
||
198 | werner | 28 | // access to climate data |
29 | const ClimateDay *dayOfYear(const int dayofyear); ///< get pointer to climate structure by day of year (0-based-index) |
||
30 | const ClimateDay *day(const int month, const int day); ///< gets pointer to climate structure of given day (0-based indices, i.e. month=11=december!) |
||
31 | /// returns two pointer (arguments!!!) to the begin and one after end of the given month (month: 0..11) |
||
209 | werner | 32 | void monthRange(const int month, const ClimateDay **rBegin, const ClimateDay **rEnd); |
208 | werner | 33 | double days(const int month); ///< returns number of days of given month |
201 | werner | 34 | int daysOfYear(); ///< returns number of days of current year |
193 | werner | 35 | |
36 | private: |
||
201 | werner | 37 | ClimateDay mInvalidDay; |
193 | werner | 38 | void load(); ///< load mLoadYears years from database |
201 | werner | 39 | void climateCalculations(ClimateDay &lastDay); ///< more calculations done after loading of climate data |
193 | werner | 40 | int mLoadYears; // count of years to load ahead |
41 | int mCurrentYear; // current year (relative) |
||
42 | int mMinYear; // lowest year in store (relative) |
||
43 | int mMaxYear; // highest year in store (relative) |
||
44 | QVector<ClimateDay> mStore; ///< storage of climate data |
||
45 | QVector<int> mDayIndices; ///< store indices for month / years within store |
||
46 | QSqlQuery mClimateQuery; ///< sql query for db access |
||
47 | }; |
||
48 | |||
49 | #endif // CLIMATE_H |