All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
QGpCompatibility::CompatInversionReport Class Reference

#include <CompatInversionReport.h>

Inheritance diagram for QGpCompatibility::CompatInversionReport:
QGpCompatibility::CompatAutocorrReport QGpCompatibility::CompatRefraReport

List of all members.

Classes

struct  paramAddress

Public Types

enum  BlockType {
  Parameters, Omegas, DispersionGoal, ModelDispersion,
  AutocorrGoal, EllipticityGoal, FKMaxGoal, Information,
  Unknown, RefraGoal
}
enum  paramID {
  H, Vs, Vp, Rho,
  Depth, ExpGrad, ModeStdDev, NAParam
}

Public Member Functions

void addDispersionGoal (CompatDispersionData *rms)
void addEllipticityGoal (CompatEllipticityData *ell)
void addModel (const Seismic1DModel *model, float *naModel, const CompatDispersion *disp, double cost, int modelID=-1)
void addModel (const Seismic1DModel *model, float *naModel, const CompatDispersion *disp, const CompatEllipticity *ell, double cost, int modelID=-1)
void addOmegas (CompatMultiModalFrequency *omegas)
void addParameter (paramID which, int layer)
const char * className ()
 CompatInversionReport (bool isWrite, QString reportFile, QString naInFile=QString::null, int nModels=0)
int countModels ()
double currentCost ()
CompatDispersioncurrentDispersion ()
CompatEllipticitycurrentEllipticity ()
int currentID ()
int currentLoadingIndex ()
Seismic1DModelcurrentModel ()
float * currentNAModel ()
int dimension ()
void endWritingBlock ()
void flush ()
int getBestFit ()
QVector< Point > * getBestFits (QVector< Point > &curve, int &startIndex, double &minCostValue, int &generatedModels)
int getID ()
void getNAParam (int &itmax, int &nsi, int &ns, int &nr)
paramID getParamType (int paramIndex)
double getParamValue (int paramIndex)
virtual bool isA (const char *className)
bool isRightFormat ()
bool isSameGoalDispersion (CompatInversionReport *otherModels)
bool isSameOmegas (const CompatInversionReport *otherModels) const
bool isSameParameter (const CompatInversionReport *otherModels) const
bool isValid ()
double loadCostValue (int modelIndex)
bool loadDispersion (int modelIndex)
bool loadDispersion (CompatDispersion *disp, CompatEllipticity *ell, int modelIndex)
CompatDispersionDataloadDispersionGoal ()
CompatEllipticityDataloadEllipticityGoal ()
bool loadModel (int modelIndex=-1)
void loadNAModel (int modelIndex=-1)
bool loadNextModel ()
void maxOmegasCount (int &dispCount, int &ellCount)
int modesCount ()
void modifyDispersionGoal (CompatDispersionData *rms)
void modifyEllipticityGoal (CompatEllipticityData *ell)
int omegasCount ()
QString parameterName (int paramIndex)
QString reportFileName ()
QString reportName ()
BlockType reportType ()
void setCostValue (int imodel, double costValue)
void setFlushed (bool s)
void setNFromNaIn (QString naInfile)
bool startReadingBlock (int index, BlockType wantedType)
bool startWritingBlock (int index, BlockType wantedType)
bool startWritingBlock (BlockType type)
void statDispersion (int ipoint, int imode, int start_model, int end_model, double &mean, double &stddev)
void writeHeader ()
virtual ~CompatInversionReport ()

Static Public Member Functions

static bool isReady (QString reportFile)
static bool isRightFormat (QString reportFile)

Protected Member Functions

virtual bool initCurrentDispersion ()
bool initCurrentEllipticity ()
bool initCurrentModel ()
bool loadParamAddresses ()
void setMaxOmegasCount (int dispCount, int ellCount)
void writeNAModel (float *naModel)

Protected Attributes

qint64 _blockEll
qint64 _blockGoal
qint64 _blockOmegas
qint64 _blockParam
double _currentCost
CompatMultiModalCurves_currentDispersion
CompatEllipticity_currentEllipticity
int _currentID
int _currentIndex
Seismic1DModel_currentModel
float * _currentNAModel
QString _fileName
bool _flushed
int _headerBlocksCount
int _maxDispOmegaCount
int _maxEllOmegaCount
int _n
int _nd
qint64 * _offsetTable
paramAddress_paramAddresses
qint64 _ptrStart
QDataStream _s
int _trueN
bool _valid
int _version

Member Enumeration Documentation

Enumerator:
Parameters 
Omegas 
DispersionGoal 
ModelDispersion 
AutocorrGoal 
EllipticityGoal 
FKMaxGoal 
Information 
Unknown 
RefraGoal 
Enumerator:
H 
Vs 
Vp 
Rho 
Depth 
ExpGrad 
ModeStdDev 
NAParam 

Constructor & Destructor Documentation

QGpCompatibility::CompatInversionReport::CompatInversionReport ( bool  isWrite,
QString  reportFile,
QString  naInFile = QString::null,
int  nModels = 0 
)

