24 #include "getopts/getopts.h"
41 int main(
int argc,
char **argv ) {
47 opts.addOption(
"v",
"version" ,
"Display version info" ,
false );
48 opts.addOption(
"r",
"xml-req" ,
"Projection request file in XML" ,
true );
49 opts.addOption(
"o",
"model" ,
"File with serialized model (native projection)",
true );
50 opts.addOption(
"t",
"template" ,
"Raster template for the distribution map (native projection)",
true );
51 opts.addOption(
"f",
"format" ,
"File format for the distribution map (native projection)",
true );
52 opts.addOption(
"m",
"dist-map" ,
"File to store the generated model" ,
true );
53 opts.addOption(
"" ,
"log-level" ,
"Set the log level (debug, warn, info, error)",
true );
54 opts.addOption(
"" ,
"log-file" ,
"Log file" ,
true );
55 opts.addOption(
"" ,
"prog-file" ,
"File to store projection progress" ,
true );
56 opts.addOption(
"" ,
"stat-file" ,
"File to store projection statistics" ,
true );
57 opts.addOption(
"c",
"config-file",
"Configuration file for openModeller" ,
true );
59 std::string log_level(
"info");
60 std::string request_file;
61 std::string model_file;
62 std::string tmpl_file;
66 std::string progress_file;
67 std::string statistics_file;
68 std::string config_file;
70 if ( ! opts.parse( argc, argv ) ) {
72 opts.showHelp( argv[0] );
81 while ( ( option = opts.cycle() ) >= 0 ) {
86 printf(
"om_project %s\n", om.
getVersion().c_str() );
87 printf(
"This is free software; see the source for copying conditions. There is NO\n");
88 printf(
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
92 request_file = opts.getArgs( option );
95 model_file = opts.getArgs( option );
98 tmpl_file = opts.getArgs( option );
101 format = opts.getArgs( option );
104 map_file = opts.getArgs( option );
107 log_level = opts.getArgs( option );
110 log_file = opts.getArgs( option );
113 progress_file = opts.getArgs( option );
116 statistics_file = opts.getArgs( option );
119 config_file = opts.getArgs( option );
130 if ( ! log_file.empty() ) {
141 if ( ! config_file.empty() ) {
148 if ( request_file.empty() && model_file.empty() ) {
150 printf(
"Please specify either a projection request file in XML or a serialized model\n");
154 if ( (! request_file.empty()) && ( (! model_file.empty()) || (! tmpl_file.empty()) || (! format.empty() ) ) ) {
156 Log::instance()->
warn(
"When a request file is specified, --model, --template and --format are ignored" );
159 if ( map_file.empty() ) {
161 printf(
"Please specify a file to store the distribution map\n");
168 if ( ! progress_file.empty() ) {
186 MPI_Init( &argc, &argv );
188 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
190 MPI_Barrier( MPI_COMM_WORLD );
199 if ( ! progress_file.empty() ) {
204 else if ( ! statistics_file.empty() ) {
211 std::ostringstream model_output;
213 if ( ! request_file.empty() ) {
230 if ( tmpl_file.empty() ) {
233 std::string first_layer = env->getLayerPath(0);
242 if ( ! format.empty() ) {
247 om.
createMap( env, map_file.c_str(), tmpl );
254 std::ostringstream statistics_output;
261 if ( ! statistics_file.empty() ) {
263 ofstream file( statistics_file.c_str() );
264 file << statistics_output.str();
270 std::cout << statistics_output.str().c_str() << endl << flush;
276 if ( ! progress_file.empty() ) {
286 catch ( runtime_error e ) {
289 if ( ! progress_file.empty() ) {
295 printf(
"om_project aborted: %s\n", e.what() );
299 MPI_Barrier( MPI_COMM_WORLD );
static void loadConfig(const std::string configFile)
void setProjectionConfiguration(const ConstConfigurationPtr &)
void warn(const char *format,...)
'Warn' level.
static ConfigurationPtr readXml(char const *filename)
int main(int argc, char **argv)
AreaStats * getActualAreaStats()
static Log * instance()
Returns the instance pointer, creating the object on the first call.
void setMapCallback(ModelProjectionCallback func, void *param=0)
Log::Level getLogLevel(std::string level)
void setLevel(Level level)
EnvironmentPtr getEnvironment()
ConfigurationPtr getConfiguration() const
int createMap(const EnvironmentPtr &env, char const *output_file, MapFormat &format)
void setupExternalResources()
void set(Level level, std::string fileName, char const *pref="")
void progressDisplayCallback(float progress, void *extraParam)
static void writeXml(const ConstConfigurationPtr &config, char const *fileaname)
static int searchDefaultDirs()
void info(const char *format,...)
'Info' level.
void debug(const char *format,...)
'Debug' level.
void setModelConfiguration(const ConstConfigurationPtr &)
void progressFileCallback(float progress, void *progressData)