- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have an input file, which contains the following information:
10 ! Index of a 3D array, containing some information let's say the number of a composite laminate
6 ! Number of plies
[90/45/0]s! A string used for a subroutine, which creates a selection menu.
90.
45.
0.
0.
45.
90. ! The number of plyes orientations in degree.
The latter block is repeated 10 times until EOF is found.
I wrote the following subroutine, but I got a runtime error everytime with INTEL FORTRAN.
This code was running without problems on a VAX machine many years ago when I was at University.
Thanks for the help.
Gianfranco
C-------------------------------------------------------------------------------
SUBROUTINE CHOLAM(N,THEAT,LAMCHO)
C-------------------------------------------------------------------------------
C
DOUBLE PRECISION THEAT(40),THEATA(20,40)
CHARACTER*30 LAMCHO,LAMTYP(40)
INTEGER CHOICE,NPLYS(20),NLAMS
C
OPEN(UNIT=100,FILE='test.dat',ACCESS='SEQUENTIAL')
READ(50,30)NLAMS
WRITE(100,30)NLAMS
C
DO 200 J=1,NLAMS
READ(50,30)NPLYS(J)
30 FORMAT(I2/)
DO 100 I=1,NPLYS(J)+1
IF(I.EQ.1) THEN
READ(50,10)LAMTYP(J)
10 FORMAT(A30/)
ELSE
READ(50,20)THEATA(J,I-1)
20 FORMAT(F6.2/)
ENDIF
100 CONTINUE
200 CONTINUE
C
WRITE(*,*)"Enter # of laminate/ply choice..."
DO 300 J=1,NLAMS
WRITE(*,250)J,LAMTYP(J)
250 FORMAT(I3,': ',A30)
300 CONTINUE
C
READ(*,*)CHOICE
N=NPLYS(CHOICE)
LAMCHO=LAMTYP(CHOICE)
C
DO 400 K=1,N
THEAT(K)=THEATA(CHOICE,K)
400 CONTINUE
C
CLOSE(100)
RETURN
END
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
However, Jim is also correct that the data file doesn't follow the pattern.
Here's a version of the code fwith the slash problem fixed.
[fortran]DOUBLE PRECISION THEAT(40),THEATA(20,40) CHARACTER*30 LAMCHO,LAMTYP(40) INTEGER CHOICE,NPLYS(20),NLAMS OPEN(UNIT=100,FILE='test.dat',ACCESS='SEQUENTIAL') READ(50,*)NLAMS WRITE(100,30)NLAMS DO 200 J=1,NLAMS READ(50,30)NPLYS(J) 30 FORMAT(/I2) DO 100 I=1,NPLYS(J)+1 IF(I.EQ.1) THEN READ(50,10)LAMTYP(J) 10 FORMAT(A30) ELSE READ(50,20)THEATA(J,I-1) 20 FORMAT(F6.2) ENDIF 100 CONTINUE 200 CONTINUE WRITE(*,*)"Enter # of laminate/ply choice..." DO 300 J=1,NLAMS WRITE(*,250)J,LAMTYP(J) 250 FORMAT(I3,': ',A30) 300 CONTINUE READ(*,*)CHOICE N=NPLYS(CHOICE) LAMCHO=LAMTYP(CHOICE) DO 400 K=1,N THEAT(K)=THEATA(CHOICE,K) 400 CONTINUE CLOSE(100) END[/fortran]
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Without the actual input file it is impossible to reproduce the error - adding that might help as well
to diagnose the problem.
Regards,
Arjen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The format seem to follow
n
[text]
data-1
data-2
...
data-n
m
[other text]
data-1
...
data-m
However, in reading the file, it does not follow this pattern
GIGO
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
However, Jim is also correct that the data file doesn't follow the pattern.
Here's a version of the code fwith the slash problem fixed.
[fortran]DOUBLE PRECISION THEAT(40),THEATA(20,40) CHARACTER*30 LAMCHO,LAMTYP(40) INTEGER CHOICE,NPLYS(20),NLAMS OPEN(UNIT=100,FILE='test.dat',ACCESS='SEQUENTIAL') READ(50,*)NLAMS WRITE(100,30)NLAMS DO 200 J=1,NLAMS READ(50,30)NPLYS(J) 30 FORMAT(/I2) DO 100 I=1,NPLYS(J)+1 IF(I.EQ.1) THEN READ(50,10)LAMTYP(J) 10 FORMAT(A30) ELSE READ(50,20)THEATA(J,I-1) 20 FORMAT(F6.2) ENDIF 100 CONTINUE 200 CONTINUE WRITE(*,*)"Enter # of laminate/ply choice..." DO 300 J=1,NLAMS WRITE(*,250)J,LAMTYP(J) 250 FORMAT(I3,': ',A30) 300 CONTINUE READ(*,*)CHOICE N=NPLYS(CHOICE) LAMCHO=LAMTYP(CHOICE) DO 400 K=1,N THEAT(K)=THEATA(CHOICE,K) 400 CONTINUE CLOSE(100) END[/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Anyway thanks for your time and assistance.
Cheers,
Gianfranco
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks for having spotted the mistake in the file. I later realized that the blank lines weren't existing in theoriginal input file. One of my students added for a better readability, but the code wasn't written to handle them. I was lucky I had the possibility to restore an old backup and inspect the files. Moreover, the file was in UNIX format instead ofa DOS one.
Cheers,
Gianfranco Iasiello
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Maybe they had an adversion to the number 5 too and replaced it with a 6 ;)
The blank line parsing and/or embedded comment parsing is relatively easy to code. If it makes reading your input file easier then consider adding it back. Data format becomes:
[blank] (any number of blank lines)
[! comment] (comingled with any number of comments)
[C comment if you wish]
n
"[your tag here]" (required tag)
data-1
...
data-n
((repeat above until done))
You only need one section to parse the blank and comment lines and that is where you obtain the datacount.
Also note that you can code your data as
n
"[your tag here]"
data-1 ! X (embed comment with data)
data-2 ! Y
The comments will slow down the input read a bit but I would think you would only comment parameter files and not a multi-gigabyte input stream.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Direct Access Formatted Read Error
Hi, I need help in figuring out why my read statement for formatted direct access statement does not work with Intel Fortran. It worked without any problem with Visual Fortran 2005 and Compaq Fortran.
The program listing is as follows:
1 Program TestLPIntfDll
2
3 C
4 c INCLUDE 'GEPARM.FOR'
5 INCLUDE 'GEBLK1.FOR'
6 c INCLUDE 'GEBLK2.FOR'
7
14 CHARACTER(LEN=100) :: FILEPATH
15 CHARACTER(LEN=80) ::CBLOCK
16 CHARACTER(LEN=20) :: FLNAME
17 INTEGER*2 :: NROWS, NCOLS
18
19
20 FLNAME="LPTEST1.DAT"
21
22 OFFLUN=20
23 DBGLUN=25
24 DATPRT=30
25 LUNPRT=35
26 IRDWR=1
27
28 FILEPATH="G:\oms-Development\Version-VB6\Interfaces\" //
29 1 "omsLPIntf\Input\LPTEST1.DAT"
30
31
32 OPEN (UNIT=20, FILE=FILEPATH, STATUS='OLD',
33 1 ACCESS='DIRECT',RECL=80, FORM='FORMATTED',
34 2 ERR=80, IOSTAT=IOS)
35
36 Open (UNIT=25,file='C:\OMSLLC\DEBUG-' //
37 1 FLNAME,STATUS='REPLACE')
38
39 Open (UNIT=30,file='C:\OMSLLC\INPUT-DATA-' //
40 1 FLNAME,STATUS='REPLACE')
41
42 Open (UNIT=35,file='C:\OMSLLC\LP-MATRIX-SOLN-' //
43 1 FLNAME,STATUS='REPLACE')
44
45 WRITE (25,800) FILEPATH
46 800 FORMAT(A80)
47
48 C 0. LP PROBLEM RUN IDENTIFICATION TITLE
49 *
50 DO 5 IRC = 1,3
51 READ (20,FMT=990,REC=IRC,ERR=80) TITLE(IRC)
52 WRITE (30,FMT=990,ADVANCE='NO') TITLE(IRC)
53 5 CONTINUE
54 *
55 DO 51 IRC = 4,6
56 READ (20,FMT=990,REC=IRC,ERR=80) CBLOCK
57 WRITE (30,FMT=990,ADVANCE='NO') CBLOCK
58 51 CONTINUE
59
60 !6 IRC = 6
61 *
62 *---- 1. GENERAL FIXED LP PARAMETERS
63 *
Page 2 Source Listing TESTLPINTFDLL
2014-11-02 20:43 TestLPIntfDll.FOR
64 C IRC = IRC +1
65 READ (20, FMT=1000,REC=IRC,ERR=80) NROWS
66 READ (20, FMT=1000,REC=IRC+1,ERR=80) NCOLS
67 READ (20, FMT=1000,REC=IRC+2,ERR=80) NFXMCF
68 C
69 WRITE (25,6002) NROWS, NCOLS, NFXMCF
70
71 80 CONTINUE
72 WRITE (25,1050,ADVANCE='NO') FLNAME, IRC
73 *
74 *---- FORMAT STATTEMENTS
75 *
76 990 FORMAT (A72)
77 1000 FORMAT (56X,I3)
78 1050 FORMAT (/1X,' GEDATA ERROR - IN READING FILE ',A20,' AT RECORD',
79 1' NUMBER ',I3)
80 6002 FORMAT (2X,3I3)
81
82 CLOSE(20)
83 CLOSE(25)
84 CLOSE(30)
85 CLOSE(35)
86
87 !CLOSE(OFFLUN)
88 !CLOSE(DBGLUN)
89 !CLOSE(LUNPRT)
90
91 END
The input file is fixed columns data as follows:
*TITLE LP TEST CASE -1
*TITLE SMALL REFINERY WITH REFORMER AND CRACKER
*TITLE
*
****************************** FIXED LP DATA ***************************
*
NUMBER OF ROWS = 3
NUMBER OF VARIABLES = 5
NUMBER OF FIXED MATRIX COEFFS = 9
*** ROW NAMES AND RIGHT HAND SIDES ***
³ROWNAM³ ³-- RHS --³
PIPESTIL 1000.00
REFORMER 480.00
CRACKER 640.00
*** VARIABLE NAMES, LOWER / UPPER BOUNDS AND COSTS ***
³VARNAM³ ³ LOW BNDS ³³ UPP BNDS ³³- COST -³³- SOLN -³³VARSTA³
LIGHTCRD 0.00 1000.00 -0.6000 700.00 2
HEAVYCRD 0.00 1000.00 -0.5000 300.00 2
PSSLACK 0.00 1000.00 0.0000 0.00 1
RFSLACK 0.00 480.00 0.0000 0.00 1
CRSLACK 0.00 640.00 0.0000 0.00 1
*** FIXED MATRIX COEFFICIENTS ***
³ROWNAM³ ³VARNAM³ ³FIXD COEFF³
PIPESTIL LIGHTCRD 1.0000
PIPESTIL HEAVYCRD 1.0000
PIPESTIL PSSLACK 1.0000
REFORMER LIGHTCRD 0.6000
REFORMER HEAVYCRD 0.2000
REFORMER RFSLACK 1.0000
CRACKER LIGHTCRD 0.4000
CRACKER HEAVYCRD 0.8000
CRACKER CRSLACK 1.0000
*** END OF FILE ***
and I get error for record no 7 as follows:
G:\oms-Development\Version-VB6\Interfaces\omsLPIntf\Input\LPTEST1.DAT
GEDATA ERROR - IN READING FILE LPTEST1.DAT AT RECORD NUMBER 7
I can not figure out. I am sure it must be simple as I may have not specified some new option or parameter in the formatted read statement.
Any suggestion would be appreciated.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following items prevent one from running the program to make a diagnosis: 1) the include file(s) are not provided; 2) the program source and, even more importantly, the direct access data file, were posted as text inside the message; please provide files as attachments combined into a zip-file, and state the compiler version, platform, and compiler options used.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You read 3 lines for the title.
You read 3 lines for CBLOCK
You assign 6 to IRC
You have commented out the increment of IRC (line 64)
Therefore:
You are reading record number 6 for IROWS. Which according to my eyes and counting the lines in the input file is an asterix. Which means NROWS will be zero.
You then read NCOLS (record 7) and then NFXMCF (record 8)
According to the code the format for reading number of rows, columns and matrix coefficients is (56x,i3)
Are you sure that there are 53 characters and 2 spaces before the numbers? (I haven't counted.)
Are there tabs in the data file?
<edit>
Another thought. You specify a record length of 80 - presumably bytes. Could your settings be: record length is specified in words ( a record would then be 80 * word length)?
</edit>
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are reading record number 6 for IROWS.Not quite. The error is not in the value of IROWS, if you note that the code uses the property of DO loops that the index variable has the value that it had when the the DO iteration test failed -- in this case, 7. The problem is that the code reads a direct access file, and traps I/O errors by including ERR= and IOSTAT= clauses, but does nothing to check the errors returned, nor is the data file itself provided. The representation used for direct access files can vary from compiler to compiler on an operating system that does not have native record files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Check Les's suggestion about hidden tab characters.
Some of "modern" editors of the last 20 years have (had) the nasty habit of inserting Tab characters for indentation thus making the columns as viewed on screen not at the actual column as read by READ.
If your editor has an option to view tabs, then turn it on when editing Fortran formatted data files.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
mecej4 wrote:
Quote:
You are reading record number 6 for IROWS.Not quite. The error is not in the value of IROWS, if you note that the code uses the property of DO loops that the index variable has the value that it had when the the DO iteration test failed -- in this case, 7. The problem is that the code reads a direct access file, and traps I/O errors by including ERR= and IOSTAT= clauses, but does nothing to check the errors returned, nor is the data file itself provided. The representation used for direct access files can vary from compiler to compiler on an operating system that does not have native record files.
Ah you are correct, I totally missed the "!" at the beginning of line 60 (Other comments use "C")
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I suggest, as a diagnostic aid, temporarily removing the ERR= clauses from the READ statements and seeing what the complete error message is. I will also comment that providing a source listing file is not conducive to analysis, as it makes it difficult for us to build and run the program. (Of course it doesn't help that the include files are not provided.) For us to best help you, please provide a ZIP containing all the source files, the project and solution files, and the data file(s) so that we can build and run the program.
I am not sure what you mean by "Visual Fortran 2005", but I'll assume you mean some version of Intel Visual Fortran working in Visual Studio 2005.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi All,
I have enclosed all files related to this problem. I tried Steve's suggestion of removing ERR=80 and it gave the same message. The pgm reads 1-6 records as A80 and it is OK. It gives problem only in record=> where it supposed to skip 56 Characters and then read number in I3 format in columns 57-59.
The data file was created in fixed column format without using tabs.
I appreciate all your help in figuring out the problem with this File I/O program.
Also, it worked in Compaq fortran in VS 2005. Now, I am upgrading both compiler and the software system, it errors out.
I am sure in the end it may be a simple fix.
Thanks again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In your project file you have VMS Compatibility set True.
From the help:
" The -vms option affects the record length for direct access and relative organization files.
The buffer size is increased by 1 to accommodate the deleted record character."
Remove this option.
If this is the actual program you are working with then I would suggest that you do not need direct access for the data file at all.
Just read the data sequentially.
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Les,
Thanks, It worked.
However VMS option was selected to use /LIST option in the include statement and that VMS option nullified the direct access file record length.
So, I moved to sequential format and it worked. There was actually no reason to use direct access and whatever it was could be accomplished with sequential file access method.
Thanks Again for your help
Suresh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I might suggest removing the /VMS option and /LIST and adding /show=include to the compiler options to get the effect you want.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page