% C:\Documents and Settings\Lisa Taylor\My Documents\Data\APEX\0015\Modis
% gets MODIS data

% gets arrays:
  % from chlor_a_0015.mat:
    % chlor_a (2601x1106) modis chl values (rows 1 through 2601) for each 51x51 grid
        % (2601 columns) around Float 0005 for a given datetime (next row is next
        % 51x51 grid for next datetime) -1=cloud cover -999=missing data
  % from dt_im_0015.mat:
    % dt_im (1x1105): modis dates (IDL julian format) from 06/13/04 to 01/01/07
  % from dist.mat:
    % dist (1x2601)
    % distgrid (1105x2601): distance of each pixel in 51x51 grid around
      % Float 0015 (located at 26,26)
% saves modis_chl.mat containing:
  % modisChl0015 [date, chl] (1105x2602)
  % modis_chl_ts (1105x2601) just chlorophyll
  % distgrid (1105x2601)
  
close all
clear all

load data/chlor_a_0015
% There is an extra placeholder column of zeros in each of the band array (2601 x 1106), 
% just remove this first column to make it match dt_im.
chl=chlor_a(:,2:end); % (now 2601x1105)

load data/dt_im_0015

% fix the time stamp to Matlab's
t_offset=1721059;
datenumdate=(dt_im-t_offset)';

datenumdate(datenumdate==0)=NaN; % replace 0s with NaNs
chl(chl==-1)=NaN; % replace -1s (cloud cover) in 51x51 grid with NaNs
chl(chl==-999)=NaN; % replace -999s (missing data) in 51x51 grid with NaNs
chl=chl'; % now 1105x2601
modisChl0015=[datenumdate,chl]; % array of both date (col 1) and chl (remaining 2601 cols) 1105x2602
modis_chl_ts=chl; % now 1105x2601

plot(datenumdate,chl,'b.')
set(gca,'FontName','Times New Roman');
set(gca,'FontSize',16);
set(gca,'XTick',[732464 732647 732829 733012 733194]);
datetick(gca,'x','mmmyy','keepticks');
ylabel('Chlorophyll')
title({'Modis Chlorophyll','North Pacific'})

load dist

% clear unecessary variables from workspace
clear datenumdate dt_im dist chl chlor_a t_offset;

save modis_chl -v6

clear modis_chl_ts distgrid;

% also save modis date and chl data to dataFiles folder for server
save 'C:\Documents and Settings\Lisa Taylor\My Documents\Data\APEX\0015\modisChl.mat'


