]> SALOME platform Git repositories - modules/med.git/blob - src/MEDOP/tut/medloader/manage.py
Salome HOME
Add documentation for users and basic tutotial script examples (associated to the...
[modules/med.git] / src / MEDOP / tut / medloader / manage.py
1 #!/usr/bin/env python
2
3 # _T1A
4 import collections
5 def tree():
6     return collections.defaultdict(tree)
7
8 fieldTree = tree()
9 meshDict = {}
10 # _T1B
11
12 import os
13 filename = "timeseries.med"
14 filepath = os.path.join(os.path.abspath(os.path.dirname(__file__)),filename)
15
16 # _T2A
17 from MEDLoader import MEDLoader
18 meshNames = MEDLoader.GetMeshNames(filepath)
19
20 meshDimRelToMax = 0 # 0 = no restriction
21
22 for meshName in meshNames:
23     mesh = MEDLoader.ReadUMeshFromFile(filepath,meshName,meshDimRelToMax)
24     meshDict[meshName] = mesh
25
26     fieldNames = MEDLoader.GetAllFieldNamesOnMesh(filepath,meshName)
27     for fieldName in fieldNames:
28         listOfTypes = MEDLoader.GetTypesOfField(filepath,meshName,fieldName)
29         for typeOfDiscretization in listOfTypes:
30             fieldIterations = MEDLoader.GetFieldIterations(typeOfDiscretization,
31                                                            filepath,
32                                                            meshName,
33                                                            fieldName)
34             for fieldIteration in fieldIterations:
35                 itNumber = fieldIteration[0]
36                 itOrder  = fieldIteration[1]
37
38                 field = MEDLoader.ReadField(typeOfDiscretization,
39                                             filepath,
40                                             meshName,
41                                             meshDimRelToMax,
42                                             fieldName,
43                                             itNumber,
44                                             itOrder)
45
46                 fieldTree\
47                            [meshName]\
48                            [fieldName]\
49                            [typeOfDiscretization]\
50                            [itNumber][itOrder] = field
51 # _T2B
52
53 # Q: use a list of structures whose an attribute could be a
54 # MEDCoupling field? Or a tree that you cross using attribute and
55 # whose leaves are the MEDCoupling fields?
56 # R: I think that the default structure should be a simple list that
57 # store objects whith properties that corresponds to the metadata (and
58 # if loaded the MEDCouplingField or Mesh). Then for specific request,
59 # a BTree could be create to organize the search (for example if we
60 # request all the fields for a given iteration step, then we should
61 # use the iteration step as a first classifaction switch of the tree
62
63 print fieldTree.keys()
64
65 # _T3A
66 for meshName in fieldTree.keys():
67     print "%s"%meshName
68     for fieldName in fieldTree[meshName].keys():
69         print "  %s"%fieldName
70         for fieldType in fieldTree[meshName][fieldName].keys():
71             print "    %s"%fieldType
72             for itNumber in fieldTree[meshName][fieldName][fieldType].keys():
73                 for itOrder in fieldTree[meshName][fieldName][fieldType][itNumber].keys():
74                     print "      (%s,%s)"%(itNumber,itOrder)
75                     print fieldTree[meshName][fieldName][fieldType][itNumber][itOrder]
76 # _T3B