Skip to content

Commit

Permalink
Merge pull request #3 from CliMA/bm/show_cplstate
Browse files Browse the repository at this point in the history
Add Base.show for CplState object.
  • Loading branch information
jb-mackay committed Apr 8, 2021
2 parents 6cdc8c2 + 918b858 commit ee08260
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
Oceananigans = "9e8cae18-63c1-5223-a75c-80ca9d6e9a09"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[extras]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["Test", "Random"]
2 changes: 1 addition & 1 deletion docs/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
version = "1.1.0"

[[CouplerMachine]]
deps = ["CLIMAParameters", "ClimateMachine", "Dates", "JLD2", "LinearAlgebra", "MPI", "Oceananigans", "StaticArrays", "Statistics", "Unitful"]
deps = ["CLIMAParameters", "ClimateMachine", "Dates", "JLD2", "LinearAlgebra", "MPI", "Oceananigans", "PrettyTables", "Random", "StaticArrays", "Statistics", "Unitful"]
path = ".."
uuid = "4ade58fe-a8da-486c-bd89-46df092ec0c7"
version = "0.1.0"
Expand Down
3 changes: 2 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[deps]
CouplerMachine = "4ade58fe-a8da-486c-bd89-46df092ec0c7"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"

[compat]
Documenter = "0.26"
Documenter = "0.26"
20 changes: 20 additions & 0 deletions src/CplState.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Unitful, Dates
using PrettyTables

export CplState, put!, get, register_cpl_field!

Expand Down Expand Up @@ -127,4 +128,23 @@ end
# set the time of the coupled field
function settime!(cplfield::CplFieldInfo, newtime::DateTime)
cplfield.datetime = newtime
end

# display table of registered fields & their info
function Base.show(io::IO, coupler::CplState)
#=
---------------------------------------------------------------------------
| Field Name | Units | Field Time (Y-m-d H:M:S) | Grid Type |
---------------------------------------------------------------------------
| :OceanSST | °C | 2021-01-01T00:00:00 | DG Cubed Sphere |
| :Field2 | m | 2021-01-01T00:00:00 | CG Cubed Sphere |
---------------------------------------------------------------------------
=#
fields = coupler.CplStateBlob
data = Array{Any}(undef, length(fields), 4)
for (i,k) in enumerate( keys(coupler.CplStateBlob))
entry = coupler.CplStateBlob[k]
data[i,:] = [k entry.units entry.datetime entry.gridinfo.gridtype]
end
pretty_table(data, ["Field Name" "Units" "Field Time (Y-m-d H:M:S)" "Grid Type"])
end

0 comments on commit ee08260

Please sign in to comment.