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