segypp.hh

Go to the documentation of this file.
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 // uncomment for verbose output
00015 //#define FRUITCAKE
00016 
00017 /* forward declarations for CP<segy> functions, and specialization
00018    of pair extractor
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   template<>
00033   class PairExtractor< segy > {
00034   public:
00035     PairExtractor() {}
00036     PairExtractor(PairExtractor< segy > const &) {}
00037     ~PairExtractor() {}
00038     
00039     static STRING_PAIR extract(string in) {
00040       STRING_PAIR pr;
00041       pr.key="datafile";
00042       pr.val=in;
00043       return pr;
00044     }
00045   };
00046   */
00047 }
00048 
00049 // standalone global namespace function
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   //  using RVL::PairExtractor;
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   /* forward declaration */
00080   class segygen;
00081 
00122   class SEGYDC: public OCDC<float,segy> {
00123 
00124   private:
00125 
00126     string hdr;            // name of prototype SU file
00127     mutable segy tr;       // workspace for reads, proto for segytrace
00128     segytrace * buf;       // read buffer, get returns ref
00129     mutable FILE * fp;     // stream for data i/o
00130     mutable bool rd;       // set if last op is read, unset on write
00131     mutable off_t off_cur; // offset of current trace in bytes
00132     ostream & outfile;     // verbose output file
00133 
00134     FILE * fph;            // stream for prototype i/o
00135     off_t off_eof;         // prototype end-of-file offset in bytes
00136     int nb;                // prototype number of bytes per trace
00137     int ns;                // prototype number of samples per trace
00138     int dt;                // prototype sample rate
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     /* initialized on construction */
00176     string hdr;        // name of prototype file
00177     ostream & outfile; // verbose output stream
00178 
00179     /* post-construction initialization */
00180     mutable int nb;    // number of bytes for all traces
00181     mutable int nt;    // number of time samples
00182     mutable float dt;  // time step (scale in L2 norm)
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     //  ConstContainer<STRING_PAIR>(PairExtractor< segy >::extract(hdr)),
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     // can only be called by other spaces, since base class operator new is protected
00271     //    SEGYSpace * clone() { return new SEGYSpace(*this); }
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

Generated on 5 Jan 2017 for IWAVETRACE by  doxygen 1.4.7