- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm trying to make use of a gsl function to compute wigner 3j symbols within a fortran program.
I'm having a problem that my program works when I pass constants to the c function but not when I pass variables (the gsl function raises an exception). I have included a simple test case
which was compiled with the command
ifort test_gsl.f90 -lgsl -lgslcblas
the program code is
program test_gsl
use iso_c_binding
implicit none
interface
real(c_double) function gsl_sf_coupling_3j&
(l1, l2, l3, m1, m2, m3) bind(c)
use iso_c_binding
integer(c_int) :: l1, l2, l3, m1, m2, m3
end function gsl_sf_coupling_3j
end interface
real(c_double) :: wigner3j
integer(c_int) :: j
!this bit works
wigner3j = gsl_sf_coupling_3j(4, 4, 4, 0, 0, 0)
print*, wigner3j
!this bit doesn't work
j = 4_c_int
wigner3j = gsl_sf_coupling_3j(j, j, j, 0, 0, 0)
print*, wigner3j
end program test_gsl
thanks in advance for any suggestions!
Jeremy
I'm trying to make use of a gsl function to compute wigner 3j symbols within a fortran program.
I'm having a problem that my program works when I pass constants to the c function but not when I pass variables (the gsl function raises an exception). I have included a simple test case
which was compiled with the command
ifort test_gsl.f90 -lgsl -lgslcblas
the program code is
program test_gsl
use iso_c_binding
implicit none
interface
real(c_double) function gsl_sf_coupling_3j&
(l1, l2, l3, m1, m2, m3) bind(c)
use iso_c_binding
integer(c_int) :: l1, l2, l3, m1, m2, m3
end function gsl_sf_coupling_3j
end interface
real(c_double) :: wigner3j
integer(c_int) :: j
!this bit works
wigner3j = gsl_sf_coupling_3j(4, 4, 4, 0, 0, 0)
print*, wigner3j
!this bit doesn't work
j = 4_c_int
wigner3j = gsl_sf_coupling_3j(j, j, j, 0, 0, 0)
print*, wigner3j
end program test_gsl
thanks in advance for any suggestions!
Jeremy
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
the interface is not correctly specified; according to the GSL reference manual the integer arguments are passed by value. ifort supports this, so you need to declare:
integer(c_int), value :: l1, l2, l3, m1, m2, m3
[I suspect the compiler assumes intent(inout) for your code and hence performs
copy-in if constants are provided].
While we're at it, I guess I can now shamelessly plug FGSL:
http://www.lrz-muenchen.de/services/software/mathematik/gsl/fortran/index.html
Regards
the interface is not correctly specified; according to the GSL reference manual the integer arguments are passed by value. ifort supports this, so you need to declare:
integer(c_int), value :: l1, l2, l3, m1, m2, m3
[I suspect the compiler assumes intent(inout) for your code and hence performs
copy-in if constants are provided].
While we're at it, I guess I can now shamelessly plug FGSL:
http://www.lrz-muenchen.de/services/software/mathematik/gsl/fortran/index.html
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Great, that works.
I found fgsl about 5 minutes after posting my original message. It's an interesting project.
Unfortunately I needed to compute wigner 3j symbols and it turns out the gsl code isn't great at this; overflows for large angular momenta.
many thanks
Jeremy
I found fgsl about 5 minutes after posting my original message. It's an interesting project.
Unfortunately I needed to compute wigner 3j symbols and it turns out the gsl code isn't great at this; overflows for large angular momenta.
many thanks
Jeremy

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page