From c3dc7c5dbc421d34a95db4266515c78493bdea3a Mon Sep 17 00:00:00 2001 From: Gabriele Bozzola Date: Mon, 18 Sep 2023 14:14:28 -0700 Subject: [PATCH] Check if "ClimaCore version" is already attribute HDF5.jl complains if you try writing an attribute that already exists --- src/InputOutput/writers.jl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/InputOutput/writers.jl b/src/InputOutput/writers.jl index 29486ea897..cb9d0af198 100644 --- a/src/InputOutput/writers.jl +++ b/src/InputOutput/writers.jl @@ -59,7 +59,16 @@ function HDF5Writer( else file = h5open(filename, mode, context.mpicomm) end - write_attribute(file, "ClimaCore version", string(VERSION)) + # Add an attribute to the file if it doesn't already exist + if haskey(attributes(file), "ClimaCore version") + file_version = VersionNumber(attrs(file)["ClimaCore version"]) + current_version = VERSION + if file_version != current_version + @warn "$filename was written using a different version of ClimaCore than is currently loaded" file_version current_version + end + else + write_attribute(file, "ClimaCore version", string(VERSION)) + end cache = Dict{String, String}() return HDF5Writer(file, context, cache) end