2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 ############################################################################
23 # This script tests conversion of EnSight to MEDMEM by performing following
24 # operations on all available EnSight files:
25 # - read EnSight file into MEDMEM and breifly dump it's content;
26 # - store MEDMEM to med file;
27 # - write EnSight file in different formats: Gold and EnSight6, ASCII and binary;
28 # - 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
31 ############################################################################
34 from dumpMEDMEM import *
42 ,(ENSIGHT_GOLD,Binary)
47 dataDir = os.getenv("DATA_DIR")
48 tmpDir = os.getenv("TMP")
50 tmpDir = os.getenv("TMPDIR", "/tmp")
52 # EnSight samples are in EXAMPLES CVS repository, in directory SAMPLES_SRC/EnSight.
53 # DATA_DIR should contain path to SAMPLES_SRC
54 inDir = os.path.join( dataDir, "EnSight")
55 if not os.access(inDir, os.F_OK):
56 raise RuntimeError, "Path to EnSight files not found, check DATA_DIR environment"
58 outDir = os.path.join( tmpDir,"Ensight_out")
59 if not os.access(outDir, os.F_OK):
63 # find out if ens_checker is available
64 has_ens_checker = False
65 tmpFile = os.path.join( outDir, "has_ens_checker" )
66 os.system("ens_checker _.case > %s 2>&1" % tmpFile)
67 tmpFile = open( tmpFile ).read()
68 if search("EnSight Data Format Checker", tmpFile):
69 has_ens_checker = True
71 print "\nWarning: ens_checker utility NOT available"
81 def check_ens(casefile, logfile):
82 if not has_ens_checker:
84 cmd = "(cd %s; ens_checker %s > %s 2>&1)" % (outDir, casefile, logfile)
85 err = os.system( cmd )
86 if os.access(logfile, os.F_OK):
87 log = open(logfile).read()
88 if search("bummer", log):
90 raise RuntimeError, "cd %s; ens_checker %s" % (outDir, casefile)
91 if search("Warning:", log):
96 def compatibilityPb():
97 "Print traceback and return true if exception is due to EnSight-MEDMEM incompatibility"
98 isCompatibilityPb = ( sys.exc_value.__str__().find("compatibility problem") > 0 )
100 print '$$$$$$$$$$$$$$$$$$$$ COMPATIBILITY PROBLEM $$$$$$$$$$$$$$$$$$$$$$$$'
101 print sys.exc_value, "\n"
104 traceback.print_exc()
105 return isCompatibilityPb
107 from dircache import listdir
112 # ,"zmat2d_esca.case"
118 # ,"ghost_structured.case"
119 # ,"ghost_unstructured.case"
120 # ,"ironProt_ascii.case"
121 # ,"ironProt_bin.case"
122 # ,"mandelbrot1.case"
123 # ,"mandelbrot2.case"
125 # ,"office6_bin.case"
126 # ,"office_ascii.case"
128 # ,"performance.case"
129 # ,"range_structured.case"
131 # ,"RectGrid_ascii.case"
132 # ,"RectGrid_bin.case"
136 # ,"blow2_ascii.case"
140 # ,"blow5_ascii.case"
145 inFiles = listdir( inDir )
148 for inFile in inFiles: # loop on all files in inDir
151 basename, ext = os.path.splitext( inFile )
152 if ext != ".case": continue
154 # read EnSight into MEDMEM
156 setIgnoreIncompatibility(0)
158 ensFile = os.path.join( inDir, inFile )
159 print "\nreading",ensFile
164 medFromEns = ENSIGHT_MED_RDONLY_DRIVER(ensFile);
165 fields = medFromEns.read()
167 mesh = MESH(ENSIGHT_DRIVER,ensFile,"");
168 meshes.append( mesh )
172 mesh = f.getSupport().getMesh()
173 if mesh and not mesh.getName() in meshNames:
174 meshes.append( mesh )
175 meshNames.append( mesh.getName() )
181 if not compatibilityPb():
186 # show MEDMEM contents
189 ShowMesh( mesh, 10, [10,10,10] )
193 ShowFields( fields, 10 )
195 # write MEDMEM into MED
197 medFile = os.path.join( outDir, basename + ".med" )
199 print "write",medFile
201 m.write( MED_DRIVER,medFile )
204 fTyped = f.castToTypedField()
205 fTyped.write(MED_DRIVER,medFile)
208 # write MEDMEM into EnSight
210 for format,bin in formats:
211 ensFile = os.path.join( outDir, basename )
212 if format == ENSIGHT_GOLD:
213 formatName = "ENSIGHT GOLD"
216 formatName = "ENSIGHT 6"
220 formatName += " Binary"
223 formatName += " ASCII"
228 print "Format: \t",formatName
231 setEnSightFormatForWriting( format, bin )
233 print "writting", ensFile
237 medEnsDriver = ENSIGHT_MED_WRONLY_DRIVER (ensFile, fields)
240 mesh2EnsDriver = ENSIGHT_MESH_WRONLY_DRIVER( ensFile, mesh )
241 mesh2EnsDriver.write()
243 if not compatibilityPb():
246 # try to write anayway, maybe it will be ok
248 setIgnoreIncompatibility(1)
253 mesh2EnsDriver.write()
255 if not compatibilityPb():
261 # check generated EnSight
263 checkFile = os.path.join( outDir, basename + ".ens_checker" )
264 check_ens(ensFile, checkFile)
267 # Ok I was warned about it
275 # remove created files
276 for f in listdir( outDir ):
277 deleteFile( os.path.join( outDir, f ))