how to translate this matlab code to fortran

조회 수: 2 (최근 30일)
wonsoek lee
wonsoek lee 2015년 12월 15일
댓글: Walter Roberson 2015년 12월 15일
fid = fopen (CMNfile(I).name, 'r');
First get the receiver position in the CMN file: this info is on line 3
i = 1;
while 1
line = fgetl(fid);
if ~ischar(line)
Rx = [ ];
break
end
if i>3, break, end
if (i==3)
[t] = sscanf(line, '%f %f %f');
Rx = [t(3) t(1) t(2)];
end
i=i+1;
end
%receiver position done.
%%Now look for the required time
%%use the same fid because its still the same file.
out = textscan (fid, '%*f %f %*f %f %f %*f %*f %f %*f %*f', 'HeaderLines',5);
I translate this matlab function
fid = fopen (CMNfile(I).name, 'r')
to this fortran
open (unit=10, file='CMNfile(I).name', status='old',ACCESS ='READ')
but I don't know how to change fgetl, ischar, sscanf, textscan..... plz help me

답변 (1개)

Walter Roberson
Walter Roberson 2015년 12월 15일
I already showed you how to deal with the ischar() and sscanf() in your earlier question.
Is CMNfile being created by dir() ? If so then you are going to have difficulties replicating that. Using file='CMNfile(I).name' is not correct. Are you using MS Windows or Linux or OS-X ?
Replacing textscan() to read a file of unknown length is a bit of pain because Fortran does not allow arrays to be grown at need, at least not in any clean way. See https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/385790
Which Fortran compiler are you using? Can you use g77?
  댓글 수: 2
wonsoek lee
wonsoek lee 2015년 12월 15일
I'm using MS windows and what is compiler?? maybe i'm using fortran77
Walter Roberson
Walter Roberson 2015년 12월 15일
If you use
mex -setup fortran
Then which compiler does it say is installed?

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

카테고리

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