metro_read_observation_ref.py 2.98 KB
Newer Older
1
2
# METRo : Model of the Environment and Temperature of Roads
# METRo is Free and is proudly provided by the Government of Canada
Miguel Tremblay's avatar
Miguel Tremblay committed
3
# Copyright (C) Her Majesty The Queen in Right of Canada, Environment Canada, 2006
Sasa Zhang's avatar
Sasa Zhang committed
4
#
5
#  Questions or bugs report: metro@ec.gc.ca
6
#  METRo repository: https://framagit.org/metroprojects/metro
7
#  Documentation: https://framagit.org/metroprojects/metro/wikis/home
8
9
10
11
12
13
14
#
# Code contributed by:
#  Miguel Tremblay - Canadian meteorological center
#  Francois Fortin - Canadian meteorological center
#
#  $LastChangedDate$
#  $LastChangedRevision$
Sasa Zhang's avatar
Sasa Zhang committed
15
##################################################################################
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


Sasa Zhang's avatar
Sasa Zhang committed
31
from executable_module.metro_read import Metro_read
32
33
34
35
36
37
38
39
import metro_logger
import metro_config
from data_module import metro_infdata
from toolbox import metro_util


_ = metro_util.init_translation('metro_read_observation_ref')

Sasa Zhang's avatar
Sasa Zhang committed
40

41
42
class Metro_read_observation_ref(Metro_read):

Sasa Zhang's avatar
Sasa Zhang committed
43
    # methodes redefinies
44
45
46
47
48
49
50
51
52
53
    def start(self):
        Metro_read.start(self)
        if metro_config.key_exist('FILE_OBSERVATION_REF_FILENAME'):
            sFilename = metro_config.get_value('FILE_OBSERVATION_REF_FILENAME')
        else:
            sFilename = ""
        if sFilename != "":
            try:
                sFile_content = self._read_input_data(sFilename)
            except IOError:
Sasa Zhang's avatar
Sasa Zhang committed
54
55
                sError_message = _("No file was read. METRo may need this ") + _("file content later.")
                metro_logger.print_message(metro_logger.LOGGER_MSG_CRITICAL, sError_message)
56
57
            else:
                # creer et ajouter infdata
Sasa Zhang's avatar
Sasa Zhang committed
58
59
                infdata_observation_ref = metro_infdata.Metro_infdata( 'OBSERVATION_REF',
                                                                       metro_infdata.DATATYPE_METRO_DATA_COLLECTION)
60
61
62
                infdata_observation_ref.set_input_information(sFile_content)
                self.add_infdata(infdata_observation_ref)
        else:
Sasa Zhang's avatar
Sasa Zhang committed
63
64
65
66
            sError_message = _("If you want to read a second observation file,") + _("\nplease use the option: ") + \
                             _("'--input-observation-ref'.") + _("\nYou can safely remove this module from the ") + \
                             _("EXECUTION SEQUENCE\nif you don't need it.")
            metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING, sError_message)