%

% initialisation
close all;
clear;

olr=zeros(122,30,64,128);

ncload('rlut_d.AfNQIVIV.197106-09.nc','rlut');
olr(:,1,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.197206-09.nc','rlut');
olr(:,2,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.197306-09.nc','rlut');
olr(:,3,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.197406-09.nc','rlut');
olr(:,4,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.197506-09.nc','rlut');
olr(:,5,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.197606-09.nc','rlut');
olr(:,6,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.197706-09.nc','rlut');
olr(:,7,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.197806-09.nc','rlut');
olr(:,8,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.197906-09.nc','rlut');
olr(:,9,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.198006-09.nc','rlut');
olr(:,10,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.198106-09.nc','rlut');
olr(:,11,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.198206-09.nc','rlut');
olr(:,12,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.198306-09.nc','rlut');
olr(:,13,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.198406-09.nc','rlut');
olr(:,14,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.198506-09.nc','rlut');
olr(:,15,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.198606-09.nc','rlut');
olr(:,16,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.198706-09.nc','rlut');
olr(:,17,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.198806-09.nc','rlut');
olr(:,18,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.198906-09.nc','rlut');
olr(:,19,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.199006-09.nc','rlut');
olr(:,20,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.199106-09.nc','rlut');
olr(:,21,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.199206-09.nc','rlut');
olr(:,22,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.199306-09.nc','rlut');
olr(:,23,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.199406-09.nc','rlut');
olr(:,24,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.199506-09.nc','rlut');
olr(:,25,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.199606-09.nc','rlut');
olr(:,26,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.199706-09.nc','rlut');
olr(:,27,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.199806-09.nc','rlut');
olr(:,28,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.199906-09.nc','rlut');
olr(:,29,:,:)=rlut; clear rlut;

ncload('rlut_d.AfNQIVIV.200006-09.nc','rlut');
olr(:,30,:,:)=rlut; clear rlut;

% selction du domaine geographique
olr1=zeros(122,30,64,128);
olr1(:,:,:,1:64)=olr(:,:,:,65:128);
olr1(:,:,:,65:128)=olr(:,:,:,1:64);
clear olr;
olr=olr1;
clear olr1;
olr=olr(:,:,29:43,54:77);
taille=(43-29+1)*(77-54+1);
tps=122*29;
% taille de OLR
% 122 28 14 24
olr=olr(31:122,:,:,:);
olr1(:,:,:)=mean(olr);
clear olr;
olr=permute(olr1,[3 2 1]);
clear olr1;
olr=reshape(olr,360,30);
for a=1:360;
    clear vaude vaude1;
    vaude=olr(a,:);
    vaude=vaude';
    vaude=mean(vaude);
    olr(a,:)=olr(a,:)-vaude;
end;

% calcul de la matrice de covariance
vaudou=zeros(360,360);
for a=1:360;
    for b=1:360;
      clear e d covaria;
      e=olr(b,:);
      d=olr(a,:);
      covaria=cov(e,d);
      vaudou(a,b)=covaria(2,1);
    end;
end;

% on diagonalise la matrice de covariance
[C,L]=eig(vaudou);

delete('eof_annuel_AFR.mat');
save('eof_annuel_AFR.mat','C','L','olr')
