[MITgcm-support] FORTRAN binary read help.

Martin Losch Martin.Losch at awi.de
Mon Nov 16 02:43:08 EST 2009


Michael's testprog contains all the secrets. Your matlab code produces  
unblocked direct access files, so the important keywords are  
access="direct" and the record length recl=100*8, where 8 is the  
wordlength of your system. Another one is FORM="UNFORMATTED" which is  
implicit in the access="direct" statement. If you want to do it "the  
MITgcm-way", then I suggest having a look at model/src/ 
load_grid_spacing.F where single vectors are read as in your example  
(delX/Y/RFile).

Martin

On Nov 16, 2009, at 12:56 AM, Michael Schaferkotter (Contractor) wrote:

> jody;
>
> after writing out the data on a powerpc Mac using the MATLAB program
>
> x=cos(1:100); ieee='l'; prec='real*8';
> fid = fopen('HorStruct.bin','w',ieee); fwrite(fid,x,prec);  
> fclose(fid);
>
>
> the following fortran program on a Intel MacBookPro, successfully  
> reads the data back in:
>
> program testprog
>
>       integer, parameter :: real8  = selected_real_kind(10)
>
>       real(kind=real8), dimension(100) :: horStructWest
>
>       open(unit=111,file="HorStruct.bin", status="old",  
> access="direct", recl=100*8 ,action="read")
>       read(unit=111,rec=1) horStructWest
>       CLOSE (unit=111)
>
>       print *, horStructWest
>
> endprogram testprog
>
> i/m sure it/s not the only way.
>
> michael schaferkotter
>
> ps.
>
> [PowerBookG5:/] schaferk% g95 -v
> Using built-in specs.
> Target:
> Configured with: ../configure --enable-languages=c
> Thread model: posix
> gcc version 4.0.3 (g95 0.92!) Apr 24 2009
>
>
> _______________________________________________
> MITgcm-support mailing list
> MITgcm-support at mitgcm.org
> http://mitgcm.org/mailman/listinfo/mitgcm-support




More information about the MITgcm-support mailing list