From c1cd21679686f59d8f3533145108118419b40356 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 31 Jan 2024 14:02:27 +0100 Subject: Julia: Add chunkread() --- julia/CrystFEL/src/CrystFEL.jl | 2 +- julia/CrystFEL/src/streams.jl | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'julia') 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 -- cgit v1.2.3