I want to translate MATLAB to fortran

2 ビュー (過去 30 日間)
wonsoek lee
wonsoek lee 2015 年 12 月 14 日
回答済み: Walter Roberson 2015 年 12 月 14 日
fid = fopen(filename, 'r')
this matlab code to fortran
~iscahr(line)
this matlab code to fortran
sscanf(line, '%f %f %f')
this matlab code to fortran

採用された回答

Walter Roberson
Walter Roberson 2015 年 12 月 14 日
For the fopen:
INTEGER :: fid, fstatus
fid = 10
OPEN(UNIT = fid, FILE = filename, READONLY, ACCESS = 'READ',
+ STATUS = 'OLD', IOSTAT = fstatus)
IF (fstatus .NE. 0) THEN
WRITE(*,*) 'Could not open file'
CALL EXIT(0)
END IF
for the ~ischar(line) I suspect that the context is to detect end of file. If so then with the above code having set up fstatus as the IOSTAT variable, right after you do the read of the line,
IF (fstatus < 0) THEN
EXIT %exit loop
END IF
for the sscanf, assuming that the result was assigned to INVAR, at some point in the program,
REAL*8 :: INVAR(3)
INTEGER :: I
and the sscanf would be
READ( line, * ) (INVAR(I), I=1,3)

その他の回答 (0 件)

カテゴリ

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