フィルターのクリア

Can matlab read binary real*8 data written by fortran?

4 ビュー (過去 30 日間)
Carlos_D
Carlos_D 2022 年 4 月 17 日
編集済み: Walter Roberson 2022 年 4 月 17 日
I have a binary data vector written in fortran, the variable type is real*8, is it possible to read this file with Matlab, and if so, can you tell me how I can read it?

回答 (2 件)

Bruno Luong
Bruno Luong 2022 年 4 月 17 日
Normally it's just a binary file of doubles
fid = fopen(BinFilename,'rb');
data = fread(fid, 'double');
fclose(fid);
you'll gete data as double vector array.

Walter Roberson
Walter Roberson 2022 年 4 月 17 日
編集済み: Walter Roberson 2022 年 4 月 17 日
real*8 is the same as double precision. However:
  • you have to be careful about byte order. It might be stored in "big endian" (most significant byte first) but the default for MATLAB is little-endian
  • the most common way of writing Fortran files is as "records" in which each record is preceeded and followed by a four-byte record length. I seem to recall that this corresponds to Fortran Form=Direct. I seem to recall that for plain binary streams that Fortran Form=Raw but that needs to be checked as it has been years since I last checked.
MATLAB does not have a direct call to read the length-delimited records; they can be handled with fread part by part.

カテゴリ

Help Center および File ExchangeFortran with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by