~ubuntu-branches/ubuntu/precise/code-saturne/precise

« back to all changes in this revision

Viewing changes to bin/cs_plot_probes.py

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2011-11-24 00:00:08 UTC
  • mfrom: (6.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20111124000008-2vo99e38267942q5
Tags: 2.1.0-3
Install a missing file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#-------------------------------------------------------------------------------
2
 
#   This file is part of the Code_Saturne Solver.
3
 
#
4
 
#   Copyright (C) 2009  EDF
5
 
#
6
 
#   The Code_Saturne Preprocessor is free software; you can redistribute it
7
 
#   and/or modify it under the terms of the GNU General Public License
8
 
#   as published by the Free Software Foundation; either version 2 of
9
 
#   the License, or (at your option) any later version.
10
 
#
11
 
#   The Code_Saturne Preprocessor is distributed in the hope that it will be
12
 
#   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13
 
#   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
#   GNU General Public License for more details.
15
 
#
16
 
#   You should have received a copy of the GNU General Public Licence
17
 
#   along with the Code_Saturne Preprocessor; if not, write to the
18
 
#   Free Software Foundation, Inc.,
19
 
#   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
 
#-------------------------------------------------------------------------------
21
 
 
22
 
import os
23
 
import sys
24
 
import tempfile
25
 
from cs_exec_environment import run_command
26
 
from optparse import OptionParser
27
 
 
28
 
#-------------------------------------------------------------------------------
29
 
 
30
 
def process_cmd_line(argv):
31
 
    """
32
 
    Processes the passed command line arguments.
33
 
 
34
 
    Input Argument:
35
 
      arg -- This can be either a list of arguments as in
36
 
             sys.argv[1:] or a string that is similar to the one
37
 
             passed on the command line.  If it is a string the
38
 
             string is split to create a list of arguments.
39
 
    """
40
 
 
41
 
    parser = OptionParser(usage="Usage: %prog <monitoring file>")
42
 
 
43
 
    (options, args) = parser.parse_args(argv)
44
 
 
45
 
    if len(args) == 1:
46
 
        file = args[0]
47
 
    else:
48
 
        parser.print_help()
49
 
        sys.exit(1)
50
 
 
51
 
    return file
52
 
 
53
 
#-------------------------------------------------------------------------------
54
 
 
55
 
def plot(f):
56
 
    """
57
 
    Plot a monitoring file with XmGrace.
58
 
    """
59
 
    retval = 0
60
 
 
61
 
    # Create a temporary file and correctly format the monitoring file
62
 
 
63
 
    temp_file = tempfile.mkstemp(suffix=".hst")
64
 
 
65
 
    cmd = "grep -v '#'" + " " + str(f) + "|cut -c9- >" + " " + temp_file[1]
66
 
    run_command(cmd)
67
 
 
68
 
    # Run XmGrace -nxy command
69
 
 
70
 
    cmd = "xmgrace -geometry 1100x850 -nxy" + " " + temp_file[1]
71
 
    run_command(cmd)
72
 
 
73
 
    # Cleanup and exit
74
 
 
75
 
    os.remove(temp_file[1])
76
 
 
77
 
    return retval
78
 
 
79
 
#-------------------------------------------------------------------------------
80
 
 
81
 
def main(argv):
82
 
    """
83
 
    Main function.
84
 
    """
85
 
 
86
 
    file = process_cmd_line(argv)
87
 
 
88
 
    retcode = plot(file)
89
 
 
90
 
    sys.exit(retcode)
91
 
 
92
 
if __name__ == '__main__':
93
 
    main(sys.argv[1:])