function carte_eof_df(ircaam_dataset,simulation,period1, period2)
% carte_eof_df ++explication between period1 days and period2 days

%+
% module
% ======
%
% ++
%
% DESCRIPTION
% ===========
%
% From eof_arpege_\ *simulation*\ _  \ *period1*\ -\ *period2*\ d.mat
% and rlut_d.\ *simulation*\ .197106-09.nc,
% ``carte_eof_df`` compute ++.
%
% ``carte_eof_df`` plot ++.
%
% 1 Postscript file
% carte_arpege_\ *simulation*\ _ \ *period1*\ -\ *period2*\ d.eps are
% written.
%
% CAUTIONS
% ========
%
% can't work with octave because of ncload.
%
% EXAMPLES
% ========
%
% Following line read ``eof_arpege_AfNQIVIV_10-30d.mat`` and
% ``rlut_d.AfNQIVIV.197106-09.nc``,
% compute ++,
% plot ++,
% write ``carte_arpege_AfNQIVIV_10-30d.eps``
% ::
%
% >> carte_eof_df('arpege','AfNQIVIV',10,30)
%
% SEE ALSO
% ========
%
% eof_df.m_
%
% .. _eof_df.m : eof_df.m.html
%
% time_serie_eof_df.m_
%
% .. _time_serie_eof_df.m : time_serie_eof_df.m.html
%
% TODO
% ====
%
% improve description
%
% improve file pb
%
% use return function
%
% EVOLUTIONS
% ==========
%
% $Id$
%
% - fplod 2009-02-10T14:28:00Z aedon.locean-ipsl.upmc.fr (Darwin)
%
%   * replace ndmin by period1 and ndmax by period2
%
% - fplod 2009-02-02T13:45:57Z aedon.locean-ipsl.upmc.fr (Darwin)
%
%   * created from carte_eof_ircaam_1030.m to replace it as well as
%     carte_eof_ircaam_1030_as.m, carte_eof_ircaam_1030_ctl.m,
%     carte_eof_ircaam_1030_ctl_clim.m, carte_eof_ircaam_1030_tr.m,
%     carte_eof_ircaam_30100.m, carte_eof_ircaam_30100_as.m,
%     carte_eof_ircaam_30100_ctl.m and carte_eof_ircaam_30100_tr.m
%
%     Days will be now written ``period1``\-``period2d`` (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).
%
%-

global IRCAAM_ID;
global IRCAAM_OD;

