Main function which converts a PocketTopo .TXT file to a Compass .DAT file

def pockettopo2therion(txtfilename):
    """Main function which converts a PocketTopo .TXT file to a Compass .DAT file"""
    print 'Converting PocketTopo data file %s ...' % txtfilename
    infile = pockettopo.TxtFile.read(txtfilename, merge_duplicate_shots=True)
    outfilename = convert_filename(txtfilename)

    with open(outfilename, 'w') as outfile:
        print >> outfile, 'encoding utf-8'
        for insurvey in infile:
            print >> outfile
            print >> outfile, 'centreline'
            print >> outfile, '\t' 'date ' + insurvey.date.strftime('%Y.%m.%d')
            print >> outfile, '\t' 'data normal from to compass clino tape'
            for shot in insurvey:
                print >> outfile, '\t' '%s\t%s\t%7.2f\t%7.2f\t%6.2f' % \
                                  (shot['FROM'], shot.get('TO', None) or '-',
                                   shot.azm, shot.inc, shot.length)
            print >> outfile, 'endcentreline'
        print 'Wrote Therion data file %s .' % outfilename