Help to Fortran translation

조회 수: 1 (최근 30일)
Morten Seiger
Morten Seiger 2020년 6월 2일
댓글: Rena Berman 2020년 10월 12일
Hi!
I have a fortran file I have to use in Matlab. Can the MEX function handle that, if so, how? Or can someone help with a translation of the following:
I need to calculate u1 and u2 from some old wind velocity measurements. I can see that the parameters are defined in the beginning, but it is not all of the steps I fully understand.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine read(ave1,ave2,rms1,rms2,ren)
implicit real*8 (a-h,o-z)
parameter(ntotal=20480000)
parameter (nrd=ntotal*2)
character fn1*50
integer*2 ju(nrd)
dimension u1(ntotal),u2(ntotal)
real*8 usq,dudnsq,dudxsq,epsilon,lambda,Relambda
common /bl1/ u1,u2
common /bl2/ ju
nbytes = 2*nrd
n=ntotal
fn1='/data1/dhruva/two_point/dugway_8_4_98/dug2_4.bin'
open(unit=4,file=fn1,form='unformatted',status='old',
+ access='direct',recl=nbytes)
read(4,rec=1,err=55) (ju(i),i=1,nrd)
goto 60
55 print *,'error ',i,ierr
goto 60
56 print *,'end of file reached'
60 close(4)
print *,'Finish reading raw data file'
open(unit=9,file='datapts.nonconv')
do 65 i=1,15000
write(9,*)ju(i)
65 continue
close(9)
c-----------CONVERT FROM SAMPLING UNITS TO VELOCITY UNITS---------
count=0.0
gain=10.0
offset1=3.16
offset2=2.75
usq=0.0
do 12 i=2,nrd,2
c if (abs(ju(i)) .ge. 2048) then
c count=count+1
c print *,i,ju(i)
c endif
usq = (ju(i)/(gain*409.5)+offset1)**2.0
u1(i/2) = ((usq-5.3885)/1.9786)**2
  댓글 수: 1
Rena Berman
Rena Berman 2020년 10월 12일
(Answers Dev) Restored edit

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

채택된 답변

Ben Barrowes
Ben Barrowes 2020년 6월 3일
There should be more code to this file. It gets a little unwieldy to post larger files here though.
Perhaps you could try f2matlab (at the file exchange). If you need more help, email me and I can take a look.
One note, though, the direct access unformatted binary file reading may be tricky in matlab to get the format right.
  댓글 수: 1
Morten Seiger
Morten Seiger 2020년 6월 4일
I found a solution in the mean time, but thanks anyway.

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

추가 답변 (0개)

카테고리

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