function time_serie_eof_df(dataset,simulation,ndmin, ndmax)
% time_serie_eof_df ++explication between ndmin days and ndmax days

%+
% module
% ======
%
% ++
%
% DESCRIPTION
% ===========
%
% From eof_arpege_\ *simulation*\ _  \ *ndmin*\ -\ *ndmax*\ d.mat,
% ``time_serie_eof_df`` compute ++.
%
% ``time_serie_eof_df`` plot ++.
%
% ``time_serie_eof_df`` save eof[12]_arpege_\ *simulation*\ _  \ *ndmin*\ -\ *ndmax*\ d.txt.
%
% 2 Postscript files
% time_serie_arpege_\ *simulation*\ _ \ *ndmin*\ -\ *ndmax*\ d_part[12].eps are
% written.
%
% EXAMPLES
% ========
%
% Following line read ``eof_arpege_TrNQIVIV_10-30d.mat``,
% compute ++,
% plot ++,
% write ``eof[12]_arpege_TrNQIVIV_10-30d`` and
% write ``time_serie_arpege_TrNQIVIV_10-30d_part[12].eps``
% ::
%
% >> time_serie_eof_df('arpege','TrNQIVIV',10,30)
%
% SEE ALSO
% ========
%
% eof_olr_ircaam_1030_as.m_
%
% .. _eof_olr_ircaam_1030_as.m : eof_olr_ircaam_1030_as.m.html
%
% carte_eof_ircaam_1030.m_
%
% .. _carte_eof_ircaam_1030.m : carte_eof_ircaam_1030.m.html
%
% TODO
% ====
%
% improve description
%
% improve file pb
%
% use return function
%
% EVOLUTIONS
% ==========
%
% $Id$
%
% - fplod 2009-02-02T10:01:21Z aedon.locean-ipsl.upmc.fr (Darwin)
%
%   * created from time_serie_afr_1030.m to replace it as well as
%     time_serie_afr_30100.m, time_serie_as_1030.m, time_serie_as_30100.m,
%     time_serie_ctl_1030.m, time_serie_ctl_30100.m, time_serie_tr_1030.m and
%     time_serie_tr_30100.m
%
%     Days will be now written ``ndmin``\-``ndmaxd`` (ex: 10-30d) in filenames.
%
%     Dataset ``arpege`` will be forced in output file names..
%
%     Simulation name will be add to  output file names (see parameters).
%
%     Postscript files names will be suffixe by partx instead of letter.
%
%-

global IRCAAM_ID;
global IRCAAM_OD;

if nargin==4
 % dataset must be equal to arpege
 if ~strcmp(dataset,'arpege')
  disp(['dataset = ', dataset]);
  error('eee : dataset must be equal to arpege');
 end
 if strcmp(dataset,'arpege')
  list_simulation={'AfNQIVIV','TrNQIVIV','AsNQIVIV','CtIV','CtCl'};
 end
 switch simulation
 case list_simulation
  % ok
 otherwise
  disp(['simulation = ', simulation]);
  disp(['list_simulation = ', mat2str(list_simulation)]);
  error('eee : simulation must be equal to one of list_simulation');
 end
 clear list_simulation;
 % ndmin must be lower than ndmax
 if (ndmin > ndmax)
  disp(['ndmin = ', int2str(ndmin)]);
  disp(['ndmax = ', int2str(ndmax)]);
  error('eee : ndmin must be lower than ndmax');
 end
else
  usage='usage : time_serie_jjas_df(dataset,simulation,ndmin, ndmax)';
  disp(usage);
  error('eee : wrong arguments numbers')
end

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

close all;

fullfilename=[IRCAAM_ID,'eof_',dataset,'_', simulation, '_', df, '.mat'];
status=load(fullfilename,'C','olr');
clear fullfilename;

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

olr=olr';
PC1=olr*C;

%%%%%%% cronique de la VP1
time_serie_olr1=PC1(:,360);
time_serie_olr2=PC1(:,359);

dt_olr1=std(time_serie_olr1);
dt_olr2=std(time_serie_olr2);

for a=1:3538;
   time_serie_olr1(a)=time_serie_olr1(a)/dt_olr1;
   time_serie_olr2(a)=time_serie_olr2(a)/dt_olr2;
end;

fullfilename=[IRCAAM_OD,'eof1_',dataset,'_', simulation, '_', df,'.txt'];
save(fullfilename,'time_serie_olr1','-ASCII');
clear fullfilename;

fullfilename=[IRCAAM_OD,'eof2_',dataset,'_', simulation, '_', df,'.txt'];
save(fullfilename','time_serie_olr2','-ASCII');
clear fullfilename;

x=[1:3538]';
for a=1:29;
   if a<12;
      figure(1);
      subplot(4,3,a);
   elseif a<23;
      figure(2);
      subplot(4,3,a-11);
   else
      figure(3);
      subplot(4,3,a-22);
   end;
   clear koro1;
   debut=(a-1)*122+1;
   fin=a*122;
   koro1=time_serie_olr1(debut:fin);
   koro2=time_serie_olr2(debut:fin);
   clear x;
   x=[1:122]';
   plot(x,koro1,'r');
   hold on
   plot(x,koro2,'k');
   y=zeros(122,1);
   plot(x,y,'k:');
   title(a+1970,'FontSize',8);
   my_title=['serie temporelle eof ', dataset, ' ' , simulation, ' ' , df];
   if a==2;
       text(0,5.5,my_title);
   elseif a==13;
       text(0,5.5,my_title);
   elseif a==24;
       text(0,5.5,my_title);
   end;
   clear my_title;
   set (gca,'tickDir','out');
   axis([1 122 -3 3]);

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

figure(1);
fullfilename=[IRCAAM_OD,'time_serie_eof_', dataset, '_', simulation, '_', df, '_part1.eps'];
print('-depsc2',fullfilename);
clear fullfilename;

figure(2);
fullfilename=[IRCAAM_OD,'time_serie_eof_', dataset, '_', simulation, '_', df, '_part2.eps'];
print('-depsc2',fullfilename);
clear fullfilename;

figure(3);
fullfilename=[IRCAAM_OD,'time_serie_eof_', dataset, '_', simulation, '_', df, '_part3.eps'];
print('-depsc2',fullfilename);
clear fullfilename;

clear dataset;
clear simulation;
clear df;
