function time_serie_ER_rossby_df(period1, period2)
% time_serie_ER_rossby_df ++explication between period1 days and period2 days

%+
%
%  .. _time_serie_ER_rossby_df.m:
%
% =========================
% time_serie_ER_rossby_df.m
% =========================
%
% ++
%
% DESCRIPTION
% ===========
%
% plot ++ from file :file:`eof_rossby_jjas_2006_10-30d.mat`
%
% EXAMPLES
% ========
%
% Following line read :file:`eof_rossby_jjas_2006_10-30d.mat`, plot ++and produce  :file:`table_ER_10-30d.txt` file
%
% ::
%
% >> time_serie_ER_rossby_df(10,30);
%
% SEE ALSO
% ========
%
% :ref:`olr_eof_jjas2006_rossby_df.m`
%
% :ref:`carte_eof_ER_1030_article.m`
%
% :ref:`carte_eof_ER_jjas_df.m`
%
% :ref:`time_serie_ER_rossby_df_complet.m`
%
% :ref:`reconstitution_ER_rossby_df.m`
%
% TODO
% ====
%
% improve description
%
% improve file pb
%
% use return function
%
% find where ``table_ER_??-??d.txt`` are used
%
% EVOLUTIONS
% ==========
%
% $Id$
%
% - fplod 2009-02-11T16:27:34Z aedon.locean-ipsl.upmc.fr (Darwin)
%
%   * add try/catch on opening file for reading
%
% - fplod 2009-02-10T14:28:00Z aedon.locean-ipsl.upmc.fr (Darwin)
%
%   * replace ndmin by period1 and ndmax by period2
%
% - fplod 2009-01-27T10:07:29Z aedon.locean-ipsl.upmc.fr (Darwin)
%
%   * created from time_serie_ER_rossby_1030.m to replace it as well as
%     time_serie_ER_rossby_30100.m
%
%     Days will be now written ``period1``\-``period2d`` (ex: 10-30d) in filenames.
%
%-

global IRCAAM_ID;
global IRCAAM_OD;

if nargin==2
 % period1 must be lower than period2
 if (period1 > period2)
  disp(['period1 = ', int2str(period1)]);
  disp(['period2 = ', int2str(period2)]);
  error('eee : period1 must be lower than period2');
 end
else
  usage='usage : time_serie_ER_rossby_df(period1, period2)';
  disp(usage);
  error('eee : wrong arguments numbers')
end

% period1 and period2 will be used in xx-yyd form in filenames
df = [int2str(period1),'-',int2str(period2),'d'];
clear period1;
clear period2;

fullfilename=[IRCAAM_ID,'eof_rossby_jjas_2006_',df,'.mat'];
try
 status=load(fullfilename,'C','olr');
catch
 error('eee : File %s not found\n', fullfilename);
end

clear fullfilename;
C=status.C;
olr=status.olr;
clear status;

olr=olr';
PC1=olr*C;

time_serie_olr1=PC1(:,425);
time_serie_olr2=PC1(:,424);
year=zeros(122,28);
for a=1:122
    for b=1:28;
       year(a,b)=1979+(b-1);
    end;
end;
year=reshape(year,3416,1);

day=zeros(122,28);
for a=1:122
    for b=1:28;
       day(a,b)=31+28+31+30+31+a;
    end;
end;
day=reshape(day,3416,1);

table_ER=zeros(3416,4);
for a=1:3416;
     for b=1:4;
        table_ER(a,1)=year(a);
        table_ER(a,2)=day(a);
        table_ER(a,3)=time_serie_olr1(a);
        table_ER(a,4)=time_serie_olr2(a);
     end;
end;

fullfilename=[IRCAAM_OD,'table_ER_',df,'.txt'];
save(fullfilename,'table_ER','-ASCII');
clear fullfilename;

a=1;
clear koro1
debut=(a-1)*122+1;
fin=a*122;
koro1=time_serie_olr1(debut:fin);
koro2=time_serie_olr2(debut:fin);
x=[1:122]';
aa=plot(x,-koro1,'r');
hold on;
bb=plot(x,-koro2,'k');
cc=legend('EOF1','EOF2');
set (cc,'fontsize',6);
legend boxoff
y=zeros(122,1);
plot(x,y,'k:');

set (gca,'tickDir','out');
axis([1 122 -100 100]);

set (gca,'YTick',[-100:20:100],'YTickLabel',[-100:20:100],'fontname','Arial','fontsize',6);
set (gca,'XTick',[0:20:120],'XTickLabel',[0:20:120],'fontname','Arial','fontsize',6);
