Salome HOME
a08e4820c20325ce8cd37b40bfd07a9fbab953ba
[modules/med.git] / src / MEDOP / tut / medloader / explore.py
1 #!/usr/bin/env python
2
3 from MEDLoader import MEDLoader
4
5 import os
6 #filename = "madnex_field.med"
7 filename = "timeseries.med"
8 filepath = os.path.join(os.path.abspath(os.path.dirname(__file__)),filename)
9
10 # Read the source meshes
11 meshNames = MEDLoader.GetMeshNames(filepath)
12
13 # Set to True if the meshes and fields data must be loaded. Otherwise,
14 # only theire descriptions will be loaded.
15 READ_PHYSICAL_DATA=False
16
17 for meshName in meshNames:
18
19     print "%s"%meshName
20
21     # At this step, one can load the mesh of name meshName (but it is
22     # not an obligation to continue to explore the metadata)
23     meshDimRelToMax = 0 # 0 = no restriction
24     if READ_PHYSICAL_DATA:
25         mesh = MEDLoader.ReadUMeshFromFile(filepath,meshName,meshDimRelToMax)
26     # Note that the read function required the parameter
27     # meshDimRelToMax. This parameter discreminates the meshdim you
28     # are interested to relatively to the maximal dimension of cells
29     # contained in the mesh in file (then its value could be 0, -1, -2
30     # or -3 depending on the max dimension of the mesh. 0 means "no
31     # restriction".
32
33     # Read the names of the fields that rely on this mesh
34     fieldNames = MEDLoader.GetAllFieldNamesOnMesh(filepath,meshName)
35
36     for fieldName in fieldNames:
37
38         print "  %s"%fieldName
39         
40         # A field name could identify several MEDCoupling fields, that
41         # differ by their spatial discretization on the mesh (values on
42         # cells, values on nodes, ...). This spatial discretization is
43         # specified by the TypeOfField that is an integer value in this
44         # list:
45         # 0 = ON_CELLS  
46         # 1 = ON_NODES  
47         # 2 = ON_GAUSS_PT       
48         # 3 = ON_GAUSS_NE
49         #
50         # As a consequence, before loading values of a field, we have
51         # to determine the types of spatial discretization defined for
52         # this field and to chooose one.
53
54         listOfTypes = MEDLoader.GetTypesOfField(filepath,meshName,fieldName)
55         for typeOfDiscretization in listOfTypes:
56             print "    %s"%typeOfDiscretization
57
58             # Then, we can get the iterations associated to this field on
59             # this type of spatial discretization:
60             fieldIterations = MEDLoader.GetFieldIterations(typeOfDiscretization,
61                                                            filepath,
62                                                            meshName,
63                                                            fieldName)
64
65             # Then, we can access to the physical data for each
66             # iteration of this field
67             for fieldIteration in fieldIterations:
68                 itNumber = fieldIteration[0]
69                 itOrder  = fieldIteration[1]
70                 print "      (%s,%s)"%(itNumber,itOrder)
71                 
72                 if READ_PHYSICAL_DATA:
73                     medCouplingField = MEDLoader.ReadField(typeOfDiscretization,
74                                                            filepath,
75                                                            meshName,
76                                                            meshDimRelToMax,
77                                                            fieldName,
78                                                            itNumber,
79                                                            itOrder)
80                     print medCouplingField