Public Member Functions | Protected Member Functions
ShReader Class Reference

Brief description of class still missing. More...

#include <ShReader.h>

Inheritance diagram for ShReader:
QGpCoreTools::ArgumentStdinReader

List of all members.

Public Member Functions

bool setOptions (int &argc, char **argv)
 ShReader ()

Protected Member Functions

virtual bool parse (QTextStream &s)

Detailed Description

Brief description of class still missing.

Full description of class still missing


Constructor & Destructor Documentation

Description of constructor still missing

References QGpCoreTools::LogScale, and TRACE.

    : ArgumentStdinReader()
{
  TRACE;
  _nSamples=100;
  _samplingType=LogScale;
  _nSamples=100;
  _minRange=0.2;
  _maxRange=20.0;
  _qp=0.0;
  _qs=0.0;
}

Member Function Documentation

bool ShReader::parse ( QTextStream &  s) [protected, virtual]

Implements QGpCoreTools::ArgumentStdinReader.

References QGpCoreTools::Curve< pointType >::append(), QGpCoreTools::Curve< pointType >::cut(), QGpCoreTools::endl(), QGpCoreWave::Seismic1DModel::fromStream(), QGpCoreTools::Function, QGpCoreWave::Seismic1DModel::h(), QGpCoreWave::Seismic1DModel::layerCount(), psv1d_(), QGpCoreWave::Seismic1DModel::qp(), QGpCoreWave::Seismic1DModel::qs(), QGpCoreTools::Curve< pointType >::resample(), QGpCoreWave::Seismic1DModel::rho(), QGpCoreWave::Seismic1DModel::slowP(), QGpCoreWave::Seismic1DModel::slowS(), sOut(), QGpCoreTools::Curve< pointType >::toString(), QGpCoreTools::tr(), and TRACE.

{
  TRACE;
  QTextStream sOut(stdout);
  Seismic1DModel m;
  QString comments;
  if(!m.fromStream(s, &comments)) {
    return false;
  }
  if(m.layerCount()>0) {
    int nf=_nRawSamples;
    float fmax=_maxRange;
    int ln=m.layerCount();
    int nTransferFonction=2*nf+1;
    float * thickness=new float[ln];
    float * alpha0=new float[ln];
    float * beta0=new float[ln];
    float * dens=new float[ln];
    float * qp=new float[ln];
    float * qs=new float[ln];
    float * transferFonction=new float[nTransferFonction];
    for(int i=0;i<ln; i++) {
      thickness[i]=i<ln-1 ? m.h(i) : 0;
      alpha0[i]=1.0/m.slowP(i);
      beta0[i]=1.0/m.slowS(i);
      dens[i]=m.rho(i);
      if(_qp>0.0) {
        qp[i]=_qp;
      } else {
        qp[i]=m.qp(i);
        if(qp[i]<=0) {
          App::stream() << tr("gpsh: negative or null value for Qp at layer %1").arg(i) << endl;
          delete [] thickness;
          delete [] alpha0;
          delete [] beta0;
          delete [] dens;
          delete [] qp;
          delete [] qs;
          delete [] transferFonction;
          return false;
        }
      }
      if(_qs>0.0) {
        qs[i]=_qs;
      } else {
        qs[i]=m.qs(i);
        if(qs[i]<=0) {
          App::stream() << tr("gpsh: negative or null value for Qs at layer %1").arg(i) << endl;
          delete [] thickness;
          delete [] alpha0;
          delete [] beta0;
          delete [] dens;
          delete [] qp;
          delete [] qs;
          delete [] transferFonction;
          return false;
        }
      }
    }
    psv1d_(&nf, &fmax, &ln, thickness, alpha0, beta0, dens, qp, qs, transferFonction, &nTransferFonction);
    Curve<Point2D> c;
    double df=(double)fmax/(nTransferFonction-1);
    for(int i=0;i<nTransferFonction;i++) {
      c.append(Point2D(df*i, 0.5*transferFonction[i]));
    }
    c.resample(_x, Function);
    c.cut(_x[0], _x[_x.count()-1], Function);
    sOut << "# SH transfer function\n"
         << comments
         << c.toString();
    delete [] thickness;
    delete [] alpha0;
    delete [] beta0;
    delete [] dens;
    delete [] qp;
    delete [] qs;
    delete [] transferFonction;
  }
  return true;
}
bool ShReader::setOptions ( int &  argc,
char **  argv 
)

