2 #include "MEDMEM_Coordinate.hxx"
3 #include "MEDMEM_Exception.hxx"
4 #include "MEDMEM_STRING.hxx"
7 using namespace MEDMEM;
9 /*! Default Constructor : should not be used */
10 //----------------------------------------------------------//
11 COORDINATE::COORDINATE():_coordinateSystem(""),
12 _coordinate(MEDARRAY<double>()),
16 //----------------------------------------------------------//
18 BEGIN_OF("Default Constructor COORDINATE");
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),
31 //------------------------------------------------------------------------------//
33 BEGIN_OF("Constructor COORDINATE");
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 //------------------------------------------------------------------------------//
46 BEGIN_OF("Copy Constructor COORDINATE");
48 int spaceDimension = _coordinate.getLeadingValue();
49 int numberOfNodes = _coordinate.getLengthValue();
51 SCRUTE(spaceDimension);
52 setCoordinatesNames((const string*)m._coordinateName) ;
53 setCoordinatesUnits((const string*)m._coordinateUnit) ;
55 if ( (const int * const) m._nodeNumber != NULL)
56 _nodeNumber.set(numberOfNodes,(const med_int*)m._nodeNumber);
57 // PG : it's default no ?
60 // _nodeNumber.set(0);
65 /* does nothing : all attributs are object (not pointers) */
66 //----------------------//
67 COORDINATE::~COORDINATE()
68 //----------------------//
70 MESSAGE("~COORDINATE()");
73 /*! sets the attribute _coordinate with Coordinate */
74 //----------------------------------------------------------//
75 void COORDINATE::setCoordinates(MEDARRAY<double> *Coordinate)
76 //----------------------------------------------------------//
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)
84 MEDARRAY<double> pourAttribut(*Coordinate,false);
85 _coordinate = pourAttribut;
86 //_coordinate.set(mode,Coordinate->get(mode));
90 throw MED_EXCEPTION ( LOCALIZED(STRING("setCoordinates(MEDARRAY<double>
91 *Coordinate)") << "No Coordinate"));
96 Sets the value in attribute _coordinate with Coordinate.
97 _coordinate must be allocated (with
98 COORDINATE::COORDINATE(int,int,medModeSwitch).
100 //----------------------------------------------------------//
101 void COORDINATE::setCoordinates(const medModeSwitch Mode,
102 const double *Coordinate)
103 //----------------------------------------------------------//
105 // if (_coordinate == NULL)
106 // throw MEDEXCEPTION("COORDINATE::setCoordinates(double*) : coordinate array not allocated !");
108 _coordinate.set(Mode,Coordinate);
111 /*! sets the attribute _coordinateName with CoordinateName */
112 //----------------------------------------------------------//
113 void COORDINATE::setCoordinatesNames(const string * CoordinateName)
114 //----------------------------------------------------------//
116 int SpaceDimension = getSpaceDimension() ;
117 _coordinateName.set(SpaceDimension) ;
118 for (int i=0; i<SpaceDimension; i++)
119 _coordinateName[i]=CoordinateName[i];
123 sets the (i+1)^th component of the attribute _coordinateName with
126 //----------------------------------------------------------//
127 void COORDINATE::setCoordinateName(const string CoordinateName, const int i)
128 //----------------------------------------------------------//
130 _coordinateName[i]=CoordinateName;
133 /*! sets the attribute _coordinateUnit with CoordinateUnit */
134 //----------------------------------------------------------//
135 void COORDINATE::setCoordinatesUnits(const string * CoordinateUnit)
136 //----------------------------------------------------------//
138 int SpaceDimension = getSpaceDimension() ;
139 _coordinateUnit.set(SpaceDimension) ;
140 for (int i=0; i<SpaceDimension; i++)
141 _coordinateUnit[i]=CoordinateUnit[i];
145 sets the (i+1)^th component of the attribute _coordinateUnit with
148 //----------------------------------------------------------//
149 void COORDINATE::setCoordinateUnit(const string CoordinateUnit, const int i)
150 //----------------------------------------------------------//
152 _coordinateUnit[i]=CoordinateUnit;
155 /*! sets the attribute _coordinateSystem with CoordinateSystem */
156 //----------------------------------------------------------//
157 void COORDINATE::setCoordinatesSystem(const string CoordinateSystem)
158 //----------------------------------------------------------//
160 _coordinateSystem=CoordinateSystem;
163 /*! sets the attribute _nodeNumber with NodeNumber */
164 //------------------------------------------------//
165 void COORDINATE::setNodesNumbers(const int * NodeNumber)
166 //------------------------------------------------//
168 int NumberOfNodes = getNumberOfNodes() ;
169 _nodeNumber.set(NumberOfNodes,NodeNumber) ;
172 int COORDINATE::getSpaceDimension() const
174 return _coordinate.getLeadingValue() ;
177 int COORDINATE::getNumberOfNodes() const
179 return _coordinate.getLengthValue() ;
183 /*! returns a pointer to the optional array storing
184 eventual nodes numbers */
185 //-------------------------------------------------//
186 const int * COORDINATE::getNodesNumbers() const
187 //-------------------------------------------------//
189 return (const int *)_nodeNumber;
192 /*! returns a Pointer to Coordinates Array in specified mode representation */
193 //--------------------------------------------------------------------------//
194 const double * COORDINATE::getCoordinates (medModeSwitch Mode)
195 //--------------------------------------------------------------------------//
197 return _coordinate.get(Mode) ;
200 /* returns the coordinate of node Number on axis Axis */
201 //----------------------------------------------------//
202 double COORDINATE::getCoordinate(int Number,int Axis)
203 //----------------------------------------------------//
205 return _coordinate.getIJ(Number,Axis) ;
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) ;
216 /*! returns an array with names of coordinates. /n
221 //--------------------------------------//
222 const string * COORDINATE::getCoordinatesNames() const
224 return _coordinateName ;
227 /* returns the name of axis Axis */
228 //-------------------------------------------//
229 string COORDINATE::getCoordinateName(int Axis) const
230 //-------------------------------------------//
232 return _coordinateName[Axis-1];
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 //-----------------------------------------------------//
241 return _coordinateUnit ;
244 /*! returns the unit of axis Axis */
245 //------------------------------------------//
246 string COORDINATE::getCoordinateUnit(int Axis) const
247 //------------------------------------------//
249 return _coordinateUnit[Axis-1] ;
251 /*! returns "CARTESIAN", "CYLINDRICAL" or "SPHERICAL"*/
252 //---------------------------------------------------//
253 string COORDINATE::getCoordinatesSystem() const
254 //---------------------------------------------------//
256 return _coordinateSystem ;