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