%% get_spatialNST : to fetch spatial data for mission 
%%  depth is used to compute pressure for salinity and oxygen computations
%%  lat and lon are pre-mission GPS fixes, constant after mission start
%%  roll, pitch, yaw, Xpos and Ypos are extracted for 3-D mission visualization

%% -------- Depth rolland dead reckoned position -------------
%  if( exist('dataNav') ~= 1)
  if ( exist('dataN')   == 2 )
    disp (' Loading Navigation Data. ')
    dataN
  else
    disp (' Navigation Data Not Present.')
    return
  end
%  end  
  


%% reset time in dataNav
startTime = 0;
if dataNav(1,time) > startTime;
    startTime = dataNav(1,time);
end
dataNav(:,time) = dataNav(:,time) - startTime;
dataNav = NegTrunc(dataNav);

% determine measured year and decimal day from time variable
   [navyear,navmonth,navday,navhour,navmin,navsec] = datevec((dataNav(:,time)+startTime)/86400 + ...
    datenum(1970,1,1,0,0,0));
   navyearday = datenum(navyear,navmonth,navday,navhour,navmin,navsec) - ...
       datenum(navyear,1,1,0,0,0) + 1;
   clear navmonth navday navhour navmin navsec;


navtime = dataNav(:,time);
nroll = [dataNav(:,mPhi)*180/pi];
npitch = [dataNav(:,mTheta)*180/pi];
nyaw = [dataNav(:,mPsi)*180/pi];
ndepth = dataNav(:,mDepth);
posx0 = dataNav(1,mPos_x);
posy0 = dataNav(1,mPos_y);
nposx = dataNav(:,mPos_x)-posx0;
nposy = dataNav(:,mPos_y)-posy0;

%clear dataNav;

%% -------- Latitude, longitude and gps time -------------
disp ' Loading GPS data '
if( exist('gps') ~= 1 ) dataGPS; end
%% reset time in gps
gps(:,time) = gps(:,time) - startTime;
gps = NegTrunc(gps);

gpstime = gps(:,time); 
glat=gps(:,latitude);
glon=-1*gps(:,longitude);

%clear gps;
