37 module procedure monitor_in_3d
38 end interface monitor_in
43 end interface monitor_put
53 private :: monitor_writeheader
59 integer :: MONITOR_FID = -1
61 character(len=H_LONG) :: MONITOR_OUT_BASENAME =
'monitor'
62 logical :: MONITOR_USEDEVIATION = .true.
63 integer :: MONITOR_STEP_INTERVAL = 1
64 logical :: MONITOR_GLOBAL_SUM = .true.
66 real(DP) :: MONITOR_dt
68 integer,
parameter :: MONITOR_req_max = 1000
69 integer :: MONITOR_nreqs = 0
70 character(len=H_SHORT) :: MONITOR_reqs(MONITOR_req_max)
73 character(len=H_SHORT) :: name
74 character(len=H_MID) :: desc
75 character(len=H_SHORT) :: unit
82 integer :: MONITOR_nitems = 0
83 type(item),
allocatable :: MONITOR_items(:)
86 character(len=H_SHORT) :: name
91 real(RP),
allocatable :: area(:,:)
92 real(RP) :: total_area
93 real(RP),
allocatable :: volume(:,:,:)
94 real(RP) :: total_volume
96 integer,
parameter :: MONITOR_dim_max = 30
97 integer :: MONITOR_ndims = 0
98 type(dim_type) :: MONITOR_dims(MONITOR_dim_max)
109 real(dp),
intent(in) :: dt
111 namelist / param_monitor / &
112 monitor_out_basename, &
113 monitor_usedeviation, &
114 monitor_global_sum, &
115 monitor_step_interval
117 character(len=H_SHORT) :: name
119 namelist / monitor_item / &
127 log_info(
"MONITOR_setup",*)
'Setup'
133 log_info(
'MONITOR_setup',*)
'Not found namelist. Default used.'
134 elseif( ierr > 0 )
then
135 log_error(
'MONITOR_setup',*)
'Not appropriate names in namelist PARAM_MONITOR. Check!'
138 log_nml(param_monitor)
142 do n = 1, monitor_req_max
146 monitor_nreqs = n - 1
148 if ( monitor_nreqs > monitor_req_max )
then
149 log_error(
'MONITOR_setup',*)
'request of monitor file is exceed! n >', monitor_req_max
151 elseif( monitor_nreqs == 0 )
then
152 log_info(
'MONITOR_setup',*)
'No monitor file specified.'
155 log_info(
'MONITOR_setup',*)
'Number of requested monitor item : ', monitor_nreqs
156 log_info(
'MONITOR_setup',*)
'Monitor output interval [step] : ', monitor_step_interval
157 log_info(
'MONITOR_setup',*)
'Use deviation from first step? : ', monitor_usedeviation
160 allocate( monitor_items(monitor_nreqs) )
163 do n = 1, monitor_nreqs
171 log_nml(monitor_item)
174 monitor_reqs(n) = name
186 KA, KS, KE, IA, IS, IE, JA, JS, JE, &
187 dim_type, dim_size, &
189 volume, total_volume )
190 integer,
intent(in) :: ka, ks, ke
191 integer,
intent(in) :: ia, is, ie
192 integer,
intent(in) :: ja, js, je
194 character(len=*),
intent(in) :: dim_type
195 integer,
intent(in) :: dim_size
196 real(
rp),
intent(in),
optional :: area(ia,ja)
197 real(
rp),
intent(in),
optional :: total_area
198 real(
rp),
intent(in),
optional :: volume(ka,ia,ja)
199 real(
rp),
intent(in),
optional :: total_volume
203 monitor_ndims = monitor_ndims + 1
206 monitor_dims(n)%name = dim_type
207 monitor_dims(n)%dim_size = dim_size
209 monitor_dims(n)%KA = ka
210 monitor_dims(n)%KS = ks
211 monitor_dims(n)%KE = ke
212 monitor_dims(n)%IA = ia
213 monitor_dims(n)%IS = is
214 monitor_dims(n)%IE = ie
215 monitor_dims(n)%JA = ja
216 monitor_dims(n)%JS = js
217 monitor_dims(n)%JE = je
219 if ( dim_size >= 2 )
then
220 allocate( monitor_dims(n)%area(ia,ja) )
221 monitor_dims(n)%area(:,:) = area(:,:)
223 monitor_dims(n)%total_area = total_area
226 if ( dim_size >= 3 )
then
227 allocate( monitor_dims(n)%volume(ka,ia,ja) )
228 monitor_dims(n)%volume(:,:,:) = volume(:,:,:)
230 monitor_dims(n)%total_volume = total_volume
247 character(len=*),
intent(in) :: name
248 character(len=*),
intent(in) :: desc
249 character(len=*),
intent(in) :: unit
251 integer,
intent(out) :: itemid
253 integer,
intent(in),
optional :: ndims
254 character(len=*),
intent(in),
optional :: dim_type
255 logical,
intent(in),
optional :: is_tendency
257 integer :: n, reqid, dimid
261 do itemid = 1, monitor_nitems
262 if ( name == monitor_items(itemid)%name )
return
265 do reqid = 1, monitor_nreqs
266 if ( name == monitor_reqs(reqid) )
then
270 monitor_nitems = monitor_nitems + 1
271 itemid = monitor_nitems
274 monitor_items(itemid)%name = name
275 monitor_items(itemid)%desc = desc
276 monitor_items(itemid)%unit = unit
279 if (
present(dim_type) )
then
280 do n = 1, monitor_ndims
281 if ( monitor_dims(n)%name == dim_type )
then
286 if ( dimid < 0 )
then
287 log_error(
'MONITOR_reg',*)
'dim_type (', trim(dim_type),
') must be registerd by MONITOR_set_dim'
290 else if (
present(ndims) )
then
291 do n = 1, monitor_ndims
292 if ( monitor_dims(n)%dim_size == ndims )
then
297 if ( dimid == -1 )
then
298 log_error(
'MONITOR_reg',
'(a,i1,a)')
'dim_type of ', ndims,
'D must be registerd with MONITOR_set_dim'
303 do n = 1, monitor_ndims
304 if ( monitor_dims(n)%dim_size == 3 )
then
309 if ( dimid == -1 )
then
310 log_error(
'MONITOR_reg',*)
'dim_type or ndims must be specified'
315 monitor_items(itemid)%dimid = dimid
317 monitor_items(itemid)%var = 0.0_dp
318 monitor_items(itemid)%var0 = 0.0_dp
319 monitor_items(itemid)%first = .true.
320 if (
present(is_tendency) )
then
321 monitor_items(itemid)%tendency = is_tendency
323 monitor_items(itemid)%tendency = .false.
327 log_info(
'MONOTOR_reg',
'(A,I3)')
' Item registration No.= ', itemid
328 log_info_cont(*)
'Name : ', trim(monitor_items(itemid)%name)
329 log_info_cont(*)
'Description : ', trim(monitor_items(itemid)%desc)
330 log_info_cont(*)
'Unit : ', trim(monitor_items(itemid)%unit)
331 log_info_cont(*)
'Dimension type : ', trim(monitor_dims(monitor_items(itemid)%dimid)%name)
332 log_info_cont(*)
'Integ. with dt? : ', monitor_items(itemid)%tendency
352 integer,
intent(in) :: itemid
353 real(RP),
intent(in) :: var(:,:)
359 if( itemid <= 0 )
return
363 dimid = monitor_items(itemid)%dimid
365 call statistics_total( monitor_dims(dimid)%IA, monitor_dims(dimid)%IS, monitor_dims(dimid)%IE, &
366 monitor_dims(dimid)%JA, monitor_dims(dimid)%JS, monitor_dims(dimid)%JE, &
367 var(:,:), monitor_items(itemid)%name, &
368 monitor_dims(dimid)%area(:,:), monitor_dims(dimid)%total_area, &
369 log_suppress = .true., global = monitor_global_sum, &
372 if ( monitor_items(itemid)%tendency )
then
373 if ( monitor_items(itemid)%first )
then
374 monitor_items(itemid)%var = 0.0_rp
375 monitor_items(itemid)%first = .false.
377 monitor_items(itemid)%var = monitor_items(itemid)%var + total * monitor_dt
380 if ( monitor_usedeviation )
then
381 if ( monitor_items(itemid)%first )
then
382 monitor_items(itemid)%var = 0.0_rp
383 monitor_items(itemid)%var0 = total
384 monitor_items(itemid)%first = .false.
386 monitor_items(itemid)%var = total - monitor_items(itemid)%var0
389 monitor_items(itemid)%var = total
406 integer,
intent(in) :: itemid
407 real(RP),
intent(in) :: var(:,:,:)
414 if( itemid <= 0 )
return
418 dimid = monitor_items(itemid)%dimid
421 call statistics_total( monitor_dims(dimid)%KA, monitor_dims(dimid)%KS, monitor_dims(dimid)%KE, &
422 monitor_dims(dimid)%IA, monitor_dims(dimid)%IS, monitor_dims(dimid)%IE, &
423 monitor_dims(dimid)%JA, monitor_dims(dimid)%JS, monitor_dims(dimid)%JE, &
424 var(:,:,:), monitor_items(itemid)%name, &
425 monitor_dims(dimid)%volume(:,:,:), monitor_dims(dimid)%total_volume, &
426 log_suppress = .true., global = monitor_global_sum, &
429 if ( monitor_items(itemid)%tendency )
then
430 if ( monitor_items(itemid)%first )
then
431 monitor_items(itemid)%var = total * monitor_dt
432 monitor_items(itemid)%first = .false.
434 monitor_items(itemid)%var = monitor_items(itemid)%var + total * monitor_dt
437 if ( monitor_usedeviation )
then
438 if ( monitor_items(itemid)%first )
then
439 monitor_items(itemid)%var = 0.0_rp
440 monitor_items(itemid)%var0 = total
441 monitor_items(itemid)%first = .false.
443 monitor_items(itemid)%var = total - monitor_items(itemid)%var0
446 monitor_items(itemid)%var = total
464 real(RP),
intent(in) :: var(:,:)
465 character(len=*),
intent(in) :: name
466 character(len=*),
intent(in) :: desc
467 character(len=*),
intent(in) :: unit
469 integer,
intent(in),
optional :: ndims
470 character(len=*),
intent(in),
optional :: dim_type
471 logical,
intent(in),
optional :: is_tendency
478 ndims=ndims, dim_type=dim_type, &
479 is_tendency=is_tendency )
480 call monitor_put( itemid, var(:,:) )
487 subroutine monitor_in_3d( &
494 real(RP),
intent(in) :: var(:,:,:)
495 character(len=*),
intent(in) :: name
496 character(len=*),
intent(in) :: desc
497 character(len=*),
intent(in) :: unit
499 integer,
intent(in),
optional :: ndims
500 character(len=*),
intent(in),
optional :: dim_type
501 logical,
intent(in),
optional :: is_tendency
508 ndims=ndims, dim_type=dim_type, &
509 is_tendency=is_tendency )
510 call monitor_put( itemid, var(:,:,:) )
513 end subroutine monitor_in_3d
519 character(len=*),
intent(in) :: memo
520 integer ,
intent(in) :: nowstep
522 logical,
save :: firsttime = .true.
527 if( monitor_nitems == 0 )
return
533 call monitor_writeheader
536 if ( monitor_fid > 0 )
then
538 if ( mod(nowstep-1,monitor_step_interval) == 0 )
then
539 log_progress(*)
'output monitor'
541 write(monitor_fid,
'(A,i7,A,A4,A)',advance=
'no')
'STEP=',nowstep,
' (',memo,
')'
542 do n = 1, monitor_nitems
543 write(monitor_fid,
'(A,ES15.8)',advance=
'no')
' ', monitor_items(n)%var
557 subroutine monitor_writeheader
564 character(len=H_LONG) :: fname
572 log_info(
'MONITOR_writeheader',*)
'Output item list '
573 log_info_cont(*)
'Number of monitor item :', monitor_nreqs
574 log_info_cont(
'(1x,2A)')
'NAME :description ', &
575 ':UNIT :dimension_type'
576 log_info_cont(
'(1x,2A)')
'=======================================================================', &
577 '==============================='
578 do n = 1, monitor_nitems
579 log_info_cont(
'(1x,A24,A48,A16,A16)') monitor_items(n)%name, monitor_items(n)%desc, monitor_items(n)%unit, monitor_dims(monitor_items(n)%dimid)%name
581 log_info_cont(
'(1x,2A)')
'=======================================================================', &
582 '==============================='
590 if ( monitor_l )
then
594 if ( monitor_global_sum )
then
599 open( unit = monitor_fid, &
600 file = trim(fname), &
601 form =
'formatted', &
603 if ( ierr /= 0 )
then
604 log_error(
'MONITOR_writeheader',*)
'File open error! :', trim(fname)
609 log_info(
'MONITOR_writeheader',*)
'Open ASCII file for monitor, name : ', trim(fname)
611 write(monitor_fid,
'(A)',advance=
'no')
' '
612 do n = 1, monitor_nitems
613 write(monitor_fid,
'(A16)',advance=
'no') monitor_items(n)%name
620 end subroutine monitor_writeheader
629 character(len=H_LONG) :: fname
634 if ( monitor_fid > 0 )
then
636 log_info(
'MONITOR_finalize',*)
'Close monitor file'
641 do n = 1, monitor_ndims
642 if ( monitor_dims(n)%dim_size >= 2 )
then
644 deallocate( monitor_dims(n)%area )
646 if ( monitor_dims(n)%dim_size >= 3 )
then
648 deallocate( monitor_dims(n)%volume )
653 if (
allocated(monitor_items) )
deallocate( monitor_items )