Reading Fortran binary file in MATLAB
조회 수: 10 (최근 30일)
이전 댓글 표시
I am having trouble understanding Binary file and I am trying to figure out a way to read in MATLAB. I just have the following details about the file.
File name = ZDxxx, where xxx = analysis number. File type = binary direct access. Record length = 12 bytes (3 REAL*4).
Item 1 = current drift value. Item 2 = maximum positive value of this drift to this point Item 3 = maximum negative value.
The file contains NTIM+1 sets of NDRFT records, where NTIM = no. of time or load steps (set 1 = state at start of analysis) and NDRFT = no. of drifts.
I have used MATLAB for pretty basic purposes like reading text files and doing some matrix analysis. I am not a computer science student.
댓글 수: 2
dpb
2016년 7월 7일
편집: dpb
2016년 7월 7일
A Fortran direct access file has some additional structure hidden elements in it besides just the data. How that is encoded is not specified by the Fortran Standard; only that a file written by a given compiler can be read by the same compiler.
Typically, there's a record length before and after each record, often 32-bit integer but that's not necessarily so.
The simplest route for reading the data by other than Fortran would be to write it in either a text form or as 'stream' binary file which is now supported by Fortran Standard altho every compiler I'm aware of has had non-standard way of creating such for quite a long time.
You can try something like
fid=fopen('ZD...ext','r');
n=fread(fid,1,'int')
A=fread(fid,3,'single')
n=fread(fid,1,'int')
and see what you get. If you can recognize the first three values in A, then the surmise on the record marker is correct; if not, report back on what
frewind(fid)
R=fread(fid,32,'char*1');
fprintf([repmat('%02X',1,32) '\n'],R)
returns. This will show us the actual content of the first 32 bytes in the file which can use to try to decipher the record encoding.
PS: Check the documentation for your compiler; it may have the description altho it's not guaranteed to be documented since with Fortran-only solution, there's no need for such knowledge...
Martin Zuniga
2020년 3월 24일
You are trying to read a Perform3D results file, right? I have worked with Perform3D for two years and was looking into reading the binary files directly, did you succeed?
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fortran with MATLAB에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!