% C:\Documents and Settings\Lisa Taylor\My Documents\Data\SeaWIFS
% generates SeaWIFS Lnw spectra for 7.5km around the float's position:
close all
clear all

load data/nLw_412.mat
nLw_412=double(data)*0.001;
load data/nLw_443.mat
nLw_443=double(data)*0.001;
load data/nLw_490.mat
nLw_490=double(data)*0.001;
load data/nLw_510.mat
nLw_510=double(data)*0.001;
load data/nLw_555.mat
nLw_555=double(data)*0.001;
load data/nLw_670.mat
nLw_670=double(data)*0.0001;

load data/chlor_a
chl=data;

% fix the time stamp to Matlab's
t_offset=1721059;
date_seawifs=dt_im-t_offset; % record 1,1 should be 12-Jun-2004 14:45:00

k=0;
for i=1:13
    for j=1:13
        k=k+1;
        distgrid(k)=sqrt((i-7)^2+(j-7)^2)*4; %grid of distance around float
    end
end

[uu vv]=size(nLw_412);
for i=1:uu
    I=find(nLw_412(i,:)<=0);nLw_412(i,I)=NaN;
    I=find(nLw_443(i,:)<=0);nLw_443(i,I)=NaN;
    I=find(nLw_490(i,:)<=0);nLw_490(i,I)=NaN;
    I=find(nLw_510(i,:)<=0);nLw_510(i,I)=NaN;
    I=find(nLw_555(i,:)<=0);nLw_555(i,I)=NaN;
    I=find(nLw_670(i,:)<=0);nLw_670(i,I)=NaN;
    I=find(chl(i,:)<=0);chl(i,I)=NaN;
end

I10km=find(distgrid<7.5); 
  
% %%%%%%%% 7.5km of float by wavelength
for i=1:vv
   dist_10km_412_A(i)=nanmean(nLw_412(I10km,i),1);
   dist_10km_412_B(i)=nanmedian(nLw_412(I10km,i),1);
   dist_10km_412_C(i)=nanstd(nLw_412(I10km,i),1);
   dist_10km_443_A(i)=nanmean(nLw_443(I10km,i),1);
   dist_10km_443_B(i)=nanmedian(nLw_443(I10km,i),1);
   dist_10km_443_C(i)=nanstd(nLw_443(I10km,i),1);
   dist_10km_490_A(i)=nanmean(nLw_490(I10km,i),1);
   dist_10km_490_B(i)=nanmedian(nLw_490(I10km,i),1);
   dist_10km_490_C(i)=nanstd(nLw_490(I10km,i),1);
   dist_10km_510_A(i)=nanmean(nLw_510(I10km,i),1);
   dist_10km_510_B(i)=nanmedian(nLw_510(I10km,i),1);
   dist_10km_510_C(i)=nanstd(nLw_510(I10km,i),1);
   dist_10km_555_A(i)=nanmean(nLw_555(I10km,i),1);
   dist_10km_555_B(i)=nanmedian(nLw_555(I10km,i),1);
   dist_10km_555_C(i)=nanstd(nLw_555(I10km,i),1);
   dist_10km_670_A(i)=nanmean(nLw_670(I10km,i),1);
   dist_10km_670_B(i)=nanmedian(nLw_670(I10km,i),1);
   dist_10km_670_C(i)=nanstd(nLw_670(I10km,i),1);
   mean_chl(i)=nanmean(chl(I10km,i),1);
   median_chl(i)=nanmedian(chl(I10km,i),1);
   std_chl(i)=nanstd(chl(I10km,i),1);
end

spectra_median=[dist_10km_412_B',dist_10km_443_B',dist_10km_490_B',dist_10km_510_B',dist_10km_555_B',dist_10km_670_B'];
spectra_mean=[dist_10km_412_A',dist_10km_443_A',dist_10km_490_A',dist_10km_510_A',dist_10km_555_A',dist_10km_670_A'];
spectra_std=[dist_10km_412_C',dist_10km_443_C',dist_10km_490_C',dist_10km_510_C',dist_10km_555_C',dist_10km_670_C'];

wl=[412 443 490 510 555 670];
save SeaWIFS_spectra_7_5km wl mean_chl median_chl std_chl date_seawifs spectra_median spectra_mean spectra_std



