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

回答(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