PDA

View Full Version : using module


hydraulic_M.H.
06-17-2004, 10:42 AM
Hi,
I have problem using Module, I have written a module and the corresponding file name.
the module looks like follow


module chartest

contains
function abc(n)
implicit none
INTEGER , INTENT (IN) :: n ! length of thestring to return

CHARACTER (LEN = n) abc ! returned string


CHARACTER (LEN = 15) :: alpha = 'abcdefghijklmno'

abc = alpha(1:n)
end function abc

end module


and the main program looks llike follow:


program test_abc

USE chartest
implicit none
INTEGER :: n
write (*,*) 'inter int: '
read (*,*) n
write (*,*) ' it is ', abc(n)

end program



but whenever I compile the main program the foollowing error appears:

'1370-S: " mainabc", line 5: module chartest is not available. '
I don't know how to compile the main program that recognizes the module.


thanks

M.H. :confused:

tzeis
06-17-2004, 06:17 PM
You have to compile the module before you compile the program that uses the module. One easy way to make sure everything will work is to put the module into the same file as the main. If the module lives in a different directory than the main, you will have to specify the -mod option to tell the compiler where the module is when you compile the main. Don't forget to put the module's object file into the compile command for the main.