# GNU fortran help

• Fortran
Hi Everyone.
I'm trying to compile an old Fortran code (~2000 lines) with GNU Fortran and could not make it work yet. The code is from an old book, and I do not know which Fortran compiler was used to make it work. I’m guessing it’s 77 cause in many places the program uses the “common blocks” subprograms.
Here is the portion of the code:

WRITE(15,992) MODEL,MODFHT,ICOMBM,ISAC
992 FORMAT(6X,1H*,4X,'COMBUSTION MODEL =',I8,13X,1H*/
1 6X,1H*,53X,1H*/
2 6X,1H*,4X,'HEAT TRANSFER MODEL =',I8,13X,1H*/
3 6X,1H*,53X,1H*/
4 6X,1H*,4X,'COMBUSTION DURATION MODEL =',I8,13X,1H*/
5 6X,1H*,53X,1H*/
6 6X,1H*,4X,'SPARK ADVANCE ANGLE (DEG) =',I8,13X,1H*/
7 6X,1H*,53X,1H*)

As you can see the format line continues through 7 more lines, and the GNU compiler does not like the continuation line the way it is. If I put an “&” at the end of each line (except the last one) it’ll not work, if I remove the numbering from column 6 it’ll not work either.
In another section of the code, where I define the common blocks if I use an “&” at the end of the line the continuation will work:

COMMON/THERM/DELTAT(5),HFGF(5),HRPF(5),MOLWTF(5),MOLWTP(5), &
P1,P2,P3,P4,T1,T2,T3,T4,T5,T6,TA,TF,TM,TREF,V1,V2,V3,V4

Even three lines:
COMMON/CPCOEF/ACPF(5),ACPO2,ACPN2,AL(5),AH(5),BCPF(5),BCPO2, &
BCPN2,BVL(5),BL(5),BH(5),CVL(5),CL(5),CH(5),CPA, &
CPFU(5),DL(5),DH(5)

Can you please give me an advice on how to tackle this. Any response is greatly appreciated. Thank you.

## Answers and Replies

AlephZero
Homework Helper
This looks like F77, or an earlier version.

If you want to use "free format" code, you need to delete the numbers 1..7 at the start of each continuation ine. Any non-blank character in column 6 meant a continuation line, and using numbers like that was common in the days of punched cards, in case the deck of cards got accidentally shuffled.

The problem might be the "1H" data items. I think this old-style "Hollerith" data for character constants is now obsolete. Try replacing 1H* with the character string '*'.

If this doesn't help, show us exactly what code you tried to compile, and what error message(s) you get.

What errors are you getting? I built and compiled a test case with the following with no problems.

I'm using GFORTRAN (gcc version 4.3.0 20070522 i386-pc-mingw32) on Windows XP. File stored as "F77TEST.for" (hence, fixed format assumed). Compiler switches are -v -O3

Code:
      INTEGER MODEL, MODFHT, ICOMBM, ISAC
MODEL   = 101
MODFHT  = 201
ICOMBM  = 401
ISAC    = 501
C
C
WRITE(6,992) MODEL,MODFHT,ICOMBM,ISAC
992  FORMAT(6X,1H*,4X,'COMBUSTION MODEL =',I8,13X,1H*/
1 6X,1H*,53X,1H*/
2 6X,1H*,4X,'HEAT TRANSFER MODEL =',I8,13X,1H*/
3 6X,1H*,53X,1H*/
4 6X,1H*,4X,'COMBUSTION DURATION MODEL =',I8,13X,1H*/
5 6X,1H*,53X,1H*/
6 6X,1H*,4X,'SPARK ADVANCE ANGLE (DEG) =',I8,13X,1H*/
7 6X,1H*,53X,1H*)

C     Using PAUSE here will generate a warning but still execute
PAUSE
END

Hi AlephZero. Thanks for the quck response. I tried to replace the 1H* with * (character) (only) and '*' (apostrophe character apostrophe) none of those had helped. I'm getting the same gibberish 2 page long error message in CMD. I'm using fort99.zip compiler from here: http://www.cse.yorku.ca/~roumani/fortran/ftn.htm there are a few notes in the bottom of the page about the language, including the "statement continuation" and my code should work acc. to that, but it wont.
TheoMcCloskey. Thanks for the help. I put together the same test case what you did but it did not work. I've gotten ~3 pages of gibberish: missing close parenthese, extra label definition etc.
I would like to use another compiler, which is straightforward and easy to use. I think I'll try the gcc 4.3.0

