2 # -*- coding: iso-8859-1 -*-
4 # This script illustrates the basic usage of MEDCoupling and MEDLoader
5 # to read fields in a med file and make basics operation on the values
6 # (gboulant - 11/07/2011)
10 medfilename = "timeseries.med" # med source filename
11 meshName = "Grid_80x80" # name of the support mesh
12 dimrestriction = 0 # 0=no restriction
13 fieldName = "Pulse" # name of the field series
16 # ==============================================================
17 # Make a scaling. This does not require the loading of the mesh
19 from MEDLoader import MEDLoader, ON_NODES
21 iteration, order = (3,-1) # timestamps to consider
22 field=MEDLoader.ReadField(ON_NODES,
23 medfilename, meshName, dimrestriction,
24 fieldName, iteration, order)
26 field.applyFunc("f*3")
27 outfilename = "scaling.med"
28 MEDLoader.WriteField(outfilename,field,True)
32 # ==============================================================
33 # Make an addition. This requires to load first the mesh
36 # Load the support mesh
37 mesh = MEDLoader.ReadUMeshFromFile(medfilename, meshName, dimrestriction)
39 # Load the field at timestamps 3
40 iteration, order = (3,-1)
41 p3=MEDLoader.ReadField(ON_NODES,
42 medfilename,meshName,dimrestriction,
43 fieldName,iteration,order)
47 # Load the field at timestamps 4
48 iteration, order = (4,-1)
49 p4=MEDLoader.ReadField(ON_NODES,
50 medfilename, meshName, dimrestriction,
51 fieldName, iteration, order)
57 result.setName("p3+p4")
59 # We can finally save the result together with the operandes fields
60 outfilename = "addition.med"
61 MEDLoader.WriteField(outfilename,result,True)
62 MEDLoader.WriteField(outfilename,p3,False)
63 MEDLoader.WriteField(outfilename,p4,False)
66 # ==============================================================
67 # Make an addition. A different way that loads fields all at once
68 mesh = MEDLoader.ReadUMeshFromFile(medfilename, meshName, dimrestriction)
69 timestamps = [(3,-1),(4,-1)]
70 p3,p4 = MEDLoader.ReadFieldsOnSameMesh(ON_NODES,medfilename,
71 meshName,dimrestriction,
76 result.setName("p3+p4")
78 outfilename = "addition_01.med"
79 MEDLoader.WriteField(outfilename,result,True)