Subversion Repositories public iLand

Rev

Rev 211 | Rev 226 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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