Yes, the full code and the test notebook that I used to try calling the
spline is available in the dependencies folder of Spectra.jl (on
Github: https://github.com/charlesll/Spectra.jl). See also the full code at
the end of this message.
I can call the ccall, but when I try to call the c or IER variables, the
kernel dies. No error message at all...
I cannot do anything today as I can't call PyPlot since the last
Pkg.update().... At the time I call the libraries, I get some message error
that "__precompile__(true) but require failed to create a precompiled cache
file". I got a lot of Warning regarding Compat.jl so I think I got a flaw
in my install around this library... Anyway, I need to move on on my
research for now, so I will go back to Matlab to use csaps... I would like
to solve this problem for future work though.
Thanks for helping with that!
Here is the full code in the test notebook I used:
using PyPlot
x = collect(0.0:1.0:100)
y = 2.0.*x.^2 - 100.0 + x +0.0003.*x.^5
plot(x,y)
ese = y./100
NN = length(y)
wx = 1. ./(ese.^2) # relative variance of observations
wy = zeros([1])+1. # systematic errors... not used so put them to 1
VAL = ese.^2
M = 2
N = length(x)
K = 1 # number of y columns
MD = 2 #spline mode
NC = length(y)
c = ones(NN,NC)
WK = [1.,1.,1.,1.,1.,1.]
IER=Int32[0]
ccall( (:gcvspl_, "./libgcvspl.so"), Void,
(Ptr{Float64},Ptr{Float64},Ptr{Cint},Ptr{Float64},Ptr{Float64},Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{Float64},Ptr{Float64},Ptr{Cint},Ptr{Float64},Ptr{Cint}),x,y,&NN,wx,wy,&M,&N,&K,&MD,VAL,c,&NC,WK,IER)
Le mercredi 8 juin 2016 11:44:19 UTC+10, Erik Schnetter a écrit :
>
> Charles
>
> Can you show the complete code, including the definitions of `c` and `IER`?
>
> Can you also show how you "call" these variables, and what the error
> message is?
>
> The more detail you give, the easier it is to help.
>
> -erik
>
>
> On Mon, Jun 6, 2016 at 8:16 PM, Charles Ll <[email protected]
> <javascript:>> wrote:
>
>> Dear all,
>>
>> Thank you very much for you help! I've been able to write a form of
>> gcvspl that seems to run, with calling:
>>
>> ccall( (:gcvspl_, "./libgcvspl.so"), Void,
>> (Ptr{Float64},Ptr{Float64},Ptr{Cint},Ptr{Float64},Ptr{Float64},Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{Cint},Ptr{Float64},Ptr{Float64},Ptr{Cint},Ptr{Float64},Ptr{Cint}),x,y,&NN,wx,wy,&M,&N,&K,&MD,VAL,c,&NC,WK,IER)
>>
>>
>> However, when I try to call the c or IER variables, the Julia kernel
>> dies... :s
>>
>> Do you have any idea why? What am I missing?
>>
>> Furthermore, dear Erik, what do you mean by using 'Ref' for one-element
>> arrays?
>>
>> Thanks in advance!
>>
>> Best,
>> Charles.
>>
>> Le lundi 6 juin 2016 22:12:32 UTC+10, Erik Schnetter a écrit :
>>>
>>> I would use `Cint` as type, not `Int64`, as in `Ptr{Cint}`. Are you sure
>>> that your Fortran code uses 64-bit integers? Technically, this violates the
>>> Fortran standard. A Fortran integer is the same as a C int, except if you
>>> use special flags while building the Fortran library (which you might be
>>> doing).
>>>
>>> You can use `Ref` instead of one-element arrays.
>>>
>>> Your error message has nothing to do with arrays vs. pointer, but rather
>>> the mismatch between `Float64` and `Int64`.
>>>
>>> -erik
>>>
>>>
>>> On Mon, Jun 6, 2016 at 6:07 AM, Páll Haraldsson <[email protected]>
>>> wrote:
>>>
>>>> On Monday, June 6, 2016 at 3:22:47 AM UTC, 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:
>>>>>
>>>>
>>>> I think, you may already have gotten the correct answer. At first I was
>>>> expecting fcall, not just ccall keyword in Julia, to call Fortran.. It's
>>>> not strictly needed, but in fact, there is an issue somewhere still open
>>>> about fcall (keyword, or was if for a function?), and it may have been for
>>>> your situation..
>>>>
>>>>
>>>> [It might not be too helpful to know, you can call Python with
>>>> PyCall.jl, so if you've already wrapped in Python..]
>>>>
>>>> --
>>>> Palli.
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Erik Schnetter <[email protected]>
>>> http://www.perimeterinstitute.ca/personal/eschnetter/
>>>
>>
>
>
> --
> Erik Schnetter <[email protected] <javascript:>>
> http://www.perimeterinstitute.ca/personal/eschnetter/
>