SICOPOLIS V3.2
 All Classes Files Functions Variables Macros
output1.F90
Go to the documentation of this file.
1 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 !
3 ! Subroutine : o u t p u t 1
4 !
5 !> @file
6 !!
7 !! Writing of time-slice files in binary format.
8 !!
9 !! @section Copyright
10 !!
11 !! Copyright 2009-2016 Ralf Greve
12 !!
13 !! @section License
14 !!
15 !! This file is part of SICOPOLIS.
16 !!
17 !! SICOPOLIS is free software: you can redistribute it and/or modify
18 !! it under the terms of the GNU General Public License as published by
19 !! the Free Software Foundation, either version 3 of the License, or
20 !! (at your option) any later version.
21 !!
22 !! SICOPOLIS is distributed in the hope that it will be useful,
23 !! but WITHOUT ANY WARRANTY; without even the implied warranty of
24 !! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 !! GNU General Public License for more details.
26 !!
27 !! You should have received a copy of the GNU General Public License
28 !! along with SICOPOLIS. If not, see <http://www.gnu.org/licenses/>.
29 !<
30 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31 
32 !-------------------------------------------------------------------------------
33 !> Writing of time-slice files in binary format.
34 !<------------------------------------------------------------------------------
35 subroutine output1(runname, time, delta_ts, glac_index, z_sl, &
36  flag_3d_output, ndat2d, ndat3d)
37 
38 use sico_types
40 use sico_vars
41 
42 #if (CALCMOD==1 || CALCMOD==0 || CALCMOD==-1)
44 #endif
45 
46 implicit none
47 
48 real(dp), intent(in) :: time, delta_ts, glac_index, z_sl
49 character(len=100), intent(in) :: runname
50 logical, intent(in) :: flag_3d_output
51 
52 integer(i4b), intent(inout) :: ndat2d, ndat3d
53 
54 integer(i4b) :: i, j, kc, kt, kr
55 integer(i4b) :: ndat, ndat_help, ndat_1000s, ndat_100s, ndat_10s, ndat_1s
56 real(dp), dimension(0:JMAX,0:IMAX) :: h, h_cold, h_temp, dh_dtau
57 real(dp) :: v_tot, a_grounded, a_floating
58 character(len=256) :: filename
59 character :: ch_1000s, ch_100s, ch_10s, ch_1s
60 
61 integer(i2b), dimension(0:IMAX,0:JMAX) :: maske_conv, n_cts_conv, kc_cts_conv
62 real(sp) :: time_conv, delta_ts_conv, glac_index_conv, z_sl_conv, &
63  v_tot_conv, a_grounded_conv, a_floating_conv, &
64  h_r_conv, &
65  xi_conv(0:imax), eta_conv(0:jmax), &
66  sigma_level_c_conv(0:kcmax), sigma_level_t_conv(0:ktmax), &
67  sigma_level_r_conv(0:krmax)
68 real(sp), dimension(0:IMAX,0:JMAX) :: lambda_conv, phi_conv, &
69  lon_conv, lat_conv, &
70  temp_s_conv, as_perp_conv, &
71  zs_conv, zm_conv, zb_conv, zl_conv, &
72  h_cold_conv, h_temp_conv, h_conv, &
73  q_bm_conv, q_tld_conv, &
74  am_perp_conv, &
75  qx_conv, qy_conv, &
76  dzs_dtau_conv, dzm_dtau_conv, dzb_dtau_conv, dzl_dtau_conv, &
77  dh_c_dtau_conv, dh_t_dtau_conv, dh_dtau_conv, &
78  vx_b_g_conv, vy_b_g_conv, vz_b_conv, vh_b_conv, &
79  vx_s_g_conv, vy_s_g_conv, vz_s_conv, vh_s_conv, &
80  temp_b_conv, temph_b_conv, &
81  p_b_w_conv, h_w_conv, q_gl_g_conv
82 real(sp), dimension(0:IMAX,0:JMAX,0:KCMAX) :: vx_c_conv, vy_c_conv, vz_c_conv, &
83  temp_c_conv, age_c_conv, &
84  enth_c_conv, omega_c_conv, &
85  enh_c_conv
86 real(sp), dimension(0:IMAX,0:JMAX,0:KTMAX) :: vx_t_conv, vy_t_conv, vz_t_conv, &
87  omega_t_conv, age_t_conv, &
88  enth_t_conv, &
89  enh_t_conv
90 real(sp), dimension(0:IMAX,0:JMAX,0:KRMAX) :: temp_r_conv
91 
92 integer(i4b) :: ios
93 character(len= 16) :: ch_date, ch_time, ch_zone
94 character(len=256) :: ch_attr_title, ch_attr_institution, ch_attr_source, &
95  ch_attr_history, ch_attr_references
96 
97 !-------- Create consecutively numbered file names --------
98 
99 if (flag_3d_output) then
100  ndat = ndat3d
101 else
102  ndat = ndat2d
103 end if
104 
105 if (ndat > 9999) stop ' output1: Too many time-slice files!'
106 
107 ndat_help = ndat
108 ndat_1000s = ndat_help/1000
109 ndat_help = ndat_help-ndat_1000s*1000
110 ndat_100s = ndat_help/100
111 ndat_help = ndat_help-ndat_100s*100
112 ndat_10s = ndat_help/10
113 ndat_help = ndat_help-ndat_10s*10
114 ndat_1s = ndat_help
115 
116 ch_1000s = char(ndat_1000s+ichar('0'))
117 ch_100s = char(ndat_100s +ichar('0'))
118 ch_10s = char(ndat_10s +ichar('0'))
119 ch_1s = char(ndat_1s +ichar('0'))
120 
121 if (flag_3d_output) then
122  filename = trim(runname)//ch_1000s//ch_100s//ch_10s//ch_1s//'.erg'
123 else
124  filename = trim(runname)//'_2d_'//ch_1000s//ch_100s//ch_10s//ch_1s//'.erg'
125 end if
126 
127 !-------- Open time-slice file runname.erg --------
128 
129 open(unit=11, iostat=ios, &
130  file=outpath//'/'//trim(filename), &
131  status='new', form='unformatted')
132 if (ios /= 0) stop ' output1: Error when opening an erg file!'
133 
134 !-------- Write attributes on file --------
135 
136 ch_attr_title = 'Time-slice output no. '//ch_1000s//ch_100s//ch_10s//ch_1s// &
137  'of simulation '//trim(runname)
138 write(unit=11) ch_attr_title
139 
140 ch_attr_institution = 'Institute of Low Temperature Science, '// &
141  'Hokkaido University, Sapporo, Japan'
142 write(unit=11) ch_attr_institution
143 
144 ch_attr_source = 'SICOPOLIS Version '//version
145 write(unit=11) ch_attr_source
146 
147 call date_and_time(ch_date, ch_time, ch_zone)
148 ch_attr_history = ch_date(1:4)//'-'//ch_date(5:6)//'-'//ch_date(7:8)//' '// &
149  ch_time(1:2)//':'//ch_time(3:4)//':'//ch_time(5:6)//' '// &
150  ch_zone(1:3)//':'//ch_zone(4:5)//' - Data produced'
151 write(unit=11) ch_attr_history
152 
153 ch_attr_references = 'http://www.sicopolis.net/'
154 write(unit=11) ch_attr_references
155 
156 !-------- Ice thickness and time derivative --------
157 
158 h = h_c + h_t
159 dh_dtau = dh_c_dtau + dh_t_dtau
160 
161 !-------- Thickness of the cold and temperate layers --------
162 
163 h_cold = 0.0_dp
164 h_temp = 0.0_dp
165 
166 #if (CALCMOD==1)
167 do i=1, imax-1
168 do j=1, jmax-1
169  h_temp(j,i) = h_t(j,i)
170 end do
171 end do
172 #elif (CALCMOD==0 || CALCMOD==2 || CALCMOD==3 || CALCMOD==-1)
173 do i=1, imax-1
174 do j=1, jmax-1
175  h_temp(j,i) = h_c(j,i)*eaz_c_quotient(kc_cts(j,i))
176 end do
177 end do
178 #endif
179 
180 h_cold = h - h_temp
181 
182 !-------- Enthalpies for the non-enthalpy methods (POLY, COLD, ISOT) --------
183 
184 #if (CALCMOD==1)
185 
186 do i=0, imax
187 do j=0, jmax
188 
189  do kc=0, kcmax
190  enth_c(kc,j,i) = enth_fct_temp_omega(temp_c(kc,j,i), 0.0_dp)
191  end do
192 
193  if ( (maske(j,i) == 0_i2b).and.(n_cts(j,i) == 1_i2b) ) then
194  do kt=0, ktmax
195  enth_t(kt,j,i) = enth_fct_temp_omega(temp_t_m(kt,j,i), omega_t(kt,j,i))
196  end do
197  else
198  do kt=0, ktmax
199  enth_t(kt,j,i) = enth_c(0,j,i)
200  end do
201  end if
202 
203 end do
204 end do
205 
206 #elif (CALCMOD==0 || CALCMOD==-1)
207 
208 do i=0, imax
209 do j=0, jmax
210 
211  do kc=0, kcmax
212  enth_c(kc,j,i) = enth_fct_temp_omega(temp_c(kc,j,i), 0.0_dp)
213  end do
214 
215  do kt=0, ktmax
216  enth_t(kt,j,i) = enth_c(0,j,i)
217  end do
218 
219 end do
220 end do
221 
222 #endif
223 
224 !-------- Computation of the ice volume,
225 ! the area covered by grounded ice
226 ! and the area covered by floating ice --------
227 
228 v_tot = 0.0_dp
229 a_grounded = 0.0_dp
230 a_floating = 0.0_dp
231 
232 do i=0, imax
233 do j=0, jmax
234 
235  if ( (maske(j,i)==0).or.(maske(j,i)==3) ) & ! grounded or floating ice
236  v_tot = v_tot + h(j,i)*area(j,i)
237 
238  if (maske(j,i)==0) & ! grounded ice
239  a_grounded = a_grounded + area(j,i)
240 
241  if (maske(j,i)==3) & ! floating ice
242  a_floating = a_floating + area(j,i)
243 
244 end do
245 end do
246 
247 !-------- Convert data to real*4 and seconds to years --------
248 
249 #if (!defined(OUT_TIMES) || OUT_TIMES==1)
250 time_conv = real(time/year_sec,sp)
251 #elif (OUT_TIMES==2)
252 time_conv = real((time+year_zero)/year_sec,sp)
253 #else
254 stop ' output1: OUT_TIMES must be either 1 or 2!'
255 #endif
256 
257 delta_ts_conv = real(delta_ts,sp)
258 glac_index_conv = real(glac_index,sp)
259 z_sl_conv = real(z_sl,sp)
260 v_tot_conv = real(v_tot,sp)
261 a_grounded_conv = real(a_grounded,sp)
262 a_floating_conv = real(a_floating,sp)
263 h_r_conv = real(h_r,sp)
264 
265 do i=0, imax
266  xi_conv(i) = real(xi(i),sp)
267 end do
268 
269 do j=0, jmax
270  eta_conv(j) = real(eta(j),sp)
271 end do
272 
273 do kc=0, kcmax
274  sigma_level_c_conv(kc) = real(eaz_c_quotient(kc),sp)
275 end do
276 
277 do kt=0, ktmax
278  sigma_level_t_conv(kt) = real(zeta_t(kt),sp)
279 end do
280 
281 do kr=0, krmax
282  sigma_level_r_conv(kr) = real(kr,sp)/real(krmax,sp)
283 end do
284 
285 do i=0, imax
286 do j=0, jmax
287 
288  maske_conv(i,j) = maske(j,i)
289  n_cts_conv(i,j) = n_cts(j,i)
290  kc_cts_conv(i,j) = kc_cts(j,i)
291 
292  lambda_conv(i,j) = real(lambda(j,i),sp)
293  phi_conv(i,j) = real(phi(j,i),sp)
294  lon_conv(i,j) = real(lambda(j,i)*pi_180_inv,sp) ! longitude in deg
295  lon_conv(i,j) = modulo(lon_conv(i,j)+180.0_sp, 360.0_sp)-180.0_sp
296  ! mapping to interval [-180 deg, +180 deg)
297  lat_conv(i,j) = real(phi(j,i) *pi_180_inv,sp) ! latitute in deg
298  if (lat_conv(i,j) > 90.0_sp) lat_conv(i,j) = 90.0_sp
299  if (lat_conv(i,j) < -90.0_sp) lat_conv(i,j) = -90.0_sp
300  ! constraining to interval [-90 deg, +90 deg]
301  temp_s_conv(i,j) = real(temp_s(j,i),sp)
302  as_perp_conv(i,j) = real(as_perp(j,i)*year_sec,sp)
303  zs_conv(i,j) = real(zs(j,i),sp)
304  zm_conv(i,j) = real(zm(j,i),sp)
305  zb_conv(i,j) = real(zb(j,i),sp)
306  zl_conv(i,j) = real(zl(j,i),sp)
307  h_cold_conv(i,j) = real(H_cold(j,i),sp)
308  h_temp_conv(i,j) = real(H_temp(j,i),sp)
309  h_conv(i,j) = real(H(j,i),sp)
310  q_bm_conv(i,j) = real(q_bm(j,i)*year_sec,sp)
311  q_tld_conv(i,j) = real(q_tld(j,i)*year_sec,sp)
312  am_perp_conv(i,j) = real(am_perp(j,i)*year_sec,sp)
313  qx_conv(i,j) = real(qx(j,i)*year_sec,sp)
314  qy_conv(i,j) = real(qy(j,i)*year_sec,sp)
315  dzs_dtau_conv(i,j) = real(dzs_dtau(j,i)*year_sec,sp)
316  dzm_dtau_conv(i,j) = real(dzm_dtau(j,i)*year_sec,sp)
317  dzb_dtau_conv(i,j) = real(dzb_dtau(j,i)*year_sec,sp)
318  dzl_dtau_conv(i,j) = real(dzl_dtau(j,i)*year_sec,sp)
319  dh_c_dtau_conv(i,j) = real(dh_c_dtau(j,i)*year_sec,sp)
320  dh_t_dtau_conv(i,j) = real(dh_t_dtau(j,i)*year_sec,sp)
321  dh_dtau_conv(i,j) = real(dh_dtau(j,i)*year_sec,sp)
322  vx_b_g_conv(i,j) = real(vx_b_g(j,i)*year_sec,sp)
323  vy_b_g_conv(i,j) = real(vy_b_g(j,i)*year_sec,sp)
324  vz_b_conv(i,j) = real(vz_b(j,i)*year_sec,sp)
325  vh_b_conv(i,j) = sqrt( vx_b_g_conv(i,j)**2 + vy_b_g_conv(i,j)**2 )
326  vx_s_g_conv(i,j) = real(vx_s_g(j,i)*year_sec,sp)
327  vy_s_g_conv(i,j) = real(vy_s_g(j,i)*year_sec,sp)
328  vz_s_conv(i,j) = real(vz_s(j,i)*year_sec,sp)
329  vh_s_conv(i,j) = sqrt( vx_s_g_conv(i,j)**2 + vy_s_g_conv(i,j)**2 )
330  temp_b_conv(i,j) = real(temp_b(j,i),sp)
331  temph_b_conv(i,j) = real(temph_b(j,i),sp)
332  p_b_w_conv(i,j) = real(p_b_w(j,i),sp)
333  h_w_conv(i,j) = real(H_w(j,i),sp)
334  q_gl_g_conv(i,j) = real(q_gl_g(j,i)*year_sec,sp)
335 
336  do kr=0, krmax
337  temp_r_conv(i,j,kr) = real(temp_r(kr,j,i),sp)
338  end do
339 
340  do kt=0, ktmax
341  vx_t_conv(i,j,kt) = real(vx_t(kt,j,i)*year_sec,sp)
342  vy_t_conv(i,j,kt) = real(vy_t(kt,j,i)*year_sec,sp)
343  vz_t_conv(i,j,kt) = real(vz_t(kt,j,i)*year_sec,sp)
344  omega_t_conv(i,j,kt) = real(omega_t(kt,j,i),sp)
345  age_t_conv(i,j,kt) = real(age_t(kt,j,i)/year_sec,sp)
346  enth_t_conv(i,j,kt) = real(enth_t(kt,j,i),sp)
347  enh_t_conv(i,j,kt) = real(enh_t(kt,j,i),sp)
348  end do
349 
350  do kc=0, kcmax
351  vx_c_conv(i,j,kc) = real(vx_c(kc,j,i)*year_sec,sp)
352  vy_c_conv(i,j,kc) = real(vy_c(kc,j,i)*year_sec,sp)
353  vz_c_conv(i,j,kc) = real(vz_c(kc,j,i)*year_sec,sp)
354  temp_c_conv(i,j,kc) = real(temp_c(kc,j,i),sp)
355  age_c_conv(i,j,kc) = real(age_c(kc,j,i)/year_sec,sp)
356  enth_c_conv(i,j,kc) = real(enth_c(kc,j,i),sp)
357  omega_c_conv(i,j,kc) = real(omega_c(kc,j,i),sp)
358  enh_c_conv(i,j,kc) = real(enh_c(kc,j,i),sp)
359  end do
360 
361 end do
362 end do
363 
364 !-------- Write data on file --------
365 
366 write(unit=11) time_conv
367 if (forcing_flag == 1) then
368  write(unit=11) delta_ts_conv
369 else if (forcing_flag == 2) then
370  write(unit=11) glac_index_conv
371 else if (forcing_flag == 3) then
372  glac_index_conv = 1.11e+11 ! dummy value
373  write(unit=11) glac_index_conv
374 end if
375 write(unit=11) z_sl_conv
376 write(unit=11) xi_conv
377 write(unit=11) eta_conv
378 write(unit=11) sigma_level_c_conv
379 write(unit=11) sigma_level_t_conv
380 write(unit=11) sigma_level_r_conv
381 write(unit=11) lon_conv
382 write(unit=11) lat_conv
383 write(unit=11) lambda_conv
384 write(unit=11) phi_conv
385 write(unit=11) temp_s_conv
386 write(unit=11) as_perp_conv
387 write(unit=11) maske_conv
388 write(unit=11) n_cts_conv
389 write(unit=11) kc_cts_conv
390 write(unit=11) zs_conv
391 write(unit=11) zm_conv
392 write(unit=11) zb_conv
393 write(unit=11) zl_conv
394 write(unit=11) h_cold_conv
395 write(unit=11) h_temp_conv
396 write(unit=11) h_conv
397 write(unit=11) h_r_conv
398 if (flag_3d_output) then
399  write(unit=11) vx_c_conv
400  write(unit=11) vy_c_conv
401  write(unit=11) vz_c_conv
402  write(unit=11) vx_t_conv
403  write(unit=11) vy_t_conv
404  write(unit=11) vz_t_conv
405  write(unit=11) temp_c_conv
406  write(unit=11) omega_t_conv
407  write(unit=11) temp_r_conv
408  write(unit=11) enth_c_conv
409  write(unit=11) enth_t_conv
410  write(unit=11) omega_c_conv
411  write(unit=11) enh_c_conv
412  write(unit=11) enh_t_conv
413 end if
414 write(unit=11) q_bm_conv
415 write(unit=11) q_tld_conv
416 write(unit=11) am_perp_conv
417 write(unit=11) qx_conv
418 write(unit=11) qy_conv
419 if (flag_3d_output) then
420  write(unit=11) age_c_conv
421  write(unit=11) age_t_conv
422 end if
423 write(unit=11) dzs_dtau_conv
424 write(unit=11) dzm_dtau_conv
425 write(unit=11) dzb_dtau_conv
426 write(unit=11) dzl_dtau_conv
427 write(unit=11) dh_c_dtau_conv
428 write(unit=11) dh_t_dtau_conv
429 write(unit=11) dh_dtau_conv
430 write(unit=11) vx_b_g_conv
431 write(unit=11) vy_b_g_conv
432 write(unit=11) vz_b_conv
433 write(unit=11) vh_b_conv
434 write(unit=11) vx_s_g_conv
435 write(unit=11) vy_s_g_conv
436 write(unit=11) vz_s_conv
437 write(unit=11) vh_s_conv
438 write(unit=11) temp_b_conv
439 write(unit=11) temph_b_conv
440 write(unit=11) p_b_w_conv
441 write(unit=11) h_w_conv
442 write(unit=11) q_gl_g_conv
443 write(unit=11) v_tot_conv
444 write(unit=11) a_grounded_conv
445 write(unit=11) a_floating_conv
446 
447 close(unit=11, status='keep')
448 
449 !-------- Increase file counter --------
450 
451 ndat = ndat+1
452 
453 if (flag_3d_output) then
454  ndat3d = ndat
455 else
456  ndat2d = ndat
457 end if
458 
459 end subroutine output1
460 !
Declarations of kind types for SICOPOLIS.
Definition: sico_types.F90:35
Declarations of global variables for SICOPOLIS (for the ANT domain).
Definition: sico_vars.F90:35
Declarations of global variables for SICOPOLIS.
Conversion from temperature (temp) and water content (omega) to enthalpy (enth) and vice versa...
subroutine output1(runname, time, delta_ts, glac_index, z_sl, flag_3d_output, ndat2d, ndat3d)
Writing of time-slice files in binary format.
Definition: output1.F90:35
real(dp) function, public enth_fct_temp_omega(temp_val, omega_val)
Enthalpy as a function of temperature and water content.