Clicky

Fortran Wiki
Forpedo (changes)

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

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

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 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:

#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:

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. (追記ここまで)(削除) 
 (削除ここまで)(削除) 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

(追記ここまで)
(追記) (追記ここまで)(追記) (追記ここまで)(追記) (追記ここまで)

References

Revised on April 6, 2010 12:10:11 by Jason Blevins (75.178.9.182) (2642 characters / 1.0 pages)
Edit | Back in time (1 revision) | Hide changes | History | Views: Print | TeX | Source | Linked from: 2009, Preprocessors

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