#### Attachments

• error.txt
9.6 KB · Views: 516
dibloff - The code, as written, should work with any compilier that compilies 77 syntax. But it relies on compiling in fixed-format and the continuation markers (the "1", "2",...) must be in column 6. No other elements in columns 1 through 5 other than line labels and a comment character in column one.

I haven't tried to compile in free format or F90/95 yet but I give a try a little later if I can. Does your compilier offer any command-line switches that can force F77 or fixed-format?

Well, that was quick. I modified the code as below and compiled in free-format (F95). You can see the changes I made but note that I place a comma delimiter between the "1H*" and the trailing carriage control ("/") and after the carriage control. As it turns out, this was unnecessary as gfortran still successfully compiled without these commas as well.

I guess I'm not sure what is going on unless your compiler has some built-in/default assumptions.

Code:
INTEGER MODEL, MODFHT, ICOMBM, ISAC
MODEL   = 101
MODFHT  = 201
ICOMBM  = 401
ISAC    = 501
!
!
WRITE(6,992) MODEL,MODFHT,ICOMBM,ISAC

992  FORMAT(6X,1H*,4X,'COMBUSTION MODEL =',I8,13X,1H*,/, &
6X,1H*,53X,1H*,/,&
6X,1H*,4X,'HEAT TRANSFER MODEL =',I8,13X,1H*,/, &
6X,1H*,53X,1H*,/,&
6X,1H*,4X,'COMBUSTION DURATION MODEL =',I8,13X,1H*,/, &
6X,1H*,53X,1H*,/, &
6X,1H*,4X,'SPARK ADVANCE ANGLE (DEG) =',I8,13X,1H*,/, &
6X,1H*,53X,1H*)

!     Using PAUSE here will generate a warning but still execute
PAUSE
END

TheoMCCloskey. It worked. Thank you so much for your help. I think I need to learn about this free format/non free format thing. A.

SteamKing
Staff Emeritus
Homework Helper
Your code is FORTRAN 66, which predates Fortran 77.

The problem you were having involved placing statements in the proper columns.

For the 992 FORMAT statement, the label, which is 992, must go into columns 1-5.
The key word FORMAT must start on column 7.

If a statement cannot fit on one line, like this format statement, then up to nine additional lines may follow the initial line. At each of the continuation lines, column six must contain an alphanumeric character indicating that this line is a continuation of the line before.

Hi Guys. I’m trying to compile this code from an old book. You can find the book here: http://books.google.com/books?id=xW...=4&sqi=2&ved=0CDwQ6AEwAw#v=onepage&q&f=false" Some pages are missing though, but I’m still thankful for Google for sharing it. I actually own a copy of the book. This program is outlined from p. 163 to p.219. The book actually gives some theory and principles, but I suck understanding the calculation, portion of it. I’m just an engineer who uses it, and not a software developer. I have a job, and doing this in my spare time. My ultimate goal is to see if the program will yield the same results that’s outlined in the book, with the same inputs. I ultimately want to transfer this code to WB, so I can play with it, cause excel seems a more logical environment these days. It would be easy to give it to someone who knows more about programming, but this is ~3000 lines, and I don’t have the financial means to pay for it.
So far I scanned, recognized, and structured some of the portions. My compiler will be able to compile the first two subroutines.
Based on what you said I was able to fix some portions of the “entry write1” but I’m just getting more gibberish now. I realized the further I go the more gibberish I get. I’m at a point where I can’t even ask the right question. It’s nothing like the “basic” I’ve learnt 20 years ago, or “Turbo Pascal” 15 years ago. It looks like Fortran has its own language, syntactic depending on what release, and which compiler, and it makes it real hard to troubleshoot. I think the latest wall I’m facing is the labels. Can I use the same label number in an Entry and Subroutine? Will they be related to their program section only, or will be comprehended as something across the whole program? Here are the latest set of errors.
I’m still really thankful for you guys out there, spending your time and effort helping me. Thank you!

#### Attachments

• Errors_18NO11.txt
2.8 KB · Views: 450
Last edited by a moderator:
AlephZero
Homework Helper
I would guess you have a typo somewhere betwen SUBROUTINE OUTPUT and ENTRY WRITE1.

The ENTRY WRITE1 and ENTRY WRITE2 (later in the code) are "internal" to the SUBROUTINE OUTPUT. You can't compile the part of the code starting with ENTRY WRITE1 on its own.

