def find_nonzero_intermediate(obj,start_frame,link_low=None,link_high=None): # Function made for the intermediate_muons.
    # It finds the first intermediate-bitword that is identical to the first valid non-zero output-bitword. "start_frame" is the frame in which this output_word is.
    # This is to define the offset between output and intermediate if there are problems in the alignment.

    if link_low==None:
        link_low=4

    if link_high==None:
        link_high=12

    for i in xrange(start_frame+1):
        for j in xrange(link_low,link_high):
            a = get_frame(obj,i)[j]
            b = get_frame(obj,start_frame)[0] 
            if a==b:
                return i
                break
def input_frames(obj, link=None, num_of_frames=None): # Function made for input_files. Returns the number of valid input_frames starting from link 36 (can be modified)
    # Attention: Stops at first "0v" entry! (See code) If there should be other "1v" entries below, this function doesnt take them into consideration!

    if link==None:
        link = 36

    if num_of_frames == None:
        num_of_frames = 1024

    end_frame = num_of_frames

    for i in xrange(num_of_frames):
        a = get_frame(obj, i)[link]
        if a[:2] == "1v":
            start_frame = i
            break

    for i in xrange(start_frame,num_of_frames):
        a = get_frame(obj, i)[link]
        if a[:2] == "0v":
            end_frame = i
            break

    return end_frame-start_frame
def find_nonzero_output(obj, links=None, num_of_frames=None): # Finds the first non-zero valid (1v) entry from frame 0000 to frame "num_of_frames" in the input_links 
    # Attention: links is an array of length 2 !!!

    if num_of_frames==None:
        num_of_frames = 2**10

    if links==None:
        k0 = 0
        k1 = 4
    else:
        k0 = links[0]
        k1 = links[1]

    for j in xrange(k0, k1):
        for i in xrange(num_of_frames):
            a = get_frame(obj,i)[j]
            if (a[:2] == "1v") and (a!="1v00000000"):
                return i
                break