Help to Fortran translation

3 visualizaciones (últimos 30 días)
Morten Seiger
Morten Seiger el 2 de Jun. de 2020
Comentada: Rena Berman el 12 de Oct. de 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.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Fortran with MATLAB en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by