1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 ###################################################################################
25 # This Python script is testing the writing in Med format V2.1 V2.2
26 # You can check if the analysis of the families is OK.
27 ###################################################################################
29 from libMEDMEM_Swig import *
33 #befor running this script, please be sure about the path the files
35 filePath=os.environ["MED_ROOT_DIR"]
36 filePath=os.path.join(filePath, "share", "salome", "resources", "med")
39 #medFiles.append("geomMesh21.med")
40 medFiles.append("geomMesh22.med")
41 nbOfFiles = len(medFiles)
43 for i in range(nbOfFiles):
45 medFile = os.path.join( filePath, medFile )
51 for i in range(nbOfFiles):
54 rootFile = string.split(medFile,".")[0]
55 medFileOut21 = rootFile + "Out21.med"
56 medFileOut22 = rootFile + "Out22.med"
58 print "Mounting in memory of the mesh ",meshName," from the file ",medFile
59 mesh = MESH(MED_DRIVER,medFile,meshName)
62 print "Families analysis of the mesh ",meshName," from the file ",medFile
65 for entity in [MED_NODE,MED_CELL,MED_FACE,MED_EDGE]:
66 nbFam = mesh.getNumberOfFamilies(entity)
67 if (entity == MED_NODE) & (nbFam > 0):
68 print "This mesh has",nbFam,"Node Family(ies)"
70 elif (entity == MED_CELL) & (nbFam > 0):
71 print "This mesh has",nbFam,"Cell Family(ies)"
73 elif (entity == MED_FACE) & (nbFam > 0):
74 print "This mesh has",nbFam,"Face Family(ies)"
76 elif (entity == MED_EDGE) & (nbFam > 0):
77 print "This mesh has",nbFam,"Edge Family(ies)"
81 for j in range(nbFam):
83 family = mesh.getFamily(entity,j+1)
84 familyName = family.getName()
85 familyBool = family.isOnAllElements()
87 print " -this famyly named ",familyName," is on all entities"
90 familyNumber = family.getNumber(MED_ALL_ELEMENTS)
91 print " -this famyly named ",familyName," has ",len(familyNumber)," entities"
98 print " adding a Med file V2.2 format driver to the mesh with the file ",medFileOut22
99 idMedV22 = mesh.addDriver(MED_DRIVER,medFileOut22,mesh.getName())
102 print " writing the mesh in Med file V2.2 format"
109 for i in range(nbOfFiles):
110 medFile = medFiles[i]
111 rootFile = string.split(medFile,".")[0]
112 medFileOut22 = rootFile + "Out22.med"
114 medFiles2.append(medFileOut22)
117 nbOfFiles = len(medFiles2)
119 for i in range(nbOfFiles):
120 medFile = medFiles2[i]
121 mesh = MESH(MED_DRIVER,medFile,meshName)
123 print "Families analysis of the mesh ",meshName," from the file ",medFile
125 for entity in [MED_NODE,MED_CELL,MED_FACE,MED_EDGE]:
126 nbFam = mesh.getNumberOfFamilies(entity)
127 if (entity == MED_NODE) & (nbFam > 0):
128 print "This mesh has",nbFam,"Node Family(ies)"
130 elif (entity == MED_CELL) & (nbFam > 0):
131 print "This mesh has",nbFam,"Cell Family(ies)"
133 elif (entity == MED_FACE) & (nbFam > 0):
134 print "This mesh has",nbFam,"Face Family(ies)"
136 elif (entity == MED_EDGE) & (nbFam > 0):
137 print "This mesh has",nbFam,"Edge Family(ies)"
141 for j in range(nbFam):
143 family = mesh.getFamily(entity,j+1)
144 familyName = family.getName()
145 familyBool = family.isOnAllElements()
147 print " -this famyly named ",familyName," is on all entities"
150 familyNumber = family.getNumber(MED_ALL_ELEMENTS)
151 print " -this famyly named ",familyName," has ",len(familyNumber)," entities"
159 print "END of the Pyhton script ..... Ctrl D to exit"