1 (edited by JohnWasilewski 2012-02-18 04:40:59)

Topic: Help with Fortran MODULES

I'm a Fortran-IV and F77 veteran but new to F90 et seq.
I'm starting to make use of, but not yet fully familiar with,
- structured typing,
- allocatable arrays and
- modules.

Is there anuything I need to know about adding a module to a SF project?
Should the source filename be 'filename.mod' or can be anything I like, as long as I add it to the project?

Do I add it just like anuy otehr source file?

And lastly, can anyone tell me what's wrong with this code (see below)?  I am getting an error message pegged to the USE statement that the file 'materials.mod' opened is not a GFORTRAN module file.

      MODULE MATERIALS
C     ----------------
C     Materials
C
C     jw 17-02-12 draft
C     jw 17-02-12 last amended

      Type :: MATERIAL
         REAL           ::   Gamma,Emod,Gmod
         CHARACTER(24)  ::   Desc
      END TYPE

      TYPE(MATERIAL), ALLOCATABLE :: MATLS(:)

      LOGICAL  MadeMAT, ShowsMAT, GoodMAT

      INTEGER  idMatPAN,
     +            idMatPAN1,
     +            idMatPAN2,
     +            idMatTbl


      END MODULE MATERIALS

Any help will be greatly appreciated.
---
John

Re: Help with Fortran MODULES

John,

Modules in Fortran 90 (and higher) are simply organizational units within your source code.  The files should remain named with proper Fortran extensions (.f, .f90, etc.).  Files ending in .mod are generated by the compiler, and they are not human-readable.  Furthermore, you can place multiple modules in the same Fortran file, although ordering of modules becomes important if they "use" each other. 

There is a great tutorial for Fortran 90 written by a Dr. Shene from Michigan Technological University that delves into modules.  Have a look at http://www.cs.mtu.edu/~shene/COURSES/cs … odule.html, specifically the section introducing modules as to the advantages of using them.  I've always used them as organizational units, grouping related data, functions, and subroutines together.  You can also begin thinking about data and subprogram hiding (using PRIVATE and PUBLIC keywords), overloading functions based on argument types, and working with type-bound procedures when using modules.

Jeff Armstrong
Approximatrix, LLC