# Help to Fortran translation

1 view (last 30 days)
Morten Seiger on 2 Jun 2020
Commented: Rena Berman on 12 Oct 2020
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.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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)
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
Rena Berman on 12 Oct 2020

Ben Barrowes on 3 Jun 2020
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.
Morten Seiger on 4 Jun 2020
I found a solution in the mean time, but thanks anyway.

### Tags

No tags entered yet.

### Community Treasure Hunt

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

Start Hunting!

Translated by