clear
load gps.mat
% plot gps: truncate to comparison period, about
% Apr 7 21:22 to Apr 9 11:06
set_up
addpath([matlabroot '/toolbox/local/m_map'])
s11_lat=-19 -(41.4783/60); s11_lon=-85 -(34.0093/60);
anchor_over=datenum(2011,4,6,19,30,0);
stcmp=97.89; encmp=99.46;

% end of argos transmissions: yd  99.3958
earg=datenum(2011,04,09,09,30,00); 
gps.yday=gps.mday-day1;
ix = find (gps.yday > 97.8 & gps.yday < 99.4);
gps=structtrunc(gps,ix);
dist_km=ones(length(gps.mday),1);
for iil=1:length(gps.mday),
    jla=[s11_lat gps.lat(iil)];
    jlo=[s11_lon gps.lon(iil)];
    dist_km(iil) = m_lldist(jlo,jla);
end

% gps:   2011/04/01 00:01 to 2011/04/11 11:00
% sys1:  2011/04/07 22:30 to 2011/04/09 09:30
% sys2:  2011/04/07 22:30 to 2011/04/09 09:30
% etl:   2011/03/31 00:00 to 2011/04/11 10:59
% flux:  2011/03/29 00:00 to 2011/04/10 23:55
% vos:   2011/03/29 15:35 to 2011/04/11 11:43

figure(1)
plot(gps.mday,dist_km,gps.mday,dist_km,'.')
grid on
ax=axis;
datetick('x','keeplimits');
title ('stratus 11 intercomparison')
ylabel('Distance (km)')
xlabel('2011')
print -dpng s11_dist2.png
% keyboard


stcmp=97.89; encmp=99.46;
% give 30 mins past end of argos
enm=datenum(2011,04,09,10,0,00); 
eny=enm-day1;

% truncate
load gps.mat
gps.yday=gps.mday-day1;
fprintf('gps:\n input %s ',prmmd(gps));
ix=find(gps.yday > 97.89 & gps.yday < eny);
gps=structtrunc(gps,ix);
fprintf('  now %s', prmmd(gps));

% truncate argos: times are all @ 30 minutes
load Argos.mat
fprintf('sys1: \n input %s ',prmmd(sys1));
ix=find(sys1.yday >= 97.5 & sys1.yday <= 99.5);
sys1=structtrunc(sys1,ix);
fprintf('  now %s ',prmmd(sys1));
fprintf('sys2:\n input %s ',prmmd(sys1));
ix=find(sys2.yday >= 97.5 & sys2.yday <= 99.5);
sys2=structtrunc(sys2,ix);
fprintf('  now %s ',prmmd(sys2));

load etl.mat
fprintf('etl:\n input %s ',prmmd(etl));
etl.yday=etl.mday-day1;
ix=find(etl.yday >= 97.5 & etl.yday <= eny);
etl=structtrunc(etl,ix);
fprintf('  now %s', prmmd(etl));

load etl_flux.mat
etl_flux=flux;
clear flux
fprintf('etl_flux:\n input %s ',prmmd(etl_flux));
etl_flux.yday=etl_flux.mday-day1;
ix=find(etl_flux.yday >= 97.5 & etl_flux.yday <= eny);
etl_flux=structtrunc(etl_flux,ix);
fprintf('  now %s', prmmd(etl_flux));

load vos.mat
fprintf('vos:\n input %s ',prmmd(vos));
vos.yday=vos.mday-day1;
ix=find(vos.yday >= 97.5 & vos.yday <= eny);
vos=structtrunc(vos,ix);
fprintf('  now %s\n', prmmd(vos));

save s11comp.mat gps sys1 sys2 vos etl etl_flux
