Salome HOME
mise à jour catalogues Telemac branche v7p2
[tools/eficas.git] / CarmelCND / acquiertGroupes.py
1 #! /usr/bin/env python
2 # -*- coding:utf-8 -*-
3 # /*  This file is part of MED.
4 #  *
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.
10 #  *
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.
15 #  *
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/>.
18 #  */
19
20
21 import sys
22 sys.path.append('/home/A96028/Salome/V7_main/tools/install/Medfichier-307-hdf51810/lib/python2.7/site-packages')
23
24 from med.medfile import *
25 from med.medmesh import *
26 from med.medfamily import *
27 from med.medfilter import *
28
29
30 def getGroupes(filename,debug=0) :
31     listeGroupes=[]
32     maa=""
33     
34     dicoNumFam={}
35
36     try :
37         fid = MEDfileOpen(filename,MED_ACC_RDONLY)
38     except :
39         return ("Pb a la lecture du fichier", listeGroupes,maa)
40
41    
42     # /* Lecture des infos concernant le premier maillage */
43     maa, sdim, mdim, type, desc, dtunit, sort, nstep, rep, nomcoo,unicoo = MEDmeshInfo(fid, 1)
44     if debug :
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)
54    
55     # /* Lecture du nombre de familles */
56     nfam = MEDnFamily(fid,maa)
57     if debug :
58         print "Nombre de familles : %d \n"%(nfam)
59    
60     # /* Lecture de chaque famille */
61     for i in xrange(0,nfam):
62    
63         # /* Lecture du nombre de groupe */
64         ngro = MEDnFamilyGroup(fid,maa,i+1)
65         if debug :
66             print "Famille %d a %d groupes \n"%(i+1,ngro)
67    
68         gro  = MEDCHAR(MED_LNAME_SIZE*ngro+1)
69          
70         nomfam,numfam,gro = MEDfamilyInfo(fid,maa,i+1,gro)
71         if debug :
72             print "Famille de nom %s et de numero %d : \n"%(nomfam,numfam)
73             print "Attributs : \n"
74     
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) 
82
83
84     #print dicoNumFam
85     #print listeGroupes 
86     
87     # /* Lecture des Numeros de Familles */ 
88     
89     nnoe, chgt, trsf = MEDmeshnEntity(fid,maa,MED_NO_DT,MED_NO_IT, MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE)
90     nufano = MEDINT(nnoe)
91     MEDmeshEntityFamilyNumberRd(fid,maa, MED_NO_DT, MED_NO_IT, MED_NODE,MED_NONE,nufano)
92     dicoNumNode={}
93     for groupe in dicoNumFam.keys():
94         famille=dicoNumFam[groupe]
95         i=0
96         while i < nufano.size():
97            if nufano[i]==famille :
98               dicoNumNode[groupe]=i+1
99               break
100            i=i+1
101    
102    
103     #print dicoNumNode
104     dicoCoord={}
105     for groupe in dicoNumNode.keys() :
106         flt=MEDINT(1)
107         flt[0]=dicoNumNode[groupe]
108         coo1=MEDFLOAT(3)
109         filter=med_filter()
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)
116
117     MEDfileClose(fid)
118     return ("",listeGroupes,maa,dicoCoord)
119
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)