00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00035 #ifndef gridded_fields_h
00036 #define gridded_fields_h
00037
00038 #include "matpackIV.h"
00039 #include "array.h"
00040 #include "mystring.h"
00041
00043 typedef enum {
00044 GRIDTYPE_NUMERIC,
00045 GRIDTYPE_STRING
00046 } GridType;
00047
00048 typedef Array<GridType> ArrayOfGridType;
00049
00051 class GField
00052 {
00053 private:
00054 Index dim;
00055 String mname;
00056 Array<GridType> mgridtypes;
00057 ArrayOfString mgridnames;
00058 Array<ArrayOfString> mstringgrids;
00059 ArrayOfVector mnumericgrids;
00060
00061 protected:
00063
00067 GField() : dim(0),
00068 mname(),
00069 mgridtypes(),
00070 mgridnames(),
00071 mstringgrids(),
00072 mnumericgrids()
00073 { };
00074
00076
00085 GField(const Index d, const String s) : dim(d),
00086 mname(s),
00087 mgridtypes(d, GRIDTYPE_NUMERIC),
00088 mgridnames(d),
00089 mstringgrids(d),
00090 mnumericgrids(d)
00091 { }
00092
00093
00094 public:
00096
00097 Index get_dim () const { return dim; }
00098
00099 void copy_grids (const GField& gf);
00100
00102
00108 const String& get_grid_name (Index i) const { return mgridnames[i]; }
00109
00110 Index get_grid_size (const Index i) const;
00111
00113
00119 GridType get_grid_type (Index i) const { return mgridtypes[i]; }
00120
00121 ConstVectorView get_numeric_grid (Index i) const;
00122
00123 VectorView get_numeric_grid (Index i);
00124
00125 const ArrayOfString& get_string_grid (Index i) const;
00126
00127 ArrayOfString& get_string_grid (Index i);
00128
00130
00131 const String& get_name () const { return mname; }
00132
00133 void set_grid (Index i, const Vector& g);
00134
00135 void set_grid (Index i, const ArrayOfString& g);
00136
00138
00144 void set_gridname (Index i, const String& s)
00145 {
00146 assert (i < dim);
00147 mgridnames[i] = s;
00148 };
00149
00151
00152 void set_name (const String& s) { mname = s; }
00153
00155
00162 virtual bool checksize() const { return false; };
00163
00165 virtual ~GField() { }
00166
00167 friend ostream& operator<<(ostream& os, const GField& gf);
00168 };
00169
00170
00171 class GField1: public GField, public Vector
00172 {
00173 public:
00175 GField1() : GField(1, "") {};
00177
00178 GField1(const String s) : GField(1, s) {};
00179
00181
00186 virtual bool checksize() const
00187 {
00188 return (nelem() == get_grid_size(0));
00189 }
00190
00192
00193 void resize(const GField1& gf)
00194 {
00195 Vector::resize(gf.get_grid_size(0));
00196 }
00197
00199
00200 void resize(Index n)
00201 {
00202 Vector::resize(n);
00203 }
00204
00205 friend ostream& operator<<(ostream& os, const GField1& gf);
00206 };
00207
00208
00209 class GField2: public GField, public Matrix
00210 {
00211 public:
00213 GField2() : GField(2, "") {};
00215
00216 GField2(const String s) : GField(2, s) {};
00217
00219
00224 virtual bool checksize() const
00225 {
00226 return (ncols() == get_grid_size(1)
00227 && nrows() == get_grid_size(0));
00228 }
00229
00231
00232 void resize(const GField2& gf)
00233 {
00234 Matrix::resize(gf.get_grid_size(0),
00235 gf.get_grid_size(1));
00236 }
00237
00239
00240 void resize(Index r, Index c)
00241 {
00242 Matrix::resize(r, c);
00243 }
00244
00245 friend ostream& operator<<(ostream& os, const GField2& gf);
00246 };
00247
00248
00249 class GField3: public GField, public Tensor3
00250 {
00251 public:
00253 GField3() : GField(3, "") {};
00255
00256 GField3(const String s) : GField(3, s) {};
00257
00258 GField3& operator=(Numeric n)
00259 {
00260 Tensor3::operator=(n);
00261
00262 return *this;
00263 }
00264
00266
00271 virtual bool checksize() const
00272 {
00273 return (ncols() == get_grid_size(2)
00274 && nrows() == get_grid_size(1)
00275 && npages() == get_grid_size(0));
00276 }
00277
00279
00280 void resize(const GField3& gf)
00281 {
00282 Tensor3::resize(gf.get_grid_size(0),
00283 gf.get_grid_size(1),
00284 gf.get_grid_size(2));
00285 }
00286
00288
00289 void resize(Index p, Index r, Index c)
00290 {
00291 Tensor3::resize(p, r, c);
00292 }
00293
00294 friend ostream& operator<<(ostream& os, const GField3& gf);
00295 };
00296
00297
00298 class GField4: public GField, public Tensor4
00299 {
00300 public:
00302 GField4() : GField(4, "") {};
00304
00305 GField4(const String s) : GField(4, s) {};
00306
00308
00313 virtual bool checksize() const
00314 {
00315 return (ncols() == get_grid_size(3)
00316 && nrows() == get_grid_size(2)
00317 && npages() == get_grid_size(1)
00318 && nbooks() == get_grid_size(0));
00319 }
00320
00322
00323 void resize(const GField4& gf)
00324 {
00325 Tensor4::resize(gf.get_grid_size(0),
00326 gf.get_grid_size(1),
00327 gf.get_grid_size(2),
00328 gf.get_grid_size(3));
00329 }
00330
00332
00333 void resize(Index b, Index p, Index r, Index c)
00334 {
00335 Tensor4::resize(b, p, r, c);
00336 }
00337
00338 friend ostream& operator<<(ostream& os, const GField4& gf);
00339 };
00340
00341
00342
00343
00344 ostream& operator<<(ostream& os, const GField& gf);
00345 ostream& operator<<(ostream& os, const GField1& gf);
00346 ostream& operator<<(ostream& os, const GField2& gf);
00347 ostream& operator<<(ostream& os, const GField3& gf);
00348 ostream& operator<<(ostream& os, const GField4& gf);
00349
00350
00351
00352
00353 typedef Array<GField1> ArrayOfGField1;
00354 typedef Array<GField2> ArrayOfGField2;
00355 typedef Array<GField3> ArrayOfGField3;
00356 typedef Array<GField4> ArrayOfGField4;
00357 typedef Array< Array<GField1> > ArrayOfArrayOfGField1;
00358 typedef Array< Array<GField3> > ArrayOfArrayOfGField3;
00359
00360 #endif
00361