1 #include "vtkMedDriver.h"
3 #include "vtkObjectFactory.h"
4 #include "vtkStringArray.h"
5 #include "vtkDataArray.h"
6 #include "vtkIdTypeArray.h"
9 #include "vtkMedFile.h"
10 #include "vtkMedCartesianGrid.h"
11 #include "vtkMedPolarGrid.h"
12 #include "vtkMedCurvilinearGrid.h"
13 #include "vtkMedUnstructuredGrid.h"
14 #include "vtkMedField.h"
15 #include "vtkMedMesh.h"
16 #include "vtkMedFamily.h"
17 #include "vtkMedUtilities.h"
18 #include "vtkMedEntityArray.h"
19 #include "vtkMedLocalization.h"
20 #include "vtkMedProfile.h"
21 #include "vtkMedFieldOverEntity.h"
22 #include "vtkMedFieldStep.h"
23 #include "vtkMedGroup.h"
24 #include "vtkMedIntArray.h"
25 #include "vtkMedLink.h"
27 #ifdef MedReader_HAVE_PARALLEL_INFRASTRUCTURE
28 #include "vtkMultiProcessController.h"
29 #include "vtkMPIController.h"
30 #include <vtkMPICommunicator.h>
34 vtkCxxSetObjectMacro(vtkMedDriver, MedFile, vtkMedFile);
36 //vtkCxxRevisionMacro(vtkMedDriver, "$Revision$")
37 vtkStandardNewMacro(vtkMedDriver)
39 vtkMedDriver::vtkMedDriver()
46 vtkMedDriver::~vtkMedDriver()
48 if (this->OpenLevel > 0)
50 vtkWarningMacro("The file has not be closed before destructor.")
54 this->SetMedFile(NULL);
57 int vtkMedDriver::RestrictedOpen()
60 if (this->MedFile == NULL || this->MedFile->GetFileName() == NULL)
62 vtkDebugMacro("Error : FileName has not been set ");
66 if (this->OpenLevel <= 0)
72 med_err conforme = MEDfileCompatibility(this->MedFile->GetFileName(),
76 vtkErrorMacro("The file " << this->MedFile->GetFileName()
77 << " is not a HDF5 file, aborting.");
83 vtkErrorMacro("The file " << this->MedFile->GetFileName()
84 << " has not been written with the"
85 << " same version as the one currently used to read it, this may lead"
86 << " to errors. Please use the medimport tool.");
92 vtkErrorMacro("The file " << this->MedFile->GetFileName()
93 << " is not compatible, please import it to the new version using medimport.");
97 this->FileId = MEDfileOpen(this->MedFile->GetFileName(), MED_ACC_RDONLY);
100 vtkDebugMacro("Error : unable to open file "
101 << this->MedFile->GetFileName());
108 this->ParallelFileId = -1;
112 int vtkMedDriver::Open()
115 if (this->MedFile == NULL || this->MedFile->GetFileName() == NULL)
117 vtkDebugMacro("Error : FileName has not been set ");
121 if (this->OpenLevel <= 0)
127 med_err conforme = MEDfileCompatibility(this->MedFile->GetFileName(),
131 vtkErrorMacro("The file " << this->MedFile->GetFileName()
132 << " is not a HDF5 file, aborting.");
138 vtkErrorMacro("The file " << this->MedFile->GetFileName()
139 << " has not been written with the"
140 << " same version as the one currently used to read it, this may lead"
141 << " to errors. Please use the medimport tool.");
147 vtkErrorMacro("The file " << this->MedFile->GetFileName()
148 << " is not compatible, please import it to the new version using medimport.");
152 this->FileId = MEDfileOpen(this->MedFile->GetFileName(), MED_ACC_RDONLY);
153 if (this->FileId < 0)
155 vtkDebugMacro("Error : unable to open file "
156 << this->MedFile->GetFileName());
161 this->ParallelFileId = -1;
163 #ifdef MedReader_HAVE_PARALLEL_INFRASTRUCTURE
164 // the following code opens the file in parallel
165 vtkMultiProcessController* controller =
166 vtkMultiProcessController::GetGlobalController();
168 if (controller == NULL)
174 lpID = controller->GetLocalProcessId();
177 vtkMPICommunicator* commu = vtkMPICommunicator::SafeDownCast(
178 controller->GetCommunicator() );
181 //vtkErrorMacro("Communicator is NULL in Open");
184 MPI_Comm* mpi_com = NULL;
185 mpi_com = commu->GetMPIComm()->GetHandle();
188 vtkErrorMacro("MPI communicator is NULL in Open");
192 if (controller->GetNumberOfProcesses() > 1)
194 int major, minor, release;
195 if (MEDfileNumVersionRd(this->FileId, &major, &minor, &release) < 0)
197 vtkErrorMacro("Impossible to read the version of this file");
203 this->ParallelFileId = MEDparFileOpen(this->MedFile->GetFileName(),
210 vtkErrorMacro("Parallel access is not allowed in MED files prior to version 3");
215 if (this->ParallelFileId < 0)
217 vtkDebugMacro("Error : unable to parallel-open file "
218 << this->MedFile->GetFileName());
227 void vtkMedDriver::Close()
230 if (this->OpenLevel == 0)
232 if (MEDfileClose(this->FileId) < 0)
234 vtkErrorMacro("Error: unable to close the current file.");
238 if (this->ParallelFileId != -1)
240 if (MEDfileClose(this->ParallelFileId) < 0)
242 vtkErrorMacro("Error: unable to parallel-close the current file.");
245 this->ParallelFileId = -1;
249 bool vtkMedDriver::CanReadFile()
251 bool canRead = (this->RestrictedOpen() >= 0);
256 void vtkMedDriver::ReadFileVersion(int* major, int* minor, int* release)
258 FileRestrictedOpen open(this);
260 med_int amajor, aminor, arelease;
261 if (MEDfileNumVersionRd(this->FileId, &amajor, &aminor, &arelease) < 0)
263 vtkErrorMacro("Impossible to read the version of this file");
271 void vtkMedDriver::ReadRegularGridInformation(vtkMedRegularGrid* grid)
273 vtkErrorMacro("vtkMedDriver::ReadInformation not Implemented !");
277 void vtkMedDriver::ReadCurvilinearGridInformation(vtkMedCurvilinearGrid* grid)
279 vtkErrorMacro("vtkMedDriver::ReadInformation not Implemented !");
283 void vtkMedDriver::ReadUnstructuredGridInformation(vtkMedUnstructuredGrid* grid)
285 vtkErrorMacro("vtkMedDriver::ReadInformation not Implemented !");
290 // load all Information data associated with this standard grid.
291 void vtkMedDriver::ReadGridInformation(vtkMedGrid* grid)
293 if(vtkMedRegularGrid::SafeDownCast(grid) != NULL)
295 this->ReadRegularGridInformation(vtkMedRegularGrid::SafeDownCast(grid));
297 if(vtkMedCurvilinearGrid::SafeDownCast(grid) != NULL)
299 this->ReadCurvilinearGridInformation(vtkMedCurvilinearGrid::SafeDownCast(grid));
301 if(vtkMedUnstructuredGrid::SafeDownCast(grid) != NULL)
303 this->ReadUnstructuredGridInformation(vtkMedUnstructuredGrid::SafeDownCast(grid));
307 void vtkMedDriver::ReadFamilyInformation(vtkMedMesh* mesh, vtkMedFamily* family)
309 vtkErrorMacro("vtkMedDriver::ReadFamilyInformation not Implemented !");
313 void vtkMedDriver::ReadFileInformation(vtkMedFile* file)
315 vtkErrorMacro("vtkMedDriver::ReadFileInformation not Implemented !");
319 void vtkMedDriver::ReadProfileInformation(vtkMedProfile* profile)
321 vtkErrorMacro("vtkMedDriver::ReadProfileInformation not Implemented !");
325 void vtkMedDriver::ReadFieldInformation(vtkMedField* field)
327 vtkErrorMacro("vtkMedDriver::ReadFieldInformation not Implemented !");
331 void vtkMedDriver::ReadFieldOverEntityInformation(vtkMedFieldOverEntity* fieldOverEntity)
333 vtkErrorMacro("vtkMedDriver::ReadFieldOverEntityInformation not Implemented !");
337 void vtkMedDriver::ReadMeshInformation(vtkMedMesh* mesh)
339 vtkErrorMacro("vtkMedDriver::ReadMeshInformation not Implemented !");
343 void vtkMedDriver::ReadLocalizationInformation(vtkMedLocalization* loc)
345 vtkErrorMacro("vtkMedDriver::ReadLocalizationInformation not Implemented !");
349 void vtkMedDriver::ReadInterpolationInformation(vtkMedInterpolation* interp)
351 vtkErrorMacro("vtkMedDriver::ReadInterpolationInformation not Implemented !");
355 void vtkMedDriver::ReadFieldStepInformation(vtkMedFieldStep* step, bool readAllEntityInfo)
357 vtkErrorMacro("vtkMedDriver::ReadFieldStepInformation not Implemented !");
361 void vtkMedDriver::ReadFieldOnProfileInformation(vtkMedFieldOnProfile* fop)
363 vtkErrorMacro("vtkMedDriver::ReadFieldOnProfileInformation not Implemented !");
367 void vtkMedDriver::ReadStructElementInformation(
368 vtkMedStructElement*)
370 vtkErrorMacro("vtkMedDriver::ReadStructElementInformation not Implemented !");
374 void vtkMedDriver::ReadSupportMeshInformation(
377 vtkErrorMacro("vtkMedDriver::ReadSupportMeshInformation not Implemented !");
381 void vtkMedDriver::ReadConstantAttributeInformation(vtkMedConstantAttribute*)
383 vtkErrorMacro("vtkMedDriver::ReadConstantAttributeInformation not Implemented !");
387 void vtkMedDriver::ReadVariableAttributeInformation(vtkMedVariableAttribute*)
389 vtkErrorMacro("vtkMedDriver::ReadVariableAttributeInformation not Implemented !");
393 void vtkMedDriver::LoadPointGlobalIds(vtkMedGrid* grid)
395 vtkErrorMacro("vtkMedDriver::LoadPointGlobalIds not Implemented !");
399 void vtkMedDriver::LoadFamilyIds(vtkMedEntityArray* array)
401 vtkErrorMacro("vtkMedDriver::LoadFamilyIds not Implemented !");
405 void vtkMedDriver::LoadCoordinates(vtkMedGrid* grid)
407 vtkErrorMacro("vtkMedDriver::LoadCoordinates not Implemented !");
411 void vtkMedDriver::LoadProfile(vtkMedProfile* profile)
413 vtkErrorMacro("vtkMedDriver::LoadProfile not Implemented !");
417 void vtkMedDriver::LoadConnectivity(vtkMedEntityArray* array)
419 vtkErrorMacro("vtkMedDriver::LoadConnectivity not Implemented !");
423 void vtkMedDriver::LoadCellGlobalIds(vtkMedEntityArray* array)
425 vtkErrorMacro("vtkMedDriver::LoadGlobalIds not Implemented !");
429 void vtkMedDriver::LoadField(vtkMedFieldOnProfile* foe, med_storage_mode mode)
431 vtkErrorMacro("vtkMedDriver::LoadFieldOnProfile not Implemented !");
435 void vtkMedDriver::LoadVariableAttribute(vtkMedVariableAttribute*,
438 vtkErrorMacro("vtkMedDriver::LoadVariableAttribute not Implemented !");
442 void vtkMedDriver::PrintSelf(ostream& os, vtkIndent indent)
444 this->Superclass::PrintSelf(os, indent);
445 PRINT_IVAR(os, indent, OpenLevel);
446 PRINT_IVAR(os, indent, FileId);