Enumerations | Functions | Variables
gpdcreport/main.cpp File Reference
#include <DinverCore.h>
#include <DinverDCCore.h>
#include <QGpCompatibility.h>
#include <QGpCoreTools.h>
#include <QGpCoreWave.h>
#include "gpdcreportVersion.h"
#include "gpdcreportInstallPath.h"

Enumerations

enum  InputType { NaViewer, BetaRelease, Current }
enum  OutputType {
  Parameters, Count, BestCurve, Checksum,
  GroundModel, TiltGroundModelVp, TiltGroundModelVs, VpProfile,
  VsProfile, RhoProfile, PitchProfile, ResistivityProfile,
  DispersionRayleighPhase, DispersionRayleighGroup, DispersionLovePhase, DispersionLoveGroup,
  Ellipticity, AutocorrVertical, AutocorrRadial, AutocorrTransverse,
  Report, RefractionVp, RefractionVs
}

Functions

int cleanReturn (int value)
ApplicationHelphelp ()
int main (int argc, char **argv)
void outputDCModel (QDataStream &s, int iReportModel, double misfit, ReportReader *report)
void outputModel (QDataStream &s, int iReportModel, double misfit, ReportReader *report)
void outputModel (double misfit, CompatInversionReport *report)
 PACKAGE_INFO (gpdcreport, GPDCREPORT)
QTextStream sOut (stdout)

Variables

double currentBestMisfit = 1e99
int iModel = 0
InputType inputType = Current
int modeIndex = 0
QList< DCModelInfo * > models
ReportWriteroutputReport = 0
OutputType outputType = GroundModel
QList< ReportReader * > reports
QList< int > ringIndexes
int sourceIndex = 0

Enumeration Type Documentation

enum InputType
Enumerator:
NaViewer 
BetaRelease 
Current 
enum OutputType
Enumerator:
Parameters 
Count 
BestCurve 
Checksum 
GroundModel 
TiltGroundModelVp 
TiltGroundModelVs 
VpProfile 
VsProfile 
RhoProfile 
PitchProfile 
ResistivityProfile 
DispersionRayleighPhase 
DispersionRayleighGroup 
DispersionLovePhase 
DispersionLoveGroup 
Ellipticity 
AutocorrVertical 
AutocorrRadial 
AutocorrTransverse 
Report 
RefractionVp 
RefractionVs 

Function Documentation

int cleanReturn ( int  value)

References models, outputReport, and reports.

Referenced by main().

{
  foreach(DCModelInfo * model, models) ReportReader::removeReference(model);
  foreach(ReportReader * report, reports) ReportReader::removeReference(report);
  delete outputReport;
  return value;
}
int main ( int  argc,
char **  argv 
)

References QGpCoreTools::SharedObject::addReference(), AutocorrRadial, AutocorrTransverse, AutocorrVertical, BestCurve, BetaRelease, Checksum, cleanReturn(), Count, QGpCompatibility::CompatInversionReport::countModels(), Current, QGpCompatibility::CompatInversionReport::currentCost(), DispersionLoveGroup, DispersionLovePhase, DispersionRayleighGroup, DispersionRayleighPhase, Ellipticity, QGpCoreTools::endl(), GroundModel, help(), iModel, DinverDCCore::DCModelInfo::indexInReport(), inputType, QGpCompatibility::CompatInversionReport::isValid(), QGpCompatibility::CompatInversionReport::loadDispersion(), QGpCompatibility::CompatInversionReport::loadModel(), misfit(), DinverCore::ReportReader::misfit(), DinverDCCore::DCModelInfo::misfit(), modeIndex, models, NaViewer, DinverCore::ReportWriter::open(), outputModel(), outputType, Parameters, PitchProfile, RefractionVp, RefractionVs, Report, DinverDCCore::DCModelInfo::report(), reports, ResistivityProfile, RhoProfile, ringIndexes, DinverDCCore::DCModelInfo::setIndexInReport(), DinverDCCore::DCModelInfo::setMisfit(), DinverDCCore::DCModelInfo::setReport(), sourceIndex, sOut(), DinverCore::ReportReader::stream(), TiltGroundModelVp, TiltGroundModelVs, QGpCoreTools::tr(), VpProfile, and VsProfile.

