![]() ![]() Real function circle ( x ) result ( ans ) real, intent ( in ), value :: x ans = sqrt ( 4. ![]() , 3.14 ) name = "cos" cf = choose_func ( c_loc ( name )) f => wapper print *, real_integral ( f, 0. , 2.0 ) name = "sin" cf = choose_func ( c_loc ( name )) ! c 函数指针赋值给 FortranĬall c_f_procpointer ( cf, f ) print *, real_integral ( f, 0. Real ( c_float ), intent ( in ), value :: x end functionĬharacter ( len = :), allocatable, target :: name procedure ( real_func ), pointer :: f type ( c_funptr ) :: cf ! 使用 Fortran 原生的函数指针į => circle print *, real_integral ( f, 0. If I understand the terminology correctly, the second argument of each of the 4 write statements in my example is the fmt argument, each of which contains 3 edit descriptors. Real ( c_float ) function float_func ( x ) import :: c_float Well, to be pedantic IIRC that is Fortran 95, so if youre really strict about no more than F90, then I suppose this wont work. Type ( c_ptr ), value, intent ( in ) :: c_name type ( c_funptr ) :: choose_func end function Impure real function real_integral ( f, a, b, N ) result ( ans ) procedure ( real_func ), pointer, intent ( in ) :: f real, intent ( in ) :: a, b integer, optional :: N integer :: Npoints, i real :: x, h Npoints = 10000 if ( present ( N )) Npoints = N h = ( b - a ) / Npoints ans = 0.0 do i = 1, Npoints x = a + ( i - 0.5 ) * h ans = ans + f ( x ) end doĮnd module integral_m program test use iso_c_bindingįunction choose_func ( c_name ) bind ( c ) import :: c_ptr, c_funptr ! const char*,但是 `ios_c_binding` 只有`c_ptr`类型 Views: Print TeX Source Linked from: HomePage, Standards. The final draft of the Fortran 2008 standard, ISO/IEC JTC 1/SC 22/WG 5/N1830, was released on Jand is available from the WG5’s FTP server at ftp. Real function real_func ( x ) real, intent ( in ), value :: x end function Fortran 2008 is a minor revision of Fortran 2003. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |