Functions | Variables
dinver/main.cpp File Reference
#include <time.h>
#include <QSettings>
#include <DinverCore.h>
#include <DinverGui.h>
#include <SciFigs.h>
#include "dinverInstallPath.h"
#include "dinverVersion.h"
#include "PluginSelector.h"

Functions

bool checkRemainingArguments (int argc, char **argv)
ApplicationHelphelp ()
int main (int argc, char **argv)
int modeGui (int argc, char **argv)
int modeImportanceSampling (int argc, char **argv, const QString &baseFileName)
int modeNeighborhoodOptimization (int argc, char **argv)
int modeSnoopOptimization (int argc, char **argv)
 PACKAGE_INFO (dinver, DINVER)

Variables

bool debugStream = false
QString pluginTag

Function Documentation

bool checkRemainingArguments ( int  argc,
char **  argv 
)

References QGpCoreTools::endl(), and QGpCoreTools::tr().

Referenced by modeExport(), modeGroupList(), modeGui(), modeNeighborhoodOptimization(), modeTool(), and modeWaveform().

{
  if(argc>1) {
    for(int i=1; i<argc; i++) {
      App::stream() << tr("dinver: bad option '%1', see -h").arg(argv[i]) << endl;
    }
    return false;
  } else {
    return true;
  }
}
int main ( int  argc,
char **  argv 
)

References debugStream, help(), mode, modeGui(), modeImportanceSampling(), modeNeighborhoodOptimization(), modeSnoopOptimization(), pluginTag, and DinverCore::DinverCoreObject::printPluginList().

{
  // Basic options: selection of the main modes and plugin
  enum Mode {Gui, SnoopOptimization, NeighborhoodOptimization, ImportanceSampling};
  Mode mode=Gui;
  QString baseFileName;
  // Check arguments
  int j=1;
  for(int i=1; i<argc; i++) {
    QByteArray arg=argv[i];
    if(arg[0]=='-') {
      if(arg=="-debug-stream") {
        debugStream= true;
      } else if(arg=="-plugin-list") {
        CoreApplication a(argc, argv,help);
        DinverGui::printPluginList();
        return 0;
     } else if(arg=="-i") {
        CoreApplication::checkOptionArg(i, argc, argv);
        pluginTag=argv[i];
      } else if(arg=="-na-optimization" || arg=="-optimization") { // Kept for compatibility
        mode=NeighborhoodOptimization;
      } else if(arg=="-snoop-optimization") {
        mode=SnoopOptimization;
      } else if(arg=="-importance-sampling") {
        CoreApplication::checkOptionArg(i, argc, argv);
        baseFileName=argv[i];
        mode=ImportanceSampling;
      } else {
        argv[j++]=argv[i];
      }
    } else {
      argv[j++]=argv[i];
    }
  }
  if(j < argc) {
    argv[j]=0;
    argc=j;
  }

  switch(mode) {
  case Gui:
    return modeGui(argc, argv);
  case NeighborhoodOptimization:
    return modeNeighborhoodOptimization(argc, argv);
  case SnoopOptimization:
    return modeSnoopOptimization(argc, argv);
  case ImportanceSampling:
    return modeImportanceSampling(argc, argv, baseFileName);
  };
  return 0;
}
int modeGui ( int  argc,
char **  argv 
)

References QGpGuiTools::LogWidget::addView(), checkRemainingArguments(), debugStream, QGpCoreTools::endl(), help(), DinverGui::logs(), DinverGui::open(), DinverGui::pluginSelector(), pluginTag, QGpGuiTools::Application::setConsoleMessage(), QGpGuiTools::LogWidget::setDebugMode(), DinverGui::setPlugin(), QGpCoreTools::tr(), and w.

Referenced by main().

{
  Application a(argc, argv, help);
  a.setConsoleMessage();

  // Options
  QString dinverFile;
  // Check arguments
  int j=1;
  for(int i=1; i<argc; i++) {
    QByteArray arg=argv[i];
    if(arg[0]=='-') {
      if(arg=="-env") {
        Application::checkOptionArg(i, argc, argv);
        dinverFile=argv[i];
      } else if(arg=="-clear-plugins") {
        QSettings reg;
        reg.remove( "Plugins" );
      } else {
        App::stream() << tr("dinver: bad option %1, see --help").arg(argv[i]) << endl;
        return 2;
      }
    } else {
      argv[j++]=argv[i];
    }
  }
  if(j < argc) {
    argv[j]=0;
    argc=j;
  }
  if(!checkRemainingArguments(argc,argv)) {
    return 2;
  }

  SciFigsGlobal s;
  Application::instance()->setGuiMessage();

  QString pluginFile=DinverGui::pluginSelector(pluginTag, debugStream);
  if(pluginFile.isEmpty()) {
    App::stream() << tr("No plugin selected") << endl;
    return 2;
  }

  DinverGui * w=new DinverGui;
  w->setObjectName("dinver");
  if(!w->setPlugin(pluginFile)) {
    delete w;
    App::stream() << tr("Cannot load plugin %1").arg(pluginFile) << endl;
    return 2;
  }
  w->logs()->setDebugMode(debugStream);
  // Add main message board (after debug mode switch)
  w->logs()->addView(QThread::currentThread(), tr("Messages"));
  w->show();
  if( !dinverFile.isEmpty()) w->open(dinverFile);
  return qApp->exec();
}
int modeImportanceSampling ( int  argc,
char **  argv,
const QString &  baseFileName 
)

References debugStream, DinverCore::dinverCore, QGpCoreTools::endl(), help(), DinverCore::BatchRun::importanceSampling(), DinverCore::DinverCoreObject::pluginFile(), pluginTag, reportAction, DinverCore::BatchRun::setParameters(), DinverCore::DinverCoreObject::setPlugin(), and QGpCoreTools::tr().

Referenced by main().

{
  CoreApplication a(argc, argv, help);

  if(pluginTag.isEmpty()) {
    App::stream() << tr("dinver: no plugin selected (option -i)") << endl;
    return 2;
  }

  DinverCoreObject dinverCore;
  QString pluginFile=dinverCore.pluginFile(pluginTag, debugStream);
  if(!dinverCore.setPlugin(pluginFile, debugStream)) {
    App::stream() << tr("dinver: cannot set plugin with tag %1").arg(pluginTag) << endl;
    return 2;
  }

  // Options
  QString paramFile;
  int ns=5000;
  int seed=0;
  QString outputFileName="run.report";
  ReportWriter::Action reportAction=ReportWriter::Ask;
  // Check arguments
  int j=1;
  for(int i=1; i<argc; i++) {
    QByteArray arg=argv[i];
    if(arg[0]=='-') {
      if(arg=="-param") {
        Application::checkOptionArg(i, argc, argv);
        paramFile=argv[i];
      } else if(arg=="-ns") {
        CoreApplication::checkOptionArg(i, argc, argv);
        ns=atoi(argv[i]);
      } else if(arg=="-seed") {
        CoreApplication::checkOptionArg(i, argc, argv);
        seed=atoi(argv[i]);
      } else if(arg=="-o") {
        CoreApplication::checkOptionArg(i, argc, argv);
        outputFileName=argv[i];
      } else if(arg=="-f") {
        reportAction=ReportWriter::Overwrite;
      } else if(arg=="-resume") {
        reportAction=ReportWriter::Append;
      } else if(arg=="dof") {
        CoreApplication::checkOptionArg(i, argc, argv);
        PdfPoint::setDegreesOfFreedom(atof(argv[i]));
      }
    } else {
      argv[j++]=argv[i];
    }
  }
  if(paramFile.isEmpty()) {
    App::stream() << tr("dinver: missing parameters, option '-param'") << endl;
    return 2;
  }
  BatchRun r;
  if(!r.setParameters(paramFile)) {
    App::stream() << tr("dinver: error reading parameters from file %1").arg(paramFile) << endl;
    return 2;
  }
  if(!r.importanceSampling(ns, seed, baseFileName, outputFileName, reportAction)) {
    return 2;
  }
  return 0;
}
int modeNeighborhoodOptimization ( int  argc,
char **  argv 
)

References checkRemainingArguments(), debugStream, DinverCore::dinverCore, QGpCoreTools::endl(), help(), DinverCore::BatchRun::neighborhoodOptimization(), DinverCore::DinverCoreObject::plugin(), DinverCore::DinverCoreObject::pluginFile(), pluginTag, reportAction, DinverCore::DinverInterface::setArguments(), DinverCore::BatchRun::setParameters(), DinverCore::DinverCoreObject::setPlugin(), DinverCore::BatchRun::setTargets(), and QGpCoreTools::tr().

Referenced by main().

{
  CoreApplication a(argc, argv, help);

  if(pluginTag.isEmpty()) {
    App::stream() << tr("dinver: no plugin selected (option -i)") << endl;
    return 2;
  }

  App::setStream(new StandardStream(stdout));
  DinverCoreObject dinverCore;
  QString pluginFile=dinverCore.pluginFile(pluginTag, debugStream);
  if(!dinverCore.setPlugin(pluginFile, debugStream)) {
    App::stream() << tr("dinver: cannot set plugin with tag %1").arg(pluginTag) << endl;
    return 2;
  }

  // Options
  QString paramFile;
  QString targetFile;
  int expectedBestModelCount=RAND_MAX;
  double maximumSavedMisfit=1e99;
  int ns0=50;
  int ns=2500;
  int nr=50;
  ReportWriter::Action reportAction=ReportWriter::Ask;
  QString outputFileName="run.report";
  // Check arguments
  int j=1;
  for(int i=1; i<argc; i++) {
    QByteArray arg=argv[i];
    if(arg[0]=='-') {
      if(arg=="-param") {
        Application::checkOptionArg(i, argc, argv);
        paramFile=argv[i];
      } else if(arg=="-target") {
        Application::checkOptionArg(i, argc, argv);
        targetFile=argv[i];
      } else if(arg=="-ns0") {
        CoreApplication::checkOptionArg(i, argc, argv);
        ns0=atoi(argv[i]);
      } else if(arg=="-ns") {
        CoreApplication::checkOptionArg(i, argc, argv);
        ns=atoi(argv[i]);
      } else if(arg=="-nr") {
        CoreApplication::checkOptionArg(i, argc, argv);
        nr=atoi(argv[i]);
      } else if(arg=="-max-nr") {
        CoreApplication::checkOptionArg(i, argc, argv);
        expectedBestModelCount=atoi(argv[i]);
      } else if(arg=="-max-misfit") {
        CoreApplication::checkOptionArg(i, argc, argv);
        maximumSavedMisfit=atof(argv[i])*(1.0+1e-15);
      } else if(arg=="-o") {
        CoreApplication::checkOptionArg(i, argc, argv);
        outputFileName=argv[i];
      } else if(arg=="-f") {
        reportAction=ReportWriter::Overwrite;
      } else if(arg=="-resume") {
        reportAction=ReportWriter::Append;
      } else {
        argv[j++]=argv[i];
      }
    } else {
      argv[j++]=argv[i];
    }
  }
  argc=j;
  if(!dinverCore.plugin()->setArguments(argc, argv) ||
     !checkRemainingArguments(argc, argv)) {
    return 2;
  }
  BatchRun r;
  if(!paramFile.isEmpty()) {
    if(!r.setParameters(paramFile)) {
      App::stream() << tr("dinver: error reading parameters from file %1").arg(paramFile) << endl;
      return 2;
    }
  }
  if(!targetFile.isEmpty()) {
    if(!r.setTargets(targetFile)) {
      App::stream() << tr("dinver: error reading targets from file %1").arg(targetFile) << endl;
      return 2;
    }
  }
  if(!r.neighborhoodOptimization(ns0, ns, nr, expectedBestModelCount, maximumSavedMisfit,
                                  outputFileName, reportAction)) {
    return 2;
  }
  return 0;
}
int modeSnoopOptimization ( int  argc,
char **  argv 
)

References debugStream, DinverCore::dinverCore, QGpCoreTools::endl(), help(), DinverCore::DinverCoreObject::pluginFile(), pluginTag, reportAction, DinverCore::BatchRun::setParameters(), DinverCore::DinverCoreObject::setPlugin(), DinverCore::BatchRun::setTargets(), DinverCore::BatchRun::snoopOptimization(), and QGpCoreTools::tr().

Referenced by main().

{
  CoreApplication a(argc, argv, help);

  if(pluginTag.isEmpty()) {
    App::stream() << tr("dinver: no plugin selected (option -i)") << endl;
    return 2;
  }

  DinverCoreObject dinverCore;
  QString pluginFile=dinverCore.pluginFile(pluginTag, debugStream);
  if(!dinverCore.setPlugin(pluginFile, debugStream)) {
    App::stream() << tr("dinver: cannot set plugin with tag %1").arg(pluginTag) << endl;
    return 2;
  }

  // Options
  QString paramFile;
  QString targetFile;
  int seed=0;
  ReportWriter::Action reportAction=ReportWriter::Ask;
  QString outputFileName="run.report";
  // Check arguments
  int j=1;
  for(int i=1; i<argc; i++) {
    QByteArray arg=argv[i];
    if(arg[0]=='-') {
      if(arg=="-param") {
        Application::checkOptionArg(i, argc, argv);
        paramFile=argv[i];
      } else if(arg=="-target") {
        Application::checkOptionArg(i, argc, argv);
        targetFile=argv[i];
      } else if(arg=="-seed") {
        CoreApplication::checkOptionArg(i, argc, argv);
        seed=atoi(argv[i]);
      } else if(arg=="-o") {
        CoreApplication::checkOptionArg(i, argc, argv);
        outputFileName=argv[i];
      } else if(arg=="-f") {
        reportAction=ReportWriter::Overwrite;
      } else if(arg=="-resume") {
        reportAction=ReportWriter::Append;
      }
    } else {
      argv[j++]=argv[i];
    }
  }
  if(paramFile.isEmpty()) {
    App::stream() << tr("dinver: missing parameters, option '-param'") << endl;
    return 2;
  }
  if(targetFile.isEmpty()) {
    App::stream() << tr("dinver: missing targets, option '-target'") << endl;
    return 2;
  }
  BatchRun r;
  if(!r.setParameters(paramFile)) {
    App::stream() << tr("dinver: error reading parameters from file %1").arg(paramFile) << endl;
    return 2;
  }
  if(!r.setTargets(targetFile)) {
    App::stream() << tr("dinver: error reading targets from file %1").arg(targetFile) << endl;
    return 2;
  }
  if(!r.snoopOptimization(seed, outputFileName, reportAction)) {
    return 2;
  }
  return 0;
}
PACKAGE_INFO ( dinver  ,
DINVER   
)

Variable Documentation

bool debugStream = false
QString pluginTag
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines