CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   F90-question (https://www.cfd-online.com/Forums/main/4136-f90-question.html)

Matthias November 21, 2001 11:41

F90-question
 
Dear all,

I have a question concerning F90, I hope, I it is allowed to answer such a question in this forum.

I have the following simple program:

module mytest

implicit none

integer,private :: n

contains

subroutine test

print*,'test === ',n

end subroutine test

end module mytest C%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

program main

use mytest

implicit none

integer :: n

n = 10

print*,'main === ',n

call test

end program main

How can I communicate n = 10 from the main program to the module? Is there an easy way to do this. I won't use a common block for n.

Thaks in advance

peter November 21, 2001 14:10

Re: F90-question
 
module mytest

implicit none

!integer,private :: n

contains

subroutine test (n)

integer, intent(in) :: n

print*,'test === ',n

end subroutine test

end module mytest

!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

program main

use mytest

implicit none

integer :: n

n = 10

print*,'main === ',n

call test (n)

end program main


Matthias November 22, 2001 01:36

Re: F90-question
 
Thanks Peter

but this is not what I ment, In you suggestion the variabe n in the module is only known in the subroutine test. What I' d like to get is that n will be known in the whole module mytest.

Matthias

Markus Lummer November 22, 2001 02:09

Re: F90-question
 
Write a subroutine set in module mytest:

subroutine set(nn) integer, intent(in) :: nn

n=nn

end subroutine set

Hope this helps.

Markus

Matthias November 22, 2001 02:23

Re: F90-question
 
Thanks,

easy solution :) , but what happens if I have more than only one (say 100) of such variable to communicate from the program main to the module. There I need a subroutine set with a very long data exchange header :( Is this the only one solution?

regards

Matthias

Markus Lummer November 22, 2001 03:12

Re: F90-question
 
You could use an array or a type, e.g.:

type TestData

integer :: par1,par2,par3

end type TestData

subroutine set(data)

type (TestData), intent(in) :: data

par1 = data%par1

par2 = data%par2

par3 = data%par3

end subroutine set


Matthias November 22, 2001 03:18

Re: F90-question
 
That looks fine !

Thanks Matthias

J. Keays November 22, 2001 08:21

Re: F90-question
 
Hi,

While I am here, does anyone know of an online forum that deals with fortran related questions for fluid flow problems or problems in general?

Thanks.


All times are GMT -4. The time now is 08:35.