function s=merge_m3d(varargin)
%function s=merge_m3d(flout,fl1,fl2,fl3,...)
flout=varargin{1};
disp(flout);
nargin

for k=2:nargin,
    flin=varargin{k}
    disp(flin);
    s(k-1)=read_m3d(flin);
end

p.l1=s(1).l1;
p.l2=s(1).l2;
p.l3=s(1).l3;
p.l4=s(1).l4;
p.l5=s(1).l5;
p.yrday=s(1).yrday;
p.x=s(1).x;
p.y=s(1).y;
p.u=s(1).u;
p.v=s(1).v;
p.zmin=s(1).zmin;
p.zmax=s(1).zmax;
p.zbottom=s(1).zbottom;

for k=3:nargin
    p.yrday=[p.yrday(:);s(k-1).yrday(:)];
    p.x=[p.x(:);s(k-1).x(:)];
    p.y=[p.y(:);s(k-1).y(:)];
    p.u=[p.u(:);s(k-1).u(:)];
    p.v=[p.v(:);s(k-1).v(:)];
    p.zmin=[p.zmin(:);s(k-1).zmin(:)];
    p.zmax=[p.zmax(:);s(k-1).zmax(:)];
    p.zbottom=[p.zbottom(:);s(k-1).zbottom(:)];
end    

[m,j]=sort(p.yrday);
p.yrday=p.yrday(j);
p.x=p.x(j);
p.y=p.y(j);
p.u=p.u(j);
p.v=p.v(j);
p.zmin=p.zmin(j);
p.zmax=p.zmax(j);
p.zbottom=p.zbottom(j);

write_m3d(flout,p)