Subversion Repositories public iLand

Rev

Rev 1221 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1221 Rev 1222
1
Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/global.h':
1
Redirecting to URL 'https://iland.boku.ac.at/svn/iland/tags/release_1.0/src/core/global.h':
2
/********************************************************************************************
2
/********************************************************************************************
3
**    iLand - an individual based forest landscape and disturbance model
3
**    iLand - an individual based forest landscape and disturbance model
4
**    http://iland.boku.ac.at
4
**    http://iland.boku.ac.at
5
**    Copyright (C) 2009-  Werner Rammer, Rupert Seidl
5
**    Copyright (C) 2009-  Werner Rammer, Rupert Seidl
6
**
6
**
7
**    This program is free software: you can redistribute it and/or modify
7
**    This program is free software: you can redistribute it and/or modify
8
**    it under the terms of the GNU General Public License as published by
8
**    it under the terms of the GNU General Public License as published by
9
**    the Free Software Foundation, either version 3 of the License, or
9
**    the Free Software Foundation, either version 3 of the License, or
10
**    (at your option) any later version.
10
**    (at your option) any later version.
11
**
11
**
12
**    This program is distributed in the hope that it will be useful,
12
**    This program is distributed in the hope that it will be useful,
13
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
**    GNU General Public License for more details.
15
**    GNU General Public License for more details.
16
**
16
**
17
**    You should have received a copy of the GNU General Public License
17
**    You should have received a copy of the GNU General Public License
18
**    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
**    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
********************************************************************************************/
19
********************************************************************************************/
20
20
21
#ifndef GLOBAL_H
21
#ifndef GLOBAL_H
22
#define GLOBAL_H
22
#define GLOBAL_H
23
23
24
#define MSGRETURN(x) { qDebug() << x; return; }
24
#define MSGRETURN(x) { qDebug() << x; return; }
25
#define WARNINGRETURN(x) { qWarning() << x; return; }
25
#define WARNINGRETURN(x) { qWarning() << x; return; }
26
#define ERRORRETURN(x) { qError() << x; return; }
26
#define ERRORRETURN(x) { qError() << x; return; }
27
// conversions rad/degree
27
// conversions rad/degree
28
#define RAD(x) (x*M_PI/180.)
28
#define RAD(x) (x*M_PI/180.)
29
#define GRAD(x) (x/M_PI*180.)
29
#define GRAD(x) (x/M_PI*180.)
30
#define PI2 2*M_PI
30
#define PI2 2*M_PI
31
31
32
#include <cstdlib>
32
#include <cstdlib>
33
#include "math.h"
33
#include "math.h"
34
#include "exception.h"
34
#include "exception.h"
35
// general datatypes
35
// general datatypes
36
//typedef int TreeSpecies;
36
//typedef int TreeSpecies;
37
37
38
// global debug helpers (used by macros!)
38
// global debug helpers (used by macros!)
39
void dbg_helper(const char *where, const char *what,const char* file,int line);
39
void dbg_helper(const char *where, const char *what,const char* file,int line);
40
void dbg_helper_ext(const char *where, const char *what,const char* file,int line, const QString &s);
40
void dbg_helper_ext(const char *where, const char *what,const char* file,int line, const QString &s);
41
41
42
// change to enabled detailed debug messages.
42
// change to enabled detailed debug messages.
43
// if NO_DEBUG_MSGS is defined, NO debug outputs are generated.
43
// if NO_DEBUG_MSGS is defined, NO debug outputs are generated.
44
// NO_DEBUG_MSG
44
// NO_DEBUG_MSG
45
//#if !defined(QT_DEBUG)
45
//#if !defined(QT_DEBUG)
46
//#define NO_DEBUG_MSGS
46
//#define NO_DEBUG_MSGS
47
//#endif
47
//#endif
48
48
49
#if !defined(DBG_IF)
49
#if !defined(DBG_IF)
50
#  ifndef NO_DEBUG_MSGS
50
#  ifndef NO_DEBUG_MSGS
51
#    define DBG_IF(cond, where, what) ((cond) ? dbg_helper(where, what, __FILE__, __LINE__) : qt_noop())
51
#    define DBG_IF(cond, where, what) ((cond) ? dbg_helper(where, what, __FILE__, __LINE__) : qt_noop())
52
#  else
52
#  else
53
#    define DBG_IF(cond, where, what) qt_noop()
53
#    define DBG_IF(cond, where, what) qt_noop()
54
#  endif
54
#  endif
55
#endif
55
#endif
56
56
57
#if !defined(DBG_IF_X)
57
#if !defined(DBG_IF_X)
58
#  ifndef NO_DEBUG_MSGS
58
#  ifndef NO_DEBUG_MSGS
59
#    define DBG_IF_X(cond, where, what,more) ((cond) ? dbg_helper_ext(where, what, __FILE__, __LINE__,more) : qt_noop())
59
#    define DBG_IF_X(cond, where, what,more) ((cond) ? dbg_helper_ext(where, what, __FILE__, __LINE__,more) : qt_noop())
60
#  else
60
#  else
61
#    define DBG_IF_X(cond, where, what,more) qt_noop()
61
#    define DBG_IF_X(cond, where, what,more) qt_noop()
62
#  endif
62
#  endif
63
#endif
63
#endif
64
64
65
#if !defined(DBGMODE)
65
#if !defined(DBGMODE)
66
#  ifndef NO_DEBUG_MSGS
66
#  ifndef NO_DEBUG_MSGS
67
#    define DBGMODE(stmts) { stmts }
67
#    define DBGMODE(stmts) { stmts }
68
#  else
68
#  else
69
#    define DBGMODE(stmts) qt_noop()
69
#    define DBGMODE(stmts) qt_noop()
70
#  endif
70
#  endif
71
#endif
71
#endif
72
72
73
// log level functions
73
// log level functions
74
bool logLevelDebug(); // true, if detailed debug information is logged
74
bool logLevelDebug(); // true, if detailed debug information is logged
75
bool logLevelInfo(); // true, if only important aggreate info is logged
75
bool logLevelInfo(); // true, if only important aggreate info is logged
76
bool logLevelWarning(); // true if only severe warnings/errors are logged.
76
bool logLevelWarning(); // true if only severe warnings/errors are logged.
77
void setLogLevel(int loglevel); // setter function
77
void setLogLevel(int loglevel); // setter function
78
78
79
// the random number generator:
79
// the random number generator:
80
#include "randomgenerator.h"
80
#include "randomgenerator.h"
81
81
82
82
83
inline double limit(const double value, const double lower, const double upper)
83
inline double limit(const double value, const double lower, const double upper)
84
{
84
{
85
    return qMax(qMin(value, upper), lower);
85
    return qMax(qMin(value, upper), lower);
86
}
86
}
87
inline int limit(const int value, const int lower, const int upper)
87
inline int limit(const int value, const int lower, const int upper)
88
{
88
{
89
    return qMax(qMin(value, upper), lower);
89
    return qMax(qMin(value, upper), lower);
90
}
90
}
91
inline void setBit(int &rTarget, const int bit, const bool value)
91
inline void setBit(int &rTarget, const int bit, const bool value)
92
{
92
{
93
    if (value)
93
    if (value)
94
        rTarget |= (1 << bit);  // set bit
94
        rTarget |= (1 << bit);  // set bit
95
    else
95
    else
96
        rTarget &= ( (1 << bit) ^ 0xffffff ); // clear bit
96
        rTarget &= ( (1 << bit) ^ 0xffffff ); // clear bit
97
}
97
}
98
inline bool isBitSet(const int value, const int bit)
98
inline bool isBitSet(const int value, const int bit)
99
{
99
{
100
    return value & (1 << bit);
100
    return value & (1 << bit);
101
}
101
}
102
102
103
// define a global isnan() function
103
// define a global isnan() function
104
#ifndef isnan
104
#ifndef isnan
105
#define isnan(x) ((x) != (x))
105
#define isnan(x) ((x) != (x))
106
#endif
106
#endif
107
107
108
#include "globalsettings.h"
108
#include "globalsettings.h"
109
109
110
#endif // GLOBAL_H
110
#endif // GLOBAL_H
111
 
111