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