{
  CoreApplication a(argc, argv, help);

  // Options
  int nModels=RAND_MAX;
  int bestModelCount=0;
  bool readIndexes=false;
  double maxMisfit=1e99;      // Maximum misfit selected by user
  // Check arguments
  int i, j=1;
  for(i=1; i<argc; i++) {
    QByteArray arg=argv[i];
    if(arg[0]=='-') {
      if(arg=="-n") {
        CoreApplication::checkOptionArg(i, argc, argv);
        nModels=atoi(argv[i]);
      } else if(arg=="-m") {
        CoreApplication::checkOptionArg(i, argc, argv);
        maxMisfit=atof(argv[i])*(1.0+1e-15);
      } else if(arg=="-best") {
        CoreApplication::checkOptionArg(i, argc, argv);
        bestModelCount=atoi(argv[i] );
      } else if(arg=="-best-curve") {
        outputType=BestCurve;
      } else if(arg=="-index") {
        readIndexes=true;
      } else if(arg=="-compat") {
        CoreApplication::checkOptionArg(i, argc, argv);
        if(strcmp(argv[i],"na_viewer")==0) {
          inputType=NaViewer;
        } else if(strcmp(argv[i],"beta")==0) {
          inputType=BetaRelease;
        } else if(strcmp(argv[i],"current")==0) {
          inputType=Current;
        } else {
          App::stream() << tr("gpdcreport: bad compatibility type, see -h.") << endl;
          return cleanReturn(2);
        }
         // else do nothing for compatibility, read current .report format
      } else if(arg=="-o" || arg=="-report") {  // Kept for compatibility
        if(outputReport) {
          App::stream() << tr("gpdcreport: only one option '-o' is accepted.") << endl;
          return cleanReturn(2);
        }
        CoreApplication::checkOptionArg(i, argc, argv);
        QFileInfo fi(argv[i]);
        if(fi.exists()) {
          App::stream() << tr("gpdcreport: report %1 already exists (option -o), remove it before.").arg(argv[i]) << endl;
          return cleanReturn(2);
        }
        outputReport=new ReportWriter(fi.fileName());
        if(!outputReport->open()) {
          App::stream() << tr("gpdcreport: cannot open file %1 for writing.").arg(argv[i]) << endl;
          return cleanReturn(2);
        }
        outputType=Report;
      } else if(arg=="-pm") {
        outputType=Parameters;
      } else if(arg=="-count") {
        outputType=Count;
      } else if(arg=="-checksum") {
        outputType=Checksum;
      } else if(arg=="-gm") {
        outputType=GroundModel;
      } else if(arg=="-tgmVp") {
        outputType=TiltGroundModelVp;
      } else if(arg=="-tgmVs") {
        outputType=TiltGroundModelVs;
      } else if(arg=="-vp") {
        outputType=VpProfile;
      } else if(arg=="-vs") {
        outputType=VsProfile;
      } else if(arg=="-rho") {
        outputType=RhoProfile;
      } else if(arg=="-pitch") {
        outputType=PitchProfile;
      } else if(arg=="-res") {
        outputType=ResistivityProfile;
      } else if(arg=="-pR") {
        outputType=DispersionRayleighPhase;
        CoreApplication::checkOptionArg(i, argc, argv);
        modeIndex=atoi(argv[i]);
      } else if(arg=="-gR") {
        outputType=DispersionRayleighGroup;
        CoreApplication::checkOptionArg(i, argc, argv);
        modeIndex=atoi(argv[i]);
      } else if(arg=="-pL") {
        outputType=DispersionLovePhase;
        CoreApplication::checkOptionArg(i, argc, argv);
        modeIndex=atoi(argv[i]);
      } else if(arg=="-gL") {
        outputType=DispersionLoveGroup;
        CoreApplication::checkOptionArg(i, argc, argv);
        modeIndex=atoi(argv[i]);
      } else if(arg=="-e") {
        outputType=::Ellipticity;
        CoreApplication::checkOptionArg(i, argc, argv);
        modeIndex=atoi(argv[i]);
      } else if(arg=="-aV") {
        outputType=AutocorrVertical;
        CoreApplication::checkOptionArg(i, argc, argv);
        modeIndex=atoi(argv[i]);
      } else if(arg=="-aR") {
        outputType=AutocorrRadial;
        CoreApplication::checkOptionArg(i, argc, argv);
        modeIndex=atoi(argv[i]);
      } else if(arg=="-aT") {
        outputType=AutocorrTransverse;
        CoreApplication::checkOptionArg(i, argc, argv);
        modeIndex=atoi(argv[i]);
      } else if(arg=="-ring") {
        CoreApplication::checkOptionArg(i, argc, argv);
        ringIndexes.append(atoi(argv[i]));
      } else if(arg=="-refraVp") {
        outputType=RefractionVp;
        CoreApplication::checkOptionArg(i, argc, argv);
        sourceIndex=atoi(argv[i]);
      } else if(arg=="-refraVs") {
        outputType=RefractionVs;
        CoreApplication::checkOptionArg(i, argc, argv);
        sourceIndex=atoi(argv[i]);
      } else {
        App::stream() << tr("gpdcreport: bad option %1, see --help").arg(argv[i]) << endl;
        return cleanReturn(2);
      }
    } else {
      argv[j++]=argv[i];
    }
  }
  if(j < argc) {
    argv[j]=0;
    argc=j;
  }
  if(bestModelCount>0) {
    if(inputType==NaViewer) {
      App::stream() << tr("gpdcreport: option '-best' is not supported for old .report formats\n"
                                 "            First convert it to current .report format (option '-report')") << endl;
      return cleanReturn(2);
    }
    if(readIndexes) {
      App::stream() << tr("gpdcreport: option '-best' is not compatible with option '-index'.") << endl;
      return cleanReturn(2);
    }
  }
  // Initialize list of indexes, if requested
  QList<int> indexes;
  if(readIndexes) {
    while(!feof(stdin)) {
      QString l=File::readLine(true);
      if(l[0]!='#' && !l.isEmpty()) {
        bool ok;
        int i=l.toInt(&ok);
        if(ok) {
          indexes << i;
        } else {
          App::stream() << tr("Bad model index %1").arg(l) << endl;
        }
      }
    }
  }
  i=1;
  if(inputType==NaViewer) {
    while(i<argc) {
      CompatInversionReport * report=CompatReportFactory::open(argv[i]);
      if(!report->isValid()) {
        delete report;
        App::stream() << tr("gpdcreport: cannot open file %1 for reading.").arg(argv[i]) << endl;
        return cleanReturn(2);
      }
      int nReportModels=report->countModels();
      sOut << "# "  << nReportModels << " " << argv[i] << endl;
      if(outputType==Count) {
        i++;
        continue;
      }
      if(indexes.isEmpty()) {
        for(int iReportModel=0 ; iReportModel<nReportModels; iReportModel++) {
          report->loadDispersion(iReportModel);
          double misfit=report->currentCost();
          if(misfit<=maxMisfit) {
            outputModel(misfit, report);
          }
          if(iModel>=nModels) {
            return cleanReturn(0);
          }
        }
      } else {
        for(QList<int>::iterator it=indexes.begin(); it!=indexes.end(); it++ ) {
          report->loadModel(*it);
          outputModel(report->currentCost(), report);
        }
      }
      delete report;
      i++;
    }
  } else {
    while(i<argc) {
      ReportReader * report=new ReportReader(argv[i]);
      report->addReference();
      reports << report;
      if(!report->open()) {
        App::stream() << tr("gpdcreport: cannot open file %1 for reading.").arg(argv[i]) << endl;
        return cleanReturn(2);
      }
      report->synchronize();
      int nReportModels=report->nModels();
      sOut << "# "  << nReportModels << " " << argv[i] << endl;
      if(outputType==Count) {
        i++;
        continue;
      }
      QDataStream& s=report->stream();
      if(indexes.isEmpty()) {
        for(int iReportModel=0 ; iReportModel<nReportModels; iReportModel++) {
          double misfit=report->misfit(iReportModel);
          if(bestModelCount > 0) {
            if(misfit<=maxMisfit) {
              DCModelInfo * info=new DCModelInfo;
              info->setReport(report);
              info->setIndexInReport(iReportModel);
              info->setMisfit(misfit);
              info->addReference();
              models << info;
            }
          } else {
            if(misfit<=maxMisfit) {
              outputModel(s, iReportModel, misfit, report);
            }
            if(iModel>=nModels) {
              return cleanReturn(0);
            }
          }
        }
      } else {
        for(QList<int>::iterator it=indexes.begin(); it!=indexes.end(); it++ ) {
          outputModel(s, *it, report->misfit(*it), report);
        }
      }
      i++;
    }
    if(bestModelCount>0) {
      qSort(models.begin(), models.end(), DCModelInfo::misfitLessThan);
      int iStop=models.count() - bestModelCount;
      if(iStop<0) iStop=0;
      for(int i=models.count()-1; i>=iStop; i-- ) {
        DCModelInfo * info=models.at(i);
        ReportReader * report=info->report();
        QDataStream& s=report->stream();
        report->misfit(info->indexInReport());
        outputModel(s, info->indexInReport( ), info->misfit(), report);
      }
    }
  }
  return cleanReturn(0);
}
void outputDCModel ( QDataStream &  s,
int  iReportModel,
double  misfit,
ReportReader report 
)

