Forpedo in Fortran Wiki
**Forpedo** is a preprocessor for [[Fortran 90]] code, written in Python. It performs some typical preprocessing tasks, such as including code from one file in another, but it is mostly designed to assist with advanced techniques in pre-[[Fortran 2003]] versions of the language. In particular, there is support for C++ like [[Generic programming|generics]] (templates), and run-time polymorphism from [[Object-oriented programming]]. The output of Forpedo is standard Fortran code. The output generated is clean, as if it were written by a programmer, so that if at some point you stop using Forpedo, you will be left with a high-quality body of code. Forpedo was announced on November 24, 2004. Support for run-time polymorphism was announced on February 16, 2006. Homepage: <http://www.macanics.net/forpedo/> ## Run-Time Polymorphism To define a polymorphic type (known as a 'protocol') with Forpedo, you can do something like this: ~~~~~ {: lang=fortran } #protocol AnimalProtocol AnimalProtocolMod #method makeSound type(AnimalProtocol), intent(in) :: self #endmethod #method increaseAgeInAnimalYears increase type(AnimalProtocol), intent(inout) :: self integer, intent(in) :: increase #endmethod #conformingtype Dog DogMod #conformingtype Cat CatMod #endprotocol ~~~~~ To use the type: ~~~~~ {: lang=fortran } program Main use AnimalProtocolMod use DogMod use CatMod type (Dog), target :: d type (Cat), target :: c type (AnimalProtocol) :: p ! Assign protocol to Dog p = d ! Pass pointer to a subroutine that knows nothing about the concrete type Dog call doStuffWithAnimal(p) ! Repeat for Cat. Results will be different, though subroutine call is the same. p = c call doStuffWithAnimal(p) contains subroutine doStuffWithAnimal(a) type (AnimalProtocol) :: a call makeSound(a) call increaseAgeInAnimalYears(a, 2) end subroutine end program ~~~~~ ----- ## See Also * [[Preprocessors]] * [[Tools]] ## External Links * [Forpedo homepage](http://www.macanics.net/forpedo/) * [[ANN] Forpedo: A (python-written) preprocessor for Fortran generics](http://groups.google.com/group/comp.lang.python/browse_thread/thread/e90616957838fff4), [[comp lang fortran|comp.lang.fortran]], 27 Nov 2004. * [Forpedo Preprocessor Now Supports Run-Time Polymorhpism](http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/15e547f524f4d58e) [[comp lang fortran|comp.lang.fortran]], 16 Feb 2006. ## References * McCormack, D. (2005). [Generic programming in Fortran with Forpedo](http://doi.acm.org/10.1145/1080399.1080401) *Fortran Forum*, 24, 18-29.
AltStyle
によって変換されたページ
(->オリジナル)
/
アドレス:
モード:
デフォルト
音声ブラウザ
ルビ付き
配色反転
文字拡大
モバイル