function s=mergeStruct(varargin)
% mergeStruct <Merge N structures>
% Usage:: s=mergeStruct(s1,[s2,...,sN])
% Duplicate fields are overwritten by later structs.
% Empty structures ignored
%

% revision history:
% 05/06/20 Mark D. Shattuck <mds> mergeStruct.m

%% Parse Input
if (nargin < 1)
  error('Not enough input args.');
end
N=nargin;
%% Main

ns=1;
while(ns<=N && ~isstruct(varargin{ns}))
  ns=ns+1;
end
if(ns<=N)
  s=varargin{ns};
  for n=ns:N
    if(isstruct(varargin{n}))
      f=fieldnames(varargin{n});
      for nf=1:length(f);
        s.(f{nf})=varargin{n}.(f{nf});
      end
    end
  end
else
  s=[];
end

