##^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Lance Simms, Stanford University 2009
##ReadFileList.py
##
##PURPOSE:
##To read in a list of files from a once column text file
##
##INPUTS:
##   FileList - A text file with one file path per line
##
##OUTPUTS:
##   Files - A list of the file names contained in FileList
##
##CALLING SEQUENCE:
##   Files = ReadFileList(FileList)
##
##
import csv
import os

def ReadFileList(FileList):
  Files  = []
  Reader = csv.reader(open(FileList),delimiter="\t")
  for Row in Reader:
      Files.append(Row[0]) 
  return Files

##ReadDitherList.py
##
##PURPOSE:
##To read in a list of files and x and y offsets from a 3 column 
##line
##
##INPUTS:
##   FileList - A text file with one file path and two coordinates 
##   per line with tabs separating the columns.  The lines in the file
##   should look like:
##   
##   FilePath \t XOff \t YOff
##  
##   And the file read should end when a "#" is encountered.
##
##OUTPUTS:
##   Files: strarr
##     A list of the file names contained in FileList
##   XOffs: floatarr
##     An array of the x offsets
##   YOffs: floatarr
##     An array of the y offsets
## 
##CALLING SEQUENCE:
##   Files, XOffs, YOffs = ReadDitherList(FileList)
##
import pdb
from numpy import *
def ReadDitherList(FileList):
  Files  = []
  XOffsL = []
  YOffsL = []
 
  FH = open(FileList)
  for line in FH.readlines():
    #Check to make sure that we're still reading valid lines
    if line.find(';') == -1 :
      LineList =  line.replace('\n','').split('\t')
      Files.extend([LineList[0]])
      XOffsL.extend([LineList[1]])
      YOffsL.extend([LineList[2]])
    else:
      break

  #Turn the offsets into numbers
  XOffs = array(XOffsL, dtype=double)
  YOffs = array(YOffsL, dtype=double)

  return Files, XOffs, YOffs
