aboutsummaryrefslogtreecommitdiff
path: root/julia/CrystFEL/src/millepede.jl
blob: a65256dc75bec7a35925dad3b1cd99e76bb5b95a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module Millepede

import ..CrystFEL: libcrystfel
export Mille

mutable struct InternalMille end

mutable struct Mille
    internalptr::Ptr{InternalMille}
end


"""
    Mille(filename)

Creates a new "Mille" object, which can be passed to `CrystFEL.Indexing.index()`
to accumulate detector geometry alignment information in the specified file.

When you've finished adding data, call `close()` on the Mille object.  This will
be done automatically when the object is freed by the garbage collector, but
that might not happen until Julia exits.

Corresponds to CrystFEL C API routine `crystfel_mille_new`.
"""
function Mille(filename::AbstractString)
    out = @ccall libcrystfel.crystfel_mille_new(filename::Cstring)::Ptr{InternalMille}
    if out == C_NULL
        throw(ArgumentError("Failed to create Millepede object"))
    end
    finalizer(close, Mille(out))
end


function Base.close(x::Mille)
    if x.internalptr != C_NULL
        @ccall libcrystfel.crystfel_mille_free(x.internalptr::Ptr{InternalMille})::Cvoid
        x.internalptr = C_NULL
    end
end


end  # of module