# Path: pygchem/utils/fortranformat/FortranRecordReader.py
# class FortranRecordReader(object):
#     '''
#     Generate a reader object for FORTRAN format strings
# 
#     Typical use case ...
# 
#     >>> header_line = FortranRecordReader('(A15, A15, A15)')
#     >>> header_line.read('              x              y              z')
#     ['              x', '              y', '              z']
#     >>> line = FortranRecordReader('(3F15.3)')
#     >>> line.read('          1.000          0.000          0.500')
#     [1.0, 0.0, 0.5]
#     >>> line.read('          1.100          0.100          0.600')
#     [1.1, 0.1, 0.6]
# 
#     Note: it is best to create a new object for each format, changing the format
#     causes the parser to reevalute the format string which is costly in terms of
#     performance
#     '''
#     
#     def __init__(self, format):
#         self.format = format
#         self._eds = []
#         self._rev_eds = []
#         self._parse_format()
# 
#     def __eq__(self, other):
#         if isinstance(other, FortranRecordReader):
#             return self.format == other.format
#         else:
#             return object.__eq__(self, other)
# 
#     def match(self, record):
#         try:
#             self.read(record)
#         except RecordError:
#             return False
#         else:
#             return True
# 
#     def read(self, record):
#         '''
#         Pass a string representing a FORTRAN record to obtain the relevent
#         values
#         '''
#         return _input(self._eds, self._rev_eds, record)
# 
#     def get_format(self):
#         return self._format
#     def set_format(self, format):
#         self._format = format
#         self._parse_format()
#     format = property(get_format, set_format)
# 
#     def _parse_format(self):
#         self._eds, self._rev_eds = _parser(_lexer(self.format))
# 
# Path: pygchem/utils/fortranformat/FortranRecordWriter.py
# class FortranRecordWriter(object):
#     '''
#     Generate a writer object for FORTRAN format strings
# 
#     Typical use case ...
# 
#     >>> header_line = FortranRecordWriter('(A15, A15, A15)')
#     >>> header_line.write(['x', 'y', 'z'])
#     '              x              y              z'
#     >>> line = FortranRecordWriter('(3F15.3)')
#     >>> line.write([1.0, 0.0, 0.5])
#     '          1.000          0.000          0.500'
#     >>> line.write([1.1, 0.1, 0.6])
#     '          1.100          0.100          0.600'
# 
#     Note: it is best to create a new object for each format, changing the format
#     causes the parser to reevalute the format string which is costly in terms of
#     performance
#     '''
#     def __init__(self, format):
#         self._eds = []
#         self._rev_eds = []
#         self.format = format
# 
#     def __eq__(self, other):
#         if isinstance(other, FortranRecordWriter):
#             return self.format == other.format
#         else:
#             return object.__eq__(self, other)
# 
#     def write(self, values):
#         '''
#         Pass a list of values correspoding to the FORTRAN format specified
#         to generate a string
#         '''
#         return _output(self._eds, self._rev_eds, values)
# 
#     def get_format(self):
#         return self._format
# 
#     def set_format(self, format):
#         self._format = format
#         self._parse_format()
# 
#     format = property(get_format, set_format)
# 
#     def _parse_format(self):
#         self._eds, self._rev_eds = _parser(_lexer(self.format))


import os
import collections
from pygchem.utils.fortranformat import FortranRecordReader
from pygchem.utils.fortranformat import FortranRecordWriter
    for line in f_species_dat:
        row = s_fmt.read(line)
        row = [s.strip() for s in row]
        species_info[row[0]] = row[1:]
    f_species_dat.close()
    species_info_blank = ['' for s in xrange(0, len(species_info.keys()[0]))]

    # globchem.dat file
    globchem_file = open(filename, "r")

    # get header/comments of globchem.dat
    fline = 1
    species_subheader = _format_subheader("Species List")
    header = go_2_begin(globchem_file, fline).replace(species_subheader, "")

    # read in species
    n_species = 0

    #    mass balance groups (id and status)
    species_mb_id_fmt = FortranRecordReader('20X,A3,8(1X,A3)')
    l_globchem = globchem_file.readline()
    mb_id = sanatize_str_inlist(species_mb_id_fmt.read(l_globchem))

    species_mb_st_fmt = FortranRecordReader('21X,A1,8(3X,A1)')
    l_globchem = globchem_file.readline()
    mb_st = sanatize_str_inlist(species_mb_st_fmt.read(l_globchem))

    mb_groups = dict(zip(mb_id, mb_st))
    fline += 2


