Fortran Module (CloudMonk.io)

Fortran Module



Return to Module, Fortran bibliography, Fortran, Fortran glossary, Fortran topics, Fortran glossary, Fortran courses, IBM Mainframe glossary, Awesome Fortran, Awesome IBM Mainframe, IBM Mainframe development, IBM Mainframe bibliography, COBOL, COBOL glossary

Modules are used for Fortran object oriented programming.

General form


The general form is
~~~~~~~~~~~ {: lang=fortran }
module


contains

end module
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

### Data access ##
There are three possible access properties: `public, private, protected`.

* `public`: Outside code has read and write access.
* `private`: Outside code has no access.
* `public, protected`: Outside code has read access.

### Using module in other code ###
One can include the module's public data in outside code.
There are three ways.

* `use `: includes all public data and methods
* `use , `: includes all public data and methods, but renames some public data or methods
* `use , only : `: includes only some public data and methods

### Examples ###

These examples highlight the above methods using the following module.

~~~~~~~~~~~ {: lang=fortran }
!> \\file test_module.f
module test_module
implicit none
private
integer, public :: a=1
integer, public, protected :: b=1
integer, private :: c=1
end module test_module
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#### Data access ####

~~~~~~~~~~~ {: lang=fortran }
!> \\file main.f
program main
use test_module

! accessing public object works
print *, a

! editing public object works
a = 2

! accessing protected object works
print *, b

! editing protected object does not work
!b = 2 <- ERROR

! accessing private object does not work
!print *, c <- ERROR

! editing protected object does not work
!c = 2 <- ERROR

end program main
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#### Using module in other code ####

~~~~~~~~~~~ {: lang=fortran }
!> \\file main1.f
program main
use test_module

print *, a, b

end program main
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


~~~~~~~~~~~ {: lang=fortran }
!> \\file main2.f
program main
use test_module, better_name => a

! new name use available
print *, better_name

! old name is not available anymore
!print *, a <- ERROR

end program main

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


~~~~~~~~~~~ {: lang=fortran }
!> show using only
program main
use test_module, only : a

! only a is loaded
print *, a

! b is not loaded
!print *, b <- ERROR

end program main

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




(FtrnWiki)

Research Fortran More


Fortran Research:
* ddg>Fortran Module on DuckDuckGo
* fortranwiki>Fortran Module on Fortran Wiki
* fortran>Fortran Module on Fortran-Lang.org
* fortraniso>Fortran Module on wg5-fortran.org (ISO Fortran Standards)
* fortranlib>Fortran Module on StdLib.Fortran-Lang.org
* oreilly>Fortran Module on O'Reilly
* github>Fortran Module on GitHub
* reddit>Fortran Module on Reddit
* stackoverflow>Fortran Module on StackOverflow
* scholar>Fortran Module on scholar.google.com
* youtube>Fortran Module on YouTube


Fair Use Sources


Fair Use Sources:
* B097819373 (MdFtrn 2020)
* Fortran Wiki (FtrnWiki) - https://fortranwiki.org/fortran/show/Module
* Fortran-Lang.org
* wg5-fortran.org (ISO-IEC Fortran Standards Committee)
* Fortran 2023 Draft Standard - Fortran ISO-IEC Standard

Fortran: Effective Fortran, Fortran Best Practices, Fortran Fundamentals, Fortran Inventor - Fortran Language Designer: John Backus of IBM in 1957 (see John Backus Oral History); Modern Fortran - Legacy Fortran, Fortran keywords, Fortran data structures - Fortran algorithms, Fortran syntax, IBM Mainframe DevOps, Fortran DevOps, Fortran Development Tools (Fortran IDEs and Code Editors, Fortran Compilers, Fortran CI/CD Build Tools, Fortran Standard Library), Fortran Standards (ISO Fortran: Fortran 202X | 202X, Fortran 2018 | 2018, Fortran 2018 | 2018, Fortran 2008 | 2008, Fortran 2003 | 2003, Fortran 95 | 95, Fortran 90 | 90, Fortran 77 | 77), ANSI Fortran-Fortran 66 | 66, Fortran and Supercomputers (Fortran and High-Performance Computing (HPC)), Parallel Fortran (Embarrassingly Parallel Fortran - Fortran Coarrays), Fortran Paradigms (Imperative Fortran, Procedural Fortran, [[Object-Oriented

Fortran]] - Fortran OOP, Functional Fortran), Fortran Community, Learning Fortran, Fortran on Windows, Fortran on Linux, Fortran on UNIX, Fortran on macOS, Mainframe Fortran, IBM i Fortran, Fortran installation, Fortran containerization, Fortran configuration, Fortran SRE, Fortran data science - Fortran DataOps, Fortran machine learning, Fortran deep learning, Fortran concurrency, Fortran history, Fortran bibliography, Fortran Glossary - Glossaire de Fortran - French, Fortran topics, Fortran courses, Fortran Standard Library, Fortran libraries, Fortran frameworks, Fortran research, Fortran GitHub, Written in Fortran, Fortran popularity, Fortran Awesome list, Fortran Versions. (navbar_fortran - see also navbar_cobol, navbar_mainframe)

----



Cloud Monk is Retired (impermanence |for now). Buddha with you. Copyright | © Beginningless Time - Present Moment - Three Times: The Buddhas or Fair Use. Disclaimers



SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.



----