6 #include "getopts/getopts.h"
17 int main(
int argc,
char **argv ) {
23 opts.addOption(
"" ,
"log-level" ,
"Set the log level (debug, warn, info, error)",
true );
24 opts.addOption(
"v",
"version" ,
"Display version info",
false );
25 opts.addOption(
"l",
"list" ,
"List available algorithms (id and name)",
false );
26 opts.addOption(
"d",
"dump-xml" ,
"Dump algorithms' metadata in XML",
false );
27 opts.addOption(
"i",
"id" ,
"Algorithm id",
true );
28 opts.addOption(
"c",
"config-file",
"Configuration file for openModeller",
true );
30 std::string log_level(
"info");
31 bool list_algs =
false;
32 bool dump_algs =
false;
34 std::string config_file;
36 if ( ! opts.parse( argc, argv ) ) {
38 opts.showHelp( argv[0] );
47 while ( ( option = opts.cycle() ) >= 0 ) {
52 log_level = opts.getArgs( option );
55 printf(
"om_algorithm %s\n", om.
getVersion().c_str() );
56 printf(
"This is free software; see the source for copying conditions. There is NO\n");
57 printf(
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
67 alg_id = opts.getArgs( option );
70 config_file = opts.getArgs( option );
79 if ( ( ! list_algs ) && ( ! dump_algs ) && alg_id.empty() ) {
81 printf(
"Please specify one of the parameters: --list, --dump-xml or --id\n");
92 if ( ! config_file.empty() ) {
115 if ( ! *availables ) {
117 printf(
"Could not find any algorithm.\n" );
123 printf(
"Available algorithms (id: name)\n" );
125 while ( ( metadata = *availables++ ) ) {
127 printf(
" %s: %s\n", metadata->
id.c_str(), metadata->
name.c_str() );
133 if ( ! alg_id.empty() ) {
137 printf(
"Algorithm metadata:\n" );
138 printf(
" Name: %s\n", alg_metadata->
name.c_str() );
139 printf(
" Version: %s\n", alg_metadata->
version.c_str() );
140 printf(
" Overview:\n\n%s\n\n", alg_metadata->
overview.c_str() );
141 printf(
" Description:\n\n%s\n\n", alg_metadata->
description.c_str() );
142 printf(
" Author(s): %s\n", alg_metadata->
author.c_str() );
143 printf(
" Bibliography:\n\n%s\n\n", alg_metadata->
biblio.c_str() );
144 printf(
" Developer(s): %s (%s)\n", alg_metadata->
code_author.c_str(), alg_metadata->
contact.c_str() );
146 std::string
const accepts_categorical = ( alg_metadata->
categorical ) ?
"yes" :
"no";
147 printf(
" Accepts categorical data: %s\n", accepts_categorical.c_str() );
149 std::string
const requires_absences = ( alg_metadata->
absence ) ?
"yes" :
"no";
150 printf(
" Requires absence points: %s\n", requires_absences.c_str() );
155 for (
int i = 0 ; i < alg_metadata->
nparam; param++, i++ ) {
157 printf(
"\n Parameter: %s\n", param->id.c_str() );
158 printf(
" Name: %s\n", param->name.c_str() );
160 string datatype(
"?");
162 if ( param->type ==
Integer ) {
164 datatype =
"Integer";
166 else if ( param->type ==
Real ) {
170 else if ( param->type ==
String ) {
175 printf(
" Datatype: %s\n", datatype.c_str() );
177 printf(
" Overview: %s\n", param->overview.c_str() );
179 printf(
" Description: %s\n", param->description.c_str() );
181 if ( param->has_min || param->has_max ) {
183 if ( param->has_min ) {
185 printf(
" Minimum value: %f\n", param->min_val );
187 if ( param->has_max ) {
189 printf(
" Maximum value: %f\n", param->max_val );
193 printf(
" Typical value: %s\n", param->typical.c_str() );
197 catch ( runtime_error e ) {
199 printf(
"om_algorithm: %s\n", e.what() );
static void loadConfig(const std::string configFile)
static Log * instance()
Returns the instance pointer, creating the object on the first call.
int main(int argc, char **argv)
Log::Level getLogLevel(std::string level)
void setLevel(Level level)
static ConfigurationPtr getConfiguration()
void setupExternalResources()
AlgMetadata const ** availableAlgorithms()
static void writeXml(const ConstConfigurationPtr &config, char const *fileaname)
static int searchDefaultDirs()
static AlgMetadata const * algorithmMetadata(std::string const algorithm_id)