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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
04-01-2014, 08:26 PM
|
#1
|
Member
Registered: Mar 2014
Posts: 464
Rep: 
|
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.
|
|
|
04-01-2014, 09:40 PM
|
#2
|
LQ Muse
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,686
|
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.
|
04-01-2014, 09:45 PM
|
#3
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
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.
|
04-02-2014, 04:29 PM
|
#4
|
Member
Registered: Mar 2014
Posts: 464
Original Poster
Rep: 
|
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.
|
|
|
04-02-2014, 04:33 PM
|
#5
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
vim does syntax highlighting for fortran on my machines... :shrug:
|
|
1 members found this post helpful.
|
04-02-2014, 08:11 PM
|
#6
|
Member
Registered: Mar 2014
Posts: 464
Original Poster
Rep: 
|
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.
|
|
|
04-02-2014, 08:19 PM
|
#7
|
Member
Registered: Mar 2014
Posts: 464
Original Poster
Rep: 
|
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.
|
|
|
04-02-2014, 08:20 PM
|
#8
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
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.
|
04-02-2014, 08:37 PM
|
#9
|
Member
Registered: Mar 2014
Posts: 464
Original Poster
Rep: 
|
Thanks for suggestion evo2.
Code:
601 FORMAT(4H A= ,I5,5H B= ,I5,5H C= ,I5,8H AREA= ,F10.2,12HSQUARE
$ UNITS)
|
|
|
04-02-2014, 08:40 PM
|
#10
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
Hi,
your whitespace is wrong. See what I posted in post #3.
Evo2.
|
|
1 members found this post helpful.
|
04-02-2014, 08:57 PM
|
#11
|
Member
Registered: Mar 2014
Posts: 464
Original Poster
Rep: 
|
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.
|
|
|
04-02-2014, 09:01 PM
|
#12
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
Hi,
please try it exactly as shown in post #3.
Evo2.
|
|
1 members found this post helpful.
|
04-02-2014, 09:19 PM
|
#13
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
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.
|
04-03-2014, 05:16 AM
|
#14
|
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,908
|
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.
|
04-03-2014, 08:53 AM
|
#15
|
Member
Registered: Mar 2014
Posts: 464
Original Poster
Rep: 
|
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.
|
|
|
All times are GMT -5. The time now is 01:16 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|