Exemplo n.º 1
0
 def load_table(self, filename):
     """ Load a table into a dictionary """
     table = {}
     with open(filename) as f:
         finished = False
         while not finished:
             descriptors = []
             line = f.readline()
             if line:
                 if line.lstrip()[0] != "#":
                     fxy, num_to_append, fxy_to_append = (
                         get_descriptor(line[1:7]),
                         int(line[7:10]),
                         get_descriptor(line[11:17]),
                     )
                     descriptors.append(fxy_to_append)
                     for _ in range(num_to_append - 1):
                         line = f.readline()
                         if line and line.lstrip()[0] != "#":
                             fxy_to_append = get_descriptor(line[11:17])
                             descriptors.append(fxy_to_append)
                     table[fxy] = descriptors
             else:
                 finished = True
     return table
Exemplo n.º 2
0
 def load_table(self, filename):
     """ Load a table into a dictionary """
     table = {}
     f = open(filename, "r")
     contents = f.read()
     pattern = re.compile(
         "^ (?P<FXY>\d{6}) (?P<Description>.{64}) (?P<Units>.{24}) (?P<Scale>.{3}) (?P<Ref>.{12}) (?P<Width>.{3}).*?$",
         re.M,
     )
     for m in pattern.finditer(contents):
         d = m.groupdict()
         fxy, description, units, scale, ref, width = (
             d["FXY"],
             d["Description"].strip(),
             d["Units"].strip(),
             int(d["Scale"]),
             int(d["Ref"]),
             int(d["Width"]),
         )
         if "CODE TABLE" in units:
             units = "CODE TABLE"
         if "FLAG TABLE" in units:
             units = "FLAG TABLE"
         table[get_descriptor(fxy)] = TableBEntry(description, units, scale, ref, width)
     f.close
     return table
Exemplo n.º 3
0
 def load_table(self, filename):
     """ Load a table into a dictionary """
     table = {}
     with open(filename) as f:
         for line in f:
             if line and line.lstrip()[0] != "#":
                 try:
                     fxy, description, units, scale, ref, width = (
                         line[1:7],
                         line[8:72].strip(),
                         line[73:98].strip(),
                         int(line[98:101]),
                         int(line[102:114]),
                         int(line[115:118]),
                     )
                     # get rid of any unnecessary text
                     if "CODE TABLE" in units:
                         units = "CODE TABLE"
                     if "FLAG TABLE" in units:
                         units = "FLAG TABLE"
                 except:
                     raise BufrDecodeException("Error processing table file line %s" % (line))
                 table[get_descriptor(fxy)] = TableBEntry(description, units, scale, ref, width)
     return table