|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
JRCBRITO
Joined: 29 Dec 2011 Posts: 2
|
Posted: Fri Dec 30, 2011 10:48 am Post subject: ERROR 94, Unit has neither been opened or preconnected |
|
|
Hi,
I am trying to create a executable of the following program, but wen I try to run it, appears the error 94 - Unit has neither been opened or preconnected, at the call READ(*,*) H1 and I don't andurstand why? Can anyone tell me why this happens?
Thanks for the help!
*
PROGRAM ROUTING
C Declaration of variables
INTEGER N,I,T1,DT
INTEGER T(250)
REAL A,K,H,H1,ST
REAL Q(250),QT(250),HD(250)
CHARACTER*12 NAMEIN,NAMOUT
CHARACTER*1 NO,AAA
C Input of data
WRITE (*,'(A)') ' ***** Flood routing calculation *****'
WRITE (*,*)
WRITE (*,'(A)') ' Give the name of input data file: '
READ (*,'(A12)') NAMEIN
OPEN (1,FILE=NAMEIN,STATUS='OLD',ACCESS='SEQUENTIAL')
READ (1,*) N
C N is the total number of input discharge observations (N <= 250)
READ (1,*) T1
C T1 is zero time
READ (1,*) DT
C DT is the time increment
WRITE (*,*)
WRITE (*,'(A)') ' Input hydrograph: '
DO 60 I=1,N
T(I)=T1+(I-1)*DT
READ (1,*) Q(I)
C Read discharge at each time. Time increment is constant.
WRITE (*,*) ' Time= ',T(I), ' Discharge= ',Q(I)
60 CONTINUE
READ (1,*) A
C A is the surface area of the reservoir
READ (1,*) K
C K is the const. in O=K*H^(3/2), the ouflow rate in spillway
READ (1,*) H
C H is the inicial head over the crest of spillway
CLOSE (1)
OPEN (2,FILE='Result.dat',STATUS='NEW')
C Help in manual plot of graph O*dt/2+S as a function of H
WRITE (*,*)
WRITE (*,'(A)') ' Manual plot graph O*dt/2+S function of H'
WRITE (*,*)
WRITE (*,*) ' Initial head over the spillway is = ', H
WRITE (*,*)
69 WRITE (*,'(A)') ' Enter head over crest, H1 '
WRITE (*,'(A)') ' (enter NEGATIVE number when complete) :'
READ (*,*) H1
IF (H1.LT.0.0) THEN
GOTO 100
ENDIF
ST=A*H1+DT*K*H1**(3./2.)/2
WRITE (*,'(A)') ' Please plot the point: '
WRITE (*,*) 'H= ',H1, ' O*dt/2+S= ',ST
GOTO 69
100 WRITE (*,'(A)') ' Is the graphic complete? (Y/N): '
READ (*,'(A)') NO
IF (NO.EQ. 'N') THEN
GOTO 69
ENDIF
DO 37 I = 1,N-1
WRITE (*,*) ' Time increment No. : ', I
WRITE (*,*) ' Head at time: ', I, ' is equal to:'
READ (*,*) H
D= K*H**(3./2.)
S=A*H
DS=(Q(I)+Q(I+1))*DT/2-D*DT/2+S
WRITE (*,*) ' O*dt/2+S= ', DS
QT(I)=D
HD(I)=H
WRITE (*,*)
WRITE (*,'(A)') ' From graph det. H at end time increment.'
WRITE (*,'(A)') ' When ready press RETURN and enter H.'
READ (*,'(A)') AAA
IF (I.EQ.N-1) THEN
WRITE (*,'(A)') ' Head in the last increment is: '
READ (*,*) H
D= K*H**(3./2.)
QT(I)=D
HD(I)=H
ENDIF
37 CONTINUE
C Writing final results in the terminal and in output data file
WRITE (*,'(A)') ' Time Inflow Outflow Head '
WRITE (2,'(A)') ' Time Inflow Outflow Head '
DO 600 I=1,N
WRITE (*,50) T(I), Q(I), QT(I), HD(I)
WRITE (2,50) T(I), Q(I), QT(I), HD(I)
600 CONTINUE
50 FORMAT (I5,3F8.2)
CLOSE (2)
WRITE(*,'(A)') ' ******** END of program ROUTING.FOR ******** '
END |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7924 Location: Salford, UK
|
Posted: Fri Dec 30, 2011 1:30 pm Post subject: |
|
|
The error probably occurs on a different line.
Have you tried using the debugger to run the program? |
|
Back to top |
|
|
JRCBRITO
Joined: 29 Dec 2011 Posts: 2
|
Posted: Fri Dec 30, 2011 4:13 pm Post subject: |
|
|
Yes I already use the debuger. And it point the an error in the same line. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7924 Location: Salford, UK
|
Posted: Fri Dec 30, 2011 5:00 pm Post subject: |
|
|
Try using different values for your own UNITs rather than 1 and 2.
UNIT values should start at 7 to avoid predefined values. |
|
Back to top |
|
|
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Mon Jan 02, 2012 12:27 pm Post subject: |
|
|
This problem is better illustrated by the following code.
Code: |
program anon
character(len=10) :: input
open(1,file="File.tmp")
close(1)
read(*,*) input
end program anon
|
This compiles with these warnings:
warning 868 - Opening unit 1 may affect the operation of input from the default unit '*' - are you sure you want to do this?
warning 868 - Closing unit 1 may affect the operation of input from the default unit '*' - are you sure you want to do this?
And when the code is run, the following error message is generated:
Error 94: Unit has neither been opened or preconnected.
Unit 1 is pre-connected to the keyboard. As far as the Standard is concerned, one is allowed to open a pre-connected unit number and use it. However, when the file associated with the unit is closed, the compiler is not required to re-establish the 'old' pre-connection.
Therefore, best advice is to find out what the pre-connected units are and don't use them. I always choose unit numbers between 10 and 60.
I wouldn't use 7 either as its sometimes pre-connected to the terminal for "error messages", at least in unix and linux.
If you want to be absolutely portable, you can check if a unit number is valid and not pre-connected using INQUIRE. _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|