Salome HOME
sources v1.2
[modules/med.git] / src / MEDMEM / MEDMEM_Array.hxx
1 //  MED MEDMEM : MED files in memory
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : MEDMEM_Array.hxx
25 //  Module : MED
26
27 #ifndef __MEDARRAY_H__
28 #define __MEDARRAY_H__
29
30 #include "MEDMEM_Exception.hxx"
31 #include "MEDMEM_define.hxx"
32 #include "MEDMEM_PointerOf.hxx"
33 #include "utilities.h"
34
35 using namespace MED_EN;
36
37 /*!
38   A template class to generate an array of any particular type (int, long,
39   float, double) for our purpose in the MED++ library./n/n
40
41   Arrays can be stored in MED_FULL_INTERLACE mode (ie : x1,y1,z1,x2,y2,z2...) or
42   in MED_NO_INTERLACE mode ( x1,x2,..xn, y1, y2 ..,yn,z1,...,zn)./n The alternate
43   representation mode is calculate ONLY when it is usefull. We assure coherency
44   for minor data modifications (element, line or column) if you use set methods.
45   But, if you get a pointer and modify the array, no automatical coherency is possible.
46   You can use calculateOther to force a recalculation and insure the coherency./n
47   No recalculation is done, when the entire array is modified./n
48   Theses arrays are "Med like" arrays; lower bound equals 1. (first element is element 1,
49   first coordinate is coordinate 1). /n
50
51   Available constructors are :/n
52
53   - default constructor (not very usefull)/n
54   - constructor asking for array dimensions and mode (does memory allocation for you)/n
55   - constructor asking for array dimensions, mode and values (doesn't do memory allocation
56     but copies pointers only.)/n
57   - a copy constructor which copies only pointers./n
58     (be aware of coherency)
59   - a copy constructor which copies data (deepcopy)./n
60   - assignement operator is also available and only copies pointers (and not data)./n/n
61
62   Attribute "pointers" aren't standard pointers but class PointerOf objects in order to simplify
63   memory management./n
64
65   A simple test program (testUArray) allows to test this class.
66 */
67
68 template <class T> class MEDARRAY
69 {
70 private :
71                                 
72                                 /*! leading dimension of value (example : space dimension for coordinates) */
73   med_int       _ldValues;
74                                 /*! length of values (example : number of nodes for coordinates) */
75   med_int       _lengthValues;
76                                 /*! data access mode. possible values are :\n
77                                   -  MED_FULL_INTERLACE (default mode) \n
78                                   -  MED_NO_INTERLACE */
79   medModeSwitch _mode;
80                                 /*! Pointer to representation in mode MED_FULL_INTERLACE */
81   PointerOf <T> _valuesFull;
82                                 /*! Pointer to representation in mode MED_NO_INTERLACE */
83   PointerOf <T> _valuesNo;
84                                 /*! Pointer to representation in mode _mode */
85   PointerOf <T> _valuesDefault;
86                                 /*! Pointer to representation in the other mode (!=_mode) */
87   PointerOf <T> _valuesOther;
88
89 public :
90
91   inline  MEDARRAY();
92   inline ~MEDARRAY();
93
94   MEDARRAY  (const med_int ld_values, const med_int length_values,
95              const medModeSwitch mode=MED_FULL_INTERLACE);
96   MEDARRAY  (T* values, const med_int ld_values,
97              const med_int length_values, const medModeSwitch mode=MED_FULL_INTERLACE);
98   MEDARRAY  (MEDARRAY const &m);
99   MEDARRAY  (MEDARRAY const &m, bool copyOther);
100   MEDARRAY & operator = (const MEDARRAY & m);
101
102   inline med_int getLeadingValue() const;
103   inline med_int getLengthValue()  const;
104
105   const T * get        (const medModeSwitch mode) ;
106   const T * getRow     (const med_int i) ;
107   const T * getColumn  (const med_int j) ;
108   const T   getIJ (const med_int i, const med_int j) const;
109 //    T * const get        (const medModeSwitch mode) const;
110 //    T * const getRow     (const med_int i) const;
111 //    T * const getColumn  (const med_int j) const;
112 //    T   const getIJ (const med_int i, const med_int j) const;
113
114   inline medModeSwitch getMode() const;
115
116   void set   (const medModeSwitch mode,const T* value);
117   void setI  (const med_int i,         const T* value);
118   void setJ  (const med_int j,         const T* value);
119   void setIJ (const med_int i, const med_int j, const T  value);
120
121   void calculateOther();
122 };
123
124 //-------------------------------------------------//
125 //                                                 //
126 //              IMPLEMENTED CODE                   //
127 //                                                 //
128 //-------------------------------------------------//
129
130
131 template <class T> inline MEDARRAY<T>::MEDARRAY():
132                         _ldValues(0), _lengthValues(0), _mode(MED_FULL_INTERLACE),
133                         _valuesFull(), _valuesNo(),
134                         _valuesDefault(), _valuesOther()
135 {
136 };
137
138 //                              ------------------
139
140 template <class T> inline MEDARRAY<T>::~MEDARRAY()
141 {
142 };
143
144 //                              ------------------
145
146                                 /*! This constructor does allocation and does not set values : \n.
147                                     It allocates a "T" array of length_values*ld_values length.\n
148                                     You don't have to know the T values when calling this construtor
149                                     but you have to call "set" method to initialize them later.
150                                     You also can  get the pointer to the memory zone (with "get" method),
151                                     and work with it./n
152                                     The desallocation of T array is not your responsability. \n\n
153                                     Throws MEDEXCEPTION if  T array length is < 1*/
154
155 template <class T> MEDARRAY<T>::MEDARRAY(const med_int ld_values,
156                                          const med_int length_values,
157                                          const medModeSwitch mode):
158
159                                                 _ldValues(ld_values),
160                                                 _lengthValues(length_values),
161                                                 _mode(mode),
162                                                 _valuesFull(), _valuesNo(),
163                                                 _valuesDefault(),_valuesOther()
164 {
165   BEGIN_OF("constructor MEDARRAY<T>::MEDARRAY(const med_int, const med_int, const medModeSwitch)");
166
167   // if ld_values < 1 or length_values < 1
168   // throws an exception
169   // Pointers are setted to NULL
170
171   if ((ld_values<1)|(length_values<1))
172   {
173         throw MEDEXCEPTION(LOCALIZED("MEDARRAY<T>::MEDARRAY(const med_int, const med_int, const medModeSwitch) : dimension < 1 !"));
174   }
175
176   if ( _mode == MED_FULL_INTERLACE)
177   {
178         _valuesFull.set(length_values*ld_values);
179         _valuesDefault.set((T*) _valuesFull);
180   }
181   else
182   {
183         ASSERT (_mode == MED_NO_INTERLACE);
184         _valuesNo.set(length_values*ld_values);
185         _valuesDefault.set((T*)_valuesNo);
186   }
187
188   ASSERT( (T*)_valuesDefault != NULL);
189   SCRUTE((T*)_valuesDefault);
190   SCRUTE((T*)_valuesOther);
191   SCRUTE((T*)_valuesNo);
192   SCRUTE((T*)_valuesFull);
193
194   END_OF("constructor MEDARRAY<T>::MEDARRAY(const med_int, const med_int, const medModeSwitch ()");
195 }
196
197 //                              ------------------
198
199                                 /*! This constructor duplicate T*values.\n
200                                     
201                                     Throws MEDEXCEPTION if  the lenght of T is < 1*/
202 template <class T> MEDARRAY<T>::MEDARRAY( T*values,
203                                           const med_int ld_values,
204                                           const med_int length_values,
205                                           const medModeSwitch mode):
206                                                 _ldValues(ld_values),
207                                                 _lengthValues(length_values),
208                                                 _mode(mode),
209                                                 _valuesFull(),_valuesNo(),
210                                                 _valuesDefault(),_valuesOther()
211 {
212   BEGIN_OF("constructor MEDARRAY<T>::MEDARRAY(T* values, const med_int, const med_int, const medModeSwitch)");
213
214   // if ld_values < 1 or length_values < 1, we could not allocate
215   // throws an exception
216
217   if ( (ld_values<1) | (length_values<1) )
218   {
219            throw MEDEXCEPTION(LOCALIZED("MEDARRAY<T>::MEDARRAY(T* values, const med_int, const medModeSwitch) : dimension < 1 !"));
220   }
221   if ( _mode == MED_FULL_INTERLACE)
222   {
223         _valuesFull.set(_ldValues*length_values,values);
224         _valuesDefault.set((T*)_valuesFull);
225   }
226   else
227   {
228         ASSERT (_mode == MED_NO_INTERLACE);
229         _valuesNo.set(_ldValues*length_values,values);
230         _valuesDefault.set((T*)_valuesNo);
231   }
232
233   ASSERT( (T*)_valuesDefault != NULL);
234   SCRUTE((T*)_valuesDefault);
235   SCRUTE((T*)_valuesOther);
236   SCRUTE((T*)_valuesNo);
237   SCRUTE((T*)_valuesFull);
238
239   END_OF("constructor MEDARRAY<T>::MEDARRAY(T* values, const med_int, const med_int, const medModeSwitch)");
240 }
241
242 //                              ------------------
243
244                                 /*! This constructor allocates a new medarray and does a copy of pointers/n
245                                     It DOES NOT copy the memory . The two objects will share the same data./n
246                                     (for copying data, use constructor MEDARRAY(MEDARRAY<T> const & m,bool copyOther). */
247 template <class T> MEDARRAY<T>::MEDARRAY(MEDARRAY<T> const & m ):
248                                         _ldValues(m._ldValues),
249                                         _lengthValues(m._lengthValues),
250                                         _mode(m._mode),
251                                         _valuesFull((const T*)m._valuesFull),
252                                         _valuesNo((const T*)m._valuesNo),
253                                         _valuesDefault((const T*)m._valuesDefault),
254                                         _valuesOther((const T*)m._valuesOther)
255 {
256   BEGIN_OF("constructor MEDARRAY<T>::MEDARRAY(MEDARRAY<T> const & m)");
257   ASSERT( (T*)_valuesDefault != NULL);
258   SCRUTE((T*)_valuesDefault);
259   SCRUTE((T*)_valuesOther);
260   SCRUTE((T*)_valuesNo);
261   SCRUTE((T*)_valuesFull);
262   END_OF("constructor MEDARRAY<T>::MEDARRAY(MEDARRAY<T> const & m)");
263 }
264
265                                 /*! This constructor allocates a new array and does a copy of values
266                                     included in the m arrays./n
267                                     If the boolean is setted to true, both representations (in full mode
268                                     and no interlace mode)  will be copied./n
269                                     Otherwise, only _valuesDefault will be copied./n
270                                     Desallocation of the arrays is not your reponsability./n/n
271                                     Throws MEDEXCEPTION if _valuesOther is null and copyOther equals true*/
272 template <class T> MEDARRAY<T>::MEDARRAY(MEDARRAY<T> const & p,bool copyOther ):
273                                         _ldValues(p._ldValues),
274                                         _lengthValues(p._lengthValues),
275                                         _mode(p._mode),
276                                         _valuesDefault(),
277                                         _valuesNo(),
278                                         _valuesFull(),
279                                         _valuesOther()
280 {
281   BEGIN_OF("Constructeur deepCopy MEDARRAY<T>::MEDARRAY(MEDARRAY<T> const & m,bool copyOther");
282
283   // PG : Non, s'il n'y a rien, on test et on ne copie rien, c'est tout !
284
285 //    if ( copyOther==true && ((const T*)p._valuesOther==NULL))
286 //      {
287 //        throw MEDEXCEPTION("MEDARRAY MEDARRAY const &m,bool copyOther : No Other values defined and bool = true !");
288 //      }
289   
290   if ( _mode == MED_FULL_INTERLACE)
291     {
292       _valuesFull.set(p._ldValues*p._lengthValues,(const T*)p._valuesFull);
293       _valuesDefault.set((T*)_valuesFull);
294       if (copyOther)
295         if ((const T*)p._valuesNo != NULL)
296           {
297             _valuesNo.set(p._ldValues*p._lengthValues,(const T*)p._valuesNo);
298             _valuesOther.set((T*)_valuesNo);
299           }
300     }
301   else
302     {
303       ASSERT (_mode == MED_NO_INTERLACE);
304       _valuesNo.set(p._ldValues*p._lengthValues,(const T*)p._valuesNo);
305       _valuesDefault.set((T*)_valuesNo);
306       if (copyOther)
307         if ((const T*)p._valuesFull != NULL)
308           {
309             _valuesFull.set(p._ldValues*p._lengthValues,(const T*)p._valuesFull);
310             _valuesOther.set((T*)_valuesFull);
311           }
312     }
313 }
314
315 //                              ------------------
316
317 //                              /*! This operator does a copy of pointers/n
318 //                                  It DOES NOT copy of the memory.
319 //                                  The two objects will share data./n */
320
321 template <class T> MEDARRAY<T> & MEDARRAY<T>::MEDARRAY::operator = (const MEDARRAY & m)
322 {
323
324   BEGIN_OF("Operator = MEDARRAY<T>");
325
326   _ldValues=m._ldValues;
327   _lengthValues=m._lengthValues;
328   _mode=m._mode;
329   
330   SCRUTE(_mode);
331
332   if ((const T*) m._valuesFull !=NULL)
333     _valuesFull.set(_ldValues*_lengthValues,(const T*) m._valuesFull);
334
335   if ((const T*) m._valuesNo !=NULL)
336     _valuesNo.set(_ldValues*_lengthValues,(const T*) m._valuesNo);
337   
338   if (_mode == MED_FULL_INTERLACE) {
339     //PN : pour enlever les warning compilateur
340     //_valuesDefault.set((const T*) _valuesFull);
341     //_valuesOther.set((const T*) _valuesNo);
342     _valuesDefault.set((T*) _valuesFull);
343     _valuesOther.set((T*) _valuesNo);
344   } else {
345     ASSERT (_mode == MED_NO_INTERLACE);
346     //PN : pour enlever les warning compilateur
347     //_valuesDefault.set((const T*) _valuesNo);
348     //_valuesOther.set((const T*) _valuesFull);
349     _valuesDefault.set((T*) _valuesNo);
350     _valuesOther.set((T*) _valuesFull);
351   }
352
353   SCRUTE((T*)_valuesDefault);
354   SCRUTE((T*)_valuesOther);
355   SCRUTE((T*)_valuesNo);
356   SCRUTE((T*)_valuesFull);
357
358   END_OF("Operator = MEDARRAY<T>");
359   return *this;
360 }
361
362 //                              ------------------
363
364                                 /*! returns _ldValues. (for example, space dimension for coordinates array)*/
365 template <class T> inline med_int MEDARRAY<T>::getLeadingValue() const
366 {
367   return _ldValues;
368 };
369
370 //                              ------------------
371
372                                 /*! returns _ldValues. (for example, number of nodes for coordinates array)*/
373 template <class T> inline med_int MEDARRAY<T>::getLengthValue() const
374 {
375   return _lengthValues;
376 };
377
378 //                              ------------------
379
380                                 /*! returns a pointer to _valuesDefault or _valuesOther, depending on
381                                     mode value : if mode is the same as _mode, _valuesDefault is returned.
382                                     else, if _valuesOther is calculated (if necessary) and then returned.
383                                     The pointer can be used to set values */
384 template <class T> const T* MEDARRAY<T>::get(const medModeSwitch mode)
385 {
386   BEGIN_OF("MEDARRAY<T>::get(const medModeSwitch mode)");
387   if ((T*)_valuesDefault == NULL)
388   {
389         throw MEDEXCEPTION("MEDARRAY::get(mode) : No values defined !");
390   }
391   if (mode == _mode)
392   {
393         //PN : pour enlever les warning compilateurs
394         //return (const T*)_valuesDefault;
395         return  (T*) _valuesDefault;
396   }
397   else
398   {
399         if ((T*)_valuesOther == NULL)
400         {
401                 calculateOther();
402         }
403         //PN : pour enlever les warning compilateurs
404         //return (const T*)_valuesDefault;
405         return  (T*) _valuesOther;
406   }
407   END_OF("MEDARRAY<T>::get(const medModeSwitch mode)");
408 }
409
410 //                              ------------------
411
412                                 /*! returns a pointer to ith element of the array.
413                                     (ith line in a MED_FULL_INTERLACE representation )/n
414                                     Be aware : if _mode is MED_NO_INTERLACE, the entire
415                                     array will be recalculate in MED_FULL_INTERLACE representation./n*/
416                                 
417 template <class T> const T* MEDARRAY<T>::getRow(const med_int i)
418 {
419
420   BEGIN_OF("MEDARRAY<T>::getRow(const med_int i)");
421
422   if ((T*)_valuesDefault == NULL)
423   {
424         throw MEDEXCEPTION("MEDARRAY::getRow(i) : No values defined !");
425   }
426   if (i<1)
427   {
428         throw MEDEXCEPTION("MEDARRAY::getRow(i) : argument i must be >= 1");
429   }
430   if (i>_lengthValues)
431   {
432         throw MEDEXCEPTION("MEDARRAY::getRow(i) : argument i must be <= _lengthValues");
433   }
434
435   if ((T*)_valuesFull == NULL)
436   {
437         ASSERT(((T*) _valuesDefault)==((T*) _valuesNo));
438         calculateOther();
439   }
440   ASSERT((T*)_valuesFull != NULL);
441
442   // PN pour enlever les warning compilateurs
443   //const T* ptr = (const T*)_valuesFull + (i-1)*_ldValues;
444   const T* ptr =  (T*) _valuesFull + (i-1)*_ldValues;
445
446   END_OF("MEDARRAY<T>::getRow(const med_int i )");
447   return ptr;
448 }
449 //                              ------------------
450
451                                 /*! this method is similar to getRow method./n
452                                     It returns a pointer to jth line of the array in a MED_NO-INTERLACE representation
453                                     (for example, 2nd coordinates)./n
454                                     Be aware : if _mode is MED_FULL_INTERLACE, the entire
455                                     array will be recalculate in MED_NO_INTERLACE representation./n*/
456
457 template <class T> const T* MEDARRAY<T>::getColumn(const med_int j)
458 {
459   BEGIN_OF("MEDARRAY<T>::getColumn(const med_int j)");
460   if ((T*)_valuesDefault == NULL)
461   {
462         throw MEDEXCEPTION("MEDARRAY::getColumn(j) : No values defined !");
463   }
464   if (j<1)
465   {
466         throw MEDEXCEPTION("MEDARRAY::getColumn(j) : argument j must be >= 1");
467   }
468   if (j>_ldValues)
469   {
470         throw MEDEXCEPTION("MEDARRAY::getColumn(j) : argument j must be <= _ldValues");
471   }
472
473   if ((T*)_valuesNo == NULL)
474   {
475         ASSERT(((T*) _valuesDefault)==((T*) _valuesFull));
476         calculateOther();
477   }
478   //PN pour enlever les warning compilateur
479   //const T* ptr = (const T*)_valuesNo + (j-1)*_lengthValues;
480   const T* ptr = ( T*)_valuesNo + (j-1)*_lengthValues;
481
482   return ptr;
483 }
484
485 //                              ------------------
486
487                                 /*! returns Jth value of Ith element .\n
488                                     don't forget first element is element 1 (and not element 0). */
489 template <class T> const T MEDARRAY<T>::getIJ(const med_int i,const  med_int j) const
490 {
491   BEGIN_OF("MEDARRAY<T>::getIJ(const med_int i, const med_int j)");
492   if (i<1)
493   {
494         throw MEDEXCEPTION("MEDARRAY::getIJ(i,j) : argument i must be >= 1");
495   }
496   if (i>_lengthValues)
497   {
498         throw MEDEXCEPTION("MEDARRAY::getIJ(i,j) : argument i must be <= _lengthValues");
499   }
500   if (j<1)
501   {
502         throw MEDEXCEPTION("MEDARRAY::getIJ(i,j) : argument j must be >= 1");
503   }
504   if (j>_ldValues)
505   {
506         throw MEDEXCEPTION("MEDARRAY::getIJ(i,j) : argument j must be <= _ldValues");
507   }
508
509   if ( (const T*)_valuesDefault ==  NULL)
510   {
511         throw MEDEXCEPTION("MEDARRAY::getIJ(i,j) : No value in array !");
512   }
513
514   if (_mode == MED_FULL_INTERLACE)
515   {
516         return _valuesDefault[(i-1)*_ldValues+j-1];
517   }
518   else
519   {
520         return _valuesDefault[(j-1)*_lengthValues+i-1];
521   }
522   END_OF("MEDARRAY<T>::getIJ(const med_int i, const med_int j)");
523 }
524
525 //                              ------------------
526
527                                 /*! returns the default mode (_mode)/n
528                                     (internal use : needed by write method) */
529 template <class T> inline medModeSwitch MEDARRAY<T>::getMode() const
530 {
531   BEGIN_OF("MEDARRAY<T>::getMode()");
532   END_OF("MEDARRAY<T>::getMode()");
533   return _mode;
534 }
535
536 //                              ------------------
537
538                                 /*! sets T pointer of _valuesDefault (cf class PointerOf) on value.\n
539                                     no copy of value is done. \n
540                                     the other representation mode is not recalculate.
541                                     the corresponding pointers are setted to null */
542 //  template <class T> void MEDARRAY<T>::set(const medModeSwitch mode, const T* value)
543 //  {
544
545 //    BEGIN_OF("MEDARRAY<T>::set(mode,value)");
546
547 //    _mode = mode;
548 //    if ( _mode == MED_FULL_INTERLACE)
549 //    {
550 //      _valuesFull.set(value);
551 //      _valuesDefault.set((T*)_valuesFull);
552 //      _valuesNo.set(0);
553 //    }
554 //    else
555 //    {
556 //      ASSERT (_mode == MED_NO_INTERLACE);
557 //      _valuesNo.set(value);
558 //      _valuesDefault.set((T*)_valuesNo);
559 //      _valuesFull.set(0);
560 //    }
561 //    _valuesOther.set(0);
562 //    END_OF("MEDARRAY<T>::set(mode,i,value)");
563 //  }
564
565 // set with duplication because we don't know were value come and 
566 // MEDARRAY must have properties on it !!!!
567 template <class T> void MEDARRAY<T>::set(const medModeSwitch mode, const T* value)
568 {
569   BEGIN_OF("MEDARRAY<T>::set(mode,value)");
570
571   _mode = mode;
572   if ( _mode == MED_FULL_INTERLACE)
573     {
574       _valuesFull.set(_ldValues*_lengthValues,value);
575       _valuesDefault.set((T*)_valuesFull);
576       _valuesNo.set(0);
577     }
578   else
579     {
580       ASSERT (_mode == MED_NO_INTERLACE);
581       _valuesNo.set(_ldValues*_lengthValues,value);
582       _valuesDefault.set((T*)_valuesNo);
583       _valuesFull.set(0);
584     }
585   _valuesOther.set(0);
586
587   END_OF("MEDARRAY<T>::set(mode,i,value)");
588 }
589
590
591
592 //                              ------------------
593
594                                         /*! Sets ith element to T* values\n
595                                             if they both exist, both _valuesFull and _valuesNo arrays will be updated./n
596                                             Throws exception if i < 1 or i > _lengthValues */
597 template <class T> void MEDARRAY<T>::setI(const med_int i, const T* value)
598 {
599   BEGIN_OF("MEDARRAY<T>::setI(i,value)");
600
601   if ((T*)_valuesDefault == NULL)
602   {
603         throw MEDEXCEPTION("MEDARRAY::setI(i,value) : No values defined !");
604   }
605   if (i<=0)
606   {
607       throw MEDEXCEPTION("MEDARRAY::setI(i,value) : argument i must be > 0");
608   }
609   if ( i > _lengthValues)
610   {
611      throw MEDEXCEPTION("MEDARRAY::setI(i,value) : argument i must be <= _lenghtValues");
612   }
613
614   if ((T*)_valuesFull != NULL)
615   {
616    for (int k = 0;k<_ldValues;k++)
617    {
618                 _valuesFull[k+_ldValues*(i-1)] = value[k];
619    }
620   }
621
622   if ((T*)_valuesNo != NULL)
623   {
624    for (int k = 0;k<_ldValues;k++)
625    {
626                 _valuesNo[k*_lengthValues +(i-1)] = value[k];
627    }
628   }
629
630   END_OF("MEDARRAY::setI(i,value)");
631 }
632 //                              ------------------
633
634                                         /*! Sets ith element to T* values\n
635                                             if they both exist, both _valuesFull and _valuesNo arrays will be updated./n
636                                             Throws exception if i < 1 or i > _lengthValues */
637 template <class T> void MEDARRAY<T>::setJ(const med_int j, const T* value)
638 {
639   BEGIN_OF("MEDARRAY::setJ(j,value)");
640   if (( T*)_valuesDefault == NULL)
641   {
642         throw MEDEXCEPTION("MEDARRAY::setJ(j) : No values defined !");
643   }
644   if (j<1)
645   {
646         throw MEDEXCEPTION("MEDARRAY::setJ(j) : argument j must be >= 1");
647   }
648   if (j>_ldValues)
649   {
650         throw MEDEXCEPTION("MEDARRAY::setJ(j) : argument j must be <= _ldValues");
651   }
652   if ((T*)_valuesFull != NULL)
653   {
654    for (int k = 0;k<_lengthValues;k++)
655    {
656                 _valuesFull[k*_ldValues+(j-1)] = value[k];
657    }
658   }
659
660   if ((T*)_valuesNo != NULL)
661   {
662    for (int k = 0;k<_lengthValues;k++)
663    {
664                 _valuesNo[k+_lengthValues*(j-1)] = value[k];
665    }
666   }
667   END_OF("MEDARRAY::setJ(j,value)");
668 }
669
670 //                              ------------------
671
672                                         /*! Sets value of Jth coordinate of Ith element to T value./n
673                                             Maintains coherency./n
674                                             Throws exception if we don't have
675                                             1<=i<=_lengthValues and 1<=j<=_ldValues */
676 template <class T> void MEDARRAY<T>::setIJ(const med_int i, const med_int j, const T value)
677 {
678   // 1<=i<=_lengthValues and 1<=j<=_ldValues
679
680   if (i<1)
681     throw MEDEXCEPTION("MEDARRAY::setIJ(i,j,value) : argument i must be >= 1");
682   if (i>_lengthValues)
683     throw MEDEXCEPTION("MEDARRAY::setIJ(i,j,value) : argument i must be <= _lengthValues");
684
685   if (j<1)
686     throw MEDEXCEPTION("MEDARRAY::setIJ(i,j,value) : argument j must be >= 1");
687   if (j>_ldValues)
688     throw MEDEXCEPTION("MEDARRAY::setIJ(i,j,value) : argument j must be <= _ldValues");
689
690   if ((T*)_valuesDefault == NULL)
691   {
692     throw MEDEXCEPTION("MEDARRAY::setIJ(i,j,value) : No value in array !");
693   }
694
695   if ((T*)_valuesFull != NULL)
696   {
697         _valuesFull[j-1+_ldValues*(i-1)] = value;
698   }
699   if ((T*)_valuesNo != NULL)
700   {
701         _valuesNo[(j-1)*_lengthValues+i-1] = value;
702   }
703 }
704
705                                         /*! Calculates the other mode of representation : MED_FULL_INTERLACE
706                                             if __mode = MED_NO_INTERLACE and vice versa./n
707                                             Throws exception if no value are setted */
708 template <class T> void MEDARRAY<T>::calculateOther()
709 {
710   BEGIN_OF("MEDARRAY<T>::calculateOther()");
711   if ((T*)_valuesDefault == NULL)
712   {
713         throw MEDEXCEPTION("MEDARRAY::calculateOther() : No values defined !");
714   }
715
716   if ((T*)_valuesOther == NULL)
717   {
718         _valuesOther.set(_ldValues*_lengthValues);
719   }
720   if (_mode == MED_NO_INTERLACE)
721   {
722         _valuesFull.set((T*)_valuesOther);
723   }
724   else
725   {
726         ASSERT( _mode==MED_FULL_INTERLACE);
727         _valuesNo.set((T*)_valuesOther);
728   }
729
730   for (int i=0; i<_lengthValues;i++)
731   {
732         for (int j=0; j<_ldValues; j++)
733         {
734                 if (_mode == MED_NO_INTERLACE)
735                 {
736                         _valuesFull[i*_ldValues+j] = _valuesNo[j*_lengthValues+i];
737                 }
738                 else
739                 {
740                         _valuesNo[j*_lengthValues+i]=_valuesFull[i*_ldValues+j];
741                 }
742         }
743   }
744   END_OF("MEDARRAY<T>::calculateOther()");
745 }
746
747 # endif         /* # ifndef __MEDARRAY_H__ */