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