References DinverDCCore::DCReportBlock::autocorr(), AutocorrRadial, AutocorrTransverse, AutocorrVertical, BetaRelease, Current, QGpCoreWave::Profile::depths(), DinverDCCore::DCReportBlock::dispersion(), DispersionLoveGroup, DispersionLovePhase, DispersionRayleighGroup, DispersionRayleighPhase, Ellipticity, DinverDCCore::DCReportBlock::ellipticity(), QGpCoreTools::endl(), GroundModel, iModel, inputType, QGpCoreWave::Seismic1DModel::layerCount(), DinverDCCore::DCReportBlock::modalStorage(), modeIndex, NaViewer, outputType, DinverDCCore::DCReportBlock::pitch(), PitchProfile, DinverDCCore::DCReportBlock::readModalStorages(), DinverDCCore::DCReportBlock::readProfiles(), QGpCoreWave::Profile::readReport(), QGpCoreWave::RefractionFactory::readReport(), DinverDCCore::DCReportBlock::readSeismicModel(), RefractionVp, DinverDCCore::DCReportBlock::refractionVp(), RefractionVs, DinverDCCore::DCReportBlock::refractionVs(), DinverDCCore::DCReportBlock::res(), QGpCoreWave::Profile::resample(), ResistivityProfile, DinverDCCore::DCReportBlock::rho(), RhoProfile, ringIndexes, DinverDCCore::ModalStorageReader::seek(), DinverDCCore::ModalStorageReader::setBetaReleaseOffsets(), QGpCoreWave::RefractionDippingModel::setXLeft(), QGpCoreWave::RefractionFactory::sourceCount(), sourceIndex, QGpCoreWave::RefractionFactory::sources(), sOut(), DinverDCCore::DCReportBlock::stream(), TiltGroundModelVp, TiltGroundModelVs, DinverDCCore::ModalStorageReader::toStream(), QGpCoreWave::Profile::toStream(), QGpCoreWave::RefractionFactory::toStream(), QGpCoreWave::Seismic1DModel::toStream(), QGpCoreTools::unique(), DinverCore::ReportReader::userBlockVersion(), QGpCoreWave::Profile::values(), DinverDCCore::DCReportBlock::vp(), VpProfile, DinverDCCore::DCReportBlock::vs(), VsProfile, QGpCoreWave::RefractionFactory::xLeft(), and QGpCoreWave::RefractionFactory::xRight().

