Thanks for clearing up my confusion, really learning a lot here.
I am trying to implement the code @dawbarton wrote in his reply ie:
_readel(ft::IOStream, typ) = read(ft, typ)
_readel(ft::IOStream, typ::Type{<:SVector{3, T}}) where T = SVector(_readel(ft, T), _readel(ft, T), _readel(ft, T))
function _transferDataBi4(ft::IOStream, arrayVal::AbstractVector)
typ = eltype(arrayVal)
sz = length(arrayVal)
for i in eachindex(arrayVal)
if !eof(ft)
arrayVal[i] = _readel(ft, typ)
end
end
end
So it is working great for the density property and getting the result as expected:
a[1]
125751-element Array{Float32,1}:
1000.0
1000.0
1000.0
1000.0
1000.0
1000.0
1000.0
1000.0
1000.0
1000.0
1000.0
1000.0
...
This makes sense because it is running on the normal array format as before. I am having trouble with the SVector format since I do not know how to preallocate it properly. My confusion stems from that in the end I want a N by 3 matrix, but the example code I am using is only for vectors. Currently in my code I am preallocating like this:
j[i] = zeros(catTypeBi4[typ], dim)
Where catTypeBi4[typ] is either Float32 or Int32, while dim in the case of rhop is (N,) or in the case of velocity is (N,3). I really want to do this the static array way, so feedback would be much appreciated. I will continue trying. The error in the original code is stated as such:
@time readBi4Array(Vel)
ERROR: MethodError: no method matching _transferDataBi4(::IOStream, ::Array{Float32,2})
Closest candidates are:
_transferDataBi4(::IOStream, ::AbstractArray{T,1} where T) at REPL[66]:2
Stacktrace:
[1] readBi4Array(::Cat, ::Bool) at .\REPL[70]:26
[2] readBi4Array(::Cat) at .\REPL[70]:2
[3] top-level scope at util.jl:156
Kind regards