For Programmers: Free Programming Magazines  


Home > Archive > Fortran > April 2006 > Newbie making a dumb mistake but can you help?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Newbie making a dumb mistake but can you help?
JustMe2

2006-04-26, 7:04 pm

I am very new to fortran and I am (trying to) writing with fortran 90.
I have a very large project in front of me an want to use modules to
help organize the project.

I can write and compile the .mod files I can write, compile, link and
run "normal" .f90 files

Now I need to get the "use module" to work. I have a simple main that
reads the input and sets two vars. I then try to call a .mod function.

seemed simple but I cannot get the main to compile. I get an error
undefined reference to "___randoms_randie" randoms is the .mod file
randie is the function in the .mod file.

do I need to proto type? if so how do I do that, every place I put the
interface I get the error duplicate identifiers

Thank you in advance ...


========================================
==========

!***************************************
*******************************
MODULE RANDOMS
IMPLICIT NONE
CONTAINS
FUNCTION RANDIE(IX,RX)
REAL :: RANDIE
REAL, INTENT( IN ) :: IX, RX
REAL :: NIX, RI, II
RI = RX
II = IX
13 II=II*1029
NIX=IX/1048576
II=II-NIX*1048576
RI=II/1048575.7
IF(II.EQ.0)THEN
II=1
GO TO 13
END IF
RANDIE = RI
END FUNCTION RANDIE
END MODULE RANDOMS

========================================
==========
PROGRAM t_main
USE randoms
IMPLICIT NONE
REAL :: a, b, c

PRINT*, " enter a , b"
READ*, a,b
c = b
c = RANDIE(a,c)
PRINT*, " your input was ",a," and ",b," with a rondom number of ",c
PRINT*, " "

end PROGRAM t_main
========================================
===========

David Frank

2006-04-26, 7:04 pm

compiles/runs ok using my CVF compiler...


Colin Watters

2006-04-26, 7:04 pm

Given what David says, I'd guess that RANDOMS and t_main are in separate
files, and that the link script (or whatever creates the link script)
doesn't contain a reference to the file that RANDOMS is in.

Try compiling and linking the source in one file, i.e. exactly as you have
shown it in your posting.

If you tell us what compiler and opsys you are using we will be able to make
more informed guesses.

--
Qolin

Email: my qname at domain
Domain: qomputing dot demon dot co dot uk
"JustMe2" <do_mail@cox.net> wrote in message
news:1146084050.446725.56680@j33g2000cwa.googlegroups.com...
> I am very new to fortran and I am (trying to) writing with fortran 90.
> I have a very large project in front of me an want to use modules to
> help organize the project.
>
> I can write and compile the .mod files I can write, compile, link and
> run "normal" .f90 files
>
> Now I need to get the "use module" to work. I have a simple main that
> reads the input and sets two vars. I then try to call a .mod function.
>
> seemed simple but I cannot get the main to compile. I get an error
> undefined reference to "___randoms_randie" randoms is the .mod file
> randie is the function in the .mod file.
>
> do I need to proto type? if so how do I do that, every place I put the
> interface I get the error duplicate identifiers
>
> Thank you in advance ...
>
>
> ========================================
==========
>
> !***************************************
*******************************
> MODULE RANDOMS
> IMPLICIT NONE
> CONTAINS
> FUNCTION RANDIE(IX,RX)
> REAL :: RANDIE
> REAL, INTENT( IN ) :: IX, RX
> REAL :: NIX, RI, II
> RI = RX
> II = IX
> 13 II=II*1029
> NIX=IX/1048576
> II=II-NIX*1048576
> RI=II/1048575.7
> IF(II.EQ.0)THEN
> II=1
> GO TO 13
> END IF
> RANDIE = RI
> END FUNCTION RANDIE
> END MODULE RANDOMS
>
> ========================================
==========
> PROGRAM t_main
> USE randoms
> IMPLICIT NONE
> REAL :: a, b, c
>
> PRINT*, " enter a , b"
> READ*, a,b
> c = b
> c = RANDIE(a,c)
> PRINT*, " your input was ",a," and ",b," with a rondom number of ",c
> PRINT*, " "
>
> end PROGRAM t_main
> ========================================
===========
>



JustMe2

2006-04-26, 7:04 pm

if i put both in the same file it will compile link and run. I guess I
don't understand what the .mod file is for. If I have to link the obj
file as well then why would I want to use the .mod files?

thanks...

Richard Maine

2006-04-26, 7:04 pm

JustMe2 <do_mail@cox.net> wrote:

> if i put both in the same file it will compile link and run. I guess I
> don't understand what the .mod file is for. If I have to link the obj
> file as well then why would I want to use the .mod files?


You don't have a choice, actually. The .mod file is part of how modules
work. In particular, the .mod file is used at compile time (*NOT* link
time) to communicate information from the module to whatever USEs the
module. In essence, the USE statement tells the compiler to read the
..mod file to get information about the module. WIthout it, the compiler
would have no idea what is in the module and would not be able to use it
correctly.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
JustMe2

2006-04-26, 7:04 pm

Thanks Richard,

glade I do most of my programming with a real language :-)

guess I'll have to make a make file.

Thanks to all for the information. You guy (people) are great!

Richard Maine

2006-04-26, 10:02 pm

JustMe2 <do_mail@cox.net> wrote:

> guess I'll have to make a make file.


I'm not quite sure how that relates to the stated problems, but ok.

On rereading your original post in this thread, two issues occur to me.
Perhaps you were just wording things sloppily, but then perhaps not, as
both of these are errors I have seen people make.

1. You talked about how you "write and compile the .mod files." Do you
mean that literally? If so, that's an error. A .mod file is not
something you write and compile. To compile a module, you put the module
source code in a .f90 file just like any other Fortran source. The
compiler will make the .mod file during compilation. If you actually
write and try to compile a file with a .mod name, I'm not sure what will
happen, but odds are that it won't be good. Don't do that.

2. You also talked about putting interfaces various places. No, don't do
that for module procedures. If you try to do that, it will cause
problems. The USE statement provides all the interface information for
procedures in the module. If you try to also write an interface body,
that will not work.

As a rough approximation. since you imply that you are familliar with
other languages, the .mod file is somewhat like a C header file, except
that the compiler automatically writes it for you. The analogy isn't
perfect, but its a reasonable first approximation.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
JustMe2

2006-04-26, 10:02 pm

You are correct about writing the module file and compiling to get the
..mod file. Your last note made me understand the .mod was a "header
type" file so now I know why it has to be linked. The book I am using
to learn fortran didn't make that clear, it compaired the .mod to a .so
file.

the proto typing (interface) was what I tried to do to make the t_main
see the randoms module, and as stated I couldn't get that to woek, as
it shouldn't have.

Thanks once again for the info and I really like this group, you people
want to help and do a good job.

Thanks again ....

Richard Maine

2006-04-27, 4:03 am

JustMe2 <do_mail@cox.net> wrote:

> The book I am using
> to learn fortran didn't make that clear, it compaired the .mod to a .so
> file.


I'm not sure what book that is, but it sounds pretty bad from that one
data point. That comparison doesn't make any sense at all. A .mod file
has about as much relationship to a .so file as it does to an eggplant
(not much).

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com