@@ -8,11 +8,12 @@ struct NcFiles
8
8
du:: Union{NcFile,Nothing} # tendency of u [m^2/s^2]
9
9
dv:: Union{NcFile,Nothing} # tendency of v [m^2/s^2]
10
10
dη:: Union{NcFile,Nothing} # tendency of η [m^2/s]
11
+ H:: Union{NcFile,Nothing} # layer thickness at rest [m]
11
12
iout:: Array{Integer,1} # output index, stored in array for mutability
12
13
end
13
14
14
15
""" Generator function for "empty" NcFiles struct."""
15
- NcFiles (x:: Nothing ) = NcFiles (x,x,x,x,x,x,x,x,x,[0 ])
16
+ NcFiles (x:: Nothing ) = NcFiles (x,x,x,x,x,x,x,x,x,x, [0 ])
16
17
17
18
""" Generator function for NcFiles struct, creating the underlying netCDF files."""
18
19
function NcFiles (feedback:: Feedback ,S:: ModelSetup )
@@ -35,16 +36,22 @@ function NcFiles(feedback::Feedback,S::ModelSetup)
35
36
ncdu = if " du" in output_vars nc_create (x_u,y_u," du" ,runpath," m^2/s^2" ," zonal velocity tendency" ,P) else nothing end
36
37
ncdv = if " dv" in output_vars nc_create (x_v,y_v," dv" ,runpath," m^2/s^2" ," meridional velocity tendency" ,P) else nothing end
37
38
ncdη = if " dη" in output_vars nc_create (x_T,y_T," deta" ,runpath," m^2/s" ," sea surface height tendency" ,P) else nothing end
39
+ nH = if " H" in output_vars nc_create (x_T,y_T," H" ,runpath," m" ," undisturbed layer thickness" ,P,false ) else nothing end
38
40
39
41
for nc in (ncu,ncv,ncη,ncsst,ncq,ncζ,ncdu,ncdv,ncdη)
40
- if nc != nothing
42
+ if ! isnothing (nc)
41
43
NetCDF. putatt (nc," t" ,Dict (" units" => " s" ," long_name" => " time" ))
42
44
NetCDF. putatt (nc," x" ,Dict (" units" => " m" ," long_name" => " zonal coordinate" ))
43
45
NetCDF. putatt (nc," y" ,Dict (" units" => " m" ," long_name" => " meridional coordinate" ))
44
46
end
45
47
end
46
48
47
- return NcFiles (ncu,ncv,ncη,ncsst,ncq,ncζ,ncdu,ncdv,ncdη,[0 ])
49
+ if ! isnothing (nH) # output constant fields
50
+ NetCDF. putatt (nH," x" ,Dict (" units" => " m" ," long_name" => " zonal coordinate" ))
51
+ NetCDF. putatt (nH," y" ,Dict (" units" => " m" ," long_name" => " meridional coordinate" ))
52
+ end
53
+
54
+ return NcFiles (ncu,ncv,ncη,ncsst,ncq,ncζ,ncdu,ncdv,ncdη,nH,[0 ])
48
55
else
49
56
return NcFiles (nothing )
50
57
end
@@ -57,18 +64,24 @@ function nc_create( x::Array{T,1},
57
64
path:: String ,
58
65
unit:: String ,
59
66
long_name:: String ,
60
- P:: Parameter ) where {T<: Real }
67
+ P:: Parameter ,
68
+ output_tdim:: Bool = true ) where {T<: Real }
61
69
62
70
@unpack compression_level = P
63
71
64
72
xdim = NcDim (" x" ,length (x),values= x)
65
73
ydim = NcDim (" y" ,length (y),values= y)
66
- tdim = NcDim (" t" ,0 ,unlimited= true )
74
+
75
+ if output_tdim
76
+ tdim = NcDim (" t" ,0 ,unlimited= true )
77
+ var = NcVar (name,[xdim,ydim,tdim],t= Float32,compress= compression_level)
78
+ tvar = NcVar (" t" ,tdim,t= Int32)
79
+ nc = NetCDF. create (joinpath (path,name* " .nc" ),[var,tvar],mode= NC_NETCDF4)
80
+ else
81
+ var = NcVar (name,[xdim,ydim],t= Float32,compress= compression_level)
82
+ nc = NetCDF. create (joinpath (path,name* " .nc" ),[var],mode= NC_NETCDF4)
83
+ end
67
84
68
- var = NcVar (name,[xdim,ydim,tdim],t= Float32,compress= compression_level)
69
- tvar = NcVar (" t" ,tdim,t= Int32)
70
-
71
- nc = NetCDF. create (joinpath (path,name* " .nc" ),[var,tvar],mode= NC_NETCDF4)
72
85
# add missing_value although irrelevant for ncview compatibility
73
86
NetCDF. putatt (nc,name,Dict (" units" => unit," long_name" => long_name," missing_value" => - 999999f0 ))
74
87
return nc
@@ -96,51 +109,55 @@ function output_nc!(i::Int,
96
109
# As output is before copyto!(u,u0), take u0,v0,η0
97
110
# Tendencies calculate from the last time step, du = u_n+1-u_n etc
98
111
# WRITING THE VARIABLES
99
- if ncs. u != nothing
112
+ if ! isnothing ( ncs. u)
100
113
@views u = Float32 .(scale_inv* Diag. RungeKutta. u0[halo+ 1 : end - halo,halo+ 1 : end - halo])
101
114
NetCDF. putvar (ncs. u," u" ,u,start= [1 ,1 ,iout],count= [- 1 ,- 1 ,1 ])
102
115
end
103
- if ncs. v != nothing
116
+ if ! isnothing ( ncs. v)
104
117
@views v = Float32 .(scale_inv* Diag. RungeKutta. v0[halo+ 1 : end - halo,halo+ 1 : end - halo])
105
118
NetCDF. putvar (ncs. v," v" ,v,start= [1 ,1 ,iout],count= [- 1 ,- 1 ,1 ])
106
119
end
107
- if ncs. η != nothing
120
+ if ! isnothing ( ncs. η)
108
121
@views η = Float32 .(Diag. RungeKutta. η0[haloη+ 1 : end - haloη,haloη+ 1 : end - haloη])
109
122
NetCDF. putvar (ncs. η," eta" ,η,start= [1 ,1 ,iout],count= [- 1 ,- 1 ,1 ])
110
123
end
111
- if ncs. sst != nothing
124
+ if ! isnothing ( ncs. sst)
112
125
@views sst = Float32 .(Prog. sst[halosstx+ 1 : end - halosstx,halossty+ 1 : end - halossty]/ scale_sst)
113
126
NetCDF. putvar (ncs. sst," sst" ,sst,start= [1 ,1 ,iout],count= [- 1 ,- 1 ,1 ])
114
127
end
115
- if ncs. q != nothing
128
+ if ! isnothing ( ncs. q)
116
129
@views q = Float32 .(scale_inv* Diag. Vorticity. q[haloη+ 1 : end - haloη,haloη+ 1 : end - haloη])
117
130
NetCDF. putvar (ncs. q," q" ,q,start= [1 ,1 ,iout],count= [- 1 ,- 1 ,1 ])
118
131
end
119
- if ncs. ζ != nothing
132
+ if ! isnothing ( ncs. ζ)
120
133
@unpack dvdx,dudy = Diag. Vorticity
121
134
@unpack f_q = S. grid
122
135
@views ζ = Float32 .((dvdx[2 : end - 1 ,2 : end - 1 ]- dudy[2 + ep: end - 1 ,2 : end - 1 ]). / abs .(f_q))
123
136
NetCDF. putvar (ncs. ζ," relvort" ,ζ,start= [1 ,1 ,iout],count= [- 1 ,- 1 ,1 ])
124
137
end
125
- if ncs. du != nothing
138
+ if ! isnothing ( ncs. du)
126
139
@views u = Float32 .(scale_inv* Diag. RungeKutta. u0[halo+ 1 : end - halo,halo+ 1 : end - halo])
127
140
@views du = u- Float32 .(scale_inv* Prog. u[halo+ 1 : end - halo,halo+ 1 : end - halo])
128
141
NetCDF. putvar (ncs. du," du" ,du,start= [1 ,1 ,iout],count= [- 1 ,- 1 ,1 ])
129
142
end
130
- if ncs. dv != nothing
143
+ if ! isnothing ( ncs. dv)
131
144
@views v = Float32 .(scale_inv* Diag. RungeKutta. v0[halo+ 1 : end - halo,halo+ 1 : end - halo])
132
145
@views dv = v- Float32 .(scale_inv* Prog. v[halo+ 1 : end - halo,halo+ 1 : end - halo])
133
146
NetCDF. putvar (ncs. dv," dv" ,dv,start= [1 ,1 ,iout],count= [- 1 ,- 1 ,1 ])
134
147
end
135
- if ncs. dη != nothing
148
+ if ! isnothing ( ncs. dη)
136
149
@views η = Float32 .(Diag. RungeKutta. η0[haloη+ 1 : end - haloη,haloη+ 1 : end - haloη])
137
150
@views dη = η- Float32 .(Prog. η[haloη+ 1 : end - haloη,haloη+ 1 : end - haloη])
138
151
NetCDF. putvar (ncs. dη," deta" ,dη,start= [1 ,1 ,iout],count= [- 1 ,- 1 ,1 ])
139
152
end
153
+ if i== 0 && ! isnothing (ncs. H) # constant field, output only once, before the timestepping
154
+ @views H = Float32 .(S. forcing. H[haloη+ 1 : end - haloη,haloη+ 1 : end - haloη])
155
+ NetCDF. putvar (ncs. H," H" ,H,start= [1 ,1 ],count= [- 1 ,- 1 ])
156
+ end
140
157
141
158
# WRITING THE TIME
142
159
for nc in (ncs. u,ncs. v,ncs. η,ncs. sst,ncs. q,ncs. ζ,ncs. du,ncs. dv,ncs. dη)
143
- if nc != nothing
160
+ if ! isnothing (nc)
144
161
NetCDF. putvar (nc," t" ,Int64[i* dtint],start= [iout])
145
162
NetCDF. sync (nc) # sync to view netcdf while model is still running
146
163
end
0 commit comments