diff --git a/src/InputOutput/writers.jl b/src/InputOutput/writers.jl index 102106b56e..29486ea897 100644 --- a/src/InputOutput/writers.jl +++ b/src/InputOutput/writers.jl @@ -1,7 +1,8 @@ abstract type AbstractWriter end """ - HDF5Writer(filename::AbstractString[, context::ClimaComms.AbstractCommsContext]) + HDF5Writer(filename::AbstractString[, context::ClimaComms.AbstractCommsContext]; + overwrite::Bool = true) An `AbstractWriter` for writing to HDF5-formatted files using the ClimaCore storage conventions. An internal cache is used to avoid writing duplicate @@ -12,6 +13,10 @@ The optional `context` can be used for writing distributed fields: in this case, the `MPICommsContext` used passed as an argument: this must match the context used for distributing the `Field`. +The writer overwrites or appends to existing files depending on the value of the +`overwrite` keyword argument. When `overwrite` is `false`, the writer appends to +`filename` if the file already exists, otherwise it creates a new one. + !!! note The default Julia HDF5 binaries are not built with MPI support. To use the @@ -44,12 +49,15 @@ end function HDF5Writer( filename::AbstractString, - context::ClimaComms.AbstractCommsContext, + context::ClimaComms.AbstractCommsContext; + overwrite::Bool = true, ) + mode = overwrite ? "w" : "cw" + if context isa ClimaComms.SingletonCommsContext - file = h5open(filename, "w") + file = h5open(filename, mode) else - file = h5open(filename, "w", context.mpicomm) + file = h5open(filename, mode, context.mpicomm) end write_attribute(file, "ClimaCore version", string(VERSION)) cache = Dict{String, String}()