필터 지우기
필터 지우기

How to read binary file or GrADS

조회 수: 14 (최근 30일)
peterhack
peterhack 2016년 11월 7일
답변: Ramakrishna reddy Pareddy 2019년 3월 25일
Hey guys,
I want to extract sattelite data from a binary file , where also a GrADS is provided. The manual says one could get the data by executing the following Fortran code:
name = xxx.bin
nlines = 180; ncolumns= 180; ntime= 803
size = nlines * ncolumns * ntime
REAL G(nlines, ncolumns, ntime)
OPEN (1, FILE= name, ACCESS= direct, FORM= unformattedRECL= 4*size)
READ (1,REC=1) G
CLOSE (1)
However, could someone give me assistance on translating this to MATLAB? I have also tried the GrADS - Matlab Interface , but the data variable did not contain anything.
Many thanks!

답변 (3개)

Ramakrishna reddy Pareddy
Ramakrishna reddy Pareddy 2019년 3월 25일
how to read .grd format file in matlab not ascii.grd file please provide me code

KSSV
KSSV 2016년 11월 8일
Below one is the rough translation of your fortran code. I am not sure whether the below works or not. You read about fread to know more about reading the binary files. Let me know whether the below one worked. If it shows error, try to attach one binary file, so that I can change the code and see.
clc; clear all ;
filename = 'GL12g_AS_04pentad_V02.bin' ;
m = 180; n = 180; p = 803 ;
t= m*n*p ;
fid = fopen(filename) ;
G = fread(fid,t,'double') ; % try uint16 etc if double fails
fclose(fid) ;

peterhack
peterhack 2016년 11월 8일
편집: peterhack 2016년 11월 10일
It really seems to work using
G = fread(fid,t,'real*4');
  댓글 수: 1
KSSV
KSSV 2016년 11월 9일
Attach the file.....what is that code given on top?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Fortran with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by