Reading Fortran binary file in MATLAB
3 ビュー (過去 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!