#!/usr/bin/env python3

'''
Copyright 2016 Sofus Rose

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
'''

import sys, os, time
import multiprocessing as mp

import numpy as np

#Matplotlib is optional.
MOD_MATPLOTLIB = False
try:
	import matplotlib.pyplot as plt
	import matplotlib.mlab as mlab
	
	MOD_MATPLOTLIB = True
except:
	print("Matplotlib not installed. Graphs won't be drawn")

class Files :
	"""
	The Files object is an immutable sequence of files, which supports writing simultaneously to all the files.
	"""
	def __init__(self, *files) :
		seq=[]
		for f in files:
			if isinstance(f, Files): seq += f.files
			elif 'write' in dir(f): seq.append(f)
			else: raise TypeError('Wrong Input Type: ' + repr(f))

		self.files = tuple(seq) #Immutable tuple of file-like objects,



	def write(self, inStr, exclInd=[]) :
		"""
		Writes inStr all file-like objects stored within the Files object. You may exclude certain entries with a sequence of indices.
		"""
		for f in enumerate(self.files) :
			if f[0] in exclInd: continue
			f[1].write(inStr)




	def __add__(self, o, commut=False) :
		"""
		Implements merging with Files objects and appending file-like objects. Returns new Files object.
		"""
		if isinstance(o, Files) :