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,bool shallowCopy)
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)
86 _coordinate.shallowCopy(*Coordinate);
90 MEDARRAY<double> pourAttribut(*Coordinate,false);
91 _coordinate = pourAttribut;
92 //_coordinate.set(mode,Coordinate->get(mode));
97 throw MED_EXCEPTION ( LOCALIZED(STRING("setCoordinates(MEDARRAY<double> *Coordinate)") << "No Coordinate"));
102 Sets the value in attribute _coordinate with Coordinate.
103 _coordinate must be allocated (with
104 COORDINATE::COORDINATE(int,int,medModeSwitch).
106 //----------------------------------------------------------//
107 void COORDINATE::setCoordinates(const medModeSwitch Mode,
108 const double *Coordinate)
109 //----------------------------------------------------------//
111 // if (_coordinate == NULL)
112 // throw MEDEXCEPTION("COORDINATE::setCoordinates(double*) : coordinate array not allocated !");
114 _coordinate.set(Mode,Coordinate);
117 /*! sets the attribute _coordinateName with CoordinateName */
118 //----------------------------------------------------------//
119 void COORDINATE::setCoordinatesNames(const string * CoordinateName)
120 //----------------------------------------------------------//
122 int SpaceDimension = getSpaceDimension() ;
123 _coordinateName.set(SpaceDimension) ;
124 for (int i=0; i<SpaceDimension; i++)
125 _coordinateName[i]=CoordinateName[i];
129 sets the (i+1)^th component of the attribute _coordinateName with
132 //----------------------------------------------------------//
133 void COORDINATE::setCoordinateName(const string CoordinateName, const int i)
134 //----------------------------------------------------------//
136 _coordinateName[i]=CoordinateName;
139 /*! sets the attribute _coordinateUnit with CoordinateUnit */
140 //----------------------------------------------------------//
141 void COORDINATE::setCoordinatesUnits(const string * CoordinateUnit)
142 //----------------------------------------------------------//
144 int SpaceDimension = getSpaceDimension() ;
145 _coordinateUnit.set(SpaceDimension) ;
146 for (int i=0; i<SpaceDimension; i++)
147 _coordinateUnit[i]=CoordinateUnit[i];
151 sets the (i+1)^th component of the attribute _coordinateUnit with
154 //----------------------------------------------------------//
155 void COORDINATE::setCoordinateUnit(const string CoordinateUnit, const int i)
156 //----------------------------------------------------------//
158 _coordinateUnit[i]=CoordinateUnit;
161 /*! sets the attribute _coordinateSystem with CoordinateSystem */
162 //----------------------------------------------------------//
163 void COORDINATE::setCoordinatesSystem(const string CoordinateSystem)
164 //----------------------------------------------------------//
166 _coordinateSystem=CoordinateSystem;
169 /*! sets the attribute _nodeNumber with NodeNumber */
170 //------------------------------------------------//
171 void COORDINATE::setNodesNumbers(const int * NodeNumber)
172 //------------------------------------------------//
174 int NumberOfNodes = getNumberOfNodes() ;
175 _nodeNumber.set(NumberOfNodes,NodeNumber) ;
178 int COORDINATE::getSpaceDimension() const
180 return _coordinate.getLeadingValue() ;
183 int COORDINATE::getNumberOfNodes() const
185 return _coordinate.getLengthValue() ;
189 /*! returns a pointer to the optional array storing
190 eventual nodes numbers */
191 //-------------------------------------------------//
192 const int * COORDINATE::getNodesNumbers() const
193 //-------------------------------------------------//
195 return (const int *)_nodeNumber;
198 /*! returns a Pointer to Coordinates Array in specified mode representation */
199 //--------------------------------------------------------------------------//
200 const double * COORDINATE::getCoordinates (medModeSwitch Mode)
201 //--------------------------------------------------------------------------//
203 return _coordinate.get(Mode) ;
206 /* returns the coordinate of node Number on axis Axis */
207 //----------------------------------------------------//
208 double COORDINATE::getCoordinate(int Number,int Axis)
209 //----------------------------------------------------//
211 return _coordinate.getIJ(Number,Axis) ;
214 /* returns all nodes coordinates from axis Axis */
215 //----------------------------------------------------//
216 const double * COORDINATE::getCoordinateAxis(int Axis)
217 //----------------------------------------------------//
218 { //< return all nodes coordinates from axis Axis
219 return _coordinate.getColumn(Axis) ;
222 /*! returns an array with names of coordinates. \n
227 //--------------------------------------//
228 const string * COORDINATE::getCoordinatesNames() const
230 return _coordinateName ;
233 /* returns the name of axis Axis */
234 //-------------------------------------------//
235 string COORDINATE::getCoordinateName(int Axis) const
236 //-------------------------------------------//
238 return _coordinateName[Axis-1];
241 /*! returns an array with units of coordinates (cm, m, mm, ...)
242 It could be empty. We suppose we are IS (meter). */
243 //-----------------------------------------------------//
244 const string * COORDINATE::getCoordinatesUnits() const
245 //-----------------------------------------------------//
247 return _coordinateUnit ;
250 /*! returns the unit of axis Axis */
251 //------------------------------------------//
252 string COORDINATE::getCoordinateUnit(int Axis) const
253 //------------------------------------------//
255 return _coordinateUnit[Axis-1] ;
257 /*! returns "CARTESIAN", "CYLINDRICAL" or "SPHERICAL"*/
258 //---------------------------------------------------//
259 string COORDINATE::getCoordinatesSystem() const
260 //---------------------------------------------------//
262 return _coordinateSystem ;