SICOPOLIS V3.0
 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-2013 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 
41 implicit none
42 
43 real(dp), intent (in) :: time, delta_ts, glac_index, z_sl
44 character (len=100), intent (in) :: runname
45 logical, intent (in) :: flag_3d_output
46 
47 integer(i4b), intent (inout) :: ndat2d, ndat3d
48 
49 integer(i4b) :: i, j, kc, kt, kr
50 integer(i4b) :: ndat, ndat_help, ndat_1000s, ndat_100s, ndat_10s, ndat_1s
51 real(dp) :: v_tot, a_grounded, a_floating
52 real(sp) :: time_conv, delta_ts_conv, glac_index_conv, z_sl_conv, &
53  v_tot_conv, a_grounded_conv, a_floating_conv, &
54  h_r_conv, xi_conv(0:imax), eta_conv(0:jmax), &
55  sigma_level_c_conv(0:kcmax), sigma_level_t_conv(0:ktmax), &
56  sigma_level_r_conv(0:krmax), &
57  lambda_conv(0:jmax,0:imax), phi_conv(0:jmax,0:imax), &
58  temp_s_conv(0:jmax,0:imax), as_perp_conv(0:jmax,0:imax), &
59  zs_conv(0:jmax,0:imax), zm_conv(0:jmax,0:imax), &
60  zb_conv(0:jmax,0:imax), zl_conv(0:jmax,0:imax), &
61  h_c_conv(0:jmax,0:imax), h_t_conv(0:jmax,0:imax), &
62  h_conv(0:jmax,0:imax), &
63  q_bm_conv(0:jmax,0:imax), q_tld_conv(0:jmax,0:imax), &
64  am_perp_conv(0:jmax,0:imax), &
65  qx_conv(0:jmax,0:imax), qy_conv(0:jmax,0:imax), &
66  temp_r_conv(0:krmax,0:jmax,0:imax), &
67  vx_c_conv(0:kcmax,0:jmax,0:imax), &
68  vy_c_conv(0:kcmax,0:jmax,0:imax), &
69  vz_c_conv(0:kcmax,0:jmax,0:imax), &
70  vx_t_conv(0:ktmax,0:jmax,0:imax), &
71  vy_t_conv(0:ktmax,0:jmax,0:imax), &
72  vz_t_conv(0:ktmax,0:jmax,0:imax), &
73  temp_c_conv(0:kcmax,0:jmax,0:imax), &
74  age_c_conv(0:kcmax,0:jmax,0:imax), &
75  omega_t_conv(0:ktmax,0:jmax,0:imax), &
76  age_t_conv(0:ktmax,0:jmax,0:imax), &
77  dzs_dtau_conv(0:jmax,0:imax), dzm_dtau_conv(0:jmax,0:imax), &
78  dzb_dtau_conv(0:jmax,0:imax), dzl_dtau_conv(0:jmax,0:imax), &
79  dh_c_dtau_conv(0:jmax,0:imax), dh_t_dtau_conv(0:jmax,0:imax), &
80  dh_dtau_conv(0:jmax,0:imax), &
81  vx_b_g_conv(0:jmax,0:imax), vy_b_g_conv(0:jmax,0:imax), &
82  vz_b_conv(0:jmax,0:imax), &
83  vx_s_g_conv(0:jmax,0:imax), vy_s_g_conv(0:jmax,0:imax), &
84  vz_s_conv(0:jmax,0:imax), &
85  temp_b_conv(0:jmax,0:imax), temph_b_conv(0:jmax,0:imax), &
86  p_b_w_conv(0:jmax,0:imax), h_w_conv(0:jmax,0:imax), &
87  q_gl_g_conv(0:jmax,0:imax)
88 character (len=256) :: filename
89 character :: ch_1000s, ch_100s, ch_10s, ch_1s
90 
91 integer(i4b) :: ios
92 character (len= 16) :: ch_date, ch_time, ch_zone
93 character (len=256) :: ch_attr_title, ch_attr_institution, ch_attr_source, &
94  ch_attr_history, ch_attr_references
95 
96 !-------- Create consecutively numbered file names --------
97 
98 if (flag_3d_output) then
99  ndat = ndat3d
100 else
101  ndat = ndat2d
102 end if
103 
104 if (ndat > 9999) stop ' output1: Too many time-slice files!'
105 
106 ndat_help = ndat
107 ndat_1000s = ndat_help/1000
108 ndat_help = ndat_help-ndat_1000s*1000
109 ndat_100s = ndat_help/100
110 ndat_help = ndat_help-ndat_100s*100
111 ndat_10s = ndat_help/10
112 ndat_help = ndat_help-ndat_10s*10
113 ndat_1s = ndat_help
114 
115 ch_1000s = char(ndat_1000s+ichar('0'))
116 ch_100s = char(ndat_100s +ichar('0'))
117 ch_10s = char(ndat_10s +ichar('0'))
118 ch_1s = char(ndat_1s +ichar('0'))
119 
120 if (flag_3d_output) then
121  filename = trim(runname)//ch_1000s//ch_100s//ch_10s//ch_1s//'.erg'
122 else
123  filename = trim(runname)//'_2d_'//ch_1000s//ch_100s//ch_10s//ch_1s//'.erg'
124 end if
125 
126 !-------- Open time-slice file runname.erg --------
127 
128 open(11, iostat=ios, &
129  file=outpath//'/'//trim(filename), &
130  status='new', form='unformatted')
131 if (ios /= 0) stop ' output1: Error when opening an erg file!'
132 
133 !-------- Write attributes on file --------
134 
135 ch_attr_title = 'Time-slice output no. '//ch_1000s//ch_100s//ch_10s//ch_1s// &
136  'of simulation '//trim(runname)
137 write(11) ch_attr_title
138 
139 ch_attr_institution = 'Institute of Low Temperature Science, '// &
140  'Hokkaido University, Sapporo, Japan'
141 write(11) ch_attr_institution
142 
143 ch_attr_source = 'SICOPOLIS Version '//version
144 write(11) ch_attr_source
145 
146 call date_and_time(ch_date, ch_time, ch_zone)
147 ch_attr_history = ch_date(1:4)//'-'//ch_date(5:6)//'-'//ch_date(7:8)//' '// &
148  ch_time(1:2)//':'//ch_time(3:4)//':'//ch_time(5:6)//' '// &
149  ch_zone(1:3)//':'//ch_zone(4:5)//' - Data produced'
150 write(11) ch_attr_history
151 
152 ch_attr_references = 'http://sicopolis.greveweb.net/'
153 write(11) ch_attr_references
154 
155 !-------- Computation of the ice volume,
156 ! the area covered by grounded ice
157 ! and the area covered by floating ice --------
158 
159 v_tot = 0.0_dp
160 a_grounded = 0.0_dp
161 a_floating = 0.0_dp
162 
163 do i=0, imax
164 do j=0, jmax
165 
166  if ( (maske(j,i)==0).or.(maske(j,i)==3) ) & ! grounded or floating ice
167  v_tot = v_tot + (h_c(j,i)+h_t(j,i))*area(j,i)
168 
169  if (maske(j,i)==0) & ! grounded ice
170  a_grounded = a_grounded + area(j,i)
171 
172  if (maske(j,i)==3) & ! floating ice
173  a_floating = a_floating + area(j,i)
174 
175 end do
176 end do
177 
178 !-------- Convert data to real*4 --------
179 
180 #if ( !defined(OUT_TIMES) || OUT_TIMES==1 )
181 time_conv = real(time,sp)
182 #elif OUT_TIMES == 2
183 time_conv = real((time+year_zero),sp)
184 #else
185 stop ' output1: OUT_TIMES must be either 1 or 2!'
186 #endif
187 
188 delta_ts_conv = real(delta_ts,sp)
189 glac_index_conv = real(glac_index,sp)
190 z_sl_conv = real(z_sl,sp)
191 v_tot_conv = real(v_tot,sp)
192 a_grounded_conv = real(a_grounded,sp)
193 a_floating_conv = real(a_floating,sp)
194 h_r_conv = real(h_r,sp)
195 
196 do i=0, imax
197  xi_conv(i) = real(xi(i),sp)
198 end do
199 
200 do j=0, jmax
201  eta_conv(j) = real(eta(j),sp)
202 end do
203 
204 do kc=0, kcmax
205  sigma_level_c_conv(kc) = real(eaz_c_quotient(kc),sp)
206 end do
207 
208 do kt=0, ktmax
209  sigma_level_t_conv(kt) = real(zeta_t(kt),sp)
210 end do
211 
212 do kr=0, krmax
213  sigma_level_r_conv(kr) = real(kr,sp)/real(krmax,sp)
214 end do
215 
216 do i=0, imax
217 do j=0, jmax
218 
219  lambda_conv(j,i) = real(lambda(j,i),sp)
220  phi_conv(j,i) = real(phi(j,i),sp)
221  temp_s_conv(j,i) = real(temp_s(j,i),sp)
222  as_perp_conv(j,i) = real(as_perp(j,i),sp)
223  zs_conv(j,i) = real(zs(j,i),sp)
224  zm_conv(j,i) = real(zm(j,i),sp)
225  zb_conv(j,i) = real(zb(j,i),sp)
226  zl_conv(j,i) = real(zl(j,i),sp)
227  h_c_conv(j,i) = real(H_c(j,i),sp)
228  h_t_conv(j,i) = real(H_t(j,i),sp)
229  h_conv(j,i) = real(H_c(j,i)+H_t(j,i),sp)
230  q_bm_conv(j,i) = real(Q_bm(j,i),sp)
231  q_tld_conv(j,i) = real(Q_tld(j,i),sp)
232  am_perp_conv(j,i) = real(am_perp(j,i),sp)
233  qx_conv(j,i) = real(qx(j,i),sp)
234  qy_conv(j,i) = real(qy(j,i),sp)
235  dzs_dtau_conv(j,i) = real(dzs_dtau(j,i),sp)
236  dzm_dtau_conv(j,i) = real(dzm_dtau(j,i),sp)
237  dzb_dtau_conv(j,i) = real(dzb_dtau(j,i),sp)
238  dzl_dtau_conv(j,i) = real(dzl_dtau(j,i),sp)
239  dh_c_dtau_conv(j,i) = real(dH_c_dtau(j,i),sp)
240  dh_t_dtau_conv(j,i) = real(dH_t_dtau(j,i),sp)
241  dh_dtau_conv(j,i) = real(dH_c_dtau(j,i)+dH_t_dtau(j,i),sp)
242  vx_b_g_conv(j,i) = real(vx_b_g(j,i),sp)
243  vy_b_g_conv(j,i) = real(vy_b_g(j,i),sp)
244  vz_b_conv(j,i) = real(vz_b(j,i),sp)
245  vx_s_g_conv(j,i) = real(vx_s_g(j,i),sp)
246  vy_s_g_conv(j,i) = real(vy_s_g(j,i),sp)
247  vz_s_conv(j,i) = real(vz_s(j,i),sp)
248  temp_b_conv(j,i) = real(temp_b(j,i),sp)
249  temph_b_conv(j,i) = real(temph_b(j,i),sp)
250  p_b_w_conv(j,i) = real(p_b_w(j,i),sp)
251  h_w_conv(j,i) = real(H_w(j,i),sp)
252  q_gl_g_conv(j,i) = real(q_gl_g(j,i),sp)
253 
254  do kr=0, krmax
255  temp_r_conv(kr,j,i) = real(temp_r(kr,j,i),sp)
256  end do
257 
258  do kt=0, ktmax
259  vx_t_conv(kt,j,i) = real(vx_t(kt,j,i),sp)
260  vy_t_conv(kt,j,i) = real(vy_t(kt,j,i),sp)
261  vz_t_conv(kt,j,i) = real(vz_t(kt,j,i),sp)
262  omega_t_conv(kt,j,i) = real(omega_t(kt,j,i),sp)
263  age_t_conv(kt,j,i) = real(age_t(kt,j,i),sp)
264  end do
265 
266  do kc=0, kcmax
267  vx_c_conv(kc,j,i) = real(vx_c(kc,j,i),sp)
268  vy_c_conv(kc,j,i) = real(vy_c(kc,j,i),sp)
269  vz_c_conv(kc,j,i) = real(vz_c(kc,j,i),sp)
270  temp_c_conv(kc,j,i) = real(temp_c(kc,j,i),sp)
271  age_c_conv(kc,j,i) = real(age_c(kc,j,i),sp)
272  end do
273 
274 end do
275 end do
276 
277 !-------- Write data on file --------
278 
279 write(11) time_conv
280 if (forcing_flag == 1) then
281  write(11) delta_ts_conv
282 else if (forcing_flag == 2) then
283  write(11) glac_index_conv
284 else if (forcing_flag == 3) then
285  glac_index_conv = 1.11e+11 ! dummy value
286  write(11) glac_index_conv
287 end if
288 write(11) z_sl_conv
289 write(11) xi_conv
290 write(11) eta_conv
291 write(11) sigma_level_c_conv
292 write(11) sigma_level_t_conv
293 write(11) sigma_level_r_conv
294 write(11) lambda_conv
295 write(11) phi_conv
296 write(11) temp_s_conv
297 write(11) as_perp_conv
298 write(11) maske
299 write(11) n_cts
300 write(11) zs_conv
301 write(11) zm_conv
302 write(11) zb_conv
303 write(11) zl_conv
304 write(11) h_c_conv
305 write(11) h_t_conv
306 write(11) h_conv
307 write(11) h_r_conv
308 if (flag_3d_output) then
309  write(11) vx_c_conv
310  write(11) vy_c_conv
311  write(11) vz_c_conv
312  write(11) vx_t_conv
313  write(11) vy_t_conv
314  write(11) vz_t_conv
315  write(11) temp_c_conv
316  write(11) omega_t_conv
317  write(11) temp_r_conv
318 end if
319 write(11) q_bm_conv
320 write(11) q_tld_conv
321 write(11) am_perp_conv
322 write(11) qx_conv
323 write(11) qy_conv
324 if (flag_3d_output) then
325  write(11) age_c_conv
326  write(11) age_t_conv
327 end if
328 write(11) dzs_dtau_conv
329 write(11) dzm_dtau_conv
330 write(11) dzb_dtau_conv
331 write(11) dzl_dtau_conv
332 write(11) dh_c_dtau_conv
333 write(11) dh_t_dtau_conv
334 write(11) dh_dtau_conv
335 write(11) vx_b_g_conv
336 write(11) vy_b_g_conv
337 write(11) vz_b_conv
338 write(11) vx_s_g_conv
339 write(11) vy_s_g_conv
340 write(11) vz_s_conv
341 write(11) temp_b_conv
342 write(11) temph_b_conv
343 write(11) p_b_w_conv
344 write(11) h_w_conv
345 write(11) q_gl_g_conv
346 write(11) v_tot_conv
347 write(11) a_grounded_conv
348 write(11) a_floating_conv
349 
350 close(11, status='keep')
351 
352 !-------- Increase file counter --------
353 
354 ndat = ndat+1
355 
356 if (flag_3d_output) then
357  ndat3d = ndat
358 else
359  ndat2d = ndat
360 end if
361 
362 end subroutine output1
363 !