Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Very old .FOR Compile question

GWats1
New Contributor I
5,091 Views

I'm trying to Compile a 1980's Fortran Code a friend wrote and having trouble with entering a filename. He opens unit 1 as 'CON'  with this statement: OPEN (1,FILE='CON')  and does some error checking. I'm thinking he meant CONSOLE 

 

I'm trying to compile as an x86 in Visual Studio and eventually I wanted to add Fortan_WinPrint and maybe try to figure out how to use GetOpenFileName to let the user pick a filename instead of having to type a name at a DOS prompt.

 

I got it to compile but when I try to type in the filename, I get an error that it can't read or something.

 

The ancient FOR file is attached and I commented out all the old JCL commands. 

 

 compile_error.jpg 

Labels (2)
0 Kudos
1 Solution
Arjen_Markus
Honored Contributor I
5,059 Views

"CON" is one of the magic file names under MS DOS. Others are "PRN" and "NUL". And there were a few more, if I am not mistaken. "CON" is indeed the console. It is much better to write that as "READ(*,'(A)') FLNAME".

Oh, the code also uses control characters that will not work anymore, a "+" in the first column. It used to work specifically on printers.

View solution in original post

34 Replies
Arjen_Markus
Honored Contributor I
5,060 Views

"CON" is one of the magic file names under MS DOS. Others are "PRN" and "NUL". And there were a few more, if I am not mistaken. "CON" is indeed the console. It is much better to write that as "READ(*,'(A)') FLNAME".

Oh, the code also uses control characters that will not work anymore, a "+" in the first column. It used to work specifically on printers.

GWats1
New Contributor I
3,676 Views

Hello Arjen;

I'll try it out and see. He gave me the input file name and I'm not sure if I input it as "D:\infile.dsp" because it was giving the error no matter what I tried. 

0 Kudos
mecej4
Honored Contributor III
3,697 Views

CON is a device file name in MSDOS, associated with the console. Other devices are COM1, COM2, COM3, COM4, PRN, AUX, LPT, NUL, etc., as you can see listed in the article https://en.wikipedia.org/wiki/Device_file . Note that PRN stands for the printer device, which may or may not exist as a physical device on your system.

I suggest that you change your program to use the unit "number" * in your READ statements, instead of the unit number 1 connected to the console.

jimdempseyatthecove
Honored Contributor III
3,689 Views

The pointing arrow on the left bar usually points to the return address on the call stack from where the error occurred. This would indicate that the preceding WRITE statement encountered the error.

 

There had been recent issues reported regarding improperly parsing tokens within comment lines. This may be another case of this.

As a verification, try removing the continuation line by collapsing it into the WRITE statement:

29     WRITE (*,'(A)') 'ENTER: INPUT FILE NAME        ------>'

 

Jim Dempsey

0 Kudos
GWats1
New Contributor I
3,670 Views

I tried putting the WRITE on one line and still get the error in the READ about Buffer Too Small.  I tried making FLNAME*40 (from *20) and it still gets the same error.

 

 

 

compile_error1.jpg

 

compile_error2.jpg

0 Kudos
jimdempseyatthecove
Honored Contributor III
3,655 Views

Let's do some debugging.

Place a break point on the READ following  the 29 write.

1) What does the debugger indicate the length of FLNAME? Is it the 40 you set or a smaller number?

2) Regardless of what it says, place a break point on the following line (INQUIRE), and perform a Continue

3) enter XYZ for a file name (not the desired file name). This name is shorter and identifialable.

4) Do you get the error or do you reach the break point?

5) If at break point, do you see the XYZ?

6) if you see the XYZ, Right-Mouse Click on the READ line (one line back), and select "Set Next Statement"

7) Continue

8-RightParn Enter the file name you desire without the D-colon

9) does that succeed or fail?

10) If succeeds, does FILNAME have what you typed in?

11) if succeeds, repeat steps 6, 7 but this time enter the file name with the

 

What we are hunting for is what is causing the error to manifest. Sometimes what you see in the code is not what the compiler sees in the code. For example:

a) If your code is not using IMPLICIT NONE at the top of the procedure, and,

b) FLNAME is not declared in the scope of the procedure, then

c) FLNAME is implicitly a REAL variable

Note, in step 1) above the debugger would have shown FLNAME as a REAL not CHARACTER

 

Jim Dempsey

jimdempseyatthecove
Honored Contributor III
3,653 Views

This stupid form messaging system is replacing 8-Right Parn with nothing and removing D colon.

It must think I am using smiley faces, and trashing the text

Jim Dempsey

0 Kudos
GWats1
New Contributor I
3,641 Views

