%

% ncload('pr_d.AfNQIVIV.197106-09.nc')
% whos
% Name        Size                  Bytes  Class     Attributes
%
% ans         1x4                     268  cell
% lat        64x1                     512  double
% lon       128x1                    1024  double
% pr      122x64x128            7995392  double
% time      122x1                     976  double
%

close all;
clear;

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

ncload('pr_d.AfNQIVIV.197106-09.nc','pr');
pluie(:,1,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.197206-09.nc','pr');
pluie(:,2,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.197306-09.nc','pr');
pluie(:,3,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.197406-09.nc','pr');
pluie(:,4,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.197506-09.nc','pr');
pluie(:,5,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.197606-09.nc','pr');
pluie(:,6,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.197706-09.nc','pr');
pluie(:,7,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.197806-09.nc','pr');
pluie(:,8,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.197906-09.nc','pr');
pluie(:,9,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.198006-09.nc','pr');
pluie(:,10,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.198106-09.nc','pr');
pluie(:,11,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.198206-09.nc','pr');
pluie(:,12,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.198306-09.nc','pr');
pluie(:,13,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.198406-09.nc','pr');
pluie(:,14,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.198506-09.nc','pr');
pluie(:,15,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.198606-09.nc','pr');
pluie(:,16,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.198706-09.nc','pr');
pluie(:,17,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.198806-09.nc','pr');
pluie(:,18,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.198906-09.nc','pr');
pluie(:,19,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.199006-09.nc','pr');
pluie(:,20,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.199106-09.nc','pr');
pluie(:,21,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.199206-09.nc','pr');
pluie(:,22,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.199306-09.nc','pr');
pluie(:,23,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.199406-09.nc','pr');
pluie(:,24,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.199506-09.nc','pr');
pluie(:,25,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.199606-09.nc','pr');
pluie(:,26,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.199706-09.nc','pr');
pluie(:,27,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.199806-09.nc','pr');
pluie(:,28,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.199906-09.nc','pr');
pluie(:,29,:,:)=pr; clear pr;

ncload('pr_d.AfNQIVIV.200006-09.nc','pr');
pluie(:,30,:,:)=pr; clear pr;

% selction du domaine geographique
pluie1=zeros(122,30,64,128);
pluie1(:,:,:,1:64)=pluie(:,:,:,65:128);
pluie1(:,:,:,65:128)=pluie(:,:,:,1:64);
clear pluie
pluie=pluie1;
clear pluie1;
pluie=pluie(:,:,29:43,54:77);
taille=(43-29+1)*(77-54+1);
tps=122*29;
% taille de PLUIE
% 122 28 14 24
pluie=pluie(31:122,:,:,:);
pluie1(:,:,:)=mean(pluie);
clear pluie;
pluie=permute(pluie1,[3 2 1]);
clear pluie1;
pluie=reshape(pluie,360,30);
for a=1:360;
    clear vaude vaude1;
    vaude=pluie(a,:);
    vaude=vaude';
    vaude=mean(vaude);
    pluie(a,:)=pluie(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=pluie(b,:);
      d=pluie(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_pluie_annuel_AFR.mat');
save('eof_pluie_annuel_AFR.mat','C','L','pluie');
