function params = keep_data(params,gis)
%in a structure of similar data vectors, keep only the gis indices of
%vectors
%A. Ganachaud 2014

gfields=fieldnames(params);
for ifield=1:length(gfields)
    %first check consistency between fields: must be all same vectors
    %except parameters (are 1x1)
    if length(getfield(params,gfields{ifield}))~=1 & ~ischar(getfield(params,gfields{ifield}))
        if ~exist('ndata') %define once only
            ndata=size(getfield(params,gfields{ifield}),1);
        end
        if ((size(getfield(params,gfields{ifield}),1)~=ndata))% | (size(getfield(params,gfields{ifield}),2)~=1))
            error('fields vectors must all be same first dimension')
        end
    end
end

for ifield=1:length(gfields)
    if length(getfield(params,gfields{ifield}))~=1 & ~ischar(getfield(params,gfields{ifield}))
        tmpfield=getfield(params,gfields{ifield});
        params=setfield(params,gfields{ifield},tmpfield(gis,:));
    end
end
