00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef FILE_SELDONDATA_FORMAT_HXX
00019
00020 #include <stdio.h>
00021 #include <iostream>
00022 using std::cout;
00023 using std::endl;
00024 #include <string>
00025 #include <fstream>
00026 using namespace std;
00027
00028 #ifdef SELDONDATA_WITH_NETCDF
00029 #include "netcdfcpp.h"
00030 #endif
00031
00032 #ifdef SELDONDATA_WITH_GRIB
00033 #include "decode_grib.cpp"
00034 #endif
00035
00036 namespace SeldonData
00037 {
00038
00040 class Format
00041 {
00042
00043 protected:
00044
00045 public:
00046 Format() throw();
00047 ~Format() throw();
00048
00049 };
00050
00051
00053 template<class T>
00054 class FormatBinary: public Format
00055 {
00056
00057 protected:
00058
00059 public:
00060 FormatBinary() throw();
00061 ~FormatBinary() throw();
00062
00063
00064
00065 template<class TG>
00066 void Read(string FileName, RegularGrid<TG>& G) const;
00067 template<class TG>
00068 void Read(ExtStream& FileStream, RegularGrid<TG>& G) const;
00069 template<class TG>
00070 void Read(ifstream& FileStream, RegularGrid<TG>& G) const;
00071 template<class TG, int N>
00072 void Read(string FileName, GeneralGrid<TG, N>& G) const;
00073 template<class TG, int N>
00074 void Read(ExtStream& FileStream, GeneralGrid<TG, N>& G) const;
00075 template<class TG, int N>
00076 void Read(ifstream& FileStream, GeneralGrid<TG, N>& G) const;
00077
00078 template<class TG>
00079 void Write(RegularGrid<TG>& G, string FileName) const;
00080 template<class TG>
00081 void Write(RegularGrid<TG>& G, ofstream& FileStream) const;
00082 template<class TG, int N>
00083 void Write(GeneralGrid<TG, N>& G, string FileName) const;
00084 template<class TG, int N>
00085 void Write(GeneralGrid<TG, N>& G, ofstream& FileStream) const;
00086
00087 template<class TG>
00088 void Append(RegularGrid<TG>& G, string FileName) const;
00089 template<class TG, int N>
00090 void Append(GeneralGrid<TG, N>& G, string FileName) const;
00091
00092
00093
00094 template<class TD, int N, class TG>
00095 void Read(string FileName, Data<TD, N, TG>& D) const;
00096 template<class TD, int N, class TG>
00097 void Read(ExtStream& FileStream, Data<TD, N, TG>& D) const;
00098 template<class TD, int N, class TG>
00099 void Read(ifstream& FileStream, Data<TD, N, TG>& D) const;
00100
00101 template<class TD, int N, class TG>
00102 void ReadSteps(string FileName, int steps, Data<TD, N, TG>& D) const;
00103 template<class TD, int N, class TG>
00104 void ReadRecord(string FileName, int steps, Data<TD, N, TG>& D) const;
00105
00106 template<class TD, int N, class TG>
00107 void Write(Data<TD, N, TG>& D, string FileName) const;
00108 template<class TD, int N, class TG>
00109 void Write(Data<TD, N, TG>& D, ofstream& FileStream) const;
00110
00111 template<class TD, int N, class TG>
00112 void Append(Data<TD, N, TG>& D, string FileName) const;
00113
00114
00115
00116 template<class TA, int N>
00117 void Read(string FileName, Array<TA, N>& A) const;
00118 template<int N>
00119 void Read(ExtStream& FileStream, Array<T, N>& A) const;
00120 template<int N>
00121 void Read(ifstream& FileStream, Array<T, N>& A) const;
00122 template<class TA, int N>
00123 void Read(ExtStream& FileStream, Array<TA, N>& A) const;
00124 template<class TA, int N>
00125 void Read(ifstream& FileStream, Array<TA, N>& A) const;
00126
00127 template<class TA, int N>
00128 void ReadSteps(string FileName, int steps, Array<TA, N>& A) const;
00129 template<class TA, int N>
00130 void ReadRecord(string FileName, int steps, Array<TA, N>& A) const;
00131
00132 template<class TA, int N>
00133 void Write(Array<TA, N>& A, string FileName) const;
00134 template<int N>
00135 void Write(Array<T, N>& A, ofstream& FileStream) const;
00136 template<class TA, int N>
00137 void Write(Array<TA, N>& A, ofstream& FileStream) const;
00138
00139 template<class TA, int N>
00140 void Append(Array<TA, N>& A, string FileName) const;
00141
00142 };
00143
00144
00146 class FormatText: public Format
00147 {
00148
00149 protected:
00150 string separator_;
00151 fstream::fmtflags flags_;
00152 streamsize precision_;
00153 streamsize width_;
00154
00155 public:
00156 FormatText() throw();
00157 FormatText(string separator) throw();
00158 FormatText(fstream::fmtflags flags, string separator = "\t\t") throw();
00159 FormatText(fstream::fmtflags flags, streamsize precision,
00160 streamsize width = -1, string separator = "\t\t") throw();
00161 ~FormatText() throw();
00162
00163 void SetSeparator(string separator);
00164 void SetFlags(ofstream::fmtflags flags);
00165 void SetPrecision(streamsize precision);
00166 void SetWidth(streamsize width);
00167
00168
00169
00170 template<class TG>
00171 void Read(string FileName, RegularGrid<TG>& G) const;
00172 template<class TG>
00173 void Read(ifstream& FileStream, RegularGrid<TG>& G) const;
00174 template<class TG, int N>
00175 void Read(string FileName, GeneralGrid<TG, N>& G) const;
00176 template<class TG, int N>
00177 void Read(ifstream& FileStream, GeneralGrid<TG, N>& G) const;
00178
00179 template<class TG>
00180 void Write(RegularGrid<TG>& G, string FileName) const;
00181 template<class TG>
00182 void Write(RegularGrid<TG>& G, ofstream& FileStream) const;
00183 template<class TG, int N>
00184 void Write(GeneralGrid<TG, N>& G, string FileName) const;
00185 template<class TG, int N>
00186 void Write(GeneralGrid<TG, N>& G, ofstream& FileStream) const;
00187
00188
00189
00190 template<class TD, int N, class TG>
00191 void Read(string FileName, Data<TD, N, TG>& D) const;
00192 template<class TD, int N, class TG>
00193 void Read(ifstream& FileStream, Data<TD, N, TG>& D) const;
00194
00195 template<class TD, int N, class TG>
00196 void Write(Data<TD, N, TG>& D, string FileName) const;
00197 template<class TD, int N, class TG>
00198 void Write(Data<TD, N, TG>& D, ofstream& FileStream) const;
00199
00200
00201
00202 template<class TA, int N>
00203 void Read(string FileName, Array<TA, N>& A) const;
00204 template<class TA, int N>
00205 void Read(ifstream& FileStream, Array<TA, N>& A) const;
00206 template<class TA>
00207 void Read(ifstream& FileStream, Array<TA, 1>& A) const;
00208
00209 template<class TA, int N>
00210 void Write(Array<TA, N>& A, string FileName) const;
00211 template<class TA, int N>
00212 void Write(Array<TA, N>& A, ofstream& FileStream) const;
00213
00214 };
00215
00216
00218 class FormatFormattedText: public Format
00219 {
00220
00221 protected:
00223 string format_;
00225 string comments_;
00227 string delimiters_;
00229 vector<string> info_str;
00231 vector<int> info_nb0;
00233 vector<int> info_nb1;
00234
00235 private:
00236 void SetVectors();
00237 void SkipMarkup(ExtStream&, streampos pos, int) const;
00238 template <class T>
00239 int ReadMarkup(ExtStream&, streampos pos, int, T*, int) const;
00240
00241 public:
00242 FormatFormattedText(string format,
00243 string comments = "#%",
00244 string delimiters = " \t:;,|\n");
00245 ~FormatFormattedText();
00246
00247 string GetFormat() const;
00248 string GetDelimiters() const;
00249 string GetComments() const;
00250
00251 void SetFormat(string format);
00252 void SetDelimiters(string delimiters);
00253 void SetComments(string comments);
00254
00255
00256
00257 template<class TG>
00258 void Read(string FileName, string extract, RegularGrid<TG>& G) const;
00259 template<class TG>
00260 void Read(ExtStream& FileStream, string extract, RegularGrid<TG>& G) const;
00261 template<class TG, int N>
00262 void Read(string FileName, string extract, GeneralGrid<TG, N>& G) const;
00263 template<class TG, int N>
00264 void Read(ExtStream& FileStream, string extract, GeneralGrid<TG, N>& G) const;
00265
00266
00267
00268 template<class TD, int N, class TG>
00269 void Read(string FileName, string extract, Data<TD, N, TG>& D) const;
00270 template<class TD, int N, class TG>
00271 void Read(ExtStream& FileStream, string extract, Data<TD, N, TG>& D) const;
00272
00273
00274
00275 template<class TA, int N>
00276 void Read(string FileName, string extract, Array<TA, N>& A) const;
00277 template<class TA, int N>
00278 void Read(ExtStream& FileStream, string extract, Array<TA, N>& A) const;
00279
00280 };
00281
00282
00283 #ifdef SELDONDATA_WITH_NETCDF
00285 template<class T>
00286 class FormatNetCDF: public Format
00287 {
00288
00289 protected:
00290
00291 public:
00292 FormatNetCDF() throw();
00293 ~FormatNetCDF() throw();
00294
00295
00296
00297 template<class TG>
00298 void Read(string FileName, string variable, RegularGrid<TG>& G) const;
00299 template<class TG, int N>
00300 void Read(string FileName, string variable, GeneralGrid<TG, N>& G) const;
00301
00302
00303
00304 template<class TD, int N, class TG>
00305 void Read(string FileName, string variable, Data<TD, N, TG>& D) const;
00306
00307
00308
00309 template<class TA, int N>
00310 void Read(string FileName, string variable, Array<TA, N>& A) const;
00311
00312 };
00313 #endif
00314
00315
00316 #ifdef SELDONDATA_WITH_GRIB
00318 class FormatGrib: public Format
00319 {
00320
00321 protected:
00322
00323 public:
00324 FormatGrib() throw();
00325 ~FormatGrib() throw();
00326
00327
00328
00329 template<class TG>
00330 void Read(string FileName, int variable, RegularGrid<TG>& G) const;
00331 template<class TG, int N>
00332 void Read(string FileName, int variable, GeneralGrid<TG, N>& G) const;
00333
00334
00335
00336 template<class TD, int N, class TG>
00337 void Read(string FileName, int variable, Data<TD, N, TG>& D) const;
00338
00339
00340
00341 template<class TA, int N>
00342 void Read(string FileName, int variable, Array<TA, N>& A) const;
00343
00344 };
00345 #endif
00346
00347
00349 class FormatChimere: public Format
00350 {
00351
00352 protected:
00353 int date_;
00354
00355 public:
00356 FormatChimere() throw();
00357 FormatChimere(int date) throw();
00358 ~FormatChimere() throw();
00359
00360 void SetDate(int date);
00361 int GetDate() const;
00362
00363
00364
00365 template<class TD, int N, class TG>
00366 void Read(string FileName, Data<TD, N, TG>& D,
00367 int nb_lines = -1) const;
00368 template<class TD, int N, class TG>
00369 void Read(ifstream& FileStream, Data<TD, N, TG>& D,
00370 int nb_lines = -1) const;
00371
00372
00373
00374 template<class TA, int N>
00375 void Read(string FileName, Array<TA, N>& A,
00376 int nb_lines = -1) const;
00377 template<class TA, int N>
00378 void Read(ifstream& FileStream, Array<TA, N>& A,
00379 int nb_lines = -1) const;
00380
00381 };
00382
00383 }
00384
00385 #define FILE_SELDONDATA_FORMAT_HXX
00386 #endif