procit=0;

if procit
    clear all; close all
    
    sub=[5:966];
    
    %% u
    load data_u; u=ConVel'; u=u(:,sub); bad=min(u(:)); idx=find(u==bad); u(idx)=NaN; ut=ConTitle;
    %% v
    load data_v; v=ConVel';  v=v(:,sub); bad=min(v(:)); idx=find(v==bad); v(idx)=NaN; vt=ConTitle;
    %% w
    load data_w; w=ConVel';  w=w(:,sub); bad=min(w(:)); idx=find(w==bad); w(idx)=NaN; wt=ConTitle;
    %% magnitude
    load data_mag; mag=ConVel';  mag=mag(:,sub); bad=min(mag(:)); idx=find(mag==bad); mag(idx)=NaN; magt=ConTitle;
    %% magnitude
    load data_dir; dir=ConVel';  dir=dir(:,sub); bad=min(dir(:)); idx=find(dir==bad); dir(idx)=NaN; dirt=ConTitle;
    %% Error velocity
    load data_error; e=ConVel';  e=e(:,sub); bad=min(e(:)); idx=find(e==bad); e(idx)=NaN; et=ConTitle;
    %% Average amplitude
    load data_amp; a=ConEchoAmp';  a=a(:,sub); bad=min(a(:)); idx=find(a==bad); a(idx)=NaN; at=ConTitle;
    
    % Time reference
    dd=ConDay(sub); hh=ConHour(sub); mn=ConMin(sub); sec=ConSec(sub);
    time=dd+hh/24+mn/(24*60)+sec/(24*60*60);
    idx=find(diff(time)<0); sub=[idx+1:length(time)]; mtime=time(sub); mtime=mtime-min(mtime);
    mtime=mtime+1/48; time(sub)=time(idx)+mtime;
    figure(1); clf; plot(time); hold on; plot(idx,time(idx),'r*');
    % Depth reference: 
    % First 77 m look good, cant see above 10 m or so
    % First good +3 m
    z=[87:-1:11]'; 
    u=mf(u,3,1); v=mf(v,3,1); w=mf(w,3,1); a=mf(a,3,1); mag=mf(mag,3,1); dir=mf(dir,3,1);
    sub=[1:77]; u=u(sub,:); v=v(sub,:); w=w(sub,:); a=a(sub,:); mag=mag(sub,:); dir=dir(sub,:);
    save processed_data u v w mag dir time z; return
else
    load processed_data
end

    % time=time-min(time);
    XT=[floor(min(time)):1:floor(max(time))];
    figure(1); clf; thx_fig; load jetplus; colormap(jet);
    subplot(411); imagesc(time,z,u/10); set(gca,'Ydir','reverse'); ylabel('Depth (m)'); 
    cb=colorbar; yl=get(cb,'Ylabel'); set(yl,'string','u (cm/s)');
    set(gca,'Xtick',XT,'Tickdir','out');
    subplot(412); imagesc(time,z,v/10); set(gca,'Ydir','reverse'); ylabel('Depth (m)');
    cb=colorbar; yl=get(cb,'Ylabel'); set(yl,'string','v (cm/s)');
    set(gca,'Xtick',XT,'Tickdir','out');
    subplot(413); imagesc(time,z,w/10); caxis([-2 2]); set(gca,'Ydir','reverse'); ylabel('Depth (m)');
    cb=colorbar; yl=get(cb,'Ylabel'); set(yl,'string','w (cm/s)');
    set(gca,'Xtick',XT,'Tickdir','out');
    subplot(414); imagesc(time,z,a); set(gca,'Ydir','reverse'); ylabel('Depth (m)');
    cb=colorbar; yl=get(cb,'Ylabel'); set(yl,'string','amp (counts)');
    set(gca,'Xtick',XT,'Tickdir','out');
    xlabel('Day of time series, starting June 11');
    
    frame
    t=text(.5,.97,'MBARI OCCO Program, Northern Shelfbreak ADCP, June 2003');
    set(t,'fontsize',12,'fontweight','bold','horizontalalignment','center');
    
    return
    figure(2); clf; thx_fig; load jetplus; colormap(jet);
    subplot(211); imagesc(time,z,mag/10); set(gca,'Ydir','reverse'); ylabel('Depth (m)');
    cb=colorbar; yl=get(cb,'Ylabel'); set(yl,'string','speed (cm/s)');
    set(gca,'Xtick',XT,'Tickdir','out');
    subplot(212); imagesc(time,z,dir/10); set(gca,'Ydir','reverse'); ylabel('Depth (m)');
    cb=colorbar; yl=get(cb,'Ylabel'); set(yl,'string','direction');
    set(gca,'Xtick',XT,'Tickdir','out');
    xlabel('Day of time series, starting June 11');
    
    frame
    t=text(.5,.97,'MBARI OCCO Program, Northern Shelfbreak ADCP, June 2003');
    set(t,'fontsize',12,'fontweight','bold','horizontalalignment','center');


   