Subversion Repositories public iLand

Rev

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

Rev 210 Rev 211
Line 34... Line 34...
34
/** loads active species from a database table and creates/setups the species.
34
/** loads active species from a database table and creates/setups the species.
35
    The function uses the global database-connection.
35
    The function uses the global database-connection.
36
  */
36
  */
37
int SpeciesSet::setup()
37
int SpeciesSet::setup()
38
{
38
{
-
 
39
    // setup phenology
-
 
40
    setupPhenology();
-
 
41
39
    const XmlHelper &xml = GlobalSettings::instance()->settings();
42
    const XmlHelper &xml = GlobalSettings::instance()->settings();
40
    QString tableName = xml.value("model.species.source", "species");
43
    QString tableName = xml.value("model.species.source", "species");
41
    QString readerFile = xml.value("model.species.reader", "reader.bin");
44
    QString readerFile = xml.value("model.species.reader", "reader.bin");
42
    readerFile = GlobalSettings::instance()->path(readerFile, "lip");
45
    readerFile = GlobalSettings::instance()->path(readerFile, "lip");
43
    mReaderStamp.load(readerFile);
46
    mReaderStamp.load(readerFile);
Line 88... Line 91...
88
        throw IException("at least one parameter of model.species.CO2Response is not valid!");
91
        throw IException("at least one parameter of model.species.CO2Response is not valid!");
89
92
90
    return mSpecies.count();
93
    return mSpecies.count();
91
94
92
}
95
}
-
 
96
-
 
97
void SpeciesSet::setupPhenology()
-
 
98
{
-
 
99
    mPhenology.clear();
-
 
100
    mPhenology.push_back(Phenology()); // id=0
-
 
101
    XmlHelper xml(GlobalSettings::instance()->settings().node("model.species.phenology"));
-
 
102
    int i=0;
-
 
103
    do {
-
 
104
        QDomElement n = xml.node(QString("type[%1]").arg(i));
-
 
105
        if (n.isNull())
-
 
106
            break;
-
 
107
        i++;
-
 
108
        int id;
-
 
109
        id = n.attribute("id", "-1").toInt();
-
 
110
        if (id<0) throw IException(QString("Error setting up phenology: id invalid\ndump: %1").arg(xml.dump("")));
-
 
111
        xml.setCurrentNode(QString("type[%1]").arg(i));
-
 
112
        Phenology item( id,
-
 
113
                        xml.valueDouble(".vpdMin",0.5), // use relative access to node (".x")
-
 
114
                        xml.valueDouble(".vpdMax", 5),
-
 
115
                        xml.valueDouble(".minDayLength",10),
-
 
116
                        xml.valueDouble(".maxDayLength",11),
-
 
117
                        xml.valueDouble(".tempMin", 2),
-
 
118
                        xml.valueDouble(".tempMax", 9) );
-
 
119
-
 
120
        mPhenology.push_back(item);
-
 
121
    } while(true);
-
 
122
-
 
123
}
-
 
124
93
/** retrieves variables from the datasource available during the setup of species.
125
/** retrieves variables from the datasource available during the setup of species.
94
  */
126
  */
95
QVariant SpeciesSet::var(const QString& varName)
127
QVariant SpeciesSet::var(const QString& varName)
96
{
128
{
97
    Q_ASSERT(mSetupQuery!=0);
129
    Q_ASSERT(mSetupQuery!=0);
Line 158... Line 190...
158
    double K1 = (1. + K2*deltaC) / deltaC;
190
    double K1 = (1. + K2*deltaC) / deltaC;
159
191
160
    double response = mCO2p0 * K1*(ambientCO2 - mCO2comp) / (1 + K2*(ambientCO2-mCO2comp)); // Eq. 16
192
    double response = mCO2p0 * K1*(ambientCO2 - mCO2comp) / (1 + K2*(ambientCO2-mCO2comp)); // Eq. 16
161
    return response;
193
    return response;
162
194
-
 
195
}
-
 
196
-
 
197
/** return the phenology of the group... */
-
 
198
const Phenology &SpeciesSet::phenology(const int phenologyGroup)
-
 
199
{
-
 
200
    const Phenology &p = mPhenology.at(phenologyGroup);
-
 
201
    if (p.id() == phenologyGroup)
-
 
202
        return p;
-
 
203
    // search...
-
 
204
    for (int i=0;i<mPhenology.count();i++)
-
 
205
        if (mPhenology[i].id()==phenologyGroup)
-
 
206
            return mPhenology[i];
-
 
207
    throw IException(QString("Error at SpeciesSEt::phenology(): invalid group: %1").arg(phenologyGroup));
163
}
208
}