Referenced by outputModel().

{
  int reportDCVersion=report->userBlockVersion("DISP");
  if(reportDCVersion>=0) {
    DCReportBlock dcBlock(s);
    dcBlock.readProfiles(reportDCVersion);
    switch (outputType) {
    case VpProfile:
      if(dcBlock.vp()) {
        Profile p;
        p.readReport(s);
        sOut << QString("# Vp profile %1: value=%2").arg(iReportModel).arg(misfit) << endl;
        p.toStream(sOut, true);
        iModel++;
      }
      break;
    case VsProfile:
      if(dcBlock.vs()) {
        Profile p;
        p.readReport(s);
        sOut << QString("# Vs profile %1: value=%2").arg(iReportModel).arg(misfit) << endl;
        p.toStream(sOut, true);
        iModel++;
      }
      break;
    case RhoProfile:
      if(dcBlock.rho()) {
        Profile p;
        p.readReport(s);
        sOut << QString("# Rho profile %1: value=%2").arg(iReportModel).arg(misfit) << endl;
        p.toStream(sOut, true);
        iModel++;
      }
      break;
    case PitchProfile:
      if(dcBlock.pitch()) {
        Profile p;
        p.readReport(s);
        sOut << QString("# Pitch profile %1: value=%2").arg(iReportModel).arg(misfit) << endl;
        p.toStream(sOut, true);
        iModel++;
      }
      break;
    case ResistivityProfile:
      if(dcBlock.res()) {
        Profile p;
        p.readReport(s);
        sOut << QString("# Resistivity profile %1: value=%2").arg(iReportModel).arg(misfit) << endl;
        p.toStream(sOut, true);
        iModel++;
      }
      break;
    case GroundModel: {
        Seismic1DModel * m=dcBlock.readSeismicModel();
        if(!m) return;
        sOut << QString("# Layered model %1: value=%2").arg(iReportModel).arg(misfit) << endl;
        m->toStream(sOut);
        delete m;
        iModel++;
      }
      break;
     case TiltGroundModelVp: {
        Profile vp,pitch;
        if(dcBlock.vp()) vp.readReport(s); else return;
        if(dcBlock.pitch()) pitch.readReport(s); else return;
        RefractionFactory f;
        if(dcBlock.refractionVp()) f.readReport(dcBlock.stream()); else return;
        QVector<double> depths;
        depths << vp.depths();
        depths << pitch.depths();
        qSort(depths);
        unique(depths);
        vp.resample(depths);
        pitch.resample(depths);
        Seismic1DModel * m;
        m=DCReportBlock::vpModel(depths ,vp.values());
        RefractionDippingModel tm(m->layerCount());
        tm.setXLeft(f.xLeft());
        tm.setXRight(f.xRight());
        tm.fromSeismic1DModel( *m, pitch.values(), Seismic1DModel::P);
        sOut << QString("# Vp Tilt Layered model %1: value=%2").arg(iReportModel).arg(misfit) << endl;
        tm.toStream(sOut);
        delete m;
        iModel++;
      }
      break;
     case TiltGroundModelVs: {
        Profile vs,pitch;
        if(dcBlock.vs()) vs.readReport(s); else return;
        if(dcBlock.pitch()) pitch.readReport(s); else return;
        RefractionFactory f;
        if(dcBlock.refractionVs()) f.readReport(dcBlock.stream()); else return;
        QVector<double> depths;
        depths << vs.depths();
        depths << pitch.depths();
        qSort(depths);
        unique(depths);
        vs.resample(depths);
        pitch.resample(depths);
        Seismic1DModel * m;
        m=DCReportBlock::vsModel(depths ,vs.values());
        RefractionDippingModel tm(m->layerCount());
        tm.setXLeft(f.xLeft());
        tm.setXRight(f.xRight());
        tm.fromSeismic1DModel( *m, pitch.values(), Seismic1DModel::S);
        sOut << QString("# Vs Tilt Layered model %1: value=%2").arg(iReportModel).arg(misfit) << endl;
        tm.toStream(sOut);
        delete m;
        iModel++;
      }
      break;
   case DispersionRayleighPhase:
      if(dcBlock.dispersion()) {
        switch(inputType) {
        case BetaRelease: { /* Nothing else than phase Love and phase Rayleigh were available at that time
                               Rayleigh and Love was indicated by nRayleighModes */
            ModalStorageReader m(s); // Read number of modes
            m.setBetaReleaseOffsets(s, true); // Read number of Rayleigh modes
            if(m.seek(s, modeIndex)) {
              QTextStream sOut(stdout);
              sOut << QString("# Rayleigh Phase dispersion curve (mode=%1) %2: value=%3")
                             .arg(modeIndex).arg(iReportModel).arg(misfit) << endl;
              m.toStream(s, sOut);
              iModel++;
            }
          }
          break;
        case Current:
          dcBlock.readModalStorages(4);
          if(dcBlock.modalStorage(0)) {
            ModalStorageReader m(s);
            if(m.seek(s, modeIndex)) {
              sOut << QString("# Rayleigh Phase dispersion curve (mode=%1) %2: value=%3")
                             .arg(modeIndex).arg(iReportModel).arg(misfit) << endl;
              m.toStream(s, sOut);
              iModel++;
            }
          }
          break;
        case NaViewer: // Not possible here
          break;
        }
      }
      break;
    case DispersionRayleighGroup:
      if(dcBlock.dispersion()) {
        switch(inputType) {
        case Current:
          dcBlock.readModalStorages(4);
          if(dcBlock.modalStorage(1)) {
            ModalStorageReader m(s);
            if(m.seek(s, modeIndex)) {
              sOut << QString("# Rayleigh Group dispersion curve (mode=%1) %2: value=%3")
                             .arg(modeIndex).arg(iReportModel).arg(misfit) << endl;
              m.toStream(s, sOut);
              iModel++;
            }
          }
          break;
        case BetaRelease: // Not possible here
        case NaViewer: // Not possible here
          break;
        }
      }
      break;
    case DispersionLovePhase:
      if(dcBlock.dispersion()) {
        switch(inputType) {
        case BetaRelease: { /* Nothing else than phase Love and phase Rayleigh were available at that time
                               Rayleigh and Love was indicated by nRayleighModes */
            ModalStorageReader m(s); // Read number of modes
            m.setBetaReleaseOffsets(s, false); // Read number of Rayleigh modes
            if(m.seek(s, modeIndex)) {
              sOut << QString("# Love Phase dispersion curve (mode=%1) %2: value=%3")
                             .arg(modeIndex).arg(iReportModel).arg(misfit) << endl;
              m.toStream(s, sOut);
              iModel++;
            }
          }
          break;
        case Current:
          dcBlock.readModalStorages(4);
          if(dcBlock.modalStorage(2)) {
            ModalStorageReader m(s);
            if(m.seek(s, modeIndex)) {
              sOut << QString("# Love Phase dispersion curve (mode=%1) %2: value=%3")
                             .arg(modeIndex).arg(iReportModel).arg(misfit) << endl;
              m.toStream(s, sOut);
              iModel++;
            }
          }
          break;
        case NaViewer: // Not possible here
          break;
        }
      }
      break;
    case DispersionLoveGroup:
      if(dcBlock.dispersion()) {
        switch(inputType) {
        case Current:
          dcBlock.readModalStorages(4);
          if(dcBlock.modalStorage(3)) {
            ModalStorageReader m(s);
            if(m.seek(s, modeIndex)) {
              sOut << QString("# Love Group dispersion curve (mode=%1) %2: value=%3")
                             .arg(modeIndex).arg(iReportModel).arg(misfit) << endl;
              m.toStream(s, sOut);
              iModel++;
            }
          }
        case BetaRelease: // Not possible here
        case NaViewer: // Not possible here
          break;
        }
      }
      break;
    case ::Ellipticity:
      if(dcBlock.ellipticity()) {
        dcBlock.readModalStorages(1);
        if(dcBlock.modalStorage(0)) {
          ModalStorageReader m(s);
          if(m.seek(s, modeIndex)) {
            sOut << QString("# Ellipticity curve (mode=%1) %2: value=%3")
                            .arg(modeIndex).arg(iReportModel).arg(misfit) << endl;
            m.toStream(s, sOut);
            iModel++;
          }
        }
      }
      break;
    case AutocorrVertical:
      if(dcBlock.autocorr()) {
        int nRings;
        s >> nRings;
        dcBlock.readModalStorages(nRings*3);
        for(QList<int>::iterator it=ringIndexes.begin();it!=ringIndexes.end();it++) {
          if(*it<nRings) {
            if(dcBlock.modalStorage(*it*3)) {
              ModalStorageReader m(s);
              if(m.seek(s,modeIndex)) {
                sOut << QString("# Vertical autocorrelation curve (ring=%1,mode=%2) %3: value=%4")
                                .arg(*it).arg(modeIndex).arg(iReportModel).arg(misfit) << endl;
                m.toStream(s, sOut);
                iModel++;
              }
            }
          }
        }
      }
      break;
    case AutocorrRadial:
      if(dcBlock.autocorr()) {
        int nRings;
        s >> nRings;
        dcBlock.readModalStorages(nRings*3);
        for(QList<int>::iterator it=ringIndexes.begin();it!=ringIndexes.end();it++) {
          if(*it<nRings) {
            if(dcBlock.modalStorage(*it*3+1)) {
              ModalStorageReader m(s);
              if(m.seek(s,modeIndex)) {
                sOut << QString("# Radial autocorrelation curve (ring=%1,mode=%2) %3: value=%4")
                                .arg(*it).arg(modeIndex).arg(iReportModel).arg(misfit) << endl;
                m.toStream(s, sOut);
                iModel++;
              }
            }
          }
        }
      }
      break;
    case AutocorrTransverse:
      if(dcBlock.autocorr()) {
        int nRings;
        s >> nRings;
        dcBlock.readModalStorages(nRings*3);
        for(QList<int>::iterator it=ringIndexes.begin();it!=ringIndexes.end();it++) {
          if(*it<nRings) {
            if(dcBlock.modalStorage(*it*3+2)) {
              ModalStorageReader m(s);
              if(m.seek(s,modeIndex)) {
                sOut << QString("# Transverse autocorrelation curve (ring=%1,mode=%2) %3: value=%4")
                                .arg(*it).arg(modeIndex).arg(iReportModel).arg(misfit) << endl;
                m.toStream(s, sOut);
                iModel++;
              }
            }
          }
        }
      }
      break;
    case RefractionVp:
      if(dcBlock.refractionVp() && inputType==Current) {
        RefractionFactory f;
        f.readReport(dcBlock.stream());
        if(sourceIndex<f.sourceCount()) {
          sOut << QString("# Vp refraction curve (source %1 at %2 m) %3: value=%4")
                          .arg(sourceIndex).arg(f.sources()[sourceIndex]).arg(iReportModel).arg(misfit) << endl;
          f.toStream(sourceIndex, sOut);
          iModel++;
        }
      }
      break;
    case RefractionVs:
      if(dcBlock.refractionVs() && inputType==Current) {
        RefractionFactory f;
        f.readReport(dcBlock.stream());
        if(sourceIndex<f.sourceCount()) {
          sOut << QString("# Vs refraction curve (source %1 at %2 m) %3: value=%4")
                          .arg(sourceIndex).arg(f.sources()[sourceIndex]).arg(iReportModel).arg(misfit) << endl;
          f.toStream(sourceIndex, sOut);
          iModel++;
        }
      }
      break;
    default:
      break;
    }
  }
}
void outputModel ( QDataStream &  s,
int  iReportModel,
double  misfit,
ReportReader report 
)

