Salome HOME
Copyright update 2020
[tools/medcoupling.git] / src / MEDLoader / Swig / case2med
1 #!/usr/bin/env python
2 #  -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2020  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
22 from CaseReader import CaseReader
23 from optparse import OptionParser
24 import os
25
26 parser = OptionParser()
27 parser.set_usage("Convert a Case file to a MED file.\n   %prog [options] case_file")
28 parser.add_option("-c", "--currentdir", action="store_true", dest="here", default=False,
29                   help="Are generated MED file generated in current directory. By default not, MED file is generated in directory containing the input file (default False)")
30 (opts, args) = parser.parse_args()
31
32 if len(args) != 1:
33     parser.print_usage()
34     exit(1)
35     pass
36     
37 fname=args[0]  #"cas_test_simple.case"
38 if opts.here:
39     fOut=os.path.splitext(os.path.basename(fname))[0]+".med"
40     pass
41 else:
42     fOut=os.path.splitext(fname)[0]+".med"
43     pass
44 ###
45 cr=CaseReader(fname)
46 try:
47     medfd=cr.loadInMEDFileDS()
48 except:
49     print("An error occurred during the conversion!")
50     print("#######################################")
51     raise
52 medfd.write(fOut,2)
53 print("#########\nFile \"%s\" written !\n#########"%(fOut))
54