Functions
gppoisson/main.cpp File Reference
#include <math.h>
#include <QGpCoreTools.h>
#include "gppoissonVersion.h"
#include "gppoissonInstallPath.h"

Functions

ApplicationHelphelp ()
int main (int argc, char **argv)
 PACKAGE_INFO (gppoisson, GPPOISSON)

Function Documentation

int main ( int  argc,
char **  argv 
)

References QGpCoreTools::endl(), help(), mode, QGpCoreTools::LineParser::setString(), sOut(), QGpCoreTools::sqrt(), QGpCoreTools::LineParser::toDouble(), and QGpCoreTools::tr().

{
  CoreApplication a(argc, argv, help);

  // Options
  int mode=0;
  // Check arguments
  int i, j=1;
  for(i=1; i<argc; i++) {
    QByteArray arg=argv[i];
    if(arg[0]=='-') {
      if(arg=="-nu") {
        mode=0;
      } else if(arg=="-vp") {
        mode=1;
      } else if(arg=="-vs") {
        mode=2;
      } else {
        App::stream() << tr("gppoisson: bad option %1, see --help").arg(argv[i]) << endl;
        return 2;
      }
    } else {
      argv[j++]=argv[i];
    }
  }
  if(j < argc) {
    argv[j]=0;
    argc=j;
  }

  QTextStream sOut(stdout);
  LineParser p;
  bool ok=true;
  double vs, vp, nu;
  while(!feof(stdin)) {
    QString l=File::readLine(true);
    if(l=="exit" || l=="quit") break;
    if(!l.isEmpty() && l[0]!='#') {
      p.setString(l);
      switch (mode) {
      case 1:
        vs=p.toDouble(0, ok);
        nu=p.toDouble(1, ok);
        if( !ok) {
          App::stream() << tr("gppoisson: error reading Vs and Nu") << endl;
          return 2;
        }
        sOut << vs*sqrt(2*(nu-1)/(2*nu-1)) << endl;
        break;
      case 2:
        vp=p.toDouble(0, ok);
        nu=p.toDouble(1, ok);
        if( !ok) {
          App::stream() << tr("gppoisson: error reading Vp and Nu") << endl;
          return 2;
        }
        sOut << vp*sqrt(0.5*(2*nu-1)/(nu-1)) << endl;
        break;
      default:
        vp=p.toDouble(0, ok);
        vs=p.toDouble(1, ok);
        vp *= vp;
        vs *= vs;
        if( !ok) {
          App::stream() << tr("gppoisson: error reading Vp and Vs") << endl;
          return 2;
        }
        sOut << (vs-0.5*vp)/(vs-vp) << endl;
        break;
      }
    }
  }
  return 0;
}
PACKAGE_INFO ( gppoisson  ,
GPPOISSON   
)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines