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