References _blockEll, _blockGoal, _blockOmegas, _blockParam, _currentDispersion, _currentEllipticity, _currentID, _currentIndex, _currentModel, _currentNAModel, _fileName, _headerBlocksCount, _maxDispOmegaCount, _maxEllOmegaCount, _n, _nd, _offsetTable, _paramAddresses, _ptrStart, _s, _trueN, _valid, _version, countModels(), CURRENT_VERSION, currentEllipticity(), FILE_TAG, Information, isRightFormat(), loadParamAddresses(), MAX_HEADER_BLOCKS_COUNT, MSG_ID, setNFromNaIn(), startReadingBlock(), TAG_LENGTH, TRACE, and writeHeader().

{
  TRACE;
  // in case of I/O error these members should be correctly initialized
  _maxDispOmegaCount=0;
  _maxEllOmegaCount=0;
  _headerBlocksCount=4;
  _paramAddresses=0;
  _currentModel=0;
  _currentNAModel=0;
  _currentDispersion=0;
  _currentEllipticity=0;
  _ptrStart=0;
  _offsetTable=0;
  _trueN=0; 
  QDir d;
  _fileName=d.absoluteFilePath(reportFile);
  QFile *f=new QFile(reportFile);
  if(isWrite) {
    if(!f->open(QIODevice::ReadWrite | QIODevice::Truncate)) {
      Message::critical(MSG_ID,"Inversion report", QString("file not found %1, or error writing to file").
                arg(reportFile),Message::cancel());
      _valid=false;
      return;
    }
    _s.setDevice(f);
    _nd=0;
    _currentID=0;
    _version=CURRENT_VERSION ;
    _blockParam=1;
    _blockOmegas=2;
    _blockGoal=3;
    _blockEll=4;
    // Add one more model in case of ellipticity
    if(!naInFile.isNull()) setNFromNaIn(naInFile); else _n=MAX_HEADER_BLOCKS_COUNT;
    _n+=nModels;
    if(_n<=0) {
      printf("No max number of models specified, setting it by default to 1000\n");
      _n=1000;
    }
    _offsetTable=new qint64 [_n];
    writeHeader();
    _currentIndex=-1;
  }
  else {
    if(!f->open(QIODevice::ReadWrite)) {
      Message::critical(MSG_ID,"Inversion report", QString("file not found %1, or error writing to file").
                arg(reportFile),Message::cancel());
      _valid=false;
      return;
    }
    _s.setDevice(f);
    if(!isRightFormat()) {
      Message::critical(MSG_ID,"Inversion report", QString("Bad file tag for %1, should be %2").
              arg(reportFile).arg(FILE_TAG),Message::cancel());
      _valid=false;
      return;
    }
    _s.device()->seek(TAG_LENGTH);
    _s >> _n;
    _offsetTable=new qint64 [_n];
    _trueN=countModels()+_headerBlocksCount;
    // Read the version, if block does not exist, it is version 0
    if(startReadingBlock(0,Information)) {
      _s >> _version;
      if(_version>CURRENT_VERSION) {
        Message::critical(MSG_ID,"Inversion report", QString("Bad file version (current=%1): %2, %3").
                arg(CURRENT_VERSION).arg(reportFile).arg(_version),Message::cancel());
        _valid=false;
        return;        
      }
      _blockParam=1;
      _blockOmegas=2;
      _blockGoal=3;
      _blockEll=4;
    }
    else {
      _version=0;
      _blockParam=0;
      _blockOmegas=1;
      _blockGoal=2;
      _blockEll=3;
    }
    if(!loadParamAddresses()) {
      _valid=false;
      return;
    }
    if(currentEllipticity()!=0) _headerBlocksCount++;
    _currentIndex=-1;
  }
  _valid=true;
}

Member Function Documentation

References _blockOmegas, _s, QGpCompatibility::CompatMultiModalData::dataToReport(), DispersionGoal, endWritingBlock(), Omegas, QGpCompatibility::CompatMultiModalCurves::rayleighModesCount(), startReadingBlock(), startWritingBlock(), and TRACE.

{
  TRACE;
  // tests if omegas are entered
  if(!startReadingBlock(_blockOmegas,Omegas)) {
    printf("You must call addOmegas before calling addDispersionGoal\n");
    return;
  }    
  startWritingBlock(DispersionGoal);
  if(rms) {
    _s << rms->rayleighModesCount();
    rms->dataToReport(_s);
  }
  endWritingBlock();
}

References _blockOmegas, _headerBlocksCount, _s, QGpCompatibility::CompatMultiModalData::dataToReport(), EllipticityGoal, endWritingBlock(), QGpCompatibility::CompatEllipticityData::f0ToReport(), Omegas, startReadingBlock(), startWritingBlock(), and TRACE.

{
  TRACE;
  // tests if omegas are entered
  if(!startReadingBlock(_blockOmegas,Omegas))  {
    printf("You must call addOmegas before calling addDispersionGoal\n");
    return;
  }
  
  startWritingBlock(EllipticityGoal);  
  if(ell) {
    ell->dataToReport(_s);
    ell->f0ToReport(_s);
    _headerBlocksCount++;
  }
  endWritingBlock();
}
void QGpCompatibility::CompatInversionReport::addModel ( const Seismic1DModel model,
float *  naModel,
const CompatDispersion disp,
double  cost,
int  modelID = -1 
)

