LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-01-2014, 08:26 PM   #1
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Rep: Reputation: Disabled
Gfortran statement does not compile


Hi there. I hope there is someone out there familiar with Fortran IV. Many years ago I was writing Fortran IV programs, month after months. I probably wrote tens of thousand statements and of course everything compiled. Since then I went through C, Pascal, C++, C# (lately) and Visual Fox Pro, and now I need Fortran again. My environment is: Windows 7==>VirtualBox==>Ubuntu==>GFortran (Fortran 77). Needless to say I forgot my Fortran. Now I have to recover what I've lost. Anyhow, I began by copying a code for Fortran IV from this website to Vim editor. I then ran Gfortran in Ubuntu and got an error message that one FORMAT statement was incorrect.

Quote:
601 FORMAT(4H A= ,I5,5H B= ,I5,5H C= ,I5,8H AREA= ,F10.2,12HSQUARE UNITS)
Quote:
fortran_1.f:6.72:

601 FORMAT(4H A= ,I5,5H B= ,I5,5H C= ,I5,8H AREA= ,F10.2,12HSQUARE UNI
1
Error: Unexpected end of format string in format string at (1)
fortran_1.f:15.17:
I decided that the statement was too long. I remember that in Fortran IV the statements could not exceed 78 characters I believe, so I broke the line in two this way:

Quote:
601 FORMAT(4H A= ,I5,5H B= ,I5,5H C= ,I5,8H AREA= ,F10.2,12HSQUARE &
UNITS)
It still gave me an error.

Quote:
Error: Unexpected end of format string in format string at (1)
fortran_1.f:7.13:
What is wrong with this statement?

Thanks, - Alex

Last edited by AlexBB; 04-01-2014 at 08:36 PM.
 
Old 04-01-2014, 09:40 PM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
f77 is in the legacy gcc group

f90 and 95 is in the gcc 4 branch
f77 is in the compatibility gcc 3

install gcc33-fortran or gcc34-fortran for f77 support
 
1 members found this post helpful.
Old 04-01-2014, 09:45 PM   #3
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

to continue a line in fortran you need to put character in the 6th column of the continued line. See for example
http://gcc.gnu.org/onlinedocs/gcc-3....tion-Line.html

So you could use something like:
Code:
 601  FORMAT(4H A= ,I5,5H B= ,I5,5H C= ,I5,8H AREA= ,F10.2,12HSQUARE                           
     $     UNITS)
It really helps to use a text editor that understands the language you are coding in. I don't use vim but I suspect it must have some sort of fortran mode that helps with your syntax.

Evo2.
 
1 members found this post helpful.
Old 04-02-2014, 04:29 PM   #4
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Original Poster
Rep: Reputation: Disabled
Thank you guys. Yes evo2, I recall now, the asterisk in the 6th column should do the trick. I will be able to try it in a few hours. I thought too, Vim should have sensed Fortran. It really does not. I could not even force it to display column numbers somewhere. There must be a special editor for the language in Ubuntu. - Alex

Last edited by AlexBB; 04-02-2014 at 04:30 PM.
 
Old 04-02-2014, 04:33 PM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
vim does syntax highlighting for fortran on my machines... :shrug:
 
1 members found this post helpful.
Old 04-02-2014, 08:11 PM   #6
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Original Poster
Rep: Reputation: Disabled
Suicidaleggroll, you are correct, the Vim senses Gfortran. I did not notice it last night, got too tired. I still get an error however:

Quote:
601 FORMAT(4H A= ,I5,5H B= ,I5,5H C= ,I5,8H AREA= ,F10.2,12HSQUARE
$ UNITS)
This is what it says:

Quote:
$ UNITS)
1
Error: Unexpected element 'N' in format string at (1)
fortran_1.f:16.17:
I figured the quote marks distort columns. The dollar sign actually is between 601 and Format, in the right position. The error mark "1" points to "I" in UNITS.
Go, figure. Thanks, - Alex

Last edited by AlexBB; 04-02-2014 at 08:13 PM.
 
Old 04-02-2014, 08:19 PM   #7
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Original Poster
Rep: Reputation: Disabled
John_W, as far as I remember you have never given me a suggestion that worked. More than that, they all resulted in wasted efforts and confusion. When I tried to install gcc33-fortran and gcc-34-fortran as you advised I got an error: the package could not be found. It happened with both installation attempts.