# Path: pygchem/utils/fortranformat/FortranRecordReader.py
# class FortranRecordReader(object):
#     '''
#     Generate a reader object for FORTRAN format strings
# 
#     Typical use case ...
# 
#     >>> header_line = FortranRecordReader('(A15, A15, A15)')
#     >>> header_line.read('              x              y              z')
#     ['              x', '              y', '              z']
#     >>> line = FortranRecordReader('(3F15.3)')
#     >>> line.read('          1.000          0.000          0.500')
#     [1.0, 0.0, 0.5]
#     >>> line.read('          1.100          0.100          0.600')
#     [1.1, 0.1, 0.6]
# 
#     Note: it is best to create a new object for each format, changing the format
#     causes the parser to reevalute the format string which is costly in terms of
#     performance
#     '''
#     
#     def __init__(self, format):
#         self.format = format
#         self._eds = []
#         self._rev_eds = []
#         self._parse_format()
# 
#     def __eq__(self, other):
#         if isinstance(other, FortranRecordReader):
#             return self.format == other.format
#         else:
#             return object.__eq__(self, other)
# 
#     def match(self, record):
#         try:
#             self.read(record)
#         except RecordError:
#             return False
#         else:
#             return True
# 
#     def read(self, record):
#         '''
#         Pass a string representing a FORTRAN record to obtain the relevent
#         values
#         '''
#         return _input(self._eds, self._rev_eds, record)
# 
#     def get_format(self):
#         return self._format
#     def set_format(self, format):
#         self._format = format
#         self._parse_format()
#     format = property(get_format, set_format)
# 
#     def _parse_format(self):
#         self._eds, self._rev_eds = _parser(_lexer(self.format))
# 
# Path: pygchem/utils/fortranformat/FortranRecordWriter.py
# class FortranRecordWriter(object):
#     '''
#     Generate a writer object for FORTRAN format strings
# 
#     Typical use case ...
# 
#     >>> header_line = FortranRecordWriter('(A15, A15, A15)')
#     >>> header_line.write(['x', 'y', 'z'])
#     '              x              y              z'
#     >>> line = FortranRecordWriter('(3F15.3)')
#     >>> line.write([1.0, 0.0, 0.5])
#     '          1.000          0.000          0.500'
#     >>> line.write([1.1, 0.1, 0.6])
#     '          1.100          0.100          0.600'
# 
#     Note: it is best to create a new object for each format, changing the format
#     causes the parser to reevalute the format string which is costly in terms of
#     performance
#     '''
#     def __init__(self, format):
#         self._eds = []
#         self._rev_eds = []
#         self.format = format
# 
#     def __eq__(self, other):
#         if isinstance(other, FortranRecordWriter):
#             return self.format == other.format
#         else:
#             return object.__eq__(self, other)
# 
#     def write(self, values):
#         '''
#         Pass a list of values correspoding to the FORTRAN format specified
#         to generate a string
#         '''
#         return _output(self._eds, self._rev_eds, values)
# 
#     def get_format(self):
#         return self._format
# 
#     def set_format(self, format):
#         self._format = format
#         self._parse_format()
# 
#     format = property(get_format, set_format)
# 
#     def _parse_format(self):
#         self._eds, self._rev_eds = _parser(_lexer(self.format))


# Path: pygchem/io/globchem.py
import os
import collections
from pygchem.utils.fortranformat import FortranRecordReader
from pygchem.utils.fortranformat import FortranRecordWriter

    for line in f_species_dat:
        row = s_fmt.read(line)
        row = [s.strip() for s in row]
        species_info[row[0]] = row[1:]
    f_species_dat.close()
    species_info_blank = ['' for s in xrange(0, len(species_info.keys()[0]))]

    # globchem.dat file
    globchem_file = open(filename, "r")

    # get header/comments of globchem.dat
    fline = 1
    species_subheader = _format_subheader("Species List")
    header = go_2_begin(globchem_file, fline).replace(species_subheader, "")

    # read in species
    n_species = 0

    #    mass balance groups (id and status)
    species_mb_id_fmt = FortranRecordReader('20X,A3,8(1X,A3)')
    l_globchem = globchem_file.readline()
    mb_id = sanatize_str_inlist(species_mb_id_fmt.read(l_globchem))

    species_mb_st_fmt = FortranRecordReader('21X,A1,8(3X,A1)')
    l_globchem = globchem_file.readline()
    mb_st = sanatize_str_inlist(species_mb_st_fmt.read(l_globchem))

    mb_groups = dict(zip(mb_id, mb_st))
    fline += 2


    species_r1_fmt = FortranRecordReader('(A1,1X,A14,A2,1X,0PF6.2,4(1PE10.3))')