def ens_to_indx(ens_num, max_start=1000000):
    """
    Get the index related to the ensemble number : e.g 101 => 0
    :param ens_num: ensemble number, int
    :param max_start: max number of ensembles, int
    :return: index, int
    """
    start = 100
    while start < max_start:
        ind = ens_num % start
        if ind < start:
            return ind - 1
        # Otherwise, try with bigger number of ensembles
        start *= 10

    print("Error: ens_to_index function: ensemble number cannot be converted to index")