 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
jcgalvez713
Joined: 28 Jan 2013 Posts: 5
|
Posted: Sat Feb 02, 2013 4:13 pm Post subject: Fortran code does not compile (modules do not compile) |
|
|
Hi everyone,
My classmate and I are working with Fortran to do programming in numerical macro. To program, I am using Silverfrost. However, for one of our assignments, my classmate used modules. When I try to run the main code, there is an error:
error 404 - Cannot find definition for MODULE GLOBAL_VARIABLE.
However, when I tried running the modules separately, and when I build the solution, the compiler tells me that the compilation failed.
Is it a problem with the compiler? |
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2402 Location: Yateley, Hants, UK
|
Posted: Sat Feb 02, 2013 4:26 pm Post subject: |
|
|
Just a guess, and that is that you put your program first in the source code: when using modules they have to come first.
E |
|
Back to top |
|
 |
jcgalvez713
Joined: 28 Jan 2013 Posts: 5
|
Posted: Sat Feb 02, 2013 5:37 pm Post subject: |
|
|
Actually the main code of the program is like this:
program main
use global_variable ! Define the global parameters that will be used in this project
use functions ! Define objective functions
use auxfuncs ! basis functions to approximate our goal function
use powell_optim
implicit none
real( :: interval, lambda(Ibis), func_value(Ibis)
integer :: j, counter2
spot_plot = linspace(Blower,Bupper,fPlot)
spot_plot2 = linspace(Blower,Bupper,JJ)
x_grid = linspace(Blower,Bupper,Ibis)
lambda =0
j = 1
interval = Bupper - Blower
h = interval / JJ
! Chebyshev are defines over [-1,1], we convert [0,5] to [-1,1] first
x_newgrid = 2*(x_grid-Blower) / interval -1
spot_plotnew = 2*(spot_plot-Blower) / interval -1
!choose which method to use to approximating
!first calculate the value of Ibis points for object
do j=1,Ibis
func_value(j) = func(x_grid(j))
end do
!******************************************!
! MSE method
guess_results = 0
xmatrix = 0
do j=1,Ibis
xmatrix(j,j)=1
end do
call powell(guess_results,xmatrix,ftoll,iterr,frett)
do j=1,fPlot
func_approxi_plot2(j) = sum(guess_results*func_basis(spot_plot(j)))
end do
!%%%%%%%%%%%%%%%%%%%%%%!
if (types2 ==1) then
! calculate the weighting vector for the basis
do j=1,Ibis
func_approxi(j, =func_basis(x_grid(j))
end do
call inverse(func_approxi,invi,Ibis)
do j=1,Ibis
lambda(j) = sum(func_value*invi(j, )
end do
!calculate the data for plotting
do j=1,fPlot
func_value_plot(j) = func(spot_plot(j))
func_approxi_plot(j) = sum(lambda*func_basis(spot_plot(j)))
end do
!%%%%%%%%%%%%%%%%%%%%%%%!
else if (types2 == 2) then
do j=1,Ibis
func_approxi(j, =func_basis(x_newgrid(j))
end do
call inverse(func_approxi,invi,Ibis)
do j=1,Ibis
lambda(j) = sum(func_value*invi(j, )
end do
!%%%%%%%%%%%%%%%%%%%%%%%!
else
lambda = func_value
do j=1,fPlot
func_value_plot(j) = func(spot_plot(j))
func_approxi_plot(j) = sum(lambda*func_basis(spot_plot(j)))
end do
end if
!%%%%%% save data %%%%%%%%!
open(unit=9,file='lambda_MSE.txt')
write(9, '(1G14.6)') guess_results
close(9)
open(unit=9,file='lambda.txt')
write(9, '(1G14.6)') lambda
close(9)
open(unit=9,file='functionvalue.txt')
write(9, '(1G14.6)') func_value_plot
close(9)
open(unit=9,file='axis.txt')
write(9,'(1G14.6)') spot_plot
close(9)
open(unit=9,file='function_approximation_value.txt')
write(9,'(1G14.6)') func_approxi_plot
close(9)
open(unit=9,file='function_approximation_value_MSE.txt')
write(9,'(1G14.6)') func_approxi_plot2
close(9)
! if (flag_normtest == 1) then
! open(unit=14,file='normality_tests_expansion')
! do i = 1, fPlot
! write(10,100) normaltest_normal(i,
! write(11,100) normaltest_t(i,
! write(12,100) normaltest_kotz(i,
! write(13,100) normaltest_mixture(i,
! write(14,100) normaltest_expansion(i,
! end do
! close(14)
! end if
end program main |
|
Back to top |
|
 |
jcgalvez713
Joined: 28 Jan 2013 Posts: 5
|
Posted: Sat Feb 02, 2013 5:41 pm Post subject: |
|
|
Hence, what you mean is that before I begin with the main program, I have to put the use above main program? |
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2402 Location: Yateley, Hants, UK
|
Posted: Sat Feb 02, 2013 7:19 pm Post subject: |
|
|
Your code has the following USE statements:
Code: | use global_variable ! Define the global parameters that will be used in this project
use functions ! Define objective functions
use auxfuncs ! basis functions to approximate our goal function
use powell_optim |
if the statements refer to modules you programmed yourself, all the module source code has to come before the PROGRAM statement. If they are precompiled modules they have to be somewhere where the compiler can find them.
E |
|
Back to top |
|
 |
jcgalvez713
Joined: 28 Jan 2013 Posts: 5
|
Posted: Sun Feb 03, 2013 11:12 am Post subject: |
|
|
What you mean is, instead of me writing them as separate modules, I put everything that I wrote in the main source code before the main program? Like this?
MODULE XXXXX
[STATEMENTS]
END MODULE XXXXX
PROGRAM YYYYY
USE XXXXX
END PROGRAM YYYYY |
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2402 Location: Yateley, Hants, UK
|
Posted: Sun Feb 03, 2013 5:08 pm Post subject: |
|
|
That's the first of two alternatives. What definitely won't work is to put the program block first.
There is nothing wrong with doing a separate compilation, but the modules have to exist, and be available when the compiler deals with the PROGRAM block. Otherwise, and this is so obvious that it hardly needs saying, the program block cannot be compiled, which is what the error message is telling you: during compilation, the compiler can't find the module.
E |
|
Back to top |
|
 |
jcgalvez713
Joined: 28 Jan 2013 Posts: 5
|
Posted: Sun Feb 03, 2013 8:44 pm Post subject: |
|
|
Then, in that case where I can compile separately, do I first compile the modules, and compile the main program after? I tried to do that, and I still ran into problems since it tells me that the module failed to compile. |
|
Back to top |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Wed Feb 06, 2013 10:27 am Post subject: |
|
|
If you use different files, you must compile in an order that means each module is compiled before any other file that uses it.
If you use Plato, Visual Studio, or the Visual Studio Shell (FTN95express) this will be done for you. _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|