Hi,
What kind of files are suggested to be included?
Are those modules or subroutines?
I've also surfed the old topic, and finds someone talking about these
included file's extension, e.g. ".inc", ".fi" etc.
Why do we need to name it in a different file extension? I've tried to
rename my module file extension from ".f90" to ".fi", and suddenly the
color of the module
file turns out very uncomfortable (not as usually for *.f90, *.for).
And also it also looks like
a fixed format.
In addition, I also found (maybe it's not anything new for you all)
that I could just create
a new main program, specifying which modules needed to be included in
the beginning.
And then compile, the subroutines in modules will automatically came
into the project
as external dependencies. Then I tried to create the main program in
somewhere else,
even in C: disk. Interestingly, it also automatically capture the
modules and also the
subroutines contained in it. So I thought it's great. These files
called by module can be
opened even they are not in the same directory. But finally when I
add an additional subroutine in this module,after compiling, it won't
be opened even I put that file into
the project directory. I am confused. Why?
ps.
***main program****
include "modA.f90"
program main
use modA
integer b
call subA(10,b)
print *,b
call subB(13,b)
print *,b
print *,x
stop
end
*********modA.f90*****
module modA
implicit none
contains
include "subA.f90"
include "subB.f90"
end module modA
****** subA & subB are just simple stuffs***
Besides, are subroutines/functions needed to be named as another file
extension?
Thank you.
Mike
|
|
0
|
|
|
|
Reply
|
acout (157)
|
6/15/2006 6:15:23 AM |
|
Mike schreef:
> Hi,
>
> What kind of files are suggested to be included?
> Are those modules or subroutines?
> I've also surfed the old topic, and finds someone talking about these
>
> included file's extension, e.g. ".inc", ".fi" etc.
You seem to be confusing a number of things here. I am probably
not using the completely correct "jargon" in my attempt at a
clarification
below but still :).
First of all:
The compiler processes source files, they usually have a fixed
extension
(.f, .f90, .for, to name the most common ones), because that allows it
to recognise the form (fixed or free) and the type (how it should
process
it or whether it should leave it to another compiler or the linker).
These source files can contain include statements. All that happens is
that the include statement is replaced by the contents of the file to
be included
and that the resulting new file is processed.
That means an include file can contain anything, as long as the result
after
substitution is valid Fortran code:
- Comments
- Fragments of a function or subroutine
- Complete modules
whatever you like
There is no inherent extension for these include files - to the
compiler
they are simply text files. The _only_ requirement is that the file be
found somewhere. Compiler often offer an option to specify the
directories
to search for such files.
Then: modules
If you use the "use" statement, you ask the compiler to take along
information
about the module you want, while it is processing the source file. The
process
is completely different:
- The module must have been compiled already and its "module
intermediate file"
(something compiler-specific, containing all information about the
module
the compiler needs) must be available somewhere in the directories
the
compiler searches in (again: there is probably an option to set the
list
of directories).
- The information about the module is used to compile your source file,
but your source file (after processing the include statements) must
contain
complete source text - the source of the module need not be available
at all.
The third step: linking all into a program
Well, linking is another story. The results of all compilation steps
are combined
into a program and you will need to specify what "object" files to link
and
what libraries.
All in all, in each step the compiler or linker needs to know what
files you want
to process. Some default directories are provided, but if these are not
enough
you need to givel these directories explicitly.
(The details depend on your system, but this is the somewhat lengthy
overall
story).
Regards,
Arjen
|
|
0
|
|
|
|
Reply
|
arjen.markus (2628)
|
6/15/2006 8:07:39 AM
|
|
> - The module must have been compiled already and its "module
> intermediate file"
How to compile the module alone? Oh I forgot to mention I use Compaq
Visual Fortran.
> (something compiler-specific, containing all information about the
> module
> the compiler needs) must be available somewhere in the directories
> the
> compiler searches in (again: there is probably an option to set the
> list
> of directories).
Where to find the directory where the compiler searches?
> - The information about the module is used to compile your source file,
> but your source file (after processing the include statements) must
> contain
> complete source text - the source of the module need not be available
> at all.
Do you mean I can link the compiled module files?
Mike
|
|
0
|
|
|
|
Reply
|
acout (157)
|
6/15/2006 1:14:05 PM
|
|
Mike wrote:
>>- The module must have been compiled already and its "module
>>intermediate file"
>
>
> How to compile the module alone? Oh I forgot to mention I use Compaq
> Visual Fortran.
Assuming it stands alone in a source file, add that file to your
project. If it doesn't stand alone in a source file, you can't compile
the module alone, you must compile the entire file including anything
else that appears in it.
>> (something compiler-specific, containing all information about the
>>module
>> the compiler needs) must be available somewhere in the directories
>>the
>> compiler searches in (again: there is probably an option to set the
>>list
>> of directories).
>
>
> Where to find the directory where the compiler searches?
It's in the settings somewhere. Usually, something like Tools >>
Options or Tools >> Directories or somesuch (I don't recall exactly
where it is in Visual Studio and I'm currently in Linux so I can't load
it to look).
>>- The information about the module is used to compile your source file,
>> but your source file (after processing the include statements) must
>>contain
>> complete source text - the source of the module need not be available
>>at all.
>
>
> Do you mean I can link the compiled module files?
Compiling a module will produce two files: the module file (typically
ending in .mod on most platforms) containing information about the
module interface, which is required to compile client code, and the
object file (may be .obj or .o for the common platforms), which needs to
be linked. In Visual Fortran, as long as the module source file appears
in your project, the object file will be linked in automatically (but
you may have some order-of-compilation issues with the .mod file as I
recall).
|
|
0
|
|
|
|
Reply
|
enigma (394)
|
6/15/2006 6:18:15 PM
|
|
|
3 Replies
35 Views
(page loaded in 0.174 seconds)
|