]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_Coordinate.cxx
Salome HOME
correct small problem from the version in the MedFileV2_2 branch.
[modules/med.git] / src / MEDMEM / MEDMEM_Coordinate.cxx
1 using namespace std;
2 #include "MEDMEM_Coordinate.hxx"
3 #include "MEDMEM_Exception.hxx"
4 #include "MEDMEM_STRING.hxx"
5
6 #include "utilities.h"
7 using namespace MEDMEM;
8
9 /*! Default Constructor : should not be used */
10 //----------------------------------------------------------//
11 COORDINATE::COORDINATE():_coordinateSystem(""),
12                          _coordinate(MEDARRAY<double>()),
13                          _coordinateName(),
14                          _coordinateUnit(),
15                          _nodeNumber()
16 //----------------------------------------------------------//
17 {
18     BEGIN_OF("Default Constructor COORDINATE");
19 }
20
21 /*! This constructor allocate a MEDARRAY of SpaceDimension * NumberOfNodes./n
22     It will create empty array for optional data (nodeNumber..) */
23 //------------------------------------------------------------------------------//
24 COORDINATE::COORDINATE(int SpaceDimension, int NumberOfNodes, medModeSwitch Mode):
25   _coordinateSystem(""),
26   _coordinate(SpaceDimension,NumberOfNodes,Mode),
27   _coordinateName(SpaceDimension),
28   _coordinateUnit(SpaceDimension),
29   _nodeNumber()
30
31 //------------------------------------------------------------------------------//
32 {
33     BEGIN_OF("Constructor COORDINATE");
34 }
35
36 /*! This constructor will COPY all data (it is a deep copy) included in m./n  
37     But only the default storage mode of coordinates array
38     will be copied (not both storage representation modes even if they both
39     exist in original object) :  for example only full_interlace mode  */
40 //------------------------------------------------------------------------------//
41 COORDINATE::COORDINATE(const COORDINATE & m):
42   _coordinateSystem(m._coordinateSystem),
43   _coordinate(m._coordinate,false)
44 //------------------------------------------------------------------------------//
45 {
46   BEGIN_OF("Copy Constructor COORDINATE");
47
48   int spaceDimension = _coordinate.getLeadingValue();
49   int numberOfNodes = _coordinate.getLengthValue();
50
51   SCRUTE(spaceDimension);
52   setCoordinatesNames((const string*)m._coordinateName) ;
53   setCoordinatesUnits((const string*)m._coordinateUnit) ;
54
55   if ( (const int * const) m._nodeNumber != NULL)
56     _nodeNumber.set(numberOfNodes,(const med_int*)m._nodeNumber);
57   // PG : it's default no ?
58 //    else
59 //      {
60 //        _nodeNumber.set(0);
61 //      }
62 }
63
64
65 /* does nothing :   all attributs are object (not pointers) */
66 //----------------------//
67 COORDINATE::~COORDINATE()
68 //----------------------//
69 {
70   MESSAGE("~COORDINATE()");
71 }
72
73 /*! sets the attribute _coordinate with Coordinate           */
74 //----------------------------------------------------------//
75 void COORDINATE::setCoordinates(MEDARRAY<double> *Coordinate) 
76 //----------------------------------------------------------//
77
78
79   const medModeSwitch mode = Coordinate->getMode(); 
80   //  const int  spaceDimension = (int) Coordinate->getLeadingValue();
81   //  const int  numberOfNodes  = (int) Coordinate->getLengthValue();
82   if ( Coordinate->get(mode) != NULL)
83   {
84       MEDARRAY<double> pourAttribut(*Coordinate,false);
85       _coordinate = pourAttribut;
86       //_coordinate.set(mode,Coordinate->get(mode));
87   }
88   else
89   {
90         throw MED_EXCEPTION ( LOCALIZED(STRING("setCoordinates(MEDARRAY<double>
91          *Coordinate)") << "No Coordinate"));
92   }
93 }
94
95 /*!
96   Sets the value in attribute _coordinate with Coordinate.
97   _coordinate must be allocated (with 
98   COORDINATE::COORDINATE(int,int,medModeSwitch).
99 */
100 //----------------------------------------------------------//
101 void COORDINATE::setCoordinates(const medModeSwitch Mode, 
102                                 const double *Coordinate) 
103 //----------------------------------------------------------//
104
105 //    if (_coordinate == NULL)
106 //      throw MEDEXCEPTION("COORDINATE::setCoordinates(double*) : coordinate array not allocated !");
107
108   _coordinate.set(Mode,Coordinate);
109 }
110
111 /*! sets the attribute _coordinateName with CoordinateName   */
112 //----------------------------------------------------------//
113 void COORDINATE::setCoordinatesNames(const string * CoordinateName) 
114 //----------------------------------------------------------//
115 {
116   int SpaceDimension = getSpaceDimension() ;
117   _coordinateName.set(SpaceDimension) ;
118   for (int i=0; i<SpaceDimension; i++)
119     _coordinateName[i]=CoordinateName[i];
120 }
121
122 /*!
123   sets the (i+1)^th component of the attribute _coordinateName with
124   CoordinateName
125 */
126 //----------------------------------------------------------//
127 void COORDINATE::setCoordinateName(const string CoordinateName, const int i)
128 //----------------------------------------------------------//
129 {
130   _coordinateName[i]=CoordinateName;
131 }
132
133 /*! sets the attribute _coordinateUnit with CoordinateUnit   */
134 //----------------------------------------------------------//
135 void COORDINATE::setCoordinatesUnits(const string * CoordinateUnit) 
136 //----------------------------------------------------------//
137
138   int SpaceDimension = getSpaceDimension() ;
139   _coordinateUnit.set(SpaceDimension) ; 
140   for (int i=0; i<SpaceDimension; i++)
141     _coordinateUnit[i]=CoordinateUnit[i];
142 }
143
144 /*!
145   sets the (i+1)^th component of the attribute _coordinateUnit with
146   CoordinateUnit
147 */
148 //----------------------------------------------------------//
149 void COORDINATE::setCoordinateUnit(const string CoordinateUnit, const int i) 
150 //----------------------------------------------------------//
151
152   _coordinateUnit[i]=CoordinateUnit;
153 }
154
155 /*! sets the attribute _coordinateSystem with CoordinateSystem   */
156 //----------------------------------------------------------//
157 void COORDINATE::setCoordinatesSystem(const string CoordinateSystem) 
158 //----------------------------------------------------------//
159
160         _coordinateSystem=CoordinateSystem; 
161 }
162
163 /*! sets the attribute _nodeNumber with NodeNumber */
164 //------------------------------------------------//
165 void COORDINATE::setNodesNumbers(const int * NodeNumber) 
166 //------------------------------------------------//
167 {       
168   int NumberOfNodes = getNumberOfNodes() ;
169   _nodeNumber.set(NumberOfNodes,NodeNumber) ; 
170 }
171
172 int COORDINATE::getSpaceDimension() const
173 {       
174   return _coordinate.getLeadingValue() ; 
175 }
176
177 int COORDINATE::getNumberOfNodes() const
178 {       
179   return _coordinate.getLengthValue() ; 
180 }
181
182
183 /*! returns a pointer to the optional array storing 
184     eventual nodes numbers */
185 //-------------------------------------------------//
186 const int * COORDINATE::getNodesNumbers() const
187 //-------------------------------------------------//
188 {
189         return  (const int *)_nodeNumber;
190 }
191
192 /*! returns a Pointer to Coordinates Array in specified mode representation */
193 //--------------------------------------------------------------------------//
194 const double *  COORDINATE::getCoordinates (medModeSwitch Mode)
195 //--------------------------------------------------------------------------//
196 {
197         return _coordinate.get(Mode) ;
198 }
199
200 /* returns the coordinate of node Number on axis Axis */
201 //----------------------------------------------------//
202 double COORDINATE::getCoordinate(int Number,int Axis) 
203 //----------------------------------------------------//
204 {       
205         return _coordinate.getIJ(Number,Axis) ;
206 }
207
208 /* returns all nodes coordinates from  axis Axis      */
209 //----------------------------------------------------//
210 const double *  COORDINATE::getCoordinateAxis(int Axis)
211 //----------------------------------------------------//
212 {                       //< return all nodes coordinates from axis Axis
213          return _coordinate.getColumn(Axis) ;
214 }
215
216 /*! returns an array with names of coordinates. /n
217       Example : /n
218       - x,y,z /n
219       - r,teta,phi /n
220       - ... */
221 //--------------------------------------//
222 const string * COORDINATE::getCoordinatesNames() const
223 {
224         return _coordinateName ;
225 }
226
227 /* returns the name of axis Axis             */
228 //-------------------------------------------//
229 string COORDINATE::getCoordinateName(int Axis) const
230 //-------------------------------------------//
231 {
232         return _coordinateName[Axis-1];
233 }
234
235 /*!  returns an array with units of coordinates (cm, m, mm, ...)
236      It could be empty. We suppose we are IS (meter).  */
237 //-----------------------------------------------------//
238 const string * COORDINATE::getCoordinatesUnits() const
239 //-----------------------------------------------------//
240 {
241         return _coordinateUnit ;
242 }
243
244 /*! returns the unit of axis Axis           */
245 //------------------------------------------//
246 string COORDINATE::getCoordinateUnit(int Axis) const
247 //------------------------------------------//
248 {
249         return _coordinateUnit[Axis-1] ;
250 }
251 /*! returns "CARTESIAN", "CYLINDRICAL" or "SPHERICAL"*/
252 //---------------------------------------------------//
253 string COORDINATE::getCoordinatesSystem() const
254 //---------------------------------------------------//
255 {
256   return _coordinateSystem ;
257 }