how to translate this matlab code to fortran
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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
Walter Roberson
2015년 12월 15일
If you use
mex -setup fortran
Then which compiler does it say is installed?
참고 항목
카테고리
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!