Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with OPEN statement

Status
Not open for further replies.

BertVogts

Programmer
Nov 14, 2009
1
DE
Hello all!
I am new to this site and to Fortran. I wanted to write my first program now, but it doesn't work. The error seems to be in the OPEN statement, cause when i run the .exe, the PC aborts and puts out a big positive number (once I also received a -1), so the status isn't 0. Here is the important part of the program:
PROGRAM timeseries


IMPLICIT NONE

! Declare Variables
INTEGER:: n
INTEGER:: year
INTEGER:: status
REAL, DIMENSION(262) :: array
CHARACTER(len=20):: filename
REAL:: temp

WRITE (*,*) 'get input data'
! READ (*,*) filename
OPEN ( 20, FILE='C:\program files\Fortran\ytemp2m.dat', STATUS='OLD')
IF ( status /= 0 )THEN
WRITE (*,*) 'open failed', status

(...)

CLOSE (22)
END PROGRAM

I use the gfortran compiler and tried Fortran 77, 90 and 95.

Thanks for your help
 
Hi BertVogts

The OPEN statement seems to be correct, and here is how I would do this in F77. Note the ERR=88 in the open statement, which causes a jump to the statement "88 continue" if the opening fails.

Code:
      PROGRAM  TEST
      IMPLICIT NONE
       
!     Declare Variables
      INTEGER n
      INTEGER year
      REAL*8 array(262)
      CHARACTER*20 filename
      REAL temp
       
      WRITE (*,*) ' Get input data'

!     READ (*,*) filename
      OPEN (20, FILE='C:\program files\Fortran\ytemp2m.dat', STATUS='OLD', ERR=88)

!     Read from the file
!     (...)

      CLOSE (20)
      GOTO 99

88    CONTINUE
      WRITE (*,*) ' Open failed'

99    CONTINUE
      END
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top