References _currentID, _s, endWritingBlock(), ModelDispersion, QGpCompatibility::CompatMultiModalCurves::refinesCount(), QGpCompatibility::CompatMultiModalCurves::refinesToReport(), setMaxOmegasCount(), startWritingBlock(), QGpCoreWave::Seismic1DModel::toStream(), TRACE, QGpCompatibility::CompatMultiModalCurves::valuesToReport(), and writeNAModel().

{
  TRACE;
  // Write new model at the end of file
  if(startWritingBlock(ModelDispersion)) {
    if(modelID<0) {
      _s << _currentID;
      _currentID++;
    }
    else {
      if(modelID>=_currentID) _currentID=modelID+1;
      _s << modelID;   
    }
    model->toStream(_s);
    _s << cost;
    writeNAModel(naModel);
    disp->valuesToReport(_s);
    disp->refinesToReport(_s);
  }
  else printf("Maximum number of models is reached, model not added\n");
  endWritingBlock();
  setMaxOmegasCount(disp->refinesCount(),0);
}
void QGpCompatibility::CompatInversionReport::addModel ( const Seismic1DModel model,
float *  naModel,
const CompatDispersion disp,
const CompatEllipticity ell,
double  cost,
int  modelID = -1 
)

References _currentID, _s, endWritingBlock(), ModelDispersion, QGpCompatibility::CompatMultiModalCurves::refinesCount(), QGpCompatibility::CompatMultiModalCurves::refinesToReport(), setMaxOmegasCount(), startWritingBlock(), QGpCoreWave::Seismic1DModel::toStream(), TRACE, QGpCompatibility::CompatMultiModalCurves::valuesToReport(), and writeNAModel().

{
  TRACE;
  // Write new model at the end of file
  if(startWritingBlock(ModelDispersion)) {
    if(modelID<0) {
      _s << _currentID;
      _currentID++;
    }
    else {
      if(modelID>=_currentID) _currentID=modelID+1;
      _s << modelID;   
    }
    model->toStream(_s);
    _s << cost;
    writeNAModel(naModel);
    disp->valuesToReport(_s);
    disp->refinesToReport(_s);
    ell->valuesToReport(_s);
    ell->refinesToReport(_s);
  }
  else printf("Maximum number of models is reached, model not added\n");
  endWritingBlock();
  setMaxOmegasCount(disp->refinesCount(),ell->refinesCount());
}

References _nd, _s, endWritingBlock(), Omegas, QGpCompatibility::CompatMultiModalFrequency::omegaToReport(), startWritingBlock(), and TRACE.

{
  TRACE;
  // tests if parameters are entered (at least one)
  ASSERT(_nd);
  startWritingBlock(Omegas);  
  omegas->omegaToReport(_s);
  endWritingBlock();
}

References _blockParam, _nd, _s, endWritingBlock(), startWritingBlock(), and TRACE.

{
  TRACE;
  // Description of parameters: 
  // - number of parameters (=nd) (initialized to 0 by writeHeader())
  // for each parameter:
  // - (0=H, 1=Vs, 2=Vp, 3=Rho) [enum paramID]
  // - layer number
  // (Must be set in file "init_param.cpp")
  
  _nd++;
  if(startWritingBlock(_blockParam,Parameters)) {
    // update nd
    _s << _nd;
    // move to correct parameter
    _s.device()->seek((_nd-1)*2*sizeof(int)+_s.device()->pos());
    // add informations on this parameter
    _s << which;
    _s << layer;
  }
  else printf("Error in writing the list of parameters to the inversion report\n");
  endWritingBlock();
}
{return "CompatInversionReport";}

References _headerBlocksCount, _n, _offsetTable, _s, _trueN, TAG_LENGTH, and TRACE.

Referenced by CompatInversionReport(), and main().

{
  TRACE;
  if(_trueN<_n) {
    ASSERT (_offsetTable);
    int tmp;
    qint64 * it=_offsetTable+_trueN;
    _s.device()->seek(TAG_LENGTH+sizeof(int)*(_trueN+1));
    for(int i=_trueN;i<_n;i++,it++) {
      _s >> tmp;
      *it=tmp;
      if(!*it) {
        _trueN=i;
        return _trueN-_headerBlocksCount;
      }
    }
    _trueN=_n;
  }
  return _trueN-_headerBlocksCount;
}

Referenced by main().

{return _currentCost;}
{return _currentID;}
{return _currentIndex;}

References _currentNAModel, loadModel(), and TRACE.

Referenced by outputModel().

Referenced by outputModel().

{return _nd;}

References _n, _offsetTable, _ptrStart, _s, _trueN, flush(), TAG_LENGTH, and TRACE.

Referenced by QGpCompatibility::CompatAutocorrReport::addAutocorrGoal(), addDispersionGoal(), addEllipticityGoal(), QGpCompatibility::CompatAutocorrReport::addModel(), addModel(), addOmegas(), addParameter(), QGpCompatibility::CompatRefraReport::addRefraGoal(), QGpCompatibility::CompatAutocorrReport::modifyAutocorrGoal(), modifyDispersionGoal(), modifyEllipticityGoal(), QGpCompatibility::CompatRefraReport::modifyRefraGoal(), setCostValue(), setMaxOmegasCount(), and writeHeader().

{
  TRACE;
  // effectively writes the block to disk (we are sure that the block is really
  // written on the disk before the pointer in the table.
  static_cast<QFile *>(_s.device())->flush();
  if(_ptrStart>0) {
    _s.device()->seek((_trueN+1)*sizeof(int)+TAG_LENGTH);
    _s << (qint32)_ptrStart;
    _offsetTable[_trueN]=_ptrStart;
    _trueN++;
  }
  else if(_ptrStart<0)
  {
    // Tests if size of block has changed, if it is the last block ok, else error
    int index=-_ptrStart-1;
    if(index!=_n-1)
    {
      qint32 tmp;
      qint64 ptrEnd;
      qint64 lastPtr=_s.device()->pos();
      _s.device()->seek(TAG_LENGTH+sizeof(int)*(index+2));
      _s >> tmp;
      ptrEnd=tmp;
      if(ptrEnd && ptrEnd<lastPtr)
        printf("You write over existing data, the file may be corrupted\n");
    }
  }
  else 
  {
    printf("startWritingBlock did not execute correctly, you should call it before endWritingBlock\n");
  }
  _ptrStart=0;
}

References _flushed, _s, and TRACE.

Referenced by endWritingBlock(), and writeHeader().

{
  TRACE;
  if(!_flushed)
  {
    static_cast<QFile *>(_s.device())->flush();
    _flushed=true;
  }
}

References _headerBlocksCount, _s, _trueN, ModelDispersion, startReadingBlock(), and TRACE.

{
  TRACE;
  int minCostIndex=-1, i=0, modelID, n;
  double cost,minCost=1e99;
  while(i+_headerBlocksCount<_trueN) {
    if(!startReadingBlock(i+_headerBlocksCount,ModelDispersion)) break;
    _s >> modelID;
    // Skip the layered model
    _s >> n;
    _s.device()->seek((4*n-1)*sizeof(double)+_s.device()->pos());
    _s >> cost;
    if(cost<minCost) {
      minCost=cost;
      minCostIndex=i;
    }
    i++;
  }
  return minCostIndex;
}
QVector< Point > * QGpCompatibility::CompatInversionReport::getBestFits ( QVector< Point > &  curve,
int &  startIndex,
double &  minCostValue,
int &  generatedModels 
)

References _currentCost, _currentID, _headerBlocksCount, _s, _trueN, ModelDispersion, and startReadingBlock().

{
  int minCostIndex=-1;
  int interCount=2000;
  while(startIndex+_headerBlocksCount<_trueN) {
    if(!startReadingBlock(startIndex+_headerBlocksCount,ModelDispersion)) break;
    _s >> _currentID;
    int n; // Skip the layered model
    _s >> n;
    _s.device()->seek((4*n-1)*sizeof(double)+_s.device()->pos());
    _s >> _currentCost;
    if(_currentCost<minCostValue) {
      if(curve.count()<2000) {
        minCostValue=_currentCost;
        if(_currentID==-1) minCostIndex=startIndex; else minCostIndex=_currentID;
        curve.push_back(Point(minCostIndex,minCostValue,0));
      }
      else {
        if(interCount>0) interCount--;
        else {
          minCostValue=_currentCost;
          if(_currentID==-1) minCostIndex=startIndex; else minCostIndex=_currentID;
          curve.push_back(Point(minCostIndex,minCostValue,0));
          interCount=2000;
        }
      }
    }
    startIndex++;
  }
  // Check again last record (needed if no more blocks were added since last call)
  startReadingBlock(startIndex+_headerBlocksCount-1,ModelDispersion);
  _s >> _currentID;
  generatedModels=_currentID;
  return &curve;
}
{return _currentID;}
void QGpCompatibility::CompatInversionReport::getNAParam ( int &  itmax,
int &  nsi,
int &  ns,
int &  nr 
)

References _fileName, and TRACE.

{
  TRACE;
  QFileInfo fi(_fileName);
  QDir d(fi.absolutePath());
  d.cd(QString("wd_%1").arg(fi.baseName()));
  if(d.exists("na.in")) {
    // Read na.in to get the total number of models that will be generated
    FILE * f;
    f=fopen(d.absoluteFilePath("na.in").toAscii().data(),"r");
    if(f) {
      int buflen=256;
      char * buf=new char [buflen];
      File::readLine(buf, buflen, f); // comment line
      File::readLine(buf, buflen, f); // comment line
      File::readLine(buf, buflen, f); // comment line
      File::readLine(buf, buflen, f); // Perform NA or MC ?
      File::readLine(buf, buflen, f); // maximum number of iterations
      sscanf(buf,"%i", &itmax);
      File::readLine(buf, buflen, f); // sample size for initial population
      sscanf(buf,"%i", &nsi);
      File::readLine(buf, buflen, f); // sample size for remaining populations
      sscanf(buf,"%i", &ns);
      File::readLine(buf, buflen, f); // number of cell to resample
      sscanf(buf,"%i", &nr);
      fclose(f);
      delete [] buf;
    }
  }
}
{return _paramAddresses[paramIndex].which;}

References _currentModel, _currentNAModel, _nd, _paramAddresses, Depth, QGpCoreWave::Seismic1DModel::depth(), ExpGrad, QGpCoreWave::Seismic1DModel::expGrad(), QGpCoreWave::Seismic1DModel::h(), H, QGpCompatibility::CompatInversionReport::paramAddress::layer, QGpCoreWave::Seismic1DModel::layerCount(), ModeStdDev, NAParam, QGpCoreWave::Seismic1DModel::rho(), Rho, QGpCoreWave::Seismic1DModel::slowP(), QGpCoreWave::Seismic1DModel::slowS(), TRACE, Vp, Vs, and QGpCompatibility::CompatInversionReport::paramAddress::which.

{
  TRACE;
  paramAddress& a=_paramAddresses[paramIndex];
  if(a.which<NAParam && a.layer>=_currentModel->layerCount()) {
    a.layer=_currentModel->layerCount()-1;
    printf("Layer number for parameter greater than layer number in model\n");
  }
  else if(a.which>=NAParam && a.layer>=_nd) {
    a.layer=_nd-1;
    printf("Number for parameter greater than dimension number in model\n");    
  }
  switch (a.which) {
  case H:
    return _currentModel->h(a.layer);
  case Vs:
    return 1.0/_currentModel->slowS(a.layer);
  case Vp:
    return 1.0/_currentModel->slowP(a.layer);
  case Rho:
    return _currentModel->rho(a.layer);
  case Depth:
    return _currentModel->depth(a.layer);
  case ExpGrad:
    return _currentModel->expGrad(a.layer);
  case ModeStdDev:
    return _currentModel->slowS(a.layer);
  case NAParam:
    return _currentNAModel[a.layer];
  }
  return 0;
}

References _blockOmegas, _currentEllipticity, _s, MSG_ID, Omegas, QGpCompatibility::CompatMultiModalCurves::reportToOmega(), startReadingBlock(), and TRACE.

Referenced by QGpCompatibility::CompatRefraReport::initCurrentDispersion(), and initCurrentDispersion().

{
  TRACE;
  ASSERT(!_currentEllipticity);
  _currentEllipticity=new CompatEllipticity();
  if(startReadingBlock(_blockOmegas,Omegas)) {
    _currentEllipticity->reportToOmega(_s);
    return true;
  }
  else {
    Message::critical(MSG_ID,"Inversion report", "Bad block: omegas at index 1",Message::cancel());
    return false;
  }    
}

References _currentModel, _headerBlocksCount, _s, ModelDispersion, MSG_ID, startReadingBlock(), and TRACE.

Referenced by QGpCompatibility::CompatRefraReport::initCurrentTiltModel(), QGpCompatibility::CompatAutocorrReport::loadAutocorr(), QGpCompatibility::CompatAutocorrReport::loadAutocorrOnly(), loadCostValue(), loadDispersion(), loadModel(), and loadNextModel().

{
  TRACE;
  // Get number of layers per model
  // Get Ptr to the first model
  if(startReadingBlock(_headerBlocksCount,ModelDispersion)) {
    int nLayers;
    _s >> nLayers; // ID unused here
    _s >> nLayers;
    _currentModel=new Seismic1DModel(nLayers);
    return true;
  }
  else {
    Message::critical(MSG_ID,"Inversion report", "Bad block for first ModelDispersion",Message::cancel());
    return false;
  }
}
bool QGpCompatibility::CompatInversionReport::isA ( const char *  className) [virtual]

Reimplemented in QGpCompatibility::CompatRefraReport, and QGpCompatibility::CompatAutocorrReport.

References TRACE.

{
  TRACE;
  return strcmp(className,"CompatInversionReport")==0;
}
bool QGpCompatibility::CompatInversionReport::isReady ( QString  reportFile) [static]

References FILE_TAG, MAX_HEADER_BLOCKS_COUNT, ModelDispersion, TAG_LENGTH, and TRACE.

{
  TRACE;
  QFile f(reportFile);
  if(!f.open(QIODevice::ReadOnly)) return false;
  QDataStream s(&f);
  
  char buf [TAG_LENGTH];
  s.readRawData(buf,TAG_LENGTH);
  if(strcmp(buf,FILE_TAG)) return false;
  
  int ptrStart;
  f.seek(TAG_LENGTH+sizeof(int)*(MAX_HEADER_BLOCKS_COUNT+1));
  s >> ptrStart;
  if(ptrStart) {
    int blockType=0;
    f.seek(ptrStart);
    s >> blockType;
    return (blockType==ModelDispersion);
  }
  else return false;
}
bool QGpCompatibility::CompatInversionReport::isRightFormat ( QString  reportFile) [static]

References FILE_TAG, TAG_LENGTH, and TRACE.

{
  TRACE;
  QFile f(reportFile);
  if(!f.open(QIODevice::ReadOnly)) return false;
  QDataStream s(&f);
  
  char buf [TAG_LENGTH];
  s.readRawData(buf,TAG_LENGTH);
  if(strcmp(buf,FILE_TAG)) return false;
  return true;
}

References _s, FILE_TAG, TAG_LENGTH, and TRACE.

Referenced by CompatInversionReport().

{
  TRACE;
  char buf [TAG_LENGTH];
  _s.readRawData(buf,TAG_LENGTH);
  return !strcmp(buf,FILE_TAG);
}

References _currentDispersion, QGpCompatibility::CompatMultiModalData::isSameData(), loadDispersionGoal(), QGpCompatibility::CompatMultiModalFrequency::modesCount(), QGpCompatibility::CompatMultiModalFrequency::omegasCount(), and TRACE.

{
  TRACE;
  int nModes=_currentDispersion->modesCount();
  int n=_currentDispersion->omegasCount();
  if(nModes!=otherModels->_currentDispersion->modesCount() || 
      n!=otherModels->_currentDispersion->omegasCount()) return false;
  
  CompatDispersionData * rms1, * rms2;
  rms1=loadDispersionGoal();
  rms2=otherModels->loadDispersionGoal();
  
  return rms1->isSameData(rms2);
}

References _nd, _paramAddresses, QGpCompatibility::CompatInversionReport::paramAddress::layer, TRACE, and QGpCompatibility::CompatInversionReport::paramAddress::which.

{
  TRACE;
  if(_nd!=otherModels->_nd) return false;
  for(int i=0;i<_nd;i++) {
    paramAddress& a=_paramAddresses[i];
    paramAddress& b=otherModels->_paramAddresses[i];
    if(a.which!=b.which || a.layer!=b.layer) return false;
  }
  return true;
}

Referenced by main().

{return _valid;}

References _currentCost, _currentID, _currentModel, _headerBlocksCount, _s, initCurrentModel(), ModelDispersion, startReadingBlock(), and TRACE.

{
  TRACE;
  if(!_currentModel && !initCurrentModel()) return 0;
  if(startReadingBlock(modelIndex+_headerBlocksCount,ModelDispersion))
  {
    _s >> _currentID;
    int n; // Skip the layered model
    _s >> n;
    _s.device()->seek((4*n-1)*sizeof(double)+_s.device()->pos());
    _s >> _currentCost;
  }
  else _currentCost=-1;
  return _currentCost;
}

References _blockGoal, _currentDispersion, _s, _version, QGpCompatibility::CompatDispersionData::convertStddev(), DispersionGoal, initCurrentDispersion(), QGpCompatibility::CompatMultiModalData::reportToData(), QGpCompatibility::CompatMultiModalData::reportToDataWeight(), QGpCompatibility::CompatMultiModalCurves::setRayleighModesCount(), startReadingBlock(), and TRACE.

Referenced by isSameGoalDispersion().

{
  TRACE;
  if(!_currentDispersion) initCurrentDispersion();
  CompatDispersionData * rms=new CompatDispersionData(_currentDispersion);
  if(startReadingBlock(_blockGoal,DispersionGoal)) {
    if(_version>=2) {
      uint rayleighModesCount;
      _s >> rayleighModesCount;
      rms->setRayleighModesCount(rayleighModesCount);
      _currentDispersion->setRayleighModesCount(rayleighModesCount);
    }
    rms->reportToData(_s);
    rms->reportToDataWeight(_s,_version>=3);
  }
  else printf("unable to read block DispersionGoal in current file\n");
  if(_version==0) rms->convertStddev();
  return rms;
}

References _blockEll, _currentEllipticity, _s, _version, EllipticityGoal, QGpCompatibility::CompatMultiModalData::reportToData(), QGpCompatibility::CompatMultiModalData::reportToDataWeight(), QGpCompatibility::CompatEllipticityData::reportToF0(), startReadingBlock(), and TRACE.

Referenced by EllipticityPeakTargetWidget::loadReport().

{
  TRACE;
  if(!_currentEllipticity) return 0;
  CompatEllipticityData * ell=new CompatEllipticityData(_currentEllipticity);
  if(startReadingBlock(_blockEll,EllipticityGoal)) {
    ell->reportToData(_s);
    ell->reportToDataWeight(_s,_version>=3);
    if(_version>=5) ell->reportToF0(_s);
  }
  else printf("unable to read block EllipticityGoal in current file\n");
  return ell;
}

References _blockParam, _nd, _paramAddresses, _s, QGpCompatibility::CompatInversionReport::paramAddress::layer, MSG_ID, startReadingBlock(), TRACE, and QGpCompatibility::CompatInversionReport::paramAddress::which.

Referenced by CompatInversionReport().

{
  TRACE;
  if(startReadingBlock(_blockParam,Parameters)) {
    _s >> _nd;
    _paramAddresses=new paramAddress [_nd];
    for(int i=0;i<_nd;i++) {
      paramAddress& a=_paramAddresses[i];
      int tmp;
      _s >> tmp;
      a.which=(paramID)tmp;
      _s >> a.layer;
    }
    return true;
  }
  else {
    Message::critical(MSG_ID,"Inversion report", "Bad block: Parameters at index 0",Message::cancel());
    return false;
  }    
}
void QGpCompatibility::CompatInversionReport::maxOmegasCount ( int &  dispCount,
int &  ellCount 
)

References _maxDispOmegaCount, _maxEllOmegaCount, _s, _version, Information, omegasCount(), startReadingBlock(), and TRACE.

{
  TRACE;
  dispCount=omegasCount();
  ellCount=dispCount;
  if(_version>=1) {
    if(startReadingBlock(0,Information)) {
      _s.device()->seek(_s.device()->pos()+sizeof(int));
      _s >> _maxDispOmegaCount;
      _s >> _maxEllOmegaCount;
      dispCount+=_maxDispOmegaCount;
      ellCount+=_maxEllOmegaCount;
    }
    else fprintf(stderr," ### ERROR ### : cannot read information block");
  }
}

References _paramAddresses, Depth, ExpGrad, H, QGpCompatibility::CompatInversionReport::paramAddress::layer, ModeStdDev, NAParam, Rho, str, TRACE, Vp, Vs, and QGpCompatibility::CompatInversionReport::paramAddress::which.

{
  TRACE;
  paramAddress& a=_paramAddresses[paramIndex];
  QString str;
  switch (a.which) {
  case H:
    str="H%1";
    break;
  case Vs:
    str="Vs%1";
    break;
  case Vp:
    str="Vp%1";
    break;
  case Rho:
    str="Rho%1";
    break;
  case Depth:
    str="Depth%1";
    break;
  case ExpGrad:
    str="Power law exp %1";
    break;
  case ModeStdDev:
    str="Std dev %1";
    break;
  case NAParam:
    str="NA %1";
    break;
  }
  return str.arg(a.layer);
}

References _fileName, and TRACE.

{
  TRACE;
  return _fileName;
}

References _fileName, and TRACE.

{
  TRACE;
  QFileInfo f(_fileName);
  return f.baseName();
}

References _blockGoal, _ptrStart, _s, TAG_LENGTH, and Unknown.

Referenced by QGpCompatibility::CompatReportFactory::open().

{
  _s.device()->seek(TAG_LENGTH+sizeof(int)*(_blockGoal+1));
  qint32 tmp;
  _s >> tmp;
  _ptrStart=tmp;
  if(_ptrStart) {
    _s.device()->seek(_ptrStart);
    int blockType=0;
    _s >> blockType;
    _ptrStart=0;
    return (BlockType)blockType;
  }
  else return Unknown;
}
void QGpCompatibility::CompatInversionReport::setCostValue ( int  imodel,
double  costValue 
)

References _currentID, _headerBlocksCount, _s, endWritingBlock(), ModelDispersion, startWritingBlock(), and TRACE.

{
  TRACE;
  if(startWritingBlock(imodel+_headerBlocksCount,ModelDispersion))
  {
    _s >> _currentID;
    int n; // Skip the layered model
    _s >> n;
    _s.device()->seek((4*n-1)*sizeof(double)+_s.device()->pos());
    _s << costValue;
  } else fprintf(stderr,"Bad model index, when rewriting a block\n");
  endWritingBlock(); 
}
{_flushed=s;}
void QGpCompatibility::CompatInversionReport::setMaxOmegasCount ( int  dispCount,
int  ellCount 
) [protected]

References _maxDispOmegaCount, _maxEllOmegaCount, _s, endWritingBlock(), Information, startWritingBlock(), and TRACE.

Referenced by QGpCompatibility::CompatAutocorrReport::addModel(), and addModel().

{
  TRACE;
  if(dispCount>_maxDispOmegaCount) {
    _maxDispOmegaCount=dispCount;
    if(ellCount>_maxEllOmegaCount) {
      _maxEllOmegaCount=ellCount;
      startWritingBlock(0,Information);  
      _s.device()->seek(_s.device()->pos()+sizeof(int));
      _s << _maxDispOmegaCount;
      _s << _maxEllOmegaCount;
      endWritingBlock();
    }
    else {
      startWritingBlock(0,Information);  
      _s.device()->seek(_s.device()->pos()+sizeof(int));
      _s << _maxDispOmegaCount;
      endWritingBlock();     
    }
  }
  else {
    if(ellCount>_maxEllOmegaCount) {
      _maxEllOmegaCount=ellCount;
      startWritingBlock(0,Information);  
      _s.device()->seek(_s.device()->pos()+sizeof(int)*2);
      _s << _maxEllOmegaCount;
      endWritingBlock();
    }
  }
}

References _n, MAX_HEADER_BLOCKS_COUNT, and TRACE.

Referenced by CompatInversionReport().

{
  TRACE;
  // Read na.in to get the total number of models that will be generated
  FILE * f;
  f=fopen(naInfile.toAscii().data(),"r");
  int itmax=10,nsamplei=10,nsample=10;
  if(f) {
    int buflen=256;
    char * buf=new char [buflen];
    File::readLine(buf, buflen, f); // comment line
    File::readLine(buf, buflen, f); // comment line
    File::readLine(buf, buflen, f); // comment line
    File::readLine(buf, buflen, f); // Perform NA or MC ?
    File::readLine(buf, buflen, f); // maximum number of iterations
    sscanf(buf,"%i", &itmax);
    File::readLine(buf, buflen, f); // sample size for initial population
    sscanf(buf,"%i", &nsamplei);
    File::readLine(buf, buflen, f); // sample size for remaining populations
    sscanf(buf,"%i", &nsample);
    fclose(f);
    delete [] buf;
  }
  // Calculate the number of models
  // Add one more model in case of ellipticity
  _n=nsamplei+itmax*nsample+MAX_HEADER_BLOCKS_COUNT;
}
bool QGpCompatibility::CompatInversionReport::startReadingBlock ( int  index,
BlockType  wantedType 
) [inline]

References _ptrStart, _s, TAG_LENGTH, and TRACE.

Referenced by QGpCompatibility::CompatAutocorrReport::addAutocorrGoal(), addDispersionGoal(), addEllipticityGoal(), QGpCompatibility::CompatAutocorrReport::addModel(), addModel(), addOmegas(), addParameter(), QGpCompatibility::CompatRefraReport::addRefraGoal(), QGpCompatibility::CompatAutocorrReport::modifyAutocorrGoal(), modifyDispersionGoal(), modifyEllipticityGoal(), QGpCompatibility::CompatRefraReport::modifyRefraGoal(), setCostValue(), setMaxOmegasCount(), and writeHeader().

{
  TRACE;
  if(_ptrStart) 
  {
    printf("You must call endWritingBlock before calling startWritingBlock\n");
    return false;
  }
  _s.device()->seek(TAG_LENGTH+sizeof(int)*(index+1));
  qint32 tmp;
  _s >> tmp;
  _ptrStart=tmp;
  if(_ptrStart) {
    int blockType;
    _s.device()->seek(_ptrStart);
    _s >> blockType;
    _ptrStart=-index-1;
#ifdef Q_WS_WIN
    // Under Windows it seems that there some difference between read and write
    // pointers, the next line update the write pointer 
    _s.device()->seek(_s.device()->pos());
#endif
    return (blockType==wantedType);
  }
  return false;
}

References _n, _ptrStart, _s, _trueN, and TRACE.

{
  TRACE;
  ASSERT(!_ptrStart);
  if(_trueN<_n) {
    _s.device()->seek(_s.device()->size());
    _ptrStart=_s.device()->pos();
    _s << wantedType;
  }
  else return false;
  return true;
}
void QGpCompatibility::CompatInversionReport::statDispersion ( int  ipoint,
int  imode,
int  start_model,
int  end_model,
double &  mean,
double &  stddev 
)

References _currentDispersion, loadDispersion(), QGpCoreTools::sqrt(), TRACE, and QGpCompatibility::CompatMultiModalCurves::value().

{
  TRACE;
  mean=0;
  stddev=0;
  for(int i=start_model;i<=end_model;i++) {
    loadDispersion(i);
    double xi=1/_currentDispersion->value(ipoint,imode);
    mean+=xi;
    stddev+=xi*xi;
  }
  int count=end_model-start_model+1;
  mean/=(double)count;
  stddev=sqrt((stddev/(double)count)-mean*mean);
}

References _n, _s, _version, endWritingBlock(), FILE_TAG, flush(), Information, startWritingBlock(), TAG_LENGTH, and TRACE.

Referenced by CompatInversionReport().

{
  TRACE;
  // Reset file ptr to the beginning of file
  _s.device()->seek(0);
  // Write tag (TAG_LENGTH-1 bytes)
  _s.writeRawData(FILE_TAG,TAG_LENGTH);
  // max number of binary blocks (1 for parameters+
  //                              1 for omegas+
  //                              1 for goal dispersion+
  //                              n models)
  // may be less if process stopped
  _s << _n;   
  // initialize table to null
  int a=0;
  for(int i=0;i<_n;i++) _s << a;
  static_cast<QFile *>(_s.device())->flush();
  // initialize information block (any information can be added, changing the version)
  startWritingBlock(Information);
  _s << (int) _version; // Version
  _s << (int) 0; // space for the max number of omegas in all dispersion blocks
  _s << (int) 0; // space for the max number of omegas in all ellipticities blocks
  endWritingBlock();  
  // initialize parameter table with nd (parameters count) to null
  startWritingBlock(Parameters);  
  _s << a;
  endWritingBlock();
}
void QGpCompatibility::CompatInversionReport::writeNAModel ( float *  naModel) [inline, protected]

References _nd, _s, and TRACE.

Referenced by QGpCompatibility::CompatAutocorrReport::addModel(), and addModel().

{
  TRACE;
  if(naModel)
    _s.writeRawData((char *)naModel,_nd*sizeof(float));
  else {
    double * tmp=new double [_nd];
    _s.writeRawData((char *)tmp,_nd*sizeof(float));
    delete [] tmp;
  }
}

Member Data Documentation

Referenced by flush().

Referenced by CompatInversionReport().


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