Skip to content

Commit

Permalink
Merge pull request #93 from ali-ramadhan/netcdf-io
Browse files Browse the repository at this point in the history
read_output function for NetCDF.
  • Loading branch information
ali-ramadhan authored Feb 28, 2019
2 parents 30150f9 + 88cc345 commit c980a11
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/output_writers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,23 @@ function write_output(model::Model, fw::NetCDFFieldWriter)

isfile(nc_filepath) && rm(nc_filepath)

nccreate(nc_filepath, "u", "xC", xF, xF_attr, "yC", yC, yC_attr, "zC", zC, zC_attr, atts=u_attr, compress=5)
nccreate(nc_filepath, "u", "xC", xC, xC_attr, "yC", yC, yC_attr, "zC", zC, zC_attr, atts=u_attr, compress=5)
ncwrite(model.velocities.u.data, nc_filepath, "u")

nccreate(nc_filepath, "v", "xC", xF, xF_attr, "yC", yC, yC_attr, "zC", zC, zC_attr, atts=v_attr, compress=5)
nccreate(nc_filepath, "v", "xC", xC, xC_attr, "yC", yC, yC_attr, "zC", zC, zC_attr, atts=v_attr, compress=5)
ncwrite(model.velocities.v.data, nc_filepath, "v")

nccreate(nc_filepath, "w", "xC", xF, xF_attr, "yC", yC, yC_attr, "zC", zC, zC_attr, atts=w_attr, compress=5)
nccreate(nc_filepath, "w", "xC", xC, xC_attr, "yC", yC, yC_attr, "zC", zC, zC_attr, atts=w_attr, compress=5)
ncwrite(model.velocities.w.data, nc_filepath, "w")

nccreate(nc_filepath, "T", "xC", xC, xC_attr, "yC", yC, yC_attr, "zC", zC, zC_attr, atts=T_attr, compress=5)
ncwrite(model.tracers.T.data, nc_filepath, "T")

ncclose(nc_filename)
end

function read_output(fw::NetCDFFieldWriter, field_name, iter)
nc_filename = fw.filename_prefix * "_" * lpad(iter, 9, "0") * ".nc"
nc_filepath = joinpath(fw.dir, nc_filename)
ncread(nc_filepath, field_name)
end

0 comments on commit c980a11

Please sign in to comment.