aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2024-01-31 14:02:27 +0100
committerThomas White <taw@physics.org>2024-02-06 16:59:35 +0100
commitc1cd21679686f59d8f3533145108118419b40356 (patch)
tree75fb561492ab6d721fcdd52fa744814dfa0be9ee
parentcaf4062de65c47146965a8d8caadbf9b642405b7 (diff)
Julia: Add chunkread()
-rw-r--r--julia/CrystFEL/src/CrystFEL.jl2
-rw-r--r--julia/CrystFEL/src/streams.jl19
2 files changed, 19 insertions, 2 deletions
diff --git a/julia/CrystFEL/src/CrystFEL.jl b/julia/CrystFEL/src/CrystFEL.jl
index 230def00..86637014 100644
--- a/julia/CrystFEL/src/CrystFEL.jl
+++ b/julia/CrystFEL/src/CrystFEL.jl
@@ -76,7 +76,7 @@ export Indexer, index
include("streams.jl")
using .Streams
-export Stream, chunkwrite
+export Stream, chunkwrite, chunkread
include("millepede.jl")
using .Millepede
diff --git a/julia/CrystFEL/src/streams.jl b/julia/CrystFEL/src/streams.jl
index 29f0de5d..d5c86464 100644
--- a/julia/CrystFEL/src/streams.jl
+++ b/julia/CrystFEL/src/streams.jl
@@ -3,7 +3,7 @@ module Streams
import ..CrystFEL: libcrystfel
import ..CrystFEL.DataTemplates: DataTemplate, InternalDataTemplate
import ..CrystFEL.Images: Image, InternalImage
-export Stream, chunkwrite
+export Stream, chunkwrite, chunkread
# Represents the real C-side (opaque) structure.
mutable struct InternalStream end
@@ -98,6 +98,7 @@ end
function chunkwrite(st::Stream, image::Image; peaks=true, reflections=true)
+ st.internalptr == C_NULL && throw(ErrorException("Stream is closed"))
flags = streamflags(peaks, reflections, false)
@ccall libcrystfel.stream_write_chunk(st.internalptr::Ptr{InternalStream},
image.internalptr::Ptr{InternalImage},
@@ -105,4 +106,20 @@ function chunkwrite(st::Stream, image::Image; peaks=true, reflections=true)
end
+function chunkread(st::Stream; peaks=true, reflections=true)
+
+ st.internalptr == C_NULL && throw(ErrorException("Stream is closed"))
+
+ flags = streamflags(peaks, reflections, true)
+ out = @ccall libcrystfel.stream_read_chunk(st.internalptr::Ptr{InternalStream},
+ flags::Cint)::Ptr{InternalImage}
+ out == C_NULL && return nothing
+
+ finalizer(Image(out, nothing, [], [])) do x
+ ccall((:image_free, libcrystfel), Cvoid, (Ptr{InternalImage},), x.internalptr)
+ end
+
+end
+
+
end # of module