SICOPOLIS V5-dev  Revision 1368
output_m.F90
Go to the documentation of this file.
1 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 !
3 ! Module : o u t p u t _ m
4 !
5 !> @file
6 !!
7 !! Writing of output data on files.
8 !!
9 !! @section Copyright
10 !!
11 !! Copyright 2009-2018 Ralf Greve, Reinhard Calov, Thomas Goelles,
12 !! Thorben Dunse
13 !!
14 !! @section License
15 !!
16 !! This file is part of SICOPOLIS.
17 !!
18 !! SICOPOLIS is free software: you can redistribute it and/or modify
19 !! it under the terms of the GNU General Public License as published by
20 !! the Free Software Foundation, either version 3 of the License, or
21 !! (at your option) any later version.
22 !!
23 !! SICOPOLIS is distributed in the hope that it will be useful,
24 !! but WITHOUT ANY WARRANTY; without even the implied warranty of
25 !! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 !! GNU General Public License for more details.
27 !!
28 !! You should have received a copy of the GNU General Public License
29 !! along with SICOPOLIS. If not, see <http://www.gnu.org/licenses/>.
30 !<
31 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32 
33 !-------------------------------------------------------------------------------
34 !> Writing of output data on files.
35 !<------------------------------------------------------------------------------
36 module output_m
37 
38  use sico_types_m
40  use sico_vars_m
41  use error_m
42 
43  implicit none
44 
45  real(dp), parameter :: sec_to_year = 1.0_dp/year_sec
46 
47  private
48  public :: output1, output2, output4, borehole
49 #if (defined(ASF))
50  public :: output5
51 #endif
52 
53 contains
54 
55 !-------------------------------------------------------------------------------
56 !> Writing of time-slice files in native binary or NetCDF format.
57 !<------------------------------------------------------------------------------
58 subroutine output1(runname, time, delta_ts, glac_index, z_sl, &
59  flag_3d_output, ndat2d, ndat3d)
60 
61 #if (CALCMOD==1 || CALCMOD==0 || CALCMOD==-1)
63 #endif
64 
65 #if (NETCDF==2) /* time-slice file in NetCDF format */
66  use netcdf
67  use nc_check_m
68 #endif
69 
70 #if (DISC>0)
72 #endif
73 
74 implicit none
75 
76 real(dp), intent(in) :: time, delta_ts, glac_index, z_sl
77 character(len=100), intent(in) :: runname
78 logical, intent(in) :: flag_3d_output
79 
80 integer(i4b), intent(inout) :: ndat2d, ndat3d
81 
82 integer(i4b) :: i, j, kc, kt, kr
83 integer(i4b) :: ndat, ndat_help, ndat_1000s, ndat_100s, ndat_10s, ndat_1s
84 real(dp), dimension(0:JMAX,0:IMAX) :: H, H_cold, H_temp, dH_dtau
85 real(dp), dimension(0:JMAX,0:IMAX) :: vx_m_g, vy_m_g
86 real(dp), dimension(0:JMAX,0:IMAX) :: tau_b_driving, tau_b_drag
87 real(dp) :: V_tot, V_grounded, V_floating, V_gr_redu, V_af
88 real(dp) :: A_grounded, A_floating
89 real(sp) :: lon0, lat0
90 real(dp) :: rhosw_rho_ratio
91 character(len=256) :: filename, filename_with_path
92 character :: ch_1000s, ch_100s, ch_10s, ch_1s
93 character(len=16) :: ch_date, ch_time, ch_zone
94 
95 real(dp), parameter :: one_year = 1.0_dp
96 
97 integer(i1b), dimension(0:IMAX,0:JMAX) :: maske_conv, maske_old_conv, &
98  mask_ablation_type_conv, &
99  n_cts_conv
100 integer(i4b), dimension(0:IMAX,0:JMAX) :: kc_cts_conv
101 integer(i1b), dimension(0:IMAX,0:JMAX) :: mask_mar_conv
102 integer(i1b), dimension(0:IMAX,0:JMAX) :: flag_shelfy_stream_x_conv, &
103  flag_shelfy_stream_y_conv, &
104  flag_shelfy_stream_conv
105 integer(i1b), dimension(0:IMAX,0:JMAX) :: flag_grounding_line_1_conv, &
106  flag_grounding_line_2_conv, &
107  flag_calving_front_1_conv, &
108  flag_calving_front_2_conv, &
109  flag_grounded_front_a_1_conv, &
110  flag_grounded_front_a_2_conv, &
111  flag_grounded_front_b_1_conv, &
112  flag_grounded_front_b_2_conv
113 
114 real(sp) :: time_conv, delta_ts_conv, glac_index_conv, z_sl_conv, &
115  V_tot_conv, V_af_conv, A_grounded_conv, A_floating_conv, &
116  H_R_conv, &
117  xi_conv(0:imax), eta_conv(0:jmax), &
118  sigma_level_c_conv(0:kcmax), sigma_level_t_conv(0:ktmax), &
119  sigma_level_r_conv(0:krmax)
120 real(sp), dimension(0:IMAX,0:JMAX) :: lambda_conv, phi_conv, &
121  lon_conv, lat_conv, &
122  temp_s_conv, accum_conv, &
123  snowfall_conv, rainfall_conv, pdd_conv, &
124  as_perp_conv, as_perp_apl_conv, smb_corr_conv, &
125  q_geo_conv, &
126  zs_conv, zm_conv, zb_conv, zl_conv, zl0_conv, &
127  H_cold_conv, H_temp_conv, H_conv, &
128  Q_bm_conv, Q_tld_conv, &
129  am_perp_conv, &
130  qx_conv, qy_conv, &
131  dzs_dtau_conv, dzm_dtau_conv, dzb_dtau_conv, dzl_dtau_conv, &
132  dH_c_dtau_conv, dH_t_dtau_conv, dH_dtau_conv, &
133  vx_b_g_conv, vy_b_g_conv, vz_b_conv, vh_b_conv, &
134  vx_s_g_conv, vy_s_g_conv, vz_s_conv, vh_s_conv, &
135  vx_m_g_conv, vy_m_g_conv, vh_m_conv, &
136  temp_b_conv, temph_b_conv, &
137  tau_b_driving_conv, tau_b_drag_conv, &
138  p_b_w_conv, q_w_conv, q_w_x_conv, q_w_y_conv, H_w_conv, &
139  q_gl_g_conv, q_cf_g_conv, &
140  cst_dist_conv, cos_grad_tc_conv, dis_perp_conv, &
141  ratio_sl_x_conv, ratio_sl_y_conv, &
142  vis_int_g_conv
143 
144 real(sp), dimension(0:IMAX,0:JMAX,0:KCMAX) :: vx_c_conv, vy_c_conv, vz_c_conv, &
145  temp_c_conv, age_c_conv, &
146  enth_c_conv, omega_c_conv, &
147  enh_c_conv
148 real(sp), dimension(0:IMAX,0:JMAX,0:KTMAX) :: vx_t_conv, vy_t_conv, vz_t_conv, &
149  omega_t_conv, age_t_conv, &
150  enth_t_conv, &
151  enh_t_conv
152 real(sp), dimension(0:IMAX,0:JMAX,0:KRMAX) :: temp_r_conv
153 
154 #if (NETCDF==1) /* time-slice file in native binary format */
155 
156 integer(i4b) :: ios
157 character(len=256) :: ch_attr_title, ch_attr_institution, ch_attr_source, &
158  ch_attr_history, ch_attr_references
159 character(len= 16), parameter :: filename_extension = '.erg'
160 
161 #elif (NETCDF==2) /* time-slice file in NetCDF format */
162 
163 integer(i4b) :: ncid, ncv
164 ! ncid: ID of the output file
165 ! ncv: Variable ID
166 integer(i4b) :: ncd, nc1d, nc2d(2), nc3d(3)
167 ! ncd: Dimension ID
168 ! nc1d: Dimension of a 1-d array
169 ! nc2d: Vector with the dimensions of a 2-d array
170 ! nc3d: Vector with the dimensions of a 3-d array
171 integer(i4b) :: nc2flag(2), nc3flag(3), nc4flag(4)
172 ! nc2flag: Vector with the 2 possible values of a flag variable
173 ! nc3flag: Vector with the 3 possible values of a flag variable
174 ! nc4flag: Vector with the 4 possible values of a flag variable
175 integer(i4b) :: nc1cor_i(1), nc1cor_j(1), &
176  nc1cor_kc(1), nc1cor_kt(1), nc1cor_kr(1), &
177  nc2cor_ij(2), &
178  nc3cor_ijkc(3), nc3cor_ijkt(3), nc3cor_ijkr(3)
179 ! nc1cor(1): Corner of a 1-d array
180 ! nc2cor(2): Corner of a 2-d array
181 ! nc3cor(3): Corner of a 3-d array
182 integer(i4b) :: nc1cnt_i(1), nc1cnt_j(1), &
183  nc1cnt_kc(1), nc1cnt_kt(1), nc1cnt_kr(1), &
184  nc2cnt_ij(2), &
185  nc3cnt_ijkc(3), nc3cnt_ijkt(3), nc3cnt_ijkr(3)
186 ! nc1cnt(1): Count of a 1-d array
187 ! nc2cnt(2): Count of a 2-d array
188 ! nc3cnt(3): Count of a 3-d array
189 character(len=256) :: buffer
190 character(len= 16), parameter :: filename_extension = '.nc'
191 character(len= 16), allocatable :: coord_id(:)
192 
193 #else
194 errormsg = ' >>> output1: Parameter NETCDF must be either 1 or 2!'
195 call error(errormsg)
196 #endif
197 
198 character(len=64), parameter :: thisroutine = 'output1'
199 
200 #if (NETCDF==2) /* time-slice file in NetCDF format */
201 
202 nc1cor_i = (/ 1 /)
203 nc1cnt_i = (/ imax+1 /)
204 
205 nc1cor_j = (/ 1 /)
206 nc1cnt_j = (/ jmax+1 /)
207 
208 nc1cor_kc = (/ 1 /)
209 nc1cnt_kc = (/ kcmax+1 /)
210 
211 nc1cor_kt = (/ 1 /)
212 nc1cnt_kt = (/ ktmax+1 /)
213 
214 nc1cor_kr = (/ 1 /)
215 nc1cnt_kr = (/ krmax+1 /)
216 
217 nc2cor_ij = (/ 1, 1 /)
218 nc2cnt_ij = (/ imax+1, jmax+1 /)
219 
220 nc3cor_ijkc = (/ 1, 1, 1 /)
221 nc3cnt_ijkc = (/ imax+1, jmax+1, kcmax+1 /)
222 
223 nc3cor_ijkt = (/ 1, 1, 1 /)
224 nc3cnt_ijkt = (/ imax+1, jmax+1, ktmax+1 /)
225 
226 nc3cor_ijkr = (/ 1, 1, 1 /)
227 nc3cnt_ijkr = (/ imax+1, jmax+1, krmax+1 /)
228 
229 #endif
230 
231 !-------- Create consecutively numbered file names --------
232 
233 if (flag_3d_output) then
234  ndat = ndat3d
235 else
236  ndat = ndat2d
237 end if
238 
239 if (ndat > 9999) then
240  errormsg = ' >>> output1: Too many time-slice files!'
241  call error(errormsg)
242 endif
243 
244 ndat_help = ndat
245 ndat_1000s = ndat_help/1000
246 ndat_help = ndat_help-ndat_1000s*1000
247 ndat_100s = ndat_help/100
248 ndat_help = ndat_help-ndat_100s*100
249 ndat_10s = ndat_help/10
250 ndat_help = ndat_help-ndat_10s*10
251 ndat_1s = ndat_help
252 
253 ch_1000s = char(ndat_1000s+ichar('0'))
254 ch_100s = char(ndat_100s +ichar('0'))
255 ch_10s = char(ndat_10s +ichar('0'))
256 ch_1s = char(ndat_1s +ichar('0'))
257 
258 if (flag_3d_output) then
259  filename = trim(runname)//ch_1000s//ch_100s//ch_10s//ch_1s &
260  //trim(filename_extension)
261 else
262  filename = trim(runname)//'_2d_'//ch_1000s//ch_100s//ch_10s//ch_1s &
263  //trim(filename_extension)
264 end if
265 
266 filename_with_path = trim(outpath)//'/'//trim(filename)
267 
268 !-------- File initialization --------
269 
270 #if (NETCDF==1) /* time-slice file in native binary format */
271 
272 ! ------ Open native binary file
273 
274 open(unit=11, iostat=ios, file=trim(filename_with_path), status='new', &
275  form='unformatted')
276 
277 if (ios /= 0) then
278  errormsg = ' >>> output1: Error when opening an erg file!'
279  call error(errormsg)
280 end if
281 
282 ! ------ Global attributes
283 
284 ch_attr_title = 'Time-slice output no. '//ch_1000s//ch_100s//ch_10s//ch_1s// &
285  ' of simulation '//trim(runname)
286 write(unit=11) ch_attr_title
287 
288 ch_attr_institution = 'Institute of Low Temperature Science, '// &
289  'Hokkaido University, Sapporo, Japan'
290 write(unit=11) ch_attr_institution
291 
292 ch_attr_source = 'SICOPOLIS Version '//version
293 write(unit=11) ch_attr_source
294 
295 call date_and_time(ch_date, ch_time, ch_zone)
296 ch_attr_history = ch_date(1:4)//'-'//ch_date(5:6)//'-'//ch_date(7:8)//' '// &
297  ch_time(1:2)//':'//ch_time(3:4)//':'//ch_time(5:6)//' '// &
298  ch_zone(1:3)//':'//ch_zone(4:5)//' - Data produced'
299 write(unit=11) ch_attr_history
300 
301 ch_attr_references = 'http://www.sicopolis.net/'
302 write(unit=11) ch_attr_references
303 
304 #elif (NETCDF==2) /* time-slice file in NetCDF format */
305 
306 if (allocated(coord_id)) deallocate(coord_id); allocate(coord_id(5))
307 coord_id(1) = 'x'; coord_id(2) = 'y'
308 coord_id(3) = 'zeta_c'; coord_id(4) = 'zeta_t'; coord_id(5) = 'zeta_r'
309 
310 ! ------ Open NetCDF file
311 
312 call check( nf90_create(trim(filename_with_path), nf90_noclobber, ncid), &
313  thisroutine )
314 
315 ! ------ Global attributes
316 
317 buffer = 'Time-slice output no. '//ch_1000s//ch_100s//ch_10s//ch_1s// &
318  ' of simulation '//trim(runname)
319 call check( nf90_put_att(ncid, nf90_global, 'title', trim(buffer)), &
320  thisroutine )
321 
322 buffer = 'Institute of Low Temperature Science, Hokkaido University, '// &
323  'Sapporo, Japan'
324 call check( nf90_put_att(ncid, nf90_global, 'institution', trim(buffer)), &
325  thisroutine )
326 
327 buffer = 'SICOPOLIS Version '//version
328 call check( nf90_put_att(ncid, nf90_global, 'source', trim(buffer)), &
329  thisroutine )
330 
331 call date_and_time(ch_date, ch_time, ch_zone)
332 buffer = ch_date(1:4)//'-'//ch_date(5:6)//'-'//ch_date(7:8)//' '// &
333  ch_time(1:2)//':'//ch_time(3:4)//':'//ch_time(5:6)//' '// &
334  ch_zone(1:3)//':'//ch_zone(4:5)//' - Data produced'
335 call check( nf90_put_att(ncid, nf90_global, 'history', trim(buffer)), &
336  thisroutine )
337 
338 buffer = 'http://www.sicopolis.net/'
339 call check( nf90_put_att(ncid, nf90_global, 'references', trim(buffer)), &
340  thisroutine )
341 
342 ! ------ Definition of the dimensions
343 
344 call check( nf90_def_dim(ncid, trim(coord_id(1)), imax+1, ncd), thisroutine )
345 call check( nf90_def_dim(ncid, trim(coord_id(2)), jmax+1, ncd), thisroutine )
346 call check( nf90_def_dim(ncid, trim(coord_id(3)), kcmax+1, ncd), thisroutine )
347 call check( nf90_def_dim(ncid, trim(coord_id(4)), ktmax+1, ncd), thisroutine )
348 call check( nf90_def_dim(ncid, trim(coord_id(5)), krmax+1, ncd), thisroutine )
349 
350 ! ------ Definition of the variables
351 
352 ! ---- crs
353 
354 call check( nf90_def_var(ncid, 'crs', nf90_byte, ncv), thisroutine )
355 #if (GRID==0 || GRID==1)
356 buffer = 'polar_stereographic'
357 call check( nf90_put_att(ncid, ncv, 'grid_mapping_name', trim(buffer)), &
358  thisroutine )
359 #elif (GRID==2)
360 buffer = 'latitude_longitude'
361 call check( nf90_put_att(ncid, ncv, 'grid_mapping_name', trim(buffer)), &
362  thisroutine )
363 #endif
364 #if (defined(ANT) \
365  || defined(asf) \
366  || defined(grl) \
367  || defined(scand) \
368  || defined(nhem) \
369  || defined(tibet) \
370  || defined(emtp2sge) \
371  || defined(xyz)) /* terrestrial ice sheet */
372 buffer = 'WGS84'
373 call check( nf90_put_att(ncid, ncv, 'ellipsoid', trim(buffer)), &
374  thisroutine )
375 #elif (defined(NMARS) || defined(SMARS)) /* Martian ice sheet */
376 buffer = 'Mars_ellipsoid'
377 call check( nf90_put_att(ncid, ncv, 'ellipsoid', trim(buffer)), &
378  thisroutine )
379 #else
380 errormsg = ' >>> output1: No valid domain (ANT, GRL etc.) specified!'
381 call error(errormsg)
382 #endif
383 #if (GRID==0 || GRID==1)
384 call check( nf90_put_att(ncid, ncv, 'false_easting', 0.0), &
385  thisroutine )
386 call check( nf90_put_att(ncid, ncv, 'false_northing', 0.0), &
387  thisroutine )
388 lon0 = real(lambda0*pi_180_inv,sp)
389 lon0 = modulo(lon0+180.0_sp, 360.0_sp)-180.0_sp
390 lon0 = real(nint(lon0*1.0e+04_sp),sp)*1.0e-04_sp
391 lat0 = real(phi0*pi_180_inv,sp)
392 if (lat0 > 90.0_sp) lat0 = 90.0_sp
393 if (lat0 < -90.0_sp) lat0 = -90.0_sp
394 lat0 = real(nint(lat0*1.0e+04_sp),sp)*1.0e-04_sp
395  ! reference longitude and standard parallel in deg rounded to 4 digits
396 if (lat0 >= 0.0_sp) then
397  call check( nf90_put_att(ncid, ncv, &
398  'latitude_of_projection_origin', 90.0), &
399  thisroutine )
400 else
401  call check( nf90_put_att(ncid, ncv, &
402  'latitude_of_projection_origin', -90.0), &
403  thisroutine )
404 end if
405 call check( nf90_put_att(ncid, ncv, &
406  'straight_vertical_longitude_from_pole', lon0), &
407  thisroutine )
408 call check( nf90_put_att(ncid, ncv, &
409  'standard_parallel', lat0), &
410  thisroutine )
411 #endif
412 
413 ! ---- time
414 
415 call check( nf90_def_var(ncid, 'time', nf90_float, ncv), &
416  thisroutine )
417 buffer = 'a'
418 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
419  thisroutine )
420 buffer = 'time'
421 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
422  thisroutine )
423 buffer = 'Time'
424 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
425  thisroutine )
426 
427 if (forcing_flag == 1) then
428 
429 ! ---- delta_ts
430 
431  call check( nf90_def_var(ncid, 'delta_ts', nf90_float, ncv), &
432  thisroutine )
433  buffer = 'degC'
434  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
435  thisroutine )
436  buffer = 'surface_temperature_anomaly'
437  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
438  thisroutine )
439  buffer = 'Surface temperature anomaly'
440  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
441  thisroutine )
442 
443 else if (forcing_flag == 2) then
444 
445 ! ---- glac_index
446 
447  call check( nf90_def_var(ncid, 'glac_index', nf90_float, ncv), &
448  thisroutine )
449  buffer = '1'
450  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
451  thisroutine )
452  buffer = 'glacial_index'
453  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
454  thisroutine )
455  buffer = 'Glacial index'
456  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
457  thisroutine )
458 
459 else if (forcing_flag == 3) then
460 
461 ! ---- glac_index
462 
463  call check( nf90_def_var(ncid, 'glac_index', nf90_float, ncv), &
464  thisroutine )
465  buffer = '1'
466  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
467  thisroutine )
468  buffer = 'glacial_index'
469  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
470  thisroutine )
471  buffer = 'Glacial index'
472  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
473  thisroutine )
474  buffer = 'This variable will be assigned a dummy value only!'
475  call check( nf90_put_att(ncid, ncv, 'comment', trim(buffer)), &
476  thisroutine )
477 
478 end if
479 
480 ! ---- z_sl
481 
482 call check( nf90_def_var(ncid, 'z_sl', nf90_float, ncv), &
483  thisroutine )
484 buffer = 'm'
485 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
486  thisroutine )
487 buffer = 'global_average_sea_level_change'
488 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
489  thisroutine )
490 buffer = 'Sea level'
491 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
492  thisroutine )
493 
494 ! ---- V_tot
495 
496 call check( nf90_def_var(ncid, 'V_tot', nf90_float, ncv), &
497  thisroutine )
498 buffer = 'm3'
499 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
500  thisroutine )
501 buffer = 'land_ice_volume'
502 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
503  thisroutine )
504 buffer = 'Ice volume'
505 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
506  thisroutine )
507 
508 ! ---- V_af
509 
510 call check( nf90_def_var(ncid, 'V_af', nf90_float, ncv), &
511  thisroutine )
512 buffer = 'm3'
513 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
514  thisroutine )
515 buffer = 'land_ice_volume_not_displacing_sea_water'
516 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
517  thisroutine )
518 buffer = 'Ice volume above flotation'
519 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
520  thisroutine )
521 
522 ! ---- A_grounded
523 
524 call check( nf90_def_var(ncid, 'A_grounded', nf90_float, ncv), &
525  thisroutine )
526 buffer = 'm2'
527 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
528  thisroutine )
529 buffer = 'grounded_land_ice_area'
530 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
531  thisroutine )
532 buffer = 'Area covered by grounded ice'
533 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
534  thisroutine )
535 
536 ! ---- A_floating
537 
538 call check( nf90_def_var(ncid, 'A_floating', nf90_float, ncv), &
539  thisroutine )
540 buffer = 'm2'
541 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
542  thisroutine )
543 buffer = 'floating_ice_shelf_area'
544 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
545  thisroutine )
546 buffer = 'Area covered by floating ice'
547 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
548  thisroutine )
549 
550 ! ---- x (= xi)
551 
552 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc1d), &
553  thisroutine )
554 call check( nf90_def_var(ncid, 'x', nf90_float, nc1d, ncv), &
555  thisroutine )
556 buffer = 'm'
557 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
558  thisroutine )
559 buffer = 'projection_x_coordinate'
560 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
561  thisroutine )
562 buffer = 'x-coordinate of the grid point i'
563 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
564  thisroutine )
565 call check( nf90_put_att(ncid, ncv, 'axis', 'x'), &
566  thisroutine )
567 
568 ! ---- y (= eta)
569 
570 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc1d), &
571  thisroutine )
572 call check( nf90_def_var(ncid, 'y', nf90_float, nc1d, ncv), &
573  thisroutine )
574 buffer = 'm'
575 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
576  thisroutine )
577 buffer = 'projection_y_coordinate'
578 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
579  thisroutine )
580 buffer = 'y-coordinate of the grid point j'
581 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
582  thisroutine )
583 call check( nf90_put_att(ncid, ncv, 'axis', 'y'), &
584  thisroutine )
585 
586 ! ---- sigma_level_c
587 
588 call check( nf90_inq_dimid(ncid, trim(coord_id(3)), nc1d), &
589  thisroutine )
590 call check( nf90_def_var(ncid, 'sigma_level_c', nf90_float, nc1d, ncv), &
591  thisroutine )
592 buffer = 'up'
593 call check( nf90_put_att(ncid, ncv, 'positive', trim(buffer)), &
594  thisroutine )
595 buffer = 'land_ice_kc_layer_sigma_coordinate'
596 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
597  thisroutine )
598 buffer = 'sigma-coordinate of the grid point kc'
599 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
600  thisroutine )
601 
602 ! ---- sigma_level_t
603 
604 call check( nf90_inq_dimid(ncid, trim(coord_id(4)), nc1d), &
605  thisroutine )
606 call check( nf90_def_var(ncid, 'sigma_level_t', nf90_float, nc1d, ncv), &
607  thisroutine )
608 buffer = 'up'
609 call check( nf90_put_att(ncid, ncv, 'positive', trim(buffer)), &
610  thisroutine )
611 buffer = 'land_ice_kt_layer_sigma_coordinate'
612 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
613  thisroutine )
614 buffer = 'sigma-coordinate of the grid point kt'
615 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
616  thisroutine )
617 
618 ! ---- sigma_level_r
619 
620 call check( nf90_inq_dimid(ncid, trim(coord_id(5)), nc1d), &
621  thisroutine )
622 call check( nf90_def_var(ncid, 'sigma_level_r', nf90_float, nc1d, ncv), &
623  thisroutine )
624 buffer = 'up'
625 call check( nf90_put_att(ncid, ncv, 'positive', trim(buffer)), &
626  thisroutine )
627 buffer = 'lithosphere_layer_sigma_coordinate'
628 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
629  thisroutine )
630 buffer = 'sigma-coordinate of the grid point kr'
631 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
632  thisroutine )
633 
634 ! ---- lon
635 
636 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
637  thisroutine )
638 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
639  thisroutine )
640 call check( nf90_def_var(ncid, 'lon', nf90_float, nc2d, ncv), &
641  thisroutine )
642 buffer = 'degrees_E'
643 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
644  thisroutine )
645 buffer = 'longitude'
646 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
647  thisroutine )
648 buffer = 'Geographical longitude'
649 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
650  thisroutine )
651 
652 ! ---- lat
653 
654 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
655  thisroutine )
656 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
657  thisroutine )
658 call check( nf90_def_var(ncid, 'lat', nf90_float, nc2d, ncv), &
659  thisroutine )
660 buffer = 'degrees_N'
661 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
662  thisroutine )
663 buffer = 'latitude'
664 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
665  thisroutine )
666 buffer = 'Geographical latitude'
667 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
668  thisroutine )
669 
670 ! ---- lambda
671 
672 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
673  thisroutine )
674 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
675  thisroutine )
676 call check( nf90_def_var(ncid, 'lambda', nf90_float, nc2d, ncv), &
677  thisroutine )
678 buffer = 'rad'
679 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
680  thisroutine )
681 buffer = 'longitude'
682 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
683  thisroutine )
684 buffer = 'Geographical longitude'
685 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
686  thisroutine )
687 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
688  thisroutine )
689 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
690  thisroutine )
691 
692 ! ---- phi
693 
694 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
695  thisroutine )
696 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
697  thisroutine )
698 call check( nf90_def_var(ncid, 'phi', nf90_float, nc2d, ncv), &
699  thisroutine )
700 buffer = 'rad'
701 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
702  thisroutine )
703 buffer = 'latitude'
704 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
705  thisroutine )
706 buffer = 'Geographical latitude'
707 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
708  thisroutine )
709 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
710  thisroutine )
711 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
712  thisroutine )
713 
714 ! ---- temp_s
715 
716 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
717  thisroutine )
718 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
719  thisroutine )
720 call check( nf90_def_var(ncid, 'temp_s', nf90_float, nc2d, ncv), &
721  thisroutine )
722 buffer = 'degC'
723 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
724  thisroutine )
725 buffer = 'surface_temperature'
726 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
727  thisroutine )
728 buffer = 'Temperature at the ice surface'
729 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
730  thisroutine )
731 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
732  thisroutine )
733 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
734  thisroutine )
735 
736 ! ---- accum
737 
738 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
739  thisroutine )
740 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
741  thisroutine )
742 call check( nf90_def_var(ncid, 'prec', nf90_float, nc2d, ncv), &
743  thisroutine )
744 buffer = 'm a-1'
745 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
746  thisroutine )
747 buffer = 'land_ice_precipitation'
748 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
749  thisroutine )
750 buffer = 'Annual precipitation at the ice surface'
751 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
752  thisroutine )
753 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
754  thisroutine )
755 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
756  thisroutine )
757 
758 ! ---- snowfall
759 
760 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
761  thisroutine )
762 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
763  thisroutine )
764 call check( nf90_def_var(ncid, 'snowfall', nf90_float, nc2d, ncv), &
765  thisroutine )
766 buffer = 'm a-1'
767 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
768  thisroutine )
769 buffer = 'land_ice_snowfall'
770 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
771  thisroutine )
772 buffer = 'Annual snowfall at the ice surface'
773 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
774  thisroutine )
775 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
776  thisroutine )
777 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
778  thisroutine )
779 
780 ! ---- rainfall
781 
782 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
783  thisroutine )
784 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
785  thisroutine )
786 call check( nf90_def_var(ncid, 'rainfall', nf90_float, nc2d, ncv), &
787  thisroutine )
788 buffer = 'm a-1'
789 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
790  thisroutine )
791 buffer = 'land_ice_rainfall'
792 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
793  thisroutine )
794 buffer = 'Annual rainfall at the ice surface'
795 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
796  thisroutine )
797 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
798  thisroutine )
799 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
800  thisroutine )
801 
802 ! ---- pdd
803 
804 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
805  thisroutine )
806 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
807  thisroutine )
808 call check( nf90_def_var(ncid, 'pdd', nf90_float, nc2d, ncv), &
809  thisroutine )
810 buffer = 'degC a'
811 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
812  thisroutine )
813 buffer = 'land_ice_positive_degree_days'
814 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
815  thisroutine )
816 buffer = 'Positive degree days at the ice surface'
817 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
818  thisroutine )
819 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
820  thisroutine )
821 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
822  thisroutine )
823 
824 ! ---- as_perp
825 
826 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
827  thisroutine )
828 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
829  thisroutine )
830 call check( nf90_def_var(ncid, 'as_perp', nf90_float, nc2d, ncv), &
831  thisroutine )
832 buffer = 'm a-1'
833 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
834  thisroutine )
835 buffer = 'land_ice_surface_mass_balance'
836 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
837  thisroutine )
838 buffer = 'Mass balance at the ice surface'
839 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
840  thisroutine )
841 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
842  thisroutine )
843 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
844  thisroutine )
845 
846 ! ---- as_perp_apl
847 
848 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
849  thisroutine )
850 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
851  thisroutine )
852 call check( nf90_def_var(ncid, 'as_perp_apl', nf90_float, nc2d, ncv), &
853  thisroutine )
854 buffer = 'm a-1'
855 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
856  thisroutine )
857 buffer = 'applied_land_ice_surface_mass_balance'
858 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
859  thisroutine )
860 buffer = 'Applied mass balance at the ice surface'
861 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
862  thisroutine )
863 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
864  thisroutine )
865 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
866  thisroutine )
867 
868 ! ---- smb_corr
869 
870 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
871  thisroutine )
872 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
873  thisroutine )
874 call check( nf90_def_var(ncid, 'smb_corr', nf90_float, nc2d, ncv), &
875  thisroutine )
876 buffer = 'm a-1'
877 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
878  thisroutine )
879 buffer = 'land_ice_surface_mass_balance_diagnosed_correction'
880 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
881  thisroutine )
882 buffer = 'Diagnosed correction of the mass balance at the ice surface'
883 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
884  thisroutine )
885 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
886  thisroutine )
887 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
888  thisroutine )
889 
890 #if (DISC>0) /* Ice discharge parameterisation */
891 
892 ! ---- dis_perp
893 
894 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
895  thisroutine )
896 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
897  thisroutine )
898 call check( nf90_def_var(ncid, 'dis_perp', nf90_float, nc2d, ncv), &
899  thisroutine )
900 buffer = 'm a-1'
901 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
902  thisroutine )
903 buffer = 'ice_discharge'
904 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
905  thisroutine )
906 buffer = 'Ice discharge'
907 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
908  thisroutine )
909 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
910  thisroutine )
911 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
912  thisroutine )
913 
914 ! ---- cst_dist
915 
916 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
917  thisroutine )
918 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
919  thisroutine )
920 call check( nf90_def_var(ncid, 'cst_dist', nf90_float, nc2d, ncv), &
921  thisroutine )
922 buffer = 'km'
923 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
924  thisroutine )
925 buffer = 'coastal_distance'
926 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
927  thisroutine )
928 buffer = 'Coastal distance'
929 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
930  thisroutine )
931 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
932  thisroutine )
933 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
934  thisroutine )
935 
936 ! ---- cos_grad_tc
937 
938 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
939  thisroutine )
940 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
941  thisroutine )
942 call check( nf90_def_var(ncid, 'cos_grad_tc', nf90_float, nc2d, ncv), &
943  thisroutine )
944 buffer = '1'
945 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
946  thisroutine )
947 buffer = 'cos_alpha'
948 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
949  thisroutine )
950 buffer = 'Cosine of angle between surface gradient and cst dist gradient'
951 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
952  thisroutine )
953 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
954  thisroutine )
955 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
956  thisroutine )
957 
958 ! ---- mask_mar
959 
960 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
961  thisroutine )
962 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
963  thisroutine )
964 call check( nf90_def_var(ncid, 'mask_mar', nf90_byte, nc2d, ncv), &
965  thisroutine )
966 buffer = 'marginal_ring_mask'
967 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
968  thisroutine )
969 buffer = 'Marginal ring mask'
970 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
971  thisroutine )
972 nc2flag = (/ 0, 1 /)
973 call check( nf90_put_att(ncid, ncv, 'flag_values', nc2flag), &
974  thisroutine )
975 buffer = 'no_ring '// &
976  'ring'
977 call check( nf90_put_att(ncid, ncv, 'flag_meanings', trim(buffer)), &
978  thisroutine )
979 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
980  thisroutine )
981 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
982  thisroutine )
983 
984 #endif
985 
986 ! ---- q_geo
987 
988 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
989  thisroutine )
990 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
991  thisroutine )
992 call check( nf90_def_var(ncid, 'q_geo', nf90_float, nc2d, ncv), &
993  thisroutine )
994 buffer = 'W m-2'
995 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
996  thisroutine )
997 buffer = 'upward_geothermal_heat_flux_at_ground_level'
998 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
999  thisroutine )
1000 buffer = 'Geothermal heat flux'
1001 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1002  thisroutine )
1003 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1004  thisroutine )
1005 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1006  thisroutine )
1007 
1008 ! ---- maske
1009 
1010 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1011  thisroutine )
1012 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1013  thisroutine )
1014 call check( nf90_def_var(ncid, 'maske', nf90_byte, nc2d, ncv), &
1015  thisroutine )
1016 buffer = 'ice_land_sea_mask'
1017 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1018  thisroutine )
1019 buffer = 'Ice-land-sea mask'
1020 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1021  thisroutine )
1022 nc4flag = (/ 0, 1, 2, 3 /)
1023 call check( nf90_put_att(ncid, ncv, 'flag_values', nc4flag), &
1024  thisroutine )
1025 buffer = 'glaciated_land '// &
1026  'ice_free_land '// &
1027  'sea '// &
1028  'floating_ice'
1029 call check( nf90_put_att(ncid, ncv, 'flag_meanings', trim(buffer)), &
1030  thisroutine )
1031 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1032  thisroutine )
1033 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1034  thisroutine )
1035 
1036 ! ---- maske_old
1037 
1038 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1039  thisroutine )
1040 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1041  thisroutine )
1042 call check( nf90_def_var(ncid, 'maske_old', nf90_byte, nc2d, ncv), &
1043  thisroutine )
1044 buffer = 'ice_land_sea_mask_old'
1045 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1046  thisroutine )
1047 buffer = 'Ice-land-sea mask (old)'
1048 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1049  thisroutine )
1050 nc4flag = (/ 0, 1, 2, 3 /)
1051 call check( nf90_put_att(ncid, ncv, 'flag_values', nc4flag), &
1052  thisroutine )
1053 buffer = 'glaciated_land '// &
1054  'ice_free_land '// &
1055  'sea '// &
1056  'floating_ice'
1057 call check( nf90_put_att(ncid, ncv, 'flag_meanings', trim(buffer)), &
1058  thisroutine )
1059 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1060  thisroutine )
1061 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1062  thisroutine )
1063 
1064 ! ---- mask_ablation_type
1065 
1066 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1067  thisroutine )
1068 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1069  thisroutine )
1070 call check( nf90_def_var(ncid, 'mask_ablation_type', nf90_byte, nc2d, ncv), &
1071  thisroutine )
1072 buffer = 'mask_indicating_ablation_type'
1073 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1074  thisroutine )
1075 buffer = 'Mask indicating ablation type'
1076 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1077  thisroutine )
1078 nc4flag = (/ -2, -1, 1, 2 /)
1079 call check( nf90_put_att(ncid, ncv, 'flag_values', nc4flag), &
1080  thisroutine )
1081 buffer = 'hidden (ocean) '// &
1082  'hidden (land) '// &
1083  'visible (land) '// &
1084  'visible (ocean)'
1085 call check( nf90_put_att(ncid, ncv, 'flag_meanings', trim(buffer)), &
1086  thisroutine )
1087 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1088  thisroutine )
1089 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1090  thisroutine )
1091 
1092 ! ---- n_cts
1093 
1094 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1095  thisroutine )
1096 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1097  thisroutine )
1098 call check( nf90_def_var(ncid, 'n_cts', nf90_byte, nc2d, ncv), &
1099  thisroutine )
1100 buffer = 'polythermal_condition_mask'
1101 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1102  thisroutine )
1103 buffer = 'Mask for polythermal conditions'
1104 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1105  thisroutine )
1106 nc3flag = (/ -1, 0, 1 /)
1107 call check( nf90_put_att(ncid, ncv, 'flag_values', nc3flag), &
1108  thisroutine )
1109 buffer = 'cold_base '// &
1110  'temperate_base_with_cold_ice_above '// &
1111  'temperate_base_with_temperate_ice_above'
1112 call check( nf90_put_att(ncid, ncv, 'flag_meanings', trim(buffer)), &
1113  thisroutine )
1114 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1115  thisroutine )
1116 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1117  thisroutine )
1118 
1119 ! ---- kc_cts
1120 
1121 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1122  thisroutine )
1123 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1124  thisroutine )
1125 call check( nf90_def_var(ncid, 'kc_cts', nf90_int, nc2d, ncv), &
1126  thisroutine )
1127 buffer = 'CTS_position_grid_index'
1128 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1129  thisroutine )
1130 buffer = 'Grid index of the CTS position'
1131 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1132  thisroutine )
1133 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1134  thisroutine )
1135 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1136  thisroutine )
1137 
1138 ! ---- zs
1139 
1140 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1141  thisroutine )
1142 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1143  thisroutine )
1144 call check( nf90_def_var(ncid, 'zs', nf90_float, nc2d, ncv), &
1145  thisroutine )
1146 buffer = 'm'
1147 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1148  thisroutine )
1149 buffer = 'surface_altitude'
1150 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1151  thisroutine )
1152 buffer = 'Topography of the free surface'
1153 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1154  thisroutine )
1155 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1156  thisroutine )
1157 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1158  thisroutine )
1159 
1160 ! ---- zm
1161 
1162 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1163  thisroutine )
1164 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1165  thisroutine )
1166 call check( nf90_def_var(ncid, 'zm', nf90_float, nc2d, ncv), &
1167  thisroutine )
1168 buffer = 'm'
1169 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1170  thisroutine )
1171 buffer = 'zm_interface_altitude'
1172 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1173  thisroutine )
1174 buffer = 'Topography of the z=zm interface'
1175 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1176  thisroutine )
1177 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1178  thisroutine )
1179 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1180  thisroutine )
1181 
1182 ! ---- zb
1183 
1184 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1185  thisroutine )
1186 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1187  thisroutine )
1188 call check( nf90_def_var(ncid, 'zb', nf90_float, nc2d, ncv), &
1189  thisroutine )
1190 buffer = 'm'
1191 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1192  thisroutine )
1193 buffer = 'ice_base_altitude'
1194 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1195  thisroutine )
1196 buffer = 'Topography of the ice base'
1197 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1198  thisroutine )
1199 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1200  thisroutine )
1201 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1202  thisroutine )
1203 
1204 ! ---- zl
1205 
1206 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1207  thisroutine )
1208 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1209  thisroutine )
1210 call check( nf90_def_var(ncid, 'zl', nf90_float, nc2d, ncv), &
1211  thisroutine )
1212 buffer = 'm'
1213 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1214  thisroutine )
1215 buffer = 'bedrock_altitude'
1216 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1217  thisroutine )
1218 buffer = 'Topography of the lithosphere surface'
1219 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1220  thisroutine )
1221 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1222  thisroutine )
1223 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1224  thisroutine )
1225 
1226 ! ---- zl0
1227 
1228 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1229  thisroutine )
1230 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1231  thisroutine )
1232 call check( nf90_def_var(ncid, 'zl0', nf90_float, nc2d, ncv), &
1233  thisroutine )
1234 buffer = 'm'
1235 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1236  thisroutine )
1237 buffer = 'isostatically_relaxed_bedrock_altitude'
1238 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1239  thisroutine )
1240 buffer = 'Topography of the isostatically relaxed lithosphere surface'
1241 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1242  thisroutine )
1243 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1244  thisroutine )
1245 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1246  thisroutine )
1247 
1248 ! ---- H_cold
1249 
1250 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1251  thisroutine )
1252 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1253  thisroutine )
1254 call check( nf90_def_var(ncid, 'H_cold', nf90_float, nc2d, ncv), &
1255  thisroutine )
1256 buffer = 'm'
1257 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1258  thisroutine )
1259 buffer = 'land_ice_cold_layer_thickness'
1260 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1261  thisroutine )
1262 buffer = 'Thickness of the cold ice layer'
1263 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1264  thisroutine )
1265 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1266  thisroutine )
1267 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1268  thisroutine )
1269 
1270 ! ---- H_temp
1271 
1272 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1273  thisroutine )
1274 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1275  thisroutine )
1276 call check( nf90_def_var(ncid, 'H_temp', nf90_float, nc2d, ncv), &
1277  thisroutine )
1278 buffer = 'm'
1279 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1280  thisroutine )
1281 buffer = 'land_ice_temperate_layer_thickness'
1282 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1283  thisroutine )
1284 buffer = 'Thickness of the temperate ice layer'
1285 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1286  thisroutine )
1287 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1288  thisroutine )
1289 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1290  thisroutine )
1291 
1292 ! ---- H
1293 
1294 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1295  thisroutine )
1296 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1297  thisroutine )
1298 call check( nf90_def_var(ncid, 'H', nf90_float, nc2d, ncv), &
1299  thisroutine )
1300 buffer = 'm'
1301 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1302  thisroutine )
1303 buffer = 'land_ice_thickness'
1304 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1305  thisroutine )
1306 buffer = 'Ice thickness'
1307 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1308  thisroutine )
1309 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1310  thisroutine )
1311 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1312  thisroutine )
1313 
1314 ! ---- H_R
1315 
1316 call check( nf90_def_var(ncid, 'H_R', nf90_float, ncv), &
1317  thisroutine )
1318 buffer = 'm'
1319 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1320  thisroutine )
1321 buffer = 'lithosphere_layer_thickness'
1322 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1323  thisroutine )
1324 buffer = 'Thickness of the lithosphere layer'
1325 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1326  thisroutine )
1327 
1328 ! ---- Q_bm
1329 
1330 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1331  thisroutine )
1332 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1333  thisroutine )
1334 call check( nf90_def_var(ncid, 'Q_bm', nf90_float, nc2d, ncv), &
1335  thisroutine )
1336 buffer = 'm a-1'
1337 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1338  thisroutine )
1339 buffer = 'land_ice_basal_melt_rate'
1340 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1341  thisroutine )
1342 buffer = 'Basal melting rate'
1343 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1344  thisroutine )
1345 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1346  thisroutine )
1347 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1348  thisroutine )
1349 
1350 ! ---- Q_tld
1351 
1352 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1353  thisroutine )
1354 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1355  thisroutine )
1356 call check( nf90_def_var(ncid, 'Q_tld', nf90_float, nc2d, ncv), &
1357  thisroutine )
1358 buffer = 'm a-1'
1359 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1360  thisroutine )
1361 buffer = 'land_ice_temperate_layer_water_drainage'
1362 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1363  thisroutine )
1364 buffer = 'Water drainage from the temperate layer'
1365 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1366  thisroutine )
1367 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1368  thisroutine )
1369 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1370  thisroutine )
1371 
1372 ! ---- am_perp
1373 
1374 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1375  thisroutine )
1376 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1377  thisroutine )
1378 call check( nf90_def_var(ncid, 'am_perp', nf90_float, nc2d, ncv), &
1379  thisroutine )
1380 buffer = 'm a-1'
1381 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1382  thisroutine )
1383 buffer = 'land_ice_volume_flux_across_zm_interface'
1384 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1385  thisroutine )
1386 buffer = 'Volume flux across the z=zm interface'
1387 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1388  thisroutine )
1389 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1390  thisroutine )
1391 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1392  thisroutine )
1393 
1394 ! ---- qx
1395 
1396 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1397  thisroutine )
1398 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1399  thisroutine )
1400 call check( nf90_def_var(ncid, 'qx', nf90_float, nc2d, ncv), &
1401  thisroutine )
1402 buffer = 'm2 a-1'
1403 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1404  thisroutine )
1405 buffer = 'land_ice_vertical_integral_x_velocity'
1406 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1407  thisroutine )
1408 buffer = 'Horizontal volume flux qx'
1409 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1410  thisroutine )
1411 buffer = 'Staggered grid variable, defined at (j,i+1/2)'
1412 call check( nf90_put_att(ncid, ncv, 'comment', trim(buffer)), &
1413  thisroutine )
1414 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1415  thisroutine )
1416 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1417  thisroutine )
1418 
1419 ! ---- qy
1420 
1421 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1422  thisroutine )
1423 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1424  thisroutine )
1425 call check( nf90_def_var(ncid, 'qy', nf90_float, nc2d, ncv), &
1426  thisroutine )
1427 buffer = 'm2 a-1'
1428 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1429  thisroutine )
1430 buffer = 'land_ice_vertical_integral_y_velocity'
1431 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1432  thisroutine )
1433 buffer = 'Horizontal volume flux qy'
1434 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1435  thisroutine )
1436 buffer = 'Staggered grid variable, defined at (j+1/2,i)'
1437 call check( nf90_put_att(ncid, ncv, 'comment', trim(buffer)), &
1438  thisroutine )
1439 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1440  thisroutine )
1441 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1442  thisroutine )
1443 
1444 ! ---- dzs_dt (= dzs_dtau)
1445 
1446 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1447  thisroutine )
1448 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1449  thisroutine )
1450 call check( nf90_def_var(ncid, 'dzs_dt', nf90_float, nc2d, ncv), &
1451  thisroutine )
1452 buffer = 'm a-1'
1453 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1454  thisroutine )
1455 buffer = 'tendency_of_surface_altitude'
1456 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1457  thisroutine )
1458 buffer = 'Rate of change of the topography of the free surface'
1459 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1460  thisroutine )
1461 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1462  thisroutine )
1463 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1464  thisroutine )
1465 
1466 ! ---- dzm_dt (= dzm_dtau)
1467 
1468 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1469  thisroutine )
1470 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1471  thisroutine )
1472 call check( nf90_def_var(ncid, 'dzm_dt', nf90_float, nc2d, ncv), &
1473  thisroutine )
1474 buffer = 'm a-1'
1475 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1476  thisroutine )
1477 buffer = 'tendency_of_zm_interface_altitude'
1478 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1479  thisroutine )
1480 buffer = 'Rate of change of the topography of the z=zm interface'
1481 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1482  thisroutine )
1483 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1484  thisroutine )
1485 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1486  thisroutine )
1487 
1488 ! ---- dzb_dt (= dzb_dtau)
1489 
1490 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1491  thisroutine )
1492 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1493  thisroutine )
1494 call check( nf90_def_var(ncid, 'dzb_dt', nf90_float, nc2d, ncv), &
1495  thisroutine )
1496 buffer = 'm a-1'
1497 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1498  thisroutine )
1499 buffer = 'tendency_of_ice_base_altitude'
1500 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1501  thisroutine )
1502 buffer = 'Rate of change of the topography of the ice base'
1503 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1504  thisroutine )
1505 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1506  thisroutine )
1507 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1508  thisroutine )
1509 
1510 ! ---- dzl_dt (= dzl_dtau)
1511 
1512 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1513  thisroutine )
1514 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1515  thisroutine )
1516 call check( nf90_def_var(ncid, 'dzl_dt', nf90_float, nc2d, ncv), &
1517  thisroutine )
1518 buffer = 'm a-1'
1519 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1520  thisroutine )
1521 buffer = 'tendency_of_bedrock_altitude'
1522 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1523  thisroutine )
1524 buffer = 'Rate of change of the topography of the lithosphere surface'
1525 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1526  thisroutine )
1527 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1528  thisroutine )
1529 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1530  thisroutine )
1531 
1532 ! ---- dH_c_dt (= dH_c_dtau)
1533 
1534 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1535  thisroutine )
1536 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1537  thisroutine )
1538 call check( nf90_def_var(ncid, 'dH_c_dt', nf90_float, nc2d, ncv), &
1539  thisroutine )
1540 buffer = 'm a-1'
1541 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1542  thisroutine )
1543 buffer = 'tendency_of_land_ice_kc_layer_thickness'
1544 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1545  thisroutine )
1546 buffer = 'Rate of change of the thickness of the upper (kc) ice layer'
1547 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1548  thisroutine )
1549 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1550  thisroutine )
1551 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1552  thisroutine )
1553 
1554 ! ---- dH_t_dt (= dH_t_dtau)
1555 
1556 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1557  thisroutine )
1558 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1559  thisroutine )
1560 call check( nf90_def_var(ncid, 'dH_t_dt', nf90_float, nc2d, ncv), &
1561  thisroutine )
1562 buffer = 'm a-1'
1563 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1564  thisroutine )
1565 buffer = 'tendency_of_land_ice_kt_layer_thickness'
1566 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1567  thisroutine )
1568 buffer = 'Rate of change of the thickness of the lower (kt) ice layer'
1569 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1570  thisroutine )
1571 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1572  thisroutine )
1573 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1574  thisroutine )
1575 
1576 ! ---- dH_dt (= dH_dtau)
1577 
1578 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1579  thisroutine )
1580 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1581  thisroutine )
1582 call check( nf90_def_var(ncid, 'dH_dt', nf90_float, nc2d, ncv), &
1583  thisroutine )
1584 buffer = 'm a-1'
1585 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1586  thisroutine )
1587 buffer = 'tendency_of_land_ice_thickness'
1588 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1589  thisroutine )
1590 buffer = 'Rate of change of the ice thickness'
1591 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1592  thisroutine )
1593 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1594  thisroutine )
1595 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1596  thisroutine )
1597 
1598 ! ---- vx_b_g
1599 
1600 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1601  thisroutine )
1602 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1603  thisroutine )
1604 call check( nf90_def_var(ncid, 'vx_b_g', nf90_float, nc2d, ncv), &
1605  thisroutine )
1606 buffer = 'm a-1'
1607 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1608  thisroutine )
1609 buffer = 'land_ice_base_x_velocity'
1610 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1611  thisroutine )
1612 buffer = 'Horizontal velocity vx at the ice base'
1613 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1614  thisroutine )
1615 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1616  thisroutine )
1617 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1618  thisroutine )
1619 
1620 ! ---- vy_b_g
1621 
1622 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1623  thisroutine )
1624 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1625  thisroutine )
1626 call check( nf90_def_var(ncid, 'vy_b_g', nf90_float, nc2d, ncv), &
1627  thisroutine )
1628 buffer = 'm a-1'
1629 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1630  thisroutine )
1631 buffer = 'land_ice_base_y_velocity'
1632 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1633  thisroutine )
1634 buffer = 'Horizontal velocity vy at the ice base'
1635 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1636  thisroutine )
1637 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1638  thisroutine )
1639 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1640  thisroutine )
1641 
1642 ! ---- vz_b
1643 
1644 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1645  thisroutine )
1646 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1647  thisroutine )
1648 call check( nf90_def_var(ncid, 'vz_b', nf90_float, nc2d, ncv), &
1649  thisroutine )
1650 buffer = 'm a-1'
1651 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1652  thisroutine )
1653 buffer = 'land_ice_base_z_velocity'
1654 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1655  thisroutine )
1656 buffer = 'Vertical velocity vz at the ice base'
1657 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1658  thisroutine )
1659 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1660  thisroutine )
1661 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1662  thisroutine )
1663 
1664 ! ---- vh_b
1665 
1666 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1667  thisroutine )
1668 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1669  thisroutine )
1670 call check( nf90_def_var(ncid, 'vh_b', nf90_float, nc2d, ncv), &
1671  thisroutine )
1672 buffer = 'm a-1'
1673 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1674  thisroutine )
1675 buffer = 'land_ice_base_horizontal_velocity'
1676 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1677  thisroutine )
1678 buffer = 'Horizontal velocity vh at the ice base'
1679 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1680  thisroutine )
1681 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1682  thisroutine )
1683 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1684  thisroutine )
1685 
1686 ! ---- vx_s_g
1687 
1688 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1689  thisroutine )
1690 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1691  thisroutine )
1692 call check( nf90_def_var(ncid, 'vx_s_g', nf90_float, nc2d, ncv), &
1693  thisroutine )
1694 buffer = 'm a-1'
1695 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1696  thisroutine )
1697 buffer = 'land_ice_surface_x_velocity'
1698 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1699  thisroutine )
1700 buffer = 'Horizontal velocity vx at the ice surface'
1701 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1702  thisroutine )
1703 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1704  thisroutine )
1705 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1706  thisroutine )
1707 
1708 ! ---- vy_s_g
1709 
1710 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1711  thisroutine )
1712 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1713  thisroutine )
1714 call check( nf90_def_var(ncid, 'vy_s_g', nf90_float, nc2d, ncv), &
1715  thisroutine )
1716 buffer = 'm a-1'
1717 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1718  thisroutine )
1719 buffer = 'land_ice_surface_y_velocity'
1720 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1721  thisroutine )
1722 buffer = 'Horizontal velocity vy at the ice surface'
1723 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1724  thisroutine )
1725 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1726  thisroutine )
1727 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1728  thisroutine )
1729 
1730 ! ---- vz_s
1731 
1732 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1733  thisroutine )
1734 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1735  thisroutine )
1736 call check( nf90_def_var(ncid, 'vz_s', nf90_float, nc2d, ncv), &
1737  thisroutine )
1738 buffer = 'm a-1'
1739 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1740  thisroutine )
1741 buffer = 'land_ice_surface_z_velocity'
1742 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1743  thisroutine )
1744 buffer = 'Vertical velocity vz at the ice surface'
1745 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1746  thisroutine )
1747 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1748  thisroutine )
1749 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1750  thisroutine )
1751 
1752 ! ---- vh_s
1753 
1754 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1755  thisroutine )
1756 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1757  thisroutine )
1758 call check( nf90_def_var(ncid, 'vh_s', nf90_float, nc2d, ncv), &
1759  thisroutine )
1760 buffer = 'm a-1'
1761 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1762  thisroutine )
1763 buffer = 'land_ice_surface_horizontal_velocity'
1764 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1765  thisroutine )
1766 buffer = 'Horizontal velocity vh at the ice surface'
1767 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1768  thisroutine )
1769 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1770  thisroutine )
1771 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1772  thisroutine )
1773 
1774 ! ---- vx_m_g
1775 
1776 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1777  thisroutine )
1778 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1779  thisroutine )
1780 call check( nf90_def_var(ncid, 'vx_m_g', nf90_float, nc2d, ncv), &
1781  thisroutine )
1782 buffer = 'm a-1'
1783 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1784  thisroutine )
1785 buffer = 'land_ice_vertical_mean_x_velocity'
1786 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1787  thisroutine )
1788 buffer = 'Vertical mean of horizontal velocity vx'
1789 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1790  thisroutine )
1791 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1792  thisroutine )
1793 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1794  thisroutine )
1795 
1796 ! ---- vy_m_g
1797 
1798 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1799  thisroutine )
1800 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1801  thisroutine )
1802 call check( nf90_def_var(ncid, 'vy_m_g', nf90_float, nc2d, ncv), &
1803  thisroutine )
1804 buffer = 'm a-1'
1805 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1806  thisroutine )
1807 buffer = 'land_ice_vertical_mean_y_velocity'
1808 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1809  thisroutine )
1810 buffer = 'Vertical mean of horizontal velocity vy'
1811 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1812  thisroutine )
1813 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1814  thisroutine )
1815 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1816  thisroutine )
1817 
1818 ! ---- vh_m
1819 
1820 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1821  thisroutine )
1822 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1823  thisroutine )
1824 call check( nf90_def_var(ncid, 'vh_m', nf90_float, nc2d, ncv), &
1825  thisroutine )
1826 buffer = 'm a-1'
1827 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1828  thisroutine )
1829 buffer = 'land_ice_vertical_mean_horizontal_velocity'
1830 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1831  thisroutine )
1832 buffer = 'Vertical mean of horizontal velocity vh'
1833 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1834  thisroutine )
1835 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1836  thisroutine )
1837 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1838  thisroutine )
1839 
1840 ! ---- temp_b
1841 
1842 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1843  thisroutine )
1844 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1845  thisroutine )
1846 call check( nf90_def_var(ncid, 'temp_b', nf90_float, nc2d, ncv), &
1847  thisroutine )
1848 buffer = 'degC'
1849 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1850  thisroutine )
1851 buffer = 'basal_temperature'
1852 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1853  thisroutine )
1854 buffer = 'Temperature at the ice base'
1855 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1856  thisroutine )
1857 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1858  thisroutine )
1859 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1860  thisroutine )
1861 
1862 ! ---- temph_b
1863 
1864 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1865  thisroutine )
1866 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1867  thisroutine )
1868 call check( nf90_def_var(ncid, 'temph_b', nf90_float, nc2d, ncv), &
1869  thisroutine )
1870 buffer = 'degC'
1871 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1872  thisroutine )
1873 buffer = 'basal_temperature_rel_to_pmp'
1874 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1875  thisroutine )
1876 buffer = 'Temperature at the ice base relative to the pressure melting point'
1877 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1878  thisroutine )
1879 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1880  thisroutine )
1881 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1882  thisroutine )
1883 
1884 ! ---- tau_b_driving
1885 
1886 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1887  thisroutine )
1888 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1889  thisroutine )
1890 call check( nf90_def_var(ncid, 'tau_b_driving', nf90_float, nc2d, ncv), &
1891  thisroutine )
1892 buffer = 'Pa'
1893 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1894  thisroutine )
1895 buffer = 'magnitude_of_land_ice_driving_stress'
1896 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1897  thisroutine )
1898 buffer = 'Driving stress'
1899 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1900  thisroutine )
1901 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1902  thisroutine )
1903 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1904  thisroutine )
1905 
1906 ! ---- tau_b_drag
1907 
1908 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1909  thisroutine )
1910 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1911  thisroutine )
1912 call check( nf90_def_var(ncid, 'tau_b_drag', nf90_float, nc2d, ncv), &
1913  thisroutine )
1914 buffer = 'Pa'
1915 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1916  thisroutine )
1917 buffer = 'magnitude_of_land_ice_basal_drag'
1918 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1919  thisroutine )
1920 buffer = 'Basal drag'
1921 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1922  thisroutine )
1923 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1924  thisroutine )
1925 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1926  thisroutine )
1927 
1928 ! ---- p_b_w
1929 
1930 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1931  thisroutine )
1932 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1933  thisroutine )
1934 call check( nf90_def_var(ncid, 'p_b_w', nf90_float, nc2d, ncv), &
1935  thisroutine )
1936 buffer = 'Pa'
1937 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1938  thisroutine )
1939 buffer = 'basal_water_pressure'
1940 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1941  thisroutine )
1942 buffer = 'Basal water pressure'
1943 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1944  thisroutine )
1945 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1946  thisroutine )
1947 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1948  thisroutine )
1949 
1950 ! ---- q_w
1951 
1952 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1953  thisroutine )
1954 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1955  thisroutine )
1956 call check( nf90_def_var(ncid, 'q_w', nf90_float, nc2d, ncv), &
1957  thisroutine )
1958 buffer = 'm2 a-1'
1959 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1960  thisroutine )
1961 buffer = 'basal_water_flux'
1962 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1963  thisroutine )
1964 buffer = 'Volume flux of basal water'
1965 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1966  thisroutine )
1967 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1968  thisroutine )
1969 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1970  thisroutine )
1971 
1972 ! ---- q_w_x
1973 
1974 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1975  thisroutine )
1976 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1977  thisroutine )
1978 call check( nf90_def_var(ncid, 'q_w_x', nf90_float, nc2d, ncv), &
1979  thisroutine )
1980 buffer = 'm2 a-1'
1981 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
1982  thisroutine )
1983 buffer = 'basal_water_flux_x'
1984 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
1985  thisroutine )
1986 buffer = 'Volume flux of basal water in x-direction'
1987 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
1988  thisroutine )
1989 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
1990  thisroutine )
1991 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
1992  thisroutine )
1993 
1994 ! ---- q_w_y
1995 
1996 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
1997  thisroutine )
1998 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
1999  thisroutine )
2000 call check( nf90_def_var(ncid, 'q_w_y', nf90_float, nc2d, ncv), &
2001  thisroutine )
2002 buffer = 'm2 a-1'
2003 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2004  thisroutine )
2005 buffer = 'basal_water_flux_y'
2006 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2007  thisroutine )
2008 buffer = 'Volume flux of basal water in y-direction'
2009 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2010  thisroutine )
2011 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2012  thisroutine )
2013 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2014  thisroutine )
2015 
2016 ! ---- H_w
2017 
2018 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
2019  thisroutine )
2020 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
2021  thisroutine )
2022 call check( nf90_def_var(ncid, 'H_w', nf90_float, nc2d, ncv), &
2023  thisroutine )
2024 buffer = 'm'
2025 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2026  thisroutine )
2027 buffer = 'water_column_thickness'
2028 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2029  thisroutine )
2030 buffer = 'Thickness of the water column under the ice base'
2031 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2032  thisroutine )
2033 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2034  thisroutine )
2035 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2036  thisroutine )
2037 
2038 ! ---- q_gl_g
2039 
2040 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
2041  thisroutine )
2042 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
2043  thisroutine )
2044 call check( nf90_def_var(ncid, 'q_gl_g', nf90_float, nc2d, ncv), &
2045  thisroutine )
2046 buffer = 'm2 a-1'
2047 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2048  thisroutine )
2049 buffer = 'land_ice_volume_flux_across_gl'
2050 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2051  thisroutine )
2052 buffer = 'Horizontal volume flux across the grounding line'
2053 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2054  thisroutine )
2055 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2056  thisroutine )
2057 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2058  thisroutine )
2059 
2060 ! ---- q_cf_g
2061 
2062 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
2063  thisroutine )
2064 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
2065  thisroutine )
2066 call check( nf90_def_var(ncid, 'q_cf_g', nf90_float, nc2d, ncv), &
2067  thisroutine )
2068 buffer = 'm a-1'
2069 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2070  thisroutine )
2071 buffer = 'land_ice_volume_flux_due_to_calving'
2072 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2073  thisroutine )
2074 buffer = 'Calving flux'
2075 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2076  thisroutine )
2077 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2078  thisroutine )
2079 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2080  thisroutine )
2081 
2082 ! ---- ratio_sl_x
2083 
2084 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
2085  thisroutine )
2086 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
2087  thisroutine )
2088 call check( nf90_def_var(ncid, 'ratio_sl_x', nf90_float, nc2d, ncv), &
2089  thisroutine )
2090 buffer = '-'
2091 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2092  thisroutine )
2093 buffer = 'land_ice_x_slip_ratio'
2094 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2095  thisroutine )
2096 buffer = 'Ratio of basal to surface velocity (slip ratio) in x-direction, ' &
2097  // 'at (i+1/2,j)'
2098 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2099  thisroutine )
2100 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2101  thisroutine )
2102 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2103  thisroutine )
2104 
2105 ! ---- ratio_sl_y
2106 
2107 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
2108  thisroutine )
2109 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
2110  thisroutine )
2111 call check( nf90_def_var(ncid, 'ratio_sl_y', nf90_float, nc2d, ncv), &
2112  thisroutine )
2113 buffer = '-'
2114 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2115  thisroutine )
2116 buffer = 'land_ice_y_slip_ratio'
2117 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2118  thisroutine )
2119 buffer = 'Ratio of basal to surface velocity (slip ratio) in y-direction, ' &
2120  // 'at (i+1/2,j)'
2121 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2122  thisroutine )
2123 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2124  thisroutine )
2125 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2126  thisroutine )
2127 
2128 ! ---- flag_shelfy_stream_x
2129 
2130 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
2131  thisroutine )
2132 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
2133  thisroutine )
2134 call check( nf90_def_var(ncid, 'flag_shelfy_stream_x', nf90_byte, nc2d, ncv), &
2135  thisroutine )
2136 buffer = '-'
2137 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2138  thisroutine )
2139 buffer = 'land_ice_x_shelfy_stream_flag'
2140 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2141  thisroutine )
2142 buffer = 'Shelfy stream flag in x-direction, at (i+1/2,j)'
2143 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2144  thisroutine )
2145 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2146  thisroutine )
2147 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2148  thisroutine )
2149 
2150 ! ---- flag_shelfy_stream_y
2151 
2152 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
2153  thisroutine )
2154 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
2155  thisroutine )
2156 call check( nf90_def_var(ncid, 'flag_shelfy_stream_y', nf90_byte, nc2d, ncv), &
2157  thisroutine )
2158 buffer = '-'
2159 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2160  thisroutine )
2161 buffer = 'land_ice_y_shelfy_stream_flag'
2162 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2163  thisroutine )
2164 buffer = 'Shelfy stream flag in y-direction, at (i,j+1/2)'
2165 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2166  thisroutine )
2167 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2168  thisroutine )
2169 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2170  thisroutine )
2171 
2172 ! ---- flag_shelfy_stream
2173 
2174 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
2175  thisroutine )
2176 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
2177  thisroutine )
2178 call check( nf90_def_var(ncid, 'flag_shelfy_stream', nf90_byte, nc2d, ncv), &
2179  thisroutine )
2180 buffer = '-'
2181 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2182  thisroutine )
2183 buffer = 'land_ice_shelfy_stream_flag'
2184 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2185  thisroutine )
2186 buffer = 'Shelfy stream flag'
2187 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2188  thisroutine )
2189 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2190  thisroutine )
2191 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2192  thisroutine )
2193 
2194 ! ---- flag_grounding_line_1
2195 
2196 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
2197  thisroutine )
2198 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
2199  thisroutine )
2200 call check( nf90_def_var(ncid, 'flag_grounding_line_1', nf90_byte, nc2d, ncv), &
2201  thisroutine )
2202 buffer = '-'
2203 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2204  thisroutine )
2205 buffer = 'land_ice_grounding_line_1_flag'
2206 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2207  thisroutine )
2208 buffer = 'Grounding line flag 1'
2209 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2210  thisroutine )
2211 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2212  thisroutine )
2213 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2214  thisroutine )
2215 
2216 ! ---- flag_grounding_line_2
2217 
2218 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
2219  thisroutine )
2220 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
2221  thisroutine )
2222 call check( nf90_def_var(ncid, 'flag_grounding_line_2', nf90_byte, nc2d, ncv), &
2223  thisroutine )
2224 buffer = '-'
2225 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2226  thisroutine )
2227 buffer = 'land_ice_grounding_line_2_flag'
2228 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2229  thisroutine )
2230 buffer = 'Grounding line flag 2'
2231 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2232  thisroutine )
2233 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2234  thisroutine )
2235 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2236  thisroutine )
2237 
2238 ! ---- flag_calving_front_1
2239 
2240 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
2241  thisroutine )
2242 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
2243  thisroutine )
2244 call check( nf90_def_var(ncid, 'flag_calving_front_1', nf90_byte, nc2d, ncv), &
2245  thisroutine )
2246 buffer = '-'
2247 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2248  thisroutine )
2249 buffer = 'land_ice_calving_front_1_flag'
2250 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2251  thisroutine )
2252 buffer = 'Calving front flag 1'
2253 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2254  thisroutine )
2255 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2256  thisroutine )
2257 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2258  thisroutine )
2259 
2260 ! ---- flag_calving_front_2
2261 
2262 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
2263  thisroutine )
2264 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
2265  thisroutine )
2266 call check( nf90_def_var(ncid, 'flag_calving_front_2', nf90_byte, nc2d, ncv), &
2267  thisroutine )
2268 buffer = '-'
2269 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2270  thisroutine )
2271 buffer = 'land_ice_calving_front_2_flag'
2272 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2273  thisroutine )
2274 buffer = 'Calving front flag 2'
2275 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2276  thisroutine )
2277 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2278  thisroutine )
2279 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2280  thisroutine )
2281 
2282 ! ---- flag_grounded_front_a_1
2283 
2284 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
2285  thisroutine )
2286 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
2287  thisroutine )
2288 call check( nf90_def_var(ncid, 'flag_grounded_front_a_1', nf90_byte, nc2d, ncv), &
2289  thisroutine )
2290 buffer = '-'
2291 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2292  thisroutine )
2293 buffer = 'land_ice_grounded_front_a_1_flag'
2294 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2295  thisroutine )
2296 buffer = 'Grounded front flag a 1'
2297 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2298  thisroutine )
2299 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2300  thisroutine )
2301 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2302  thisroutine )
2303 
2304 ! ---- flag_grounded_front_a_2
2305 
2306 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
2307  thisroutine )
2308 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
2309  thisroutine )
2310 call check( nf90_def_var(ncid, 'flag_grounded_front_a_2', nf90_byte, nc2d, ncv), &
2311  thisroutine )
2312 buffer = '-'
2313 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2314  thisroutine )
2315 buffer = 'land_ice_grounded_front_a_2_flag'
2316 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2317  thisroutine )
2318 buffer = 'Grounded front flag a 2'
2319 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2320  thisroutine )
2321 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2322  thisroutine )
2323 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2324  thisroutine )
2325 
2326 ! ---- flag_grounded_front_b_1
2327 
2328 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
2329  thisroutine )
2330 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
2331  thisroutine )
2332 call check( nf90_def_var(ncid, 'flag_grounded_front_b_1', nf90_byte, nc2d, ncv), &
2333  thisroutine )
2334 buffer = '-'
2335 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2336  thisroutine )
2337 buffer = 'land_ice_grounded_front_b_1_flag'
2338 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2339  thisroutine )
2340 buffer = 'Grounded front flag b 1'
2341 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2342  thisroutine )
2343 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2344  thisroutine )
2345 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2346  thisroutine )
2347 
2348 ! ---- flag_grounded_front_b_2
2349 
2350 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
2351  thisroutine )
2352 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
2353  thisroutine )
2354 call check( nf90_def_var(ncid, 'flag_grounded_front_b_2', nf90_byte, nc2d, ncv), &
2355  thisroutine )
2356 buffer = '-'
2357 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2358  thisroutine )
2359 buffer = 'land_ice_grounded_front_b_2_flag'
2360 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2361  thisroutine )
2362 buffer = 'Grounded front flag b 2'
2363 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2364  thisroutine )
2365 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2366  thisroutine )
2367 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2368  thisroutine )
2369 
2370 ! ---- vis_int_g
2371 
2372 call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc2d(1)), &
2373  thisroutine )
2374 call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc2d(2)), &
2375  thisroutine )
2376 call check( nf90_def_var(ncid, 'vis_int_g', nf90_float, nc2d, ncv), &
2377  thisroutine )
2378 buffer = 'Pa s m'
2379 call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2380  thisroutine )
2381 buffer = 'land_ice_vertical_integral_viscosity'
2382 call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2383  thisroutine )
2384 buffer = 'Depth-integrated viscosity'
2385 call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2386  thisroutine )
2387 call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2388  thisroutine )
2389 call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2390  thisroutine )
2391 
2392 if (flag_3d_output) then
2393 
2394 ! ---- vx_c
2395 
2396  call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc3d(1)), &
2397  thisroutine )
2398  call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc3d(2)), &
2399  thisroutine )
2400  call check( nf90_inq_dimid(ncid, trim(coord_id(3)), nc3d(3)), &
2401  thisroutine )
2402  call check( nf90_def_var(ncid, 'vx_c', nf90_float, nc3d, ncv), &
2403  thisroutine )
2404  buffer = 'm a-1'
2405  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2406  thisroutine )
2407  buffer = 'land_ice_kc_layer_x_velocity'
2408  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2409  thisroutine )
2410  buffer = 'Horizontal velocity vx in the upper (kc) ice layer'
2411  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2412  thisroutine )
2413  buffer = 'Staggered grid variable, defined at (kc,j,i+1/2)'
2414  call check( nf90_put_att(ncid, ncv, 'comment', trim(buffer)), &
2415  thisroutine )
2416  call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2417  thisroutine )
2418  call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2419  thisroutine )
2420 
2421 ! ---- vy_c
2422 
2423  call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc3d(1)), &
2424  thisroutine )
2425  call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc3d(2)), &
2426  thisroutine )
2427  call check( nf90_inq_dimid(ncid, trim(coord_id(3)), nc3d(3)), &
2428  thisroutine )
2429  call check( nf90_def_var(ncid, 'vy_c', nf90_float, nc3d, ncv), &
2430  thisroutine )
2431  buffer = 'm a-1'
2432  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2433  thisroutine )
2434  buffer = 'land_ice_kc_layer_y_velocity'
2435  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2436  thisroutine )
2437  buffer = 'Horizontal velocity vy in the upper (kc) ice layer'
2438  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2439  thisroutine )
2440  buffer = 'Staggered grid variable, defined at (kc,j+1/2,i)'
2441  call check( nf90_put_att(ncid, ncv, 'comment', trim(buffer)), &
2442  thisroutine )
2443  call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2444  thisroutine )
2445  call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2446  thisroutine )
2447 
2448 ! ---- vz_c
2449 
2450  call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc3d(1)), &
2451  thisroutine )
2452  call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc3d(2)), &
2453  thisroutine )
2454  call check( nf90_inq_dimid(ncid, trim(coord_id(3)), nc3d(3)), &
2455  thisroutine )
2456  call check( nf90_def_var(ncid, 'vz_c', nf90_float, nc3d, ncv), &
2457  thisroutine )
2458  buffer = 'm a-1'
2459  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2460  thisroutine )
2461  buffer = 'land_ice_kc_layer_z_velocity'
2462  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2463  thisroutine )
2464  buffer = 'Vertical velocity vz in the upper (kc) ice layer'
2465  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2466  thisroutine )
2467  buffer = 'Staggered grid variable, defined at (kc+1/2,j,i)'
2468  call check( nf90_put_att(ncid, ncv, 'comment', trim(buffer)), &
2469  thisroutine )
2470  call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2471  thisroutine )
2472  call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2473  thisroutine )
2474 
2475 ! ---- vx_t
2476 
2477  call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc3d(1)), &
2478  thisroutine )
2479  call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc3d(2)), &
2480  thisroutine )
2481  call check( nf90_inq_dimid(ncid, trim(coord_id(4)), nc3d(3)), &
2482  thisroutine )
2483  call check( nf90_def_var(ncid, 'vx_t', nf90_float, nc3d, ncv), &
2484  thisroutine )
2485  buffer = 'm a-1'
2486  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2487  thisroutine )
2488  buffer = 'land_ice_kt_layer_x_velocity'
2489  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2490  thisroutine )
2491  buffer = 'Horizontal velocity vx in the lower (kt) ice layer'
2492  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2493  thisroutine )
2494  buffer = 'Staggered grid variable, defined at (kt,j,i+1/2)'
2495  call check( nf90_put_att(ncid, ncv, 'comment', trim(buffer)), &
2496  thisroutine )
2497  call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2498  thisroutine )
2499  call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2500  thisroutine )
2501 
2502 ! ---- vy_t
2503 
2504  call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc3d(1)), &
2505  thisroutine )
2506  call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc3d(2)), &
2507  thisroutine )
2508  call check( nf90_inq_dimid(ncid, trim(coord_id(4)), nc3d(3)), &
2509  thisroutine )
2510  call check( nf90_def_var(ncid, 'vy_t', nf90_float, nc3d, ncv), &
2511  thisroutine )
2512  buffer = 'm a-1'
2513  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2514  thisroutine )
2515  buffer = 'land_ice_kt_layer_y_velocity'
2516  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2517  thisroutine )
2518  buffer = 'Horizontal velocity vy in the lower (kt) ice layer'
2519  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2520  thisroutine )
2521  buffer = 'Staggered grid variable, defined at (kt,j+1/2,i)'
2522  call check( nf90_put_att(ncid, ncv, 'comment', trim(buffer)), &
2523  thisroutine )
2524  call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2525  thisroutine )
2526  call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2527  thisroutine )
2528 
2529 ! ---- vz_t
2530 
2531  call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc3d(1)), &
2532  thisroutine )
2533  call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc3d(2)), &
2534  thisroutine )
2535  call check( nf90_inq_dimid(ncid, trim(coord_id(4)), nc3d(3)), &
2536  thisroutine )
2537  call check( nf90_def_var(ncid, 'vz_t', nf90_float, nc3d, ncv), &
2538  thisroutine )
2539  buffer = 'm a-1'
2540  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2541  thisroutine )
2542  buffer = 'land_ice_kt_layer_z_velocity'
2543  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2544  thisroutine )
2545  buffer = 'Vertical velocity vz in the lower (kt) ice layer'
2546  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2547  thisroutine )
2548  buffer = 'Staggered grid variable, defined at (kt+1/2,j,i)'
2549  call check( nf90_put_att(ncid, ncv, 'comment', trim(buffer)), &
2550  thisroutine )
2551  call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2552  thisroutine )
2553  call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2554  thisroutine )
2555 
2556 ! ---- temp_c
2557 
2558  call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc3d(1)), &
2559  thisroutine )
2560  call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc3d(2)), &
2561  thisroutine )
2562  call check( nf90_inq_dimid(ncid, trim(coord_id(3)), nc3d(3)), &
2563  thisroutine )
2564  call check( nf90_def_var(ncid, 'temp_c', nf90_float, nc3d, ncv), &
2565  thisroutine )
2566  buffer = 'degC'
2567  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2568  thisroutine )
2569  buffer = 'land_ice_kc_layer_temperature'
2570  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2571  thisroutine )
2572  buffer = 'Temperature in the upper (kc) ice layer'
2573  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2574  thisroutine )
2575  call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2576  thisroutine )
2577  call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2578  thisroutine )
2579 
2580 ! ---- omega_t
2581 
2582  call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc3d(1)), &
2583  thisroutine )
2584  call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc3d(2)), &
2585  thisroutine )
2586  call check( nf90_inq_dimid(ncid, trim(coord_id(4)), nc3d(3)), &
2587  thisroutine )
2588  call check( nf90_def_var(ncid, 'omega_t', nf90_float, nc3d, ncv), &
2589  thisroutine )
2590  buffer = '1'
2591  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2592  thisroutine )
2593  buffer = 'land_ice_kt_layer_water_content'
2594  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2595  thisroutine )
2596  buffer = 'Water content in the lower (kt) ice layer'
2597  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2598  thisroutine )
2599  call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2600  thisroutine )
2601  call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2602  thisroutine )
2603 
2604 ! ---- temp_r
2605 
2606  call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc3d(1)), &
2607  thisroutine )
2608  call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc3d(2)), &
2609  thisroutine )
2610  call check( nf90_inq_dimid(ncid, trim(coord_id(5)), nc3d(3)), &
2611  thisroutine )
2612  call check( nf90_def_var(ncid, 'temp_r', nf90_float, nc3d, ncv), &
2613  thisroutine )
2614  buffer = 'degC'
2615  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2616  thisroutine )
2617  buffer = 'lithosphere_layer_temperature'
2618  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2619  thisroutine )
2620  buffer = 'Temperature in the lithosphere layer'
2621  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2622  thisroutine )
2623  call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2624  thisroutine )
2625  call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2626  thisroutine )
2627 
2628 ! ---- enth_c
2629 
2630  call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc3d(1)), &
2631  thisroutine )
2632  call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc3d(2)), &
2633  thisroutine )
2634  call check( nf90_inq_dimid(ncid, trim(coord_id(3)), nc3d(3)), &
2635  thisroutine )
2636  call check( nf90_def_var(ncid, 'enth_c', nf90_float, nc3d, ncv), &
2637  thisroutine )
2638  buffer = 'J kg-1'
2639  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2640  thisroutine )
2641  buffer = 'land_ice_kc_layer_enthalpy'
2642  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2643  thisroutine )
2644  buffer = 'Enthalpy in the upper (kc) ice layer'
2645  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2646  thisroutine )
2647  call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2648  thisroutine )
2649  call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2650  thisroutine )
2651 
2652 ! ---- enth_t
2653 
2654  call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc3d(1)), &
2655  thisroutine )
2656  call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc3d(2)), &
2657  thisroutine )
2658  call check( nf90_inq_dimid(ncid, trim(coord_id(4)), nc3d(3)), &
2659  thisroutine )
2660  call check( nf90_def_var(ncid, 'enth_t', nf90_float, nc3d, ncv), &
2661  thisroutine )
2662  buffer = 'J kg-1'
2663  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2664  thisroutine )
2665  buffer = 'land_ice_kt_layer_enthalpy'
2666  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2667  thisroutine )
2668  buffer = 'Enthalpy in the lower (kt) ice layer'
2669  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2670  thisroutine )
2671  call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2672  thisroutine )
2673  call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2674  thisroutine )
2675 
2676 ! ---- omega_c
2677 
2678  call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc3d(1)), &
2679  thisroutine )
2680  call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc3d(2)), &
2681  thisroutine )
2682  call check( nf90_inq_dimid(ncid, trim(coord_id(3)), nc3d(3)), &
2683  thisroutine )
2684  call check( nf90_def_var(ncid, 'omega_c', nf90_float, nc3d, ncv), &
2685  thisroutine )
2686  buffer = '1'
2687  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2688  thisroutine )
2689  buffer = 'land_ice_kc_layer_water_content'
2690  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2691  thisroutine )
2692  buffer = 'Water content in the upper (kc) ice layer'
2693  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2694  thisroutine )
2695  call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2696  thisroutine )
2697  call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2698  thisroutine )
2699 
2700 ! ---- enh_c
2701 
2702  call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc3d(1)), &
2703  thisroutine )
2704  call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc3d(2)), &
2705  thisroutine )
2706  call check( nf90_inq_dimid(ncid, trim(coord_id(3)), nc3d(3)), &
2707  thisroutine )
2708  call check( nf90_def_var(ncid, 'enh_c', nf90_float, nc3d, ncv), &
2709  thisroutine )
2710  buffer = '1'
2711  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2712  thisroutine )
2713  buffer = 'land_ice_kc_layer_flow_enhancement_factor'
2714  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2715  thisroutine )
2716  buffer = 'Flow enhancement factor in the upper (kc) ice layer'
2717  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2718  thisroutine )
2719  call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2720  thisroutine )
2721  call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2722  thisroutine )
2723 
2724 ! ---- enh_t
2725 
2726  call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc3d(1)), &
2727  thisroutine )
2728  call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc3d(2)), &
2729  thisroutine )
2730  call check( nf90_inq_dimid(ncid, trim(coord_id(4)), nc3d(3)), &
2731  thisroutine )
2732  call check( nf90_def_var(ncid, 'enh_t', nf90_float, nc3d, ncv), &
2733  thisroutine )
2734  buffer = '1'
2735  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2736  thisroutine )
2737  buffer = 'land_ice_kt_layer_flow_enhancement_factor'
2738  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2739  thisroutine )
2740  buffer = 'Flow enhancement factor in the lower (kt) ice layer'
2741  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2742  thisroutine )
2743  call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2744  thisroutine )
2745  call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2746  thisroutine )
2747 
2748 ! ---- age_c
2749 
2750  call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc3d(1)), &
2751  thisroutine )
2752  call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc3d(2)), &
2753  thisroutine )
2754  call check( nf90_inq_dimid(ncid, trim(coord_id(3)), nc3d(3)), &
2755  thisroutine )
2756  call check( nf90_def_var(ncid, 'age_c', nf90_float, nc3d, ncv), &
2757  thisroutine )
2758  buffer = 'a'
2759  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2760  thisroutine )
2761  buffer = 'land_ice_kc_layer_age'
2762  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2763  thisroutine )
2764  buffer = 'Age in the upper (kc) ice layer'
2765  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2766  thisroutine )
2767  call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2768  thisroutine )
2769  call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2770  thisroutine )
2771 
2772 ! ---- age_t
2773 
2774  call check( nf90_inq_dimid(ncid, trim(coord_id(1)), nc3d(1)), &
2775  thisroutine )
2776  call check( nf90_inq_dimid(ncid, trim(coord_id(2)), nc3d(2)), &
2777  thisroutine )
2778  call check( nf90_inq_dimid(ncid, trim(coord_id(4)), nc3d(3)), &
2779  thisroutine )
2780  call check( nf90_def_var(ncid, 'age_t', nf90_float, nc3d, ncv), &
2781  thisroutine )
2782  buffer = 'a'
2783  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
2784  thisroutine )
2785  buffer = 'land_ice_kt_layer_age'
2786  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
2787  thisroutine )
2788  buffer = 'Age in the lower (kt) ice layer'
2789  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
2790  thisroutine )
2791  call check( nf90_put_att(ncid, ncv, 'grid_mapping', 'crs'), &
2792  thisroutine )
2793  call check( nf90_put_att(ncid, ncv, 'coordinates', 'lat lon'), &
2794  thisroutine )
2795 
2796 end if
2797 
2798 ! ---- End of the definitions
2799 
2800 call check( nf90_enddef(ncid), thisroutine )
2801 
2802 #endif
2803 
2804 !-------- Ice thickness and time derivative --------
2805 
2806 h = h_c + h_t
2807 dh_dtau = dh_c_dtau + dh_t_dtau
2808 
2809 !-------- Thickness of the cold and temperate layers --------
2810 
2811 h_cold = 0.0_dp
2812 h_temp = 0.0_dp
2813 
2814 #if (CALCMOD==1)
2815 do i=1, imax-1
2816 do j=1, jmax-1
2817  h_temp(j,i) = h_t(j,i)
2818 end do
2819 end do
2820 #elif (CALCMOD==0 || CALCMOD==2 || CALCMOD==3 || CALCMOD==-1)
2821 do i=1, imax-1
2822 do j=1, jmax-1
2823  h_temp(j,i) = h_c(j,i)*eaz_c_quotient(kc_cts(j,i))
2824 end do
2825 end do
2826 #endif
2827 
2828 h_cold = h - h_temp
2829 
2830 !-------- Enthalpies for the non-enthalpy methods (POLY, COLD, ISOT) --------
2831 
2832 #if (CALCMOD==1)
2833 
2834 do i=0, imax
2835 do j=0, jmax
2836 
2837  do kc=0, kcmax
2838  enth_c(kc,j,i) = enth_fct_temp_omega(temp_c(kc,j,i), 0.0_dp)
2839  end do
2840 
2841  if ( (maske(j,i)==0_i1b).and.(n_cts(j,i)==1_i1b) ) then
2842  do kt=0, ktmax
2843  enth_t(kt,j,i) = enth_fct_temp_omega(temp_t_m(kt,j,i), omega_t(kt,j,i))
2844  end do
2845  else
2846  do kt=0, ktmax
2847  enth_t(kt,j,i) = enth_c(0,j,i)
2848  end do
2849  end if
2850 
2851 end do
2852 end do
2853 
2854 #elif (CALCMOD==0 || CALCMOD==-1)
2855 
2856 do i=0, imax
2857 do j=0, jmax
2858 
2859  do kc=0, kcmax
2860  enth_c(kc,j,i) = enth_fct_temp_omega(temp_c(kc,j,i), 0.0_dp)
2861  end do
2862 
2863  do kt=0, ktmax
2864  enth_t(kt,j,i) = enth_c(0,j,i)
2865  end do
2866 
2867 end do
2868 end do
2869 
2870 #endif
2871 
2872 !-------- Vertical mean of horizontal velocities --------
2873 
2874 vx_m_g = 0.0_dp
2875 vy_m_g = 0.0_dp
2876 
2877 do i=1, imax-1
2878 do j=1, jmax-1
2879 
2880  if ( (maske(j,i)==0_i1b).or.(maske(j,i)==3_i1b) ) then
2881  vx_m_g(j,i) = 0.5_dp*(vx_m(j,i)+vx_m(j,i-1))
2882  vy_m_g(j,i) = 0.5_dp*(vy_m(j,i)+vy_m(j-1,i))
2883  end if
2884 
2885 end do
2886 end do
2887 
2888 !-------- Driving stress and basal drag --------
2889 
2890 tau_b_driving = 0.0_dp
2891 tau_b_drag = 0.0_dp
2892 
2893 do i=0, imax
2894 do j=0, jmax
2895 
2896  if (maske(j,i)==0_i1b) then ! grounded ice
2897 
2898  tau_b_driving(j,i) = rho*g*h(j,i) &
2899  * sqrt( dzs_dxi_g(j,i)**2 + dzs_deta_g(j,i)**2 )
2900 
2901  if (.not.flag_shelfy_stream(j,i)) then
2902  tau_b_drag(j,i) = tau_b_driving(j,i)
2903  else
2904  tau_b_drag(j,i) = no_value_neg_2 ! dummy value
2905  end if
2906 
2907  else if (maske(j,i)==3_i1b) then ! floating ice
2908 
2909  tau_b_driving(j,i) = rho*g*h(j,i) &
2910  * sqrt( dzs_dxi_g(j,i)**2 + dzs_deta_g(j,i)**2 )
2911 
2912  tau_b_drag(j,i) = 0.0_dp
2913 
2914  end if
2915 
2916 end do
2917 end do
2918 
2919 !-------- Computation of the ice volume, the volume above flotation,
2920 ! the area covered by grounded ice, the area covered by floating ice,
2921 ! the total surface mass balance, the total basal mass balance
2922 ! and the total calving flux --------
2923 
2924 rhosw_rho_ratio = rho_sw/rho
2925 
2926 v_grounded = 0.0_dp
2927 v_floating = 0.0_dp
2928 v_gr_redu = 0.0_dp
2929 a_grounded = 0.0_dp
2930 a_floating = 0.0_dp
2931 
2932 do i=0, imax
2933 do j=0, jmax
2934 
2935  if (maske(j,i)==0_i1b) then ! grounded ice
2936 
2937  v_grounded = v_grounded + h(j,i)*area(j,i)
2938  a_grounded = a_grounded + area(j,i)
2939  v_gr_redu = v_gr_redu &
2940  + rhosw_rho_ratio*max((z_sl-zl(j,i)),0.0_dp)*area(j,i)
2941 
2942  else if (maske(j,i)==3_i1b) then ! floating ice
2943 
2944  v_floating = v_floating + h(j,i)*area(j,i)
2945  a_floating = a_floating + area(j,i)
2946 
2947  end if
2948 
2949 end do
2950 end do
2951 
2952 v_tot = v_grounded + v_floating
2953 v_af = v_grounded - v_gr_redu
2954 
2955 !-------- Convert data to real*4 and seconds to years --------
2956 
2957 #if (!defined(OUT_TIMES) || OUT_TIMES==1)
2958 time_conv = real(time*sec_to_year,sp)
2959 #elif (OUT_TIMES==2)
2960 time_conv = real((time+year_zero)*sec_to_year,sp)
2961 #else
2962 errormsg = ' >>> output1: OUT_TIMES must be either 1 or 2!'
2963 call error(errormsg)
2964 #endif
2965 
2966 delta_ts_conv = real(delta_ts,sp)
2967 glac_index_conv = real(glac_index,sp)
2968 z_sl_conv = real(z_sl,sp)
2969 v_tot_conv = real(v_tot,sp)
2970 v_af_conv = real(v_af,sp)
2971 a_grounded_conv = real(a_grounded,sp)
2972 a_floating_conv = real(a_floating,sp)
2973 h_r_conv = real(h_r,sp)
2974 
2975 do i=0, imax
2976  xi_conv(i) = real(xi(i),sp)
2977 end do
2978 
2979 do j=0, jmax
2980  eta_conv(j) = real(eta(j),sp)
2981 end do
2982 
2983 do kc=0, kcmax
2984  sigma_level_c_conv(kc) = real(eaz_c_quotient(kc),sp)
2985 end do
2986 
2987 do kt=0, ktmax
2988  sigma_level_t_conv(kt) = real(zeta_t(kt),sp)
2989 end do
2990 
2991 do kr=0, krmax
2992  sigma_level_r_conv(kr) = real(kr,sp)/real(krmax,sp)
2993 end do
2994 
2995 do i=0, imax
2996 do j=0, jmax
2997 
2998  maske_conv(i,j) = maske(j,i)
2999  maske_old_conv(i,j) = maske_old(j,i)
3000  mask_ablation_type_conv(i,j) = mask_ablation_type(j,i)
3001  n_cts_conv(i,j) = n_cts(j,i)
3002  kc_cts_conv(i,j) = kc_cts(j,i)
3003 
3004  lambda_conv(i,j) = real(lambda(j,i),sp)
3005  phi_conv(i,j) = real(phi(j,i),sp)
3006  lon_conv(i,j) = real(lambda(j,i)*pi_180_inv,sp) ! longitude in deg
3007  lon_conv(i,j) = modulo(lon_conv(i,j)+180.0_sp, 360.0_sp)-180.0_sp
3008  ! mapping to interval [-180 deg, +180 deg)
3009  lat_conv(i,j) = real(phi(j,i) *pi_180_inv,sp) ! latitute in deg
3010  if (lat_conv(i,j) > 90.0_sp) lat_conv(i,j) = 90.0_sp
3011  if (lat_conv(i,j) < -90.0_sp) lat_conv(i,j) = -90.0_sp
3012  ! constraining to interval [-90 deg, +90 deg]
3013  temp_s_conv(i,j) = real(temp_s(j,i),sp)
3014  accum_conv(i,j) = real(accum(j,i)*year_sec,sp)
3015  snowfall_conv(i,j) = real(snowfall(j,i)*year_sec,sp)
3016  rainfall_conv(i,j) = real(rainfall(j,i)*year_sec,sp)
3017  pdd_conv(i,j) = real(et(j,i)*one_year,sp)
3018  as_perp_conv(i,j) = real(as_perp(j,i)*year_sec,sp)
3019  as_perp_apl_conv(i,j) = real(as_perp_apl(j,i)*year_sec,sp)
3020  smb_corr_conv(i,j) = real(smb_corr(j,i)*year_sec,sp)
3021 
3022 #if (DISC>0) /* Ice discharge parameterisation */
3023  dis_perp_conv(i,j) = real(dis_perp(j,i)*year_sec,sp)
3024  cst_dist_conv(i,j) = real(cst_dist(j,i)*0.001_dp,sp)
3025  cos_grad_tc_conv(i,j) = real(cos_grad_tc(j,i),sp)
3026  mask_mar_conv(i,j) = mask_mar(j,i)
3027 #endif
3028 
3029  q_geo_conv(i,j) = real(q_geo(j,i),sp)
3030  zs_conv(i,j) = real(zs(j,i),sp)
3031  zm_conv(i,j) = real(zm(j,i),sp)
3032  zb_conv(i,j) = real(zb(j,i),sp)
3033  zl_conv(i,j) = real(zl(j,i),sp)
3034  zl0_conv(i,j) = real(zl0(j,i),sp)
3035  h_cold_conv(i,j) = real(H_cold(j,i),sp)
3036  h_temp_conv(i,j) = real(H_temp(j,i),sp)
3037  h_conv(i,j) = real(H(j,i),sp)
3038  q_bm_conv(i,j) = real(q_bm(j,i)*year_sec,sp)
3039  q_tld_conv(i,j) = real(q_tld(j,i)*year_sec,sp)
3040  am_perp_conv(i,j) = real(am_perp(j,i)*year_sec,sp)
3041  qx_conv(i,j) = real(qx(j,i)*year_sec,sp)
3042  qy_conv(i,j) = real(qy(j,i)*year_sec,sp)
3043  dzs_dtau_conv(i,j) = real(dzs_dtau(j,i)*year_sec,sp)
3044  dzm_dtau_conv(i,j) = real(dzm_dtau(j,i)*year_sec,sp)
3045  dzb_dtau_conv(i,j) = real(dzb_dtau(j,i)*year_sec,sp)
3046  dzl_dtau_conv(i,j) = real(dzl_dtau(j,i)*year_sec,sp)
3047  dh_c_dtau_conv(i,j) = real(dh_c_dtau(j,i)*year_sec,sp)
3048  dh_t_dtau_conv(i,j) = real(dh_t_dtau(j,i)*year_sec,sp)
3049  dh_dtau_conv(i,j) = real(dh_dtau(j,i)*year_sec,sp)
3050  vx_b_g_conv(i,j) = real(vx_b_g(j,i)*year_sec,sp)
3051  vy_b_g_conv(i,j) = real(vy_b_g(j,i)*year_sec,sp)
3052  vz_b_conv(i,j) = real(vz_b(j,i)*year_sec,sp)
3053  vh_b_conv(i,j) = sqrt( vx_b_g_conv(i,j)**2 + vy_b_g_conv(i,j)**2 )
3054  vx_s_g_conv(i,j) = real(vx_s_g(j,i)*year_sec,sp)
3055  vy_s_g_conv(i,j) = real(vy_s_g(j,i)*year_sec,sp)
3056  vz_s_conv(i,j) = real(vz_s(j,i)*year_sec,sp)
3057  vh_s_conv(i,j) = sqrt( vx_s_g_conv(i,j)**2 + vy_s_g_conv(i,j)**2 )
3058  vx_m_g_conv(i,j) = real(vx_m_g(j,i)*year_sec,sp)
3059  vy_m_g_conv(i,j) = real(vy_m_g(j,i)*year_sec,sp)
3060  vh_m_conv(i,j) = sqrt( vx_m_g_conv(i,j)**2 + vy_m_g_conv(i,j)**2 )
3061  temp_b_conv(i,j) = real(temp_b(j,i),sp)
3062  temph_b_conv(i,j) = real(temph_b(j,i),sp)
3063  tau_b_driving_conv(i,j) = real(tau_b_driving(j,i),sp)
3064  tau_b_drag_conv(i,j) = real(tau_b_drag(j,i),sp)
3065  p_b_w_conv(i,j) = real(p_b_w(j,i),sp)
3066  q_w_conv(i,j) = real(q_w(j,i)*year_sec,sp)
3067  q_w_x_conv(i,j) = real(q_w_x(j,i)*year_sec,sp)
3068  q_w_y_conv(i,j) = real(q_w_y(j,i)*year_sec,sp)
3069  h_w_conv(i,j) = real(H_w(j,i),sp)
3070  q_gl_g_conv(i,j) = real(q_gl_g(j,i)*year_sec,sp)
3071  q_cf_g_conv(i,j) = real(calv_grounded(j,i)*year_sec,sp)
3072  ratio_sl_x_conv(i,j) = real(ratio_sl_x(j,i),sp)
3073  ratio_sl_y_conv(i,j) = real(ratio_sl_y(j,i),sp)
3074 
3075  if (flag_shelfy_stream_x(j,i)) then
3076  flag_shelfy_stream_x_conv(i,j) = 1_i1b
3077  else
3078  flag_shelfy_stream_x_conv(i,j) = 0_i1b
3079  end if
3080 
3081  if (flag_shelfy_stream_y(j,i)) then
3082  flag_shelfy_stream_y_conv(i,j) = 1_i1b
3083  else
3084  flag_shelfy_stream_y_conv(i,j) = 0_i1b
3085  end if
3086 
3087  if (flag_shelfy_stream(j,i)) then
3088  flag_shelfy_stream_conv(i,j) = 1_i1b
3089  else
3090  flag_shelfy_stream_conv(i,j) = 0_i1b
3091  end if
3092 
3093  if (flag_grounding_line_1(j,i)) then
3094  flag_grounding_line_1_conv(i,j) = 1_i1b
3095  else
3096  flag_grounding_line_1_conv(i,j) = 0_i1b
3097  end if
3098 
3099  if (flag_grounding_line_2(j,i)) then
3100  flag_grounding_line_2_conv(i,j) = 1_i1b
3101  else
3102  flag_grounding_line_2_conv(i,j) = 0_i1b
3103  end if
3104 
3105  if (flag_calving_front_1(j,i)) then
3106  flag_calving_front_1_conv(i,j) = 1_i1b
3107  else
3108  flag_calving_front_1_conv(i,j) = 0_i1b
3109  end if
3110 
3111  if (flag_calving_front_2(j,i)) then
3112  flag_calving_front_2_conv(i,j) = 1_i1b
3113  else
3114  flag_calving_front_2_conv(i,j) = 0_i1b
3115  end if
3116 
3117  if (flag_grounded_front_a_1(j,i)) then
3118  flag_grounded_front_a_1_conv(i,j) = 1_i1b
3119  else
3120  flag_grounded_front_a_1_conv(i,j) = 0_i1b
3121  end if
3122 
3123  if (flag_grounded_front_a_2(j,i)) then
3124  flag_grounded_front_a_2_conv(i,j) = 1_i1b
3125  else
3126  flag_grounded_front_a_2_conv(i,j) = 0_i1b
3127  end if
3128 
3129  if (flag_grounded_front_b_1(j,i)) then
3130  flag_grounded_front_b_1_conv(i,j) = 1_i1b
3131  else
3132  flag_grounded_front_b_1_conv(i,j) = 0_i1b
3133  end if
3134 
3135  if (flag_grounded_front_b_2(j,i)) then
3136  flag_grounded_front_b_2_conv(i,j) = 1_i1b
3137  else
3138  flag_grounded_front_b_2_conv(i,j) = 0_i1b
3139  end if
3140 
3141  vis_int_g_conv(i,j) = real(vis_int_g(j,i),sp)
3142 
3143  do kr=0, krmax
3144  temp_r_conv(i,j,kr) = real(temp_r(kr,j,i),sp)
3145  end do
3146 
3147  do kt=0, ktmax
3148  vx_t_conv(i,j,kt) = real(vx_t(kt,j,i)*year_sec,sp)
3149  vy_t_conv(i,j,kt) = real(vy_t(kt,j,i)*year_sec,sp)
3150  vz_t_conv(i,j,kt) = real(vz_t(kt,j,i)*year_sec,sp)
3151  omega_t_conv(i,j,kt) = real(omega_t(kt,j,i),sp)
3152  age_t_conv(i,j,kt) = real(age_t(kt,j,i)*sec_to_year,sp)
3153  enth_t_conv(i,j,kt) = real(enth_t(kt,j,i),sp)
3154  enh_t_conv(i,j,kt) = real(enh_t(kt,j,i),sp)
3155  end do
3156 
3157  do kc=0, kcmax
3158  vx_c_conv(i,j,kc) = real(vx_c(kc,j,i)*year_sec,sp)
3159  vy_c_conv(i,j,kc) = real(vy_c(kc,j,i)*year_sec,sp)
3160  vz_c_conv(i,j,kc) = real(vz_c(kc,j,i)*year_sec,sp)
3161  temp_c_conv(i,j,kc) = real(temp_c(kc,j,i),sp)
3162  age_c_conv(i,j,kc) = real(age_c(kc,j,i)*sec_to_year,sp)
3163  enth_c_conv(i,j,kc) = real(enth_c(kc,j,i),sp)
3164  omega_c_conv(i,j,kc) = real(omega_c(kc,j,i),sp)
3165  enh_c_conv(i,j,kc) = real(enh_c(kc,j,i),sp)
3166  end do
3167 
3168 end do
3169 end do
3170 
3171 !-------- Write data on file --------
3172 
3173 #if (NETCDF==1) /* time-slice file in native binary format */
3174 
3175 write(unit=11) time_conv
3176 if (forcing_flag == 1) then
3177  write(unit=11) delta_ts_conv
3178 else if (forcing_flag == 2) then
3179  write(unit=11) glac_index_conv
3180 else if (forcing_flag == 3) then
3181  glac_index_conv = real(no_value_pos_1,sp) ! dummy value
3182  write(unit=11) glac_index_conv
3183 end if
3184 write(unit=11) z_sl_conv
3185 
3186 write(unit=11) v_tot_conv
3187 write(unit=11) v_af_conv
3188 write(unit=11) a_grounded_conv
3189 write(unit=11) a_floating_conv
3190 
3191 write(unit=11) xi_conv
3192 write(unit=11) eta_conv
3193 write(unit=11) sigma_level_c_conv
3194 write(unit=11) sigma_level_t_conv
3195 write(unit=11) sigma_level_r_conv
3196 write(unit=11) lon_conv
3197 write(unit=11) lat_conv
3198 write(unit=11) lambda_conv
3199 write(unit=11) phi_conv
3200 write(unit=11) temp_s_conv
3201 write(unit=11) accum_conv
3202 write(unit=11) snowfall_conv
3203 write(unit=11) rainfall_conv
3204 write(unit=11) pdd_conv
3205 write(unit=11) as_perp_conv
3206 write(unit=11) as_perp_apl_conv
3207 write(unit=11) smb_corr_conv
3208 
3209 #if (DISC>0) /* Ice discharge parameterisation */
3210 
3211 write(unit=11) dis_perp_conv
3212 write(unit=11) cst_dist_conv
3213 write(unit=11) cos_grad_tc_conv
3214 write(unit=11) mask_mar_conv
3215 
3216 #endif
3217 
3218 write(unit=11) q_geo_conv
3219 write(unit=11) maske_conv
3220 write(unit=11) maske_old_conv
3221 write(unit=11) n_cts_conv
3222 write(unit=11) kc_cts_conv
3223 write(unit=11) zs_conv
3224 write(unit=11) zm_conv
3225 write(unit=11) zb_conv
3226 write(unit=11) zl_conv
3227 write(unit=11) zl0_conv
3228 write(unit=11) h_cold_conv
3229 write(unit=11) h_temp_conv
3230 write(unit=11) h_conv
3231 write(unit=11) h_r_conv
3232 write(unit=11) q_bm_conv
3233 write(unit=11) q_tld_conv
3234 write(unit=11) am_perp_conv
3235 write(unit=11) qx_conv
3236 write(unit=11) qy_conv
3237 write(unit=11) dzs_dtau_conv
3238 write(unit=11) dzm_dtau_conv
3239 write(unit=11) dzb_dtau_conv
3240 write(unit=11) dzl_dtau_conv
3241 write(unit=11) dh_c_dtau_conv
3242 write(unit=11) dh_t_dtau_conv
3243 write(unit=11) dh_dtau_conv
3244 write(unit=11) vx_b_g_conv
3245 write(unit=11) vy_b_g_conv
3246 write(unit=11) vz_b_conv
3247 write(unit=11) vh_b_conv
3248 write(unit=11) vx_s_g_conv
3249 write(unit=11) vy_s_g_conv
3250 write(unit=11) vz_s_conv
3251 write(unit=11) vh_s_conv
3252 write(unit=11) vx_m_g_conv
3253 write(unit=11) vy_m_g_conv
3254 write(unit=11) vh_m_conv
3255 write(unit=11) temp_b_conv
3256 write(unit=11) temph_b_conv
3257 write(unit=11) tau_b_driving_conv
3258 write(unit=11) tau_b_drag_conv
3259 write(unit=11) p_b_w_conv
3260 write(unit=11) q_w_conv
3261 write(unit=11) q_w_x_conv
3262 write(unit=11) q_w_y_conv
3263 write(unit=11) h_w_conv
3264 write(unit=11) q_gl_g_conv
3265 write(unit=11) q_cf_g_conv
3266 
3267 if (flag_3d_output) then
3268 
3269  write(unit=11) vx_c_conv
3270  write(unit=11) vy_c_conv
3271  write(unit=11) vz_c_conv
3272  write(unit=11) vx_t_conv
3273  write(unit=11) vy_t_conv
3274  write(unit=11) vz_t_conv
3275  write(unit=11) temp_c_conv
3276  write(unit=11) omega_t_conv
3277  write(unit=11) temp_r_conv
3278  write(unit=11) enth_c_conv
3279  write(unit=11) enth_t_conv
3280  write(unit=11) omega_c_conv
3281  write(unit=11) enh_c_conv
3282  write(unit=11) enh_t_conv
3283  write(unit=11) age_c_conv
3284  write(unit=11) age_t_conv
3285 
3286 end if
3287 
3288 #elif (NETCDF==2) /* time-slice file in NetCDF format */
3289 
3290 call check( nf90_inq_varid(ncid, 'crs', ncv), thisroutine )
3291 call check( nf90_put_var(ncid, ncv, 0), thisroutine )
3292 
3293 call check( nf90_inq_varid(ncid, 'time', ncv), thisroutine )
3294 call check( nf90_put_var(ncid, ncv, time_conv), thisroutine )
3295 
3296 if (forcing_flag == 1) then
3297 
3298  call check( nf90_inq_varid(ncid, 'delta_ts', ncv), thisroutine )
3299  call check( nf90_put_var(ncid, ncv, delta_ts_conv), thisroutine )
3300 
3301 else if (forcing_flag == 2) then
3302 
3303  call check( nf90_inq_varid(ncid, 'glac_index', ncv), thisroutine )
3304  call check( nf90_put_var(ncid, ncv, glac_index_conv), thisroutine )
3305 
3306 else if (forcing_flag == 3) then
3307 
3308  call check( nf90_inq_varid(ncid, 'glac_index', ncv), thisroutine )
3309  glac_index_conv = real(no_value_pos_1,sp) ! dummy value
3310  call check( nf90_put_var(ncid, ncv, glac_index_conv), thisroutine )
3311 
3312 end if
3313 
3314 call check( nf90_inq_varid(ncid, 'z_sl', ncv), thisroutine )
3315 call check( nf90_put_var(ncid, ncv, z_sl_conv), thisroutine )
3316 
3317 call check( nf90_inq_varid(ncid, 'V_tot', ncv), thisroutine )
3318 call check( nf90_put_var(ncid, ncv, v_tot_conv), thisroutine )
3319 
3320 call check( nf90_inq_varid(ncid, 'V_af', ncv), thisroutine )
3321 call check( nf90_put_var(ncid, ncv, v_af_conv), thisroutine )
3322 
3323 call check( nf90_inq_varid(ncid, 'A_grounded', ncv), thisroutine )
3324 call check( nf90_put_var(ncid, ncv, a_grounded_conv), thisroutine )
3325 
3326 call check( nf90_inq_varid(ncid, 'A_floating', ncv), thisroutine )
3327 call check( nf90_put_var(ncid, ncv, a_floating_conv), thisroutine )
3328 
3329 call check( nf90_inq_varid(ncid, 'x', ncv), thisroutine )
3330 call check( nf90_put_var(ncid, ncv, xi_conv, &
3331  start=nc1cor_i, count=nc1cnt_i), &
3332  thisroutine )
3333 
3334 call check( nf90_inq_varid(ncid, 'y', ncv), thisroutine )
3335 call check( nf90_put_var(ncid, ncv, eta_conv, &
3336  start=nc1cor_j, count=nc1cnt_j), &
3337  thisroutine )
3338 
3339 call check( nf90_inq_varid(ncid, 'sigma_level_c', ncv), thisroutine )
3340 call check( nf90_put_var(ncid, ncv, sigma_level_c_conv, &
3341  start=nc1cor_kc, count=nc1cnt_kc), &
3342  thisroutine )
3343 
3344 call check( nf90_inq_varid(ncid, 'sigma_level_t', ncv), thisroutine )
3345 call check( nf90_put_var(ncid, ncv, sigma_level_t_conv, &
3346  start=nc1cor_kt, count=nc1cnt_kt), &
3347  thisroutine )
3348 
3349 call check( nf90_inq_varid(ncid, 'sigma_level_r', ncv), thisroutine )
3350 call check( nf90_put_var(ncid, ncv, sigma_level_r_conv, &
3351  start=nc1cor_kr, count=nc1cnt_kr), &
3352  thisroutine )
3353 
3354 call check( nf90_inq_varid(ncid, 'lon', ncv), thisroutine )
3355 call check( nf90_put_var(ncid, ncv, lon_conv, &
3356  start=nc2cor_ij, count=nc2cnt_ij), &
3357  thisroutine )
3358 
3359 call check( nf90_inq_varid(ncid, 'lat', ncv), thisroutine )
3360 call check( nf90_put_var(ncid, ncv, lat_conv, &
3361  start=nc2cor_ij, count=nc2cnt_ij), &
3362  thisroutine )
3363 
3364 call check( nf90_inq_varid(ncid, 'lambda', ncv), thisroutine )
3365 call check( nf90_put_var(ncid, ncv, lambda_conv, &
3366  start=nc2cor_ij, count=nc2cnt_ij), &
3367  thisroutine )
3368 
3369 call check( nf90_inq_varid(ncid, 'phi', ncv), thisroutine )
3370 call check( nf90_put_var(ncid, ncv, phi_conv, &
3371  start=nc2cor_ij, count=nc2cnt_ij), &
3372  thisroutine )
3373 
3374 call check( nf90_inq_varid(ncid, 'temp_s', ncv), thisroutine )
3375 call check( nf90_put_var(ncid, ncv, temp_s_conv, &
3376  start=nc2cor_ij, count=nc2cnt_ij), &
3377  thisroutine )
3378 
3379 call check( nf90_inq_varid(ncid, 'prec', ncv), thisroutine )
3380 call check( nf90_put_var(ncid, ncv, accum_conv, &
3381  start=nc2cor_ij, count=nc2cnt_ij), &
3382  thisroutine )
3383 
3384 call check( nf90_inq_varid(ncid, 'snowfall', ncv), thisroutine )
3385 call check( nf90_put_var(ncid, ncv, snowfall_conv, &
3386  start=nc2cor_ij, count=nc2cnt_ij), &
3387  thisroutine )
3388 
3389 call check( nf90_inq_varid(ncid, 'rainfall', ncv), thisroutine )
3390 call check( nf90_put_var(ncid, ncv, rainfall_conv, &
3391  start=nc2cor_ij, count=nc2cnt_ij), &
3392  thisroutine )
3393 
3394 call check( nf90_inq_varid(ncid, 'pdd', ncv), thisroutine )
3395 call check( nf90_put_var(ncid, ncv, pdd_conv, &
3396  start=nc2cor_ij, count=nc2cnt_ij), &
3397  thisroutine )
3398 
3399 call check( nf90_inq_varid(ncid, 'as_perp', ncv), thisroutine )
3400 call check( nf90_put_var(ncid, ncv, as_perp_conv, &
3401  start=nc2cor_ij, count=nc2cnt_ij), &
3402  thisroutine )
3403 
3404 call check( nf90_inq_varid(ncid, 'as_perp_apl', ncv), thisroutine )
3405 call check( nf90_put_var(ncid, ncv, as_perp_apl_conv, &
3406  start=nc2cor_ij, count=nc2cnt_ij), &
3407  thisroutine )
3408 
3409 call check( nf90_inq_varid(ncid, 'smb_corr', ncv), thisroutine )
3410 call check( nf90_put_var(ncid, ncv, smb_corr_conv, &
3411  start=nc2cor_ij, count=nc2cnt_ij), &
3412  thisroutine )
3413 
3414 #if (DISC>0) /* Ice discharge parameterisation */
3415 
3416 call check( nf90_inq_varid(ncid, 'dis_perp', ncv), thisroutine )
3417 call check( nf90_put_var(ncid, ncv, dis_perp_conv, &
3418  start=nc2cor_ij, count=nc2cnt_ij), &
3419  thisroutine )
3420 
3421 call check( nf90_inq_varid(ncid, 'cst_dist', ncv), thisroutine )
3422 call check( nf90_put_var(ncid, ncv, cst_dist_conv, &
3423  start=nc2cor_ij, count=nc2cnt_ij), &
3424  thisroutine )
3425 
3426 call check( nf90_inq_varid(ncid, 'cos_grad_tc', ncv), thisroutine )
3427 call check( nf90_put_var(ncid, ncv, cos_grad_tc_conv, &
3428  start=nc2cor_ij, count=nc2cnt_ij), &
3429  thisroutine )
3430 
3431 call check( nf90_inq_varid(ncid, 'mask_mar', ncv), thisroutine )
3432 call check( nf90_put_var(ncid, ncv, mask_mar_conv, &
3433  start=nc2cor_ij, count=nc2cnt_ij), &
3434  thisroutine )
3435 
3436 #endif
3437 
3438 call check( nf90_inq_varid(ncid, 'q_geo', ncv), thisroutine )
3439 call check( nf90_put_var(ncid, ncv, q_geo_conv, &
3440  start=nc2cor_ij, count=nc2cnt_ij), &
3441  thisroutine )
3442 
3443 call check( nf90_inq_varid(ncid, 'maske', ncv), thisroutine )
3444 call check( nf90_put_var(ncid, ncv, maske_conv, &
3445  start=nc2cor_ij, count=nc2cnt_ij), &
3446  thisroutine )
3447 
3448 call check( nf90_inq_varid(ncid, 'maske_old', ncv), thisroutine )
3449 call check( nf90_put_var(ncid, ncv, maske_old_conv, &
3450  start=nc2cor_ij, count=nc2cnt_ij), &
3451  thisroutine )
3452 
3453 call check( nf90_inq_varid(ncid, 'mask_ablation_type', ncv), thisroutine )
3454 call check( nf90_put_var(ncid, ncv, mask_ablation_type_conv, &
3455  start=nc2cor_ij, count=nc2cnt_ij), &
3456  thisroutine )
3457 
3458 call check( nf90_inq_varid(ncid, 'n_cts', ncv), thisroutine )
3459 call check( nf90_put_var(ncid, ncv, n_cts_conv, &
3460  start=nc2cor_ij, count=nc2cnt_ij), &
3461  thisroutine )
3462 
3463 call check( nf90_inq_varid(ncid, 'kc_cts', ncv), thisroutine )
3464 call check( nf90_put_var(ncid, ncv, kc_cts_conv, &
3465  start=nc2cor_ij, count=nc2cnt_ij), &
3466  thisroutine )
3467 
3468 call check( nf90_inq_varid(ncid, 'zs', ncv), thisroutine )
3469 call check( nf90_put_var(ncid, ncv, zs_conv, &
3470  start=nc2cor_ij, count=nc2cnt_ij), &
3471  thisroutine )
3472 
3473 call check( nf90_inq_varid(ncid, 'zm', ncv), thisroutine )
3474 call check( nf90_put_var(ncid, ncv, zm_conv, &
3475  start=nc2cor_ij, count=nc2cnt_ij), &
3476  thisroutine )
3477 
3478 call check( nf90_inq_varid(ncid, 'zb', ncv), thisroutine )
3479 call check( nf90_put_var(ncid, ncv, zb_conv, &
3480  start=nc2cor_ij, count=nc2cnt_ij), &
3481  thisroutine )
3482 
3483 call check( nf90_inq_varid(ncid, 'zl', ncv), thisroutine )
3484 call check( nf90_put_var(ncid, ncv, zl_conv, &
3485  start=nc2cor_ij, count=nc2cnt_ij), &
3486  thisroutine )
3487 
3488 call check( nf90_inq_varid(ncid, 'zl0', ncv), thisroutine )
3489 call check( nf90_put_var(ncid, ncv, zl0_conv, &
3490  start=nc2cor_ij, count=nc2cnt_ij), &
3491  thisroutine )
3492 
3493 call check( nf90_inq_varid(ncid, 'H_cold', ncv), thisroutine )
3494 call check( nf90_put_var(ncid, ncv, h_cold_conv, &
3495  start=nc2cor_ij, count=nc2cnt_ij), &
3496  thisroutine )
3497 
3498 call check( nf90_inq_varid(ncid, 'H_temp', ncv), thisroutine )
3499 call check( nf90_put_var(ncid, ncv, h_temp_conv, &
3500  start=nc2cor_ij, count=nc2cnt_ij), &
3501  thisroutine )
3502 
3503 call check( nf90_inq_varid(ncid, 'H', ncv), thisroutine )
3504 call check( nf90_put_var(ncid, ncv, h_conv, &
3505  start=nc2cor_ij, count=nc2cnt_ij), &
3506  thisroutine )
3507 
3508 call check( nf90_inq_varid(ncid, 'H_R', ncv), thisroutine )
3509 call check( nf90_put_var(ncid, ncv, h_r_conv), thisroutine )
3510 
3511 call check( nf90_inq_varid(ncid, 'Q_bm', ncv), thisroutine )
3512 call check( nf90_put_var(ncid, ncv, q_bm_conv, &
3513  start=nc2cor_ij, count=nc2cnt_ij), &
3514  thisroutine )
3515 
3516 call check( nf90_inq_varid(ncid, 'Q_tld', ncv), thisroutine )
3517 call check( nf90_put_var(ncid, ncv, q_tld_conv, &
3518  start=nc2cor_ij, count=nc2cnt_ij), &
3519  thisroutine )
3520 
3521 call check( nf90_inq_varid(ncid, 'am_perp', ncv), thisroutine )
3522 call check( nf90_put_var(ncid, ncv, am_perp_conv, &
3523  start=nc2cor_ij, count=nc2cnt_ij), &
3524  thisroutine )
3525 
3526 call check( nf90_inq_varid(ncid, 'qx', ncv), thisroutine )
3527 call check( nf90_put_var(ncid, ncv, qx_conv, &
3528  start=nc2cor_ij, count=nc2cnt_ij), &
3529  thisroutine )
3530 
3531 call check( nf90_inq_varid(ncid, 'qy', ncv), thisroutine )
3532 call check( nf90_put_var(ncid, ncv, qy_conv, &
3533  start=nc2cor_ij, count=nc2cnt_ij), &
3534  thisroutine )
3535 
3536 call check( nf90_inq_varid(ncid, 'dzs_dt', ncv), thisroutine )
3537 call check( nf90_put_var(ncid, ncv, dzs_dtau_conv, &
3538  start=nc2cor_ij, count=nc2cnt_ij), &
3539  thisroutine )
3540 
3541 call check( nf90_inq_varid(ncid, 'dzm_dt', ncv), thisroutine )
3542 call check( nf90_put_var(ncid, ncv, dzm_dtau_conv, &
3543  start=nc2cor_ij, count=nc2cnt_ij), &
3544  thisroutine )
3545 
3546 call check( nf90_inq_varid(ncid, 'dzb_dt', ncv), thisroutine )
3547 call check( nf90_put_var(ncid, ncv, dzb_dtau_conv, &
3548  start=nc2cor_ij, count=nc2cnt_ij), &
3549  thisroutine )
3550 
3551 call check( nf90_inq_varid(ncid, 'dzl_dt', ncv), thisroutine )
3552 call check( nf90_put_var(ncid, ncv, dzl_dtau_conv, &
3553  start=nc2cor_ij, count=nc2cnt_ij), &
3554  thisroutine )
3555 
3556 call check( nf90_inq_varid(ncid, 'dH_c_dt', ncv), thisroutine )
3557 call check( nf90_put_var(ncid, ncv, dh_c_dtau_conv, &
3558  start=nc2cor_ij, count=nc2cnt_ij), &
3559  thisroutine )
3560 
3561 call check( nf90_inq_varid(ncid, 'dH_t_dt', ncv), thisroutine )
3562 call check( nf90_put_var(ncid, ncv, dh_t_dtau_conv, &
3563  start=nc2cor_ij, count=nc2cnt_ij), &
3564  thisroutine )
3565 
3566 call check( nf90_inq_varid(ncid, 'dH_dt', ncv), thisroutine )
3567 call check( nf90_put_var(ncid, ncv, dh_dtau_conv, &
3568  start=nc2cor_ij, count=nc2cnt_ij), &
3569  thisroutine )
3570 
3571 call check( nf90_inq_varid(ncid, 'vx_b_g', ncv), thisroutine )
3572 call check( nf90_put_var(ncid, ncv, vx_b_g_conv, &
3573  start=nc2cor_ij, count=nc2cnt_ij), &
3574  thisroutine )
3575 
3576 call check( nf90_inq_varid(ncid, 'vy_b_g', ncv), thisroutine )
3577 call check( nf90_put_var(ncid, ncv, vy_b_g_conv, &
3578  start=nc2cor_ij, count=nc2cnt_ij), &
3579  thisroutine )
3580 
3581 call check( nf90_inq_varid(ncid, 'vz_b', ncv), thisroutine )
3582 call check( nf90_put_var(ncid, ncv, vz_b_conv, &
3583  start=nc2cor_ij, count=nc2cnt_ij), &
3584  thisroutine )
3585 
3586 call check( nf90_inq_varid(ncid, 'vh_b', ncv), thisroutine )
3587 call check( nf90_put_var(ncid, ncv, vh_b_conv, &
3588  start=nc2cor_ij, count=nc2cnt_ij), &
3589  thisroutine )
3590 
3591 call check( nf90_inq_varid(ncid, 'vx_s_g', ncv), thisroutine )
3592 call check( nf90_put_var(ncid, ncv, vx_s_g_conv, &
3593  start=nc2cor_ij, count=nc2cnt_ij), &
3594  thisroutine )
3595 
3596 call check( nf90_inq_varid(ncid, 'vy_s_g', ncv), thisroutine )
3597 call check( nf90_put_var(ncid, ncv, vy_s_g_conv, &
3598  start=nc2cor_ij, count=nc2cnt_ij), &
3599  thisroutine )
3600 
3601 call check( nf90_inq_varid(ncid, 'vz_s', ncv), thisroutine )
3602 call check( nf90_put_var(ncid, ncv, vz_s_conv, &
3603  start=nc2cor_ij, count=nc2cnt_ij), &
3604  thisroutine )
3605 
3606 call check( nf90_inq_varid(ncid, 'vh_s', ncv), thisroutine )
3607 call check( nf90_put_var(ncid, ncv, vh_s_conv, &
3608  start=nc2cor_ij, count=nc2cnt_ij), &
3609  thisroutine )
3610 
3611 call check( nf90_inq_varid(ncid, 'vx_m_g', ncv), thisroutine )
3612 call check( nf90_put_var(ncid, ncv, vx_m_g_conv, &
3613  start=nc2cor_ij, count=nc2cnt_ij), &
3614  thisroutine )
3615 
3616 call check( nf90_inq_varid(ncid, 'vy_m_g', ncv), thisroutine )
3617 call check( nf90_put_var(ncid, ncv, vy_m_g_conv, &
3618  start=nc2cor_ij, count=nc2cnt_ij), &
3619  thisroutine )
3620 
3621 call check( nf90_inq_varid(ncid, 'vh_m', ncv), thisroutine )
3622 call check( nf90_put_var(ncid, ncv, vh_m_conv, &
3623  start=nc2cor_ij, count=nc2cnt_ij), &
3624  thisroutine )
3625 
3626 call check( nf90_inq_varid(ncid, 'temp_b', ncv), thisroutine )
3627 call check( nf90_put_var(ncid, ncv, temp_b_conv, &
3628  start=nc2cor_ij, count=nc2cnt_ij), &
3629  thisroutine )
3630 
3631 call check( nf90_inq_varid(ncid, 'temph_b', ncv), thisroutine )
3632 call check( nf90_put_var(ncid, ncv, temph_b_conv, &
3633  start=nc2cor_ij, count=nc2cnt_ij), &
3634  thisroutine )
3635 
3636 call check( nf90_inq_varid(ncid, 'tau_b_driving', ncv), thisroutine )
3637 call check( nf90_put_var(ncid, ncv, tau_b_driving_conv, &
3638  start=nc2cor_ij, count=nc2cnt_ij), &
3639  thisroutine )
3640 
3641 call check( nf90_inq_varid(ncid, 'tau_b_drag', ncv), thisroutine )
3642 call check( nf90_put_var(ncid, ncv, tau_b_drag_conv, &
3643  start=nc2cor_ij, count=nc2cnt_ij), &
3644  thisroutine )
3645 
3646 call check( nf90_inq_varid(ncid, 'p_b_w', ncv), thisroutine )
3647 call check( nf90_put_var(ncid, ncv, p_b_w_conv, &
3648  start=nc2cor_ij, count=nc2cnt_ij), &
3649  thisroutine )
3650 
3651 call check( nf90_inq_varid(ncid, 'q_w', ncv), thisroutine )
3652 call check( nf90_put_var(ncid, ncv, q_w_conv, &
3653  start=nc2cor_ij, count=nc2cnt_ij), &
3654  thisroutine )
3655 
3656 call check( nf90_inq_varid(ncid, 'q_w_x', ncv), thisroutine )
3657 call check( nf90_put_var(ncid, ncv, q_w_x_conv, &
3658  start=nc2cor_ij, count=nc2cnt_ij), &
3659  thisroutine )
3660 
3661 call check( nf90_inq_varid(ncid, 'q_w_y', ncv), thisroutine )
3662 call check( nf90_put_var(ncid, ncv, q_w_y_conv, &
3663  start=nc2cor_ij, count=nc2cnt_ij), &
3664  thisroutine )
3665 
3666 call check( nf90_inq_varid(ncid, 'H_w', ncv), thisroutine )
3667 call check( nf90_put_var(ncid, ncv, h_w_conv, &
3668  start=nc2cor_ij, count=nc2cnt_ij), &
3669  thisroutine )
3670 
3671 call check( nf90_inq_varid(ncid, 'q_gl_g', ncv), thisroutine )
3672 call check( nf90_put_var(ncid, ncv, q_gl_g_conv, &
3673  start=nc2cor_ij, count=nc2cnt_ij), &
3674  thisroutine )
3675 
3676 call check( nf90_inq_varid(ncid, 'q_cf_g', ncv), thisroutine )
3677 call check( nf90_put_var(ncid, ncv, q_cf_g_conv, &
3678  start=nc2cor_ij, count=nc2cnt_ij), &
3679  thisroutine )
3680 
3681 call check( nf90_inq_varid(ncid, 'ratio_sl_x', ncv), thisroutine )
3682 call check( nf90_put_var(ncid, ncv, ratio_sl_x_conv, &
3683  start=nc2cor_ij, count=nc2cnt_ij), &
3684  thisroutine )
3685 
3686 call check( nf90_inq_varid(ncid, 'ratio_sl_y', ncv), thisroutine )
3687 call check( nf90_put_var(ncid, ncv, ratio_sl_y_conv, &
3688  start=nc2cor_ij, count=nc2cnt_ij), &
3689  thisroutine )
3690 
3691 call check( nf90_inq_varid(ncid, 'flag_shelfy_stream_x', ncv), thisroutine )
3692 call check( nf90_put_var(ncid, ncv, flag_shelfy_stream_x_conv, &
3693  start=nc2cor_ij, count=nc2cnt_ij), &
3694  thisroutine )
3695 
3696 call check( nf90_inq_varid(ncid, 'flag_shelfy_stream_y', ncv), thisroutine )
3697 call check( nf90_put_var(ncid, ncv, flag_shelfy_stream_y_conv, &
3698  start=nc2cor_ij, count=nc2cnt_ij), &
3699  thisroutine )
3700 
3701 call check( nf90_inq_varid(ncid, 'flag_shelfy_stream', ncv), thisroutine )
3702 call check( nf90_put_var(ncid, ncv, flag_shelfy_stream_conv, &
3703  start=nc2cor_ij, count=nc2cnt_ij), &
3704  thisroutine )
3705 
3706 call check( nf90_inq_varid(ncid, 'flag_grounding_line_1', ncv), thisroutine )
3707 call check( nf90_put_var(ncid, ncv, flag_grounding_line_1_conv, &
3708  start=nc2cor_ij, count=nc2cnt_ij), &
3709  thisroutine )
3710 
3711 call check( nf90_inq_varid(ncid, 'flag_grounding_line_2', ncv), thisroutine )
3712 call check( nf90_put_var(ncid, ncv, flag_grounding_line_2_conv, &
3713  start=nc2cor_ij, count=nc2cnt_ij), &
3714  thisroutine )
3715 
3716 call check( nf90_inq_varid(ncid, 'flag_calving_front_1', ncv), thisroutine )
3717 call check( nf90_put_var(ncid, ncv, flag_calving_front_1_conv, &
3718  start=nc2cor_ij, count=nc2cnt_ij), &
3719  thisroutine )
3720 
3721 call check( nf90_inq_varid(ncid, 'flag_calving_front_2', ncv), thisroutine )
3722 call check( nf90_put_var(ncid, ncv, flag_calving_front_2_conv, &
3723  start=nc2cor_ij, count=nc2cnt_ij), &
3724  thisroutine )
3725 
3726 call check( nf90_inq_varid(ncid, 'flag_grounded_front_a_1', ncv), thisroutine )
3727 call check( nf90_put_var(ncid, ncv, flag_grounded_front_a_1_conv, &
3728  start=nc2cor_ij, count=nc2cnt_ij), &
3729  thisroutine )
3730 
3731 call check( nf90_inq_varid(ncid, 'flag_grounded_front_a_2', ncv), thisroutine )
3732 call check( nf90_put_var(ncid, ncv, flag_grounded_front_a_2_conv, &
3733  start=nc2cor_ij, count=nc2cnt_ij), &
3734  thisroutine )
3735 
3736 call check( nf90_inq_varid(ncid, 'flag_grounded_front_b_1', ncv), thisroutine )
3737 call check( nf90_put_var(ncid, ncv, flag_grounded_front_b_1_conv, &
3738  start=nc2cor_ij, count=nc2cnt_ij), &
3739  thisroutine )
3740 
3741 call check( nf90_inq_varid(ncid, 'flag_grounded_front_b_2', ncv), thisroutine )
3742 call check( nf90_put_var(ncid, ncv, flag_grounded_front_b_2_conv, &
3743  start=nc2cor_ij, count=nc2cnt_ij), &
3744  thisroutine )
3745 
3746 call check( nf90_inq_varid(ncid, 'vis_int_g', ncv), thisroutine )
3747 call check( nf90_put_var(ncid, ncv, vis_int_g_conv, &
3748  start=nc2cor_ij, count=nc2cnt_ij), &
3749  thisroutine )
3750 
3751 if (flag_3d_output) then
3752 
3753  call check( nf90_inq_varid(ncid, 'vx_c', ncv), thisroutine )
3754  call check( nf90_put_var(ncid, ncv, vx_c_conv, &
3755  start=nc3cor_ijkc, count=nc3cnt_ijkc), &
3756  thisroutine )
3757 
3758  call check( nf90_inq_varid(ncid, 'vy_c', ncv), thisroutine )
3759  call check( nf90_put_var(ncid, ncv, vy_c_conv, &
3760  start=nc3cor_ijkc, count=nc3cnt_ijkc), &
3761  thisroutine )
3762 
3763  call check( nf90_inq_varid(ncid, 'vz_c', ncv), thisroutine )
3764  call check( nf90_put_var(ncid, ncv, vz_c_conv, &
3765  start=nc3cor_ijkc, count=nc3cnt_ijkc), &
3766  thisroutine )
3767 
3768  call check( nf90_inq_varid(ncid, 'vx_t', ncv), thisroutine )
3769  call check( nf90_put_var(ncid, ncv, vx_t_conv, &
3770  start=nc3cor_ijkt, count=nc3cnt_ijkt), &
3771  thisroutine )
3772 
3773  call check( nf90_inq_varid(ncid, 'vy_t', ncv), thisroutine )
3774  call check( nf90_put_var(ncid, ncv, vy_t_conv, &
3775  start=nc3cor_ijkt, count=nc3cnt_ijkt), &
3776  thisroutine )
3777 
3778  call check( nf90_inq_varid(ncid, 'vz_t', ncv), thisroutine )
3779  call check( nf90_put_var(ncid, ncv, vz_t_conv, &
3780  start=nc3cor_ijkt, count=nc3cnt_ijkt), &
3781  thisroutine )
3782 
3783  call check( nf90_inq_varid(ncid, 'temp_c', ncv), thisroutine )
3784  call check( nf90_put_var(ncid, ncv, temp_c_conv, &
3785  start=nc3cor_ijkc, count=nc3cnt_ijkc), &
3786  thisroutine )
3787 
3788  call check( nf90_inq_varid(ncid, 'omega_t', ncv), thisroutine )
3789  call check( nf90_put_var(ncid, ncv, omega_t_conv, &
3790  start=nc3cor_ijkt, count=nc3cnt_ijkt), &
3791  thisroutine )
3792 
3793  call check( nf90_inq_varid(ncid, 'temp_r', ncv), thisroutine )
3794  call check( nf90_put_var(ncid, ncv, temp_r_conv, &
3795  start=nc3cor_ijkr, count=nc3cnt_ijkr), &
3796  thisroutine )
3797 
3798  call check( nf90_inq_varid(ncid, 'enth_c', ncv), thisroutine )
3799  call check( nf90_put_var(ncid, ncv, enth_c_conv, &
3800  start=nc3cor_ijkc, count=nc3cnt_ijkc), &
3801  thisroutine )
3802 
3803  call check( nf90_inq_varid(ncid, 'enth_t', ncv), thisroutine )
3804  call check( nf90_put_var(ncid, ncv, enth_t_conv, &
3805  start=nc3cor_ijkt, count=nc3cnt_ijkt), &
3806  thisroutine )
3807 
3808  call check( nf90_inq_varid(ncid, 'omega_c', ncv), thisroutine )
3809  call check( nf90_put_var(ncid, ncv, omega_c_conv, &
3810  start=nc3cor_ijkc, count=nc3cnt_ijkc), &
3811  thisroutine )
3812 
3813  call check( nf90_inq_varid(ncid, 'enh_c', ncv), thisroutine )
3814  call check( nf90_put_var(ncid, ncv, enh_c_conv, &
3815  start=nc3cor_ijkc, count=nc3cnt_ijkc), &
3816  thisroutine )
3817 
3818  call check( nf90_inq_varid(ncid, 'enh_t', ncv), thisroutine )
3819  call check( nf90_put_var(ncid, ncv, enh_t_conv, &
3820  start=nc3cor_ijkt, count=nc3cnt_ijkt), &
3821  thisroutine )
3822 
3823  call check( nf90_inq_varid(ncid, 'age_c', ncv), thisroutine )
3824  call check( nf90_put_var(ncid, ncv, age_c_conv, &
3825  start=nc3cor_ijkc, count=nc3cnt_ijkc), &
3826  thisroutine )
3827 
3828  call check( nf90_inq_varid(ncid, 'age_t', ncv), thisroutine )
3829  call check( nf90_put_var(ncid, ncv, age_t_conv, &
3830  start=nc3cor_ijkt, count=nc3cnt_ijkt), &
3831  thisroutine )
3832 
3833 end if
3834 
3835 #endif
3836 
3837 !-------- Close file --------
3838 
3839 #if (NETCDF==1) /* time-slice file in native binary format */
3840 
3841 close(unit=11, status='keep')
3842 
3843 #elif (NETCDF==2) /* time-slice file in NetCDF format */
3844 
3845 call check( nf90_sync(ncid), thisroutine )
3846 call check( nf90_close(ncid), thisroutine )
3847 
3848 deallocate(coord_id)
3849 
3850 #endif
3851 
3852 !-------- Increase file counter --------
3853 
3854 ndat = ndat+1
3855 
3856 if (flag_3d_output) then
3857  ndat3d = ndat
3858 else
3859  ndat2d = ndat
3860 end if
3861 
3862 end subroutine output1
3863 
3864 !-------------------------------------------------------------------------------
3865 !> Writing of time-series data on file in ASCII format
3866 !! (and optionally in NetCDF format).
3867 !<------------------------------------------------------------------------------
3868 subroutine output2(time, dxi, deta, delta_ts, glac_index, z_sl)
3870 #if (NETCDF>1)
3871  use netcdf
3872  use nc_check_m
3873 #endif
3874 
3875 #if (DISC>0)
3876  use discharge_workers_m, only: dt_glann, dt_sub
3877 #endif
3878 
3879 implicit none
3880 
3881 real(dp), intent(in) :: time, dxi, deta, delta_ts, glac_index, z_sl
3882 
3883 integer(i4b) :: i, j
3884 integer(i4b) :: n_base, n_tempbase
3885 real(dp) :: time_val, &
3886  V_tot, V_grounded, V_floating, A_tot, A_grounded, A_floating, &
3887  V_af, V_sle, V_temp, A_temp, &
3888  Q_s, Q_b, Q_temp, &
3889  H_max, H_t_max, zs_max, vs_max, Tbh_max, &
3890  accum_tot, calv_tot, mbp, &
3891  MB, LMT, OMT, LMB, OMB, LMH, OMH, ODT, ODH, &
3892  disc_lsc, disc_ssc
3893 real(dp) :: x_pos, y_pos
3894 real(dp), dimension(0:JMAX,0:IMAX) :: H, H_cold, H_temp
3895 real(dp) :: V_gr_redu, A_surf, rhosw_rho_ratio
3896 real(dp) :: vs_help, Tbh_help
3897 real(dp) :: H_ave_sed, Tbh_ave_sed, Atb_sed
3898 real(dp) :: sum_area_sed
3899 
3900 #if (NETCDF>1)
3901 integer(i4b), save :: ncid
3902 integer(i4b) :: ncd, ncv, nc1d
3903 integer(i4b) :: nc1cor(1), nc1cnt(1)
3904 integer(i4b) :: n_sync
3905 real(dp) :: dV_dt, precip_tot, runoff_tot, bmb_tot, mb_resid
3906 real(dp), save :: time_add_offset_val
3907 character(len= 16) :: ch_date, ch_time, ch_zone
3908 character(len=256) :: filename, filename_with_path, buffer
3909 logical, save :: grads_nc_tweaks
3910 #endif
3911 
3912 integer(i4b), save :: counter = 0
3913 logical, save :: firstcall = .true.
3914 
3915 character(len=64), parameter :: thisroutine = 'output2'
3916 
3917 character(len=128), parameter :: &
3918  fmt1 = '(1pe13.6,2(1pe13.4),/,' // &
3919  '13x,6(1pe13.4),/,' // &
3920  '26x,3(1pe13.4),/,' // &
3921  '26x,5(1pe13.4),/)'
3922 
3923 character(len=128), parameter :: &
3924  fmt2 = '(1pe13.6,2(1pe13.4),/,' // &
3925  '13x,3(1pe13.4),/)'
3926 
3927 character(len=128), parameter :: &
3928  fmt3 = '(1pe13.6,3(1pe13.4),/)'
3929 
3930 counter = counter + 1
3931 
3932 !-------- Ice thickness --------
3933 
3934 h = h_c + h_t
3935 
3936 !-------- Thickness of the cold and temperate layers --------
3937 
3938 h_cold = 0.0_dp
3939 h_temp = 0.0_dp
3940 
3941 #if (CALCMOD==1)
3942 do i=1, imax-1
3943 do j=1, jmax-1
3944  h_temp(j,i) = h_t(j,i)
3945 end do
3946 end do
3947 #elif (CALCMOD==0 || CALCMOD==2 || CALCMOD==3 || CALCMOD==-1)
3948 do i=1, imax-1
3949 do j=1, jmax-1
3950  h_temp(j,i) = h_c(j,i)*eaz_c_quotient(kc_cts(j,i))
3951 end do
3952 end do
3953 #endif
3954 
3955 h_cold = h - h_temp
3956 
3957 !-------- Maximum ice elevation and thickness, ice volume,
3958 ! sea-level equivalent, volume of the temperate ice,
3959 ! area, area covered by temperate ice,
3960 ! freshwater production due to melting and calving,
3961 ! water drainage due to basal melting,
3962 ! water drainage from the temperate layer,
3963 ! maximum thickness of the temperate layer,
3964 ! maximum surface velocity,
3965 ! maximum basal temperature rel. to pmp --------
3966 
3967 #if (defined(ANT) \
3968  || defined(grl) \
3969  || defined(scand) \
3970  || defined(nhem) \
3971  || defined(tibet) \
3972  || defined(asf) \
3973  || defined(emtp2sge) \
3974  || defined(xyz)) /* terrestrial ice sheet */
3975 
3976 rhosw_rho_ratio = rho_sw/rho
3977 
3978 #elif (defined(NMARS) || defined(SMARS)) /* Martian ice sheet */
3979 
3980 rhosw_rho_ratio = 0.0_dp ! dummy value
3981 
3982 #else
3983 errormsg = ' >>> output2: No valid domain specified!'
3984 call error(errormsg)
3985 #endif
3986 
3987 v_grounded = 0.0_dp
3988 v_gr_redu = 0.0_dp
3989 v_floating = 0.0_dp
3990 a_grounded = 0.0_dp
3991 a_floating = 0.0_dp
3992 v_temp = 0.0_dp
3993 a_temp = 0.0_dp
3994 q_s = 0.0_dp
3995 q_b = 0.0_dp
3996 q_temp = 0.0_dp
3997 h_max = 0.0_dp
3998 h_t_max = 0.0_dp
3999 zs_max = no_value_neg_2
4000 vs_max = 0.0_dp
4001 tbh_max = no_value_neg_2
4002 accum_tot = 0.0_dp
4003 
4004 do i=1, imax-1
4005 do j=1, jmax-1
4006 
4007  if (maske(j,i)==0_i1b) then ! grounded ice
4008 
4009  if (zs(j,i) > zs_max) zs_max = zs(j,i)
4010  if (h(j,i) > h_max ) h_max = h(j,i)
4011  if (h_temp(j,i) > h_t_max) h_t_max = h_temp(j,i)
4012 
4013  v_grounded = v_grounded + h(j,i) *area(j,i)
4014  v_temp = v_temp + h_temp(j,i)*area(j,i)
4015 
4016 #if (defined(ANT) \
4017  || defined(grl) \
4018  || defined(scand) \
4019  || defined(nhem) \
4020  || defined(tibet) \
4021  || defined(asf) \
4022  || defined(emtp2sge) \
4023  || defined(xyz)) /* terrestrial ice sheet */
4024 
4025  v_gr_redu = v_gr_redu &
4026  + rhosw_rho_ratio*max((z_sl-zl(j,i)),0.0_dp)*area(j,i)
4027 
4028 #endif
4029 
4030  a_grounded = a_grounded + area(j,i)
4031 
4032  if (n_cts(j,i) /= -1_i1b) a_temp = a_temp + area(j,i)
4033 
4034  vs_help = sqrt( &
4035  0.25_dp*(vx_c(kcmax,j,i)+vx_c(kcmax,j,i-1))**2 &
4036  +0.25_dp*(vy_c(kcmax,j,i)+vy_c(kcmax,j-1,i))**2 )
4037  if (vs_help > vs_max) vs_max = vs_help
4038 
4039  if (n_cts(j,i) >= 0_i1b) then ! temperate base
4040  tbh_max = 0.0_dp
4041  else ! cold base
4042  tbh_help = min((temp_c(0,j,i)-temp_c_m(0,j,i)), 0.0_dp)
4043  if (tbh_help > tbh_max) tbh_max = tbh_help
4044  end if
4045 
4046  accum_tot = accum_tot + accum(j,i)*area(j,i)
4047 
4048  else if (maske(j,i)==3_i1b) then ! floating ice
4049  ! (basal temperature assumed to be below
4050  ! the pressure melting point for pure ice)
4051 
4052  if (zs(j,i) > zs_max) zs_max = zs(j,i)
4053  if (h(j,i) > h_max) h_max = h(j,i)
4054 
4055  v_floating = v_floating + h(j,i)*area(j,i)
4056  a_floating = a_floating + area(j,i)
4057 
4058  vs_help = sqrt( &
4059  0.25_dp*(vx_c(kcmax,j,i)+vx_c(kcmax,j,i-1))**2 &
4060  +0.25_dp*(vy_c(kcmax,j,i)+vy_c(kcmax,j-1,i))**2 )
4061  if (vs_help > vs_max) vs_max = vs_help
4062 
4063  tbh_help = min((temp_c(0,j,i)-temp_c_m(0,j,i)), 0.0_dp)
4064  if (tbh_help > tbh_max) tbh_max = tbh_help
4065 
4066  accum_tot = accum_tot + accum(j,i)*area(j,i)
4067 
4068  end if
4069 
4070  if ( (maske(j,i)==0_i1b).or.(maske_old(j,i)==0_i1b) &
4071  .or.(maske(j,i)==3_i1b).or.(maske_old(j,i)==3_i1b) ) then
4072  ! grounded or floating ice before or after the time step
4073 
4074  q_s = q_s + as_perp_apl(j,i) * area(j,i)
4075  q_b = q_b + q_bm(j,i) * area(j,i)
4076 
4077  end if
4078 
4079  if ( (maske(j,i)==0_i1b).or.(maske_old(j,i)==0_i1b) ) then
4080  ! grounded ice before or after the time step
4081 
4082  q_temp = q_temp + q_tld(j,i) * area(j,i)
4083 
4084  end if
4085 
4086 end do
4087 end do
4088 
4089 !-------- Conversion --------
4090 
4091 #if (defined(ANT) \
4092  || defined(grl) \
4093  || defined(scand) \
4094  || defined(nhem) \
4095  || defined(tibet) \
4096  || defined(asf) \
4097  || defined(emtp2sge) \
4098  || defined(xyz)) /* terrestrial ice sheet */
4099 
4100 a_surf = 3.61132e+14_dp ! global ocean area, in m^2
4101 
4102 v_af = v_grounded - v_gr_redu
4103 v_sle = v_af*(rho/rho_w)/a_surf ! m^3 ice equiv./m^2 -> m water equiv.
4104 
4105 #elif (defined(NMARS) || defined(SMARS)) /* Martian ice sheet */
4106 
4107 a_surf = 1.4441e+14_dp ! surface area of Mars, in m^2
4108 v_sle = v_grounded*(rho_i/rho_w)*(1.0_dp-frac_dust)/a_surf
4109  ! m^3 (ice+dust) equiv./m^2 -> m water equiv.
4110 
4111 #endif
4112 
4113 #if (!defined(OUT_TIMES) || OUT_TIMES==1)
4114 time_val = time *sec_to_year ! s -> a
4115 #elif (OUT_TIMES==2)
4116 time_val = (time+year_zero) *sec_to_year ! s -> a
4117 #else
4118 errormsg = ' >>> output2: OUT_TIMES must be either 1 or 2!'
4119 call error(errormsg)
4120 #endif
4121 
4122 v_tot = v_grounded + v_floating ! in m^3
4123 a_tot = a_grounded + a_floating ! in m^2
4124 
4125 vs_max = vs_max *year_sec ! m/s -> m/a
4126 
4127 #if (defined(ANT) \
4128  || defined(grl) \
4129  || defined(scand) \
4130  || defined(nhem) \
4131  || defined(tibet) \
4132  || defined(asf) \
4133  || defined(emtp2sge) \
4134  || defined(xyz)) /* terrestrial ice sheet */
4135 
4136 q_s = q_s *year_sec *(rho/rho_w)
4137  ! m^3/s ice equiv. -> m^3/a water equiv.
4138 q_b = q_b *year_sec *(rho/rho_w)
4139  ! m^3/s ice equiv. -> m^3/a water equiv.
4140 q_temp = q_temp *year_sec *(rho/rho_w)
4141  ! m^3/s ice equiv. -> m^3/a water equiv.
4142 
4143 accum_tot = accum_tot *year_sec *(rho/rho_w)
4144  ! m^3/s ice equiv. -> m^3/a water equiv.
4145 
4146 #elif (defined(NMARS) || defined(SMARS)) /* Martian ice sheet */
4147 
4148 q_s = q_s *year_sec *(rho_i/rho_w)*(1.0_dp-frac_dust)
4149  ! m^3/s (ice+dust) equiv. -> m^3/a water equiv.
4150 q_b = q_b *year_sec *(rho_i/rho_w)*(1.0_dp-frac_dust)
4151  ! m^3/s (ice+dust) equiv. -> m^3/a water equiv.
4152 q_temp = q_temp *year_sec *(rho_i/rho_w)*(1.0_dp-frac_dust)
4153  ! m^3/s (ice+dust) equiv. -> m^3/a water equiv.
4154 #endif
4155 
4156 !-------- Writing of data on time-series file --------
4157 
4158 if (forcing_flag == 1) then
4159 
4160  write(unit=12, fmt=trim(fmt1)) time_val, delta_ts, z_sl, &
4161  v_tot, v_grounded, v_floating, a_tot, a_grounded, a_floating, &
4162  v_sle, v_temp, a_temp, &
4163  h_max, h_t_max, zs_max, vs_max, tbh_max
4164 
4165 else if (forcing_flag == 2) then
4166 
4167  write(unit=12, fmt=trim(fmt1)) time_val, glac_index, z_sl, &
4168  v_tot, v_grounded, v_floating, a_tot, a_grounded, a_floating, &
4169  v_sle, v_temp, a_temp, &
4170  h_max, h_t_max, zs_max, vs_max, tbh_max
4171 
4172 else if (forcing_flag == 3) then
4173 
4174  write(unit=12, fmt=trim(fmt1)) time_val, no_value_pos_1, z_sl, &
4175  v_tot, v_grounded, v_floating, a_tot, a_grounded, a_floating, &
4176  v_sle, v_temp, a_temp, &
4177  h_max, h_t_max, zs_max, vs_max, tbh_max
4178 
4179 end if
4180 
4181 !-------- Special output --------
4182 
4183 ! ------ Time-series data for the sediment region of HEINO
4184 
4185 #if (defined(XYZ))
4186 
4187 #if (defined(HEINO))
4188 
4189 ! ---- Average ice thickness, average basal temperature rel. to pmp,
4190 ! temperate basal area
4191 
4192 h_ave_sed = 0.0_dp
4193 tbh_ave_sed = 0.0_dp
4194 atb_sed = 0.0_dp
4195 sum_area_sed = 0.0_dp
4196 
4197 do i=1, imax-1
4198 do j=1, jmax-1
4199 
4200  if (maske_sedi(j,i)==7_i1b) then ! sediment region
4201 
4202  sum_area_sed = sum_area_sed + area(j,i)
4203 
4204  h_ave_sed = h_ave_sed + area(j,i)*h(j,i)
4205 
4206  if (n_cts(j,i) /= -1_i1b) then ! temperate base
4207  tbh_help = 0.0_dp
4208  else ! cold base
4209  tbh_help = min((temp_c(0,j,i)-temp_c_m(0,j,i)), 0.0_dp)
4210  end if
4211  tbh_ave_sed = tbh_ave_sed + area(j,i)*tbh_help
4212 
4213  if (n_cts(j,i) /= -1_i1b) atb_sed = atb_sed + area(j,i)
4214 
4215  end if
4216 
4217 end do
4218 end do
4219 
4220 if (sum_area_sed > eps) then
4221  h_ave_sed = h_ave_sed / sum_area_sed
4222  tbh_ave_sed = tbh_ave_sed / sum_area_sed
4223 else
4224  errormsg = ' >>> output2: No sediment area found!'
4225  call error(errormsg)
4226 end if
4227 
4228 ! ---- Writing of data on time-series file
4229 
4230 if (forcing_flag == 1) then
4231  write(unit=15, fmt=trim(fmt2)) time_val, delta_ts, z_sl, &
4232  h_ave_sed, tbh_ave_sed, atb_sed
4233 else if (forcing_flag == 2) then
4234  write(unit=15, fmt=trim(fmt2)) time_val, glac_index, z_sl, &
4235  h_ave_sed, tbh_ave_sed, atb_sed
4236 else if (forcing_flag == 3) then
4237  write(unit=15, fmt=trim(fmt2)) time_val, no_value_pos_1, z_sl, &
4238  h_ave_sed, tbh_ave_sed, atb_sed
4239 end if
4240 
4241 #endif
4242 
4243 #endif
4244 
4245 !-------- Extended time-series file in NetCDF format --------
4246 
4247 #if (NETCDF>1)
4248 
4249 if (firstcall) then
4250 
4251 ! ------ Open NetCDF file
4252 
4253  filename = trim(runname)//'_ser.nc'
4254  filename_with_path = trim(outpath)//'/'//trim(filename)
4255 
4256  call check( nf90_create(trim(filename_with_path), nf90_noclobber, ncid), &
4257  thisroutine )
4258 
4259  ncid_ser = ncid
4260 
4261 ! ------ Global attributes
4262 
4263  buffer = 'Time-series output of simulation '//trim(runname)
4264  call check( nf90_put_att(ncid, nf90_global, 'title', trim(buffer)), &
4265  thisroutine )
4266 
4267  buffer = 'Institute of Low Temperature Science, Hokkaido University, '// &
4268  'Sapporo, Japan'
4269  call check( nf90_put_att(ncid, nf90_global, 'institution', trim(buffer)), &
4270  thisroutine )
4271 
4272  buffer = 'SICOPOLIS Version '//version
4273  call check( nf90_put_att(ncid, nf90_global, 'source', trim(buffer)), &
4274  thisroutine )
4275 
4276  call date_and_time(ch_date, ch_time, ch_zone)
4277  buffer = ch_date(1:4)//'-'//ch_date(5:6)//'-'//ch_date(7:8)//' '// &
4278  ch_time(1:2)//':'//ch_time(3:4)//':'//ch_time(5:6)//' '// &
4279  ch_zone(1:3)//':'//ch_zone(4:5)//' - Data produced'
4280  call check( nf90_put_att(ncid, nf90_global, 'history', trim(buffer)), &
4281  thisroutine )
4282 
4283  buffer = 'http://www.sicopolis.net/'
4284  call check( nf90_put_att(ncid, nf90_global, 'references', trim(buffer)), &
4285  thisroutine )
4286 
4287 ! ------ Definition of the dimensions
4288 
4289  call set_grads_nc_tweaks(grads_nc_tweaks)
4290 
4291  if (grads_nc_tweaks) then
4292  call check( nf90_def_dim(ncid, 'x', 1, ncd), thisroutine )
4293  call check( nf90_def_dim(ncid, 'y', 1, ncd), thisroutine )
4294  end if
4295 
4296  call check( nf90_def_dim(ncid, 't', nf90_unlimited, ncd), thisroutine )
4297 
4298 ! ------ Definition of the variables
4299 
4300  if (grads_nc_tweaks) then
4301 
4302 ! ---- x
4303 
4304  call check( nf90_inq_dimid(ncid, 'x', nc1d), thisroutine )
4305  call check( nf90_def_var(ncid, 'x', nf90_float, nc1d, ncv), &
4306  thisroutine )
4307  buffer = 'm'
4308  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4309  thisroutine )
4310  buffer = 'x'
4311  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4312  thisroutine )
4313  buffer = 'Dummy x-coordinate for one point'
4314  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4315  thisroutine )
4316  call check( nf90_put_att(ncid, ncv, 'axis', 'x'), thisroutine )
4317 
4318 ! ---- y
4319 
4320  call check( nf90_inq_dimid(ncid, 'y', nc1d), thisroutine )
4321  call check( nf90_def_var(ncid, 'y', nf90_float, nc1d, ncv), &
4322  thisroutine )
4323  buffer = 'm'
4324  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4325  thisroutine )
4326  buffer = 'y'
4327  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4328  thisroutine )
4329  buffer = 'Dummy y-coordinate for one point'
4330  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4331  thisroutine )
4332  call check( nf90_put_att(ncid, ncv, 'axis', 'y'), thisroutine )
4333 
4334  end if
4335 
4336 ! ---- Time
4337 
4338  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4339  call check( nf90_def_var(ncid, 't', nf90_float, nc1d, ncv), &
4340  thisroutine )
4341  buffer = 'a'
4342  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4343  thisroutine )
4344  buffer = 'time'
4345  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4346  thisroutine )
4347  buffer = 'Time'
4348  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4349  thisroutine )
4350  call check( nf90_put_att(ncid, ncv, 'axis', 't'), thisroutine )
4351 
4352  if (grads_nc_tweaks) then
4353 
4354 ! ---- Time offset
4355 
4356  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4357  call check( nf90_def_var(ncid, 't_add_offset', nf90_float, nc1d, ncv), &
4358  thisroutine )
4359  buffer = 'a'
4360  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4361  thisroutine )
4362  buffer = 'time_add_offset'
4363  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4364  thisroutine )
4365  buffer = 'Time offset'
4366  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4367  thisroutine )
4368 
4369  time_add_offset_val = min(time_val, 0.0_dp)
4370 
4371  end if
4372 
4373  if (forcing_flag == 1) then
4374 
4375 ! ---- delta_ts
4376 
4377  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4378  call check( nf90_def_var(ncid, 'delta_ts', nf90_float, nc1d, ncv), &
4379  thisroutine )
4380  buffer = 'degC'
4381  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4382  thisroutine )
4383  buffer = 'surface_temperature_anomaly'
4384  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4385  thisroutine )
4386  buffer = 'Surface temperature anomaly'
4387  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4388  thisroutine )
4389 
4390  else if ((forcing_flag == 2).or.(forcing_flag == 3)) then
4391 
4392 ! ---- glac_index
4393 
4394  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4395  call check( nf90_def_var(ncid, 'glac_index', nf90_float, nc1d, ncv), &
4396  thisroutine )
4397  buffer = '1'
4398  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4399  thisroutine )
4400  buffer = 'glacial_index'
4401  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4402  thisroutine )
4403  buffer = 'Glacial index'
4404  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4405  thisroutine )
4406 
4407  end if
4408 
4409 ! ---- z_sl
4410 
4411  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4412  call check( nf90_def_var(ncid, 'z_sl', nf90_float, nc1d, ncv), &
4413  thisroutine )
4414  buffer = 'm'
4415  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4416  thisroutine )
4417  buffer = 'global_average_sea_level_change'
4418  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4419  thisroutine )
4420  buffer = 'Sea level'
4421  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4422  thisroutine )
4423 
4424 ! ---- V_tot
4425 
4426  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4427  call check( nf90_def_var(ncid, 'V_tot', nf90_float, nc1d, ncv), &
4428  thisroutine )
4429  buffer = 'm3'
4430  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4431  thisroutine )
4432  buffer = 'land_ice_volume'
4433  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4434  thisroutine )
4435  buffer = 'Ice volume'
4436  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4437  thisroutine )
4438 
4439 ! ---- V_grounded
4440 
4441  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4442  call check( nf90_def_var(ncid, 'V_grounded', nf90_float, nc1d, ncv), &
4443  thisroutine )
4444  buffer = 'm3'
4445  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4446  thisroutine )
4447  buffer = 'grounded_land_ice_volume'
4448  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4449  thisroutine )
4450  buffer = 'Volume of grounded ice'
4451  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4452  thisroutine )
4453 
4454 ! ---- V_floating
4455 
4456  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4457  call check( nf90_def_var(ncid, 'V_floating', nf90_float, nc1d, ncv), &
4458  thisroutine )
4459  buffer = 'm3'
4460  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4461  thisroutine )
4462  buffer = 'floating_ice_shelf_volume'
4463  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4464  thisroutine )
4465  buffer = 'Volume of floating ice'
4466  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4467  thisroutine )
4468 
4469 ! ---- A_tot
4470 
4471  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4472  call check( nf90_def_var(ncid, 'A_tot', nf90_float, nc1d, ncv), &
4473  thisroutine )
4474  buffer = 'm2'
4475  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4476  thisroutine )
4477  buffer = 'land_ice_area'
4478  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4479  thisroutine )
4480  buffer = 'Ice area'
4481  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4482  thisroutine )
4483 
4484 ! ---- A_grounded
4485 
4486  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4487  call check( nf90_def_var(ncid, 'A_grounded', nf90_float, nc1d, ncv), &
4488  thisroutine )
4489  buffer = 'm2'
4490  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4491  thisroutine )
4492  buffer = 'grounded_land_ice_area'
4493  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4494  thisroutine )
4495  buffer = 'Area covered by grounded ice'
4496  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4497  thisroutine )
4498 
4499 ! ---- A_floating
4500 
4501  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4502  call check( nf90_def_var(ncid, 'A_floating', nf90_float, nc1d, ncv), &
4503  thisroutine )
4504  buffer = 'm2'
4505  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4506  thisroutine )
4507  buffer = 'floating_ice_shelf_area'
4508  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4509  thisroutine )
4510  buffer = 'Area covered by floating ice'
4511  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4512  thisroutine )
4513 
4514 ! ---- V_af
4515 
4516  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4517  call check( nf90_def_var(ncid, 'V_af', nf90_float, nc1d, ncv), &
4518  thisroutine )
4519  buffer = 'm3'
4520  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4521  thisroutine )
4522  buffer = 'land_ice_volume_not_displacing_sea_water'
4523  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4524  thisroutine )
4525  buffer = 'Ice volume above flotation'
4526  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4527  thisroutine )
4528 
4529 ! ---- V_sle
4530 
4531  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4532  call check( nf90_def_var(ncid, 'V_sle', nf90_float, nc1d, ncv), &
4533  thisroutine )
4534  buffer = 'm SLE'
4535  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4536  thisroutine )
4537  buffer = 'land_ice_volume_sle'
4538  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4539  thisroutine )
4540  buffer = 'Ice volume in SLE'
4541  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4542  thisroutine )
4543 
4544 ! ---- V_temp
4545 
4546  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4547  call check( nf90_def_var(ncid, 'V_temp', nf90_float, nc1d, ncv), &
4548  thisroutine )
4549  buffer = 'm3'
4550  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4551  thisroutine )
4552  buffer = 'temperate_land_ice_volume'
4553  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4554  thisroutine )
4555  buffer = 'Volume of temperate ice'
4556  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4557  thisroutine )
4558 
4559 ! ---- A_temp
4560 
4561  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4562  call check( nf90_def_var(ncid, 'A_temp', nf90_float, nc1d, ncv), &
4563  thisroutine )
4564  buffer = 'm2'
4565  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4566  thisroutine )
4567  buffer = 'temperate_land_ice_area'
4568  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4569  thisroutine )
4570  buffer = 'Area covered by temperate ice'
4571  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4572  thisroutine )
4573 
4574 ! ---- Q_s
4575 
4576  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4577  call check( nf90_def_var(ncid, 'Q_s', nf90_float, nc1d, ncv), &
4578  thisroutine )
4579  buffer = 'm3 ice equiv. a-1'
4580  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4581  thisroutine )
4582  buffer = 'tendency_of_land_ice_volume_due_to_surface_mass_balance'
4583  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4584  thisroutine )
4585  buffer = 'Total surface mass balance'
4586  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4587  thisroutine )
4588 
4589 ! ---- precip_tot
4590 
4591  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4592  call check( nf90_def_var(ncid, 'precip_tot', nf90_float, nc1d, ncv), &
4593  thisroutine )
4594  buffer = 'm3 ice equiv. a-1'
4595  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4596  thisroutine )
4597  buffer = 'precipitation_rate'
4598  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4599  thisroutine )
4600  buffer = 'Precipitation rate'
4601  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4602  thisroutine )
4603 
4604 ! ---- runoff_tot
4605 
4606  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4607  call check( nf90_def_var(ncid, 'runoff_tot', nf90_float, nc1d, ncv), &
4608  thisroutine )
4609  buffer = 'm3 ice equiv. a-1'
4610  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4611  thisroutine )
4612  buffer = 'runoff_rate'
4613  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4614  thisroutine )
4615  buffer = 'Runoff rate'
4616  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4617  thisroutine )
4618 
4619 ! ---- bmb_tot
4620 
4621  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4622  call check( nf90_def_var(ncid, 'bmb_tot', nf90_float, nc1d, ncv), &
4623  thisroutine )
4624  buffer = 'm3 ice equiv. a-1'
4625  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4626  thisroutine )
4627  buffer = 'tendency_of_land_ice_volume_due_to_basal_mass_balance'
4628  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4629  thisroutine )
4630  buffer = 'Total basal mass balance'
4631  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4632  thisroutine )
4633 
4634 ! ---- Q_b
4635 
4636  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4637  call check( nf90_def_var(ncid, 'Q_b', nf90_float, nc1d, ncv), &
4638  thisroutine )
4639  buffer = 'm3 ice equiv. a-1'
4640  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4641  thisroutine )
4642  buffer = 'basal_melting_rate'
4643  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4644  thisroutine )
4645  buffer = 'Basal melting rate'
4646  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4647  thisroutine )
4648 
4649 ! ---- Q_temp
4650 
4651  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4652  call check( nf90_def_var(ncid, 'Q_temp', nf90_float, nc1d, ncv), &
4653  thisroutine )
4654  buffer = 'm3 ice equiv. a-1'
4655  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4656  thisroutine )
4657  buffer = 'temperate_layer_drainage_rate'
4658  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4659  thisroutine )
4660  buffer = 'Drainage rate from the temperate ice layer'
4661  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4662  thisroutine )
4663 
4664 ! ---- calv_tot
4665 
4666  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4667  call check( nf90_def_var(ncid, 'calv_tot', nf90_float, nc1d, ncv), &
4668  thisroutine )
4669  buffer = 'm3 ice equiv. a-1'
4670  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4671  thisroutine )
4672  buffer = 'tendency_of_land_ice_volume_due_to_calving'
4673  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4674  thisroutine )
4675  buffer = 'Total calving rate'
4676  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4677  thisroutine )
4678 
4679 #if (DISC>0)
4680 
4681 ! ---- disc_lsc
4682 
4683  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4684  call check( nf90_def_var(ncid, 'disc_lsc', nf90_float, nc1d, ncv), &
4685  thisroutine )
4686  buffer = 'm3 ice equiv. a-1'
4687  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4688  thisroutine )
4689  buffer = 'large_scale_ice_lost_into_the_ocean'
4690  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4691  thisroutine )
4692  buffer = 'Large scale ice lost into the ocean'
4693  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4694  thisroutine )
4695 
4696 ! ---- disc_ssc
4697 
4698  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4699  call check( nf90_def_var(ncid, 'disc_ssc', nf90_float, nc1d, ncv), &
4700  thisroutine )
4701  buffer = 'm3 ice equiv. a-1'
4702  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4703  thisroutine )
4704  buffer = 'small_scale_ice_lost_into_the_ocean'
4705  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4706  thisroutine )
4707  buffer = 'Small scale ice lost into the ocean'
4708  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4709  thisroutine )
4710 
4711 ! ---- dT_glann
4712 
4713  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4714  call check( nf90_def_var(ncid, 'dT_glann', nf90_float, nc1d, ncv), &
4715  thisroutine )
4716  buffer = 'degC'
4717  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4718  thisroutine )
4719  buffer = 'global_annual_temperature_anomaly'
4720  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4721  thisroutine )
4722  buffer = 'Global annual temperature anomaly'
4723  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4724  thisroutine )
4725 
4726 ! ---- dT_sub
4727 
4728  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4729  call check( nf90_def_var(ncid, 'dT_sub', nf90_float, nc1d, ncv), &
4730  thisroutine )
4731  buffer = 'degC'
4732  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4733  thisroutine )
4734  buffer = 'subsurface_ocean_temperature_anomaly'
4735  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4736  thisroutine )
4737  buffer = 'Subsurface ocean temperature anomaly'
4738  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4739  thisroutine )
4740 
4741 #endif
4742 
4743 ! ---- dV_dt
4744 
4745  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4746  call check( nf90_def_var(ncid, 'dV_dt', nf90_float, nc1d, ncv), &
4747  thisroutine )
4748  buffer = 'm3 a-1'
4749  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4750  thisroutine )
4751  buffer = 'tendency_of_land_ice_volume'
4752  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4753  thisroutine )
4754  buffer = 'Rate of ice volume change'
4755  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4756  thisroutine )
4757 
4758 ! ---- mb_resid
4759 
4760  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4761  call check( nf90_def_var(ncid, 'mb_resid', nf90_float, nc1d, ncv), &
4762  thisroutine )
4763  buffer = 'm3 ice equiv. a-1'
4764  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4765  thisroutine )
4766  buffer = 'total_mass_balance_residual'
4767  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4768  thisroutine )
4769  buffer = 'Residual of the total mass balance'
4770  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4771  thisroutine )
4772 
4773 ! ---- mbp
4774 
4775  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4776  call check( nf90_def_var(ncid, 'mbp', nf90_float, nc1d, ncv), &
4777  thisroutine )
4778  buffer = '1'
4779  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4780  thisroutine )
4781  buffer = 'mass_balance_partition'
4782  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4783  thisroutine )
4784  buffer = 'Mass balance partition'
4785  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4786  thisroutine )
4787 
4788 ! ---- H_max
4789 
4790  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4791  call check( nf90_def_var(ncid, 'H_max', nf90_float, nc1d, ncv), &
4792  thisroutine )
4793  buffer = 'm'
4794  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4795  thisroutine )
4796  buffer = 'maximum_ice_thickness'
4797  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4798  thisroutine )
4799  buffer = 'Maximum ice thickness'
4800  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4801  thisroutine )
4802 
4803 ! ---- H_t_max
4804 
4805  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4806  call check( nf90_def_var(ncid, 'H_t_max', nf90_float, nc1d, ncv), &
4807  thisroutine )
4808  buffer = 'm'
4809  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4810  thisroutine )
4811  buffer = 'maximum_thickness_of_temperate_ice'
4812  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4813  thisroutine )
4814  buffer = 'Maximum thickness of temperate ice'
4815  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4816  thisroutine )
4817 
4818 ! ---- zs_max
4819 
4820  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4821  call check( nf90_def_var(ncid, 'zs_max', nf90_float, nc1d, ncv), &
4822  thisroutine )
4823  buffer = 'm'
4824  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4825  thisroutine )
4826  buffer = 'maximum_surface_elevation'
4827  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4828  thisroutine )
4829  buffer = 'Maximum surface elevation'
4830  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4831  thisroutine )
4832 
4833 ! ---- vs_max
4834 
4835  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4836  call check( nf90_def_var(ncid, 'vs_max', nf90_float, nc1d, ncv), &
4837  thisroutine )
4838  buffer = 'm a-1'
4839  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4840  thisroutine )
4841  buffer = 'maximum_surface_speed'
4842  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4843  thisroutine )
4844  buffer = 'Maximum surface speed'
4845  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4846  thisroutine )
4847 
4848 ! ---- Tbh_max
4849 
4850  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
4851  call check( nf90_def_var(ncid, 'Tbh_max', nf90_float, nc1d, ncv), &
4852  thisroutine )
4853  buffer = 'degC'
4854  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
4855  thisroutine )
4856  buffer = 'maximum_basal_temperature_relative_to_pmp'
4857  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
4858  thisroutine )
4859  buffer = 'Maximum basal temperature relative to pmp'
4860  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
4861  thisroutine )
4862 
4863 ! ---- End of the definitions
4864 
4865  call check( nf90_enddef(ncid), thisroutine )
4866 
4867 end if
4868 
4869 ! ------ Computation of further data
4870 
4871 ! Q_s, Q_b, Q_temp from earlier computations (now in ice equiv.)
4872 q_s = q_s *(rho_w/rho)
4873  ! m^3/a water equiv. -> m^3/a ice equiv.
4874 q_b = q_b *(rho_w/rho)
4875  ! m^3/a water equiv. -> m^3/a ice equiv.
4876 q_temp = q_temp *(rho_w/rho)
4877  ! m^3/a water equiv. -> m^3/a ice equiv.
4878 
4879 ! Computation of volume fluxes
4880 
4881 dv_dt = 0.0_dp
4882 precip_tot = 0.0_dp
4883 
4884 do i=1, imax-1
4885 do j=1, jmax-1
4886 
4887  if ( (maske(j,i)==0_i1b).or.(maske_old(j,i)==0_i1b) &
4888  .or.(maske(j,i)==3_i1b).or.(maske_old(j,i)==3_i1b) ) then
4889  ! grounded or floating ice before or after the time step
4890 
4891  ! Volume change
4892  dv_dt = dv_dt + (dzs_dtau(j,i)-dzb_dtau(j,i))*area(j,i)
4893  precip_tot = precip_tot + accum(j,i)*area(j,i)
4894 
4895  end if
4896 
4897 end do
4898 end do
4899 
4900 precip_tot = precip_tot *year_sec
4901  ! m^3/s ice equiv. -> m^3/a ice equiv.
4902 dv_dt = dv_dt *year_sec
4903  ! m^3/s ice equiv. -> m^3/a ice equiv.
4904 
4905 #if (MB_ACCOUNT==0)
4906 
4907 runoff_tot = 0.0_dp
4908 calv_tot = 0.0_dp
4909 
4910 do i=1, imax-1
4911 do j=1, jmax-1
4912 
4913  if ( (maske(j,i)==0_i1b).or.(maske_old(j,i)==0_i1b) &
4914  .or.(maske(j,i)==3_i1b).or.(maske_old(j,i)==3_i1b) ) then
4915  ! grounded or floating ice before or after the time step
4916 
4917  runoff_tot = runoff_tot + runoff(j,i)*area(j,i)
4918  calv_tot = calv_tot + calv_grounded(j,i)*area(j,i)
4919 
4920  end if
4921 
4922 end do
4923 end do
4924 
4925 bmb_tot = -(q_b+q_temp) ! positive for supply, negative for loss
4926 
4927 #elif (MB_ACCOUNT==1)
4928 
4929 ! MB: total mass balance as computed in subroutine apply_smb
4930 ! LMT: total lost on land at the top of the ice sheet
4931 ! LMB: total lost on land at the base of the ice sheet
4932 ! LMH: total hidden lost on land
4933 ! OMT: total lost in the ocean at the top of the ice sheet
4934 ! OMB: total lost in the ocean at the base of the ice sheet
4935 ! OMH: total hidden lost in the ocean
4936 ! ODT: total lost through ice discharge parameterization
4937 ! ODH: total hidden lost through ice discharge parameterization
4938 
4939 mb = 0.0_dp
4940 lmt = 0.0_dp; omt = 0.0_dp
4941 lmb = 0.0_dp; omb = 0.0_dp
4942 lmh = 0.0_dp; omh = 0.0_dp
4943 odt = 0.0_dp; odh = 0.0_dp
4944 
4945 do i=1, imax-1
4946 do j=1, jmax-1
4947 
4948  if ( mask_ablation_type(j,i) /= 0_i1b ) then
4949  ! glaciated land and ocean (including hidden melt points)
4950 
4951  ! Quantify what types of melt occurred
4952  select case ( mask_ablation_type(j,i) )
4953  case( 2_i1b )
4954  omt = omt + runoff_apl(j,i) * area(j,i)
4955  odt = odt + calv_grounded_apl(j,i) * area(j,i)
4956  omb = omb + q_b_apl(j,i) * area(j,i)
4957  case( 1_i1b )
4958  lmt = lmt + runoff_apl(j,i) * area(j,i)
4959  odt = odt + calv_grounded_apl(j,i) * area(j,i) ! ok
4960  lmb = lmb + q_b_apl(j,i) * area(j,i)
4961  case( -1_i1b )
4962  odh = odh + calv_grounded_apl(j,i) * area(j,i)
4963  lmh = lmh + runoff_apl(j,i) * area(j,i)
4964 ! note: Q_b_apl(j,i) not counted as hidden yet
4965  case( -2_i1b )
4966  odh = odh + calv_grounded_apl(j,i) * area(j,i)
4967  omh = omh + runoff_apl(j,i) * area(j,i)
4968 ! note: Q_b_apl(j,i) not counted as hidden yet
4969  end select
4970 
4971  end if
4972 
4973  ! Actual ice mass balance (from top melt, bottom melt and calving)
4974  mb = mb + mb_source_apl(j,i)*area(j,i)
4975 
4976 end do
4977 end do
4978 
4979 ! Runoff on land (excluding basal melt)
4980 runoff_tot = lmt + lmh
4981 ! Ice discharge (excluding basal melt)
4982 calv_tot = omt + omh + odt + odh
4983 ! Ice discharge from ice flow, large scale
4984 disc_lsc = omt + omh
4985 ! Ice discharge from parameterization, small scale
4986 disc_ssc = odt + odh
4987 ! Basal mass balance (here basal melt only)
4988 bmb_tot = -lmb-omb
4989 
4990 mb = mb * year_sec
4991  ! m^3/s ice equiv. -> m^3/a ice equiv.
4992 disc_lsc = disc_lsc * year_sec
4993  ! m^3/s ice equiv. -> m^3/a ice equiv.
4994 disc_ssc = disc_ssc * year_sec
4995  ! m^3/s ice equiv. -> m^3/a ice equiv.
4996 bmb_tot = bmb_tot * year_sec
4997  ! m^3/s ice equiv. -> m^3/a ice equiv.
4998 
4999 #endif /* if (MB_ACCOUNT==0) elif (MB_ACCOUNT==1) */
5000 
5001 runoff_tot = runoff_tot *year_sec
5002  ! m^3/s ice equiv. -> m^3/a ice equiv.
5003 calv_tot = calv_tot * year_sec
5004  ! m^3/s ice equiv. -> m^3/a ice equiv.
5005 
5006 if (precip_tot /= 0.0_dp) then
5007  mbp = calv_tot/precip_tot
5008 else
5009  mbp = 0.0_dp
5010 end if
5011 
5012 #if (MB_ACCOUNT==0)
5013 mb_resid = q_s + bmb_tot - calv_tot - dv_dt
5014 #elif(MB_ACCOUNT==1)
5015 mb_resid = mb - dv_dt
5016 #endif
5017 
5018 ! ------ Writing of data on NetCDF file
5019 
5020 if (firstcall.and.grads_nc_tweaks) then
5021 
5022  nc1cor = (/ 1 /)
5023 
5024  call check( nf90_inq_varid(ncid, 'x', ncv), thisroutine )
5025  call check( nf90_put_var(ncid, ncv, 0.0_sp, start=nc1cor), thisroutine )
5026 
5027  call check( nf90_inq_varid(ncid, 'y', ncv), thisroutine )
5028  call check( nf90_put_var(ncid, ncv, 0.0_sp, start=nc1cor), thisroutine )
5029 
5030  call check( nf90_sync(ncid), thisroutine )
5031 
5032 end if
5033 
5034 nc1cor(1) = counter
5035 ! nc1cnt(1) = 1 ! (not needed, and causes troubles for whatever reason)
5036 
5037 call check( nf90_inq_varid(ncid, 't', ncv), thisroutine )
5038 
5039 if (.not.grads_nc_tweaks) then
5040  call check( nf90_put_var(ncid, ncv, real(time_val,sp), &
5041  start=nc1cor), thisroutine )
5042 else
5043  call check( nf90_put_var(ncid, ncv, &
5044  real(time_val-time_add_offset_val,sp), &
5045  start=nc1cor), thisroutine )
5046  ! this makes sure that all times are >=0
5047  ! (GrADS doesn't like negative numbers)
5048  call check( nf90_inq_varid(ncid, 't_add_offset', ncv), thisroutine )
5049  call check( nf90_put_var(ncid, ncv, &
5050  real(time_add_offset_val,sp), &
5051  start=nc1cor), thisroutine )
5052 end if
5053 
5054 if (forcing_flag == 1) then
5055 
5056  call check( nf90_inq_varid(ncid, 'delta_ts', ncv), thisroutine )
5057  call check( nf90_put_var(ncid, ncv, real(delta_ts,sp), &
5058  start=nc1cor), thisroutine )
5059 
5060 else if (forcing_flag == 2) then
5061 
5062  call check( nf90_inq_varid(ncid, 'glac_index', ncv), thisroutine )
5063  call check( nf90_put_var(ncid, ncv, real(glac_index,sp), &
5064  start=nc1cor), thisroutine )
5065 
5066 else if (forcing_flag == 3) then
5067 
5068  call check( nf90_inq_varid(ncid, 'glac_index', ncv), thisroutine )
5069  call check( nf90_put_var(ncid, ncv, real(no_value_neg_2,sp), &
5070  start=nc1cor), thisroutine )
5071 
5072 end if
5073 
5074 call check( nf90_inq_varid(ncid, 'z_sl', ncv), thisroutine )
5075 call check( nf90_put_var(ncid, ncv, real(z_sl,sp), &
5076  start=nc1cor), thisroutine )
5077 
5078 call check( nf90_inq_varid(ncid, 'V_tot', ncv), thisroutine )
5079 call check( nf90_put_var(ncid, ncv, real(V_tot,sp), &
5080  start=nc1cor), thisroutine )
5081 
5082 call check( nf90_inq_varid(ncid, 'V_grounded', ncv), thisroutine )
5083 call check( nf90_put_var(ncid, ncv, real(V_grounded,sp), &
5084  start=nc1cor), thisroutine )
5085 
5086 call check( nf90_inq_varid(ncid, 'V_floating', ncv), thisroutine )
5087 call check( nf90_put_var(ncid, ncv, real(V_floating,sp), &
5088  start=nc1cor), thisroutine )
5089 
5090 call check( nf90_inq_varid(ncid, 'A_tot', ncv), thisroutine )
5091 call check( nf90_put_var(ncid, ncv, real(A_tot,sp), &
5092  start=nc1cor), thisroutine )
5093 
5094 call check( nf90_inq_varid(ncid, 'A_grounded', ncv), thisroutine )
5095 call check( nf90_put_var(ncid, ncv, real(A_grounded,sp), &
5096  start=nc1cor), thisroutine )
5097 
5098 call check( nf90_inq_varid(ncid, 'A_floating', ncv), thisroutine )
5099 call check( nf90_put_var(ncid, ncv, real(A_floating,sp), &
5100  start=nc1cor), thisroutine )
5101 
5102 call check( nf90_inq_varid(ncid, 'V_af', ncv), thisroutine )
5103 call check( nf90_put_var(ncid, ncv, real(V_af,sp), &
5104  start=nc1cor), thisroutine )
5105 
5106 call check( nf90_inq_varid(ncid, 'V_sle', ncv), thisroutine )
5107 call check( nf90_put_var(ncid, ncv, real(V_sle,sp), &
5108  start=nc1cor), thisroutine )
5109 
5110 call check( nf90_inq_varid(ncid, 'V_temp', ncv), thisroutine )
5111 call check( nf90_put_var(ncid, ncv, real(V_temp,sp), &
5112  start=nc1cor), thisroutine )
5113 
5114 call check( nf90_inq_varid(ncid, 'A_temp', ncv), thisroutine )
5115 call check( nf90_put_var(ncid, ncv, real(A_temp,sp), &
5116  start=nc1cor), thisroutine )
5117 
5118 call check( nf90_inq_varid(ncid, 'Q_s', ncv), thisroutine )
5119 call check( nf90_put_var(ncid, ncv, real(Q_s,sp), &
5120  start=nc1cor), thisroutine )
5121 
5122 call check( nf90_inq_varid(ncid, 'precip_tot', ncv), thisroutine )
5123 call check( nf90_put_var(ncid, ncv, real(precip_tot,sp), &
5124  start=nc1cor), thisroutine )
5125 
5126 call check( nf90_inq_varid(ncid, 'runoff_tot', ncv), thisroutine )
5127 call check( nf90_put_var(ncid, ncv, real(runoff_tot,sp), &
5128  start=nc1cor), thisroutine )
5129 
5130 call check( nf90_inq_varid(ncid, 'bmb_tot', ncv), thisroutine )
5131 call check( nf90_put_var(ncid, ncv, real(bmb_tot,sp), &
5132  start=nc1cor), thisroutine )
5133 
5134 call check( nf90_inq_varid(ncid, 'Q_b', ncv), thisroutine )
5135 call check( nf90_put_var(ncid, ncv, real(Q_b,sp), &
5136  start=nc1cor), thisroutine )
5137 
5138 call check( nf90_inq_varid(ncid, 'Q_temp', ncv), thisroutine )
5139 call check( nf90_put_var(ncid, ncv, real(Q_temp,sp), &
5140  start=nc1cor), thisroutine )
5141 
5142 call check( nf90_inq_varid(ncid, 'calv_tot', ncv), thisroutine )
5143 call check( nf90_put_var(ncid, ncv, real(calv_tot,sp), &
5144  start=nc1cor), thisroutine )
5145 
5146 #if (DISC>0)
5147 call check( nf90_inq_varid(ncid, 'disc_lsc', ncv), thisroutine )
5148 call check( nf90_put_var(ncid, ncv, real(disc_lsc,sp), &
5149  start=nc1cor), thisroutine )
5150 
5151 call check( nf90_inq_varid(ncid, 'disc_ssc', ncv), thisroutine )
5152 call check( nf90_put_var(ncid, ncv, real(disc_ssc,sp), &
5153  start=nc1cor), thisroutine )
5154 
5155 call check( nf90_inq_varid(ncid, 'dT_glann', ncv), thisroutine )
5156 call check( nf90_put_var(ncid, ncv, real(dT_glann,sp), &
5157  start=nc1cor), thisroutine )
5158 
5159 call check( nf90_inq_varid(ncid, 'dT_sub', ncv), thisroutine )
5160 call check( nf90_put_var(ncid, ncv, real(dT_sub,sp), &
5161  start=nc1cor), thisroutine )
5162 #endif
5163 
5164 call check( nf90_inq_varid(ncid, 'dV_dt', ncv), thisroutine )
5165 call check( nf90_put_var(ncid, ncv, real(dV_dt,sp), &
5166  start=nc1cor), thisroutine )
5167 
5168 call check( nf90_inq_varid(ncid, 'mb_resid', ncv), thisroutine )
5169 call check( nf90_put_var(ncid, ncv, real(mb_resid,sp), &
5170  start=nc1cor), thisroutine )
5171 
5172 call check( nf90_inq_varid(ncid, 'mbp', ncv), thisroutine )
5173 call check( nf90_put_var(ncid, ncv, real(mbp,sp), &
5174  start=nc1cor), thisroutine )
5175 
5176 call check( nf90_inq_varid(ncid, 'H_max', ncv), thisroutine )
5177 call check( nf90_put_var(ncid, ncv, real(H_max,sp), &
5178  start=nc1cor), thisroutine )
5179 
5180 call check( nf90_inq_varid(ncid, 'H_t_max', ncv), thisroutine )
5181 call check( nf90_put_var(ncid, ncv, real(H_t_max,sp), &
5182  start=nc1cor), thisroutine )
5183 
5184 call check( nf90_inq_varid(ncid, 'zs_max', ncv), thisroutine )
5185 call check( nf90_put_var(ncid, ncv, real(zs_max,sp), &
5186  start=nc1cor), thisroutine )
5187 
5188 call check( nf90_inq_varid(ncid, 'vs_max', ncv), thisroutine )
5189 call check( nf90_put_var(ncid, ncv, real(vs_max,sp), &
5190  start=nc1cor), thisroutine )
5191 
5192 call check( nf90_inq_varid(ncid, 'Tbh_max', ncv), thisroutine )
5193 call check( nf90_put_var(ncid, ncv, real(Tbh_max,sp), &
5194  start=nc1cor), thisroutine )
5195 
5196 ! ------ Syncing NetCDF file (every 100th time)
5197 
5198 n_sync = 100
5199 
5200 if ( mod((counter-1), n_sync) == 0 ) &
5201  call check( nf90_sync(ncid), thisroutine )
5202 
5203 #endif
5204 
5205 if (firstcall) firstcall = .false.
5206 
5207 end subroutine output2
5208 
5209 !-------------------------------------------------------------------------------
5210 !> Writing of time-series data of the deep ice cores on file in ASCII format
5211 !! (and optionally in NetCDF format).
5212 !<------------------------------------------------------------------------------
5213 subroutine output4(time, dxi, deta, delta_ts, glac_index, z_sl)
5215 #if (NETCDF>1)
5216  use netcdf
5217  use nc_check_m
5218 #endif
5219 
5220 implicit none
5221 
5222 real(dp), intent(in) :: time, dxi, deta, delta_ts, glac_index, z_sl
5223 
5224 integer(i4b) :: i, j, n
5225 real(sp), dimension(:), allocatable :: r_n_core
5226 real(dp) :: time_val
5227 real(dp), dimension(0:JMAX,0:IMAX) :: field
5228 real(dp), dimension(:), allocatable :: H_core, temp_b_core, &
5229  vx_b_core, vy_b_core, vh_b_core, &
5230  vx_s_core, vy_s_core, vh_s_core, &
5231  Rx_b_core, Ry_b_core, R_b_core, &
5232  bmb_core
5233 
5234 #if (NETCDF>1)
5235 integer(i4b), save :: ncid
5236 integer(i4b) :: ncd, ncv, nc1d, nc2d(2)
5237 integer(i4b) :: nc1cor(1), nc1cnt(1), nc2cor(2), nc2cnt(2)
5238 integer(i4b) :: n_sync
5239 real(dp), save :: time_add_offset_val
5240 character(len= 16) :: ch_date, ch_time, ch_zone
5241 character(len=256) :: filename, filename_with_path, buffer
5242 logical, save :: grads_nc_tweaks
5243 #endif
5244 
5245 integer(i4b), save :: counter = 0
5246 logical, save :: firstcall = .true.
5247 
5248 character(len=64), parameter :: thisroutine = 'output4'
5249 
5250 counter = counter + 1
5251 
5252 if (n_core >= 1) then
5253 
5254  allocate(r_n_core(n_core), h_core(n_core), temp_b_core(n_core), &
5255  vx_b_core(n_core), vy_b_core(n_core), vh_b_core(n_core), &
5256  vx_s_core(n_core), vy_s_core(n_core), vh_s_core(n_core), &
5257  rx_b_core(n_core), ry_b_core(n_core), r_b_core(n_core), &
5258  bmb_core(n_core))
5259 
5260 !-------- Determination of ice-core data --------
5261 
5262  do n=1, n_core
5263 
5264 ! ------Ice core number
5265 
5266  r_n_core(n) = real(n,sp)
5267 
5268 ! ------ Ice thickness
5269 
5270  field = h_c + h_t
5271  call borehole(field, x_core(n), y_core(n), dxi, deta, 'grid', h_core(n))
5272 
5273 ! ------ Basal velocity
5274 
5275  do i=0, imax
5276  do j=0, jmax
5277  field(j,i) = vx_t(0,j,i)
5278  end do
5279  end do
5280 
5281  call borehole(field, x_core(n), y_core(n), dxi, deta, 'sg_x', vx_b_core(n))
5282 
5283  do i=0, imax
5284  do j=0, jmax
5285  field(j,i) = vy_t(0,j,i)
5286  end do
5287  end do
5288 
5289  call borehole(field, x_core(n), y_core(n), dxi, deta, 'sg_y', vy_b_core(n))
5290 
5291  vh_b_core(n) = sqrt(vx_b_core(n)**2+vy_b_core(n)**2)
5292 
5293 ! ------ Surface velocity
5294 
5295  do i=0, imax
5296  do j=0, jmax
5297  field(j,i) = vx_c(kcmax,j,i)
5298  end do
5299  end do
5300 
5301  call borehole(field, x_core(n), y_core(n), dxi, deta, 'sg_x', vx_s_core(n))
5302 
5303  do i=0, imax
5304  do j=0, jmax
5305  field(j,i) = vy_c(kcmax,j,i)
5306  end do
5307  end do
5308 
5309  call borehole(field, x_core(n), y_core(n), dxi, deta, 'sg_y', vy_s_core(n))
5310 
5311  vh_s_core(n) = sqrt(vx_s_core(n)**2+vy_s_core(n)**2)
5312 
5313 ! ------ Basal temperature
5314 
5315  do i=0, imax
5316  do j=0, jmax
5317  field(j,i) = temp_r(krmax,j,i)
5318  end do
5319  end do
5320 
5321  call borehole(field, x_core(n), y_core(n), dxi, deta, 'grid', temp_b_core(n))
5322 
5323 ! ------ Basal frictional heating
5324 
5325  do i=0, imax
5326  do j=0, jmax
5327  field(j,i) = vx_t(0,j,i)*txz_t(0,j,i)
5328  end do
5329  end do
5330 
5331  call borehole(field, x_core(n), y_core(n), dxi, deta, 'sg_x', rx_b_core(n))
5332 
5333  do i=0, imax
5334  do j=0, jmax
5335  field(j,i) = vy_t(0,j,i)*tyz_t(0,j,i)
5336  end do
5337  end do
5338 
5339  call borehole(field, x_core(n), y_core(n), dxi, deta, 'sg_y', ry_b_core(n))
5340 
5341  r_b_core(n) = rx_b_core(n) + ry_b_core(n)
5342 
5343 ! ------ Basal mass balance
5344 
5345  field = -(q_bm+q_tld) ! positive for supply, negative for loss
5346  call borehole(field, x_core(n), y_core(n), dxi, deta, 'grid', bmb_core(n))
5347 
5348  end do
5349 
5350 ! ------ Conversion
5351 
5352 #if (!defined(OUT_TIMES) || OUT_TIMES==1)
5353  time_val = time *sec_to_year ! s -> a
5354 #elif (OUT_TIMES==2)
5355  time_val = (time+year_zero) *sec_to_year ! s -> a
5356 #else
5357  errormsg = ' >>> output4: OUT_TIMES must be either 1 or 2!'
5358  call error(errormsg)
5359 #endif
5360 
5361  vh_b_core = vh_b_core *year_sec ! m/s -> m/a
5362  vh_s_core = vh_s_core *year_sec ! m/s -> m/a
5363 
5364  bmb_core = bmb_core *year_sec ! m ice equiv./s -> m ice equiv./a
5365 
5366 !-------- Writing of data on file --------
5367 
5368  if (forcing_flag == 1) then
5369  write(unit=14, fmt='(1pe13.6,2(1pe13.4))') time_val, delta_ts, z_sl
5370  else if (forcing_flag == 2) then
5371  write(unit=14, fmt='(1pe13.6,2(1pe13.4))') time_val, glac_index, z_sl
5372  else if (forcing_flag == 3) then
5373  write(unit=14, fmt='(1pe13.6,2(1pe13.4))') time_val, no_value_pos_1, z_sl
5374  end if
5375 
5376  n=1
5377  write(unit=14, fmt='(13x,1pe13.4)', advance='no') h_core(n)
5378  do n=2, n_core-1
5379  write(unit=14, fmt='(1pe13.4)', advance='no') h_core(n)
5380  end do
5381  n=n_core
5382  write(unit=14, fmt='(1pe13.4)') h_core(n)
5383 
5384  n=1
5385  write(unit=14, fmt='(13x,1pe13.4)', advance='no') vh_s_core(n)
5386  do n=2, n_core-1
5387  write(unit=14, fmt='(1pe13.4)', advance='no') vh_s_core(n)
5388  end do
5389  n=n_core
5390  write(unit=14, fmt='(1pe13.4)') vh_s_core(n)
5391 
5392  n=1
5393  write(unit=14, fmt='(13x,1pe13.4)', advance='no') temp_b_core(n)
5394  do n=2, n_core-1
5395  write(unit=14, fmt='(1pe13.4)', advance='no') temp_b_core(n)
5396  end do
5397  n=n_core
5398  write(unit=14, fmt='(1pe13.4,/)') temp_b_core(n)
5399 
5400 !-------- Extended time-series file in NetCDF format --------
5401 
5402 #if (NETCDF>1)
5403 
5404  if (firstcall) then
5405 
5406 ! ------ Open NetCDF file
5407 
5408  filename = trim(runname)//'_core.nc'
5409  filename_with_path = trim(outpath)//'/'//trim(filename)
5410 
5411  call check( nf90_create(trim(filename_with_path), nf90_noclobber, ncid), &
5412  thisroutine )
5413 
5414  ncid_core = ncid
5415 
5416 ! ------ Global attributes
5417 
5418  buffer = 'Time-series output for the deep ice cores of simulation '// &
5419  trim(runname)
5420  call check( nf90_put_att(ncid, nf90_global, 'title', trim(buffer)), &
5421  thisroutine )
5422 
5423  buffer = 'Institute of Low Temperature Science, Hokkaido University, '// &
5424  'Sapporo, Japan'
5425  call check( nf90_put_att(ncid, nf90_global, 'institution', &
5426  trim(buffer)), &
5427  thisroutine )
5428 
5429  buffer = 'SICOPOLIS Version '//version
5430  call check( nf90_put_att(ncid, nf90_global, 'source', trim(buffer)), &
5431  thisroutine )
5432 
5433  call date_and_time(ch_date, ch_time, ch_zone)
5434  buffer = ch_date(1:4)//'-'//ch_date(5:6)//'-'//ch_date(7:8)//' '// &
5435  ch_time(1:2)//':'//ch_time(3:4)//':'//ch_time(5:6)//' '// &
5436  ch_zone(1:3)//':'//ch_zone(4:5)//' - Data produced'
5437  call check( nf90_put_att(ncid, nf90_global, 'history', trim(buffer)), &
5438  thisroutine )
5439 
5440  buffer = 'http://www.sicopolis.net/'
5441  call check( nf90_put_att(ncid, nf90_global, 'references', trim(buffer)), &
5442  thisroutine )
5443 
5444 ! ------ Definition of the dimensions
5445 
5446  call set_grads_nc_tweaks(grads_nc_tweaks)
5447 
5448  if (grads_nc_tweaks) then
5449  call check( nf90_def_dim(ncid, 'x', 1, ncd), thisroutine )
5450  call check( nf90_def_dim(ncid, 'y', 1, ncd), thisroutine )
5451  end if
5452 
5453  call check( nf90_def_dim(ncid, 'n', n_core, ncd), thisroutine )
5454  call check( nf90_def_dim(ncid, 't', nf90_unlimited, ncd), thisroutine )
5455 
5456 ! ------ Definition of the variables
5457 
5458  if (grads_nc_tweaks) then
5459 
5460 ! ---- x
5461 
5462  call check( nf90_inq_dimid(ncid, 'x', nc1d), thisroutine )
5463  call check( nf90_def_var(ncid, 'x', nf90_float, nc1d, ncv), &
5464  thisroutine )
5465  buffer = 'm'
5466  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
5467  thisroutine )
5468  buffer = 'x'
5469  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
5470  thisroutine )
5471  buffer = 'Dummy x-coordinate for one point'
5472  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
5473  thisroutine )
5474  call check( nf90_put_att(ncid, ncv, 'axis', 'x'), thisroutine )
5475 
5476 ! ---- y
5477 
5478  call check( nf90_inq_dimid(ncid, 'y', nc1d), thisroutine )
5479  call check( nf90_def_var(ncid, 'y', nf90_float, nc1d, ncv), &
5480  thisroutine )
5481  buffer = 'm'
5482  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
5483  thisroutine )
5484  buffer = 'y'
5485  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
5486  thisroutine )
5487  buffer = 'Dummy y-coordinate for one point'
5488  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
5489  thisroutine )
5490  call check( nf90_put_att(ncid, ncv, 'axis', 'y'), thisroutine )
5491 
5492  end if
5493 
5494 ! ---- Time
5495 
5496  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
5497  call check( nf90_def_var(ncid, 't', nf90_float, nc1d, ncv), &
5498  thisroutine )
5499  buffer = 'a'
5500  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
5501  thisroutine )
5502  buffer = 'time'
5503  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
5504  thisroutine )
5505  buffer = 'Time'
5506  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
5507  thisroutine )
5508  call check( nf90_put_att(ncid, ncv, 'axis', 't'), thisroutine )
5509 
5510  if (grads_nc_tweaks) then
5511 
5512 ! ---- Time offset
5513 
5514  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
5515  call check( nf90_def_var(ncid, 't_add_offset', &
5516  nf90_float, nc1d, ncv), &
5517  thisroutine )
5518  buffer = 'a'
5519  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
5520  thisroutine )
5521  buffer = 'time_add_offset'
5522  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
5523  thisroutine )
5524  buffer = 'Time offset'
5525  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
5526  thisroutine )
5527 
5528  time_add_offset_val = min(time_val, 0.0_dp)
5529 
5530  end if
5531 
5532 ! ---- Ice core number
5533 
5534  call check( nf90_inq_dimid(ncid, 'n', nc1d), thisroutine )
5535  call check( nf90_def_var(ncid, 'n', nf90_float, nc1d, ncv), &
5536  thisroutine )
5537  buffer = '1'
5538  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
5539  thisroutine )
5540  buffer = 'ice_core_number'
5541  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
5542  thisroutine )
5543  buffer = 'Ice core number'
5544  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
5545  thisroutine )
5546  buffer = trim(ch_core(1))
5547  do n=2, n_core; buffer = trim(buffer)//', '//trim(ch_core(n)); end do
5548  call check( nf90_put_att(ncid, ncv, 'ice_core_names', trim(buffer)), &
5549  thisroutine )
5550  call check( nf90_put_att(ncid, ncv, 'axis', 'n'), thisroutine )
5551 
5552  if (forcing_flag == 1) then
5553 
5554 ! ---- delta_ts
5555 
5556  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
5557  call check( nf90_def_var(ncid, 'delta_ts', nf90_float, nc1d, ncv), &
5558  thisroutine )
5559  buffer = 'degC'
5560  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
5561  thisroutine )
5562  buffer = 'surface_temperature_anomaly'
5563  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
5564  thisroutine )
5565  buffer = 'Surface temperature anomaly'
5566  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
5567  thisroutine )
5568 
5569  else if ((forcing_flag == 2).or.(forcing_flag == 3)) then
5570 
5571 ! ---- glac_index
5572 
5573  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
5574  call check( nf90_def_var(ncid, 'glac_index', nf90_float, nc1d, ncv), &
5575  thisroutine )
5576  buffer = '1'
5577  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
5578  thisroutine )
5579  buffer = 'glacial_index'
5580  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
5581  thisroutine )
5582  buffer = 'Glacial index'
5583  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
5584  thisroutine )
5585 
5586  end if
5587 
5588 ! ---- z_sl
5589 
5590  call check( nf90_inq_dimid(ncid, 't', nc1d), thisroutine )
5591  call check( nf90_def_var(ncid, 'z_sl', nf90_float, nc1d, ncv), &
5592  thisroutine )
5593  buffer = 'm'
5594  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
5595  thisroutine )
5596  buffer = 'global_average_sea_level_change'
5597  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
5598  thisroutine )
5599  buffer = 'Sea level'
5600  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
5601  thisroutine )
5602 
5603 ! ---- H_core
5604 
5605  call check( nf90_inq_dimid(ncid, 'n', nc2d(1)), thisroutine )
5606  call check( nf90_inq_dimid(ncid, 't', nc2d(2)), thisroutine )
5607  call check( nf90_def_var(ncid, 'H_core', nf90_float, nc2d, ncv), &
5608  thisroutine )
5609  buffer = 'm'
5610  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
5611  thisroutine )
5612  buffer = 'land_ice_thickness'
5613  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
5614  thisroutine )
5615  buffer = 'Ice thickness'
5616  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
5617  thisroutine )
5618 
5619 ! ---- vh_b_core
5620 
5621  call check( nf90_inq_dimid(ncid, 'n', nc2d(1)), thisroutine )
5622  call check( nf90_inq_dimid(ncid, 't', nc2d(2)), thisroutine )
5623  call check( nf90_def_var(ncid, 'vh_b_core', nf90_float, nc2d, ncv), &
5624  thisroutine )
5625  buffer = 'm a-1'
5626  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
5627  thisroutine )
5628  buffer = 'land_ice_basal_horizontal_velocity'
5629  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
5630  thisroutine )
5631  buffer = 'Horizontal velocity at the ice base'
5632  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
5633  thisroutine )
5634 
5635 ! ---- vh_s_core
5636 
5637  call check( nf90_inq_dimid(ncid, 'n', nc2d(1)), thisroutine )
5638  call check( nf90_inq_dimid(ncid, 't', nc2d(2)), thisroutine )
5639  call check( nf90_def_var(ncid, 'vh_s_core', nf90_float, nc2d, ncv), &
5640  thisroutine )
5641  buffer = 'm a-1'
5642  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
5643  thisroutine )
5644  buffer = 'land_ice_surface_horizontal_velocity'
5645  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
5646  thisroutine )
5647  buffer = 'Horizontal velocity at the ice surface'
5648  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
5649  thisroutine )
5650 
5651 ! ---- temp_b_core
5652 
5653  call check( nf90_inq_dimid(ncid, 'n', nc2d(1)), thisroutine )
5654  call check( nf90_inq_dimid(ncid, 't', nc2d(2)), thisroutine )
5655  call check( nf90_def_var(ncid, 'temp_b_core', nf90_float, nc2d, ncv), &
5656  thisroutine )
5657  buffer = 'degC'
5658  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
5659  thisroutine )
5660  buffer = 'basal_temperature'
5661  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
5662  thisroutine )
5663  buffer = 'Temperature at the ice base'
5664  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
5665  thisroutine )
5666 
5667 ! ---- R_b_core
5668 
5669  call check( nf90_inq_dimid(ncid, 'n', nc2d(1)), thisroutine )
5670  call check( nf90_inq_dimid(ncid, 't', nc2d(2)), thisroutine )
5671  call check( nf90_def_var(ncid, 'R_b_core', nf90_float, nc2d, ncv), &
5672  thisroutine )
5673  buffer = 'W m-2'
5674  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
5675  thisroutine )
5676  buffer = 'basal_frictional_heating'
5677  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
5678  thisroutine )
5679  buffer = 'Basal frictional heating'
5680  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
5681  thisroutine )
5682 
5683 ! ---- bmb_core
5684 
5685  call check( nf90_inq_dimid(ncid, 'n', nc2d(1)), thisroutine )
5686  call check( nf90_inq_dimid(ncid, 't', nc2d(2)), thisroutine )
5687  call check( nf90_def_var(ncid, 'bmb_core', nf90_float, nc2d, ncv), &
5688  thisroutine )
5689  buffer = 'm ice equiv. a-1'
5690  call check( nf90_put_att(ncid, ncv, 'units', trim(buffer)), &
5691  thisroutine )
5692  buffer = 'land_ice_basal_mass_balance'
5693  call check( nf90_put_att(ncid, ncv, 'standard_name', trim(buffer)), &
5694  thisroutine )
5695  buffer = 'Basal mass balance'
5696  call check( nf90_put_att(ncid, ncv, 'long_name', trim(buffer)), &
5697  thisroutine )
5698 
5699 ! ---- End of the definitions
5700 
5701  call check( nf90_enddef(ncid), thisroutine )
5702 
5703  end if
5704 
5705 ! ------ Writing of data on NetCDF file
5706 
5707  if (firstcall.and.grads_nc_tweaks) then
5708 
5709  nc1cor = (/ 1 /)
5710 
5711  call check( nf90_inq_varid(ncid, 'x', ncv), thisroutine )
5712  call check( nf90_put_var(ncid, ncv, 0.0_sp, start=nc1cor), thisroutine )
5713 
5714  call check( nf90_inq_varid(ncid, 'y', ncv), thisroutine )
5715  call check( nf90_put_var(ncid, ncv, 0.0_sp, start=nc1cor), thisroutine )
5716 
5717  call check( nf90_sync(ncid), thisroutine )
5718 
5719  end if
5720 
5721  if (firstcall) then
5722 
5723  nc1cor = (/ 1 /)
5724 
5725  call check( nf90_inq_varid(ncid, 'n', ncv), thisroutine )
5726  call check( nf90_put_var(ncid, ncv, r_n_core, &
5727  start=nc1cor), thisroutine )
5728 
5729  end if
5730 
5731  nc1cor(1) = counter
5732  ! nc1cnt(1) = 1 ! (not needed, and causes troubles for whatever reason)
5733 
5734  nc2cor(1) = 1
5735  nc2cor(2) = counter
5736  nc2cnt(1) = n_core
5737  nc2cnt(2) = 1
5738 
5739  call check( nf90_inq_varid(ncid, 't', ncv), thisroutine )
5740 
5741  if (.not.grads_nc_tweaks) then
5742  call check( nf90_put_var(ncid, ncv, real(time_val,sp), &
5743  start=nc1cor), thisroutine )
5744  else
5745  call check( nf90_put_var(ncid, ncv, &
5746  real(time_val-time_add_offset_val,sp), &
5747  start=nc1cor), thisroutine )
5748  ! this makes sure that all times are >=0
5749  ! (GrADS doesn't like negative numbers)
5750  call check( nf90_inq_varid(ncid, 't_add_offset', ncv), thisroutine )
5751  call check( nf90_put_var(ncid, ncv, &
5752  real(time_add_offset_val,sp), &
5753  start=nc1cor), thisroutine )
5754  end if
5755 
5756  if (forcing_flag == 1) then
5757 
5758  call check( nf90_inq_varid(ncid, 'delta_ts', ncv), thisroutine )
5759  call check( nf90_put_var(ncid, ncv, real(delta_ts,sp), &
5760  start=nc1cor), thisroutine )
5761 
5762  else if (forcing_flag == 2) then
5763 
5764  call check( nf90_inq_varid(ncid, 'glac_index', ncv), thisroutine )
5765  call check( nf90_put_var(ncid, ncv, real(glac_index,sp), &
5766  start=nc1cor), thisroutine )
5767 
5768  else if (forcing_flag == 3) then
5769 
5770  call check( nf90_inq_varid(ncid, 'glac_index', ncv), thisroutine )
5771  call check( nf90_put_var(ncid, ncv, real(no_value_neg_2,sp), &
5772  start=nc1cor), thisroutine )
5773 
5774  end if
5775 
5776  call check( nf90_inq_varid(ncid, 'z_sl', ncv), thisroutine )
5777  call check( nf90_put_var(ncid, ncv, real(z_sl,sp), &
5778  start=nc1cor), thisroutine )
5779 
5780  call check( nf90_inq_varid(ncid, 'H_core', ncv), thisroutine )
5781  call check( nf90_put_var(ncid, ncv, real(H_core,sp), &
5782  start=nc2cor, count=nc2cnt), thisroutine )
5783 
5784  call check( nf90_inq_varid(ncid, 'vh_b_core', ncv), thisroutine )
5785  call check( nf90_put_var(ncid, ncv, real(vh_b_core,sp), &
5786  start=nc2cor, count=nc2cnt), thisroutine )
5787 
5788  call check( nf90_inq_varid(ncid, 'vh_s_core', ncv), thisroutine )
5789  call check( nf90_put_var(ncid, ncv, real(vh_s_core,sp), &
5790  start=nc2cor, count=nc2cnt), thisroutine )
5791 
5792  call check( nf90_inq_varid(ncid, 'temp_b_core', ncv), thisroutine )
5793  call check( nf90_put_var(ncid, ncv, real(temp_b_core,sp), &
5794  start=nc2cor, count=nc2cnt), thisroutine )
5795 
5796  call check( nf90_inq_varid(ncid, 'R_b_core', ncv), thisroutine )
5797  call check( nf90_put_var(ncid, ncv, real(R_b_core,sp), &
5798  start=nc2cor, count=nc2cnt), thisroutine )
5799 
5800  call check( nf90_inq_varid(ncid, 'bmb_core', ncv), thisroutine )
5801  call check( nf90_put_var(ncid, ncv, real(bmb_core,sp), &
5802  start=nc2cor, count=nc2cnt), thisroutine )
5803 
5804 ! ------ Syncing NetCDF file (every 100th time)
5805 
5806  n_sync = 100
5807 
5808  if ( mod((counter-1), n_sync) == 0 ) &
5809  call check( nf90_sync(ncid), thisroutine )
5810 
5811 #endif
5812 
5813  deallocate(r_n_core, h_core, &
5814  vx_b_core, vy_b_core, vh_b_core, &
5815  vx_s_core, vy_s_core, vh_s_core, &
5816  temp_b_core, &
5817  rx_b_core, ry_b_core, r_b_core, &
5818  bmb_core)
5819 
5820 !!! else ! (n_core == 0 -> do nothing)
5821 !!!
5822 !!! continue
5823 
5824 end if
5825 
5826 if (firstcall) firstcall = .false.
5827 
5828 end subroutine output4
5829 
5830 #if (defined(ASF))
5831 
5832 !-------------------------------------------------------------------------------
5833 !> Writing of time-series data for all defined surface points on file
5834 !! in ASCII format. Modification of Tolly's output7 by Thorben Dunse.
5835 !<------------------------------------------------------------------------------
5836 subroutine output5(time, dxi, deta, delta_ts, glac_index, z_sl)
5837 
5838 implicit none
5839 
5840 real(dp), intent(in) :: time, dxi, deta, delta_ts, glac_index, z_sl
5841 
5842 integer(i4b) :: n, k
5843 real(dp) :: time_v