For Programmers: Free Programming Magazines  


Home > Archive > Fortran > February 2005 > replacement for form='binary'









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author replacement for form='binary'
beliavsky@aol.com

2005-02-18, 3:59 am

David Frank's word-processing code has a line

open (1,file=fname,form='binary',position='ap
pend')

where fname is the name of a text file. This is not standard Fortran
95, because form should be 'formatted' or 'unformatted', but
form='binary' is supported by several commerical compilers I tried
(although not g95 or gfortran). What is the suggested
standard-conforming alternative for the line above?

robert.corbett@sun.com

2005-02-18, 3:59 am

There is no substitute in Fortran 95. There is in Fortran 2003.


Sincerely,

Bob Corbett

Ken Plotkin

2005-02-18, 3:59 am

On 17 Feb 2005 19:30:29 -0800, beliavsky@aol.com wrote:

>David Frank's word-processing code has a line
>
>open (1,file=fname,form='binary',position='ap
pend')
>
>where fname is the name of a text file. This is not standard Fortran
>95, because form should be 'formatted' or 'unformatted', but
>form='binary' is supported by several commerical compilers I tried
>(although not g95 or gfortran). What is the suggested
>standard-conforming alternative for the line above?


form='unformatted',access='direct' works on most systems -
particularly those where files are treated as a sequence of bytes.
You may need to play around with recl= for a particular application.

In F2003, this will be form='stream' (or will it be access='stream'?).
IMHO, it should have been called form='threepwood'.

Ken Plotkin

Herman D. Knoble

2005-02-18, 3:59 pm

While the following is not standard Fortran 90 or 95, it
provides a simple way to make it work with several
(linux) compilers:

....
Open(Unit=50, file='whatever', &
form='BINARY')

! form='UNFORMATTED',Access='TRANSPARENT')
! Lahey
! form='BINARY') ! PathScale and Portland
! form='UNFORMATTED',recordtype='STREAM') ! Intel
....

Skip Knoble

On 17 Feb 2005 19:30:29 -0800, beliavsky@aol.com wrote:

-|David Frank's word-processing code has a line
-|
-|open (1,file=fname,form='binary',position='ap
pend')
-|
-|where fname is the name of a text file. This is not standard Fortran
-|95, because form should be 'formatted' or 'unformatted', but
-|form='binary' is supported by several commerical compilers I tried
-|(although not g95 or gfortran). What is the suggested
-|standard-conforming alternative for the line above?

Richard E Maine

2005-02-18, 3:59 pm

In article <1108697429.388659.274590@o13g2000cwo.googlegroups.com>,
beliavsky@aol.com wrote:

> open (1,file=fname,form='binary',position='ap
pend')
>
> where fname is the name of a text file. This is not standard Fortran
> 95, because form should be 'formatted' or 'unformatted', but
> form='binary' is supported by several commerical compilers I tried
> (although not g95 or gfortran). What is the suggested
> standard-conforming alternative for the line above?


As others have noted, there isn't one in f95. Access='stream' is the
standard equivalent added in f2003. In my opinion, that feature is long
overdue in the standard and is one of the most important additions in
f2003. In many ways it is a small feature, but I still think it an
important one. (Small+important is a nice combination.) I wouldn't
think it such an important feature if there were a way to do the
equivalent in f95, but there isn't.

Many f95 compilers have comparable functionality, but they are not all
spelled the same.

Direct access can sometimes fill the bill in a more-or-less
standard-conforming way. The syntax of the code for direct access is
standard, but it is not guaranteed what such a file looks like, which
typically matters for interoperability reasons. Almost all
implementations can be made to do the trick with direct access
(sometimes you need a compiler switch like Lahey's /nohead... or however
that was spelled).

The big problem with direct access, however, is the restriction to fixed
record length. You can largely work around that by doing your own record
management (I've done so), but that can be a significant nuisance. Been
there. Done that. Convinced me to push for a better way in f2003. Also,
if the file can be of arbitrary length, not necessarily an even multiple
of some handy size, then there can be other major nuisances.

As somewhat of an aside, I didn't look at Dave's code and don't intend
to. But I've never seen the need for the new functionality of stream
access to be as significant for text files. The first version of my
access='stream' proposal didn't even include formatted streams, as I
found them less useful and more complicated; I was trying to keep the
proposal simple. A clear majority favored adding formatted streams, so
that was later done (and has since been the source of most of the
tweaking needed, because they *ARE* significantly more complicated).
There are certainly some applications for the formatted case, but I just
don't find them as pervasive. For many (I admit it isn't all)
applications of formatted stream, one can do about as well with
formatted sequential and advance='no', which is standard f95 (and f90).

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com