Only if "year" ever hits 2999 on any of the lines read will the
IF---THEN loop be executed, and the write is preceded by the EXIT from
the loop. You ought to say:
IF(YEAR==2999)EXIT (from the DO loop)
WRITE(4...... (otherwise do the write to 4)
And drop the THEN and END IF. Either that or put the write after the END
IF. If you want to have it stop on end of file on 5, rather than hitting
a bogus year=2999, just add after the READ:
IF(END5.NE.0)EXIT
And forget testing for year=2999.
HTH
Dick Russell
-----Original Message-----
From: Fortran 90 List [mailto:[log in to unmask]] On Behalf
Of Blair, Ernest R.
Sent: Tuesday, September 28, 2004 2:11 PM
To: [log in to unmask]
Subject: Windows file I/O in F : newbie querstion
Folks,
In the program below, I'm just trying to read in / write out a file
under Windows (I'm under XP and haven't "upgraded" to the latest to come
out of Redmond if it makes any difference). Program executes normally,
but I get
the header on unit 4 but nothing else. Also would like to end with an
end-of-file on unit 5, but haven't figured that one out either.
Appreciate any help.
Ernest Blair
Sr. Modeling & Simulation Eng. - Operations Research Future Combat
Systems, Lead Systems Integration Team, Manned Ground Vehicles
- SAIC, 4110 Campus Point Ct, M/S E3-X, San Diego, CA 92121
______________________________________
tel: 858-826-5138 fax: 858-826-5129
[log in to unmask]
------------------------------------------------------------------------
----
-----
program read_data4
character (len=107) :: a1
character (len=3) :: Away,Home,Dir,Adom,Hdom,away2,home2,day
character (len=5) :: WX,Aturf,Hturf
real :: tline,sline
integer ::
Year,Wk,ACode,HCode,Tmp,Vel,Hum,ascr,hscr,seq,ios5,ios4,end5,i
open(unit=5, iostat=ios5, status="old", action="read",
position="rewind", &
access="sequential", form="formatted", &
file="c:\documents and
settings\ernie\desktop\masterfiles\data\wx_data.txt")
open(unit=4, iostat=ios4, status="replace", action="write",
access="sequential", &
position="rewind", form="formatted", &
file="c:\documents and
settings\ernie\desktop\masterfiles\data\wx_data_out.txt")
! read/write header
read (unit=5, fmt=*) a1
write (unit=4, fmt=*) a1
! read/write Weather info
do i = 1,10000
read (unit=5, fmt=*, iostat=end5)
Year,Wk,Away,Home,ACode,HCode,Tmp,Dir,Vel,Hum,&
WX,Adom,Hdom,Aturf,Hturf,away2,ascr,tline,day,home2,hscr,sline,seq
if (Year == 2999) then
exit
write(unit=4, fmt=*) Year,Wk,Away,Home,ACode,HCode,Tmp,Dir,Vel,Hum,&
WX,Adom,Hdom,Aturf,Hturf,away2,ascr,tline,day,home2,hscr,sline,seq
end if
end do
close (unit=5, status="keep")
close (unit=4, status="keep")
end program read_data4
-----------------------------------------------------------------------
-----------------------------------------
*****************Internet Email Confidentiality Footer******************
Privileged/Confidential Information may be contained in this message.
If you are not the addressee indicated in this message (or responsible
for delivery of the message to such person), you may not copy or deliver
this message to anyone. In such case, you should destroy this message
and notify the sender by reply email. Please advise immediately if you
or your employer do not consent to Internet email for messages of this
kind. Opinions, conclusions and other information in this message that
do not relate to the official business of The Shaw Group Inc. or its
subsidiaries shall be understood as neither given nor endorsed by it.
________________________________________________________________________
The Shaw Group Inc.
http://www.shawgrp.com
|