3 # /* This file is part of MED.
5 # * COPYRIGHT (C) 1999 - 2013 EDF R&D, CEA/DEN
6 # * MED is free software: you can redistribute it and/or modify
7 # * it under the terms of the GNU Lesser General Public License as published by
8 # * the Free Software Foundation, either version 3 of the License, or
9 # * (at your option) any later version.
11 # * MED is distributed in the hope that it will be useful,
12 # * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # * GNU Lesser General Public License for more details.
16 # * You should have received a copy of the GNU Lesser General Public License
17 # * along with MED. If not, see <http://www.gnu.org/licenses/>.
22 sys.path.append('/home/A96028/Salome/V7_main/tools/install/Medfichier-307-hdf51810/lib/python2.7/site-packages')
24 from med.medfile import *
25 from med.medmesh import *
26 from med.medfamily import *
27 from med.medfilter import *
30 def getGroupes(filename,debug=0) :
37 fid = MEDfileOpen(filename,MED_ACC_RDONLY)
39 return ("Pb a la lecture du fichier", listeGroupes,maa)
42 # /* Lecture des infos concernant le premier maillage */
43 maa, sdim, mdim, type, desc, dtunit, sort, nstep, rep, nomcoo,unicoo = MEDmeshInfo(fid, 1)
45 print "Maillage de nom : |%s| de dimension : %ld , et de type %s\n"%(maa,mdim,type)
46 print "Maillage de nom : |%s| , de dimension : %ld , et de type %s\n"%(maa,mdim,type)
47 print "\t -Dimension de l'espace : %ld\n"%(sdim)
48 print "\t -Description du maillage : %s\n"%(desc)
49 print "\t -Noms des axes : |%s|\n"%(nomcoo)
50 print "\t -Unités des axes : |%s|\n"%(unicoo)
51 print "\t -Type de repère : %s\n"%(rep)
52 print "\t -Nombre d'étape de calcul : %ld\n"%(nstep)
53 print "\t -Unité des dates : |%s|\n"%(dtunit)
55 # /* Lecture du nombre de familles */
56 nfam = MEDnFamily(fid,maa)
58 print "Nombre de familles : %d \n"%(nfam)
60 # /* Lecture de chaque famille */
61 for i in xrange(0,nfam):
63 # /* Lecture du nombre de groupe */
64 ngro = MEDnFamilyGroup(fid,maa,i+1)
66 print "Famille %d a %d groupes \n"%(i+1,ngro)
68 gro = MEDCHAR(MED_LNAME_SIZE*ngro+1)
70 nomfam,numfam,gro = MEDfamilyInfo(fid,maa,i+1,gro)
72 print "Famille de nom %s et de numero %d : \n"%(nomfam,numfam)
73 print "Attributs : \n"
75 for j in xrange(0,ngro):
76 # print "gro = %s\n"%(gro[j*MED_LNAME_SIZE:j*MED_LNAME_SIZE+MED_LNAME_SIZE])
77 groupSplit=gro[j*MED_LNAME_SIZE:j*MED_LNAME_SIZE+MED_LNAME_SIZE]
78 groupeName="".join(groupSplit).split("\x00")[0]
79 groupeName=groupeName.replace(' ','')
80 if groupeName[0:7]=="CENTRE_" : dicoNumFam[groupeName]=numfam
81 if groupeName not in listeGroupes : listeGroupes.append(groupeName)
87 # /* Lecture des Numeros de Familles */
89 nnoe, chgt, trsf = MEDmeshnEntity(fid,maa,MED_NO_DT,MED_NO_IT, MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE)
91 MEDmeshEntityFamilyNumberRd(fid,maa, MED_NO_DT, MED_NO_IT, MED_NODE,MED_NONE,nufano)
93 for groupe in dicoNumFam.keys():
94 famille=dicoNumFam[groupe]
96 while i < nufano.size():
97 if nufano[i]==famille :
98 dicoNumNode[groupe]=i+1
105 for groupe in dicoNumNode.keys() :
107 flt[0]=dicoNumNode[groupe]
110 err=MEDfilterEntityCr( fid, nnoe, 1, sdim, MED_ALL_CONSTITUENT, MED_FULL_INTERLACE, MED_COMPACT_PFLMODE, MED_NO_PROFILE,1 , flt, filter)
111 MEDmeshNodeCoordinateAdvancedRd(fid, maa, MED_NO_DT, MED_NO_IT, filter, coo1)
112 MEDfilterClose(filter)
113 dicoCoord[groupe]=coo1
114 # dicoCoord['CENTRE_saxBas']=(0,0,28.5e-3)
115 # dicoCoord['CENTRE_saxHaut']=(0,0,31.5e-3)
118 return ("",listeGroupes,maa,dicoCoord)
120 if __name__ == "__main__":
121 filename="/home/A96028/Carmel/Pascale/Domaine_Bidouille.med"
122 #filename="/home/A96028/Carmel/nouveauMed/Domaine.med"
123 print getGroupes(filename)