if nargin==4
 % ircaam_dataset must be equal to arpege
 if ~strcmp(ircaam_dataset,'arpege')
  disp(['ircaam_dataset = ', ircaam_dataset]);
  error('eee : ircaam_dataset must be equal to arpege');
 end
 if strcmp(ircaam_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;
 % 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 : carte_eof_df(ircaam_dataset,simulation,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;

close all;

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

clear fullfilename;

C=status.C;
L=status.L;
clear status;

carte1=C(:,360);
carte=reshape(carte1,24,15);
carte=carte';
clear carte1;

% definition des lat et lon
fullfilename=[IRCAAM_ID,'rlut_d.',simulation, '.197106-09.nc'];
ncload(fullfilename,'lat','lon');
clear fullfilename;

lon=lon-180;
lon=lon(54:77);
lat=lat(29:43)';

figure(1);
orient('landscape');
subplot(3,2,1);
palette;
for a=1:15;
    for b=1:24;
        if carte(a,b)>0.2;
            carte(a,b)=0.2;
        elseif carte(a,b)<-0.2;
            carte(a,b)=-0.2;
        end;
    end;
end;
carte(1,1)=-0.2001;
carte(1,2)=0.2001;

contourf(lon,lat,-carte,[-0.2:0.02:0.2],'LineStyle','none');
colorbar;
title('OLR EOF1','Fontsize',8);
hold on;
cartemonde;
set (gca,'YTick',[-10:10:30],'YTickLabel',['10S';'  0';'10N';'20N';'30N'],'fontname','Arial','fontsize',6);
set (gca,'XTick',[-30:10:30],'XTickLabel',['30W';'20W';'10W';'  0';'10E';'20E';'30E'],'fontname','Arial','fontsize',6);
set (gca,'tickDir','out');

clear carte1 x y a b carte coco;
carte1=C(:,359);
carte=reshape(carte1,24,15);
carte=carte';

clear carte1;

subplot(3,2,3);
palette;
for a=1:15;
    for b=1:24;
        if carte(a,b)>0.2;
            carte(a,b)=0.2;
        elseif carte(a,b)<-0.2;
            carte(a,b)=-0.2;
        end;
    end;
end;
carte(1,1)=-0.2001;
carte(1,2)=0.2001;

contourf(lon,lat,carte,[-0.2:0.02:0.2],'LineStyle','none');
colorbar;

title('OLR EOF2','Fontsize',8);
hold on;
cartemonde;
set (gca,'YTick',[-10:10:30],'YTickLabel',['10S';'  0';'10N';'20N';'30N'],'fontname','Arial','fontsize',6);
set (gca,'XTick',[-30:10:30],'XTickLabel',['30W';'20W';'10W';'  0';'10E';'20E';'30E'],'fontname','Arial','fontsize',6);
set (gca,'tickDir','out');

clear carte1 x y a b carte coco;
carte1=C(:,358);
carte=reshape(carte1,24,15);
carte=carte';
clear carte1;

subplot(3,2,5);
palette;
for a=1:15;
    for b=1:24;
        if carte(a,b)>0.2;
            carte(a,b)=0.2;
        elseif carte(a,b)<-0.2;
            carte(a,b)=-0.2;
        end;
    end;
end;
carte(1,1)=-0.2001;
carte(1,2)=0.2001;

contourf(lon,lat,-carte,[-0.2:0.02:0.2],'LineStyle','none');
colorbar;
title('OLR EOF3','Fontsize',8);
hold on;
cartemonde;
set (gca,'YTick',[-10:10:30],'YTickLabel',['10S';'  0';'10N';'20N';'30N'],'fontname','Arial','fontsize',6);
set (gca,'XTick',[-30:10:30],'XTickLabel',['30W';'20W';'10W';'  0';'10E';'20E';'30E'],'fontname','Arial','fontsize',6);
set (gca,'tickDir','out');

clear carte1 x y a b carte coco;
carte1=C(:,357);
carte=reshape(carte1,24,15);
carte=carte';
clear carte1;

subplot(3,2,2);
palette;
for a=1:15;
    for b=1:24;
        if carte(a,b)>0.2;
            carte(a,b)=0.2;
        elseif carte(a,b)<-0.2;
            carte(a,b)=-0.2;
        end;
    end;
end;
carte(1,1)=-0.2001;
carte(1,2)=0.2001;

contourf(lon,lat,-carte,[-0.2:0.02:0.2],'LineStyle','none');
colorbar;
title('OLR EOF4','Fontsize',8);
hold on;
cartemonde;
set (gca,'YTick',[-10:10:30],'YTickLabel',['10S';'  0';'10N';'20N';'30N'],'fontname','Arial','fontsize',6);
set (gca,'XTick',[-30:10:30],'XTickLabel',['30W';'20W';'10W';'  0';'10E';'20E';'30E'],'fontname','Arial','fontsize',6);
set (gca,'tickDir','out');

subplot(3,2,4);
vaude=0;
for a=1:360;
   vaude=vaude+L(a,a);
end;
vecteurs=zeros(20,1);
for a=1:20;
   b=360-(a-1);
   vecteurs(a)=100*(L(b,b)/vaude);
end;
x=[1:20]';

bar(x,vecteurs,'LineStyle','none')
axis([0.5 20.5 0 25]);
set (gca,'YTick',[0:5:25],'YTickLabel',[0:5:25],'fontname','Arial','fontsize',6);
set (gca,'XTick',[2:2:20],'XTickLabel',[2:2:20],'fontname','Arial','fontsize',6);
set (gca,'tickDir','out');

fullfilename=[IRCAAM_OD,'carte_eof_', ircaam_dataset, '_', simulation, '_', df, '.eps'];
print('-depsc2',fullfilename);
clear fullfilename;

clear ircaam_dataset;
clear simulation;
clear df;
