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