References DinverCore::ReportWriter::addModel(), BestCurve, BetaRelease, Checksum, Current, currentBestMisfit, QGpCoreTools::endl(), iModel, inputType, misfit(), NaViewer, outputDCModel(), outputType, Report, DinverCore::Parameter::setRealValue(), and sOut().

Referenced by main().

{
  switch(outputType) {
  case Parameters: {
      int nd;
      uint cs;
      double val;
      s >> nd;
      s >> cs;
      sOut <<  iReportModel << " " << nd << " ";
      sOut.setRealNumberPrecision(20);
      for(int id=0 ; id<nd; id++ ) {
        s >> val;
        sOut << val << " ";
      }
      sOut << misfit << endl;
      iModel++;
    }
    break;
  case Checksum: {
      int nd;
      uint cs;
      s >> nd;
      s >> cs;
      sOut <<  iReportModel << " " << cs << "\n";
    }
    break;
  case BestCurve: {
      if(misfit<currentBestMisfit) {
        sOut <<  iReportModel << " " << misfit << "\n";
        currentBestMisfit=misfit;
      }
    }
    break;
  case Report: {
      int nParams;
      uint cs;
      double val;
      qint64 blockOffset=s.device()->pos();
      s >> nParams;
      s >> cs;
      Parameter * params[nParams];
      for(int id=0 ; id<nParams; id++ ) {
        s >> val;
        params[id]=new Parameter;
        params[id]->setRealValue(val);
      }
      outputReport->addModel(misfit, cs, nParams, params);
      for(int id=0 ; id<nParams; id++ ) delete params[id];
      s.device()->seek(blockOffset);
      switch(inputType) {
      case BetaRelease:
        DCReportBlock::writeBeta(outputReport, report);
        break;
      case Current:
        DCReportBlock::write(outputReport, report);
        break;
      case NaViewer: // Not possible here
        break;
      }
      iModel++;
    }
    break;
  default:
    outputDCModel(s, iReportModel, misfit, report);
    break;
  }
}
void outputModel ( double  misfit,
CompatInversionReport report 
)

