Rev 211 | Rev 226 | 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> |
||
214 | werner | 6 | #include "phenology.h" |
210 | werner | 7 | /// current climate variables of a day. @sa Climate. |
193 | werner | 8 | struct ClimateDay |
9 | { |
||
10 | int year; // year |
||
11 | int month; // month |
||
12 | int day; // day of year |
||
13 | double temperature; // average day °C |
||
198 | werner | 14 | double temp_delayed; // temperature delayed (after Maekela, 2008) for response calculations |
193 | werner | 15 | double preciptitation; // sum of day [mm] |
16 | double radiation; // sum of day (MJ/m2) |
||
17 | double vpd; // average of day [kPa] |
||
214 | werner | 18 | QString toString() const { return QString("%1.%2.%3").arg(day).arg(month).arg(year); } |
209 | werner | 19 | bool isValid() const { return (year>=0); } |
193 | werner | 20 | }; |
208 | werner | 21 | |
210 | werner | 22 | /// Sun handles calculations of day lengths, etc. |
23 | class Sun |
||
24 | { |
||
25 | public: |
||
26 | void setup(const double latitude_rad); |
||
27 | QString dump(); |
||
211 | werner | 28 | const double &daylength(const int day) const { return mDaylength_h[day]; } |
29 | int longestDay() const { return mDayWithMaxLength; } |
||
214 | werner | 30 | bool northernHemishere() const { return mDayWithMaxLength<300; } |
210 | werner | 31 | private: |
211 | werner | 32 | double mLatitude; ///< latitude in radians |
33 | int mDayWithMaxLength; ///< day of year with maximum day length |
||
210 | werner | 34 | double mDaylength_h[366]; ///< daylength per day in hours |
35 | }; |
||
36 | |||
193 | werner | 37 | class Climate |
38 | { |
||
39 | public: |
||
40 | Climate(); |
||
41 | void setup(); ///< setup routine that opens database connection |
||
42 | // activity |
||
43 | void nextYear(); |
||
198 | werner | 44 | // access to climate data |
214 | werner | 45 | const ClimateDay *dayOfYear(const int dayofyear) { return mBegin + dayofyear;} ///< get pointer to climate structure by day of year (0-based-index) |
198 | werner | 46 | 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!) |
47 | /// returns two pointer (arguments!!!) to the begin and one after end of the given month (month: 0..11) |
||
209 | werner | 48 | void monthRange(const int month, const ClimateDay **rBegin, const ClimateDay **rEnd); |
208 | werner | 49 | double days(const int month); ///< returns number of days of given month |
201 | werner | 50 | int daysOfYear(); ///< returns number of days of current year |
214 | werner | 51 | const ClimateDay *begin() { return mBegin; } ///< STL-like (pointer)-iterator |
52 | const ClimateDay *end() { return mEnd; } ///< STL-like pointer iterator |
||
53 | void toDate(const int yearday, int *rDay=0, int *rMonth=0, int *rYear=0); ///< decode "yearday" to the actual year, month, day if provided |
||
54 | // access to other subsystems |
||
55 | const Phenology &phenology(const int phenologyGroup); ///< phenology class of given type |
||
56 | const Sun &sun() { return mSun; } ///< solar radiation class |
||
193 | werner | 57 | |
58 | private: |
||
214 | werner | 59 | Sun mSun; ///< class doing solar radiation calculations |
193 | werner | 60 | void load(); ///< load mLoadYears years from database |
214 | werner | 61 | void setupPhenology(); ///< setup of phenology groups |
201 | werner | 62 | void climateCalculations(ClimateDay &lastDay); ///< more calculations done after loading of climate data |
214 | werner | 63 | ClimateDay mInvalidDay; |
193 | werner | 64 | int mLoadYears; // count of years to load ahead |
65 | int mCurrentYear; // current year (relative) |
||
66 | int mMinYear; // lowest year in store (relative) |
||
67 | int mMaxYear; // highest year in store (relative) |
||
214 | werner | 68 | ClimateDay *mBegin; // pointer to the first day of the current year |
69 | ClimateDay *mEnd; // pointer to the last day of the current year (+1) |
||
193 | werner | 70 | QVector<ClimateDay> mStore; ///< storage of climate data |
71 | QVector<int> mDayIndices; ///< store indices for month / years within store |
||
72 | QSqlQuery mClimateQuery; ///< sql query for db access |
||
214 | werner | 73 | QList<Phenology> mPhenology; ///< phenology calculations |
193 | werner | 74 | }; |
75 | |||
76 | #endif // CLIMATE_H |