00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011 #ifndef _DATAFILEIF_H_
00012 #define _DATAFILEIF_H_
00013
00014 #include <iostream>
00015 #include <fstream>
00016 using std::istream;
00017 using std::ifstream;
00018
00019 #include "MayDay.H"
00020 #include "RealVect.H"
00021 #include "IntVectSet.H"
00022 #include "FArrayBox.H"
00023 #include "RefCountedPtr.H"
00024
00025 #include "BaseIF.H"
00026
00027 #include "NamespaceHeader.H"
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 class DataFileIF: public BaseIF
00056 {
00057 public:
00058
00059
00060
00061
00062 enum DataType
00063 {
00064 Invalid = -1,
00065 ASCII = 0,
00066 Binary ,
00067 NUMDATATYPES
00068 };
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 DataFileIF(const DataFileIF::DataType& a_dataType,
00079 const Real& a_value,
00080 const bool& a_inside,
00081 const bool& a_useCubicInterp = false);
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 DataFileIF(const char* const a_filename,
00092 const DataFileIF::DataType& a_dataType,
00093 const Real& a_value,
00094 const bool& a_inside,
00095 const bool& a_useCubicInterp = false);
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 DataFileIF(const DataFileIF::DataType& a_dataType,
00107 const RealVect& a_spacing,
00108 const RealVect& a_origin,
00109 const Real& a_value,
00110 const bool& a_inside,
00111 const bool& a_useCubicInterp = false);
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 DataFileIF(const char* const a_filename,
00123 const DataFileIF::DataType& a_dataType,
00124 const RealVect& a_spacing,
00125 const RealVect& a_origin,
00126 const Real& a_value,
00127 const bool& a_inside,
00128 const bool& a_useCubicInterp = false);
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 DataFileIF(const DataFileIF::DataType& a_dataType,
00140 const IntVect& a_num,
00141 const RealVect& a_spacing,
00142 const RealVect& a_origin,
00143 const Real& a_value,
00144 const bool& a_inside,
00145 const bool& a_useCubicInterp = false);
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 DataFileIF(const char* const a_filename,
00157 const DataFileIF::DataType& a_dataType,
00158 const IntVect& a_num,
00159 const RealVect& a_spacing,
00160 const RealVect& a_origin,
00161 const Real& a_value,
00162 const bool& a_inside,
00163 const bool& a_useCubicInterp = false);
00164
00165
00166 DataFileIF(const DataFileIF& a_inputIF);
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 DataFileIF(const RefCountedPtr<FArrayBox> a_ascii_data,
00181 const RefCountedPtr<BaseFab<unsigned char> > a_binary_data,
00182 const Real& a_noDataValue,
00183 const IntVect& a_num,
00184 const RealVect& a_spacing,
00185 const RealVect& a_origin,
00186 const Real& a_value,
00187 const bool& a_inside,
00188 const bool& a_useCubicInterp = false);
00189
00190
00191 virtual ~DataFileIF();
00192
00193
00194
00195
00196
00197 virtual void GetHeader(IntVect& a_num,
00198 RealVect& a_spacing,
00199 RealVect& a_origin) const;
00200
00201
00202
00203
00204
00205 virtual void GetParams(Real& a_value,
00206 bool& a_inside,
00207 bool& a_useCubicInterp) const;
00208
00209
00210
00211
00212
00213 virtual void SetParams(const Real& a_value,
00214 const bool& a_inside,
00215 const bool& a_useCubicInterp = false);
00216
00217
00218
00219
00220
00221 virtual void SetNoDataValue(const Real& a_value);
00222
00223
00224
00225
00226
00227
00228
00229 virtual Real value(const RealVect& a_point) const;
00230
00231 virtual Real value(const IndexTM<Real,GLOBALDIM>& a_point) const;
00232
00233 virtual Real value(const IndexTM<int,GLOBALDIM> & a_partialDerivative,
00234 const IndexTM<Real,GLOBALDIM>& a_point) const;
00235
00236 virtual BaseIF* newImplicitFunction() const;
00237
00238 void GetFullHeader(IntVect& a_num,
00239 RealVect& a_spacing,
00240 RealVect& a_origin)
00241 {
00242 a_num = m_num;
00243 a_spacing = m_spacing;
00244 a_origin = m_origin;
00245 }
00246
00247 RefCountedPtr<FArrayBox> GetAsciiData(void)
00248 {
00249 return m_ascii_data;
00250 }
00251
00252 RefCountedPtr<BaseFab<unsigned char> > GetBinaryData(void)
00253 {
00254 return m_binary_data;
00255 }
00256
00257 protected:
00258 void OpenFile(ifstream& a_file,
00259 const char* const a_filename);
00260
00261 void CloseFile(ifstream& a_file);
00262
00263 void ReadMinHeader(IntVect& a_num,
00264 istream& a_file);
00265
00266 void ReadFullHeader(IntVect& a_num,
00267 RealVect& a_spacing,
00268 RealVect& a_origin,
00269 istream& a_file);
00270
00271 void ReadData(Real& a_maxValue,
00272 istream& a_file,
00273 const DataFileIF::DataType& a_dataType,
00274 const IntVect& a_num);
00275
00276 void MakeCorners(void);
00277
00278 IntVect m_num;
00279 RealVect m_spacing;
00280 RealVect m_origin;
00281
00282 Real m_value;
00283
00284 bool m_inside;
00285
00286
00287 RefCountedPtr<FArrayBox> m_ascii_data;
00288 RefCountedPtr<BaseFab<unsigned char> > m_binary_data;
00289
00290 Real m_noDataValue;
00291
00292 IntVectSet m_cornersLinear;
00293 IntVectSet m_cornersCubic;
00294
00295 bool m_useCubicInterp;
00296
00297 private:
00298 DataFileIF()
00299 {
00300 MayDay::Abort("DataFileIF uses strong construction");
00301 }
00302
00303 void operator=(const DataFileIF& a_inputIF)
00304 {
00305 MayDay::Abort("DataFileIF doesn't allow assignment");
00306 }
00307 };
00308
00309 #include "NamespaceFooter.H"
00310 #endif