## Friday, February 28, 2014

### Convert TRRM Real Time Binary File into ESRI ASCII

Seven simple steps for converting TRMM binary to ASCII grid using MATLAB

Step1:
%Open TRMM realtime binary file

trmmFile = fopen('E:\TrmmBinary Processing\3B42RT.2012.03.27.09z.bin', 'rb');

Step2:
%Move file pointer to the begining of  file

frewind(trmmFile);

Step3:
%Read TRMM value from the binary file having 1140 rows and 480 columns

Step4:
%Shift precipitation by 90 degree to relate data with equator

precipitation = rot90(precipitation);

Step5:
%After rotaion by 90 degree ncols changed into 1440 from 480 and nrows
%changed into 480 from 1440

Step6:
%Open ASCII file to store binary data

asciiFile='3B42RT.2012.03.27.09z.bin_matlab.asc';

Step7:
%Write ASCII header for ESRI ASCII

dlmwrite(asciiFile, precipitation,'delimiter',' ','precision',6,'roffset',0,'coffset',0,'-append');

Addition: Read TRMM RT binary and convert it into X-Coordinate,Y-Coordinate,Z-value table into a CSV file

Open binary file
fid = fopen('E:\TrmmBinary Processing\3B42RT.2012.03.02.03z.bin', 'r');
Move file reader into the begining of the file
frewind(fid);
Read 32bit floating point binary with 1440 row/lat and 480 cols/lat
precipitation = rot90(precipitation);
lon=1440;
lat=480;
for lo=1:lon
for la=1:lat
rlon=0.125+0.25*(lo-1);
rlat=-59.875+0.25+(la-1);
output=sprintf('f,f,f',rlat,rlon,precipitation(lo,la));
disp(output);
M=[rlat,rlon,precipitation(lo,la)];
dlmwrite ('trmmoutput.csv',M,'-append');

end
end
Enjoy

References: