Salome HOME
Copyright update 2021
[tools/medcoupling.git] / src / MEDLoader / Swig / med2case
1 #!/usr/bin/env python
2 #  -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2021  CEA/DEN, EDF R&D
4 #
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, or (at your option) any later version.
9 #
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.
14 #
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
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21 # Author : Anthony GEAY (CEA/DEN/DM2S/STMF/LGLS)
22
23 from MEDLoader import MEDFileData,InterpKernelException
24 from CaseWriter import CaseWriter
25 from optparse import OptionParser
26 import os
27
28 parser = OptionParser()
29 parser.set_usage("Convert a MED file to a Case file.\n   %prog [options] med_file")
30 parser.add_option("-g", "--groups", action="store_true", dest="groups", default=False,
31                   help="Are groups in meshes stored in MEDFile exported in output case as subparts (default False)")
32 parser.add_option("-c", "--currentdir", action="store_true", dest="here", default=False,
33                   help="Are generated case,geo files generated in current directory. By default not, files are generated in directory containing the input file  (default False)")
34 (opts, args) = parser.parse_args()
35
36 if len(args) != 1:
37     parser.print_usage()
38     exit(1)
39     pass
40     
41 fname=os.path.abspath(args[0])  #"cas_test_simple.case"
42 if opts.here:
43     fOut=os.path.splitext(os.path.basename(fname))[0]+".case"
44     pass
45 else:
46     fOut=os.path.splitext(fname)[0]+".case"
47     pass
48 ###
49 try:
50     cw=CaseWriter.New()
51     cw.setExportingGroups(opts.groups)
52     mfd=MEDFileData(fname)
53     cw.setMEDFileDS(mfd)
54     listOfWrittenFileNames=cw.write(fOut)
55 except InterpKernelException as e:
56     print("An error occurred during the conversion!")
57     print("#######################################")
58     raise e
59 print("#########")
60 for l in listOfWrittenFileNames:
61     print("File \"%s\" successfully written !"%(l))
62     pass
63 print("#########")