Commit 7257bcfa authored by Alberto Ramos's avatar Alberto Ramos

Added trajectory ID to I/O format

parent 8ca2d6ad
......@@ -200,7 +200,7 @@ All observables are stored in a single `BDIO` record of type `BDIO_BIN_GENERIC`.
- neid (`Int32`): The number of ensembles contributing to the observable.
- ndata (`Vector{Int32}(neid)`): The length of each ensemble.
- nrep (`Vector{Int32}(neid)`): The number of replica of each enemble.
- vrep (`Vector{Int32}`): The replica vector for each ensemble.
- vrep (`Vector{Int32}`): A vector with length the number of replica that contains the number of measurements in each replica.
- ids (`Vector{Int32}(neid)`): The ensemble numeric `ID`'s.
- nt (`Vector{Int32}(neid)`): Half the largest replica of each ensemble.
- zero (`Vector{Float64}(neid)`): just `neid` zeros.
......@@ -208,9 +208,10 @@ All observables are stored in a single `BDIO` record of type `BDIO_BIN_GENERIC`.
- delta (`Vector{Float64}`): The fluctuations for each ensemble.
- name (NULL terminated `String`): A description of the observable.
- `ID` tags: A list of `neid` tuples `(Int32, String)` that maps each numeric `ID` to an ensemble tag. All strings are NULL terminated.
- Replica names: A list of `neid` tuples `(Int32, Vector{String})`
that maps each numeric `ID` to a vector of replica names. All
strings are NULL terminated.
- Replica details: `neid` times the following information:
- First an `Int32` wiht the numeric `ID` tag of the ensemble.
- Then a `Vector{String}` that contains the replica names.
- Finally a `Vector{Int32}` that contains the the configuration index where each measurement has been performed.
!!! alert
Obviously this weird format is what it is for some legacy reasons, but it is strongly encouraged that new implementations respect this standard with all its weirdness.
......
......@@ -34,7 +34,7 @@ include("ADerrorsUtils.jl")
export err, value, derror, taui, dtaui, window, rho, drho, details, ensembles, mchist
export uwreal, uwerr, change_id
export cov, trcov, trcorr, neid
export cov, trcov, trcorr, neid, derivative
export read_uwreal, write_uwreal
export addobs, cobs
export root_error, chiexp, fit_error, int_error
......
......@@ -90,21 +90,28 @@ function get_name_from_id(id::Int64, ws::wspace)
return str
end
function add_repnames(id::Int64, ws::wspace, rname::Vector{String})
function add_repnames(id::Int64, ws::wspace, rname::Vector{String},
ridc::Vector{Int64})
if haskey(ws.repnam, id)
for i in 1:length(rname)
if rname[i] != ws.repnam[id][i]
error("Mistmatch in replica names for ensemble: "*get_name_from_id(id,ws))
end
if ridc[i] != ws.repidc[id][i]
error("Mistmatch in replica configuration index for ensemble: "
*get_name_from_id(id,ws)*" replicum: "*rname[i])
end
end
else
ws.repnam[id] = rname
ws.repidc[id] = ridc
end
end
get_repnames_from_id(id::Int64, ws::wspace) = ws.repnam[id]
get_repidc_from_id(id::Int64, ws::wspace) = ws.repidc[id]
function add_maps(id::Int64, ws::wspace, iv::Vector{Int64})
......@@ -699,7 +706,8 @@ wsg = ADerrors.wspace(similar(Vector{ADerrors.fbd}, 0),
similar(Vector{Int64}, 0),
Dict{Int64, Int64}(),
Dict{Int64, String}(), Dict{String, Int64}(),
Dict{Int64, Vector{String}}(),
Dict{Int64, Vector{String}}(),
Dict{Int64, Vector{Int64}}(),
-12345)
get_id_from_name(str::String) = get_id_from_name(str, wsg)
......@@ -839,35 +847,30 @@ uwreal(x::Float64) = ADerrors.uwreal(x, 0.0, 0.0,
Vector{Int64}(), Vector{cfdata}())
uwreal(data::Vector{Float64},
id::Int64) = ADerrors.uwcls(data,
id,
wsg,
[length(data)])
id::Int64) = uwreal(data,
string(id))
uwreal(data::Vector{Float64},
id::Int64,
iv::Vector{Int64}) = ADerrors.uwcls(data,
id,
wsg,
iv)
iv::Vector{Int64}) = uwreal(data,
string(id),
iv)
uwreal(data::Vector{Float64},
id::Int64,
idm::Vector{Int64},
nms::Int64) = ADerrors.uwcls_gaps(data,
id,
wsg,
[nms],
idm,
nms)
nms::Int64) = uwreal(data,
string(id),
[nms],
idm,
nms)
uwreal(data::Vector{Float64},
id::Int64,
iv::Vector{Int64},
idm::Vector{Int64},
nms::Int64) = ADerrors.uwcls_gaps(data,
id,
wsg,
iv,
idm,
nms)
nms::Int64) = uwreal(data,
string(id),
iv,
idm,
nms)
function uwreal(data::Vector{Float64}, str::String)
uw = ADerrors.uwcls(data,
......@@ -875,7 +878,8 @@ function uwreal(data::Vector{Float64}, str::String)
wsg,
[length(data)])
v = [str*"_r0"]
add_repnames(get_id_from_name(str, wsg), wsg, v)
idc = collect(1:length(data))
add_repnames(get_id_from_name(str, wsg), wsg, v, idc)
return uw
end
......@@ -886,10 +890,17 @@ function uwreal(data::Vector{Float64},
uw = ADerrors.uwcls(data, get_id_from_name(str, wsg), wsg, iv)
v = Vector{String}(undef, length(iv))
idc = Vector{Int64}(undef, length(data))
iof = 0
for i in 1:length(v)
v[i] = str*"r"*string(i-1)
for k in 1:iv[i]
idc[k+iof] = k
end
iof = iof + iv[i]
end
add_repnames(get_id_from_name(str, wsg), wsg, v)
add_repnames(get_id_from_name(str, wsg), wsg, v, idc)
return uw
end
......@@ -905,7 +916,8 @@ function uwreal(data::Vector{Float64},
idm,
nms)
v = [str*"_r0"]
add_repnames(get_id_from_name(str, wsg), wsg, v)
idc = collect(1:nms)
add_repnames(get_id_from_name(str, wsg), wsg, v, idc)
return uw
end
......@@ -921,10 +933,16 @@ function uwreal(data::Vector{Float64},
idm,
nms)
v = Vector{String}(undef, length(iv))
idc = Vector{Int64}(undef, length(data))
iof = 0
for i in 1:length(v)
v[i] = str*"r"*string(i-1)
for k in 1:iv[i]
idc[k+iof] = k
end
iof = iof + iv[i]
end
add_repnames(get_id_from_name(str, wsg), wsg, v)
add_repnames(get_id_from_name(str, wsg), wsg, v, idc)
return uw
end
......@@ -935,7 +953,8 @@ function uwreal(data::Vector{Float64}, str::String, rname::Vector{String})
get_id_from_name(str, wsg),
wsg,
[length(data)])
add_repnames(get_id_from_name(str, wsg), wsg, rname)
idc = collect(1:length(data))
add_repnames(get_id_from_name(str, wsg), wsg, rname, idc)
return uw
end
......@@ -945,7 +964,16 @@ function uwreal(data::Vector{Float64},
iv::Vector{Int64})
uw = ADerrors.uwcls(data, get_id_from_name(str, wsg), wsg, iv)
add_repnames(get_id_from_name(str, wsg), wsg, rname)
idc = Vector{Int64}(undef, length(data))
iof = 0
for i in 1:length(iv)
for k in 1:iv[i]
idc[k+iof] = k
end
iof = iof + iv[i]
end
add_repnames(get_id_from_name(str, wsg), wsg, rname, idc)
return uw
end
......@@ -960,7 +988,9 @@ function uwreal(data::Vector{Float64},
[nms],
idm,
nms)
add_repnames(get_id_from_name(str, wsg), wsg, rname)
idc = collect(1:nms)
add_repnames(get_id_from_name(str, wsg), wsg, rname, idc)
return uw
end
......@@ -975,7 +1005,15 @@ function uwreal(data::Vector{Float64},
iv,
idm,
nms)
add_repnames(get_id_from_name(str, wsg), wsg, rname)
iof = 0
for i in 1:length(iv)
for k in 1:iv[i]
idc[k+iof] = k
end
iof = iof + iv[i]
end
add_repnames(get_id_from_name(str, wsg), wsg, rname, iv)
return uw
end
......
......@@ -357,27 +357,35 @@ function read_bdio(fb, ws::wspace, mapids::Dict{Int64, Int64})
# Here not to use ids[i]
if BDIO.BDIO_eor(fb)
is = 1
for i in 1:nid
ie = is + nrep[i] - 1
v = Vector{String}(undef, nrep[i])
idc = Vector{Int32}(undef, nds[i])
BDIO.BDIO_read(fb, ifoo)
str = get_name_from_id(ids[i], ws)
for j in 1:nrep[i]
v[j] = str*"_r"*string(j)
for k in is:ie
idc[k] = convert(Int32, k-is+1)
end
end
add_repnames(convert(Int64, ids_obs[i]), ws, v)
add_repnames(convert(Int64, ids_obs[i]), ws, v, idc)
is = ie + 1
end
else
for i in 1:nid
v = Vector{String}(undef, nrep[i])
idc = Vector{Int32}(undef, nds[i])
BDIO.BDIO_read(fb, ifoo)
for j in 1:nrep[i]
v[j] = BDIO.BDIO_read_str(fb)
end
add_repnames(convert(Int64, ids_obs[i]), ws, v)
BDIO.BDIO_read(fb, idc)
add_repnames(convert(Int64, ids_obs[i]), ws, v, convert(Vector{Int64}, idc))
end
end
return uwreal(dfoo[1], p, d)
end
......@@ -436,6 +444,7 @@ function write_bdio(p::uwreal, fb, iu::Int, ws::wspace; name="NO NAME")
for j in 1:length(v)
BDIO.BDIO_write!(fb, v[j]*"\0")
end
BDIO.BDIO_write!(fb, convert(Vector{Int32}, get_repidc_from_id(p.ids[i], ws)))
end
BDIO.BDIO_write_hash!(fb)
......
......@@ -104,7 +104,6 @@ function cobs(avgs::Vector{Float64}, cov::Array{Float64, 2}, ids::Vector{Int64})
p[j] = p[j] + uwreal([0.0, A[j,i]], ids[i])
end
end
end
return p
......
......@@ -78,6 +78,7 @@ mutable struct wspace
id2str::Dict{Int64, String} # Ensemble id for each String
str2id::Dict{String, Int64} # Ensemble String for each id
repnam::Dict{Int64, Vector{String}} # Vector of replica names for each id
repidc::Dict{Int64, Vector{Int64}} # Configuration number for each replicum
newid::Int64
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment