Functions | Variables
max2curve/main.cpp File Reference
#include <QFileInfo>
#include <QGpCoreTools.h>
#include <SciFigs.h>
#include "max2curveVersion.h"
#include "max2curveInstallPath.h"
#include "HistogramWidget.h"

Functions

void filter (HistogramWidget *w)
ApplicationHelphelp ()
int main (int argc, char **argv)
 PACKAGE_INFO (max2curve, MAX2CURVE)

Variables

SamplingOption scaleType
bool scaleTypeForced = false
double tfaAmpH = -1.0
double tfaAmpZ = -1.0
double tfaDelay = 1e99
double tfaFactor = -1.0
int tfaNppf = -1
double tfaNppm = -1.0
double tmax = 0.0
double tmin = 0.0

Function Documentation

void filter ( HistogramWidget w)

References MaxEntryList::CURVE, MaxEntryList::FK, QGpCoreTools::LinearScale, QGpCoreTools::LogScale, HistogramWidget::maxEntryList(), MaxEntryList::rejectAmplitudeHorizontalAbsolute(), MaxEntryList::rejectAmplitudeVerticalAbsolute(), MaxEntryList::rejectAmplitudeVerticalFactor(), MaxEntryList::rejectDelay(), MaxEntryList::rejectNPeaksPerFrequency(), MaxEntryList::rejectNPeaksPerMinute(), scaleType, scaleTypeForced, MaxEntryList::SPAC, MaxEntryList::TFA, tfaAmpH, tfaAmpZ, tfaDelay, tfaFactor, tfaNppf, tfaNppm, tmax, tmin, TRACE, MaxEntryList::type(), and MaxEntryList::Undefined.

Referenced by QGpGuiTools::HttpProxyList::HttpProxyList(), main(), and GeopsyCore::StationProcessSignals::setHighPassFilter().

{
  TRACE;
  MaxEntryList * entryList=w->maxEntryList();
  // User selection
  switch (entryList->type()) {
  case MaxEntryList::FK:
  case MaxEntryList::SPAC:
  case MaxEntryList::CURVE:
    if(!scaleTypeForced) scaleType=LinearScale;
    break;
  case MaxEntryList::TFA:
    if(tfaDelay!=1e99) entryList->rejectDelay(tfaDelay);
    if(tfaFactor > -1.0) entryList->rejectAmplitudeVerticalFactor(tfaFactor);
    if(tfaAmpZ > -1.0) entryList->rejectAmplitudeVerticalAbsolute(tfaAmpZ);
    if(tfaAmpH > -1.0) entryList->rejectAmplitudeHorizontalAbsolute(tfaAmpH);
    if(tfaNppm > -1.0) entryList->rejectNPeaksPerMinute(tfaNppm);
    if(tfaNppf > -1.0) entryList->rejectNPeaksPerFrequency(tfaNppf);
    if(!scaleTypeForced) scaleType=LogScale;
    break;
  case MaxEntryList::Undefined:
    break;
  }
  if(tmin<tmax) {
    entryList-> rejectTime(tmin,tmax);
  }
}
int main ( int  argc,
char **  argv 
)

References MaxEntryList::count(), MaxEntryList::CURVE, QGpCoreTools::endl(), HistogramWidget::fillGrid(), filter(), MaxEntryList::FK, help(), HistogramWidget::initGrid(), QGpCoreTools::LinearScale, MaxEntryList::load(), QGpCoreTools::LogScale, HistogramWidget::maxEntryList(), mode, MSG_ID, scaleType, scaleTypeForced, HistogramWidget::select(), MaxEntryList::setType(), HistogramWidget::show(), sOut(), MaxEntryList::SPAC, MaxEntryList::TFA, tfaAmpH, tfaAmpZ, tfaDelay, tfaFactor, tfaNppf, tfaNppm, tmax, tmin, MaxEntryList::toStream(), HistogramWidget::toStream(), QGpCoreTools::tr(), and w.

