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