load SHA_area1;            % load SHA time serie area 1
load SHA_area2;            % load SHA time serie area 2
area(1).box=SHA_area1;       
area(2).box=SHA_area2;
color=['b';'r'];                %Color lines: BLUE area1, RED area2 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%                                          _________            %%%%%%%%%%%                                            
%%%%%%%%%%%           Monthly Mean SHA (cm)  ---->   SHA(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,4) );        %  SHA(month)
        month_std=std( area1(area1(:,2)==month,4) );   %        _________       
        month_m=[month_m;[month m_m month_std]];       % Month, SHA(month), Std
    end

    subplot(322)
    hold on
    h1=errorbar(month_m(:,2),month_m(:,3),color(ind)); % SHA(month), Std
    set(h1,'Linewidth',2)
    ylabel('Monthly Mean SHA [cm]');xlabel('Month')
    axis([0.5 12.5 -12 12])
    set(gca,'Box','on')
    hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%                                                              %%%%%%%%
%%%%%%%%%%%%%%     SHA time serie 1985 - 2008     SHA(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));            %First month of the whole data time serie
       month_max=max(area1(ii,2));            %Last  month of the whole data time serie   
       for m=month_min:month_max              %Loop SHA(year_month) Time serie
           ii=find(area1(:,1)==y & area1(:,2)==m);
           st_deviation=std(area1(ii,4));                 
           prom=[prom; [y m mean(area1(ii,4)) st_deviation]];% Year, month, SHA(year_month)  Std 
       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 SHA [cm]')
    plot([1984 2009],[0 0],'black')
    axis([1984 2009 -8 14])
    set(gca,'Box','on')
    hold off
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%                                           _________       %%%%%%%%%                                 
    %%%%%%%%%%%%%%      SHAR(year_month) = SHA(year_month) - SHA(month)      %%%%%%%%%    
    %%%%%%%%%%%%%%                                                           %%%%%%%%%
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
    v=[];
    for y=min(prom(:,1)):max((prom(:,1)))  % minimun year to maximun year
         ii=find(prom(:,1)==y);                % Find data for 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             %                                                          __________           
             val=prom(prom(:,1)==y & prom(:,2)==m,3)-month_m(m,2); % SHAR(year_month) = SHA(year_month) - SHA(month)
             v=[v;[y m val]];                  % Year, Month, SHAR(year_month)
         end
    end
    subplot(313)
    hold on
     plot(v(:,1)+(v(:,2)-1)/12,v(:,3),color(ind),'Linewidth',2)
     
     axis([1984 2009 -10 10])
     plot([1984 2009],[0 0],'black')
     xlabel('Year');ylabel('Monthly SHA Residuals [cm]')
     set(gca,'Box','on')
    hold off
    if area(1).box==area(2).box break;end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%                                                            %%%%%%%%%%%
%%%%%%%%%%%%%%%%                  World Map picture                        %%%%%%%%%%%                      
%%%%%%%%%%%%%%%%                                                            %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(321)
hold on
load coast
grid
h3=plot(long,lat,'black');
a1x=[-30 -25 -25 -30 -30];             
a1y=[25 25 30 30 25];
a2x=[-30 -25 -25 -30 -30];
a2y=[-30 -30 -25 -25 -30];
fill(a1x,a1y,'b')
set(gca,'Box','on')
if ind==2,fill(a2x,a2y,'r'),end
hold off
subplot(312)
grid
subplot(313)
grid
subplot(322)
grid
%%%%%%%%%%%%%%%%%%%  Save figure as tiff, jpg and ps format

print -djpeg90 SHA_time_serieR1
print -dpsc SHA_time_serieR1
print -dtiff SHA_time_serieR1