image thumbnail

read_teqc_compact

by

 

17 Apr 2011 (Updated )

Reads teqc's QC compact files more rapidly -- without for loops.

read_teqc_compact (dir, basename, ext, elev, azim)
function varargout = read_teqc_compact (dir, basename, ext, elev, azim)
    if (nargin < 2),  basename = [];  end
    if (nargin < 3) || isempty(ext),  ext = {'mp1', 'mp2', 'sn1', 'sn2', 'iod', 'ion'};  end
    if ~iscell(ext),  ext = {ext};  end
    if (nargin < 4),  elev = [];  end
    if (nargin < 5),  azim = [];  end

    % elev & azim files are always read (otherwise, 
    % call read_teqc_compact_each separately).
    if isempty(elev)
        filepath = fullfile(dir, [basename, '.ele']);
        [elev.obs, elev.epoch, elev.prn, elev.sys] = read_teqc_compact_each (filepath);
    end
    if isempty(azim)
        filepath = fullfile(dir, [basename, '.azi']);
        [azim.obs, azim.epoch, azim.prn, azim.sys] = read_teqc_compact_each (filepath);
    end

    % merge elev & azim already:
    elev.epochprnsys = [elev.epoch, elev.prn, double(elev.sys)];
    azim.epochprnsys = [azim.epoch, azim.prn, double(azim.sys)];
    if isequal(elev.epochprnsys, azim.epochprnsys)
        epochprnsys = elev.epochprnsys;
        elev = elev.obs;
        azim = azim.obs;
    else
        [epochprnsys, elev.ind, azim.ind] = intersect(...
            elev.epochprnsys, azim.epochprnsys, 'rows');
        elev = elev.obs(elev.ind);
        azim = azim.obs(azim.ind);
    end
    epoch = epochprnsys(:,1);
    prn   = epochprnsys(:,2);
    sys   = char(epochprnsys(:,3));
    siz = size(epoch);
    obs = struct();

    for i=1:numel(ext)
        filepath = fullfile(dir, [basename, '.' ext{i}]);
        if ~exist(filepath, 'file')
            warning('MATLAB:read_teqc_compact:badExt', ...
                'File with extension "%s" not found:\n\t%s', ext{i}, filepath);
            continue;
        end
        [obs2, epoch2, prn2, sys2] = read_teqc_compact1 (filepath);
        epochprnsys2 = [epoch2, prn2, double(sys2)];
        [idx, ind] = ismember(epochprnsys2, epochprnsys, 'rows');
        obs.(ext{i}) = NaN(siz);
        obs.(ext{i})(ind(idx)) = obs2(idx);
    end
    
    %TODO: remove NaN records?

    if isscalar(ext),  obs = obs.(ext{1});  end
    try azim = azimuth_range_positive(azim); catch; end %#ok<CTCH>

    [varargout{1:nargout}] = read_teqc_compact_out (...
        obs, epoch, prn, sys, azim, elev);
end

Contact us