2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2012-2016 CEA/DEN, EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 # This script illustrates the basic usage of MEDCoupling and MEDLoader
23 # to read fields in a med file and make basics operation on the values
24 # (gboulant - 11/07/2011)
28 medfilename = "timeseries.med" # med source filename
29 meshName = "Grid_80x80" # name of the support mesh
30 dimrestriction = 0 # 0=no restriction
31 fieldName = "Pulse" # name of the field series
34 # ==============================================================
35 # Make a scaling. This does not require the loading of the mesh
37 from MEDLoader import MEDLoader, ON_NODES
39 iteration, order = (3,-1) # timestamps to consider
40 field=MEDLoader.ReadField(ON_NODES,
41 medfilename, meshName, dimrestriction,
42 fieldName, iteration, order)
44 field.applyFunc("f*3")
45 outfilename = "scaling.med"
46 MEDLoader.WriteField(outfilename,field,True)
50 # ==============================================================
51 # Make an addition. This requires to load first the mesh
54 # Load the support mesh
55 mesh = MEDLoader.ReadUMeshFromFile(medfilename, meshName, dimrestriction)
57 # Load the field at timestamps 3
58 iteration, order = (3,-1)
59 p3=MEDLoader.ReadField(ON_NODES,
60 medfilename,meshName,dimrestriction,
61 fieldName,iteration,order)
65 # Load the field at timestamps 4
66 iteration, order = (4,-1)
67 p4=MEDLoader.ReadField(ON_NODES,
68 medfilename, meshName, dimrestriction,
69 fieldName, iteration, order)
75 result.setName("p3+p4")
77 # We can finally save the result together with the operandes fields
78 outfilename = "addition.med"
79 MEDLoader.WriteField(outfilename,result,True)
80 MEDLoader.WriteField(outfilename,p3,False)
81 MEDLoader.WriteField(outfilename,p4,False)
84 # ==============================================================
85 # Make an addition. A different way that loads fields all at once
86 mesh = MEDLoader.ReadUMeshFromFile(medfilename, meshName, dimrestriction)
87 timestamps = [(3,-1),(4,-1)]
88 p3,p4 = MEDLoader.ReadFieldsOnSameMesh(ON_NODES,medfilename,
89 meshName,dimrestriction,
94 result.setName("p3+p4")
96 outfilename = "addition_01.med"
97 MEDLoader.WriteField(outfilename,result,True)