def __init__(self, filename): if type(filename) is str: output_ = AttribDict() grid = output_.setdefault('grid', []) reciever = output_.setdefault('reciever', []) corners = output_.setdefault('corners', []) fh = open(filename, 'r') while True: line = fh.readline() if not line: fh.close() break else: line = line.strip() if 'reading input file' in line: output_.read_input_file_phase = line.split( 'reading input file')[1] continue if 'start up phase' in line: output_.start_up_phase = line.split('start up phase')[1] continue if 'solver phase' in line: output_.solver_phase = line.split('solver phase')[1] continue if line.startswith('Grid'): line = line.split() keys = line while True: line = fh.readline() if line.startswith('Total'): grid.append( AttribDict( {'points': int(float(line.split()[-1]))})) break else: line = line.split() grid_i = AttribDict() for k, v in zip(keys, line): grid_i[k] = int(v) grid.append(grid_i) if line.startswith('Receiver INFO'): name = line.split()[-1][:-1] while True: line = fh.readline().strip() if line.startswith('nearest'): x, y, z = [ float(item) for item in line.split()[5:8]] station = AttribDict( {'station': name, 'x': x, 'y': y, 'z': z}) reciever.append(station) break if line.startswith('Geographic and Cartesian'): for i in range(4): line = fh.readline().split(',') number, lon = line[0].split(':') line[0] = lon corner = AttribDict({'number': number}) for item in line: k, v = item.split('=') corner[k.strip()] = float(v) corners.append(corner) continue if line.startswith('Start Time'): start_time, goal_time = line.split('Goal Time =') output_.start_time = float(start_time.split('=')[1]) output_.goal_time = float(goal_time) continue if line.startswith('Number of time steps'): npts, dt = line.split('dt:') output_.npts = int(npts.split('=')[1]) output_.dt = float(dt) continue if line.startswith('Total seismic moment'): output_.M0 = float(line.split()[4]) continue if line.startswith('Moment magnitude'): output_.Mw = float(line.split()[3]) else: output_ = filename super(Outputfile, self).__init__(output_)