1 // Copyright (C) 2010-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "vtkMedDriver.h"
22 #include "vtkObjectFactory.h"
23 #include "vtkStringArray.h"
24 #include "vtkDataArray.h"
25 #include "vtkIdTypeArray.h"
28 #include "vtkMedFile.h"
29 #include "vtkMedCartesianGrid.h"
30 #include "vtkMedPolarGrid.h"
31 #include "vtkMedCurvilinearGrid.h"
32 #include "vtkMedUnstructuredGrid.h"
33 #include "vtkMedField.h"
34 #include "vtkMedMesh.h"
35 #include "vtkMedFamily.h"
36 #include "vtkMedUtilities.h"
37 #include "vtkMedEntityArray.h"
38 #include "vtkMedLocalization.h"
39 #include "vtkMedProfile.h"
40 #include "vtkMedFieldOverEntity.h"
41 #include "vtkMedFieldStep.h"
42 #include "vtkMedGroup.h"
43 #include "vtkMedIntArray.h"
44 #include "vtkMedLink.h"
46 #ifdef MedReader_HAVE_PARALLEL_INFRASTRUCTURE
47 #include "vtkMultiProcessController.h"
48 #include "vtkMPIController.h"
49 #include <vtkMPICommunicator.h>
53 vtkCxxSetObjectMacro(vtkMedDriver, MedFile, vtkMedFile);
55 //vtkCxxRevisionMacro(vtkMedDriver, "$Revision$")
56 vtkStandardNewMacro(vtkMedDriver)
58 vtkMedDriver::vtkMedDriver()
65 vtkMedDriver::~vtkMedDriver()
67 if (this->OpenLevel > 0)
69 vtkWarningMacro("The file has not be closed before destructor.")
73 this->SetMedFile(NULL);
76 int vtkMedDriver::RestrictedOpen()
79 if (this->MedFile == NULL || this->MedFile->GetFileName() == NULL)
81 vtkDebugMacro("Error : FileName has not been set ");
85 if (this->OpenLevel <= 0)
91 med_err conforme = MEDfileCompatibility(this->MedFile->GetFileName(),
95 vtkErrorMacro("The file " << this->MedFile->GetFileName()
96 << " is not a HDF5 file, aborting.");
102 vtkErrorMacro("The file " << this->MedFile->GetFileName()
103 << " has not been written with the"
104 << " same version as the one currently used to read it, this may lead"
105 << " to errors. Please use the medimport tool.");
111 vtkErrorMacro("The file " << this->MedFile->GetFileName()
112 << " is not compatible, please import it to the new version using medimport.");
116 this->FileId = MEDfileOpen(this->MedFile->GetFileName(), MED_ACC_RDONLY);
117 if (this->FileId < 0)
119 vtkDebugMacro("Error : unable to open file "
120 << this->MedFile->GetFileName());
127 this->ParallelFileId = -1;
131 int vtkMedDriver::Open()
134 if (this->MedFile == NULL || this->MedFile->GetFileName() == NULL)
136 vtkDebugMacro("Error : FileName has not been set ");
140 if (this->OpenLevel <= 0)
146 med_err conforme = MEDfileCompatibility(this->MedFile->GetFileName(),
150 vtkErrorMacro("The file " << this->MedFile->GetFileName()
151 << " is not a HDF5 file, aborting.");
157 vtkErrorMacro("The file " << this->MedFile->GetFileName()
158 << " has not been written with the"
159 << " same version as the one currently used to read it, this may lead"
160 << " to errors. Please use the medimport tool.");
166 vtkErrorMacro("The file " << this->MedFile->GetFileName()
167 << " is not compatible, please import it to the new version using medimport.");
171 this->FileId = MEDfileOpen(this->MedFile->GetFileName(), MED_ACC_RDONLY);
172 if (this->FileId < 0)
174 vtkDebugMacro("Error : unable to open file "
175 << this->MedFile->GetFileName());
180 this->ParallelFileId = -1;
182 #ifdef MedReader_HAVE_PARALLEL_INFRASTRUCTURE
183 // the following code opens the file in parallel
184 vtkMultiProcessController* controller =
185 vtkMultiProcessController::GetGlobalController();
187 if (controller == NULL)
193 lpID = controller->GetLocalProcessId();
196 vtkMPICommunicator* commu = vtkMPICommunicator::SafeDownCast(
197 controller->GetCommunicator() );
200 //vtkErrorMacro("Communicator is NULL in Open");
203 MPI_Comm* mpi_com = NULL;
204 mpi_com = commu->GetMPIComm()->GetHandle();
207 vtkErrorMacro("MPI communicator is NULL in Open");
211 if (controller->GetNumberOfProcesses() > 1)
213 int major, minor, release;
214 if (MEDfileNumVersionRd(this->FileId, &major, &minor, &release) < 0)
216 vtkErrorMacro("Impossible to read the version of this file");
222 this->ParallelFileId = MEDparFileOpen(this->MedFile->GetFileName(),
229 vtkErrorMacro("Parallel access is not allowed in MED files prior to version 3");
234 if (this->ParallelFileId < 0)
236 vtkDebugMacro("Error : unable to parallel-open file "
237 << this->MedFile->GetFileName());
246 void vtkMedDriver::Close()
249 if (this->OpenLevel == 0)
251 if (MEDfileClose(this->FileId) < 0)
253 vtkErrorMacro("Error: unable to close the current file.");
257 if (this->ParallelFileId != -1)
259 if (MEDfileClose(this->ParallelFileId) < 0)
261 vtkErrorMacro("Error: unable to parallel-close the current file.");
264 this->ParallelFileId = -1;
268 bool vtkMedDriver::CanReadFile()
270 bool canRead = (this->RestrictedOpen() >= 0);
275 void vtkMedDriver::ReadFileVersion(int* major, int* minor, int* release)
277 FileRestrictedOpen open(this);
279 med_int amajor, aminor, arelease;
280 if (MEDfileNumVersionRd(this->FileId, &amajor, &aminor, &arelease) < 0)
282 vtkErrorMacro("Impossible to read the version of this file");
290 void vtkMedDriver::ReadRegularGridInformation(vtkMedRegularGrid* grid)
292 vtkErrorMacro("vtkMedDriver::ReadInformation not Implemented !");
296 void vtkMedDriver::ReadCurvilinearGridInformation(vtkMedCurvilinearGrid* grid)
298 vtkErrorMacro("vtkMedDriver::ReadInformation not Implemented !");
302 void vtkMedDriver::ReadUnstructuredGridInformation(vtkMedUnstructuredGrid* grid)
304 vtkErrorMacro("vtkMedDriver::ReadInformation not Implemented !");
309 // load all Information data associated with this standard grid.
310 void vtkMedDriver::ReadGridInformation(vtkMedGrid* grid)
312 if(vtkMedRegularGrid::SafeDownCast(grid) != NULL)
314 this->ReadRegularGridInformation(vtkMedRegularGrid::SafeDownCast(grid));
316 if(vtkMedCurvilinearGrid::SafeDownCast(grid) != NULL)
318 this->ReadCurvilinearGridInformation(vtkMedCurvilinearGrid::SafeDownCast(grid));
320 if(vtkMedUnstructuredGrid::SafeDownCast(grid) != NULL)
322 this->ReadUnstructuredGridInformation(vtkMedUnstructuredGrid::SafeDownCast(grid));
326 void vtkMedDriver::ReadFamilyInformation(vtkMedMesh* mesh, vtkMedFamily* family)
328 vtkErrorMacro("vtkMedDriver::ReadFamilyInformation not Implemented !");
332 void vtkMedDriver::ReadFileInformation(vtkMedFile* file)
334 vtkErrorMacro("vtkMedDriver::ReadFileInformation not Implemented !");
338 void vtkMedDriver::ReadProfileInformation(vtkMedProfile* profile)
340 vtkErrorMacro("vtkMedDriver::ReadProfileInformation not Implemented !");
344 void vtkMedDriver::ReadFieldInformation(vtkMedField* field)
346 vtkErrorMacro("vtkMedDriver::ReadFieldInformation not Implemented !");
350 void vtkMedDriver::ReadFieldOverEntityInformation(vtkMedFieldOverEntity* fieldOverEntity)
352 vtkErrorMacro("vtkMedDriver::ReadFieldOverEntityInformation not Implemented !");
356 void vtkMedDriver::ReadMeshInformation(vtkMedMesh* mesh)
358 vtkErrorMacro("vtkMedDriver::ReadMeshInformation not Implemented !");
362 void vtkMedDriver::ReadLocalizationInformation(vtkMedLocalization* loc)
364 vtkErrorMacro("vtkMedDriver::ReadLocalizationInformation not Implemented !");
368 void vtkMedDriver::ReadInterpolationInformation(vtkMedInterpolation* interp)
370 vtkErrorMacro("vtkMedDriver::ReadInterpolationInformation not Implemented !");
374 void vtkMedDriver::ReadFieldStepInformation(vtkMedFieldStep* step, bool readAllEntityInfo)
376 vtkErrorMacro("vtkMedDriver::ReadFieldStepInformation not Implemented !");
380 void vtkMedDriver::ReadFieldOnProfileInformation(vtkMedFieldOnProfile* fop)
382 vtkErrorMacro("vtkMedDriver::ReadFieldOnProfileInformation not Implemented !");
386 void vtkMedDriver::ReadStructElementInformation(
387 vtkMedStructElement*)
389 vtkErrorMacro("vtkMedDriver::ReadStructElementInformation not Implemented !");
393 void vtkMedDriver::ReadSupportMeshInformation(
396 vtkErrorMacro("vtkMedDriver::ReadSupportMeshInformation not Implemented !");
400 void vtkMedDriver::ReadConstantAttributeInformation(vtkMedConstantAttribute*)
402 vtkErrorMacro("vtkMedDriver::ReadConstantAttributeInformation not Implemented !");
406 void vtkMedDriver::ReadVariableAttributeInformation(vtkMedVariableAttribute*)
408 vtkErrorMacro("vtkMedDriver::ReadVariableAttributeInformation not Implemented !");
412 void vtkMedDriver::LoadPointGlobalIds(vtkMedGrid* grid)
414 vtkErrorMacro("vtkMedDriver::LoadPointGlobalIds not Implemented !");
418 void vtkMedDriver::LoadFamilyIds(vtkMedEntityArray* array)
420 vtkErrorMacro("vtkMedDriver::LoadFamilyIds not Implemented !");
424 void vtkMedDriver::LoadCoordinates(vtkMedGrid* grid)
426 vtkErrorMacro("vtkMedDriver::LoadCoordinates not Implemented !");
430 void vtkMedDriver::LoadProfile(vtkMedProfile* profile)
432 vtkErrorMacro("vtkMedDriver::LoadProfile not Implemented !");
436 void vtkMedDriver::LoadConnectivity(vtkMedEntityArray* array)
438 vtkErrorMacro("vtkMedDriver::LoadConnectivity not Implemented !");
442 void vtkMedDriver::LoadCellGlobalIds(vtkMedEntityArray* array)
444 vtkErrorMacro("vtkMedDriver::LoadGlobalIds not Implemented !");
448 void vtkMedDriver::LoadField(vtkMedFieldOnProfile* foe, med_storage_mode mode)
450 vtkErrorMacro("vtkMedDriver::LoadFieldOnProfile not Implemented !");
454 void vtkMedDriver::LoadVariableAttribute(vtkMedVariableAttribute*,
457 vtkErrorMacro("vtkMedDriver::LoadVariableAttribute not Implemented !");
461 void vtkMedDriver::PrintSelf(ostream& os, vtkIndent indent)
463 this->Superclass::PrintSelf(os, indent);
464 PRINT_IVAR(os, indent, OpenLevel);
465 PRINT_IVAR(os, indent, FileId);