%

%%%%%%%%%%%%%%% FICHIER pluie IRD
% ouverture / lecture du fichier
clear;
close all;

% on selectionne les mois d ete (attention aux annees bixestiles!)

siz1=31+28+31+30+31+1;
siz1bis=31+28+31+30+31+30+31+31+30;
pluie=zeros(41,17,122,12);

clear v fid; fid=fopen('pluvio.79.haut','r','b'); siz=41*17*365;
v=fread(fid,siz,'float'); fclose(fid);
v=reshape(v,41,17,365);
clear a b c;
for a=1:41;
   for b=1:17;
       for c=1:365;
          if v(a,b,c)>990;
              v(a,b,c)=NaN;
          elseif v(a,b,c)<0;
              v(a,b,c)=NaN;
          end;
       end;
   end;
end;
pluie(:,:,:,1)=v(:,:,siz1:siz1bis); % 1979

clear v fid; fid=fopen('pluvio.80.haut','r','b'); siz=41*17*366;
v=fread(fid,siz,'float'); fclose(fid);
v=reshape(v,41,17,366);
clear a b c;
for a=1:41;
   for b=1:17;
       for c=1:366;
          if v(a,b,c)>990;
              v(a,b,c)=NaN;
          elseif v(a,b,c)<0;
              v(a,b,c)=NaN;
          end;
       end;
   end;
end;
pluie(:,:,:,2)=v(:,:,siz1+1:siz1bis+1); % 1980

clear v fid; fid=fopen('pluvio.81.haut','r','b'); siz=41*17*365;
v=fread(fid,siz,'float'); fclose(fid);
v=reshape(v,41,17,365);
clear a b c;
for a=1:41;
   for b=1:17;
       for c=1:365;
          if v(a,b,c)>990;
              v(a,b,c)=NaN;
          elseif v(a,b,c)<0;
              v(a,b,c)=NaN;
          end;
       end;
   end;
end;
pluie(:,:,:,3)=v(:,:,siz1:siz1bis); % 1981

clear v fid; fid=fopen('pluvio.82.haut','r','b'); siz=41*17*365;
v=fread(fid,siz,'float'); fclose(fid);
v=reshape(v,41,17,365);
clear a b c;
for a=1:41;
   for b=1:17;
       for c=1:365;
          if v(a,b,c)>990;
              v(a,b,c)=NaN;
          elseif v(a,b,c)<0;
              v(a,b,c)=NaN;
          end;
       end;
   end;
end;
pluie(:,:,:,4)=v(:,:,siz1:siz1bis); % 1982

clear v fid; fid=fopen('pluvio.83.haut','r','b'); siz=41*17*365;
v=fread(fid,siz,'float'); fclose(fid);
v=reshape(v,41,17,365);
clear a b c;
for a=1:41;
   for b=1:17;
       for c=1:365;
          if v(a,b,c)>990;
              v(a,b,c)=NaN;
          elseif v(a,b,c)<0;
              v(a,b,c)=NaN;
          end;
       end;
   end;
end;

pluie(:,:,:,5)=v(:,:,siz1:siz1bis); % 1983

clear v fid; fid=fopen('pluvio.84.haut','r','b'); siz=41*17*366;
v=fread(fid,siz,'float'); fclose(fid);
v=reshape(v,41,17,366);
clear a b c;
for a=1:41;
   for b=1:17;
       for c=1:366;
          if v(a,b,c)>990;
              v(a,b,c)=NaN;
          elseif v(a,b,c)<0;
              v(a,b,c)=NaN;
          end;
       end;
   end;
end;
pluie(:,:,:,6)=v(:,:,siz1+1:siz1bis+1); % 1984

clear v fid; fid=fopen('pluvio.85.haut','r','b'); siz=41*17*365;
v=fread(fid,siz,'float'); fclose(fid);
v=reshape(v,41,17,365);
clear a b c;
for a=1:41;
   for b=1:17;
       for c=1:365;
          if v(a,b,c)>990;
              v(a,b,c)=NaN;
          elseif v(a,b,c)<0;
              v(a,b,c)=NaN;
          end;
       end;
   end;
