1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #ifndef __MEDARRAY_H__
23 #define __MEDARRAY_H__
25 #include "MEDMEM_Exception.hxx"
26 #include "MEDMEM_define.hxx"
27 #include "MEDMEM_PointerOf.hxx"
28 #include "MEDMEM_Utilities.hxx"
31 A template class to generate an array of any particular type (int, long,
32 float, double) for our purpose in the MED++ library.\n\n
34 Arrays can be stored in MED_FULL_INTERLACE mode (ie : x1,y1,z1,x2,y2,z2...) or
35 in MED_NO_INTERLACE mode ( x1,x2,..xn, y1, y2 ..,yn,z1,...,zn).\n The alternate
36 representation mode is calculate ONLY when it is usefull. We assure coherency
37 for minor data modifications (element, line or column) if you use set methods.
38 But, if you get a pointer and modify the array, no automatical coherency is possible.
39 You can use calculateOther to force a recalculation and insure the coherency.\n
40 No recalculation is done, when the entire array is modified.\n
41 Theses arrays are "Med like" arrays; lower bound equals 1. (first element is element 1,
42 first coordinate is coordinate 1). \n
44 Available constructors are :\n
46 - default constructor (not very usefull)\n
47 - constructor asking for array dimensions and mode (does memory allocation for you)\n
48 - constructor asking for array dimensions, mode and values (doesn't do memory allocation
49 but copies pointers only.)\n
50 - a copy constructor which copies only pointers.\n
51 (be aware of coherency)
52 - a copy constructor which copies data (deepcopy).\n
53 - assignement operator is also available and only copies pointers (and not data).\n\n
55 Attribute "pointers" aren't standard pointers but class PointerOf objects in order to simplify
58 A simple test program (testUArray) allows to test this class.
62 template <class T> class MEDARRAY
66 /*! leading dimension of value (example : space dimension for coordinates) */
68 /*! length of values (example : number of nodes for coordinates) */
70 /*! data access mode. possible values are :\n
71 - MED_FULL_INTERLACE (default mode) \n
73 MED_EN::medModeSwitch _mode;
74 /*! Pointer to representation in mode MED_FULL_INTERLACE */
75 PointerOf <T> _valuesFull;
76 /*! Pointer to representation in mode MED_NO_INTERLACE */
77 PointerOf <T> _valuesNo;
78 /*! Pointer to representation in mode _mode */
79 PointerOf <T> _valuesDefault;
80 /*! Pointer to representation in the other mode (!=_mode) */
81 PointerOf <T> _valuesOther;
88 MEDARRAY (const int ld_values, const int length_values,
89 const MED_EN::medModeSwitch mode=MED_EN::MED_FULL_INTERLACE);
90 MEDARRAY (T* values, const int ld_values,
91 const int length_values, const MED_EN::medModeSwitch mode=MED_EN::MED_FULL_INTERLACE,bool shallowCopy=false, bool ownershipOfValues=false);
92 MEDARRAY (MEDARRAY const &m);
93 MEDARRAY (MEDARRAY const &m, bool copyOther);
94 MEDARRAY & operator = (const MEDARRAY & m);
96 MEDARRAY & shallowCopy(const MEDARRAY & m);
98 inline int getLeadingValue() const;
99 inline int getLengthValue() const;
101 const T * get (const MED_EN::medModeSwitch mode) ;
102 const T * getRow (const int i) ;
103 const T * getColumn (const int j) ;
104 const T getIJ (const int i, const int j) const;
105 // T * const get (const MED_EN::medModeSwitch mode) const;
106 // T * const getRow (const int i) const;
107 // T * const getColumn (const int j) const;
108 // T const getIJ (const int i, const int j) const;
110 inline MED_EN::medModeSwitch getMode() const;
112 void set (const MED_EN::medModeSwitch mode,const T* value);
113 void setI (const int i, const T* value);
114 void setJ (const int j, const T* value);
115 void setIJ (const int i, const int j, const T value);
117 void calculateOther();
118 bool isOtherCalculated() const {return (const T*)_valuesOther != NULL;}
119 void clearOtherMode();
122 //-------------------------------------------------//
124 // IMPLEMENTED CODE //
126 //-------------------------------------------------//
129 template <class T> inline MEDARRAY<T>::MEDARRAY():
130 _ldValues(0), _lengthValues(0), _mode(MED_EN::MED_FULL_INTERLACE),
131 _valuesFull(), _valuesNo(),
132 _valuesDefault(), _valuesOther()
136 // ------------------
138 template <class T> inline MEDARRAY<T>::~MEDARRAY()
142 // ------------------
144 /*! This constructor does allocation and does not set values : \n.
145 It allocates a "T" array of length_values*ld_values length.\n
146 You don't have to know the T values when calling this construtor
147 but you have to call "set" method to initialize them later.
148 You also can get the pointer to the memory zone (with "get" method),
150 The desallocation of T array is not your responsability. \n\n
151 Throws MEDEXCEPTION if T array length is < 1*/
153 template <class T> MEDARRAY<T>::MEDARRAY(const int ld_values,
154 const int length_values,
155 const MED_EN::medModeSwitch mode):
157 _ldValues(ld_values),
158 _lengthValues(length_values),
160 _valuesFull(), _valuesNo(),
161 _valuesDefault(),_valuesOther()
163 // BEGIN_OF_MED("constructor MEDARRAY<T>::MEDARRAY(const int, const int, const medModeSwitch)");
165 // if ld_values < 1 or length_values < 1
166 // throws an exception
167 // Pointers are setted to NULL
169 if ((ld_values<1)|(length_values<1))
171 throw MEDEXCEPTION(LOCALIZED("MEDARRAY<T>::MEDARRAY(const int, const int, const medModeSwitch) : dimension < 1 !"));
174 if ( _mode == MED_EN::MED_FULL_INTERLACE)
176 _valuesFull.set(length_values*ld_values);
177 _valuesDefault.set((T*) _valuesFull);
181 ASSERT_MED (_mode == MED_EN::MED_NO_INTERLACE);
182 _valuesNo.set(length_values*ld_values);
183 _valuesDefault.set((T*)_valuesNo);
186 ASSERT_MED( (T*)_valuesDefault != NULL);
187 // SCRUTE_MED((T*)_valuesDefault);
188 // SCRUTE_MED((T*)_valuesOther);
189 // SCRUTE_MED((T*)_valuesNo);
190 // SCRUTE_MED((T*)_valuesFull);
192 // END_OF_MED("constructor MEDARRAY<T>::MEDARRAY(const int, const int, const medModeSwitch ()");
195 // ------------------
197 /*! This constructor duplicate T*values.\n
199 Throws MEDEXCEPTION if the lenght of T is < 1*/
200 template <class T> MEDARRAY<T>::MEDARRAY( T*values,
202 const int length_values,
203 const MED_EN::medModeSwitch mode,
205 bool ownershipOfValues):
206 _ldValues(ld_values),
207 _lengthValues(length_values),
209 _valuesFull(),_valuesNo(),
210 _valuesDefault(),_valuesOther()
212 // BEGIN_OF_MED("constructor MEDARRAY<T>::MEDARRAY(T* values, const int, const int, const medModeSwitch)");
214 // if ld_values < 1 or length_values < 1, we could not allocate
215 // throws an exception
217 if ( (ld_values<1) | (length_values<1) )
219 throw MEDEXCEPTION(LOCALIZED("MEDARRAY<T>::MEDARRAY(T* values, const int, const medModeSwitch) : dimension < 1 !"));
221 if ( _mode == MED_EN::MED_FULL_INTERLACE)
225 if(ownershipOfValues)
227 _valuesFull.setShallowAndOwnership((const T*)values);
231 _valuesFull.set((const T*)values);
236 _valuesFull.set(_ldValues*length_values,values);
238 _valuesDefault.set((T*)_valuesFull);
242 ASSERT_MED (_mode == MED_EN::MED_NO_INTERLACE);
245 if(ownershipOfValues)
247 _valuesNo.setShallowAndOwnership((const T*)values);
251 _valuesNo.set((const T*)values);
255 _valuesNo.set(_ldValues*length_values,values);
256 _valuesDefault.set((T*)_valuesNo);
258 ASSERT_MED( (T*)_valuesDefault != NULL);
259 // SCRUTE_MED((T*)_valuesDefault);
260 // SCRUTE_MED((T*)_valuesOther);
261 // SCRUTE_MED((T*)_valuesNo);
262 // SCRUTE_MED((T*)_valuesFull);
264 // END_OF_MED("constructor MEDARRAY<T>::MEDARRAY(T* values, const int, const int, const medModeSwitch)");
267 // ------------------
269 /*! This constructor allocates a new medarray and does a copy of pointers\n
270 It DOES NOT copy the memory . The two objects will share the same data.\n
271 (for copying data, use constructor MEDARRAY(MEDARRAY<T> const & m,bool copyOther). */
272 template <class T> MEDARRAY<T>::MEDARRAY(MEDARRAY<T> const & m ):
273 _ldValues(m._ldValues),
274 _lengthValues(m._lengthValues),
276 _valuesFull((const T*)m._valuesFull),
277 _valuesNo((const T*)m._valuesNo),
278 _valuesDefault((const T*)m._valuesDefault),
279 _valuesOther((const T*)m._valuesOther)
281 // BEGIN_OF_MED("constructor MEDARRAY<T>::MEDARRAY(MEDARRAY<T> const & m)");
282 ASSERT_MED( (T*)_valuesDefault != NULL);
283 // SCRUTE_MED((T*)_valuesDefault);
284 // SCRUTE_MED((T*)_valuesOther);
285 // SCRUTE_MED((T*)_valuesNo);
286 // SCRUTE_MED((T*)_valuesFull);
287 // END_OF_MED("constructor MEDARRAY<T>::MEDARRAY(MEDARRAY<T> const & m)");
290 /*! This constructor allocates a new array and does a copy of values
291 included in the m arrays.\n
292 If the boolean is setted to true, both representations (in full mode
293 and no interlace mode) will be copied.\n
294 Otherwise, only _valuesDefault will be copied.\n
295 Desallocation of the arrays is not your reponsability.\n\n
296 Throws MEDEXCEPTION if _valuesOther is null and copyOther equals true*/
297 template <class T> MEDARRAY<T>::MEDARRAY(MEDARRAY<T> const & p,bool copyOther ):
298 _ldValues(p._ldValues),
299 _lengthValues(p._lengthValues),
306 // BEGIN_OF_MED("Constructeur deepCopy MEDARRAY<T>::MEDARRAY(MEDARRAY<T> const & m,bool copyOther");
308 // PG : Non, s'il n'y a rien, on test et on ne copie rien, c'est tout !
310 // if ( copyOther==true && ((const T*)p._valuesOther==NULL))
312 // throw MEDEXCEPTION("MEDARRAY MEDARRAY const &m,bool copyOther : No Other values defined and bool = true !");
315 if ( _mode == MED_EN::MED_FULL_INTERLACE)
317 _valuesFull.set(p._ldValues*p._lengthValues,(const T*)p._valuesFull);
318 _valuesDefault.set((T*)_valuesFull);
320 if ((const T*)p._valuesNo != NULL)
322 _valuesNo.set(p._ldValues*p._lengthValues,(const T*)p._valuesNo);
323 _valuesOther.set((T*)_valuesNo);
328 ASSERT_MED (_mode == MED_EN::MED_NO_INTERLACE);
329 _valuesNo.set(p._ldValues*p._lengthValues,(const T*)p._valuesNo);
330 _valuesDefault.set((T*)_valuesNo);
332 if ((const T*)p._valuesFull != NULL)
334 _valuesFull.set(p._ldValues*p._lengthValues,(const T*)p._valuesFull);
335 _valuesOther.set((T*)_valuesFull);
340 // ------------------
342 /*! This operator makes a deep copy of the arrays.\n */
344 template <class T> MEDARRAY<T> & MEDARRAY<T>::operator = (const MEDARRAY & m)
347 // BEGIN_OF_MED("Operator = MEDARRAY<T>");
349 _ldValues=m._ldValues;
350 _lengthValues=m._lengthValues;
353 // SCRUTE_MED(_mode);
355 if ((const T*) m._valuesFull !=NULL)
356 _valuesFull.set(_ldValues*_lengthValues,(const T*) m._valuesFull);
358 if ((const T*) m._valuesNo !=NULL)
359 _valuesNo.set(_ldValues*_lengthValues,(const T*) m._valuesNo);
361 if (_mode == MED_EN::MED_FULL_INTERLACE) {
362 //PN : pour enlever les warning compilateur
363 //_valuesDefault.set((const T*) _valuesFull);
364 //_valuesOther.set((const T*) _valuesNo);
365 _valuesDefault.set((T*) _valuesFull);
366 _valuesOther.set((T*) _valuesNo);
368 ASSERT_MED (_mode == MED_EN::MED_NO_INTERLACE);
369 //PN : pour enlever les warning compilateur
370 //_valuesDefault.set((const T*) _valuesNo);
371 //_valuesOther.set((const T*) _valuesFull);
372 _valuesDefault.set((T*) _valuesNo);
373 _valuesOther.set((T*) _valuesFull);
376 // SCRUTE_MED((T*)_valuesDefault);
377 // SCRUTE_MED((T*)_valuesOther);
378 // SCRUTE_MED((T*)_valuesNo);
379 // SCRUTE_MED((T*)_valuesFull);
381 // END_OF_MED("Operator = MEDARRAY<T>");
385 /*! Idem operator= but performs only shallow copy (just copy of pointers) of arrays contains in _valuesFull and _valuesNo \n
386 WARNING the MEDARRAY returned HAS THE OWNERSHIP OF THE ARRAY !!!! */
388 template <class T> MEDARRAY<T> & MEDARRAY<T>::shallowCopy(const MEDARRAY & m)
390 _ldValues=m._ldValues;
391 _lengthValues=m._lengthValues;
393 if ((const T*) m._valuesFull !=NULL)
394 _valuesFull.setShallowAndOwnership((const T*) m._valuesFull);
395 if ((const T*) m._valuesNo !=NULL)
396 _valuesNo.setShallowAndOwnership((const T*) m._valuesNo);
397 if (_mode == MED_EN::MED_FULL_INTERLACE) {
398 _valuesDefault.set((T*) _valuesFull);
399 _valuesOther.set((T*) _valuesNo);
401 _valuesDefault.set((T*) _valuesNo);
402 _valuesOther.set((T*) _valuesFull);
407 // ------------------
409 /*! returns _ldValues. (for example, space dimension for coordinates array)*/
410 template <class T> inline int MEDARRAY<T>::getLeadingValue() const
415 // ------------------
417 /*! returns _ldValues. (for example, number of nodes for coordinates array)*/
418 template <class T> inline int MEDARRAY<T>::getLengthValue() const
420 return _lengthValues;
423 // ------------------
425 /*! returns a pointer to _valuesDefault or _valuesOther, depending on
426 mode value : if mode is the same as _mode, _valuesDefault is returned.
427 else, if _valuesOther is calculated (if necessary) and then returned.
428 The pointer can be used to set values */
429 template <class T> const T* MEDARRAY<T>::get(const MED_EN::medModeSwitch mode)
431 // BEGIN_OF_MED("MEDARRAY<T>::get(const medModeSwitch mode)");
432 if ((T*)_valuesDefault == NULL)
434 throw MEDEXCEPTION("MEDARRAY::get(mode) : No values defined !");
438 //PN : pour enlever les warning compilateurs
439 //return (const T*)_valuesDefault;
440 return (T*) _valuesDefault;
444 if ((T*)_valuesOther == NULL)
448 //PN : pour enlever les warning compilateurs
449 //return (const T*)_valuesDefault;
450 return (T*) _valuesOther;
454 // ------------------
456 /*! returns a pointer to ith element of the array.
457 (ith line in a MED_FULL_INTERLACE representation )\n
458 Be aware : if _mode is MED_NO_INTERLACE, the entire
459 array will be recalculate in MED_FULL_INTERLACE representation.\n*/
461 template <class T> const T* MEDARRAY<T>::getRow(const int i)
463 if ((T*)_valuesDefault == NULL)
465 throw MEDEXCEPTION("MEDARRAY::getRow(i) : No values defined !");
469 throw MEDEXCEPTION("MEDARRAY::getRow(i) : argument i must be >= 1");
473 throw MEDEXCEPTION("MEDARRAY::getRow(i) : argument i must be <= _lengthValues");
476 if ((T*)_valuesFull == NULL)
480 ASSERT_MED((T*)_valuesFull != NULL);
482 // PN pour enlever les warning compilateurs
483 //const T* ptr = (const T*)_valuesFull + (i-1)*_ldValues;
484 const T* ptr = (T*) _valuesFull + (i-1)*_ldValues;
488 // ------------------
490 /*! this method is similar to getRow method.\n
491 It returns a pointer to jth line of the array in a MED_NO-INTERLACE representation
492 (for example, 2nd coordinates).\n
493 Be aware : if _mode is MED_FULL_INTERLACE, the entire
494 array will be recalculate in MED_NO_INTERLACE representation.\n*/
496 template <class T> const T* MEDARRAY<T>::getColumn(const int j)
498 if ((T*)_valuesDefault == NULL)
500 throw MEDEXCEPTION("MEDARRAY::getColumn(j) : No values defined !");
504 throw MEDEXCEPTION("MEDARRAY::getColumn(j) : argument j must be >= 1");
508 throw MEDEXCEPTION("MEDARRAY::getColumn(j) : argument j must be <= _ldValues");
511 if ((T*)_valuesNo == NULL)
513 ASSERT_MED(((T*) _valuesDefault)==((T*) _valuesFull));
516 //PN pour enlever les warning compilateur
517 //const T* ptr = (const T*)_valuesNo + (j-1)*_lengthValues;
518 const T* ptr = ( T*)_valuesNo + (j-1)*_lengthValues;
523 // ------------------
525 /*! returns Jth value of Ith element .\n
526 don't forget first element is element 1 (and not element 0). */
527 template <class T> const T MEDARRAY<T>::getIJ(const int i,const int j) const
532 throw MEDEXCEPTION("MEDARRAY::getIJ(i,j) : argument i must be >= 1");
536 throw MEDEXCEPTION("MEDARRAY::getIJ(i,j) : argument i must be <= _lengthValues");
540 throw MEDEXCEPTION("MEDARRAY::getIJ(i,j) : argument j must be >= 1");
544 throw MEDEXCEPTION("MEDARRAY::getIJ(i,j) : argument j must be <= _ldValues");
547 if ( (const T*)_valuesDefault == NULL)
549 throw MEDEXCEPTION("MEDARRAY::getIJ(i,j) : No value in array !");
552 if (_mode == MED_EN::MED_FULL_INTERLACE)
554 return _valuesDefault[(i-1)*_ldValues+j-1];
558 return _valuesDefault[(j-1)*_lengthValues+i-1];
563 // ------------------
565 /*! returns the default mode (_mode)\n
566 (internal use : needed by write method) */
567 template <class T> inline MED_EN::medModeSwitch MEDARRAY<T>::getMode() const
572 // ------------------
574 /*! sets T pointer of _valuesDefault (cf class PointerOf) on value.\n
575 no copy of value is done. \n
576 the other representation mode is not recalculate.
577 the corresponding pointers are setted to null */
578 // template <class T> void MEDARRAY<T>::set(const medModeSwitch mode, const T* value)
581 // BEGIN_OF_MED("MEDARRAY<T>::set(mode,value)");
584 // if ( _mode == MED_FULL_INTERLACE)
586 // _valuesFull.set(value);
587 // _valuesDefault.set((T*)_valuesFull);
592 // ASSERT_MED (_mode == MED_NO_INTERLACE);
593 // _valuesNo.set(value);
594 // _valuesDefault.set((T*)_valuesNo);
595 // _valuesFull.set(0);
597 // _valuesOther.set(0);
598 // END_OF_MED("MEDARRAY<T>::set(mode,i,value)");
601 // set with duplication because we don't know were value come and
602 // MEDARRAY must have properties on it !!!!
603 template <class T> void MEDARRAY<T>::set(const MED_EN::medModeSwitch mode, const T* value)
605 // BEGIN_OF_MED("MEDARRAY<T>::set(mode,value)");
608 if ( _mode == MED_EN::MED_FULL_INTERLACE)
610 _valuesFull.set(_ldValues*_lengthValues,value);
611 _valuesDefault.set((T*)_valuesFull);
616 ASSERT_MED (_mode == MED_EN::MED_NO_INTERLACE);
617 _valuesNo.set(_ldValues*_lengthValues,value);
618 _valuesDefault.set((T*)_valuesNo);
623 // END_OF_MED("MEDARRAY<T>::set(mode,i,value)");
626 /*! This function clears the other mode of representation if it exists
627 * It is usefull for people who needs for optimisation reasons to work directly
628 * on the inside array without using set-functions
630 template <class T> void MEDARRAY<T>::clearOtherMode()
632 if(isOtherCalculated())
634 if ( _mode == MED_EN::MED_FULL_INTERLACE)
643 // ------------------
645 /*! Sets ith element to T* values\n
646 if they both exist, both _valuesFull and _valuesNo arrays will be updated.\n
647 Throws exception if i < 1 or i > _lengthValues */
648 template <class T> void MEDARRAY<T>::setI(const int i, const T* value)
650 // BEGIN_OF_MED("MEDARRAY<T>::setI(i,value)");
652 if ((T*)_valuesDefault == NULL)
654 throw MEDEXCEPTION("MEDARRAY::setI(i,value) : No values defined !");
658 throw MEDEXCEPTION("MEDARRAY::setI(i,value) : argument i must be > 0");
660 if ( i > _lengthValues)
662 throw MEDEXCEPTION("MEDARRAY::setI(i,value) : argument i must be <= _lenghtValues");
665 if ((T*)_valuesFull != NULL)
667 for (int k = 0;k<_ldValues;k++)
669 _valuesFull[k+_ldValues*(i-1)] = value[k];
673 if ((T*)_valuesNo != NULL)
675 for (int k = 0;k<_ldValues;k++)
677 _valuesNo[k*_lengthValues +(i-1)] = value[k];
681 // END_OF_MED("MEDARRAY::setI(i,value)");
683 // ------------------
685 /*! Sets ith element to T* values\n
686 if they both exist, both _valuesFull and _valuesNo arrays will be updated.\n
687 Throws exception if i < 1 or i > _lengthValues */
688 template <class T> void MEDARRAY<T>::setJ(const int j, const T* value)
690 // BEGIN_OF_MED("MEDARRAY::setJ(j,value)");
691 if (( T*)_valuesDefault == NULL)
693 throw MEDEXCEPTION("MEDARRAY::setJ(j) : No values defined !");
697 throw MEDEXCEPTION("MEDARRAY::setJ(j) : argument j must be >= 1");
701 throw MEDEXCEPTION("MEDARRAY::setJ(j) : argument j must be <= _ldValues");
703 if ((T*)_valuesFull != NULL)
705 for (int k = 0;k<_lengthValues;k++)
707 _valuesFull[k*_ldValues+(j-1)] = value[k];
711 if ((T*)_valuesNo != NULL)
713 for (int k = 0;k<_lengthValues;k++)
715 _valuesNo[k+_lengthValues*(j-1)] = value[k];
718 // END_OF_MED("MEDARRAY::setJ(j,value)");
721 // ------------------
723 /*! Sets value of Jth coordinate of Ith element to T value.\n
724 Maintains coherency.\n
725 Throws exception if we don't have
726 1<=i<=_lengthValues and 1<=j<=_ldValues */
727 template <class T> void MEDARRAY<T>::setIJ(const int i, const int j, const T value)
729 // 1<=i<=_lengthValues and 1<=j<=_ldValues
732 throw MEDEXCEPTION("MEDARRAY::setIJ(i,j,value) : argument i must be >= 1");
734 throw MEDEXCEPTION("MEDARRAY::setIJ(i,j,value) : argument i must be <= _lengthValues");
737 throw MEDEXCEPTION("MEDARRAY::setIJ(i,j,value) : argument j must be >= 1");
739 throw MEDEXCEPTION("MEDARRAY::setIJ(i,j,value) : argument j must be <= _ldValues");
741 if ((T*)_valuesDefault == NULL)
743 throw MEDEXCEPTION("MEDARRAY::setIJ(i,j,value) : No value in array !");
746 if ((T*)_valuesFull != NULL)
748 _valuesFull[j-1+_ldValues*(i-1)] = value;
750 if ((T*)_valuesNo != NULL)
752 _valuesNo[(j-1)*_lengthValues+i-1] = value;
756 /*! Calculates the other mode of representation : MED_FULL_INTERLACE
757 if __mode = MED_NO_INTERLACE and vice versa.\n
758 Throws exception if no value are setted */
759 template <class T> void MEDARRAY<T>::calculateOther()
761 // BEGIN_OF_MED("MEDARRAY<T>::calculateOther()");
762 if ((T*)_valuesDefault == NULL)
764 throw MEDEXCEPTION("MEDARRAY::calculateOther() : No values defined !");
767 if ((T*)_valuesOther == NULL)
769 _valuesOther.set(_ldValues*_lengthValues);
771 if (_mode == MED_EN::MED_NO_INTERLACE)
773 _valuesFull.set((T*)_valuesOther);
777 ASSERT_MED( _mode==MED_EN::MED_FULL_INTERLACE);
778 _valuesNo.set((T*)_valuesOther);
781 for (int i=0; i<_lengthValues;i++)
783 for (int j=0; j<_ldValues; j++)
785 if (_mode == MED_EN::MED_NO_INTERLACE)
787 _valuesFull[i*_ldValues+j] = _valuesNo[j*_lengthValues+i];
791 _valuesNo[j*_lengthValues+i]=_valuesFull[i*_ldValues+j];
795 // END_OF_MED("MEDARRAY<T>::calculateOther()");
798 } //End of namespace MEDMEM
800 # endif /* # ifndef __MEDARRAY_H__ */