2 # Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG
3 # PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 ############################################################################
22 # This script tests conversion of EnSight to MEDMEM by performing following
23 # operations on all available EnSight files:
24 # - read EnSight file into MEDMEM and breifly dump it's content;
25 # - store MEDMEM to med file;
26 # - write EnSight file in different formats: Gold and EnSight6, ASCII and binary;
27 # - checks generated EnSight files using ens_checker utility (if available).
29 # EnSight samples are in EXAMPLES salome CVS repository, in directory SAMPLES_SRC/EnSight.
30 # DATA_DIR should contain path to SAMPLES_SRC
32 ############################################################################
35 from dumpMEDMEM import *
43 ,(ENSIGHT_GOLD,Binary)
48 dataDir = os.getenv("DATA_DIR")
49 tmpDir = os.getenv("TMP")
51 tmpDir = os.getenv("TMPDIR")
53 # EnSight samples are in EXAMPLES CVS repository, in directory SAMPLES_SRC/EnSight.
54 # DATA_DIR should contain path to SAMPLES_SRC
55 inDir = os.path.join( dataDir, "EnSight")
56 if not os.access(inDir, os.F_OK):
57 raise RuntimeError, "Path to EnSight files not found, check DATA_DIR environment"
59 outDir = os.path.join( tmpDir,"Ensight_out")
60 if not os.access(outDir, os.F_OK):
64 # find out if ens_checker is available
65 has_ens_checker = False
66 tmpFile = os.path.join( outDir, "has_ens_checker" )
67 os.system("ens_checker _.case > %s 2>&1" % tmpFile)
68 tmpFile = open( tmpFile ).read()
69 if search("EnSight Data Format Checker", tmpFile):
70 has_ens_checker = True
72 print "\nWarning: ens_checker utility NOT available"
82 def check_ens(casefile, logfile):
83 if not has_ens_checker:
85 cmd = "(cd %s; ens_checker %s > %s 2>&1)" % (outDir, casefile, logfile)
86 err = os.system( cmd )
87 if os.access(logfile, os.F_OK):
88 log = open(logfile).read()
89 if search("bummer", log):
91 raise RuntimeError, "cd %s; ens_checker %s" % (outDir, casefile)
92 if search("Warning:", log):
97 def compatibilityPb():
98 "Print traceback and return true if exception is due to EnSight-MEDMEM incompatibility"
99 isCompatibilityPb = ( sys.exc_value.__str__().find("compatibility problem") > 0 )
100 if isCompatibilityPb:
101 print '$$$$$$$$$$$$$$$$$$$$ COMPATIBILITY PROBLEM $$$$$$$$$$$$$$$$$$$$$$$$'
102 print sys.exc_value, "\n"
105 traceback.print_exc()
106 return isCompatibilityPb
108 from dircache import listdir
113 # ,"zmat2d_esca.case"
119 # ,"ghost_structured.case"
120 # ,"ghost_unstructured.case"
121 # ,"ironProt_ascii.case"
122 # ,"ironProt_bin.case"
123 # ,"mandelbrot1.case"
124 # ,"mandelbrot2.case"
126 # ,"office6_bin.case"
127 # ,"office_ascii.case"
129 # ,"performance.case"
130 # ,"range_structured.case"
132 # ,"RectGrid_ascii.case"
133 # ,"RectGrid_bin.case"
137 # ,"blow2_ascii.case"
141 # ,"blow5_ascii.case"
146 inFiles = listdir( inDir )
149 for inFile in inFiles: # loop on all files in inDir
152 basename, ext = os.path.splitext( inFile )
153 if ext != ".case": continue
155 # read EnSight into MEDMEM
157 setIgnoreIncompatibility(0)
159 ensFile = os.path.join( inDir, inFile )
160 print "\nreading",ensFile
163 medFromEns = MED(ENSIGHT_DRIVER, ensFile)
166 if not compatibilityPb():
171 # show MEDMEM contents
172 m2m_nom = medFromEns.getMeshName(0)
173 mesh = medFromEns.getMesh(m2m_nom)
175 ShowMesh( mesh, 10, [10,10,10] )
179 ShowFields( medFromEns, 10 )
181 # write MEDMEM into MED
183 medFile = os.path.join( outDir, basename + ".med" )
185 print "write",medFile
186 wdrv = medFromEns.addDriver(MED_DRIVER,medFile)
187 medFromEns.write( wdrv )
189 # write MEDMEM into EnSight
191 for format,bin in formats:
192 ensFile = os.path.join( outDir, basename )
193 if format == ENSIGHT_GOLD:
194 formatName = "ENSIGHT GOLD"
197 formatName = "ENSIGHT 6"
201 formatName += " Binary"
204 formatName += " ASCII"
209 print "Format: \t",formatName
212 setEnSightFormatForWriting( format, bin )
214 medEnsDriver = ENSIGHT_MED_WRONLY_DRIVER (ensFile, medFromEns)
215 print "writting", ensFile
220 if not compatibilityPb():
223 # try to write anayway, maybe it will be ok
225 setIgnoreIncompatibility(1)
229 if not compatibilityPb():
235 # check generated EnSight
237 checkFile = os.path.join( outDir, basename + ".ens_checker" )
238 check_ens(ensFile, checkFile)
241 # Ok I was warned about it
249 # remove created files
250 for f in listdir( outDir ):
251 deleteFile( os.path.join( outDir, f ))