import math


def lmoments_parameter_estimation_gamma(lambda1, lambda2):
    """Return the location and scale of the gamma distribution.

    Based on SUBROUTINE PELGAM of the LMOMENTS Fortran package version 3.04, July 2005

    :param lambda1: L-moment-1 (:math:`\lambda_1`)
    :type lambda1: float
    :param lambda2: L-moment-2 (:math:`\lambda_2`)
    :type lambda12: float
    :return: (*float*) location and scale
    """
    if lambda1 <= lambda2 or lambda2 <= 0.0:
        return None, None
    cv = lambda2 / lambda1
    if cv >= 0.5:
        t = 1.0 - cv
        alpha = t * (0.7213 - t * 0.5947) / (1.0 + t * (-2.1817 + t * 1.2113))
    else:
        t = math.pi * cv * cv
        alpha = (1.0 - 0.3080 * t) / (t * (1.0 + t * (-0.05812 + t * 0.01765)))
    return alpha, lambda1/alpha