Topic: Opening binary file

Dear friends,

I tried to open binary file with

open(unit=9,file='data/Grid_3D.dat',form='binary')

and got an Error message

"Form specifier in OPEN statement has invalid value 'binary'".

Why?

Re: Opening binary file

Like the error says, 'binary' is not a valid value for FORM.  Some compilers may have implemented this in the past, but it definitely isn't standards-compliant.

If you have a Fortran binary file, you can instead use:

open(unit=9,file='data/Grid_3D.dat',form='formatted')

and just read/write as you need.

More information might be helpful, though.  Are you attempting to read or write the file?  Do you happen to know what the file should contain?

Jeff Armstrong
Approximatrix, LLC

Re: Opening binary file

I am looking for a new compiler now that Lahey is out of business.  I downloaded Simply Fortran to test it with this problem in mind.    Using 'formatted' as the form does not work as suggested by Jeff (tried it).

Binary and Unformatted files may not be standard, but are extensively used in the groundwater modeling world (USGS code MODFLOW).

Is there any way to open and read these binary files and (for older MODFLOW models) unformatted files?

I can provide examples if needed.

Re: Opening binary file

If you could provide code and data samples, I might be able to help.  Binary files tend to be extremely problematic, especially if the routines to read/write them relied on any language extensions implemented by a compiler. 

If you need to send along some data files and code, you can email it directly to support@approximatrix.com.

Jeff Armstrong
Approximatrix, LLC

Re: Opening binary file

I sent the examples to Jeff and he found a solution.  I appreciate the help.

Re: Opening binary file

I really like it when a group of administrators answer questions right away. You guys are the best!

Re: Opening binary file

Can you share the "solution" for this specific problem?

Re: Opening binary file

Basically, binary files can be read using the "stream" access keyword:

open(100, file='binary.dat', status='old', action='read', access='stream', form='unformatted')

It worked in this specific case.  The "stream" access was designed to try to add some standard method of binary access that wasn't compiler-vendor-specific.

Jeff Armstrong
Approximatrix, LLC