LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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, 09:26 PM   #1
AlexBB
Member
 
Registered: Mar 2014
Posts: 435

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 09:36 PM.
 
Old 04-01-2014, 10:40 PM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 16,818

Rep: Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408
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, 10:45 PM   #3
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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, 05:29 PM   #4
AlexBB
Member
 
Registered: Mar 2014
Posts: 435

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 05:30 PM.
 
Old 04-02-2014, 05:33 PM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

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

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 09:13 PM.
 
Old 04-02-2014, 09:19 PM   #7
AlexBB
Member
 
Registered: Mar 2014
Posts: 435

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 09:20 PM.
 
Old 04-02-2014, 09:20 PM   #8
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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, 09:37 PM   #9
AlexBB
Member
 
Registered: Mar 2014
Posts: 435

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, 09:40 PM   #10
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

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

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

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, 10:01 PM   #12
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

please try it exactly as shown in post #3.

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

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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 10:22 PM.
 
1 members found this post helpful.
Old 04-03-2014, 06:16 AM   #14
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,602

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
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, 09:53 AM   #15
AlexBB
Member
 
Registered: Mar 2014
Posts: 435

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 09:55 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 07:33 PM
Can't compile f77 code using gfortran or g77 GradientDrift Programming 2 11-18-2009 11:18 PM
gfortran: Syntax error in DATA statement at (1) science_guy Programming 1 10-16-2009 01:10 AM
XLF compile HELP !The unformatted I/O statement on the file "..." cannot be completed chonchis AIX 0 06-12-2009 02:22 PM
Gfortran compile error aukuntin Linux From Scratch 2 01-28-2007 09:08 PM


All times are GMT -5. The time now is 02:57 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration