1 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2009-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
21 # Author : Erwan ADAM (CEA), Anthony GEAY (CEA)
24 from MEDLoader import *
34 def convert(file_in, driver_in, driver_out, format=1, file_out=None):
40 if driver_out == "GIBI":
42 elif driver_out == "MED":
45 msg = "Driver out %s is unknown"%(driver_out)
46 raise NotImplementedError(msg)
50 if driver_in == "GIBI":
51 sr = SauvReader.New(file_in)
52 mfd= sr.loadInMEDFileDS()
54 elif driver_in == "MED":
55 mfd = MEDFileData(file_in)
58 raise NotImplementedError("Driver in %s is unknown"%(driver_in))
62 if driver_out == "GIBI":
64 sw.setMEDFileDS(mfd,0);#0 ?
67 mesh = mfd.getMeshes()[0]
68 mesh_dim = mesh.getSpaceDimension()
70 from sys import platform
71 if platform in ["win32"]:
75 content = content.replace("IFOUR -1", "IFOUR 2")
76 content = content.replace("IFOMOD -1", "IFOMOD 2")
77 f = open(file_out, "w")
82 cmd += ' -e "s/IFOUR -1/IFOUR 2/g"'
83 cmd += ' -e "s/IFOMOD -1/IFOMOD 2/g"'
84 # cmd += ' -e "s/IECHO 1/IECHO 0/g"'
85 cmd += ' %s > .dummy'%(file_out)
87 cmd += ' mv -f .dummy %s'%(file_out)
94 from castemlauncher import CastemLauncher
96 dgibi_stream += "OPTI REST FORMAT '%s' ;\n"%(file_out)
97 dgibi_stream += "REST FORMAT;\n"
98 file_out = file_out.replace('__format__', '')
99 dgibi_stream += "OPTI SAUV '%s' ;\n"%(file_out)
100 dgibi_stream += "SAUV ;\n"
101 cl = CastemLauncher(dgibi_stream)
102 cl.addTmpFiles(file_out+'__format__', "UTILNOTI", "UTILPROC")
106 elif driver_out == "MED":
107 mfd.write(file_out,2)
110 raise NotImplementedError("Driver in %s is unknown"%(driver_in))
115 convert(arg, "GIBI", "MED")
123 if arg.find('--format') == 0:
126 value = arg.split("=")[1]
139 convert(arg, "MED", "GIBI", format)