I'm not real familiar with the debugging stuff but managed to put a Breakpoint on the READ. The Value of FLNAME is '     ' and it is a Character(20) This is just before the Read. BTW, the FLNAME is defined at the beginning of the Program.  Here is a piece of the revised Code where I made FLNAME as 20.

PROGRAM DPA
USE Fortran_WinPrint
DIMENSION SAVE(200), PSF(200), IT(15)
CHARACTER IANS*5, IDT*8, TITLE*60,FLNAME*20,BUF*10
LOGICAL EXX
INTEGER TYPE(20), PYSTA(31)
REAL MT, MOM
COMMON /BK1/ TITLE
COMMON /RANGE/ IRANGE,INCR,THICKNESS,E,EI,IPIPE
COMMON /LOADS/ ILOADS,KD
COMMON /BK3/ MT, HT, VT,IPROB, DEPTH, DIAM, CAP, Z(20), C(20),
1DENSE(20), E50(20), PHI(20), H2O, NUMST, IU8, TYPE,IDT
COMMON /BK4/ IEND
100 FORMAT (' PROGRAM TERMINATED - DEPTH OR DIAMETER = 0')
102 FORMAT ('00001 DPA - BEAMCOL 28 VERSION - IBM 2.4',/
1,'00002 ',A60, /
1,'00003 LATERALLY LOADED DRILLED SHAFT FOUNDATIONS')
103 FORMAT(I2.2, '000 1 H=', F6.1, ' D=', F4.1, ' CAP=', F4.1,1P,
1' MT=', E10.3, ' HT=', E10.3, ' VT=', E10.3)
104 FORMAT(I2.2, '200', I5, T21, F4.0, T31, '100.0', T41,F5.3)
105 FORMAT (I2.2, '401', T31, 1P, E10.3, T51, E10.3)
106 FORMAT (I2.2, '402', T20, '1', 1PE10.3, T71, 1PE10.3)
107 FORMAT (I2.2, '403', T11, I5, T21, 1PE10.3)
108 FORMAT ('00001 DPA - BEAMCOL 28 VERSION - IBM 2.4',/
1,'00002 ',A60, /
1,'00003 STEEL PIPE PILE FOUNDATION, WALL THICKNESS = ',
1 F8.5,' IN.')
120 FORMAT (//////,15X,35('*'),//,19X,'DPA BY MARK S. JOHNSON',
1 /,17X,'WINDOWS VERSION 1.0 - MAR 2023'
1//,15X,(35('*')),///,
1T20,'SOIL TYPES DEFAULTS = *', //
1T20,'TYPE 0 - DEFAULT', /
1T20,'TYPE 1 - SOFT CLAY', /
1T20,'TYPE 2 - STIFF CLAY', /
1T18,'* TYPE 3 - SAND BELOW THE WATER TABLE', /
1T20,'TYPE 4 - STIFF CLAY BELOW THE WATER TABLE', /
1T20,'TYPE 5 - PADLL',/,
1T18,'* TYPE 6 - CLAY82 - OCT. 1982 ASCE',/,
1T20,'TYPE 7 - CLAY79 - AUG. 1979 ASCE',///)
121 FORMAT (A5,A60)
122 FORMAT (I2.2, '100', 15I5)
IDT = ' '
C OPEN (1,FILE='CON')
C WRITE (*,123) CHAR(27),'[33;44m',CHAR(27),'[2J'
123 FORMAT (1X,4A)
WRITE (*,120)
C---INITIAILIZE VALUES
29 WRITE (*,'(A)')' ENTER: INPUT FILE NAME ---->'
READ (*,'(A)') FLNAME
INQUIRE (FILE=FLNAME,EXIST=EXX)

IF (EXX) THEN
OPEN (8,FILE=FLNAME,STATUS='OLD')
ELSE
WRITE (*,'(3A)') ' FILE --',FLNAME,'-- NOT FOUND -->TRY AGAIN'
GO TO 29
ENDIF

 

The window at the bottomThe window at the bottom

 

As soon as I put anything at the prompt and hit enter, it errors out.  Another question on his choice of Variable names. He used SAVE as a real variable array and he used TYPE as an Integer Array but the Visual Studio makes the letters Blue so I assume that are reserved and I might need to change them. Would this cause the read error?

 

0 Kudos
GWats1
New Contributor I
3,640 Views

Here is the newer version of the FOR code

0 Kudos
GWats1
New Contributor I
3,618 Views

I found a newer version of the .FOR code which had been updated a little to run in Win7. Someone changed the Open 1 to READ (*,'(A)') FLNAME. I was getting the same error as before, so I made FLNAME = 'D:infile.dsp' and it got past that but errored out when it tried to READ the next filename. I set a Breakpoint and FLNAME is correct.

 

I did find an EXE that someone compiled in 2015 for Win7 and it reads the test file fine.

 

I'm just wondering if I have the general solution parameters correct?

 

compile_error4.jpg

0 Kudos
mfinnis
New Contributor II
3,609 Views

You haven't said what version of the compiler and Visual Studio you are using. How did you create the project that you are building?

Using Visual Studio Community 2017 Version 15.9.52 with Intel Fortran Compiler Intel Fortran Compiler Classic 2021.7.0 I created an empty console project and added your original source file DPA4.FOR. It built and ran to the filename entry without error and responded
"FILE --filename -- NOT FOUND ---> PLEASE TRY AGAIN" when I entered the text filename.

0 Kudos
GWats1
New Contributor I
3,596 Views
I'm on the bus home and the pc is back at work but I'm using VS17 and don't remember the Fortran version. I'll have to check in the morning if I remember how.
0 Kudos
GWats1
New Contributor I
3,551 Views

I'm running Win10 on a HP ZBook 17 G5 with a Xeon CPU at 2.9GHz and 32GB ram.

I attached the input file I am testing but had to rename it as a .TXT to post it below. It looks like my Fortran version is 19.1 and I don't remember installing it recently. (our Draconian IT folks don't allow users Admin rights)

 

