source: trunk/aeres/scripts/aeresrh.py @ 161

Last change on this file since 161 was 161, checked in by pinsard, 12 years ago

draft of AERES tools

  • Property svn:executable set to *
  • Property svn:keywords set to Id URL
File size: 2.9 KB
Line 
1#!/usr/bin/env python
2# -*- coding: iso-8859-1 -*-
3
4"""
5
6==========
7aeresrh.py
8==========
9
10DESCRIPTION
11===========
12
13extract information from aeresrh.xls
14
15.. option:: --ifile <file>
16             
17      file to read
18
19.. only:: man
20
21    Figure is visible on PDF and HTML documents only.
22
23    .. only:: html or latex
24
25       .. graphviz::
26
27             digraph aeresrh {
28     rh [shape=diamond,
29         fontname=Courier,
30 label='{ifile}'
31
32           aeresrh [shape=box,
33             fontname=Courier,
34               color=blue,
35                 URL="http://forge.ipsl.jussieu.fr/pulsation/browser//branches/aeresrh/scripts/aeresrh.py",
36           label="${PROJECT}/++/aeresrh.py"];
37             }
38         
39SEE ALSO
40========
41
42:ref:
43
44EXAMPLES
45========
46
47 aeresrh.py -ifile ${PROJECT}/data/aeresrh.xls
48
49TODO
50====
51
52make it work
53
54coding rules (pylint)
55
56EVOLUTIONS
57==========
58
59$Id$
60
61$URL$
62
63- fplod 20120405
64
65  * creation draft
66
67"""
68   
69import sys
70import os
71from os.path import dirname, basename
72import glob
73from optparse import OptionParser
74
75try:
76    import xlrd
77except ImportError:
78    print("Failed to import xlrd from any known place")
79    sys.exit(1)
80
81def get_option_parser ():
82    """parse CLI arguments
83
84           :returns: parser
85          :rtype: :class:`optparse.OptionParser`
86    """
87
88    parser = OptionParser('%prog [--verbose ] [--ifile file')
89    parser.add_option ('-V', '--verbose',
90        help='produce verbose output',
91        action='store_true',
92        default=False,
93        dest='is_verbose')
94    parser.add_option ('-i', '--ifile',
95        help='file to be read',
96        type='string',
97        dest='ifile',
98        default=None,
99        action='store')
100
101    return parser
102
103def readrh(ifile, is_verbose):
104
105    """
106    read ifile
107
108    return ++
109    """
110     
111    if is_verbose == True:
112        print('iii : read %s' % filein_namelist_wrf)
113
114    # ouverture du fichier Excel
115    wb = xlrd.open_workbook(ifile)
116
117    # feuilles dans le classeur
118    print wb.sheet_names()
119
120    # lecture des données dans la première feuille
121    sh = wb.sheet_by_name(u'Feuil1')
122    for rownum in range(sh.nrows):
123        print sh.row_values(rownum)
124
125    # lecture par colonne
126    colonne1 = sh.col_values(0)
127    print colonne1
128     
129    colonne2=sh.col_values(1)
130    print colonne2
131    [u'x', 235.0, 245.0, 255.0, 265.0, 275.0, 285.0, 295.0]
132 
133    # extraction d'un élément particulier
134    print colonne1[1],colonne2[1]
135
136    return sh.col_values(1)
137
138def aeresrh():
139    """main
140        """
141    try:
142        parser = get_option_parser ()
143        (fromcli, args) = parser.parse_args()
144    except IOError, msg:
145        parser.error(str(msg))
146
147    is_verbose = fromcli.is_verbose
148    ifile = fromcli.ifile
149    if fromcli.is_verbose == True:
150       print ('ifile : %s' % (ifile))
151
152    surname, firstname = readrh(ifile, is_verbose)
153    print (' surname %s' % (surname))
154
155# Run main, if called from the command line
156if __name__ == '__main__':
157    aeresrh()
158
Note: See TracBrowser for help on using the repository browser.