Read a container back from an open stream unit.
Validates the envelope and the schema string before touching any
payload, so a stream written from a different field list is rejected
with ERROR_VALIDATION rather than decoded as garbage. Every field
record must hold exactly the element count the prologue announced.
On success the container holds exactly the elements from the stream and its capacity equals its size. On failure it is left deallocated rather than half filled.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(particle_soa_t), | intent(inout) | :: | this |
Container to fill. Any previous contents are discarded. |
||
| integer(kind=default_int), | intent(in) | :: | unit |
Stream unit opened for unformatted stream reading. |
||
| type(error_t), | intent(inout) | :: | err |
Error state, |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=default_int), | private | :: | n | ||||
| logical, | private | :: | swapped |
subroutine particle_soa_deserialize(this, unit, err) !! Read a container back from an open stream unit. !! !! Validates the envelope and the schema string before touching any !! payload, so a stream written from a different field list is rejected !! with `ERROR_VALIDATION` rather than decoded as garbage. Every field !! record must hold exactly the element count the prologue announced. !! !! On success the container holds exactly the elements from the stream !! and its capacity equals its size. On failure it is left deallocated !! rather than half filled. class(particle_soa_t), intent(inout) :: this !! Container to fill. Any previous contents are discarded. integer(default_int), intent(in) :: unit !! Stream unit opened for unformatted stream reading. type(error_t), intent(inout) :: err !! Error state, `ERROR_VALIDATION` on a layout or length mismatch and !! `ERROR_IO` on a truncated stream. integer(default_int) :: n logical :: swapped call this%deallocate() call soa_read_prologue(unit, PARTICLE_SOA_SCHEMA, n, swapped, err) if (err%has_error()) return call soa_read_field(unit, "id", this%id, n, swapped, err) if (err%has_error()) then call this%deallocate() return end if call soa_read_field(unit, "x", this%x, n, swapped, err) if (err%has_error()) then call this%deallocate() return end if call soa_read_field(unit, "y", this%y, n, swapped, err) if (err%has_error()) then call this%deallocate() return end if call soa_read_field(unit, "z", this%z, n, swapped, err) if (err%has_error()) then call this%deallocate() return end if call soa_read_field(unit, "mass", this%mass, n, swapped, err) if (err%has_error()) then call this%deallocate() return end if call soa_read_field(unit, "active", this%active, n, swapped, err) if (err%has_error()) then call this%deallocate() return end if this%extent%used = n this%extent%capacity = n end subroutine particle_soa_deserialize