def ijkl_string(idx4, FDparams):
    """Generate string for reading gridfunction from specific location in memory
    if DIM==4:
        input: [i,j,k,l]
        output: "i0+i,i1+j,i2+k,i3+l"
    if DIM==3:
        input: [i,j,k,l]
        output: "i0+i,i1+j,i2+k"
    etc.
    :param idx4: An array of 4 integers, indicating a finite difference grid index relative to where the fd is being computed
    :param FDparams: Parameters used in the finite-difference codegen
    :return: DIM==3 input [i,j,k,l] -> output "i0+i,i1+j,i2+k"
    >>> from finite_difference_helpers import ijkl_string, FDparams
    >>> FDparams.DIM = 4
    >>> ijkl_string([-2,1,0,-1], FDparams)
    \'i0-2,i1+1,i2,i3-1\'

    >>> from finite_difference_helpers import ijkl_string, FDparams
    >>> FDparams.DIM = 3
    >>> ijkl_string([-2,-1,-1,-300], FDparams)
    \'i0-2,i1-1,i2-1\'
    """
    retstring = ""
    for i in range(FDparams.DIM):
        if i > 0:
            # Add a comma
            retstring += ","
        retstring += "i" + str(i) + "+" + str(idx4[i])
    return retstring.replace("+-", "-").replace("+0", "")