New Reply

Simple program in FORTRAN95

 
Share Thread Thread Tools
May20-12, 01:34 AM   #1
 

Simple program in FORTRAN95


Code:
program iteration
real :: p
IMPLICIT NONE
call add(5)
p=add(5)

end iteration

real function add(a)
real :: a
a+2
end function add
It not working... Why?? I use PLATO IDE ( FORTRAN 95 )

I greet.
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> Bird's playlist could signal mental strengths and weaknesses
>> Minus environment, patterns still emerge: Computational study tracks E. coli cells' regulatory mechanisms
>> Bacterium uses natural 'thermometer' to trigger diarrheal disease, scientists find
May20-12, 12:33 PM   #2
 
What happens when you run it? Does it produce an error?

I don't think you need to include the line call add(5), since add() is a function (and not a subroutine). The assignment statement below (p=add(5)) is sufficient.

Try removing the line call add(5), and please provide the output or error message if it still does not work.
May20-12, 02:20 PM   #3

Math 2012
 
Recognitions:
Science Advisor Science Advisor
There are so many things wrong here (at least five) that it suggests either you don't know Fortran at all, or you don't know how to interpret the messages you got when you tried to compile the code.


The best answer to either problem is find a Fortran tutorial and work through it. This uses PLATO and Silverfrost: http://www.fortrantutorial.com/
May20-12, 04:25 PM   #4
 

Simple program in FORTRAN95


Code:
program iteration

IMPLICIT NONE
call potega(5)


end iteration

real function potega(a)
real :: a
a+2
end function potega
And I have error:

Error: Statement not recognised
Warning: The result of FUNCTION POTEGA has never been set
Warning: n a call to POTEGA from another procedure, the first argument was of type INTEGER(KIND=3), it is now REAL(KIND=1)
May20-12, 05:13 PM   #5
 
Dexter90:

You really need to study just the basics...programming without knowing the syntax is just a guessing game.

Code:
program iteration

IMPLICIT NONE
real::a
a = potega(5)
write(*,*) a
end iteration

real function potega(a)
real :: a
potega = a+2
end function potega
May21-12, 12:46 AM   #6
 
I have solid fundation in programming. Your code not woking, I was writing the same code
May21-12, 04:23 AM   #7
 
o.k., I actually bother to compile now:
Code:
program iteration

IMPLICIT NONE
real::a, potega
a = potega(5.0)
write(*,*) a
end program iteration

real function potega(a)
real :: a
potega = a+2
end function potega
Besides, I never said you did not have a solid foundation in progarmming, it just does not look like you are bothering to put a basic effort on reading fortran when you call the same function as a function as a subroutine in the same program.

Good luck.
May21-12, 04:35 AM   #8
 
Thank you,

I was reading that the fortran functions are placed at the end, My mistake. I am sorry.

I greet.
May21-12, 03:34 PM   #9
 
Mentor
Fortran distinguishes between FUNCTIONs and SUBROUTINEs. Your code mixed these two ideas, as you declared add/potega as a function, but used it as if it were a subroutine.

The other major mistake that I saw was the expression 'a + 2' in the function body. Writing an expression rather than an assignment statement makes me question how solid your programming foundation is. That is not the kind of mistake that someone with experience makes.
New Reply
Thread Tools


Similar Threads for: Simple program in FORTRAN95
Thread Forum Replies
Having some issues with a piece of fortran95 code Programming & Comp Sci 9
Simple Java class + driver program help. Program isn't working, but should be. Programming & Comp Sci 7
Fortran95 HELP!!! Programming & Comp Sci 5
Free simple physics program for simple designs General Engineering 2
Fortran95 datafile extraction help Programming & Comp Sci 5