Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fortran newbie, simple loop question, continues everywhere!

Status
Not open for further replies.

AndersO

Programmer
Jan 9, 2004
5
SE
I'm about to convert a Fortran77 program to C and have encounter a code snippet something like this:

DIMENSION TMP(5)
DO 10 K=1, 5
10 TMP(K)=0
CALL FUNC
20 CONTINUE

STOP
END

SUBROUTINE FUNC
WRITE (*,*)'Just a test'
RETURN
END

Whats the deal with that continue?.. There is no reference to label 20 anywhere in the program, first I thought there was some nested DO loop I've missed (This snippet is just part of a bigger program ofcourse), I've rechecked this a couple of times.. Func gets called only once too..

I've come to the conclusion that that continue is just some leftover from some old loop that was removed, but the continue was forgotten or something. Or is there some reason why one should put continues here and there in a program? :)
 
If label 20 is true unreferenced in the module, forget this continue stmt...
The Good Old FORTRAN liked labels...
 
You could comment out the CONTINUE statement, then recompile the program and see if it complains.

You could do wonderfully incomprehensible things with F77 like calling subroutines with alternative return addresses in the parameter list....

That one might be a joy to find.

rgds
Zeit.
 
Ok, as I suspected then.. I haven't completly finished the conversion so it wont compile yet.

Thanks!
 
Sorry.

I meant that you should recompile the Fortran source not your C code.

Unless you don't have a F77 compiler anymore....

I think that the 20 CONTINUE statement is very probably completely redundant, but it might pay you to check...

rgds
Zeit.
 
Oups.. I realize that now. But the Fortran code is on paper in a book!, after emailing the author I now know the continue has no meaning.

However, I downloaded a free fortran77 compiler and I'm going to write it down. Like an reference to the conversion.

And immediatly I stumble on another (newbie I guess) problem, source code line length limits.. In the book, if the line is longer than a certain characters, it is breaked down into more lines, and those lines begins with a number. But I dont get that to work with the compiler that I have. (watcom)

Hmm, this must be in some faq. I go look for it.
 
Hi.

Oh joy! Running programs out of a book! Can the author supply the source code? or is there a disk with the book?

The format of classic Fortran is that characters in positions 1 to 5 are the statement number.

(i.e. instead of 20 Continue you could have 12345 continue).

Position 6 is the continuation line indicator.

It's blank for a normal line, but will have a character at position 6 if the line is a continuation line.

So
12345678901234567890 (Character positions for the following)
12345 CONTINUE

could be written

12345
6CONTINUE

(The 6 should appear in the column after the 5 on the line above it).

though why anyone would want to....

The FORTRAN statements normally occupy characters 7 to 72.

73 to 80 are used for other purposes.

In the days of punched cards, the card number appeared here so you could sort the cards if the rubber band broke.

There are normally compiler controls to set up compilation for FORTRAN IV, FORTRAN 77, etc. as suits the source code.

hope this helps.
rgds
Zeit.
 
That helped allot!, thanks!. What a weird programming language.

No, no disk. Didn't ask for the source code either, spoiling all the fun?!

Rubber band?.. Never thrust a computer with rubber bands in it. :)
 
Nah, the rubber band was used to keep the deck of punched cards together.

After a time, the rubber band *always* broke, with a resulting cascade of cards to the floor.

Sorting the deck was made easier by the numbers in cols 73 to 80. (In theory).

In practice, most people threw the deck away & punched a new set.

Have you thought of using a scanner to scan the page into the pc & using OCR software to produce a text file?

I've tried this a few times, but it's usually a waste of time.

FORTRAN isn't really weird, it's just very old.

If you're lucky, you'll never discover the joys of the ARITHMETIC IF and the ASSIGNED GOTO.

rgds
Zeit.
 
Well, its all done now!.. Fortran and C conversion.. Took a bit longer to convert than I thought. Arrays start at 1 in Fortran and at 0 in C, that kept me going for a while..

And the result from the program seems to be the same both in Fortran and C, so either both have the same error or both is working!.


Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top