iFort_version.jpg

0 Kudos
mecej4
Honored Contributor III
3,529 Views

Your program in DPA4R1.FOR attempts to use unit 5 for input and output. By default, unit 5 is used for standard input and unit 6 for standard output. When your program connects unit 5 to an external file, from that point onward the connection to the console is lost. Similarly, you cannot write to unit 5 when that unit is connected to standard input.

The program attempts to open the special (device) file PRN as an external file. Change the file name to , say, PRNFILE .

Fix the messy situation in your source file regarding unit numbers. It is best to use unit numbers of 10 and higher for connecting to external files.

0 Kudos
GWats1
New Contributor I
3,509 Views

Hi mecej4;

I changed the read and write from Unit=5 to Unit 15 and changed the PRN to PRNFILE and recompiled with the Use Fortran_winprint commented out and removed from the solution and still get the error. 

 

I still have the x86 but tried the x64 with the same result. I think I've got VS22 installed and might try that to see if it makes any difference.

0 Kudos
jimdempseyatthecove
Honored Contributor III
3,606 Views

x86 is ok, though you might want to create/use x64.

I had to comment out USE Fortran_WinPrint to get it to compile.

I also took the C off of the READ to test your initial problem.

The read works on my system (using x86) when inputting D:INFILE.DSP

Not sure what the issue is on your end. Not having the data file(s) that is about as far as I can go.

 

The variables SAVE and TYPE I left alone, so that is not the issue. I would change them to avoid confusion.

Perhaps SAVEDATA and TYPECODE

SaveData and TypeCode would read easier, though the compiler is not case sensitive.

 

Jim Dempsey

 

0 Kudos
GWats1
New Contributor I
3,593 Views
0 Kudos
jimdempseyatthecove
Honored Contributor III
3,552 Views

Try commenting out the USE Fortran_WinPrint

I commented that out here (as I do not have it) and the program made it through the READ from console.

It may be that something in the .obj files in its .lib (and/or .dll) are replacing the default console I/O routines, and that is what is causing the error to surface.

Jim Dempsey

 

0 Kudos
GWats1
New Contributor I
3,525 Views

Hi Jim; and thanks for the help.

I commented out the Fortran_WinPrint statement (a very nice routine to select the windows printer) and I even removed it from the solution. I Built the EXE and it still gets that odd error. I tried x86 and x64 and both fail. The message says to see the Visual C++ docs but I'm wondering why it is a C++ problem since I'm using the Fortran compiler.

Anyway, the value of FLNAME is '          ' just before the read and as soon as I type the D:\INFILE.DSP and hit the enter key, the program stops with that odd error.

 

GWats1_0-1678886201137.png

 

0 Kudos
jimdempseyatthecove
Honored Contributor III
3,526 Views

It runs up to the point where it asks for 

+ENTER: BEAMCOL INPUT FILE NAME (PYCURVES.TXT)-->

And there are other files (TAPE7.TXT, etc...)

jimdempseyatthecove_0-1678886143040.png

My MS VS is 2019, but I do not think that is the issue.  I suspect it is the module Fortran_WinPrint that is causing your problem.

My version of Fortran came from a different distribution kit, but it has the same year, but slightly older revision number. I do not think this would cause the problem. Comment out the USE Fortran_WinPrint and see what happens.

 

Jim Dempsey

0 Kudos
Reply