]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_VtkFieldDriver.hxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM / MEDMEM_VtkFieldDriver.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #ifndef VTK_FIELD_DRIVER_HXX
23 #define VTK_FIELD_DRIVER_HXX
24
25 #include <string>
26 #include <fstream>
27 #include <sstream>
28
29 #include "MEDMEM_define.hxx"
30
31 #include "MEDMEM_GenDriver.hxx"
32 #include "MEDMEM_Utilities.hxx"
33
34 #include "MEDMEM_STRING.hxx"
35 #include "MEDMEM_Exception.hxx"
36 #include "MEDMEM_Unit.hxx"
37 #include "MEDMEM_nArray.hxx"
38 #include "MEDMEM_ArrayConvert.hxx"
39 #include "MEDMEM_Support.hxx"
40 #include "MEDMEM_Mesh.hxx"
41 #include "MEDMEM_CellModel.hxx"
42
43
44 /*!
45
46   Driver Med for FIELD.
47
48   Generic part : implement open and close methods.
49
50 */
51
52 namespace MEDMEM {
53 template <class T> class VTK_FIELD_DRIVER : public GENDRIVER
54 {
55 protected:
56   
57   FIELD<T> *     _ptrField;
58   mutable ofstream *        _vtkFile ;
59   string         _fieldName;
60   int            _fieldNum;
61
62 public :
63
64   // all MED cell type ?? Classe de Définition ??
65   //   static const medGeometryElement all_cell_type[MED_NBR_GEOMETRIE_MAILLE];
66   
67   //   static const char * const all_cell_type_tab [MED_NBR_GEOMETRIE_MAILLE];
68   
69   /*!
70     Constructor.
71   */
72   template <class INTERLACING_TAG>
73   VTK_FIELD_DRIVER():GENDRIVER(),
74                      _ptrField((FIELD<T> *) 0), _fieldName(""),
75                      _fieldNum(MED_INVALID)
76   {
77     const char * LOC = "VTK_FIELD_DRIVER::VTK_FIELD_DRIVER() ";
78     BEGIN_OF_MED(LOC);
79
80     _vtkFile = new ofstream();
81
82   END_OF_MED(LOC);
83   }
84   /*!
85     Constructor.
86   */
87   template <class INTERLACING_TAG>
88   VTK_FIELD_DRIVER(const string & fileName,
89                    FIELD<T, INTERLACING_TAG> * ptrField):
90     GENDRIVER(fileName, MED_EN::WRONLY, VTK_DRIVER),
91     _ptrField((FIELD<T> *) ptrField),
92     _fieldName(fileName),_fieldNum(MED_INVALID) 
93   {
94   const char* LOC = "VTK_FIELD_DRIVER::VTK_FIELD_DRIVER(const string & fileName, FIELD<T> * ptrField) ";
95   BEGIN_OF_MED(LOC);
96
97     _vtkFile = new ofstream();
98
99   END_OF_MED(LOC);
100   }
101
102   /*!
103     Copy constructor.
104   */
105   VTK_FIELD_DRIVER(const VTK_FIELD_DRIVER & fieldDriver):
106     GENDRIVER(fieldDriver),
107     _ptrField(fieldDriver._ptrField),
108     _fieldName(fieldDriver._fieldName),
109     _fieldNum(fieldDriver._fieldNum) 
110   {
111     _ptrField->addDriver(*this);
112     _vtkFile = new ofstream();
113   }
114
115   /*!
116     Destructor.
117   */
118   ~VTK_FIELD_DRIVER()
119   {
120   const char* LOC = "VTK_FIELD_DRIVER::~VTK_FIELD_DRIVER()";
121   BEGIN_OF_MED(LOC);
122
123     close();
124
125     SCRUTE_MED(_vtkFile);
126
127     delete _vtkFile ;
128
129     SCRUTE_MED(_vtkFile);
130
131   END_OF_MED(LOC);
132   }
133
134   void openConst() const throw (MEDEXCEPTION)
135   {
136     const char * LOC = "VTK_FIELD_DRIVER::openConst()" ;
137     BEGIN_OF_MED(LOC);
138
139     MESSAGE_MED(LOC<<" : _fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode);
140
141     if ( _fileName == "" )
142       throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
143                                        << "_fileName is |\"\"|, please set a correct fileName before calling open()"
144                                        )
145                             );
146
147     if (!(*_vtkFile).is_open())
148       (*_vtkFile).open(_fileName.c_str()) ; 
149 //    if (*_vtkFile)
150 //      _status = MED_OPENED ;
151 //    else
152
153
154     SCRUTE_MED((*_vtkFile).is_open());
155     SCRUTE_MED(_vtkFile);
156
157
158
159     if (!(*_vtkFile))
160       throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not open file "
161                                        << _fileName)
162                             );
163   END_OF_MED(LOC);
164   }
165
166   void openConstAppend() const throw (MEDEXCEPTION)
167   {
168     const char * LOC = "VTK_FIELD_DRIVER::openConstAppend()" ;
169     BEGIN_OF_MED(LOC);
170
171     MESSAGE_MED(LOC<<" : _fileName.c_str : "<< _fileName.c_str()<<",mode : "<< _accessMode);
172
173     if ( _fileName == "" )
174       throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) 
175                                        << "_fileName is |\"\"|, please set a correct fileName before calling open()"
176                                        )
177                             );
178
179     SCRUTE_MED((*_vtkFile).is_open());
180
181     if (!(*_vtkFile).is_open())
182       {
183         MESSAGE_MED(LOC<<"The file is already close and it is opened with the right option");
184         (*_vtkFile).open(_fileName.c_str(), ofstream::out | ofstream::app) ; 
185       }
186     else
187       {
188         MESSAGE_MED(LOC<<"The file is still open, it is closed to make sure that it will be opened with the right option");
189         //      closeConst();
190
191
192         (*_vtkFile).close() ;
193
194         _vtkFile->open(_fileName.c_str(), ofstream::out | ofstream::app) ; 
195       }
196 //    if (*_vtkFile)
197 //      _status = MED_OPENED ;
198 //    else
199
200
201     SCRUTE_MED((*_vtkFile).is_open());
202     SCRUTE_MED(_vtkFile);
203
204
205
206     if (!(*_vtkFile))
207       throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not open file "
208                                        << _fileName)
209                             );
210   END_OF_MED(LOC);
211   }
212
213   void open() throw (MEDEXCEPTION)
214   {
215     openConst() ;
216   }
217
218   void openAppend() throw (MEDEXCEPTION)
219   {
220     openConstAppend() ;
221   }
222
223   void closeConst() const throw (MEDEXCEPTION)
224   {
225     const char * LOC = "VTK_FIELD_DRIVER::closeConst() " ;
226     BEGIN_OF_MED(LOC);
227
228     SCRUTE_MED(_vtkFile);
229     SCRUTE_MED(*_vtkFile);
230
231
232     if ((*_vtkFile).is_open())
233       (*_vtkFile).close();
234   
235 //    if (*_vtkFile)
236 //      _status = MED_CLOSED ;
237 //    else
238
239     SCRUTE_MED(_vtkFile);
240     SCRUTE_MED(*_vtkFile);
241
242     if ( (*_vtkFile) && _vtkFile->is_open() )
243       //if (!(*_vtkFile))
244       throw MED_EXCEPTION ( LOCALIZED( STRING(LOC) << "Could not close file "
245                                        << _fileName)
246                             );
247
248   END_OF_MED(LOC);
249   }
250
251   void close() {
252     closeConst() ;
253   }
254
255   /*!
256     Set the name of the FIELD asked in file.
257
258     It could be different than the name of the FIELD object.
259   */
260   void   setFieldName(const string & fieldName) ;
261
262   /*!
263     Get the name of the FIELD asked in file.
264   */
265   string getFieldName() const ;
266
267   /*!
268     Return a MEDEXCEPTION : it is the write-only driver.
269   */
270   void read ( void ) throw (MEDEXCEPTION) ;
271
272   /*!
273     Write FIELD in the specified file, with its mesh through its support
274     which has to be on all entities (excluding the faces in 3d and edges
275     in 2d).
276   */
277   void write( void ) const throw (MEDEXCEPTION) ;
278
279   /*!
280     Write FIELD in the specified file, the mesh is supposed to be
281     written in this file. The field support has to be on all entities
282     (excluding the faces in 3d and edges in 2d).
283   */
284   void writeAppend( void ) const throw (MEDEXCEPTION);
285
286 private:
287   GENDRIVER * copy ( void ) const ;
288
289 };
290
291 /*-------------------------*/
292 /* template implementation */
293 /*-------------------------*/
294
295 /*--------------------- DRIVER PART -------------------------------*/
296
297 template <class T> void VTK_FIELD_DRIVER<T>::setFieldName(const string & fieldName)
298 {
299   _fieldName = fieldName; 
300 }
301
302 template <class T> string  VTK_FIELD_DRIVER<T>::getFieldName() const
303 {
304   return _fieldName;
305 }
306
307 template <class T> GENDRIVER * VTK_FIELD_DRIVER<T>::copy(void) const
308 {
309   VTK_FIELD_DRIVER<T> * myDriver = new VTK_FIELD_DRIVER<T>(*this);
310
311   return myDriver ;
312 }
313
314 template <class T> void VTK_FIELD_DRIVER<T>::read (void)
315   throw (MEDEXCEPTION)
316 {
317   throw MEDEXCEPTION("VTK_FIELD_DRIVER::read : Can't read with a VTK driver because it is write only driver !");
318 }
319
320 template <class T> void VTK_FIELD_DRIVER<T>::write(void) const
321   throw (MEDEXCEPTION)
322 {
323   const char * LOC = "VTK_FIELD_DRIVER::write(void) const " ;
324   BEGIN_OF_MED(LOC);
325
326   // we get the Support and its associated Mesh
327
328   const SUPPORT * supportField = _ptrField->getSupport();
329   MESH * meshField = supportField->getMesh();
330   if (! meshField )
331     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<": mesh was not read before writing")) ;
332
333   // Well we must open vtk file first, because there are
334   // no other driver than MED for VTK that do it !
335   openConst() ;
336
337   // could we put more than one Mesh ?????
338   (*_vtkFile) << "# vtk DataFile Version 2.0" << endl 
339            << "maillage from MedMemory"  << endl ;
340   // only ASCII for the moment (binary came later :-)
341   (*_vtkFile) << "ASCII" << endl ;
342
343   (*_vtkFile) << "DATASET UNSTRUCTURED_GRID" << endl ;
344   // put points (all point are in 3D, so if we are in 1D or 2D, we complete by zero !
345   int SpaceDimension = meshField->getSpaceDimension() ;
346   int NumberOfNodes = meshField->getNumberOfNodes() ;
347   (*_vtkFile) << "POINTS " << NumberOfNodes << " float" << endl ;
348   const double *coordinate = meshField->getCoordinates(MED_EN::MED_FULL_INTERLACE) ;
349   for (int i=0;i<NumberOfNodes;i++) {
350     for (int j=0;j<SpaceDimension;j++)
351       (*_vtkFile) << coordinate[i*SpaceDimension+j] << " " ;
352     if (SpaceDimension==1) 
353       (*_vtkFile) << "0 0" ;
354     if (SpaceDimension==2) 
355       (*_vtkFile) << "0" ;
356     (*_vtkFile) << endl ;
357   }
358
359   // we put connectivity
360   // how many cells and how many value in connectivity :
361   int cells_types_count = meshField->getNumberOfTypes(MED_EN::MED_CELL) ;
362   //  int * cells_count = meshField->get_cells_count() ;
363   //  int cells_sum = cells_count[cells_types_count] ;
364   int cells_sum = meshField->getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS) ;
365   const CELLMODEL * cells_type = meshField->getCellsTypes(MED_EN::MED_CELL) ;
366   //  int connectivity_sum = 0 ;
367
368   //const int * connectivity = meshField->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_ALL_ELEMENTS) ; !! UNUSED VARIABLE !!
369   const int * connectivityIndex = meshField->getConnectivityIndex(MED_EN::MED_NODAL,MED_EN::MED_CELL) ;
370
371   int connectivity_sum =  connectivityIndex[cells_sum]-1 ;
372
373   (*_vtkFile) << "CELLS " << cells_sum << " " << connectivity_sum+cells_sum << endl ;
374   // we put connectivity
375   for (int i=0;i<cells_types_count;i++) {
376     int *filter = (int*) NULL ; // index in vtk connectivity
377     switch (cells_type[i].getType())
378       {
379       case MED_EN::MED_POINT1  : {
380         filter = new int[1] ;
381         filter[0] = 0 ;
382         break ;
383       }
384       case MED_EN::MED_SEG2    : {
385         filter = new int[2] ;
386         filter[0] = 0 ;
387         filter[1] = 1 ;
388         break ;
389       }
390       case MED_EN::MED_SEG3    : {  
391         break ;
392       }
393       case MED_EN::MED_TRIA3   : {
394         filter = new int[3] ;
395         filter[0] = 0 ;
396         filter[1] = 1 ;
397         filter[2] = 2 ;
398         break ;
399       }
400       case MED_EN::MED_QUAD4   : {
401         filter = new int[4] ;
402         filter[0] = 0 ;
403         filter[1] = 1 ;
404         filter[2] = 2 ;
405         filter[3] = 3 ;
406         break ;
407       }
408       case MED_EN::MED_TRIA6   : {
409         break ;
410       }
411       case MED_EN::MED_QUAD8   : {
412         break ;
413       }
414       case MED_EN::MED_TETRA4  : {
415         filter = new int[4] ;
416         filter[0] = 0 ;
417         filter[1] = 1 ;
418         filter[2] = 3 ;  // 3td element in med are 4th in vtk (array begin at 0 !)
419         filter[3] = 2 ;  // 4th element in med are 3rd in vtk (array begin at 0 !)
420         break ;
421       }
422       case MED_EN::MED_PYRA5   : {
423         filter = new int[5] ;
424         filter[0] = 0 ;
425         filter[1] = 3 ;  // 2nd element in med are 4th in vtk (array begin at 0 !)
426         filter[2] = 2 ;
427         filter[3] = 1 ;  // 4th element in med are 2nd in vtk (array begin at 0 !)
428         filter[4] = 4 ;
429         break ;
430       }
431       case MED_EN::MED_PENTA6  : {
432         filter = new int[6] ;
433         filter[0] = 0 ;
434         filter[1] = 1 ;
435         filter[2] = 2 ;
436         filter[3] = 3 ;
437         filter[4] = 4 ;
438         filter[5] = 5 ;
439         break ;
440       }
441       case MED_EN::MED_HEXA8   : {
442         filter = new int[8] ;
443         filter[0] = 0 ;
444         filter[1] = 3 ;
445         filter[2] = 2 ;
446         filter[3] = 1 ;
447         filter[4] = 4 ;
448         filter[5] = 7 ;
449         filter[6] = 6 ;
450         filter[7] = 5 ;
451         break ;
452       }
453       case MED_EN::MED_TETRA10 : {
454         break ;
455       }
456       case MED_EN::MED_PYRA13  : {
457         break ;
458       }
459       case MED_EN::MED_PENTA15 : {
460         break ;
461       }
462       case MED_EN::MED_HEXA20  : {
463         break ;
464       }
465       default : { 
466         break ;
467       }
468       }
469     if (filter==NULL) 
470       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<": MED element type not supported yet : " << cells_type[i].getName() ) ) ;
471     int nodes_cell = cells_type[i].getNumberOfNodes();
472     int numberOfCell = meshField->getNumberOfElements(MED_EN::MED_CELL,cells_type[i].getType()) ;
473     const int * connectivityArray = meshField->getConnectivity(MED_EN::MED_FULL_INTERLACE,MED_EN::MED_NODAL,MED_EN::MED_CELL,cells_type[i].getType());
474     for (int j=0;j<numberOfCell;j++) {
475       (*_vtkFile) << nodes_cell << " " ;
476       for (int k=0;k<nodes_cell;k++)
477         (*_vtkFile) << connectivityArray[j*nodes_cell+filter[k]] - 1 << " " ;
478       (*_vtkFile) << endl ;
479     }
480     if (filter != NULL)
481       delete[] filter ;
482   }
483   (*_vtkFile) << endl ;
484   // we put cells type
485   (*_vtkFile) << "CELL_TYPES " << cells_sum << endl ;
486   for (int i=0;i<cells_types_count;i++) {
487     int vtkType = 0 ;
488     switch (cells_type[i].getType())
489       {
490       case MED_EN::MED_POINT1  : {
491         vtkType = 1 ;
492         break ;
493       }
494       case MED_EN::MED_SEG2    : {
495         vtkType = 3 ;
496         break ;
497       }
498       case MED_EN::MED_SEG3    : {  
499         vtkType = 0 ;
500         break ;
501       }
502       case MED_EN::MED_TRIA3   : {
503         vtkType = 5 ;
504         break ;
505       }
506       case MED_EN::MED_QUAD4   : {
507         vtkType = 9 ;
508         break ;
509       }
510       case MED_EN::MED_TRIA6   : {
511         vtkType = 0 ;
512         break ;
513       }
514       case MED_EN::MED_QUAD8   : {
515         vtkType = 0 ;
516         break ;
517       }
518       case MED_EN::MED_TETRA4  : {
519         vtkType = 10 ;
520         break ;
521       }
522       case MED_EN::MED_PYRA5   : {
523         vtkType = 14 ;
524         break ;
525       }
526       case MED_EN::MED_PENTA6  : {
527         vtkType = 13 ;
528         break ;
529       }
530       case MED_EN::MED_HEXA8   : {
531         vtkType = 12 ;
532         break ;
533       }
534       case MED_EN::MED_TETRA10 : {
535         vtkType = 0 ;
536         break ;
537       }
538       case MED_EN::MED_PYRA13  : {
539         vtkType = 0 ;
540         break ;
541       }
542       case MED_EN::MED_PENTA15 : {
543         vtkType = 0 ;
544         break ;
545       }
546       case MED_EN::MED_HEXA20  : {
547         vtkType = 0 ;
548         break ;
549       }
550       default : { 
551         vtkType = 0 ;
552         break ;
553       }
554       }
555     if (vtkType == 0)
556       throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<": MED element type not supported yet : " << cells_type[i].getType() ) ) ;
557     int numberOfCell = meshField->getNumberOfElements(MED_EN::MED_CELL,cells_type[i].getType()) ;
558     for (int j=0;j<numberOfCell;j++)
559       (*_vtkFile) << vtkType << endl ;
560   }
561
562   // first : field on node
563   // fields is on all node !
564
565   // second : field on cell
566   // fields is on all cell !
567
568   int dt = _ptrField->getIterationNumber();
569   int it = _ptrField->getOrderNumber();
570
571   ostringstream name ;
572   string nameField = _ptrField->getName();
573   MED_EN::medEntityMesh entitySupport = supportField->getEntity();
574   name << nameField << "_" << dt << "_" << it ;
575
576   if ( _ptrField->getGaussPresence() )
577     throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<<_ptrField->getName()<<" which use Gauss Points !" << entitySupport));
578
579   if (!(supportField->isOnAllElements()))
580     throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<<_ptrField->getName()<<" which is not on all entities of the mesh !" << entitySupport));
581
582   if (entitySupport == MED_EN::MED_NODE)
583     (*_vtkFile) << "POINT_DATA " << meshField->getNumberOfNodes() << endl ;
584   else if (entitySupport == MED_EN::MED_CELL)
585     (*_vtkFile) << "CELL_DATA " << meshField->getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS) << endl ;
586   else
587     throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<<_ptrField->getName()<<" which is not on all nodes or cells but it's on !" << entitySupport));
588
589   int NomberOfValue = supportField->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS) ;
590   int NomberOfComponents =  _ptrField->getNumberOfComponents() ;
591
592   MED_EN::med_type_champ fieldType = _ptrField->getValueType() ;
593
594   SCRUTE_MED(name.str());
595   SCRUTE_MED(fieldType);
596
597   switch (fieldType)
598     {
599     case MED_EN::MED_INT32 :
600       {
601         break ;
602       }
603     case MED_EN::MED_REEL64 :
604       {
605         break ;
606       }
607     default :
608       { 
609         throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<< name.str() <<" the type is not int or double !"));
610       }
611     }
612
613   if (NomberOfComponents==3)
614     (*_vtkFile) << "VECTORS " << name.str() << " int" << endl ;
615   else if (NomberOfComponents<=4)
616     {
617       (*_vtkFile) << "SCALARS " << name.str() << " int " << NomberOfComponents << endl ;
618       (*_vtkFile) << "LOOKUP_TABLE default" << endl ;
619     }
620   else
621     throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<<_ptrField->getName()<<" there are more than 4 components !"));
622
623   // IL EST POSSIBLE D'AVOIR LES DEUX BOUCLES D'ECRITURE POUR EVITER
624   // DE CONVERTIR LE CHAMP DANS LE BON TYPE D'ENTRELACEMENT
625   const T * value;
626   MEDMEM_Array_ * tmpArray = 0;
627   if ( _ptrField->getInterlacingType() == MED_EN::MED_NO_INTERLACE )
628     value = _ptrField->getValue();
629   else if ( _ptrField->getInterlacingType() == MED_EN::MED_NO_INTERLACE_BY_TYPE ) {
630     MEDMEM_Array_ * ptrArray = _ptrField->getArray();
631     MEDMEM_Array<T,NoInterlaceByTypeNoGaussPolicy> * temp = dynamic_cast<MEDMEM_Array<T,NoInterlaceByTypeNoGaussPolicy> * >  ( ptrArray );
632     MEDMEM_Array<T,NoInterlaceNoGaussPolicy> * array = ArrayConvert2No( *temp );
633     tmpArray = array;
634     value = array->getPtr();
635   }
636   else {
637     MEDMEM_Array_ * ptrArray = _ptrField->getArray();
638     MEDMEM_Array<T,FullInterlaceNoGaussPolicy> * temp = dynamic_cast<MEDMEM_Array<T,FullInterlaceNoGaussPolicy> * >  ( ptrArray );
639     MEDMEM_Array<T,NoInterlaceNoGaussPolicy> * array = ArrayConvert( *temp );
640     tmpArray = array;
641     value = array->getPtr();
642   }
643
644   for (int i=0; i<NomberOfValue; i++)
645     {
646       for(int j=0; j<NomberOfComponents; j++)
647         (*_vtkFile) << value[j*NomberOfValue+i] << " " ;
648       (*_vtkFile) << endl ;
649     }
650   
651   if ( _ptrField->getInterlacingType() != MED_EN::MED_NO_INTERLACE )
652     delete tmpArray;
653   END_OF_MED(LOC);
654 }
655
656 template <class T> void VTK_FIELD_DRIVER<T>::writeAppend(void) const
657   throw (MEDEXCEPTION)
658 {
659   const char * LOC = "VTK_FIELD_DRIVER::writeAppend(void) const " ;
660   BEGIN_OF_MED(LOC);
661
662   // we get the Support and its associated Mesh
663
664   const SUPPORT * supportField = _ptrField->getSupport();
665   MESH * meshField = supportField->getMesh();
666   if (! meshField )
667     throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<": mesh was not read before writing")) ;
668
669   // Well we must open vtk file first, because there are
670   // no other driver than MED for VTK that do it !
671   openConstAppend() ;
672
673   // first : field on node
674   // fields is on all node !
675
676   // second : field on cell
677   // fields is on all cell !
678
679   int dt = _ptrField->getIterationNumber();
680   int it = _ptrField->getOrderNumber();
681
682   ostringstream name ;
683   string nameField = _ptrField->getName();
684   MED_EN::medEntityMesh entitySupport = supportField->getEntity();
685   name << nameField << "_" << dt << "_" << it ;
686
687   if ( _ptrField->getGaussPresence() )
688     throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<<_ptrField->getName()<<" which use Gauss Points !" << entitySupport));
689
690   if (!(supportField->isOnAllElements()))
691     throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<<_ptrField->getName()<<" which is not on all entities of the mesh !" << entitySupport));
692
693   if (entitySupport == MED_EN::MED_NODE)
694     (*_vtkFile) << "POINT_DATA " << meshField->getNumberOfNodes() << endl ;
695   else if (entitySupport == MED_EN::MED_CELL)
696     (*_vtkFile) << "CELL_DATA " << meshField->getNumberOfElements(MED_EN::MED_CELL,MED_EN::MED_ALL_ELEMENTS) << endl ;
697   else
698     throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<<_ptrField->getName()<<" which is not on all nodes or cells but it's on !" << entitySupport));
699
700   int NomberOfValue = supportField->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS) ;
701   int NomberOfComponents =  _ptrField->getNumberOfComponents() ;
702
703   MED_EN::med_type_champ fieldType = _ptrField->getValueType() ;
704
705   SCRUTE_MED(name.str());
706   SCRUTE_MED(fieldType);
707   switch (fieldType)
708     {
709     case MED_EN::MED_INT32 :
710       {
711         break ;
712       }
713     case MED_EN::MED_REEL64 :
714       {
715         break ;
716       }
717     default :
718       { 
719         throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<< name.str() <<" the type is not int or double !"));
720       }
721     }
722
723   if (NomberOfComponents==3)
724     (*_vtkFile) << "VECTORS " << name.str() << " int" << endl ;
725   else if (NomberOfComponents<=4)
726     {
727       (*_vtkFile) << "SCALARS " << name.str() << " int " << NomberOfComponents << endl ;
728       (*_vtkFile) << "LOOKUP_TABLE default" << endl ;
729     }
730   else
731     throw MED_EXCEPTION(LOCALIZED(STRING(LOC) << "Could not write field "<<_ptrField->getName()<<" there are more than 4 components !"));
732
733   const T * value ;
734   MEDMEM_Array_ * tmpArray = 0;
735   if ( _ptrField->getInterlacingType() == MED_EN::MED_NO_INTERLACE )
736     value = _ptrField->getValue();
737   else if ( _ptrField->getInterlacingType() == MED_EN::MED_NO_INTERLACE_BY_TYPE ) {
738     MEDMEM_Array_ * ptrArray = _ptrField->getArray();
739     MEDMEM_Array<T,NoInterlaceByTypeNoGaussPolicy> * temp = dynamic_cast<MEDMEM_Array<T,NoInterlaceByTypeNoGaussPolicy> * >  ( ptrArray );
740     MEDMEM_Array<T,NoInterlaceNoGaussPolicy> * array = ArrayConvert2No( *temp );
741     tmpArray = array;
742     value = array->getPtr();
743   }
744   else {
745     MEDMEM_Array_ * ptrArray = _ptrField->getArray();
746     MEDMEM_Array<T,FullInterlaceNoGaussPolicy> * temp = dynamic_cast<MEDMEM_Array<T,FullInterlaceNoGaussPolicy> * >  ( ptrArray );
747     MEDMEM_Array<T,NoInterlaceNoGaussPolicy> * array = ArrayConvert( *temp );
748     tmpArray = array;
749     value = array->getPtr();
750   }
751
752   for (int i=0; i<NomberOfValue; i++)
753     {
754       for(int j=0; j<NomberOfComponents; j++)
755         (*_vtkFile) << value[j*NomberOfValue+i] << " " ;
756       (*_vtkFile) << endl ;
757     }
758
759   if ( _ptrField->getInterlacingType() != MED_EN::MED_NO_INTERLACE )
760     delete tmpArray;
761
762   END_OF_MED(LOC);
763 }
764 }//End namespace MEDMEM
765
766 #endif /* VTK_FIELD_DRIVER_HXX */