Subversion Repositories public iLand

Rev

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