def first_rec(ofile, Rec, file_type):
    """
    opens the file ofile as a magic template file with headers as the keys to Rec
    """
    keylist = []
    opened = False
    # sometimes Windows needs a little extra time to open a file
    # or else it throws an error
    while not opened:
        try:
            pmag_out = open(ofile, 'w')
            opened = True
        except IOError:
            time.sleep(1)
    outstring = "tab \t" + file_type + "\n"
    pmag_out.write(outstring)
    keystring = ""
    for key in list(Rec.keys()):
        keystring = keystring + '\t' + key.strip()
        keylist.append(key)
    keystring = keystring + '\n'
    pmag_out.write(keystring[1:])
    pmag_out.close()
    return keylist
opens the file ofile as a magic template file with headers as the keys to Rec