load CLO_area1;                          % load Chlorophylla time serie area 1
load CLO_area2;                          % load Chlorophylla time serie area 1
area(1).box=CLO_area1;
area(2).box=CLO_area2;
color=['b';'r'];                         % define color for AREA 1 (blue) for AREA 2 (red)
clf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%                                           _________            %%%%%%%%%%%                                            
%%%%%%%%%%%           Monthly Mean CLO (mg/m3)  ----> CLO(month)           %%%%%%%%%%%           
%%%%%%%%%%%                                                               %%%%%%%%%%%        
%%%%%%%%%%%                                                               %%%%%%%%%%%                                                               
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for ind=1:2
    area1=area(ind).box;
    month_m=[];
    for month=min(area1(:,2)):max(area1(:,2))
                                                          %   __________          ___  ___  ___   
        m_m=mean( area1(area1(:,2)==month,3) );           %   CLO(month)   --->   Jan, Feb, Mar, ...
        month_std=std( area1(area1(:,2)==month,3) );      %        _________
        month_m=[month_m;[month m_m month_std]];          % Month, CLO(month), Standard Deviation
    end
    subplot(322)
    hold on
    h1=errorbar(month_m(:,2),month_m(:,3),color(ind));
    set(h1,'Linewidth',2)
    ylabel('Monthly Mean Chlorophyll [mg/m^3]');xlabel('Month')
    axis([0.5 12.5 0 0.2])
    set(gca,'Box','on')
    hold off
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%                                                              %%%%%%%%
    %%%%%%%%%%%%%%     CLO time serie 1985 - 2008     CLO(year_month)           %%%%%%%%
    %%%%%%%%%%%%%%                                                              %%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                    
    prom=[];
    for y=min(area1(:,1)):max((area1(:,1)))  % min year and Max year
       ii=find(area1(:,1)==y);                %data from each year
       month_min=min(area1(ii,2));            %min month
       month_max=max(area1(ii,2));            %max month    
       for m=month_min:month_max              %Loop monthly average
           ii=find(area1(:,1)==y & area1(:,2)==m);
           st_deviation=std(area1(ii,3));
                 % year month mean_temperature  std 
           prom=[prom; [y m mean(area1(ii,3)) st_deviation]];
       end
    end
    subplot(312)
    hold on
    h2=plot(prom(:,1)+(prom(:,2)-1)/12,prom(:,3),color(ind));
    set(h2,'Linewidth',2)
    xlabel('Year');ylabel('Monthly Mean Chlorophyll [mg/m^3]')
    axis([1984 2009 0 0.2])
    set(gca,'Box','on')
    hold off
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%                                           _________       %%%%%%%%%                                 
    %%%%%%%%%%%%%%      CLOR(year_month) = CLO(year_month) - CLO(month)      %%%%%%%%%    
    %%%%%%%%%%%%%%                                                           %%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    v=[];
    for y=min(prom(:,1)):max((prom(:,1)))  % minimun year to maximun year
         ii=find(prom(:,1)==y);                %find data from a particular year
         month_min=min(prom(ii,2));            %min month
         month_max=max(prom(ii,2));            %max month    
         for m=month_min:month_max      % for m=...                                                       _________        %
             val=prom(prom(:,1)==y & prom(:,2)==m,3)-month_m(m,2); % CLOR(year_month) = CLO(year_month) - CLO(month)
             v=[v;[y m val]];                   % year, month, CLOR(year_month) 
         end
    end
    subplot(313)
    hold on
     plot(v(:,1)+(v(:,2)-1)/12,v(:,3),color(ind),'Linewidth',2)
     plot([1984 2009],[0 0],'black')
     axis([1984 2009 -0.08 0.08])
     xlabel('Year');ylabel('Monthly Chlorophyll Residual [mg/m^3]')
     set(gca,'Box','on')
    if area(1).box==area(2).box break;end

end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%                                                            %%%%%%%%%%%
%%%%%%%%%%%%%%%%                  World Map picture                        %%%%%%%%%%%                      
%%%%%%%%%%%%%%%%                                                            %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(321)
hold on
load coast
grid
axis('equal')
h3=plot(long,lat,'black');
fill([-30 -25 -25 -30 -30],[25 25 30 30 25],'b')   % Define area 1 
fill([-30 -25 -25 -30 -30],[-30 -30 -25 -25 -30],'r') % Define area 2
set(gca,'Box','on')
hold off
subplot(312)
grid
subplot(313)
grid
subplot(322)
grid
%%%%%%%%%%%%%%%%%%%  Save figure as tiff, jpg and ps format

print -djpeg90 CLO_time_serieR1
print -dpsc CLO_time_serieR1
print -dtiff CLO_time_serieR1