Hello,
I;m a new user of Fortran 77 and I'm trying to write a subroutine
where i have to read a bunch of data from an input database file. I
have written code, but when i try to write those values in a file as
a check i get the error saying that the Output file Unit already
exists. i have double checked everything, but still keep getting the
same error. Please help where i'm going wrong. I have pasted my code
and a sample of the input file.
--------------------------------------------------------------
c
c
c
PROGRAM WIMTRUCK
c
Real s(12),w(13)
CHARACTER*46 dfirst
Character Input*80
Character InputV*30,TestoutputV*30
Integer LengthLine
c
c
c PROMPT USER FOR INPUT FILE NAME
c
Write(*,10)
10 FORMAT (1X, 'Enter input file name:'
+ /'(Liger_xxx_xxx.txt file)- must be at least 6 char.')
READ (*,'(A)') Input
Print*,
CC
CC
CC BASED ON INPUT VALUE, OUTPUT FILE WILL BE AUTOMATICALLY NAMED
C
LengthLine=Len(Input)
InputV = Input(6:LengthLine)
TestoutputV= 'Testoutput'//InputV
c OPEN INPUT FILE(Liger_xxx_yyy.txt)
OPEN (UNIT=9,FILE=Input,status='old')
c OPEN OUTPUT FILE (Testoutput_xxx_yyy.txt)
OPEN (UNIT=17,FILE=TestoutputV,status='new')
DO 115 i=0,300000
READ(9,2200,end=900) dfirst,ispeed,dgvw,dlength,ilngth,inaxle,
+ w(1),w(2),w(3),w(4),w(5),w(6),w(7),w(8),w(9),w(10),w(11),
+ w(12),w(13),
+ s(1),s(2),s(3),s(4),s(5),s(6),s(7),s(8),s(9),s(10),s(11),
+ s(12), iTruckN
2200 FORMAT(A45,I2,2X,F5.1,2X,F5.1,6X,I3,3X,I2,11X,13(1X,F4.1),122X,
+ F4.1),2X,I6)
c
WRITE (17,221) dfirst,ispeed,dgvw,dlength,ilngth,inaxle,w(1),
+ w(2),w(3),w(4),w(5),w(6),w(7),w(8),w(9),w(10),w(11),
+ w(12),w(13),
+ s(1),s(2),s(3),s(4),s(5),s(6),s(7),s(8),s(9),s(10),s(11),
+ s(12),iTruckN
221 Format(A45,I2,2X,F5.1,2X,F5.1,6X,I3,3X,I2,11X,13(1X,F4.1),
+ 12(2X,F4.1),2X,I6)
c
115 Continue
900 Continue
STOP
END
-------------------------------------------------------------------
Input file name is Liger_WBNB_July05.txt
Input headers:
DATE TIME YEAR TYPELANE SPEED GVW SumLen
LENGTH NO. ESAL AXL1 AXL2 AXL3 AXL4 AXL5 AXL6
AXL7 AXL8 AXL9 AX10 AX11 AX12 AX13 SPC1 SPC2
SPC3 SPC4 SPC5 SPC6 SPC7 SPC8 SPC9 SP10 SP11
SP12 Truck #
respective values:( 3 input lines in a .txt file)
Fri Jul 01 00:01:01.20 2005 11 1 60 73.8
59.9 69 5 2.923 11.2 15.7 15.4 15.5 16.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 20.2
4.3 31.2 4.2 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 1
Fri Jul 01 00:01:26.34 2005 11 1 60 80.1 59.5
68 5 3.984 12.5 16.3 16.1 17.1 18.1 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 18.3 4.4 32.6 4.2 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 2
Fri Jul 01 00:02:06.02 2005 11 1 59 53.3 68.0
75 5 0.928 12.1 12.4 12.4 7.7 8.7 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 24.0 4.4 35.6 4.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 3
and this is the error i keep getting:
? Fortran Runtime Errors
? Status 'New" specified for an existing file
? Open <Unit=17.....
no matter what unit number i specify, i keep getting the same error.
I know this is really confusing. but if someone can please look at
the code and let me know where i'm going wrong, i would really
appreciate it. This is for my thesis defense which is next month and
I'm running out of time. I just want to make sure that the Read
statement is reading the input file in the format specified.
Thanks a lot
-Aruna