% Program to transfer QRad data to netCDF data .
%
% Inputs:  ARR###_####.bin file 
% variables : QRRtm [360x720x48] Integrated rain rate data in 0.5 hr windows. 
%             IRR   [360x720] :The average of 48 matrices.
% Outputs: ARR###_####.nc file
% 
%*****************************************************************

close all;
clear all;

RV=[4495 4495];


for indx=1:1
   disp(' ')
   disp([' Processing file# ' num2str(indx) ' of ' num2str(length(RV(:,1)))])  
   comOPEN=['fid=fopen(''ARR' num2str(RV(indx,1)) '_' num2str(RV(indx,2)), '.bin'',''r'',''ieee-be'');'];
   comR=['QRRtm=fread(fid,[360,inf],''float32'');'];
   comCLOSE=['fclose(fid);'];
   eval(comOPEN);
   eval(comR);
   eval(comCLOSE); 
   
   clear comOPEN comR comCLOSE
   
   QRRtm(QRRtm==0)=NaN;
   QRRtm(QRRtm==999)=0;
   QRRtm=reshape(QRRtm,360,720,48);
   
   % Collapse the 48 IRR matrices into a single matrix:
   IRR=zeros(360,720);
   for i=1:360
      for j=1:720
      IRR(i,j)=nanmean(QRRtm(i,j,:));
      end
   end
   
end


figure
imagesc(IRR);
colorbar;
title('QRad Int. Rain Rate 0.5*0.5, km.mm/hr');