Your first error message
Code:
gan.for: In program MAIN__':
gan.for:559:
ENTRY WRITE1
^
Statement at (^) invalid in context established by statement at (^)
probably means the compiler didn't find the SUBROUTINE OUTPUT statement and thinks it's compiling the main program. ENTRY statements are illegal in the main program (there is a logical reason for that, but if you don't know Fortran, the explanation why would be rather long)

The following other errors are probably collateral damage from the compiler thinking the ENTRY statement was in the wrong place.

BTW this is a fairly tortured way to write Fortran, but it is legal.

AlephZero. Thanks for the comments. You were right. I added the rest of the program over the weekend, and now it works fine. I can generate the exe file, and run it w/o a problem. One tiny issue is that it’s running with 0 inputs. I still need to figure out how to plug in the input file. I did not find anything in the main program, and I know all four subroutines are using the same inputs (to generate different level calculations). The author of the book (and software) said he purposely left the input file out, so he’ll make us “think”. So I’m thinking now. I’m thinking that I need to dump the input parameters with their assigned values in a managed order into a text file. Then I need to point my main program to read these in. I’ve got these two lines in the main program:
OPEN (UNIT=15,FILE=’OUT.TXT')
! OPEN (UNIT=10,FILE='PRN')
The first one creates a file calls it inside the code “15”, and dumps all the information into it with the print subroutines. As you can see the second line in being interpreted as a comment. The author left the comment on purpose there. I think it is reading in (???) the input file called ‘PRN’ and calls it “10”. So if I create a file in the same folder, and call it PRN – what should be the extension??? In what order should I list my variables in it?
Thank you. A.

jtbell
Mentor
The OPEN statement simply "opens" a file named PRN, and assigns the device number 10 to it. It doesn't actually do any input.

The actual input would be done with statements similar to

Code:
      READ (10, 1234) X, Y, Z
1234  FORMAT ('blah blah blah')

which would read three numbers from the input file into the variables X, Y and Z, according to the format specified in the associated FORMAT statment.

A simpler version would be

Code:
      READ (10, *) X, Y, Z

which would use "default format": all three numbers on one line, separated by spaces. A second READ statement would read from a second line, etc.

didloff - It looks like (to me anyway) that those two OPEN statements are actually associated with output and not input. The "UNIT=" parameter is a 'device unit' assignment that associates an I/O ID number to the file specified by the "FILE=" parameter. The number is used in the READ and WRITE commands to read or write from/to the associated "file".

The second OPEN statement is currently commented out. Note that the file associated with this device is not really a file at all but is a device "PRN" that is associated with the parrallel printer port of the machine. The value "PRN" is a special "file specification" assigned by the computer system that is associated with the parallel printer port of the machine. This was a way where we could send the printed output directly to the printer (via the parallel printer port). Other system file/devices are "CON" (console), "COM1" (serial port 1), "COM2" (serial port 2), etc.

The code is showing its age. This is probably not an advisable method unless you truely have a printer hooked up to your machine via the parallel port and you truely want to go this anguise (I wouldn't). I would recommend you change "PRN" to some other file specification.

I don't have access to the rest of the code so I don't know how these devices (unit 10 and unit 15) are being used in the program. I do see that they are two separate units being used (10 and 15). It was typical practice to comment out the OPEN statement to the printer until we were sure the output file was correct and ready for hard copy. We would then comment out the OPEN for the output file and uncomment the one for the PRN - then run again to print to the printer (this was all before we had reasonable ways to print text files to the printer via other means).

Let me know if I'm off-base with any of this - check to see if 10 or 15 are used for WRITE or READ - I suspect its the former.

Last edited:
jtbell
Mentor
It was typical practice to comment out the OPEN statement to the printer until we were sure the output file was correct and ready for hard copy. We would then comment out the OPEN for the output file and uncomment the one for the PRN

In that case one would expect the two OPEN statements to use the same unit numbers, no? Then there would be a single set of WRITE statements that could be directed to either the file or the printer, by selecting the appropriate OPEN statement.

I'd forgotten about PRN = printer until you brought it up. I think I dimly remember something like that from some version of FORTRAN that I once used.

In that case one would expect the two OPEN statements to use the same unit numbers, no? Then there would be a single set of WRITE statements that could be directed to either the file or the printer, by selecting the appropriate OPEN statement.

jtbell - Yes, that's correct. That's why I'm confused. I saw the file named "OUT.TXT" and it looked suspiciously like an output file spec, but it might be an input file (?). However, I highly suspect the "PRN" to be the parallel printer port. dibloff needs to check to see if those units are being used for READ or WRITE (ie, input or output).

AlephZero
Homework Helper
A statement like
OPEN (UNIT=15,FILE=’OUT.TXT')
is a fairly sloppy way to program.

Really, there should be options in the OPEN statement that say
- Is the file going to be used for input or output
- Is it an error if the file doesn't already exist, or can the program create a new file with that name without telling you
- Is it an error if the file does exist, or can the program just overwrite the previous data in the file without telling you
- etc.

But unless somebody was feeling really perverse when they wrote the code, it's a reasonable guess that a file called OUT.TXT will contain some output from the program, rather than the input.

JtBell and TheoMcCloskey. Makes perfect sense what you’re saying. I tried to create a file in the working directory – prn.txt – but windows won’t let me do it  (a file with the same name already exists, error message). I’m only 35 but I still remember using COM1 and COM2 back in the school. So here’s what I did: I added these to the main program:
OPEN (UNIT=15,FILE='OUT.TXT')
OPEN (UNIT=10,FILE='INPUT.TXT')
So I want to read in, the B,S and RPM in free format (hence I put *) and my input.txt reads as:
B=100
S=100
RPM=1000
And surprisingly it’s not working. It gives me “incomprehensible list input”. Any suggestions please?

Just put all the values on one input line, separated by delimiter, eg,

Code:
100, 100, 1000

Three values for three variables.

To all. I’m finally done with the main part of the code. 2485 line, almost half of which are comment lines. I can compile the code with GNU Fortran (11 and 95 mix-ish), but when I run the exe file it’ll crash (gan.exe has encountered a problem and needs to close. We are sorry for the inconvenience.). If I disable (comment out) the last subroutine it’ll run OK. I’m assuming it’s crashing because right now I’ve got zeros for all my input variables, and it’s probably dividing by zero somewhere. So I hope if I make an input file it’ll run OK. I have 72 input variables to enter. I found a nice code online, where I can dump my variables in this format into my input.txt file:

Code:
!------------------------------------------------------------------------
!     BORE				CYLINDER BORE
456.222
!------------------------------------------------------------------------
!     STROKE				ENGINE STROKE
123
!------------------------------------------------------------------------
And put together a code (based on what I found online), to see it if would work:

Code:
	program Input
implicit none
real B, S
OPEN (UNIT=10,FILE='input.txt')
100	continue
read(unit=10, fmt='(/)', err=998, end=999)
read(unit=10, fmt=*,     err=998, end=999) B
read(unit=10, fmt='(/)', err=998, end=999)
read(unit=10, fmt=*,     err=998, end=999) S
print*, B, S
goto 100
998	stop ' error reading input file '
999	stop ' end of input file '
end`
Now the trouble that this runs @ my work computer, but not @ home. I spent the whole thanksgiving weekend finding out why. I really do not understand the fmt=’(/)’ part. I could not find any reference to this online. Any ideas why would this run on one WS (64 bit, XP both of them) and would not run on another one? Also any other ideas about how to make a well structured input file for 72 input parameters? Thank you. A.

Gave up on the input file. Started to put the direct inputs (A=const) into the main program. It did not run. Then I tried to put it into the first subroutine – all 72 inputs. Then I realized that some of the inputs are vectors (array). If I put a single value it works, but if I declare it as an array it won’t work, only if it’s being declared in the subroutine that’s using it… I’m about to give up.

Hi Everyone,
i'm using gfortran 95. i'm not getting a proper output for COMPLEMENT ( NOT(I) Operand ). it was showing that, for not(1) = - 2, not(5) = - 6, not(125) = - 126........ can you please tell me the proper operand used for complement operation...

program bitmanipulate
integer n1,n2

write(*,*) 'Enter the value'
n2=not(n1)
write(*,*) n2

end

THANK YOU

Hi Everyone,
i'm using gfortran 95. i'm not getting a proper output for COMPLEMENT ( NOT(I) Operand ). it was showing that, for not(1) = - 2, not(5) = - 6, not(125) = - 126........ can you please tell me the proper operand used for complement operation...

program bitmanipulate
integer n1,n2

write(*,*) 'Enter the value'
n2=not(n1)
write(*,*) n2

end

THANK YOU

Hi Everyone,
i'm using gfortran 95. can you please tell, is there any operation(Operator) for Compare & masking two arrays and arrays extraction ?

THANK YOU