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