#  This is pseudocode for interpolating/extrapolating values for multiple timestamps

while there are still keys (time marks) left to process... 
 	find time to use
		if allWays use earliest time; otherwise use index file time
	match time key with correct data from other files (at first, this is extrap by def'n)
# 		>In the case that we are not doing "all ways" interpolation, other files may have times which 
# 		>are earlier than our target time. For each file where this is the case, read from the data file 
# 		>until a later time is found
	(For each of the time-variable pair arrays)
 		Read lines (if necessary) until we find a time that is greater than the timeKey
			save prevTime, prevData as each new line of time, data read in
			If end of file found: 
				mark it done, 
				increment count of FilesDone
				recompute AllFilesDone
			else
				save time and data for this arrray
		(End loop through lines looking for time)
	(End loop through all arrays)
#	Now we should be able to interpolate all the values to this given time ($timeKey)	
	initialize resultLine to include the time
	For each file
		If file has been fully read already
			extrapolate this value 
#			(the time for this file must be earlier than the time key (for complex logic reasons)
#			(the current value in this file serves as the nearest value for extrapolation routine)
		Else file is still open
 			if no previous value (this is first one)
				if the time matches, 
					use this value! (don't have to extrapolate)
				else
					have to extrapolate; nearest value for extrapolation is the current value 
			else we have a previous value, so we can perform an interpolation here
				if the new time match the key
					just use the actual value
				else if previous value is less than time key
					really interpolate (see equation in code)
#				else the previous time equals or exceeds time key, this is bug (why did we read ahead?)
#			(handled all possible cases for previous value existence)
#		(handled all possible cases of file done)
		append the value to the resultLine being maintained
#	(end looping over all the files)

	print the resultLine 

# 	(Now we'll go to the next timeKey)

	For every array that provided the timeKey for this round 
		save prevTime, prevData for later interpolation
		read a new record from the lucky array(s) 
		If end of file found: 
			mark it done, 
			increment count of FilesDone
			recompute AllFilesDone
		else
			save time and data for this arrray
	(End loop through arrays that matched the timeKey)

#	(End big loop looking for more keys left to process


# Method 1: Interpolate
# 	given prev time t0, new time t1, and match time t, corresponding value v at time t is found as 
# 	a function of the corresponding values v0 and v1:
	return v = v0 + (v1-v0) * (t-t0)/(t1-t0)

# Method 2: Extrapolate
 this method accepts as inputs extrapValue (nearest, empty, or "string"), and nearestValue
	return nearest, "", or "string", as appropriate

# Method 3: Is MoreWorkLeft?
#	this method determines whether we're done yet
#	We need to keep going if either the reference time file is not done, or if allWays and some file
#	is still not done, unless we've exceeded the end time:
	See if we are past the end time (time end overrides everything and is always initialized large
	See if there is more data in the first file that must be read
	See if all the files have been read that need to be
	return !pastEnd && (moreDataInFirstFile || moreDataInSomeFile)
