Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM_SWIG / test_profil_MedFieldDriver.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library 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 GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 ############################################################################
23 # this Python script is testing the profil functionality using the FIELD
24 # constructor via a MED driver.
25 ############################################################################
26 #
27 from libMEDMEM_Swig import *
28
29 # users inputs
30 #test 1 --- zzzz121b_without_tr6.med RESUZERODEPL____________________ 1 1
31 #test 2 --- zzzz121b_without_tr6.med RESUZEROERRE_ELGA_NORE__________ 1 1
32 #test 3 --- maill.00.med Indicateur_d_erreur_00 2 2
33
34 medFile = "zzzz121b_without_tr6.med"
35 #medFile = "maill.00.med"
36
37 fieldName = "RESUZERODEPL____________________"
38 #fieldName = "RESUZEROERRE_ELGA_NORE__________"
39 #fieldName = "Indicateur_d_erreur_00"
40
41 # default  value, may be changed according to what field is stored in medFile
42 ##iterationNumber = -1
43 ##orderNumber = -1
44 iterationNumber = 1
45 orderNumber = 1
46 #iterationNumber = 2
47 #orderNumber = 2
48
49 import os
50 #
51 #befor running this script, please be sure about the path the file fileName
52 #
53 filePath=os.environ["MED_ROOT_DIR"]
54 filePath=os.path.join(filePath, "share", "salome", "resources", "med")
55
56 medFile = os.path.join(filePath, medFile)
57
58 def analyseField(field):
59     fieldName = field.getName()
60     fieldType = field.getValueType()
61     fieldDesc = field.getDescription()
62     fieldIterationNumber = field.getIterationNumber()
63     fieldOrderNumber = field.getOrderNumber()
64     fieldTime = field.getTime()
65     fieldNbOfComp = field.getNumberOfComponents()
66     print "The field ",fieldName," with the description ",fieldDesc," typed ",fieldType
67     print "Iteration number ",fieldIterationNumber," OrderNumber ",fieldOrderNumber," Time ",fieldTime
68     print "It has ",fieldNbOfComp,"components"
69     for k in range(fieldNbOfComp):
70         kp1 = k+1
71         fieldCompName = field.getComponentName(kp1)
72         fieldCompDesc = field.getComponentDescription(kp1)
73         fieldCompUnit = field.getMEDComponentUnit(kp1)
74         print "      * Component:",kp1
75         print "          Name:",fieldCompName
76         print "          Description:",fieldCompDesc
77         print "          Unit:",fieldCompUnit
78         pass
79     fieldSupport = field.getSupport()
80     fieldMeshName = fieldSupport.getMeshName()
81     fieldSupportOnAll = fieldSupport.isOnAllElements()
82     fieldNbEntities = fieldSupport.getNumberOfElements(MED_ALL_ELEMENTS)
83     fieldEntityType = fieldSupport.getEntity()
84     fieldSupportNumber = range(1,fieldNbEntities+1)
85     if (not fieldSupportOnAll):
86         fieldSupportNumber = fieldSupport.getNumber(MED_ALL_ELEMENTS)
87         pass
88     print " fieldSupportNumber ", fieldSupportNumber
89     fieldInterlacingType = field.getInterlacingType()
90     print "It relies on the mesh named ",fieldMeshName
91     print "its interlacing type ",fieldInterlacingType
92     print "and it is on ",fieldNbEntities," entities of the type ",fieldEntityType
93     if (fieldInterlacingType == MED_FULL_INTERLACE):
94         for i in range(fieldNbEntities):
95             value = field.getRow(fieldSupportNumber[i])
96             print " * ",fieldSupportNumber[i]," --- ",value
97             pass
98         pass
99     elif (fieldInterlacingType == MED_FULL_INTERLACE):
100         for i in range(fieldNbOfComp):
101             value = field.getColumn(fieldSupportNumber[i])
102             print " * ",fieldSupportNumber[i]," --- ",value
103             pass
104         pass
105     pass
106
107 field = FIELDDOUBLE(MED_DRIVER, medFile, fieldName,
108                     iterationNumber, orderNumber)
109
110 analyseField(field)
111
112 print "END of the Pyhton script ..... Ctrl D to exit"