Subversion Repositories public iLand

Rev

Rev 209 | Rev 211 | 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>
210 werner 6
/// current climate variables of a day. @sa Climate.
193 werner 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
 
210 werner 21
/// Sun handles calculations of day lengths, etc.
22
class Sun
23
{
24
public:
25
    void setup(const double latitude_rad);
26
    QString dump();
27
    const double &daylength(const int day) { return mDaylength_h[day]; }
28
private:
29
    double mLatitude;
30
    double mDaylength_h[366]; ///< daylength per day in hours
31
};
32
 
193 werner 33
class Climate
34
{
35
public:
36
    Climate();
37
    void setup(); ///< setup routine that opens database connection
38
    // activity
39
    void nextYear();
198 werner 40
    // access to climate data
41
    const ClimateDay *dayOfYear(const int dayofyear); ///< get pointer to climate structure by day of year (0-based-index)
42
    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!)
43
    /// returns two pointer (arguments!!!) to the begin and one after end of the given month (month: 0..11)
209 werner 44
    void monthRange(const int month, const ClimateDay **rBegin, const ClimateDay **rEnd);
208 werner 45
    double days(const int month); ///< returns number of days of given month
201 werner 46
    int daysOfYear(); ///< returns number of days of current year
193 werner 47
 
48
private:
201 werner 49
    ClimateDay mInvalidDay;
193 werner 50
    void load(); ///< load mLoadYears years from database
201 werner 51
    void climateCalculations(ClimateDay &lastDay); ///< more calculations done after loading of climate data
193 werner 52
    int mLoadYears; // count of years to load ahead
53
    int mCurrentYear; // current year (relative)
54
    int mMinYear; // lowest year in store (relative)
55
    int mMaxYear;  // highest year in store (relative)
56
    QVector<ClimateDay> mStore; ///< storage of climate data
57
    QVector<int> mDayIndices; ///< store indices for month / years within store
58
    QSqlQuery mClimateQuery; ///< sql query for db access
59
};
60
 
61
#endif // CLIMATE_H