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