end;
pluie(:,:,:,7)=v(:,:,siz1:siz1bis); % 1985

clear v fid; fid=fopen('pluvio.86.haut','r','b'); siz=41*17*365;
v=fread(fid,siz,'float'); fclose(fid);
v=reshape(v,41,17,365);
clear a b c;
for a=1:41;
   for b=1:17;
       for c=1:365;
          if v(a,b,c)>990;
              v(a,b,c)=NaN;
          elseif v(a,b,c)<0;
              v(a,b,c)=NaN;
          end;
       end;
   end;
end;
pluie(:,:,:,8)=v(:,:,siz1:siz1bis); % 1986

clear v fid; fid=fopen('pluvio.87.haut','r','b'); siz=41*17*365;
v=fread(fid,siz,'float'); fclose(fid);
v=reshape(v,41,17,365);
clear a b c;
for a=1:41;
   for b=1:17;
       for c=1:365;
          if v(a,b,c)>990;
              v(a,b,c)=NaN;
          elseif v(a,b,c)<0;
              v(a,b,c)=NaN;
          end;
       end;
   end;
end;
pluie(:,:,:,9)=v(:,:,siz1:siz1bis); % 1987

clear v fid; fid=fopen('pluvio.88.haut','r','b'); siz=41*17*366;
v=fread(fid,siz,'float'); fclose(fid);
v=reshape(v,41,17,366);
clear a b c;
for a=1:41;
   for b=1:17;
       for c=1:366;
          if v(a,b,c)>990;
              v(a,b,c)=NaN;
          elseif v(a,b,c)<0;
              v(a,b,c)=NaN;
          end;
       end;
   end;
end;
pluie(:,:,:,10)=v(:,:,siz1:siz1bis); % 1988

clear v fid; fid=fopen('pluvio.89.haut','r','b'); siz=41*17*365;
v=fread(fid,siz,'float'); fclose(fid);
v=reshape(v,41,17,365);
clear a b c;
for a=1:41;
   for b=1:17;
       for c=1:365;
          if v(a,b,c)>990;
              v(a,b,c)=NaN;
          elseif v(a,b,c)<0;
              v(a,b,c)=NaN;
          end;
       end;
   end;
end;
pluie(:,:,:,11)=v(:,:,siz1:siz1bis); % 1989

clear v fid; fid=fopen('pluvio.90.haut','r','b'); siz=41*17*365;
v=fread(fid,siz,'float'); fclose(fid);
v=reshape(v,41,17,365);
clear a b c;
for a=1:41;
   for b=1:17;
       for c=1:365;
          if v(a,b,c)>990;
              v(a,b,c)=NaN;
          elseif v(a,b,c)<0;
              v(a,b,c)=NaN;
          end;
       end;
   end;
end;
pluie(:,:,:,12)=v(:,:,siz1:siz1bis); % 1990

clear siz sizbis;
clear v;

% essai de visualisation d'une carte de pluie annuelle
orient('landscape');
lat=[-10:2.5:30];
lon=[-70:2.5:30]';
for a=1:12;
   subplot(3,4,a);
   clear v;
   v(:,:,:)=pluie(:,:,:,a);
   v=permute(v,[3 2 1]);
   v1=zeros(17,41);
   v1(:,:)=nansum(v);
   for b=1:17;
      for c=1:41;
         if v1(b,c)>3000;
           v1(b,c)=3000;
         end;
      end;
   end;
   palette3;
   v1(1,1)=3000.1;
   contourf(lon,lat,v1,[0:200:3000],'LineStyle','none');
   colorbar;
   hold on;
   cartemonde;
   axis equal;
   axis([-20 26 0 23]);
   set (gca,'tickDir','out');
   set (gca,'XTick',[-20:10:20],'XTickLabel',['20W';'10W';' 0 ';'10E';'20E'],'fontname','Arial','fontsize',6);
   set (gca,'YTick',[0:10:20],'YTickLabel',['  0';'10N';'20N'],'fontname','Arial','fontsize',6);
end;
print('-depsc2','pluie_ird_25_degres.eps');
