[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-gsl] Linking gsl library with fortran 90

From: Brijesh Upadhaya
Subject: [Help-gsl] Linking gsl library with fortran 90
Date: Wed, 12 Oct 2016 02:12:18 +0300


I am trying to use the function gsl_sort_vector(V) from the gsl library in
my fortran90 code. I use a linux based operating system with gfortran-4.9
as the fortran compiler. I have previously compiled a c-function with the
fortran90 as main program but now with gsl I couldn't do so.

Here goes the code
program test_gsl

  use, intrinsic :: ISO_C_BINDING

  implicit none
  integer, parameter :: dp = selected_real_kind(12)
  integer :: j
  integer, dimension(1:2) :: order1 = (/2,1/)
  real(dp), dimension(1:9) :: A
  real(dp), dimension(:,:), allocatable :: tidx, tsort

    ! gsl C function void gsl_sort_vector(gsl vector * v) ascending order
    function gsl_sort_vector(data) bind(C,name="gsl_sort_vector")
      use, intrinsic :: ISO_C_BINDING
      implicit none
      real(kind=C_DOUBLE), intent(IN) :: data(*)
      real(kind=C_DOUBLE) :: tsort
    end function gsl_sort_vector
  end interface

  allocate(tidx(1:3,1:3), tsort(1:3,1))

  A = (/1,2,3,4,5,6,7,8,9/)
  tidx = RESHAPE(A, (/3,3/), ORDER=order1 )
  print *, (tidx(j,:),j=1,3)

  tsort = gsl_sort_vector(tidx(:,1))

  print *, tsort

  ! print *, (tsort(j,:),j=1,3)

end program test_gsl

It would be really nice to get some suggestion on linking as well.

Best regards,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]