% plot the cruise track for Stratus 2007

% load 30-min data
read_parameters_Stratus
x=load([way_proc_data_flux 'flux_30hf_' cruise year(3:4) '.txt']);%flux_30hf_STRATUS07.txt
%read file with 0.5-hour average data
jdy=x(:,1);%julian day at beginning of time average
U=x(:,2);%true wind,PSD sonic (m/s)
dir=x(:,3);%true wind direction, PSD sonic (deg)
tsnk=x(:,4);%sea snake temperature,PSD, 0.05 m depth (C)
tsg=x(:,5);%tsg water temperature, 5 m depth, (C)
sal=x(:,6);%tsg salinity (psu)
ta=x(:,7);%air temperature, PSD (C)
qse=x(:,8);%sea surface specific humidity,from snake (g/kg)
qa=x(:,9);%air specific humidity, PSD (g/kg)
psp=x(:,10)*1.01;%downward solar flux, PSD units (W/m^2)
rl=x(:,11);%downward IR flux,  PSD units (W/m^2)
org1=x(:,12);%rainrate, PSD STI optical rain gauge, uncorrected (mm/hr)
ushp=x(:,13);%doppler log, SCS (m/s)
head=x(:,14);%ship heading, deg clockwise rel north, SCS laser ring gyro (deg)
urel=x(:,15);%relative wind speed, PSD (m/s)
reldir=x(:,16);%relative wind direction (from),clockwise rel ship's bow, PSD sonic (deg)
lat=x(:,17);%latitude, deg  (SCS pcode)
lon=x(:,18);%longitude, deg (SCS pcode)
zts=x(:,19);%depth for bulk flux Ts reference, =0.05 when snake is used
sig_u=x(:,20);%std dev of ship speed, m/s (>.2 indicates maneuver during half hour average)
taub=x(:,21);%bulk wind stress along mean wind, (N/m^2)
hsb=x(:,22);%bulk sensible heat flux, (W/m^2)
hlb=x(:,23);%bulk latent heat flux, W/m^2 (includes Webb et al. correction)
hrain=x(:,24);%rain heat flux, as per Gosnell et al 1995, JGR, 18437-18442, (W/m^2)
ta_im=x(:,25);%IMET air temp @21 m
qa_im=x(:,26);%IMET
s_ship=x(:,27);%imet
dir_ship=x(:,28);%IMET
psp_ship=x(:,29);%imet
pir_ship=x(:,30);%imet
barpress=x(:,31);%imet

%*****   ships imet and scs data
sog=x(:,13);%speed over ground, SCS gps, (m/s)
cog=x(:,14);%%course over ground, SCS gps, (m/s)

ll=load('coast.mat');
% lli1=[1; find(isnan(ll.long(1:end-1)))-1];
% lli2=find(isnan(ll.long));
% coasts=ll.long>=-95 & ll.long<=-70 & ll.lat>=-25 & ll.lat<=10 ; % select region
% for i=1:length(lli1);
%     isles(i)=any(coasts(lli1(i):lli2(i)));
% end

% 6-hour intervals (4 per day)
hr6=floor(mod(round(jdy*4),4))+1;
comap=[[1 0 0];[1 1 1];[1 0 0];[1 1 1]];

%figure; clf
fill(ll.long,ll.lat,0.7*[1 1 1]);
axis equal
axis([-100 -70 -30 10]);
hold on;
hr6=floor(mod(floor(jdy*4),4))+1;
cm=[[1 0 0];[1 1 1];[1 0 0];[1 1 1]];
scatter(lon(end:-1:1),lat(end:-1:1),10,cm(hr6(end:-1:1),:),'filled');
for jdx=floor(jdy(1)):296;
    ii=find(jdy>=jdx,1,'first');
    plot(lon(ii),lat(ii),'.')
    ht=text(lon(ii),lat(ii),num2str(jdx));
    set(ht,'horizontalalignment','right');
end;
for jdx=297:300;
    ii=find(jdy>=jdx,1,'first');
    plot(lon(ii),lat(ii),'.')
    ht=text(lon(ii),lat(ii),num2str(jdx));
    set(ht,'rotation',-60);
end;
grid on

scl=0.5
hold on
ii=jdy>=290 & jdy<=296
plot(scl*tsnk(ii)-100,lat(ii),'r','linewidth',1.2)
plot(scl*ta(ii)-100,lat(ii),'b','linewidth',1.2)

ii=jdy>297.5 & jdy<=299.5
plot(lon(ii),scl*tsnk(ii)-35,'r','linewidth',1.2)
plot(lon(ii),scl*ta(ii)-35,'b','linewidth',1.2)

print('-depsc2',[way_images_flux 'cruise_track.eps'])
