Fixing Fortran DO Command Errors for Visual Fortran (f90)

  • Context: Fortran 
  • Thread starter Thread starter zandria
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary

Discussion Overview

The discussion revolves around errors encountered in a Fortran program, specifically related to the DO command and variable declarations in Visual Fortran (f90). Participants explore issues with variable definitions and the implications of using the IMPLICIT NONE statement.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant identifies an error related to the undeclared variable "i" in the DO loop statement.
  • Another participant suggests removing the IMPLICIT NONE statement, implying it may not be necessary for compilation.
  • In contrast, a different participant argues against removing the IMPLICIT NONE statement, stating that it enforces explicit variable declarations and prevents potential issues with undeclared variables.
  • Further, a participant elaborates on the risks of not using IMPLICIT NONE, explaining that it can lead to the creation of unintended variables, resulting in incorrect program behavior or runtime errors.

Areas of Agreement / Disagreement

There is disagreement regarding the necessity of the IMPLICIT NONE statement, with some participants advocating for its removal while others strongly oppose this action, emphasizing its importance for proper variable management.

Contextual Notes

The discussion highlights the importance of variable declarations in Fortran and the potential pitfalls of compiler behavior when IMPLICIT NONE is omitted. There are unresolved assumptions about the necessity of certain coding practices in Fortran.

zandria
Messages
15
Reaction score
0
I am working with visual Fortran (f90 I believe)

I have the following program and it says that I have 2 errors. I have narrowed it down to having something to do with my loop statement in bold. Is there something wrong that I'm not getting?

program exercise1

implicit none

integer :: limit, f1, f2, f3
read*, limit

f1 = 1
if (limit >= 1) then
print*, f1
end if

f2 = 1
if (limit >= 2) print*, f2

do i= 3, limit
f3 = f1 + f2
print*, f3
f1 = f2
f2 = f3
end do



end program exercise1
 
Technology news on Phys.org
nevermind, figured it out. I did not define "i" as a variable in my list of integers
 
Remove (delete) the statement: implicit none
 
DO NOT REMOVE THE IMPLICIT NONE STATEMENT

Having that in forces the user to explicitly define their variables. Removing that statement to get a program to compile will nearly always cause problems later down the line.

Simply put: fix it right the first time.
 
Without the IMPLICIT NONE, if you mis-spell the name of a variable once, the compiler doesn't catch it for you, as an undeclared variable. Instead, it cheerfully allocates a new variable with that name, which has no connection with the variable you meant to use. Your program compiles "successfully," but when you run it, it either produces incorrect results or crashes with a run-time error that can be very difficult to track down.
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 17 ·
Replies
17
Views
7K
  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K