Modules


If I change a value of a variable defined in a MODULE in one Subroutine, is it changed when I use it in another.

Yes. Look at and execute module.f .

What is a MODULE?

A module is a place where you reserve memory for variables with specific names. When the compiler processes the module statement it sets aside memory for the variables listed within the module. When you include a USE statement for a given module in a subprogram, the compiler looks at the list of variable names defined in the MODULE, and any time it sees a variable with one of these names in the subprogram (or main program if appropriate), it uses the memory location reserved by the MODULE rather than associating a new one for the variable. This lets several (or many) subprograms agree that a variable name really refers to the same memory location, and all pick up changes made by any one subprogram without information going through the argument lists.

Can MODULEs be put at the end of the main routine. Where do they go?

Think of them as another program unit like a SUBROUTINE, FUNCTION, or BLOCK DATA. Put them after the main program if you like, or put them after any subroutine or function. Doesn't matter.

When using COMMON blocks or MODULES where is the best place to put them?

I like to locate MODULES before the "PROGRAM" card of the main program (see module.f ). However, you can place the MODULE program unit after the END statement of the main program or any subprogram. Note that there is no flexibility in the position of the USE statement. USE statements must immediately follow the PROGRAM, SUBROUTINE, or FUNCTION statements. COMMON blocks are always contained within the program units where they are needed, grouped near the top with other non-executable statements.


Up to other Questions and Answers / Home


Maintained by John Mahaffy : jhm@psu.edu