dpb
Posts:
8,250
Registered:
6/7/07


Re: How to read an ndimensioned matrix from a binary file
Posted:
Feb 13, 2013 1:00 PM


On 2/13/2013 9:54 AM, Jim wrote: > I would like to write a Matlab script to read an Ndimensioned matrix > created in Fortran. Specifically, the Fortran code wrote to a binary > file using the following: > > write(30) a, b, c > with the following declarations for a,b,c > > real a(16,20,22,6,3, 2) > > real b(16,20,22,6,3,13) > > real c(16,20,22,6,3,13) > > In Matlab, it seems that fread handles only a vector or 2dimesional matrix > fread(fileID, sizeA) where sizeA is a vector of size n or 2dimensional > matrix [m,n]. > > How can I read the Ndimensioned matrix I described?
Need more info...did the Fortran program write a Fortran unformatted file as a default OPEN(lun,form='unformatted')? If so, there's a record structure that will have to be dealt with (Fortran unformatted files are _NOT_ Clike stream files but have internal record information to support operations like BACKSPACE). You'll have to read that information as well.
If, otoh, either a preF2003 extension was used (supported by every compiler I'm aware of in one form or another) or the F2003+ Standard mechanism has been implemented in the compiler and used, then all you need to do is to read the file and reshape since both Fortran and Matlab use columnmajor storage order.