Quote:
E: Unable to locate package gcc33-fortran

Last edited by AlexBB; 04-02-2014 at 08:20 PM.
 
Old 04-02-2014, 08:20 PM   #8
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

whitespace is important in fortran. Are you sure everything is in the correct column? Please post using [code] tags not [quote] tags to preserve the formatting.

Evo2.
 
1 members found this post helpful.
Old 04-02-2014, 08:37 PM   #9
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Original Poster
Rep: Reputation: Disabled
Thanks for suggestion evo2.

Code:
601 FORMAT(4H A= ,I5,5H B= ,I5,5H C= ,I5,8H AREA= ,F10.2,12HSQUARE
   $ UNITS)
 
Old 04-02-2014, 08:40 PM   #10
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

your whitespace is wrong. See what I posted in post #3.

Evo2.
 
1 members found this post helpful.
Old 04-02-2014, 08:57 PM   #11
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Original Poster
Rep: Reputation: Disabled
Still compilation fails.

Code:
$         UNITS)                                                   
                1
Error: Unexpected element 'U' in format string at (1)
fortran_1.f:16.17:
I keep moving the second line's start and now it points to a different character.
 
Old 04-02-2014, 09:01 PM   #12
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

please try it exactly as shown in post #3.

Evo2.
 
1 members found this post helpful.
Old 04-02-2014, 09:19 PM   #13
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
As evo2 said, you aren't following the spacing rules, as has been pointed out multiple times.

You need TWO spaces after the 601 before FORMAT (or if you don't have a space before 601, then you need three spaces between 601 and FORMAT). The F in FORMAT needs to start on column 7, your examples have it on column 5.
The $ for the line wrap (it can be any character) needs to be in column 6.

http://www.stanford.edu/class/me200c...03_basics.html
Quote:
Fortran 77 is not a free-format language, but has a very strict set of rules for how the source code should be formatted. The most important rules are the column position rules:

Col. 1 : Blank, or a "c" or "*" for comments
Col. 1-5 : Statement label (optional)
Col. 6 : Continuation of previous line (optional)
Col. 7-72 : Statements
Col. 73-80: Sequence number (optional, rarely used today)
Most lines in a Fortran 77 program starts with 6 blanks and ends before column 72, i.e. only the statement field is used.

Last edited by suicidaleggroll; 04-02-2014 at 09:22 PM.
 
1 members found this post helpful.
Old 04-03-2014, 05:16 AM   #14
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
I believe your format is in error:
Code:
601 FORMAT(4H A= ,I5,5H B= ,I5,5H C= ,I5,8H AREA= ,F10.2,12HSQUARE UNITS)
Your first spec "4H A= ,I5" is correct. 4H has space A= space. The ,I5, part is ok.

Your next hollerith form "5H B= ,I5" appears incorrect. It should be 4H as 5H includes the comma, which then cause the I5 to be run without the comma separator. Last I knew that was required.

The next hollerith form has the same error. The last looks like it is OK.

I suggest using the quote forms instead - it is easier to get them right.
 
1 members found this post helpful.
Old 04-03-2014, 08:53 AM   #15
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Original Poster
Rep: Reputation: Disabled
Thank you guys. I will try your suggestions in a few hours, at the end of the day since I am at work now. Please keep it in mind that I copied this code from a website which advertises "Fortran Samples." It is not my creation. I am trying to relearn the language in a hurry. Thanks, - Alex

Last edited by AlexBB; 04-03-2014 at 08:55 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running mysql from ssh & query statement has a Text Header in the SELECT statement? djlerman Linux - Server 6 11-19-2013 06:33 PM
Can't compile f77 code using gfortran or g77 GradientDrift Programming 2 11-18-2009 10:18 PM
gfortran: Syntax error in DATA statement at (1) science_guy Programming 1 10-16-2009 12:10 AM
XLF compile HELP !The unformatted I/O statement on the file "..." cannot be completed chonchis AIX 0 06-12-2009 01:22 PM
Gfortran compile error aukuntin Linux From Scratch 2 01-28-2007 08:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration