def subset(meta, params):
    """Extract subset of parameters from meta object returned by hapi()
    
    metar = subset(meta, parameters) modifies meta["parameters"] array so
    it only contains elements for the time variable and the parameters in
    the comma-separated list `parameters`.
    """
    if params == '':
        return meta
    p = params.split(',')
    pm = []
    for i in range(0, len(meta['parameters'])):
        pm.append(meta['parameters'][i]['name'])
    for i in range(0, len(p)):
        if p[i] not in pm:
            raise Exception('Parameter %s is not in meta' % p[i])
    pa = [meta['parameters'][0]]
    params_reordered = []
    if meta['parameters'][0] in p:
        params_reordered = [meta['parameters'][0]]
    for i in range(1, len(pm)):
        if pm[i] in p:
            pa.append(meta['parameters'][i])
            params_reordered.append(pm[i])
    meta['parameters'] = pa
    params_reordered_str = ','.join(params_reordered)
    if not params == params_reordered_str:
        msg = '\n\n' + 'Order requested: ' + params
        msg = msg + '\n\n' + 'Order required: ' + params_reordered_str
        raise ValueError(
            'Order of requested parameters does not match order of parameters in server info metadata.'
             + msg)
    return meta
