00001 #ifndef __TSOPT_SEGYPP
00002 #define __TSOPT_SEGYPP
00003
00004 #include "space.hh"
00005 #include "locallinalg.hh"
00006 #include "ocdc.hh"
00007 #include "su.h"
00008 #include "header.h"
00009 #include "segy.h"
00010 #include "parserdecl.hh"
00011 #include "iwave_fopen.h"
00012 #include "utils.h"
00013
00014
00015
00016
00017
00018
00019
00020
00021 namespace RVL {
00022
00023 template<>
00024 size_t getDataSize<segy>(segy const & md);
00025 template<>
00026 float * newData<float,segy>(segy & md);
00027 template<>
00028 void deleteData<float,segy>(float ** d,segy ** md);
00029 template<>
00030 ostream & writeMeta<segy>(segy const & md, ostream & s);
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 }
00048
00049
00050 int count_unique_flthdr(std::string fpath, std::string key, float tol=1.e-3);
00051
00052 namespace TSOpt {
00053
00054 using RVL::getDataSize;
00055 using RVL::newData;
00056 using RVL::deleteData;
00057 using RVL::ContentPackage;
00058 using RVL::PackageContainer;
00059 using RVL::PackageContainerFactory;
00060 using RVL::OCDC;
00061 using RVL::STRING_PAIR;
00062
00063 using RVL::ConstContainer;
00064 using RVL::Space;
00065 using RVL::StdSpace;
00066 using RVL::Vector;
00067 using RVL::DataContainer;
00068 using RVL::DataContainerFactory;
00069 using RVL::FunctionObject;
00070 using RVL::FunctionObjectScalarRedn;
00071 using RVL::LinearAlgebraPackage;
00072 using RVL::RVLLinearAlgebraPackage;
00073 using RVL::RVLException;
00074 using RVL::Writeable;
00075
00077 typedef ContentPackage<float,segy> segytrace;
00078
00079
00080 class segygen;
00081
00122 class SEGYDC: public OCDC<float,segy> {
00123
00124 private:
00125
00126 string hdr;
00127 mutable segy tr;
00128 segytrace * buf;
00129 mutable FILE * fp;
00130 mutable bool rd;
00131 mutable off_t off_cur;
00132 ostream & outfile;
00133
00134 FILE * fph;
00135 off_t off_eof;
00136 int nb;
00137 int ns;
00138 int dt;
00139
00140 SEGYDC();
00141 SEGYDC(SEGYDC const &);
00142
00143 protected:
00144
00145 void open_p() const;
00146 segytrace & get(bool & more);
00147 segytrace const & get(bool & more) const;
00148 void put() const;
00149 void reset() const;
00150
00151 public:
00152
00155 SEGYDC(string _hdr, ostream & _outfile = cerr);
00157 ~SEGYDC();
00158
00159 string getHdr() const { return hdr; }
00160 ostream & write(ostream & str) const;
00161
00162 };
00163
00171 class SEGYDCF: public PackageContainerFactory<float,segy> {
00172
00173 private:
00174
00175
00176 string hdr;
00177 ostream & outfile;
00178
00179
00180 mutable int nb;
00181 mutable int nt;
00182 mutable float dt;
00183 mutable bool iflag;
00184 void init() const;
00185
00186 SEGYDCF();
00187
00188 protected:
00189
00192 SEGYDC * buildSEGY() const {
00193 init();
00194 return new SEGYDC(hdr,outfile);
00195 }
00196 PackageContainer<float,segy> * buildPC() const {
00197 return buildSEGY();
00198 }
00199
00200 public:
00201
00203 SEGYDCF(string _hdr, ostream & _outfile=cerr);
00204
00206 SEGYDCF(SEGYDCF const & f)
00207 : hdr(f.hdr), outfile(f.outfile), iflag(false) {}
00208
00209 ~SEGYDCF() {}
00210
00212 SEGYDCF * cloneSEGY() const {
00213 return new SEGYDCF(*this);
00214 }
00215
00216 PackageContainerFactory<float,segy> * clone() const {
00217 return cloneSEGY();
00218 }
00219
00221 string getFilename() const { return hdr; }
00222
00225 float getDt() const { init(); return dt; }
00226
00228 int getNt() const { init(); return nt; }
00229
00231 int getNB() const { init(); return nb; }
00232
00234 bool compare( DataContainerFactory const & dcf) const;
00236 bool isCompatible( DataContainer const & dc ) const;
00238 ostream & write(ostream & str) const;
00239 };
00240
00242 class SEGYSpace: public StdSpace<float,float>,
00243 public ConstContainer<STRING_PAIR> {
00244
00245 private:
00246
00247 SEGYDCF f;
00248 RVLLinearAlgebraPackage<float> l;
00249
00250 protected:
00251
00252 Space<float> * clone() const {
00253 return new SEGYSpace(*this);
00254 }
00255
00256 public:
00257
00258 SEGYSpace(string hdr, string key, ostream & outfile = cerr)
00259 : StdSpace<float,float>(),
00260
00261 ConstContainer<STRING_PAIR>(STRING_PAIR(key,hdr)),
00262 f(hdr,outfile),
00263 l(f.getDt()) {}
00264 SEGYSpace(SEGYSpace const & sp)
00265 : StdSpace<float,float>(sp),
00266 ConstContainer<STRING_PAIR>(sp.get()),
00267 f(sp.f), l(sp.l) {}
00268 ~SEGYSpace() {}
00269
00270
00271
00272
00273 DataContainerFactory const & getDCF() const { return f; }
00274 LinearAlgebraPackage<float> const & getLAP() const { return l; }
00275
00277 string getPrototypeFilename() const { return f.getFilename(); }
00278
00280 float getDt() const {
00281 try {
00282 return f.getDt(); }
00283 catch (RVLException & e) {
00284 e<<"\ncalled from SEGYSpace::getDt\n";
00285 throw e;
00286 }
00287 }
00289 int getNt() const {
00290 try {
00291 return f.getNt(); }
00292 catch (RVLException & e) {
00293 e<<"\ncalled from SEGYSpace::getNt\n";
00294 throw e;
00295 }
00296 }
00297
00298 ostream & write(ostream & str) const;
00299 };
00300
00301 }
00302
00303 #endif