%function [T2,Ed3] = m1_integrate

m1 = netcdf('d:\web\extern\bog\netcdf\m1.nc');
t = nctime(m1);

Ed = [m1{'Ed412_0_1'}(:) m1{'Ed443_0_2'}(:) m1{'Ed490_0_3'}(:) m1{'Ed510_0_4'}(:) m1{'Ed555_0_5'}(:)];

% Deal with the problem of different red channels
Ed656 = m1{'Ed656_0_6'}(:);
Ed670 = m1{'Ed670_0_6'}(:);
ncquit(m1)
i = min(find(t >= datenum('25-Aug-1998 01:00:13')));
Ed6xx = [Ed656(1:i-1); Ed670(i:end)];

Ed = [Ed Ed6xx];
Ed(find(Ed == -999)) = NaN;
[Ed i j] = excise(Ed);
t = t(j);

lambda = [412 443 490 510 555 670];

Ed1 = trapz(lambda', Ed, 2); % This integration was checked and OK'd 10/13/00
Ed1 = Ed1*100*100/1000/1000;  % Convert uW/cm^2 to W/m2. Conversion checked 10/13/00

[Year Month Day] = datevec(t);

n = 0;
yy = unique(Year)';
for y = yy;
   
   if isleap(y)
      Feb  = 29;
   else
      Feb  = 28;
   end
   
   daysPerMonth = [31 Feb 31 30 31 30 31 31 30 31 30 31];
   for m = 1:12
      n = n + 1;
      good = find(Year == y & Month == m);
      T2(n,1)   = datenum(y, m, 15, 12, 0, 0);
      if isempty(good)
         Ed2(n, 1) = NaN;
      else
         Ed2(n, 1) = trapz(t(good), Ed1(good)); %./daysPerMonth(m);   
      end
      
   end
   
   
end

Ed3 = Ed2/1000*24 	% Convert WDay/m^2 to kWHour/m^2

