- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dears,
I don't know what I forgot, but I tryied to reproduce a problem I'm facing, which is resulting in na infinity result of: 1.713457071104324E+124. I don't know what is wrong with it
I'm trying to pass arguments through subroutines. See the code below. Could you help me please?
program principal
double precision x, y, z, k, w
x = 1;
y = 1;
z = 1;
call soma(x,y,z)
call multiplica(k,w)
write(*,*) "The value of w is: ", w
end program
subroutine soma(a,b,c)
double precision, intent(in) :: a,b
double precision, intent(out) :: c
c = a+b
end subroutine
subroutine multiplica(d,e)
double precision, intent(in) :: d
double precision, intent(out) :: e
double precision x,y,z
call soma(x,y,z)
e = z*d
end subroutine
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In your multiplica routine, the variables x and y have not been initialized.
There is no implicit global sharing of variables in Fortran. You need to share the variables via a module, pass them as arguments, or have the subroutine CONTAINed within the program that declares the variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you David, for your attention. Sorry, but I'm not undertanding it. See what I did. What's wrong now? The result is: -1.0737418E+08. Thanks again.
module somatorio
implicit none
contains
subroutine soma(a,b,c)
double precision, intent(in) :: a,b
double precision, intent(out) :: c
c = a + b
end subroutine
end module
module multi
use somatorio
implicit none
double precision x,y,z
contains
subroutine multiplica(d,e)
double precision, intent(in) :: d
double precision, intent(out) :: e
call soma(x,y,z)
e = z * d
end subroutine
end module
program principal
use somatorio
use multi
x = 1;
y = 1;
z = 1;
write(*,*) "O valor de e é: ", w
end program
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The "result" that you report is arbitrary and meaningless. It is just garbage left in memory that is being reported as if it a real number.
To find the place where the error occurs, compile using the /check:uninit compiler option and run. You will see something similar to
forrtl: severe (193): Run-Time Check Failure. The variable \'_PRINCIPAL$W\' is being used without being defined
Image PC Routine Line Source
soma.exe 003E1098 _MAIN__ 50 soma.f90
It might help if you also add 'IMPLICIT NONE' to each subroutine.
The main program USEs the modules containing the subroutines, but since there are no calls to any subroutines in the main program, none of the subroutine code gets executed. Therefore, even if the variable w had been a module variable that was available to the main program, it would still be undefined unless w was initialized.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK Guys.
Now I see where I was failing.
Thank you all.
Ewerton.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page