@@ -0,0 +1,2003 @@
+#!/usr/bin/env python%0A%22%22%22%0AA collection of handy functions for the BatStack project.%0A%0ALargely unsorted, but each function should have a decent docstring.%0A%0A%0AScott Livingston  %3Cslivingston@caltech.edu%3E%0ASep 2010.%0A%22%22%22%0A%0A%0Aimport sys%0A%0A%0Adef read_chanmap( fname ):%0A    %22%22%22Read plaintext channel map file.%0A%0ASupports either manual or automatic addressing. This is set by%0Aconsidering the number of elements in the first row of the file. If%0Athere are 5, then we assume manual and use the first element of every%0Arow as the address. If there are 4, then we assume automatic and begin%0Awith Stack of first row having address 1, second row 2, and so on.%0A%0ANote that, in manual mode, we assume addresses are given in%0Ahexadecimal format; e.g., 0x0a is read as 10 (base 10). The '0x'%0Aprefix is optional.%0A%0AReturns a dictionary with keys corresponding to Stack addresses and%0Avalues being lists (of length 4, always) where index in list%0Acorresponds to local channel number and actual value is global%0A(i.e. system-wide for your Array implementation) channel.%0A%0AOn error, an empty dictionary is returned.%0A%22%22%22%0A    try:%0A        f = open(fname, 'r')%0A    except:%0A        print 'Error: could not open %25s for reading.' %25 fname%0A        return %7B%7D%0A    line = f.readline()%0A    tok = line.split()%0A    if len(tok) == 5:%0A        man_addr_flag = True%0A    elif len(tok) == 4:%0A        man_addr_flag = False%0A        current_addr = 1%0A    else:%0A        print 'Error: file looks ill-formed.'%0A        return %7B%7D%0A    di = %7B%7D%0A    if man_addr_flag:%0A        di%5Bint(tok%5B0%5D, 16)%5D = %5Bint(x) for x in tok%5B1:%5D%5D%0A    else:%0A        di%5Bcurrent_addr%5D = %5Bint(x) for x in tok%5D%0A        current_addr += 1%0A    for line in f:%0A        tok = line.split()%0A        if man_addr_flag:%0A            di%5Bint(tok%5B0%5D, 16)%5D = %5Bint(x) for x in tok%5B1:%5D%5D%0A        else:%0A            di%5Bcurrent_addr%5D = %5Bint(x) for x in tok%5D%0A            current_addr += 1%0A    f.close()%0A    return di%0A%0A%0A# For use at the command-line,%0Aif __name__ == %22__main__%22:%0A    di = read_chanmap( sys.argv%5B1%5D )%0A    print di%0A

Create (beginnings of a) Python module for misc BatStack related functions.