% start/stop times for long concatenated hourly time series
start=[1989 12 1 0 0 0];
stop =[1996 11 30 0 0 0];
jdi=[julian(start):1/24:julian(stop)]';

% jgofs object for attenuation, 
% find all:
%          surface  (  inst_depth < 10 m)                 ==> atten(:,1)
%          subsurface  ( 27.5 m > inst_depth > 10 m)      ==> atten(:,2)
%          tripod data ( inst_depth > 27.5 m),            ==> atten(:,3)


obj='//sakhalin.er.usgs.gov/jgofs/Gulf_of_Maine/hourly/';
obj=[obj 'attenuation(depth<10.0,lon<-70.76,lon>-70.8,lat>42.35)'];
loadjg(obj,'NaN');

ind=find(time==0);
nseg=length(ind);
time=replace(time,0,nan);
jd=julian([1900 1 1 0 0 0])+time;
jd=jd(:);


att=nan*ones(length(jdi),nseg);

for i=1:nseg,
  i
  if(i==nseg),
    ii=ind(i)+1:length(time);
  else
    ii=ind(i)+1:ind(i+1)-1;
    ii(1)
    ii(length(ii))
   end
  att(:,i)=interp(jd(ii),ATTN_55(ii)',jdi);
end

%  assume minimum attenuation is the best value (less fouled)
atten(:,1)=gmin(att.').';
