def count_reads(exons, ckreads, multiple, stranded):
    """Adds (#aligned nucleotides/read length) to exon counts.
    Deals with indels, junctions etc.
    :param multiple: divide the count by the NH tag.
    :param stranded: for strand-specific protocols, use the strand information."""
    current_idx = 0
    nexons = len(exons)
    for alignment in ckreads:
        if current_idx >= nexons:
            return 0
        exon_end = exons[current_idx].end
        ali_pos = alignment.pos
        while exon_end <= ali_pos:
            current_idx += 1
            if current_idx >= nexons:
                return 0
            exon_end = exons[current_idx].end
        idx2 = current_idx
        exon_start = exons[idx2].start
        read_len = alignment.rlen
        ali_len = 0
        for op, shift in alignment.cigar:
            if op in [0, 2, 3]:
                if ali_pos < exon_start:
                    pos = ali_pos
                    ali_pos = min(exon_start, pos + shift)
                    shift = max(0, pos + shift - exon_start)
                while ali_pos + shift >= exon_end:
                    if op == 0:
                        ali_len += exon_end - ali_pos
                        exons[idx2].increment(float(ali_len) / float(
                            read_len), alignment, multiple, stranded)
                    shift -= exon_end - ali_pos
                    ali_pos = exon_end
                    ali_len = 0
                    idx2 += 1
                    if idx2 >= nexons:
                        return 0
                    exon_start = exons[idx2].start
                    exon_end = exons[idx2].end
                    if ali_pos < exon_start:
                        pos = ali_pos
                        ali_pos = min(exon_start, pos + shift)
                        shift = max(0, pos + shift - exon_start)
                if op == 0:
                    ali_len += shift
                ali_pos += shift
            elif op == 1:
                ali_len += shift
        exons[idx2].increment(float(ali_len) / float(read_len), alignment,
            multiple, stranded)
