Execute autorg.

    Inputs:
        filename: either a name of an ascii file, or an instance of Curve.
        mininterval: the minimum number of points in the Guinier range
        qminrg: the maximum value of qmin*Rg. Default of autorg is 1.0
        qmaxrg: the maximum value of qmax*Rg. Default of autorg is 1.3
        noprint: if the output of autorg should be redirected to the null 
            device.

    Outputs:
        Rg as an ErrorValue
        I0 as an ErrorValue
        qmin: the lower end of the chosen Guinier range
        qmax: the upper end of the chosen Guinier range
        quality: the quality parameter, between 0 and 1
        aggregation: float, the extent of aggregation

def autorg(filename, mininterval=None, qminrg=None, qmaxrg=None, noprint=True):
    """Execute autorg.

    Inputs:
        filename: either a name of an ascii file, or an instance of Curve.
        mininterval: the minimum number of points in the Guinier range
        qminrg: the maximum value of qmin*Rg. Default of autorg is 1.0
        qmaxrg: the maximum value of qmax*Rg. Default of autorg is 1.3
        noprint: if the output of autorg should be redirected to the null 
            device.

    Outputs:
        Rg as an ErrorValue
        I0 as an ErrorValue
        qmin: the lower end of the chosen Guinier range
        qmax: the upper end of the chosen Guinier range
        quality: the quality parameter, between 0 and 1
        aggregation: float, the extent of aggregation
    """
    if isinstance(filename, Curve):
        curve = filename
        with tempfile.NamedTemporaryFile('w+b',
                                         delete=False) as f:
            curve.save(f)
            filename = f.name
    cmdline = ['autorg', filename, '-f', 'ssv']
    if mininterval is not None:
        cmdline.extend(['--mininterval', str(mininterval)])
    if qminrg is not None:
        cmdline.extend(['--sminrg', str(qminrg)])
    if qmaxrg is not None:
        cmdline.extend(['--smaxrg', str(qmaxrg)])
    result = execute_command(cmdline, noprint=noprint)
    Rg, dRg, I0, dI0, idxfirst, idxlast, quality, aggregation, filename = result[0].split(None, 8)
    try:
        curve
    except NameError:
        curve = Curve.new_from_file(filename)
    else:
        os.unlink(filename)
    return ErrorValue(float(Rg), float(dRg)), ErrorValue(float(I0), float(dI0)), curve.q[int(idxfirst) - 1], curve.q[
        int(idxlast) - 1], float(quality), float(aggregation)