function data = load_asmat(prefix, matpath)
% data = load_asmat(prefix, matpath)
% load adcpsect matlab output files (prefix_uv.mat, prefix_xy.mat)
% input: 
%    prefix is the portion of the filename before "_xy.mat"
%    matpath is the path to get to the mat files 
%             (assumed to be './' unless specified)
% output:
%    data is a structure with fields
%    dday, x, y
%    u,v
%    z    

if (nargin == 1)
   xyfile = sprintf('%s_xy.mat',  prefix);
   uvfile = sprintf('%s_uv.mat',  prefix);
else
   xyfile = sprintf('%s_xy.mat',  fullfile(matpath, prefix));
   uvfile = sprintf('%s_uv.mat',  fullfile(matpath, prefix));
end

load(xyfile);
load(uvfile);


% parse the data -----------------------------------------------

u = uv(:,1:2:end);
v = uv(:,2:2:end);
dday = xyt(3,:);
x = xyt(1,:);
y = xyt(2,:);
x = unwrap_lon(x);


badi = find(isnan(dday));
dday(badi) = [];
x(badi) = [];
y(badi) = [];
u(:, badi) = [];
v(:, badi) = [];

data.x = x;
data.y = y;
data.dday = dday;
data.u = u;
data.v = v;
data.z = zc;



