FORTRAN95 Program for Iteration and Function Addition in PLATO IDE

  • Context: Fortran 
  • Thread starter Thread starter dexter90
  • Start date Start date
  • Tags Tags
    Fortran95 Program
Click For Summary

Discussion Overview

The discussion revolves around issues encountered while writing a FORTRAN95 program in the PLATO IDE, specifically focusing on function definitions, syntax errors, and the distinction between functions and subroutines. Participants are troubleshooting code that is not functioning as expected.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant shares a FORTRAN95 program and reports that it is not working, asking for help.
  • Another participant suggests removing a line of code that calls a function, arguing that it is unnecessary since the function is being used in an assignment statement.
  • A different participant points out multiple issues in the original code, implying a lack of understanding of FORTRAN syntax and suggesting the use of tutorials for learning.
  • A participant shares an alternative version of the program that still produces errors, highlighting issues with function return values and type mismatches.
  • One participant emphasizes the importance of understanding basic syntax before programming, providing a corrected version of the code that includes proper assignment statements.
  • Another participant asserts their programming foundation but claims the provided code does not work as intended.
  • A participant shares a revised version of the code that compiles successfully, while also addressing previous misunderstandings about function and subroutine usage.
  • One participant acknowledges their mistake regarding the placement of function definitions and expresses gratitude for the feedback.
  • A participant clarifies the distinction between functions and subroutines, criticizing the mixing of these concepts in the original code and questioning the programming experience of the author based on the errors observed.

Areas of Agreement / Disagreement

Participants express differing views on the original code's correctness and the author's programming skills. There is no consensus on the best approach to resolve the issues, and multiple perspectives on the errors and necessary corrections are presented.

Contextual Notes

Participants highlight issues related to function definitions, return values, and the correct use of FORTRAN syntax. There are unresolved questions about the specific errors encountered during compilation and the implications of mixing function and subroutine concepts.

Who May Find This Useful

This discussion may be useful for individuals learning FORTRAN programming, particularly those seeking to understand function and subroutine distinctions, syntax errors, and debugging practices in a programming environment.

dexter90
Messages
14
Reaction score
0
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.
 
Technology news on Phys.org
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.
 
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/
 
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)
 
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
 
I have solid fundation in programming. Your code not woking, I was writing the same code
 
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.
 
Thank you,

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

I greet.
 
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.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 8 ·
Replies
8
Views
5K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K