FFSM++
1.1.0
French Forest Sector Model ++
Main Page
Related Pages
Classes
Files
File List
File Members
main.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
* Copyright (C) 2015 by Laboratoire d'Economie Forestière *
3
* http://ffsm-project.org *
4
* *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 3 of the License, or *
8
* (at your option) any later version, given the compliance with the *
9
* exceptions listed in the file COPYING that is distribued together *
10
* with this file. *
11
* *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
16
* *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program; if not, write to the *
19
* Free Software Foundation, Inc., *
20
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21
***************************************************************************/
22
#include <iostream>
23
#include <string>
24
25
#include "
anyoption.h
"
26
27
28
#include <QApplication>
29
30
#include "
Sandbox.h
"
31
#include "
MainWindow.h
"
32
#include "
ThreadManager.h
"
33
34
// HTML code for the home page of the doxygen-generated documentation (Reference Manual)...
35
#include "../doc/referenceManual/mainPage.h"
36
37
using namespace
std
;
38
39
int
main
(
int
argc,
char
*argv[]){
40
#ifdef __GNUC__
41
#ifndef __MINGW32__
42
// I can't use this automatic runtime error, as ADOL-C, for some reasons, has some places that explicitally create inf or nan
43
//feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); // to enable runtime error of division by zero (only in linux, not on MinGw)
44
#endif
45
#endif
46
47
cout << endl;
48
cout <<
"*******************************************************************"
<< endl;
49
cout <<
"*** !! Welcome to FFSM - The Forest Sector Simulator !! ***"
<< endl;
50
cout <<
"*** For info & doc: http://www.ffsm-project.org/doc ***"
<< endl;
51
cout <<
"*** Full compiled on: "
<< __DATE__ <<
" - "
<< __TIME__ <<
" ***"
<< endl;
52
cout <<
"*******************************************************************"
<< endl<<endl;
53
54
// Running "simple testing" that can be done at this early time
55
Sandbox
TEST;
56
int
debug=0;
57
TEST.
basicTest
();
// normally this is an empty function, used only to place temporary in-developmentr tests
58
//TEST.runSimpleTests();
59
// TEST.testIpopt();
60
//debug = TEST.testAdolc();
61
//cout << "Early debug value: " << debug << endl;
62
63
64
QDir dir;
65
QString currentDir = dir.currentPath();
66
// it's ok to leave the current directory (relative as where we are starting the application) rather than the application
67
// path (relative to where ffsm is). This influence only the command line, where the -i option is always realtive to the local
68
// position we are calling it from.
69
70
71
QString inputFileName =
""
;
72
QString scenarioName =
""
;
73
74
75
// 1. CREATE AN OBJECT
76
AnyOption
*opt =
new
AnyOption
();
77
78
79
// 2. SET PREFERENCES
80
//opt->setVerbose(); // print warnings about unknown options
81
//opt->autoUsagePrint(true); // print usage for bad options
82
83
// 3. SET THE USAGE/HELP
84
opt->
addUsage
(
"*** FFSM - Forest Sector Simulator ***"
);
85
opt->
addUsage
(
"Usage: "
);
86
opt->
addUsage
(
""
);
87
opt->
addUsage
(
" -h --help Prints this help "
);
88
opt->
addUsage
(
" -c --console Run in console mode (no gui, default: false) "
);
89
opt->
addUsage
(
" -i --input_file [input_file_name] Input file (relative path, default: 'data/ffsmInput.ods') "
);
90
opt->
addUsage
(
" -s --scenario [scenario_name] Scenario name (default: the first defined in the input file) "
);
91
opt->
addUsage
(
""
);
92
opt->
addUsage
(
"Notes:"
);
93
opt->
addUsage
(
" - input_file and scenario options have no effect in GUI mode;"
);
94
opt->
addUsage
(
" - the working directory is the base path relative to the input file."
);
95
opt->
addUsage
(
""
);
96
opt->
addUsage
(
"Read installed documentation or browse it at http://www.ffsm-project.org/doc."
);
97
opt->
addUsage
(
""
);
98
99
// 4. SET THE OPTION STRINGS/CHARACTERS
100
opt->
setFlag
(
"help"
,
'h'
);
101
opt->
setFlag
(
"console"
,
'c'
);
102
opt->
setOption
(
"input_file"
,
'i'
);
103
opt->
setOption
(
"scenario"
,
's'
);
104
105
// 5. PROCESS THE COMMANDLINE
106
opt->
processCommandArgs
( argc, argv );
107
108
// 6. GET THE VALUES
109
if
( opt->
getFlag
(
"help"
) || opt->
getFlag
(
'h'
) || opt->
getArgc
() >0 ) {
110
opt->
printUsage
();
111
delete
opt;
112
return
EXIT_FAILURE;
113
}
114
115
if
( opt->
getValue
(
'i'
) != NULL || opt->
getValue
(
"input_file"
) != NULL ){
116
QString tempdata(opt->
getValue
(
'i'
));
117
inputFileName = currentDir +
"/"
+ tempdata;
118
}
119
else
{
120
inputFileName = currentDir +
"/data/ffsmInput.ods"
;
121
}
122
123
if
( opt->
getValue
(
's'
) != NULL || opt->
getValue
(
"scenario"
) != NULL ){
124
scenarioName = opt->
getValue
(
's'
);
125
}
126
127
if
( opt->
getFlag
(
'c'
) || opt->
getFlag
(
"console"
) ){
128
ThreadManager
modelMainThread;
129
modelMainThread.
runFromConsole
(inputFileName,scenarioName);
130
}
131
else
{
132
QApplication app(argc, argv);
133
MainWindow mainWin;
134
mainWin.show();
135
return
app.exec();
136
}
137
delete
opt;
138
}
MainWindow.h
AnyOption::setFlag
void setFlag(const char *opt_string)
Definition:
anyoption.cpp:499
std
STL namespace.
ThreadManager
Thread manager. Responsable to manage the main thread and "speak" with the GUI.
Definition:
ThreadManager.h:65
ThreadManager.h
AnyOption::getFlag
bool getFlag(const char *_option)
Definition:
anyoption.cpp:793
AnyOption::processCommandArgs
void processCommandArgs()
Definition:
anyoption.cpp:610
AnyOption
Definition:
anyoption.h:32
anyoption.h
AnyOption::getValue
char * getValue(const char *_option)
Definition:
anyoption.cpp:780
AnyOption::printUsage
void printUsage()
Definition:
anyoption.cpp:1139
Sandbox.h
AnyOption::addUsage
void addUsage(const char *line)
Definition:
anyoption.cpp:1153
ThreadManager::runFromConsole
void runFromConsole(QString inputFileName_h, QString scenarioName_h)
Re-draw the map making it to fit (with the right proportions) to the widget.
Definition:
ThreadManager.cpp:125
AnyOption::getArgc
int getArgc()
Definition:
anyoption.cpp:905
AnyOption::setOption
void setOption(const char *opt_string)
Definition:
anyoption.cpp:477
main
int main(int argc, char *argv[])
Definition:
main.cpp:39
Sandbox
Definition:
Sandbox.h:40
Sandbox::basicTest
void basicTest()
Simple tests that doesn't require anything else (are encapsulated) and so they can be run at the begi...
Definition:
Sandbox.cpp:132