Hello,
I have recently begun to learn coding in Fortran for a work project but am stuck on the debugging phase. I have tried to create a class using a module file with a derived type to hold object variables which "contains" several subroutines. Should the subroutines be able to access the variables without my having to declare them in each subroutine all over again?
Some of the common errors I am getting are "invalid delimiter" and notifications that a variable name has already been used or that an array has already been used as a function name. It seems as though the compiler is mistaking an array for a function in some cases, not sure why.
The 'invalid delimiter' issue usually comes up with statements accessing elements of arrays, such as "Psi(1)" or "Theta(I)" where I is an integer loop control variable.
This seems to happen both in my work project and a simpler program I created just to test these things.
Here is the main file of the simple program:
The 'invalid delimiter' error highlights "thing&Display(Psi, Theta) as the problem area.
And here is the module file for the above program:
I would greatly appreciate anyone's insight into this matter and advice on how to best debug a lengthy, complex Fortran program.
Thank you,
Kei
I have recently begun to learn coding in Fortran for a work project but am stuck on the debugging phase. I have tried to create a class using a module file with a derived type to hold object variables which "contains" several subroutines. Should the subroutines be able to access the variables without my having to declare them in each subroutine all over again?
Some of the common errors I am getting are "invalid delimiter" and notifications that a variable name has already been used or that an array has already been used as a function name. It seems as though the compiler is mistaking an array for a function in some cases, not sure why.
The 'invalid delimiter' issue usually comes up with statements accessing elements of arrays, such as "Psi(1)" or "Theta(I)" where I is an integer loop control variable.
This seems to happen both in my work project and a simpler program I created just to test these things.
Here is the main file of the simple program:
Code:
program Test
use Test_it
implicit none
type(resistance) :: thing
call thing%Display(Psi, Theta)
end program Test
The 'invalid delimiter' error highlights "thing&Display(Psi, Theta) as the problem area.
And here is the module file for the above program:
Code:
module Test_it
implicit none
! place global type definitions, generic interfaces,
! variable declarations and initializations here
Type resistance
real, dimension(10) :: Psi
real, dimension(10) :: Theta
end type resistance
contains
subroutine Display (Psi, Theta)
real, dimension(10) :: Psi, Theta
write (*,*) 'Enter a real number for Psi(1)'
read (*,*) Psi(1)
write (*,*) 'Enter a real number for Theta(1)'
read (*,*) Theta(1)
write (*,*) 'Psi(1):', Psi(1)
write (*,*) 'Theta(1):', Theta(1)
end subroutine Display
end module Test_it
I would greatly appreciate anyone's insight into this matter and advice on how to best debug a lengthy, complex Fortran program.
Thank you,
Kei