{
  Application a(argc, argv, help);
  SciFigsGlobal s;

  // Options
  QString maxFile;
  QString fileType;
  enum Mode {Gui, Mean, Median, Max};
  Mode mode=Gui;
  double minValue=0.0, maxValue=0.0;
  int nClasses=200;
  // Check arguments
  int i, j=1;
  for(i=1; i<argc; i++) {
    QByteArray arg=argv[i];
    if(arg[0]=='-') {
      if(arg=="-type") {
        CoreApplication::checkOptionArg(i, argc, argv);
        fileType=argv[i];
      } else if(arg=="-min") {
        CoreApplication::checkOptionArg(i, argc, argv);
        minValue=atof(argv[i] );
      } else if(arg=="-max") {
        CoreApplication::checkOptionArg(i, argc, argv);
        maxValue=atof(argv[i] );
      } else if(arg=="-n") {
        CoreApplication::checkOptionArg(i, argc, argv);
        nClasses=atoi(argv[i] );
      } else if(arg=="-mean") {
        mode=Mean;
      } else if(arg=="-median") {
        mode=Median;
      } else if(arg=="-m") {
        mode=Max;
      } else if(arg=="-linear") {
        scaleTypeForced=true;
        scaleType=LinearScale;
      } else if(arg=="-log") {
        scaleTypeForced=true;
        scaleType=LogScale;
      } else if(arg=="-tmin") {
         CoreApplication::checkOptionArg(i, argc, argv);
         tmin=atof(argv[i]);
      } else if(arg=="-tmax") {
         CoreApplication::checkOptionArg(i, argc, argv);
         tmax=atof(argv[i]);
      } else if(arg=="-tfaNppm") {
        CoreApplication::checkOptionArg(i, argc, argv);
        tfaNppm=atof(argv[i] );
      } else if(arg=="-tfaNppf") {
        CoreApplication::checkOptionArg(i, argc, argv);
        tfaNppf=atoi(argv[i] );
      } else if(arg=="-tfaFactor") {
        CoreApplication::checkOptionArg(i, argc, argv);
        tfaFactor=atof(argv[i] );
      } else if(arg=="-tfaAmpZ") {
        CoreApplication::checkOptionArg(i, argc, argv);
        tfaAmpZ=atof(argv[i] );
      } else if(arg=="-tfaAmpH") {
        CoreApplication::checkOptionArg(i, argc, argv);
        tfaAmpH=atof(argv[i] );
      } else if(arg=="-tfaDelay") {
        CoreApplication::checkOptionArg(i, argc, argv);
        tfaDelay=atof(argv[i] );
      } else {
        App::stream() << tr("max2curve: 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(argc>1) {
    maxFile=argv[1];
  }
  // Check options
  switch (mode) {
  case Max:
  case Gui:
    break;
  case Mean:
  case Median:
    if(minValue>=maxValue) {
      App::stream() << tr("Minimum and maximum are equal. These values must be defined by "
                          "options -min and -max, see -help for details.") << endl;
      return 2;
    }
    break;
  }

  if(maxFile.isEmpty()) {
    maxFile=Message::getOpenFileName(tr("Loading max file"),
                                        tr("max file (*.max)"));
    if(maxFile.isEmpty()) return 2;
  }
  MaxEntryList * maxList=new MaxEntryList;
  if(!fileType.isEmpty()) {
    if(fileType=="FK") maxList->setType(MaxEntryList::FK);
    else if(fileType=="SPAC") maxList->setType(MaxEntryList::SPAC);
    else if(fileType=="TFA") maxList->setType(MaxEntryList::TFA);
    else if(fileType=="CURVE") maxList->setType(MaxEntryList::CURVE);
  }
  if(!maxList->load(maxFile)) {
    delete maxList;
    return 2;
  }
  if(maxList->isEmpty()) {
    Message::warning(MSG_ID, tr("Loading max file"),
                         tr("No max result can be loaded"));
    return 2;
  }

  HistogramWidget * w=new HistogramWidget(maxList);
  w->setWindowTitle(QString("max2curve - %2 - %1").arg(maxFile));
  // %2 is reserved for other comments: Type,...

  int appReturn=0;
  if(mode==Gui) {
    filter(w);
    if( !w->select(scaleTypeForced, scaleType) ) {
      delete w;
      return 2;
    }
    fprintf(stderr,"Filtering: remaining %i entries\n",w->maxEntryList()->count());
    w->show();
    appReturn=a.exec();
  } else {
    filter(w);
    w->initGrid(nClasses, minValue, maxValue, scaleType);
    fprintf(stderr,"Filtering: remaining %i entries\n",w->maxEntryList()->count());
    if(w->maxEntryList()->isEmpty()) {
      fprintf(stderr,"No entries, abort\n");
      delete w;
      return 2;
    }
    // User output mode
    QTextStream sOut(stdout);
    switch (mode) {
    case Max:
      w->maxEntryList()->toStream(sOut);
      break;
    case Mean:
      w->fillGrid();
      w->addMeanCurve();
      sOut << QString("# Mean curve from file %1\n").arg(maxFile);
      w->toStream(sOut, 0);
      break;
    case Median:
      w->fillGrid();
      w->addMedianCurve();
      sOut << QString("# Median curve from file %1\n").arg(maxFile);
      w->toStream(sOut, 0);
    case Gui:
      break;
    }
  }
  delete w;
  return appReturn;
}
PACKAGE_INFO ( max2curve  ,
MAX2CURVE   
)

Variable Documentation

bool scaleTypeForced = false

Referenced by filter(), and main().

double tfaAmpH = -1.0

Referenced by filter(), and main().

double tfaAmpZ = -1.0

Referenced by filter(), and main().

double tfaDelay = 1e99

Referenced by filter(), and main().

double tfaFactor = -1.0

Referenced by filter(), and main().

int tfaNppf = -1

Referenced by filter(), and main().

double tfaNppm = -1.0

Referenced by filter(), and main().

double tmax = 0.0
double tmin = 0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines