function out = combine_(f, in) % COMBINE_ - Subfunction ussed by STORDAT_COMBINE and AT_STORDAT_COMBINE % % Use as: out = combine_(f) % out = combine_(f, in) % % Inputs: f = list of files to combine % in = data from READOUT that is to be combined with the data from the files in the list, f. % % % Output: out = data from combined files (sorted by date) % % This will combine stordat files % Brian Schlining % 15 Sep 1999 [r c] = size(f); good = 1:r; out = []; % Read the list of out files into structures and store as an array of cells for i = 1:length(good) dat{i} = readout(deblank(f(good(i),:))); end % Add additonal info from in (if present) if nargin == 2 dat{end+1} = in; good = 1:(r+1); end % Get the fieldnames for i = 1:length(good) if i == 1 fn = fieldnames(dat{i}); % Get the fieldnames of the first file in the list else buf = fieldnames(dat{i}); lfn = length(fn); lbuf = length(buf); for j = 1:lbuf fn(lfn + j) = buf(j); % Append subsequent file's fieldnames onto the list end end end ufn = unique(fn); % Extract the unique fieldnames for i = 1:length(good) % Loop through each file fn = fieldnames(dat{i}); % Get the fieldnames of the selected file ltt = length(dat{i}.TIME_TAG); % Get the number of data points in the selected file if i == 1 for j = 1:length(ufn); ifn = strmatch(ufn{j},fn); if ~isempty(ifn) out = setfield(out,ufn{j},getfield(dat{i},fn{ifn})); else out = setfield(out,ufn{j},ones(size(dat{i}.TIME_TAG))*NaN); end end else for j = 1:length(ufn) buf = getfield(out,ufn{j}); ifn = strmatch(ufn{j},fn); if ~isempty(ifn) try out = setfield(out,ufn{j},[buf; getfield(dat{i},fn{ifn})]); catch out = setfield(out,ufn{j},strvcat(buf, getfield(dat{i},fn{ifn}))); end else out = setfield(out,ufn{j},[buf; ones(size(dat{i}.TIME_TAG))*NaN]); end end end end [TIME_TAG, n] = sort(out.TIME_TAG); [r c] = size(TIME_TAG); for i = 1:length(ufn) buf = getfield(out,ufn{i}); [rb cb] = size(buf); if (rb == r & cb == c) out = setfield(out,ufn{i},buf(n)); end end