Rev 348 | Rev 436 | 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 |
||
414 | werner | 13 | double temperature; // average day °C (of the light hours) |
14 | double min_temperature; // minimum temperature of the day |
||
198 | werner | 15 | double temp_delayed; // temperature delayed (after Maekela, 2008) for response calculations |
193 | werner | 16 | double preciptitation; // sum of day [mm] |
17 | double radiation; // sum of day (MJ/m2) |
||
234 | werner | 18 | double vpd; // average of day [kPa] = [0.1 mbar] (1 bar = 100kPa) |
226 | werner | 19 | static double co2; // ambient CO2 content in ppm |
214 | werner | 20 | QString toString() const { return QString("%1.%2.%3").arg(day).arg(month).arg(year); } |
209 | werner | 21 | bool isValid() const { return (year>=0); } |
240 | werner | 22 | int id() const { return year*10000 + month*100 + day; } |
193 | werner | 23 | }; |
208 | werner | 24 | |
210 | werner | 25 | /// Sun handles calculations of day lengths, etc. |
26 | class Sun |
||
27 | { |
||
28 | public: |
||
29 | void setup(const double latitude_rad); |
||
30 | QString dump(); |
||
211 | werner | 31 | const double &daylength(const int day) const { return mDaylength_h[day]; } |
32 | int longestDay() const { return mDayWithMaxLength; } |
||
214 | werner | 33 | bool northernHemishere() const { return mDayWithMaxLength<300; } |
210 | werner | 34 | private: |
211 | werner | 35 | double mLatitude; ///< latitude in radians |
36 | int mDayWithMaxLength; ///< day of year with maximum day length |
||
210 | werner | 37 | double mDaylength_h[366]; ///< daylength per day in hours |
38 | }; |
||
39 | |||
193 | werner | 40 | class Climate |
41 | { |
||
42 | public: |
||
43 | Climate(); |
||
44 | void setup(); ///< setup routine that opens database connection |
||
280 | werner | 45 | bool isSetup() const { return mIsSetup; } |
318 | werner | 46 | const QString &name() const { return mName; } ///< table name of this climate |
193 | werner | 47 | // activity |
48 | void nextYear(); |
||
198 | werner | 49 | // access to climate data |
255 | werner | 50 | const ClimateDay *dayOfYear(const int dayofyear) const { return mBegin + dayofyear;} ///< get pointer to climate structure by day of year (0-based-index) |
51 | const ClimateDay *day(const int month, const int day) const; ///< gets pointer to climate structure of given day (0-based indices, i.e. month=11=december!) |
||
198 | werner | 52 | /// returns two pointer (arguments!!!) to the begin and one after end of the given month (month: 0..11) |
255 | werner | 53 | void monthRange(const int month, const ClimateDay **rBegin, const ClimateDay **rEnd) const; |
327 | werner | 54 | double days(const int month) const; ///< returns number of days of given month (0..11) |
255 | werner | 55 | int daysOfYear() const; ///< returns number of days of current year. points to the first day of the current year. |
327 | werner | 56 | const ClimateDay *begin() const { return mBegin; } ///< STL-like (pointer)-iterator to the first day of the current year |
57 | const ClimateDay *end() const { return mEnd; } ///< STL-like pointer iterator to the day *after* last day of the current year |
||
255 | werner | 58 | void toDate(const int yearday, int *rDay=0, int *rMonth=0, int *rYear=0) const; ///< decode "yearday" to the actual year, month, day if provided |
214 | werner | 59 | // access to other subsystems |
238 | werner | 60 | const Phenology &phenology(const int phenologyGroup) const; ///< phenology class of given type |
61 | const Sun &sun() const { return mSun; } ///< solar radiation class |
||
62 | double daylength_h(const int doy) const { return sun().daylength(doy); } ///< length of the day in hours |
||
193 | werner | 63 | |
64 | private: |
||
280 | werner | 65 | bool mIsSetup; |
348 | werner | 66 | bool mDoRandomSampling; ///< if true, the sequence of years is randomized |
318 | werner | 67 | QString mName; |
214 | werner | 68 | Sun mSun; ///< class doing solar radiation calculations |
193 | werner | 69 | void load(); ///< load mLoadYears years from database |
214 | werner | 70 | void setupPhenology(); ///< setup of phenology groups |
201 | werner | 71 | void climateCalculations(ClimateDay &lastDay); ///< more calculations done after loading of climate data |
214 | werner | 72 | ClimateDay mInvalidDay; |
193 | werner | 73 | int mLoadYears; // count of years to load ahead |
74 | int mCurrentYear; // current year (relative) |
||
75 | int mMinYear; // lowest year in store (relative) |
||
76 | int mMaxYear; // highest year in store (relative) |
||
313 | werner | 77 | double mTemperatureShift; // add this to daily temp |
78 | double mPrecipitationShift; // multiply prec with that |
||
214 | werner | 79 | ClimateDay *mBegin; // pointer to the first day of the current year |
80 | ClimateDay *mEnd; // pointer to the last day of the current year (+1) |
||
193 | werner | 81 | QVector<ClimateDay> mStore; ///< storage of climate data |
82 | QVector<int> mDayIndices; ///< store indices for month / years within store |
||
83 | QSqlQuery mClimateQuery; ///< sql query for db access |
||
214 | werner | 84 | QList<Phenology> mPhenology; ///< phenology calculations |
348 | werner | 85 | QVector<int> mRandomYearList; ///< for random sampling of years |
86 | int mRandomListIndex; ///< current index of the randomYearList for random sampling |
||
193 | werner | 87 | }; |
88 | |||
89 | #endif // CLIMATE_H |