View previous topic :: View next topic |
Author |
Message |
mojtaba8726
Joined: 27 Jun 2014 Posts: 5
|
Posted: Sat Jun 28, 2014 4:16 pm Post subject: problem on calling a subroutine inside a module |
|
|
hi everybody
i have problem on calling a subroutine that contains in a module through my main program . this is my simple code :
main program:
----------------------------------
program swapmain
use SWAPMOD ! use statements must come first
real :: a, b
! Read in two values
read(*,*) a, b
call swap(a,b)
write(*,*) a, b
end program swapmain
-----------------------------------
module swapmod
implicit none
contains
! routines provided by this module
subroutine swap(x,y)
real :: x, y, temp
temp = x
x = y
y = temp
end subroutine swap
end module swapmod |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7934 Location: Salford, UK
|
Posted: Sat Jun 28, 2014 5:18 pm Post subject: |
|
|
You need to put the module before the main program. |
|
Back to top |
|
|
mojtaba8726
Joined: 27 Jun 2014 Posts: 5
|
Posted: Sat Jun 28, 2014 6:57 pm Post subject: |
|
|
no these codes are separated in two files |
|
Back to top |
|
|
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Sat Jun 28, 2014 8:54 pm Post subject: |
|
|
a minor point, but what exactly is the 'problem' you have Mo ? |
|
Back to top |
|
|
mojtaba8726
Joined: 27 Jun 2014 Posts: 5
|
Posted: Sat Jun 28, 2014 9:15 pm Post subject: |
|
|
when i run the main program , error message on the line that calls subroutine appears. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7934 Location: Salford, UK
|
Posted: Sun Jun 29, 2014 7:36 am Post subject: |
|
|
Your program runs OK for me.
What is the error message? |
|
Back to top |
|
|
mojtaba8726
Joined: 27 Jun 2014 Posts: 5
|
Posted: Sun Jun 29, 2014 11:20 am Post subject: |
|
|
error message:
Error 29,call to missing routine:_SWAPMOD!SWAP at 0x00401099 |
|
Back to top |
|
|
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Sun Jun 29, 2014 12:18 pm Post subject: |
|
|
Check your PATH (user or system) includes the FTN95 folder.
Try rebuilding dependencies in Plato (Build menu).
Try compiling your module first, then do a build (Build menu). _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
|
mojtaba8726
Joined: 27 Jun 2014 Posts: 5
|
Posted: Sun Jun 29, 2014 9:26 pm Post subject: |
|
|
i checked all the things that you mentioned above, and i still have the problem. my software is plato version 4.63. is this version support the USE statement? by the way i use the free version. |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1892
|
Posted: Mon Jun 30, 2014 12:51 am Post subject: |
|
|
You said that you have two source files. In order to compile the main program, you would have to compile the file containing the module first. What you probably did was to link only the OBJ file with the main program. The linker would have produced an EXE file and issued an error message, which you may not have seen if you used an IDE.
Compile the two source files. Link the two OBJ files produced to produce the EXE file. |
|
Back to top |
|
|
|