00001 #ifndef __TSOPT_GRIDPP
00002 #define __TSOPT_GRIDPP
00003
00004
00005
00006
00007 #define MAX_NAMELEN 128
00008
00009 #include "space.hh"
00010 #include "locallinalg.hh"
00011 #include "ocdc.hh"
00012 #include "parserdecl.hh"
00013 #include "iwave_fopen.h"
00014 #include "grid.h"
00015 #include "gridio.h"
00016 #include "rarray.h"
00017 #include "write.hh"
00018
00019 namespace RVL {
00020
00021 template<>
00022 size_t getDataSize<RARR>(RARR const & a);
00023
00024 template<>
00025 ireal * newData<ireal,RARR>(RARR & md);
00026
00027 template<>
00028 void deleteData<ireal,RARR>(ireal ** d,RARR ** md);
00029
00030 template<>
00031 ostream & writeMeta<RARR>(RARR const & md, ostream & s);
00032
00033 }
00034
00035 namespace TSOpt {
00036
00037 using RVL::OCDC;
00038 using RVL::ConstContainer;
00039 using RVL::STRING_PAIR;
00040 using RVL::RVLException;
00041 using RVL::ScalarFieldTraits;
00042 using RVL::DataContainer;
00043 using RVL::ContentPackage;
00044 using RVL::PackageContainer;
00045 using RVL::DataContainerFactory;
00046 using RVL::PackageContainerFactory;
00047 using RVL::getDataSize;
00048 using RVL::Writeable;
00049 using RVL::Space;
00050 using RVL::StdSpace;
00051 using RVL::LinearAlgebraPackage;
00052 using RVL::RVLLinearAlgebraPackage;
00053 using RVL::parse;
00054
00055 class GridDC: public OCDC<ireal, RARR> {
00056
00057 private:
00058
00059
00060 string const & protohdr;
00061 string const & protodata;
00062 grid const & protog;
00063 string data_format;
00064 ostream & outfile;
00065
00066
00067 mutable FILE * fph;
00068 mutable FILE * fp;
00069 mutable string datafile;
00070
00071
00072 mutable ContentPackage<ireal,RARR> buf;
00073 mutable int panelindex;
00074 int panelnum;
00075 mutable bool rd;
00076
00077 GridDC();
00078 GridDC(GridDC const &);
00079
00080 protected:
00081
00084 void open_p() const;
00085 ContentPackage<ireal,RARR> & get(bool & more);
00086 ContentPackage<ireal,RARR> const & get(bool & more) const;
00087 void put() const;
00088 void reset() const;
00089
00090 public:
00091
00100 GridDC(string const & _protohdr,
00101 string const & _protodata,
00102 grid const & _protog,
00103 string const & _data_format,
00104 string data_type,
00105 bool incore = false,
00106 ostream & _outfile = cerr);
00108 ~GridDC();
00109 bool isInCore() const;
00110 string getProtohdr() const;
00111 ostream & write(ostream & str) const;
00112
00113 };
00114
00117 class GridDCF: public PackageContainerFactory<ireal, RARR> {
00118
00119 private:
00120
00121 string protohdr;
00122 string protodata;
00123 string data_format;
00124 string data_type;
00125 ostream & outfile;
00126 grid protog;
00127 ireal scfac;
00128 bool incore;
00129 ireal vol;
00130
00131 GridDCF();
00132
00133 protected:
00134
00135 GridDC * buildGridDC() const;
00136 PackageContainer<ireal, RARR> * buildPC() const;
00137
00138 public:
00139
00146 GridDCF(string _protohdr, bool _incore=false, ostream & _outfile = cerr);
00147
00150 GridDCF(GridDCF const & f);
00151 ~GridDCF();
00152
00153 PackageContainerFactory<ireal, RARR> * clone() const;
00154 grid const & getGrid() const;
00155 ireal getCellVol() const;
00156 ireal getScaleFactor() const;
00157 string getFilename() const;
00158 bool compare( DataContainerFactory const & dcf) const;
00159
00160
00161
00162
00163 bool isCompatible( DataContainer const & dc ) const;
00164 bool isIncore() const;
00165 ostream & write(ostream & str) const;
00166
00167 };
00168
00170 class GridSpace: public StdSpace<ireal,ireal>,
00171 public ConstContainer<STRING_PAIR> {
00172
00173 private:
00174
00175 GridDCF f;
00176 RVLLinearAlgebraPackage<ireal> l;
00177
00183 STRING_PAIR getPTblEntry(grid const & g,
00184 std::string tag,
00185 std::string & thdr,
00186 std::string fmt);
00187
00188 protected:
00189
00190 Space<float> * clone() const {
00191 return new GridSpace(*this);
00192 }
00193
00194 public:
00195
00212 GridSpace(string hdr,
00213 string dtype = "notype",
00214 bool incore = false,
00215 ostream & outfile = cerr);
00216
00225 GridSpace(grid const & g,
00226 std::string tag,
00227 std::string thdr="",
00228 std::string fmt="native_ireal",
00229 bool incore=false,
00230 ostream & outfile = cerr);
00231 GridSpace(GridSpace const & sp);
00232 ~GridSpace();
00233
00234 LinearAlgebraPackage<ireal> const & getLAP() const;
00235 DataContainerFactory const & getDCF() const;
00236 grid const & getGrid() const;
00237 bool isIncore() const;
00238 ostream & write(ostream & str) const;
00239 };
00240 }
00241
00242 #endif