You are missing & in ccall for variables that put as Int64 but expected to 
be passed as Ptr{Int64}.

ccall( (:gcvspl_, "./libgcvspl.so"), Void, (Ptr{Float64},Ptr{Float64},Ptr{
Int64},Ptr{Float64},Ptr{Float64},Ptr{Int64},Ptr{Int64},Ptr{Int64},Ptr{Int64
},Ptr{Float64},Ptr{Float64},Ptr{Int64},Ptr{Float64},Ptr{Int64}),x,y,&NN,wx,
wy,&M,&N,&K,&MD,VAL,c,&NC,WK,&IER)

I would make IER one element array since it needs to be retrieved as output.

IER=Int64[0]

then it is

ccall( (:gcvspl_, "./libgcvspl.so"), Void, (Ptr{Float64},Ptr{Float64},Ptr{
Int64},Ptr{Float64},Ptr{Float64},Ptr{Int64},Ptr{Int64},Ptr{Int64},Ptr{Int64
},Ptr{Float64},Ptr{Float64},Ptr{Int64},Ptr{Float64},Ptr{Int64}),x,y,&NN,wx,
wy,&M,&N,&K,&MD,VAL,c,&NC,WK,IER)

On Monday, June 6, 2016 at 6:22:47 AM UTC+3, Charles Ll wrote:
>
> Dear all,
>
> I am trying to call some Fortran code in Julia, but I have a hard time 
> doing so... I have read the docs, looked at the wrapping of ARPACK and 
> other libraries... But I did not find any way to make it work.
>
> I am trying to wrap a spline function library (gcvspl.f, 
> https://github.com/charlesll/Spectra.jl/tree/master/Dependencies), which 
> I want to use in my project, Spectra.jl.
>
> I already have a wrapper in Python, but this was easier to wrap with using 
> f2py. In Julia, I understand that I have to do it properly. The function I 
> am trying to call is:
> GCVSPL ( X, Y, NY, WX, WY, M, N, K, MD, VAL, C, NC, WK, IER) (LINE 42 of 
> GCVSPL.f)
>
>
> X(N)            ( I )   Independent variables, Float64
> Y(NY,K)       ( I )   Input data to be smoothed (or interpolated), Float64
> NY               ( I )   First dimension of array Y(NY,K), with NY.ge.N, 
> Integer
> WX(N)         ( I )   Weight factor array, Float64
> WY(K)         ( I )   Weight factor array, Float64
> M                 ( I )   M = 1,2,3,4 correspond to linear, cubic, quintic
> , and heptic splines, respectively. Integer
> N                 ( I )   Number of observations per dataset, Integer
> K                ( I )   Number of datasets, with K.ge.1., Integer
> MD             ( I )   Optimization mode switch, Integer
> VAL            ( I )   Mode value, as described above under MD., Array of 
> Float64
> C(NC,K)    ( O )   Spline coefficients, Array of Float64
> NC             ( I )  First dimension of array C(NC,K), NC.ge.N., Integer
> WK(IWK) (I/W/O) Work vector, IWK.ge.6*(N*M+1)+N, Array of Float64
> IER            ( O )   Error parameter, Integer
>
> with I and O designating Inputs and Outputs, respectively. From this and 
> my previous Python wrap, I generated a fake dataset and tried to use this 
> function with ccall:
>
> x = collect(0.0:1.0:100)
> y = 2.0.*x.^2 - 100.0 + x +0.0003.*x.^5
> ese = y./10000
>
>
> NN::Int64 = length(y)
> wx = 1./(ese.^2) # relative variance of observations
> wy = zeros([1])+1 # systematic errors... not used so put them to 1, works 
> under the Python wrap
> VAL = ese.^2
>
>
> M::Int64 = 2
> N::Int64 = length(x)
> K::Int64 = 1 # number of y columns
> MD::Int64 = 2 #spline mode
> NC::Int64 = length(y)
>
> # initialising stuffs for outputs... isit the right way?
> c = ones(NN,NC)
> WK = [1.,1.,1.,1.,1.,1.]
> IER::Int64 = 0
>
>
> ccall( (:gcvspl_, "./libgcvspl.so"), Void, (Ptr{Float64},Ptr{Float64},Ptr{
> Int64},Ptr{Float64},Ptr{Float64},Ptr{Int64},Ptr{Int64},Ptr{Int64},Ptr{
> Int64},Ptr{Float64},Ptr{Float64},Ptr{Int64},Ptr{Float64},Ptr{Int64}),x,y,
> NN,wx,wy,M,N,K,MD,VAL,c,NN,WK,IER)
>
> This code does not work, returning me some convert problems... Notably, I 
> get this one:
>
> LoadError: MethodError: `convert` has no method matching 
> convert(::Type{Ptr{Float64}}, ::Array{Int64,1})
>
>
> That I don't understand... In the "examples" (code already wrapped...) 
> available online, that was the way people wrapped stuffs... 
>
> Do anyone has some clue about doing this wrapping? The gcvspl.f code is 
> available in 
> https://github.com/charlesll/Spectra.jl/tree/master/Dependencies .
>
> Thanks in advance!
>
> Best,
> Charles.
>
>
>

Reply via email to