gfxgfx
 
Please login or register.

Login with username, password and session length
 
gfx gfx
gfx
1617 Posts in 535 Topics by 779 Members - Latest Member: rhoronjeff@comcast.net December 02, 2022, 10:05:49 PM
*
gfx* Home | Help | Search | Login | Register | gfx
gfx
Absoft User Forum  |  Support  |  General  |  How to compile a USE module .mod ?
gfx
gfxgfx
 

Author Topic: How to compile a USE module .mod ?  (Read 1149 times)

Mike Linacre

  • Sr. Member
  • ****
  • Posts: 259
How to compile a USE module .mod ?
« on: February 25, 2021, 10:21:14 PM »
A great feature of the Absoft compiler is the "use module" capability.

The User Guide says: "See Fortran 90/95 Module Files in the chapter, Building Programs for more information." but nowhere can I find instructions how to compile a Use module .mod file.

Please anyone, how do we do it ???

forumadmin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 333
Re: How to compile a USE module .mod ?
« Reply #1 on: February 26, 2021, 07:28:41 AM »
Module files (.mod extension) are created by compiling the FORTRAN source file which defines them.

If you have a source file named test.f90 which contains the following module definition:

    MODULE CONSTANTS   
    IMPLICIT NONE   
    INTEGER, PARAMETER :: SECONDS_IN_MINUTE=60   
    INTEGER, PARAMETER :: SECONDS_IN_HOUR=3600   
    INTEGER, PARAMETER :: SECONDS_IN_DAY=86400
    INTEGER, PARAMETER :: MINUTES_IN_HOUR=60   
    INTEGER, PARAMETER :: MINUTES_IN_DAY=1440
    INTEGER, PARAMETER :: HOURS_IN_DAY=24   
    END MODULE CONSTANTS


then compiling this file with

   af90 -c test.f90

will produce two output files:  a module file CONSTANTS.mod and an object code file test.obj (test.o on Linux and macOS). If a module only defines constants then you only need the .mod file to be present when you compile another source file which uses the module through a USE statement. If a module defines variables and contained subroutines or functions, then you will also need to provide the object file created when the module is compiled when you link a program which uses the module.

When a source file defines multiple modules, a separate .mod file is created for each one. The variables and contained routines for all the modules defined in single source are placed in the object file.
« Last Edit: February 26, 2021, 08:32:56 AM by forumadmin »

Mike Linacre

  • Sr. Member
  • ****
  • Posts: 259
Re: How to compile a USE module .mod ?
« Reply #2 on: February 28, 2021, 07:06:44 PM »
Thanks, forumadmin. Brilliant! It works!

For anyone else ...

Here is my "interface.f" file:
        SUBROUTINE CREPORT (QNAME, QC, QN)
        MODULE INTERF
        INTERFACE CREPORT
        INTEGER(4) ::  QNAME
        INTEGER(4) ::  QC
        INTEGER(4) ::  QN
        END SUBROUTINE CREPORT
        END INTERFACE
        END MODULE INTERF
       (MORE LINES OF FORTRAN CODE HERE)
       END

When I compile this from the Absoft command line prompt,

C:\Absoft13.0>bin\af90 -c c:\(my path)\interface.f

nothing shows on my screen, but "INTERF.mod" is in my C:\Absoft13.0 folder.

Thanks again, forumadmin! You are a treasure :-)
« Last Edit: May 30, 2021, 03:22:13 AM by Mike Linacre »

Absoft User Forum  |  Support  |  General  |  How to compile a USE module .mod ?
 

gfxgfx
gfx gfx
Powered by MySQL Powered by PHP Valid XHTML 1.0! Valid CSS!