References QGpCoreTools::endl(), QGpCoreTools::Function, QGpCoreTools::InversedScale, QGpCoreTools::Curve< pointType >::line(), QGpCoreTools::LinearScale, QGpCoreTools::LogScale, QGpCoreTools::Curve< pointType >::resample(), QGpCoreTools::tr(), TRACE, and QGpCoreTools::Curve< pointType >::xVector().

Referenced by main().

{
  TRACE;
  // Check arguments
  int i, j=1;
  for(i=1; i<argc; i++) {
    QByteArray arg=argv[i];
    if(arg[0]=='-') {
      if(arg=="-s") {
        CoreApplication::checkOptionArg(i, argc, argv);
        if(strcmp(argv[i],"period")==0) {
          _samplingType=InversedScale;
        } else if(strcmp(argv[i],"frequency")==0) {
          _samplingType=LinearScale;
        } else {
          _samplingType=LogScale;
        }
      } else if(arg=="-min") {
        CoreApplication::checkOptionArg(i, argc, argv);
        _minRange=atof(argv[i]);
        if(_minRange<=0) {
          App::stream() << tr("gpsh: negative or null value for -min") << endl;
          return false;
        }
      } else if(arg=="-max") {
        CoreApplication::checkOptionArg(i, argc, argv);
        _maxRange=atof(argv[i]);
        if(_maxRange<=0) {
          App::stream() << tr("gpsh: negative or null value for -max") << endl;
          return false;
        }
      } else if(arg=="-qp") {
        CoreApplication::checkOptionArg(i, argc, argv);
        _qp=atoi(argv[i]);
        if(_qp<0) {
          App::stream() << tr("gpsh: negative Qp (option -qp)") << endl;
          return false;
        }
      } else if(arg=="-qs") {
        CoreApplication::checkOptionArg(i, argc, argv);
        _qs=atoi(argv[i]);
        if(_qs<0) {
          App::stream() << tr("gpsh: negative Qs (option -qs)") << endl;
          return false;
        }
      } else if(arg=="-n") {
        CoreApplication::checkOptionArg(i, argc, argv);
        _nSamples=atoi(argv[i]);
        if(_nSamples<2) {
          App::stream() << tr("gpsh: number of samples less than 2 (option -n)") << endl;
          return false;
        }
      } else {
        App::stream() << tr("gpsh: bad option %1, see -help").arg(argv[i]) << endl;
        return false;
      }
    } else {
      argv[j++]=argv[i];
    }
  }
  if(j < argc) {
    argv[j]=0;
    argc=j;
  }
  // Compute common sampling scale
  Curve<Point1D> c;
  c.line(_minRange, _maxRange);
  c.resample(_nSamples, _minRange, _maxRange, _samplingType | Function);
  _x=c.xVector();
  // SH is primarily computed on a linear scale. Get the minimum spacing between two samples
  // to adjust the number of samples for the fortran call.
  double minStep;
  switch(_samplingType) {
  case InversedScale:
    minStep=_x[_x.count()-1]-_x[_x.count()-2];
    break;
  default:
    minStep=_x[1]-_x[0];
    break;
  }
  _nRawSamples=(int)ceil(_maxRange/minStep);
  if(_nRawSamples>4096) {
    App::stream() << tr("gpsh: maximum number of samples reached (max=4096, value=%1). Either "
                        "increase minimum frequency, reduce the number of sample or "
                        "switch to 'frequency' scale (option '-s').").arg(_nRawSamples) << endl;
    return false;
  }
  // Round to next power of 2
  int n2=2;
  while(n2<_nRawSamples) n2=n2 << 1;
  _nRawSamples=n2;
  return true;
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines