%% bin_mission.m : called from process_auvmission.m
function [T,C,PHV,OBS,F,OC,OT,depth,pitch,roll,yaw,Xpos,Ypos] = bin_mission(t,c,phv,obs,f,oc,ot,ndepth,npitch,nroll,nyaw,nposx,nposy,mtime,ctime,navtime);

buf=median(diff(mtime))/2;

for N=1:length(mtime);
 %%-----
 %% CTD
 %%-----
 idx = find(ctime >= mtime(N)-buf & ctime < mtime(N)+buf);
  T(N,1)=median(t(idx));
  C(N,1)=median(c(idx));
  PHV(N,1)=median(phv(idx));
  OBS(N,1)=median(obs(idx));
  F(N,1)=median(f(idx));
  OC(N,1)=median(oc(idx));
  OT(N,1)=median(ot(idx));

 %%----------
 %% Spatial 
 %%----------
 idx = find(navtime >= mtime(N)-buf & navtime < mtime(N)+buf);
  depth(N,1)=median(ndepth(idx));
  pitch(N,1)=median(npitch(idx));
  roll(N,1)=median(nroll(idx));
  yaw(N,1)=median(nyaw(idx));
  Xpos(N,1)=median(nposx(idx));
  Ypos(N,1)=median(nposy(idx));
end
 
