%% bin_missionNST.m : called from process_auvmissionNST.m
function [T1,C1,S1,D1,OBSbin,O2,FLOW1,depthnav,depth1,pitch,roll,yaw,Xpos,Ypos] = ...
    bin_mission1NST(t1,c1,s1,d1,obs,o2,flw1,dpth1,ndepth,npitch,nroll,nyaw, ...
    nposx,nposy,mtime,c1time,navtime);

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

for N=1:length(mtime)
 %%------
 %% CTD1
 %%------
 idx = find(c1time >= mtime(N)-buf & c1time < mtime(N)+buf);
if (isempty(idx) == 0)
  T1(N,1)=median(t1(idx));
  C1(N,1)=median(c1(idx));
  S1(N,1)=median(s1(idx));
  D1(N,1)=median(d1(idx));
  OBSbin(N,1)=median(obs(idx));
  O2(N,1)=median(o2(idx));
  FLOW1(N,1)=median(flw1(idx));
  depth1(N,1)=median(dpth1(idx));
end
  

 %%----------
 %% Spatial 
 %%----------
 idx = find(navtime >= mtime(N)-buf & navtime < mtime(N)+buf);
  depthnav(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



