Clicky

Fortran Wiki
PreForM.py (changes)

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

Showing changes from revision #0 to #1: (追記) Added (追記ここまで) | (削除) Removed (削除ここまで) | (削除) Chan (削除ここまで)(追記) ged (追記ここまで)

PreForM.py is a pre-processor for modern Fortran projects, written in Python.

Homepage: https://github.com/szaghi/PreForM

PreForM.py supports the most used cpp pre-processing directives and provides advanced features typical of templating systems.

As a matter of fact, many Fortran developers use cpp, the C pre-processor, being one of the most diffused and standardised pre-processor. cpp is a great pre-processor, but it is basically a macro processor, meaning that it is quite focused on macro expansion/substitution/evaluation. cpp has some limitations that makes complex using it as a template system. Let us suppose we want to write a generic interface as the following:

...
interface foo
 module procedure foo1
 module procedure foo2
 module procedure foo3
endinterface
contains
 function foo1(in) result(out)
 type(first), intent(IN):: in
 logical:: out
 out = in%logical_test()
 endfunction foo1
 function foo2(in) result(out)
 type(second), intent(IN):: in
 logical:: out
 out = in%logical_test()
 endfunction foo2
 function foo3(in) result(out)
 type(third), intent(IN):: in
 logical:: out
 out = in%logical_test()
 endfunction foo3
...

Writing a macro in cpp syntax to generalize such a generic interface implementation is quite impossible. On the contrary, using PreForM.py as a template system the implementation becomes very simple and elegant:

...
interface foo
 #PFM for i in [1,2,3]:
 module procedure foo$i
 #PFM endfor
endinterface
contains
 #PFM for i in [1,2,3] and t in [first,second,third]:
 function foo$i(in) result(out)
 type($t), intent(IN):: in
 logical:: out
 out = in%logical_test()
 endfunction foo$i
 #PFM endfor
...

PreForM.py is just a pre-processor for Fortran poor-men supporting the most used cpp directives, but overtaking some of the cpp limitations in order to make PreForM.py similar to a template system using directly the power of Python syntax.

Even if PreForM.py is currently Fortran-agnostic (it being usable within any programming languages) it is focused on Fortran programming language.

See Also

Created on July 30, 2014 12:36:12 by szaghi (150.146.145.254) (2302 characters / 1.0 pages)
Edit | Views: Print | TeX | Source | Linked from: Preprocessors

AltStyle によって変換されたページ (->オリジナル) /