Format.hxx

00001 // Copyright (C) 2003-2007, ENPC - INRIA - EDF R&D
00002 // Author(s): Vivien Mallet
00003 //
00004 // This file is part of AtmoData library, a tool for data processing in
00005 // atmospheric sciences.
00006 //
00007 // AtmoData is developed in the INRIA - ENPC joint project-team CLIME and in
00008 // the ENPC - EDF R&D joint laboratory CEREA.
00009 //
00010 // AtmoData is free software; you can redistribute it and/or modify it under
00011 // the terms of the GNU General Public License as published by the Free
00012 // Software Foundation; either version 2 of the License, or (at your option)
00013 // any later version.
00014 //
00015 // AtmoData is distributed in the hope that it will be useful, but WITHOUT ANY
00016 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
00018 // details.
00019 //
00020 // For more information, visit the AtmoData home page:
00021 //      http://cerea.enpc.fr/polyphemus/atmodata.html
00022 
00023 
00024 #ifndef ATMODATA_FILE_FORMAT_HXX
00025 
00026 namespace AtmoData
00027 {
00028 
00030   class FormatCSV: public Format
00031   {
00032 
00033   protected:
00034 
00035   public:
00036     FormatCSV()  throw();
00037     ~FormatCSV()  throw();
00038 
00039     // Data.
00040 
00041     template<class TD, int N, class TG,
00042              class TS, class TGS>
00043     void Read(string FileName, Data<TD, N, TG>& D,
00044               Data<TS, 1, TGS>& S) const;
00045     template<class TD, int N, class TG,
00046              class TS, class TGS>
00047     void Read(ifstream& FileStream, Data<TD, N, TG>& D,
00048               Data<TS, 1, TGS>& S) const;
00049 
00050     // Array.
00051 
00052     template<class TA, int N,
00053              class TS, class TGS>
00054     void Read(string FileName, Array<TA, N>& A,
00055               Data<TS, 1, TGS>& S) const;
00056     template<class TA, int N,
00057              class TS, class TGS>
00058     void Read(ifstream& FileStream, Array<TA, N>& A,
00059               Data<TS, 1, TGS>& S) const;
00060 
00061   };
00062 
00064   template<class T>
00065   class FormatECMWF: public Format
00066   {
00067 
00068   protected:
00070     int date_;
00071 
00072   public:
00073     FormatECMWF()  throw();
00074     FormatECMWF(int date)  throw();
00075     ~FormatECMWF()  throw();
00076 
00077     void SetDate(int date);
00078     int GetDate() const;
00079 
00080     // Data.
00081 
00082     template<class TD, int N, class TG>
00083     void Read(string FileName, Data<TD, N, TG>& D) const;
00084     template<class TD, int N, class TG>
00085     void Read(ifstream& FileStream, Data<TD, N, TG>& D) const;
00086 
00087     // Array.
00088 
00089     template<class TA, int N>
00090     void Read(string FileName, Array<TA, N>& A) const;
00091     template<int N>
00092     void Read(ifstream& FileStream, Array<T, N>& A) const;
00093     template<class TA, int N>
00094     void Read(ifstream& FileStream, Array<TA, N>& A) const;
00095 
00096   };
00097 
00098   // For MM5 sub-headers.
00099   class MM5SubHeader;
00100 
00102   class FormatMM5: public Format
00103   {
00104 
00105   protected:
00106 
00107   public:
00108     FormatMM5()  throw();
00109     ~FormatMM5()  throw();
00110 
00111     // Flag.
00112     int ReadFlag(ifstream& FileStream) const;
00113 
00114     // Big header.
00115     void ReadBigHeader(string FileName,
00116                        Array<int, 2>& BHI, Array<float, 2>& BHR,
00117                        Array<string, 2>& BHIC, Array<string, 2>& BHRC) const;
00118     void ReadBigHeader(ifstream& FileStream,
00119                        Array<int, 2>& BHI, Array<float, 2>& BHR,
00120                        Array<string, 2>& BHIC, Array<string, 2>& BHRC) const;
00121     void ReadBigHeader(ifstream& FileStream) const;
00122 
00123     // Sub-header.
00124     void ReadSubHeader(ifstream& FileStream, MM5SubHeader& SH) const;
00125     void ReadSubHeader(ifstream& FileStream) const;
00126 
00127     // Field.
00128     template <int N, class TG>
00129     void ReadWholeField(string FileName, string FieldName,
00130                         Data<float, N, TG>& A) const;
00131     template <int N>
00132     void ReadWholeField(string FileName, string FieldName,
00133                         Array<float, N>& A) const;
00134     template <int N, class TG>
00135     void ReadWholeField(ifstream& FileStream, string FieldName,
00136                         Data<float, N, TG>& A) const;
00137     template <int N>
00138     void ReadWholeField(ifstream& FileStream, string FieldName,
00139                         Array<float, N>& A) const;
00140     template <int N>
00141     void ReadField(ifstream& FileStream, bool cross,
00142                    Array<float, N>& A) const;
00143     template <int N, class TG>
00144     void ReadField(ifstream& FileStream, Data<float, N, TG>& A) const;
00145     template <int N>
00146     void ReadField(ifstream& FileStream, MM5SubHeader& SH,
00147                    Array<float, N>& A) const;
00148     template <int N>
00149     void ReadField(ifstream& FileStream, Array<float, N>& A) const;
00150     void ReadField(ifstream& FileStream) const;
00151 
00152   };
00153 
00155   class MM5SubHeader
00156   {
00157 
00158   public:
00160     int ndim;
00162     Array<int, 1> start_index;
00164     Array<int, 1> end_index;
00166     float xtime;
00168     string staggering;
00170     string ordering;
00172     string current_date;
00174     string name;
00176     string unit;
00178     string description;
00179 
00180   public:
00181     MM5SubHeader()  throw();
00182     MM5SubHeader(const MM5SubHeader&)  throw();
00183     ~MM5SubHeader()  throw();
00184 
00185     void Init();
00186     MM5SubHeader& operator=(MM5SubHeader&);
00187     string GetCurrentDate();
00188 
00189   };
00190 
00191 }  // namespace AtmoData.
00192 
00193 
00194 #define ATMODATA_FILE_FORMAT_HXX
00195 #endif

Generated on Tue Nov 17 11:51:45 2009 for AtmoData by  doxygen 1.5.1