References DinverCore::ReportWriter::addModel(), QGpCompatibility::CompatInversionReport::currentNAModel(), QGpCompatibility::CompatInversionReport::dimension(), iModel, outputType, Report, and DinverCore::Parameter::setRealValue().

{
  if(outputType==Report) {
    // Old reports have not this var and all parameter list
    int nParams=report->dimension();
    Parameter * params[nParams];
    float * pm=report->currentNAModel();
    for(int id=0 ; id<nParams; id++ ) {
      params[id]=new Parameter;
      params[id]->setRealValue(Number::toDouble(pm[id] ));
    }
    outputReport->addModel(misfit, 0, nParams, params);
    for(int id=0 ; id<nParams; id++ ) delete params[id];
    DCReportBlock::writeNaViewer(outputReport, report);
    iModel++;
  }
}
PACKAGE_INFO ( gpdcreport  ,
GPDCREPORT   
)
QTextStream sOut ( stdout  )

Variable Documentation

double currentBestMisfit = 1e99

Referenced by outputModel().

int iModel = 0

Referenced by main(), outputDCModel(), and outputModel().

int modeIndex = 0
QList<DCModelInfo *> models

Referenced by cleanReturn(), and reportMode().

Referenced by main(), outputDCModel(), and outputModel().

Referenced by cleanReturn(), main(), and reportMode().

QList<int> ringIndexes

Referenced by main(), and outputDCModel().

int sourceIndex = 0

Referenced by main(), and outputDCModel().

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines