00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef INVERSIONREPORT_H
00029 #define INVERSIONREPORT_H
00030
00031 #include <QGpCoreWave.h>
00032
00033 #include "QGpCompatibilityDLLExport.h"
00034
00035 namespace QGpCompatibility {
00036
00037 class CompatMultiModalFrequency;
00038 class CompatEllipticity;
00039 class CompatEllipticityData;
00040 class CompatMultiModalCurves;
00041 class CompatDispersion;
00042 class CompatDispersionData;
00043
00044 class QGPCOMPATIBILITY_EXPORT CompatInversionReport
00045 {
00046
00047
00048
00049
00050
00051 public:
00052
00053 CompatInversionReport(bool isWrite, QString reportFile, QString naInFile=QString::null, int nModels=0);
00054
00055 virtual ~CompatInversionReport();
00056
00057 static bool isReady(QString reportFile);
00058
00059 static bool isRightFormat(QString reportFile);
00060 bool isValid() {return _valid;}
00061
00062 virtual bool isA(const char * className);
00063
00064 const char * className() {return "CompatInversionReport";}
00065
00066 bool isRightFormat();
00067
00068 bool isSameParameter(const CompatInversionReport * otherModels) const;
00069
00070 void writeHeader();
00071 void setNFromNaIn(QString naInfile);
00072
00073 enum BlockType {Parameters, Omegas, DispersionGoal, ModelDispersion, AutocorrGoal,
00074 EllipticityGoal, FKMaxGoal, Information, Unknown, RefraGoal};
00075
00076 enum paramID {H, Vs, Vp, Rho, Depth, ExpGrad, ModeStdDev, NAParam};
00077
00078 BlockType reportType();
00079 void addParameter(paramID which,int layer);
00080 void addEllipticityGoal(CompatEllipticityData * ell);
00081 void modifyEllipticityGoal(CompatEllipticityData * ell);
00082
00083 void setCostValue(int imodel,double costValue);
00084
00085 bool startWritingBlock(int index,BlockType wantedType);
00086 bool startWritingBlock(BlockType type);
00087 void endWritingBlock();
00088 bool startReadingBlock(int index,BlockType wantedType);
00089
00090
00091 void flush();
00092
00093 void setFlushed(bool s) {_flushed=s;}
00094
00095 bool loadModel(int modelIndex=-1);
00096 void loadNAModel(int modelIndex=-1);
00097
00098 bool loadNextModel();
00099
00100 double loadCostValue(int modelIndex);
00101
00102 CompatEllipticityData * loadEllipticityGoal();
00103
00104 QString parameterName(int paramIndex);
00105
00106 double getParamValue(int paramIndex);
00107 paramID getParamType(int paramIndex) {return _paramAddresses[paramIndex].which;}
00108
00109 Seismic1DModel * currentModel();
00110
00111 float * currentNAModel();
00112
00113 double currentCost() {return _currentCost;}
00114
00115 int getID() {return _currentID;}
00116
00117
00118
00119
00120
00121 QVector<Point> * getBestFits(QVector<Point>& curve,
00122 int& startIndex,double& minCostValue,
00123 int& generatedModels);
00124
00125
00126 int getBestFit();
00127 void getNAParam(int& itmax, int& nsi, int& ns, int& nr);
00128
00129 int currentID() {return _currentID;}
00130 int dimension() {return _nd;}
00131 int countModels();
00132 void maxOmegasCount(int& dispCount, int& ellCount);
00133 int currentLoadingIndex() {return _currentIndex;}
00134
00135 QString reportName();
00136 QString reportFileName();
00137
00138 protected:
00139
00140 bool _valid;
00141
00142 QDataStream _s;
00143
00144 int _trueN;
00145
00146 int _currentIndex;
00147
00148 int _n;
00149
00150 int _nd;
00151 void setMaxOmegasCount(int dispCount, int ellCount);
00152 int _maxDispOmegaCount;
00153 int _maxEllOmegaCount;
00154
00155 struct paramAddress
00156 {
00157 paramID which;
00158 int layer;
00159 };
00160 paramAddress * _paramAddresses;
00161
00162 Seismic1DModel * _currentModel;
00163
00164 double _currentCost;
00165
00166 float * _currentNAModel;
00167
00168 CompatEllipticity * _currentEllipticity;
00169
00170 qint64 _ptrStart;
00171
00172 qint64 * _offsetTable;
00173
00174 bool loadParamAddresses();
00175
00176
00177
00178
00179 int _currentID;
00180
00181 QString _fileName;
00182
00183 bool initCurrentModel();
00184
00185 bool initCurrentEllipticity();
00186
00187
00188
00189
00190
00191
00192 bool _flushed;
00193
00194 int _headerBlocksCount;
00195
00196 int _version;
00197
00198 qint64 _blockParam, _blockOmegas, _blockGoal, _blockEll;
00199 void writeNAModel(float * naModel);
00200
00201
00202
00203
00204
00205 public:
00206
00207 bool isSameOmegas(const CompatInversionReport * otherModels) const;
00208
00209 bool isSameGoalDispersion(CompatInversionReport * otherModels);
00210 void addOmegas(CompatMultiModalFrequency * omegas);
00211 void addDispersionGoal(CompatDispersionData * rms);
00212
00213
00214
00215
00216
00217 void modifyDispersionGoal(CompatDispersionData * rms);
00218
00219 void addModel(const Seismic1DModel * model, float * naModel,
00220 const CompatDispersion * disp,
00221 double cost, int modelID=-1);
00222
00223 void addModel(const Seismic1DModel * model, float * naModel,
00224 const CompatDispersion * disp,
00225 const CompatEllipticity * ell,
00226 double cost, int modelID=-1);
00227
00228 bool loadDispersion(int modelIndex);
00229
00230 bool loadDispersion(CompatDispersion * disp, CompatEllipticity * ell,int modelIndex);
00231
00232 CompatDispersionData * loadDispersionGoal();
00233
00234 CompatDispersion * currentDispersion();
00235
00236 CompatEllipticity * currentEllipticity();
00237 int omegasCount();
00238 int modesCount();
00239
00240 void statDispersion(int ipoint,int imode,int start_model,int end_model,
00241 double& mean, double& stddev);
00242 protected:
00243
00244 CompatMultiModalCurves * _currentDispersion;
00245
00246 virtual bool initCurrentDispersion();
00247 };
00248
00249 }
00250
00251 #include "CompatDispersion.h"
00252
00253 namespace QGpCompatibility {
00254
00255 inline CompatDispersion * CompatInversionReport::currentDispersion()
00256 {
00257 TRACE;
00258 if(!_currentDispersion) initCurrentDispersion();
00259 return (CompatDispersion *)_currentDispersion;
00260 }
00261
00262 inline CompatEllipticity * CompatInversionReport::currentEllipticity()
00263 {
00264 TRACE;
00265 if(!_currentDispersion) initCurrentDispersion();
00266 return _currentEllipticity;
00267 }
00268
00269 inline int CompatInversionReport::omegasCount()
00270 {
00271 TRACE;
00272 if(!_currentDispersion) initCurrentDispersion();
00273 return _currentDispersion->omegasCount();
00274 }
00275
00276 inline int CompatInversionReport::modesCount()
00277 {
00278 TRACE;
00279 if(!_currentDispersion) initCurrentDispersion();
00280 return _currentDispersion->modesCount();
00281 }
00282
00283 inline bool CompatInversionReport::isSameOmegas(const CompatInversionReport * otherModels) const
00284 {
00285 TRACE;
00286 return _currentDispersion->isSameOmegas(otherModels->_currentDispersion);
00287 }
00288
00289 inline bool CompatInversionReport::startReadingBlock(int index,BlockType wantedType)
00290 {
00291 TRACE;
00292 if(index>=_trueN) {
00293 fprintf(stderr,"Model index out of range, max=%i, index=%i\n",_trueN-1,index);
00294 return false;
00295 }
00296 _s.device()->seek(_offsetTable[index]);
00297 int blockType=0;
00298 _s >> blockType;
00299 return (blockType==wantedType);
00300 }
00301
00302 inline void CompatInversionReport::writeNAModel(float * naModel)
00303 {
00304 TRACE;
00305 if(naModel)
00306 _s.writeRawData((char *)naModel,_nd*sizeof(float));
00307 else {
00308 double * tmp=new double [_nd];
00309 _s.writeRawData((char *)tmp,_nd*sizeof(float));
00310 delete [] tmp;
00311 }
00312 }
00313
00314 }
00315
00316 #endif // COMPATINVERSIONREPORT_H