how to translate this matlab code to fortran

1 view (last 30 days)
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

Answers (1)

Walter Roberson
Walter Roberson on 15 Dec 2015
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 Comments
wonsoek lee
wonsoek lee on 15 Dec 2015
I'm using MS windows and what is compiler?? maybe i'm using fortran77
Walter Roberson
Walter Roberson on 15 Dec 2015
If you use
mex -setup fortran
Then which compiler does it say is installed?

Sign in to comment.

Categories

Find more on Fortran with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!