LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 10-25-2014, 01:44 PM   #1
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Rep: Reputation: Disabled
GFortran compilation error


Hi there. I am trying to compile a simple Gfortran program with one function in it. I get a single compilation error which I cannot resolve. Please help

Code:
!Computation of LP
        program LP
! angle xx is in degrees. It is being converted to radians.
          real*8 :: xx, res
          integer*4 :: ll,mm
          xx = 20.0
          ll = 20
          mm = 5
          res = methodDirect (xx,ll,mm)
800       format (e12.3)
          write (*,800) res
        end program LP

        function methodDirect (xx,ll,mm)
!          xx is the angle in degrees. Has to be converted to radians
           real*8 :: xx, methodDirect
           real*8, parameter :: pi = 3.1415927
           integer*4 :: ll,mm
!          converting to radians:
           xx = xx * pi / 180.0
           methodDirect = xx
        end function methodDirect
The error is:

Code:
res = methodDirect (xx,ll,mm)
                     1
Error: Return type mismatch of function 'methoddirect' at (1) (INTEGER(4)/REAL(8))
I cannot understand why it claims that I have a mismatch unless I am blind.

Thanks, - Alex

Last edited by AlexBB; 10-25-2014 at 01:50 PM.
 
Old 10-25-2014, 02:43 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
Warning: my last use of Fortran was in some previous century.

methodDirect is not explicitly declared, so being in the range I-N it defaults to integer. You need to declare it real to return a real result.

Code:
       real function methodDirect(xx,ll,mm)
 
Old 10-25-2014, 05:36 PM   #3
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Original Poster
Rep: Reputation: Disabled
I tried that before with the same error:

Code:
real*8 function methodDirect (xx,ll,mm)
This Cambridge pdf manual in Fortran95 suggests that the function can be declared inside the function body which I also did and it compiled:

Code:
function f(x)
   real :: f, x
   f = x**3 + x - 3.0
end function f
 
Old 10-25-2014, 06:57 PM   #4
AlexBB
Member
 
Registered: Mar 2014
Posts: 464

Original Poster
Rep: Reputation: Disabled
I finally cracked it. The function must be declared in the main body of the program:

Code:
real*8 :: xx, res, methodDirect
 
  


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
[SOLVED] Where is the error in a Gfortran file? AlexBB Linux - Newbie 3 10-19-2014 11:42 AM
[SOLVED] Gfortran compilation error. Why? AlexBB Linux - Newbie 2 05-04-2014 10:33 AM
compilation problem for gfortran surja Programming 2 07-08-2013 07:58 AM
gfortran runtime error saray Linux - Software 1 05-02-2009 10:56 AM

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

All times are GMT -5. The time now is 12:46 AM.

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