creating .mod files and fortran documents

260 views
Skip to first unread message

new_to_lisp

unread,
Apr 4, 2006, 6:57:49 AM4/4/06
to gg95
Hi,
I don't know much about about fortran, or g95 (I'm learning mainly to
apply in scientific computing, probably during my PhD thesis studies).
In one of the posts on this mailing list, I've seen a code sample with
modules. Unfortunately i couldn't run it, as I don't know how to
compile module files and how to use them yet. As a quick help, could
you tell me how I can compile a file containing only modules (and later
how I can use them in my programs)?

I'm also having a hard time in finding good fortran documentation on
the web. Any suggestion for:
1) free online notes (pdf, ps, etc)
2) a good, not nosense fortran book with meaningful scientific
examples. (not Idiot guides, please ;-)).
would be very useful for me, as well.

Regards.

beli...@aol.com

unread,
Apr 4, 2006, 8:11:13 AM4/4/06
to gg95

new_to_lisp wrote:
> Hi,
> I don't know much about about fortran, or g95 (I'm learning mainly to
> apply in scientific computing, probably during my PhD thesis studies).
> In one of the posts on this mailing list, I've seen a code sample with
> modules. Unfortunately i couldn't run it, as I don't know how to
> compile module files and how to use them yet. As a quick help, could
> you tell me how I can compile a file containing only modules (and later
> how I can use them in my programs)?

Look at the "Running G95" section at http://www.g95.org/docs.html .

> I'm also having a hard time in finding good fortran documentation on
> the web. Any suggestion for:
> 1) free online notes (pdf, ps, etc)

There are many links to Fortran 90/95 tutorials at the Open Directory
at
http://dmoz.org/Computers/Programming/Languages/Fortran/Tutorials/Fortran_90_and_95/
.

> 2) a good, not nosense fortran book with meaningful scientific
> examples. (not Idiot guides, please ;-)).
> would be very useful for me, as well.

"Fortran 95/2003 Explained" by Michael Metcalf, John Reid and Malcolm
Cohen is good, but it focuses on describing the language and does not
have so many examples. For more examples, you could purchase the useful
Numerical Recipes in Fortran 90 library -- the accompanying book is
online.

new_to_lisp

unread,
Apr 4, 2006, 10:37:01 AM4/4/06
to gg95

Let me ask more specifically:
Assume I have a file
typedefn.for
which contains the definition for the module MyMod.
What are the command line switches to get the file MyMod.mod?

The page you link maybe contains that info, but I'm not sure after
having a look at it. If I simply issue the command

g95 typedefn.for

compiler of course complains about the MAIN_ being missing. Note that
my important problem is not to be able to say -o MyMod.mod, but rather
whether this is enough to generate a module. probably not... If it's
enough, than a module file is just an object file.
What's the correct thing to do?

Thank you.

Graham Gower

unread,
Apr 4, 2006, 10:46:13 AM4/4/06
to gg...@googlegroups.com
> Assume I have a file
> typedefn.for
> which contains the definition for the module MyMod.
> What are the command line switches to get the file MyMod.mod?
>
> The page you link maybe contains that info, but I'm not sure after
> having a look at it. If I simply issue the command
>
> g95 typedefn.for
>
> compiler of course complains about the MAIN_ being missing. Note that
> my important problem is not to be able to say -o MyMod.mod, but rather
> whether this is enough to generate a module. probably not... If it's
> enough, than a module file is just an object file.
> What's the correct thing to do?

g95 -c typedefn.for

Perhaps the manual page for g95 would be useful for you?

Graham

beli...@aol.com

unread,
Apr 4, 2006, 10:48:41 AM4/4/06
to gg95
new_to_lisp wrote:

<snip>

> Let me ask more specifically:
> Assume I have a file
> typedefn.for
> which contains the definition for the module MyMod.
> What are the command line switches to get the file MyMod.mod?

With g95 and other Fortran compilers I have used, a file foo.mod is
created automatically
when a source file containing module foo is compiled. (This is a
convention -- I don't think the Fortran standard mandates the files
containing module information be created.)

Therefore, you need only issue the command

g95 -c typedefn.for

to create MyMod.mod .

>
> The page you link maybe contains that info, but I'm not sure after
> having a look at it. If I simply issue the command
>
> g95 typedefn.for
>
> compiler of course complains about the MAIN_ being missing. Note that
> my important problem is not to be able to say -o MyMod.mod, but rather
> whether this is enough to generate a module. probably not... If it's
> enough, than a module file is just an object file.
> What's the correct thing to do?

The -o option is used to specify object files or executable names, not
module file names. As described above, the .mod files are created
automatically.

new_to_lisp

unread,
Apr 4, 2006, 12:43:36 PM4/4/06
to gg95
Thank you beliav... at aol dot com and Graham! Question may have
sounded silly (actually it was silly ;)), but I've never messed with
fortran before, so I'm not familiar even with the most basic
conventions. Thank you for your help.
Regards.

beli...@aol.com

unread,
Apr 4, 2006, 1:28:36 PM4/4/06
to gg95

You are welcome. Speaking of conventions, I (and probably most Fortran
95 programmers) think that new Fortran code should be written using
free source form, in which case ".for" is the wrong suffix, because
most compilers will treat the code as fixed source form by default.
Your earlier post mentioned a file name with the ".for" suffix. A
".f90" suffix is better.

new_to_lisp

unread,
Apr 4, 2006, 5:16:52 PM4/4/06
to gg95
Well, here is a question if you don't mind:
Does there exist any column size limit in the free form as of the
latest or most commonly held fortran standard?
I remember as though I've seen something like 132 columns in some
tutorial, but I don't know whether I have to observe this really in
practice. On one hand, it sounds strange to be limited this way (no
such thing in C, for example), yet on the other hand it's still a big
improvement over the old format ;-). Actually, I very much dislike
anything beyond 80 columns, but just in case...

As i don't have access to any other compiler than g95 and gfortran, I
cannot check it myself (so i ask you experts).

Regards,

Nusret

Graham Gower

unread,
Apr 4, 2006, 11:16:37 PM4/4/06
to gg...@googlegroups.com
On 05/04/06, new_to_lisp <nbal...@yahoo.com> wrote:
>
> Well, here is a question if you don't mind:
> Does there exist any column size limit in the free form as of the
> latest or most commonly held fortran standard?
> I remember as though I've seen something like 132 columns in some
> tutorial, but I don't know whether I have to observe this really in
> practice. On one hand, it sounds strange to be limited this way (no
> such thing in C, for example), yet on the other hand it's still a big
> improvement over the old format ;-). Actually, I very much dislike
> anything beyond 80 columns, but just in case...
>
> As i don't have access to any other compiler than g95 and gfortran, I
> cannot check it myself (so i ask you experts).

g95 does indeed complain about lines longer than 132 characters.

I whacked a bunch of spaces between 'a' and '= 1'.

$ cat test.f90
program test
integer :: a
= 1
end program

$ g95 test.f90
Warning (115): Line 2 of test.f90 is being truncated


Graham

Reply all
Reply to author
Forward
0 new messages