1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #ifndef __MEDFILEPARAMETER_HXX__
22 #define __MEDFILEPARAMETER_HXX__
24 #include "MEDLoaderDefines.hxx"
25 #include "MEDFileUtilities.hxx"
26 #include "MEDCouplingMemArray.hxx"
27 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
31 class MEDLOADER_EXPORT MEDFileParameter1TS : public RefCountObject
34 virtual MEDFileParameter1TS *deepCpy() const throw(INTERP_KERNEL::Exception) = 0;
35 virtual bool isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const;
36 virtual void simpleRepr2(int bkOffset, std::ostream& oss) const = 0;
37 virtual void readValue(med_idt fid, const std::string& name) throw(INTERP_KERNEL::Exception) = 0;
38 virtual void writeLL(med_idt fid, const std::string& name, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception) = 0;
40 void setIteration(int it) { _iteration=it; }
41 int getIteration() const { return _iteration; }
42 void setOrder(int order) { _order=order; }
43 int getOrder() const { return _order; }
44 void setTimeValue(double time) { _time=time; }
45 void setTime(int dt, int it, double time) { _time=time; _iteration=dt; _order=it; }
46 double getTime(int& dt, int& it) { dt=_iteration; it=_order; return _time; }
47 double getTimeValue() const { return _time; }
49 MEDFileParameter1TS(int iteration, int order, double time);
50 MEDFileParameter1TS();
57 class MEDLOADER_EXPORT MEDFileParameterDouble1TSWTI : public MEDFileParameter1TS
60 static MEDFileParameterDouble1TSWTI *New(int iteration, int order, double time);
61 MEDFileParameter1TS *deepCpy() const throw(INTERP_KERNEL::Exception);
62 void setValue(double val) throw(INTERP_KERNEL::Exception) { _arr=val; }
63 double getValue() const throw(INTERP_KERNEL::Exception) { return _arr; }
64 bool isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const;
65 std::size_t getHeapMemorySize() const;
66 void readValue(med_idt fid, const std::string& name) throw(INTERP_KERNEL::Exception);
67 std::string simpleRepr() const;
69 MEDFileParameterDouble1TSWTI();
70 MEDFileParameterDouble1TSWTI(int iteration, int order, double time);
71 void simpleRepr2(int bkOffset, std::ostream& oss) const;
72 void finishLoading(med_idt fid, const std::string& name, int dt, int it, int nbOfSteps) throw(INTERP_KERNEL::Exception);
73 void finishLoading(med_idt fid, const std::string& name, int timeStepId) throw(INTERP_KERNEL::Exception);
74 void writeLL(med_idt fid, const std::string& name, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception);
79 class MEDLOADER_EXPORT MEDFileParameterTinyInfo : public MEDFileWritable
82 void setDescription(const char *name) { _desc_name=name; }
83 const char *getDescription() const { return _desc_name.c_str(); }
84 void setTimeUnit(const char *unit) { _dt_unit=unit; }
85 const char *getTimeUnit() const { return _dt_unit.c_str(); }
86 std::size_t getHeapMemSizeOfStrings() const;
87 bool isEqualStrings(const MEDFileParameterTinyInfo& other, std::string& what) const;
89 void writeLLHeader(med_idt fid, med_parameter_type typ) const throw(INTERP_KERNEL::Exception);
90 void mainRepr(int bkOffset, std::ostream& oss) const;
94 std::string _desc_name;
97 class MEDLOADER_EXPORT MEDFileParameterDouble1TS : public MEDFileParameterDouble1TSWTI, public MEDFileParameterTinyInfo
100 static MEDFileParameterDouble1TS *New();
101 static MEDFileParameterDouble1TS *New(const char *fileName) throw(INTERP_KERNEL::Exception);
102 static MEDFileParameterDouble1TS *New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception);
103 static MEDFileParameterDouble1TS *New(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception);
104 virtual MEDFileParameter1TS *deepCpy() const throw(INTERP_KERNEL::Exception);
105 virtual bool isEqual(const MEDFileParameter1TS *other, double eps, std::string& what) const;
106 virtual std::string simpleRepr() const;
107 std::size_t getHeapMemorySize() const;
108 void setName(const char *name) throw(INTERP_KERNEL::Exception) { _name=name; }
109 const char *getName() const throw(INTERP_KERNEL::Exception) { return _name.c_str(); }
110 void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
112 MEDFileParameterDouble1TS();
113 MEDFileParameterDouble1TS(const char *fileName) throw(INTERP_KERNEL::Exception);
114 MEDFileParameterDouble1TS(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception);
115 MEDFileParameterDouble1TS(const char *fileName, const char *paramName, int dt, int it) throw(INTERP_KERNEL::Exception);
118 class MEDLOADER_EXPORT MEDFileParameterMultiTS : public RefCountObject, public MEDFileParameterTinyInfo
121 static MEDFileParameterMultiTS *New();
122 static MEDFileParameterMultiTS *New(const char *fileName) throw(INTERP_KERNEL::Exception);
123 static MEDFileParameterMultiTS *New(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception);
124 const char *getName() const { return _name.c_str(); }
125 void setName(const char *name) { _name=name; }
126 std::size_t getHeapMemorySize() const;
127 MEDFileParameterMultiTS *deepCpy() const throw(INTERP_KERNEL::Exception);
128 bool isEqual(const MEDFileParameterMultiTS *other, double eps, std::string& what) const;
129 void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
130 void writeLL(med_idt fid, const MEDFileWritable& mw) const throw(INTERP_KERNEL::Exception);
131 std::string simpleRepr() const;
132 void appendValue(int dt, int it, double time, double val) throw(INTERP_KERNEL::Exception);
133 double getDoubleValue(int iteration, int order) const throw(INTERP_KERNEL::Exception);
134 int getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception);
135 int getPosGivenTime(double time, double eps=1e-8) const throw(INTERP_KERNEL::Exception);
136 MEDFileParameter1TS *getTimeStepAtPos(int posId) const throw(INTERP_KERNEL::Exception);
137 void eraseTimeStepIds(const int *startIds, const int *endIds) throw(INTERP_KERNEL::Exception);
138 std::vector< std::pair<int,int> > getIterations() const throw(INTERP_KERNEL::Exception);
139 std::vector< std::pair<int,int> > getTimeSteps(std::vector<double>& ret1) const throw(INTERP_KERNEL::Exception);
140 void simpleRepr2(int bkOffset, std::ostream& oss) const;
142 MEDFileParameterMultiTS();
143 MEDFileParameterMultiTS(const MEDFileParameterMultiTS& other, bool deepCopy);
144 MEDFileParameterMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception);
145 MEDFileParameterMultiTS(const char *fileName, const char *paramName) throw(INTERP_KERNEL::Exception);
146 void finishLoading(med_idt fid, med_parameter_type typ, int nbOfSteps) throw(INTERP_KERNEL::Exception);
148 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameter1TS> > _param_per_ts;
151 class MEDLOADER_EXPORT MEDFileParameters : public RefCountObject, public MEDFileWritable
154 static MEDFileParameters *New();
155 static MEDFileParameters *New(const char *fileName) throw(INTERP_KERNEL::Exception);
156 std::size_t getHeapMemorySize() const;
157 MEDFileParameters *deepCpy() const throw(INTERP_KERNEL::Exception);
158 bool isEqual(const MEDFileParameters *other, double eps, std::string& what) const;
159 void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception);
160 void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception);
161 std::vector<std::string> getParamsNames() const throw(INTERP_KERNEL::Exception);
162 std::string simpleRepr() const;
163 void simpleReprWithoutHeader(std::ostream& oss) const;
164 void resize(int newSize) throw(INTERP_KERNEL::Exception);
165 void pushParam(MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception);
166 void setParamAtPos(int i, MEDFileParameterMultiTS *param) throw(INTERP_KERNEL::Exception);
167 MEDFileParameterMultiTS *getParamAtPos(int i) const throw(INTERP_KERNEL::Exception);
168 MEDFileParameterMultiTS *getParamWithName(const char *paramName) const throw(INTERP_KERNEL::Exception);
169 void destroyParamAtPos(int i) throw(INTERP_KERNEL::Exception);
170 int getPosFromParamName(const char *paramName) const throw(INTERP_KERNEL::Exception);
171 int getNumberOfParams() const throw(INTERP_KERNEL::Exception);
173 void simpleRepr2(int bkOffset, std::ostream& oss) const;
174 MEDFileParameters(const char *fileName) throw(INTERP_KERNEL::Exception);
175 MEDFileParameters(const MEDFileParameters& other, bool deepCopy);
178 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileParameterMultiTS> > _params;