1 | MODULE icbrst |
---|
2 | !!====================================================================== |
---|
3 | !! *** MODULE icbrst *** |
---|
4 | !! Ocean physics: read and write iceberg restart files |
---|
5 | !!====================================================================== |
---|
6 | !! History : 3.3.1 ! 2010-01 (Martin&Adcroft) Original code |
---|
7 | !! - ! 2011-03 (Madec) Part conversion to NEMO form |
---|
8 | !! - ! Removal of mapping from another grid |
---|
9 | !! - ! 2011-04 (Alderson) Split into separate modules |
---|
10 | !! - ! 2011-04 (Alderson) Restore restart routine |
---|
11 | !! - ! Currently needs a fixed processor |
---|
12 | !! - ! layout between restarts |
---|
13 | !! - ! 2015-11 Dave Storkey Convert icb_rst_read to use IOM so can |
---|
14 | !! read single restart files |
---|
15 | !!---------------------------------------------------------------------- |
---|
16 | |
---|
17 | !!---------------------------------------------------------------------- |
---|
18 | !! icb_rst_read : read restart file |
---|
19 | !! icb_rst_write : write restart file |
---|
20 | !!---------------------------------------------------------------------- |
---|
21 | USE par_oce ! NEMO parameters |
---|
22 | USE dom_oce ! NEMO domain |
---|
23 | USE in_out_manager ! NEMO IO routines |
---|
24 | USE lib_mpp ! NEMO MPI library, lk_mpp in particular |
---|
25 | USE netcdf ! netcdf routines for IO |
---|
26 | USE iom |
---|
27 | USE icb_oce ! define iceberg arrays |
---|
28 | USE icbutl ! iceberg utility routines |
---|
29 | |
---|
30 | IMPLICIT NONE |
---|
31 | PRIVATE |
---|
32 | |
---|
33 | PUBLIC icb_rst_read ! routine called in icbini.F90 module |
---|
34 | PUBLIC icb_rst_write ! routine called in icbstp.F90 module |
---|
35 | |
---|
36 | INTEGER :: nlonid, nlatid, nxid, nyid, nuvelid, nvvelid |
---|
37 | INTEGER :: nmassid, nthicknessid, nwidthid, nlengthid |
---|
38 | INTEGER :: nyearid, ndayid |
---|
39 | INTEGER :: nscaling_id, nmass_of_bits_id, nheat_density_id, numberid |
---|
40 | INTEGER :: nsiceid, nsheatid, ncalvid, ncalvhid, nkountid |
---|
41 | INTEGER :: nret, ncid, nc_dim |
---|
42 | |
---|
43 | INTEGER, DIMENSION(3) :: nstrt3, nlngth3 |
---|
44 | |
---|
45 | !!---------------------------------------------------------------------- |
---|
46 | !! NEMO/OCE 4.0 , NEMO Consortium (2018) |
---|
47 | !! $Id$ |
---|
48 | !! Software governed by the CeCILL license (see ./LICENSE) |
---|
49 | !!---------------------------------------------------------------------- |
---|
50 | CONTAINS |
---|
51 | |
---|
52 | SUBROUTINE icb_rst_read() |
---|
53 | !!---------------------------------------------------------------------- |
---|
54 | !! *** SUBROUTINE icb_rst_read *** |
---|
55 | !! |
---|
56 | !! ** Purpose : read a iceberg restart file |
---|
57 | !! NB: for this version, we just read back in the restart for this processor |
---|
58 | !! so we cannot change the processor layout currently with iceberg code |
---|
59 | !!---------------------------------------------------------------------- |
---|
60 | INTEGER :: idim, ivar, iatt |
---|
61 | INTEGER :: jn, iunlim_dim, ibergs_in_file |
---|
62 | INTEGER :: ii, ij, iclass, ibase_err, imax_icb |
---|
63 | REAL(wp), DIMENSION(nkounts) :: zdata |
---|
64 | LOGICAL :: ll_found_restart |
---|
65 | CHARACTER(len=256) :: cl_path |
---|
66 | CHARACTER(len=256) :: cl_filename |
---|
67 | CHARACTER(len=NF90_MAX_NAME) :: cl_dname |
---|
68 | TYPE(iceberg) :: localberg ! NOT a pointer but an actual local variable |
---|
69 | TYPE(point) :: localpt ! NOT a pointer but an actual local variable |
---|
70 | !!---------------------------------------------------------------------- |
---|
71 | |
---|
72 | ! Find a restart file. Assume iceberg restarts in same directory as ocean restarts |
---|
73 | ! and are called TRIM(cn_ocerst)//'_icebergs' |
---|
74 | cl_path = TRIM(cn_ocerst_indir) |
---|
75 | IF( cl_path(LEN_TRIM(cl_path):) /= '/' ) cl_path = TRIM(cl_path) // '/' |
---|
76 | cl_filename = TRIM(cn_ocerst_in)//'_icebergs' |
---|
77 | CALL iom_open( TRIM(cl_path)//cl_filename, ncid ) |
---|
78 | |
---|
79 | imax_icb = 0 |
---|
80 | IF( iom_file(ncid)%iduld .GE. 0) THEN |
---|
81 | |
---|
82 | ibergs_in_file = iom_file(ncid)%lenuld |
---|
83 | DO jn = 1,ibergs_in_file |
---|
84 | |
---|
85 | ! iom_get treats the unlimited dimension as time. Here the unlimited dimension |
---|
86 | ! is the iceberg index, but we can still use the ktime keyword to get the iceberg we want. |
---|
87 | |
---|
88 | CALL iom_get( ncid, 'xi' ,localpt%xi , ktime=jn ) |
---|
89 | CALL iom_get( ncid, 'yj' ,localpt%yj , ktime=jn ) |
---|
90 | |
---|
91 | ii = INT( localpt%xi + 0.5 ) |
---|
92 | ij = INT( localpt%yj + 0.5 ) |
---|
93 | ! Only proceed if this iceberg is on the local processor (excluding halos). |
---|
94 | IF ( ii .GE. nldi+nimpp-1 .AND. ii .LE. nlei+nimpp-1 .AND. & |
---|
95 | & ij .GE. nldj+njmpp-1 .AND. ij .LE. nlej+njmpp-1 ) THEN |
---|
96 | |
---|
97 | CALL iom_get( ncid, jpdom_unknown, 'number' , zdata(:) , ktime=jn, kstart=(/1/), kcount=(/nkounts/) ) |
---|
98 | localberg%number(:) = INT(zdata(:)) |
---|
99 | imax_icb = MAX( imax_icb, INT(zdata(1)) ) |
---|
100 | CALL iom_get( ncid, 'mass_scaling' , localberg%mass_scaling, ktime=jn ) |
---|
101 | CALL iom_get( ncid, 'lon' , localpt%lon , ktime=jn ) |
---|
102 | CALL iom_get( ncid, 'lat' , localpt%lat , ktime=jn ) |
---|
103 | CALL iom_get( ncid, 'uvel' , localpt%uvel , ktime=jn ) |
---|
104 | CALL iom_get( ncid, 'vvel' , localpt%vvel , ktime=jn ) |
---|
105 | CALL iom_get( ncid, 'mass' , localpt%mass , ktime=jn ) |
---|
106 | CALL iom_get( ncid, 'thickness' , localpt%thickness , ktime=jn ) |
---|
107 | CALL iom_get( ncid, 'width' , localpt%width , ktime=jn ) |
---|
108 | CALL iom_get( ncid, 'length' , localpt%length , ktime=jn ) |
---|
109 | CALL iom_get( ncid, 'year' , zdata(1) , ktime=jn ) |
---|
110 | localpt%year = INT(zdata(1)) |
---|
111 | CALL iom_get( ncid, 'day' , localpt%day , ktime=jn ) |
---|
112 | CALL iom_get( ncid, 'mass_of_bits' , localpt%mass_of_bits , ktime=jn ) |
---|
113 | CALL iom_get( ncid, 'heat_density' , localpt%heat_density , ktime=jn ) |
---|
114 | ! |
---|
115 | CALL icb_utl_add( localberg, localpt ) |
---|
116 | ! |
---|
117 | ENDIF |
---|
118 | ! |
---|
119 | END DO |
---|
120 | ! |
---|
121 | ELSE |
---|
122 | ibergs_in_file = 0 |
---|
123 | ENDIF |
---|
124 | |
---|
125 | ! Gridded variables |
---|
126 | CALL iom_get( ncid, jpdom_autoglo, 'calving' , src_calving ) |
---|
127 | CALL iom_get( ncid, jpdom_autoglo, 'calving_hflx', src_calving_hflx ) |
---|
128 | CALL iom_get( ncid, jpdom_autoglo, 'stored_heat' , berg_grid%stored_heat ) |
---|
129 | CALL iom_get( ncid, jpdom_autoglo_xy, 'stored_ice' , berg_grid%stored_ice, kstart=(/1,1,1/), kcount=(/1,1,nclasses/) ) |
---|
130 | |
---|
131 | CALL iom_get( ncid, jpdom_unknown, 'kount' , zdata(:) ) |
---|
132 | num_bergs(:) = INT(zdata(:)) |
---|
133 | ! |
---|
134 | |
---|
135 | ! Sanity checks |
---|
136 | jn = icb_utl_count() |
---|
137 | IF ( lwp .AND. nn_verbose_level >= 0 ) & |
---|
138 | WRITE(numout,'(2(a,i5))') 'icebergs, read_restart_bergs: # bergs =',jn,' on PE',narea-1 |
---|
139 | IF( lk_mpp ) THEN |
---|
140 | ! Only mpp_sum ibergs_in_file if we are reading from multiple restart files. |
---|
141 | IF( INDEX(iom_file(ncid)%name,'icebergs.nc' ) .EQ. 0 ) CALL mpp_sum('icbrst', ibergs_in_file) |
---|
142 | CALL mpp_sum('icbrst', jn) |
---|
143 | ENDIF |
---|
144 | IF( lwp ) WRITE(numout,'(a,i5,a,i5,a)') 'icebergs, icb_rst_read: there were',ibergs_in_file, & |
---|
145 | & ' bergs in the restart file and', jn,' bergs have been read' |
---|
146 | ! Close file |
---|
147 | CALL iom_close( ncid ) |
---|
148 | ! |
---|
149 | ! Confirm that all areas have a suitable base for assigning new iceberg |
---|
150 | ! numbers. This will not be the case if restarting from a collated dataset |
---|
151 | ! (even if using the same processor decomposition) |
---|
152 | ! |
---|
153 | ibase_err = 0 |
---|
154 | IF( num_bergs(1) < 0 .AND. num_bergs(1) /= narea - jpnij ) THEN |
---|
155 | ! If this area has never calved a new berg then the base should be |
---|
156 | ! set to narea - jpnij. If it is negative but something else then |
---|
157 | ! a new base will be needed to guarantee unique, future iceberg numbers |
---|
158 | ibase_err = 1 |
---|
159 | ELSEIF( MOD( num_bergs(1) - narea , jpnij ) /= 0 ) THEN |
---|
160 | ! If this area has a base which is not in the set {narea + N*jpnij} |
---|
161 | ! for positive integers N then a new base will be needed to guarantee |
---|
162 | ! unique, future iceberg numbers |
---|
163 | ibase_err = 1 |
---|
164 | ENDIF |
---|
165 | IF( lk_mpp ) THEN |
---|
166 | CALL mpp_sum('icbrst', ibase_err) |
---|
167 | ENDIF |
---|
168 | IF( ibase_err > 0 ) THEN |
---|
169 | ! |
---|
170 | ! A new base is needed. The only secure solution is to set bases such that |
---|
171 | ! all future icebergs numbers will be greater than the current global maximum |
---|
172 | IF( lk_mpp ) THEN |
---|
173 | CALL mpp_max('icbrst', imax_icb) |
---|
174 | ENDIF |
---|
175 | num_bergs(1) = imax_icb - jpnij + narea |
---|
176 | ENDIF |
---|
177 | ! |
---|
178 | IF( lwp .AND. nn_verbose_level >= 0 ) WRITE(numout,'(a)') 'icebergs, icb_rst_read: completed' |
---|
179 | ! |
---|
180 | END SUBROUTINE icb_rst_read |
---|
181 | |
---|
182 | |
---|
183 | SUBROUTINE icb_rst_write( kt ) |
---|
184 | !!---------------------------------------------------------------------- |
---|
185 | !! *** SUBROUTINE icb_rst_write *** |
---|
186 | !! |
---|
187 | !!---------------------------------------------------------------------- |
---|
188 | INTEGER, INTENT( in ) :: kt |
---|
189 | ! |
---|
190 | INTEGER :: jn ! dummy loop index |
---|
191 | INTEGER :: ix_dim, iy_dim, ik_dim, in_dim |
---|
192 | CHARACTER(len=256) :: cl_path |
---|
193 | CHARACTER(len=256) :: cl_filename |
---|
194 | TYPE(iceberg), POINTER :: this |
---|
195 | TYPE(point) , POINTER :: pt |
---|
196 | !!---------------------------------------------------------------------- |
---|
197 | |
---|
198 | ! Following the normal restart procedure, this routine will be called |
---|
199 | ! the timestep before a restart stage as well as the restart timestep. |
---|
200 | ! This is a performance step enabling the file to be opened and contents |
---|
201 | ! defined in advance of the write. This is not possible with icebergs |
---|
202 | ! since the number of bergs to be written could change between timesteps |
---|
203 | IF( kt == nitrst ) THEN |
---|
204 | ! Only operate on the restart timestep itself. |
---|
205 | ! Assume we write iceberg restarts to same directory as ocean restarts. |
---|
206 | cl_path = TRIM(cn_ocerst_outdir) |
---|
207 | IF( cl_path(LEN_TRIM(cl_path):) /= '/' ) cl_path = TRIM(cl_path) // '/' |
---|
208 | IF( lk_mpp ) THEN |
---|
209 | WRITE(cl_filename,'(A,"_icebergs_",I8.8,"_restart_",I4.4,".nc")') TRIM(cexper), kt, narea-1 |
---|
210 | ELSE |
---|
211 | WRITE(cl_filename,'(A,"_icebergs_",I8.8,"_restart.nc")') TRIM(cexper), kt |
---|
212 | ENDIF |
---|
213 | IF ( lwp .AND. nn_verbose_level >= 0) WRITE(numout,'(2a)') 'icebergs, write_restart: creating ', & |
---|
214 | & TRIM(cl_path)//TRIM(cl_filename) |
---|
215 | |
---|
216 | nret = NF90_CREATE(TRIM(cl_path)//TRIM(cl_filename), NF90_CLOBBER, ncid) |
---|
217 | IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_create failed') |
---|
218 | |
---|
219 | ! Dimensions |
---|
220 | nret = NF90_DEF_DIM(ncid, 'x', jpi, ix_dim) |
---|
221 | IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim x failed') |
---|
222 | |
---|
223 | nret = NF90_DEF_DIM(ncid, 'y', jpj, iy_dim) |
---|
224 | IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim y failed') |
---|
225 | |
---|
226 | nret = NF90_DEF_DIM(ncid, 'c', nclasses, nc_dim) |
---|
227 | IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim c failed') |
---|
228 | |
---|
229 | nret = NF90_DEF_DIM(ncid, 'k', nkounts, ik_dim) |
---|
230 | IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim k failed') |
---|
231 | |
---|
232 | ! global attributes |
---|
233 | IF( lk_mpp ) THEN |
---|
234 | ! Set domain parameters (assume jpdom_local_full) |
---|
235 | nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_number_total' , jpnij ) |
---|
236 | nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_number' , narea-1 ) |
---|
237 | nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_dimensions_ids' , (/1 , 2 /) ) |
---|
238 | nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_size_global' , (/jpiglo, jpjglo/) ) |
---|
239 | nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_size_local' , (/jpi , jpj /) ) |
---|
240 | nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_position_first' , (/nimpp , njmpp /) ) |
---|
241 | nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_position_last' , (/nimpp + jpi - 1 , njmpp + jpj - 1 /) ) |
---|
242 | nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_halo_size_start', (/nldi - 1 , nldj - 1 /) ) |
---|
243 | nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_halo_size_end' , (/jpi - nlei , jpj - nlej /) ) |
---|
244 | nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_type' , 'BOX' ) |
---|
245 | ENDIF |
---|
246 | |
---|
247 | IF (associated(first_berg)) then |
---|
248 | nret = NF90_DEF_DIM(ncid, 'n', NF90_UNLIMITED, in_dim) |
---|
249 | IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim n failed') |
---|
250 | ENDIF |
---|
251 | |
---|
252 | ! Variables |
---|
253 | nret = NF90_DEF_VAR(ncid, 'kount' , NF90_INT , (/ ik_dim /), nkountid) |
---|
254 | nret = NF90_DEF_VAR(ncid, 'calving' , NF90_DOUBLE, (/ ix_dim, iy_dim /), ncalvid) |
---|
255 | nret = NF90_DEF_VAR(ncid, 'calving_hflx', NF90_DOUBLE, (/ ix_dim, iy_dim /), ncalvhid) |
---|
256 | nret = NF90_DEF_VAR(ncid, 'stored_ice' , NF90_DOUBLE, (/ ix_dim, iy_dim, nc_dim /), nsiceid) |
---|
257 | nret = NF90_DEF_VAR(ncid, 'stored_heat' , NF90_DOUBLE, (/ ix_dim, iy_dim /), nsheatid) |
---|
258 | |
---|
259 | ! Attributes |
---|
260 | nret = NF90_PUT_ATT(ncid, ncalvid , 'long_name', 'iceberg calving') |
---|
261 | nret = NF90_PUT_ATT(ncid, ncalvid , 'units', 'some') |
---|
262 | nret = NF90_PUT_ATT(ncid, ncalvhid, 'long_name', 'heat flux associated with iceberg calving') |
---|
263 | nret = NF90_PUT_ATT(ncid, ncalvhid, 'units', 'some') |
---|
264 | nret = NF90_PUT_ATT(ncid, nsiceid , 'long_name', 'stored ice used to calve icebergs') |
---|
265 | nret = NF90_PUT_ATT(ncid, nsiceid , 'units', 'kg/s') |
---|
266 | nret = NF90_PUT_ATT(ncid, nsheatid, 'long_name', 'heat in stored ice used to calve icebergs') |
---|
267 | nret = NF90_PUT_ATT(ncid, nsheatid, 'units', 'J/kg/s') |
---|
268 | |
---|
269 | IF ( ASSOCIATED(first_berg) ) THEN |
---|
270 | |
---|
271 | ! Only add berg variables for this PE if we have anything to say |
---|
272 | |
---|
273 | ! Variables |
---|
274 | nret = NF90_DEF_VAR(ncid, 'lon', NF90_DOUBLE, in_dim, nlonid) |
---|
275 | nret = NF90_DEF_VAR(ncid, 'lat', NF90_DOUBLE, in_dim, nlatid) |
---|
276 | nret = NF90_DEF_VAR(ncid, 'xi', NF90_DOUBLE, in_dim, nxid) |
---|
277 | nret = NF90_DEF_VAR(ncid, 'yj', NF90_DOUBLE, in_dim, nyid) |
---|
278 | nret = NF90_DEF_VAR(ncid, 'uvel', NF90_DOUBLE, in_dim, nuvelid) |
---|
279 | nret = NF90_DEF_VAR(ncid, 'vvel', NF90_DOUBLE, in_dim, nvvelid) |
---|
280 | nret = NF90_DEF_VAR(ncid, 'mass', NF90_DOUBLE, in_dim, nmassid) |
---|
281 | nret = NF90_DEF_VAR(ncid, 'thickness', NF90_DOUBLE, in_dim, nthicknessid) |
---|
282 | nret = NF90_DEF_VAR(ncid, 'width', NF90_DOUBLE, in_dim, nwidthid) |
---|
283 | nret = NF90_DEF_VAR(ncid, 'length', NF90_DOUBLE, in_dim, nlengthid) |
---|
284 | nret = NF90_DEF_VAR(ncid, 'number', NF90_INT, (/ik_dim,in_dim/), numberid) |
---|
285 | nret = NF90_DEF_VAR(ncid, 'year', NF90_INT, in_dim, nyearid) |
---|
286 | nret = NF90_DEF_VAR(ncid, 'day', NF90_DOUBLE, in_dim, ndayid) |
---|
287 | nret = NF90_DEF_VAR(ncid, 'mass_scaling', NF90_DOUBLE, in_dim, nscaling_id) |
---|
288 | nret = NF90_DEF_VAR(ncid, 'mass_of_bits', NF90_DOUBLE, in_dim, nmass_of_bits_id) |
---|
289 | nret = NF90_DEF_VAR(ncid, 'heat_density', NF90_DOUBLE, in_dim, nheat_density_id) |
---|
290 | |
---|
291 | ! Attributes |
---|
292 | nret = NF90_PUT_ATT(ncid, nlonid, 'long_name', 'longitude') |
---|
293 | nret = NF90_PUT_ATT(ncid, nlonid, 'units', 'degrees_E') |
---|
294 | nret = NF90_PUT_ATT(ncid, nlatid, 'long_name', 'latitude') |
---|
295 | nret = NF90_PUT_ATT(ncid, nlatid, 'units', 'degrees_N') |
---|
296 | nret = NF90_PUT_ATT(ncid, nxid, 'long_name', 'x grid box position') |
---|
297 | nret = NF90_PUT_ATT(ncid, nxid, 'units', 'fractional') |
---|
298 | nret = NF90_PUT_ATT(ncid, nyid, 'long_name', 'y grid box position') |
---|
299 | nret = NF90_PUT_ATT(ncid, nyid, 'units', 'fractional') |
---|
300 | nret = NF90_PUT_ATT(ncid, nuvelid, 'long_name', 'zonal velocity') |
---|
301 | nret = NF90_PUT_ATT(ncid, nuvelid, 'units', 'm/s') |
---|
302 | nret = NF90_PUT_ATT(ncid, nvvelid, 'long_name', 'meridional velocity') |
---|
303 | nret = NF90_PUT_ATT(ncid, nvvelid, 'units', 'm/s') |
---|
304 | nret = NF90_PUT_ATT(ncid, nmassid, 'long_name', 'mass') |
---|
305 | nret = NF90_PUT_ATT(ncid, nmassid, 'units', 'kg') |
---|
306 | nret = NF90_PUT_ATT(ncid, nthicknessid, 'long_name', 'thickness') |
---|
307 | nret = NF90_PUT_ATT(ncid, nthicknessid, 'units', 'm') |
---|
308 | nret = NF90_PUT_ATT(ncid, nwidthid, 'long_name', 'width') |
---|
309 | nret = NF90_PUT_ATT(ncid, nwidthid, 'units', 'm') |
---|
310 | nret = NF90_PUT_ATT(ncid, nlengthid, 'long_name', 'length') |
---|
311 | nret = NF90_PUT_ATT(ncid, nlengthid, 'units', 'm') |
---|
312 | nret = NF90_PUT_ATT(ncid, numberid, 'long_name', 'iceberg number on this processor') |
---|
313 | nret = NF90_PUT_ATT(ncid, numberid, 'units', 'count') |
---|
314 | nret = NF90_PUT_ATT(ncid, nyearid, 'long_name', 'calendar year of calving event') |
---|
315 | nret = NF90_PUT_ATT(ncid, nyearid, 'units', 'years') |
---|
316 | nret = NF90_PUT_ATT(ncid, ndayid, 'long_name', 'year day of calving event') |
---|
317 | nret = NF90_PUT_ATT(ncid, ndayid, 'units', 'days') |
---|
318 | nret = NF90_PUT_ATT(ncid, nscaling_id, 'long_name', 'scaling factor for mass of calving berg') |
---|
319 | nret = NF90_PUT_ATT(ncid, nscaling_id, 'units', 'none') |
---|
320 | nret = NF90_PUT_ATT(ncid, nmass_of_bits_id, 'long_name', 'mass of bergy bits') |
---|
321 | nret = NF90_PUT_ATT(ncid, nmass_of_bits_id, 'units', 'kg') |
---|
322 | nret = NF90_PUT_ATT(ncid, nheat_density_id, 'long_name', 'heat density') |
---|
323 | nret = NF90_PUT_ATT(ncid, nheat_density_id, 'units', 'J/kg') |
---|
324 | |
---|
325 | ENDIF ! associated(first_berg) |
---|
326 | |
---|
327 | ! End define mode |
---|
328 | nret = NF90_ENDDEF(ncid) |
---|
329 | |
---|
330 | ! -------------------------------- |
---|
331 | ! now write some data |
---|
332 | |
---|
333 | nstrt3(1) = 1 |
---|
334 | nstrt3(2) = 1 |
---|
335 | nlngth3(1) = jpi |
---|
336 | nlngth3(2) = jpj |
---|
337 | nlngth3(3) = 1 |
---|
338 | |
---|
339 | DO jn=1,nclasses |
---|
340 | griddata(:,:,1) = berg_grid%stored_ice(:,:,jn) |
---|
341 | nstrt3(3) = jn |
---|
342 | nret = NF90_PUT_VAR( ncid, nsiceid, griddata, nstrt3, nlngth3 ) |
---|
343 | IF (nret .ne. NF90_NOERR) THEN |
---|
344 | IF( lwp ) WRITE(numout,*) TRIM(NF90_STRERROR( nret )) |
---|
345 | CALL ctl_stop('icebergs, write_restart: nf_put_var stored_ice failed') |
---|
346 | ENDIF |
---|
347 | ENDDO |
---|
348 | IF( lwp ) WRITE(numout,*) 'file: ',TRIM(cl_path)//TRIM(cl_filename),' var: stored_ice written' |
---|
349 | |
---|
350 | nret = NF90_PUT_VAR( ncid, nkountid, num_bergs(:) ) |
---|
351 | IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_put_var kount failed') |
---|
352 | |
---|
353 | nret = NF90_PUT_VAR( ncid, nsheatid, berg_grid%stored_heat(:,:) ) |
---|
354 | IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_put_var stored_heat failed') |
---|
355 | IF( lwp ) WRITE(numout,*) 'file: ',TRIM(cl_path)//TRIM(cl_filename),' var: stored_heat written' |
---|
356 | |
---|
357 | nret = NF90_PUT_VAR( ncid, ncalvid , src_calving(:,:) ) |
---|
358 | IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_put_var calving failed') |
---|
359 | nret = NF90_PUT_VAR( ncid, ncalvhid, src_calving_hflx(:,:) ) |
---|
360 | IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_put_var calving_hflx failed') |
---|
361 | IF( lwp ) WRITE(numout,*) 'file: ',TRIM(cl_path)//TRIM(cl_filename),' var: calving written' |
---|
362 | |
---|
363 | IF ( ASSOCIATED(first_berg) ) THEN |
---|
364 | |
---|
365 | ! Write variables |
---|
366 | ! just write out the current point of the trajectory |
---|
367 | |
---|
368 | this => first_berg |
---|
369 | jn = 0 |
---|
370 | DO WHILE (ASSOCIATED(this)) |
---|
371 | pt => this%current_point |
---|
372 | jn=jn+1 |
---|
373 | |
---|
374 | nret = NF90_PUT_VAR(ncid, numberid, this%number, (/1,jn/), (/nkounts,1/) ) |
---|
375 | nret = NF90_PUT_VAR(ncid, nscaling_id, this%mass_scaling, (/ jn /) ) |
---|
376 | |
---|
377 | nret = NF90_PUT_VAR(ncid, nlonid, pt%lon, (/ jn /) ) |
---|
378 | nret = NF90_PUT_VAR(ncid, nlatid, pt%lat, (/ jn /) ) |
---|
379 | nret = NF90_PUT_VAR(ncid, nxid, pt%xi, (/ jn /) ) |
---|
380 | nret = NF90_PUT_VAR(ncid, nyid, pt%yj, (/ jn /) ) |
---|
381 | nret = NF90_PUT_VAR(ncid, nuvelid, pt%uvel, (/ jn /) ) |
---|
382 | nret = NF90_PUT_VAR(ncid, nvvelid, pt%vvel, (/ jn /) ) |
---|
383 | nret = NF90_PUT_VAR(ncid, nmassid, pt%mass, (/ jn /) ) |
---|
384 | nret = NF90_PUT_VAR(ncid, nthicknessid, pt%thickness, (/ jn /) ) |
---|
385 | nret = NF90_PUT_VAR(ncid, nwidthid, pt%width, (/ jn /) ) |
---|
386 | nret = NF90_PUT_VAR(ncid, nlengthid, pt%length, (/ jn /) ) |
---|
387 | nret = NF90_PUT_VAR(ncid, nyearid, pt%year, (/ jn /) ) |
---|
388 | nret = NF90_PUT_VAR(ncid, ndayid, pt%day, (/ jn /) ) |
---|
389 | nret = NF90_PUT_VAR(ncid, nmass_of_bits_id, pt%mass_of_bits, (/ jn /) ) |
---|
390 | nret = NF90_PUT_VAR(ncid, nheat_density_id, pt%heat_density, (/ jn /) ) |
---|
391 | |
---|
392 | this=>this%next |
---|
393 | END DO |
---|
394 | ! |
---|
395 | ENDIF ! associated(first_berg) |
---|
396 | |
---|
397 | ! Finish up |
---|
398 | nret = NF90_CLOSE(ncid) |
---|
399 | IF (nret /= NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_close failed') |
---|
400 | |
---|
401 | ! Sanity check |
---|
402 | jn = icb_utl_count() |
---|
403 | IF ( lwp .AND. nn_verbose_level >= 0) & |
---|
404 | WRITE(numout,'(2(a,i5))') 'icebergs, icb_rst_write: # bergs =',jn,' on PE',narea-1 |
---|
405 | IF( lk_mpp ) THEN |
---|
406 | CALL mpp_sum('icbrst', jn) |
---|
407 | ENDIF |
---|
408 | IF(lwp) WRITE(numout,'(a,i5,a,i5,a)') 'icebergs, icb_rst_write: ', jn, & |
---|
409 | & ' bergs in total have been written at timestep ', kt |
---|
410 | ! |
---|
411 | ! Finish up |
---|
412 | ! |
---|
413 | ENDIF |
---|
414 | END SUBROUTINE icb_rst_write |
---|
415 | ! |
---|
416 | !!====================================================================== |
---|
417 | END MODULE icbrst |
---|