2 # Copyright (C) 2012-2016 CEA/DEN, EDF R&D
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, or (at your option) any later version.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 from MEDLoader import MEDLoader
24 #filename = "madnex_field.med"
25 filename = "timeseries.med"
26 filepath = os.path.join(os.path.abspath(os.path.dirname(__file__)),filename)
28 # Read the source meshes
29 meshNames = MEDLoader.GetMeshNames(filepath)
31 # Set to True if the meshes and fields data must be loaded. Otherwise,
32 # only theire descriptions will be loaded.
33 READ_PHYSICAL_DATA=False
35 for meshName in meshNames:
39 # At this step, one can load the mesh of name meshName (but it is
40 # not an obligation to continue to explore the metadata)
41 meshDimRelToMax = 0 # 0 = no restriction
42 if READ_PHYSICAL_DATA:
43 mesh = MEDLoader.ReadUMeshFromFile(filepath,meshName,meshDimRelToMax)
44 # Note that the read function required the parameter
45 # meshDimRelToMax. This parameter discreminates the meshdim you
46 # are interested to relatively to the maximal dimension of cells
47 # contained in the mesh in file (then its value could be 0, -1, -2
48 # or -3 depending on the max dimension of the mesh. 0 means "no
51 # Read the names of the fields that rely on this mesh
52 fieldNames = MEDLoader.GetAllFieldNamesOnMesh(filepath,meshName)
54 for fieldName in fieldNames:
58 # A field name could identify several MEDCoupling fields, that
59 # differ by their spatial discretization on the mesh (values on
60 # cells, values on nodes, ...). This spatial discretization is
61 # specified by the TypeOfField that is an integer value in this
68 # As a consequence, before loading values of a field, we have
69 # to determine the types of spatial discretization defined for
70 # this field and to choose one.
72 listOfTypes = MEDLoader.GetTypesOfField(filepath,meshName,fieldName)
73 for typeOfDiscretization in listOfTypes:
74 print " %s"%typeOfDiscretization
76 # Then, we can get the iterations associated to this field on
77 # this type of spatial discretization:
78 fieldIterations = MEDLoader.GetFieldIterations(typeOfDiscretization,
83 # Then, we can access to the physical data for each
84 # iteration of this field
85 for fieldIteration in fieldIterations:
86 itNumber = fieldIteration[0]
87 itOrder = fieldIteration[1]
88 print " (%s,%s)"%(itNumber,itOrder)
90 if READ_PHYSICAL_DATA:
91 medCouplingField = MEDLoader.ReadField(typeOfDiscretization,
98 print medCouplingField