2 # Copyright (C) 2012-2014 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
24 return collections.defaultdict(tree)
31 filename = "timeseries.med"
32 filepath = os.path.join(os.path.abspath(os.path.dirname(__file__)),filename)
35 from MEDLoader import MEDLoader
36 meshNames = MEDLoader.GetMeshNames(filepath)
38 meshDimRelToMax = 0 # 0 = no restriction
40 for meshName in meshNames:
41 mesh = MEDLoader.ReadUMeshFromFile(filepath,meshName,meshDimRelToMax)
42 meshDict[meshName] = mesh
44 fieldNames = MEDLoader.GetAllFieldNamesOnMesh(filepath,meshName)
45 for fieldName in fieldNames:
46 listOfTypes = MEDLoader.GetTypesOfField(filepath,meshName,fieldName)
47 for typeOfDiscretization in listOfTypes:
48 fieldIterations = MEDLoader.GetFieldIterations(typeOfDiscretization,
52 for fieldIteration in fieldIterations:
53 itNumber = fieldIteration[0]
54 itOrder = fieldIteration[1]
56 field = MEDLoader.ReadField(typeOfDiscretization,
67 [typeOfDiscretization]\
68 [itNumber][itOrder] = field
71 # Q: use a list of structures whose an attribute could be a
72 # MEDCoupling field? Or a tree that you cross using attribute and
73 # whose leaves are the MEDCoupling fields?
74 # R: I think that the default structure should be a simple list that
75 # store objects whith properties that corresponds to the metadata (and
76 # if loaded the MEDCouplingField or Mesh). Then for specific request,
77 # a BTree could be create to organize the search (for example if we
78 # request all the fields for a given iteration step, then we should
79 # use the iteration step as a first classifaction switch of the tree
81 print fieldTree.keys()
84 for meshName in fieldTree.keys():
86 for fieldName in fieldTree[meshName].keys():
88 for fieldType in fieldTree[meshName][fieldName].keys():
90 for itNumber in fieldTree[meshName][fieldName][fieldType].keys():
91 for itOrder in fieldTree[meshName][fieldName][fieldType][itNumber].keys():
92 print " (%s,%s)"%(itNumber,itOrder)
93 print fieldTree[meshName][fieldName][fieldType][itNumber][itOrder]