Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Appeding to a file



Another option would be to use a loop to read each line until the end of the file is reached.
The END specifier in the READ statement specifies a label to which flow is transferred if the end of the file is reached.
For example, each time the following code is run, it appends 'A new line of text' to the file 'test.txt'.

OPEN(UNIT=10, FILE='test.txt', STATUS='UNKNOWN',
& ACCESS='SEQUENTIAL')


DO WHILE (.true.)
READ(10, *, END=1000)
END DO


1000 WRITE(10, '(a)') 'A new line of text'


The DO WHILE loop is also non-standard fortran 77, but is commonplace. If you need strict fortran 77 you could duplicate this functionality with GOTO statements as

100 READ(10, *, END=1000)
GOTO 100

1000 WRITE(10, '(a)') 'A new line of text'

On Jan 15, 2005, at 4:02 AM, Ron Sverdlove wrote:

You should know that ACCESS='APPEND' is also non-standard, so it may not work with other compilers.  In Fortran 77 and later, the only standard values for the ACCESS specifier are 'SEQUENTIAL' and 'DIRECT'.

Ron Sverdlove


Marize Pommot-Maia wrote:

On Fri, 14 Jan 2005 21:19:28 -0500, Ron Sverdlove
<email@hidden> wrote:

Marize,

The FILEOPT specifier is non-standard. Since standard Fortran 77 did
not have a way to open a file for appending, some compilers, such as the
Sun compilers, accepted this form as an extension. The standard
specifier for this purpose in Fortran 90 and later is:
POSITION='APPEND' .

By the way, FILE=FILE(NC:) looks odd. The FILE specifier should be set
equal to a character expression, but FILE(NC:) is a character array
expression: all elements of the FILE array from position NC to the end.

Ron Sverdlove


Hi,

Thanks for the prompt replies.

Ron, your sugestion got me on the right track. f77 didn't like
POSITION='APPEND'. But, if
one defines ACCESS='append' it all comes together.That is,

<code>
OPEN(OLU,FILE=FILE(NC:),STATUS=STAT,ACCESS='APPEND',
& FILEOPT='EOF',IOSTAT=IOS)
</code>

Many thanks,



--
Ronald Sverdlove
email@hidden
609 924-9638


Andrew

===================================================
Andrew J. Miller
Graduate Student
Department of Engineering Science & Mechanics
Pennsylvania State University
212 Earth and Engineering Sciences Building
University Park, PA 16802


office: 408 Earth and Engineering Sciences Building
office Phone: (814) 863-2241
email: <mailto:email@hidden>

web: <http://www.esm.psu.edu/~ajmiller/>
===================================================
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Fortran-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/fortran-dev/email@hidden

This email sent to email@hidden

References: 
 >Appeding to a file (From: Marize Pommot-Maia <email@hidden>)
 >Re: Appeding to a file (From: Ron Sverdlove <email@hidden>)
 >Re: Appeding to a file (From: Marize Pommot-Maia <email@hidden>)
 >Re: Appeding to a file (From: Ron Sverdlove <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.