Subversion Repositories public iLand

Rev

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

Rev 213 Rev 214
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
-
 
42
    const XmlHelper &xml = GlobalSettings::instance()->settings();
39
    const XmlHelper &xml = GlobalSettings::instance()->settings();
43
    QString tableName = xml.value("model.species.source", "species");
40
    QString tableName = xml.value("model.species.source", "species");
44
    QString readerFile = xml.value("model.species.reader", "reader.bin");
41
    QString readerFile = xml.value("model.species.reader", "reader.bin");
45
    readerFile = GlobalSettings::instance()->path(readerFile, "lip");
42
    readerFile = GlobalSettings::instance()->path(readerFile, "lip");
46
    mReaderStamp.load(readerFile);
43
    mReaderStamp.load(readerFile);
Line 92... Line 89...
92
89
93
    return mSpecies.count();
90
    return mSpecies.count();
94
91
95
}
92
}
96
93
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(n);
-
 
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
94
125
/** retrieves variables from the datasource available during the setup of species.
95
/** retrieves variables from the datasource available during the setup of species.
126
  */
96
  */
127
QVariant SpeciesSet::var(const QString& varName)
97
QVariant SpeciesSet::var(const QString& varName)
128
{
98
{
Line 192... Line 162...
192
    double response = mCO2p0 * K1*(ambientCO2 - mCO2comp) / (1 + K2*(ambientCO2-mCO2comp)); // Eq. 16
162
    double response = mCO2p0 * K1*(ambientCO2 - mCO2comp) / (1 + K2*(ambientCO2-mCO2comp)); // Eq. 16
193
    return response;
163
    return response;
194
164
195
}
165
}
196
166
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));
-
 
208
}
-
 
-
 
167