Help to Fortran translation

1 vue (au cours des 30 derniers jours)
Morten Seiger
Morten Seiger le 2 Juin 2020
Commenté : Rena Berman le 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.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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 commentaire
Rena Berman
Rena Berman le 12 Oct 2020
(Answers Dev) Restored edit

Connectez-vous pour commenter.

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Fortran with MATLAB dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by