33 public :: file_history_query
35 public :: file_history_put
37 public :: file_history_in
40 public :: file_history_set_associatedcoordinate
41 public :: file_history_set_attribute
46 interface file_history_query
47 module procedure file_history_query_name
48 module procedure file_history_query_id
49 end interface file_history_query
51 interface file_history_put
52 module procedure file_history_put_0d
53 module procedure file_history_put_1d
54 module procedure file_history_put_2d
55 module procedure file_history_put_3d
56 module procedure file_history_put_4d
57 end interface file_history_put
59 interface file_history_in
65 end interface file_history_in
68 subroutine truncate_1d( src, dim_type, zcoord, fill_halo, dsc )
70 real(RP),
intent(in) :: src(:)
71 character(len=*),
intent(in) :: dim_type
72 character(len=*),
intent(in) :: zcoord
73 logical,
intent(in) :: fill_halo
74 real(DP),
intent(out) :: dsc(:)
75 end subroutine truncate_1d
80 subroutine truncate_2d( src, dim_type, zcoord, fill_halo, dsc )
82 real(
rp),
intent(in) :: src(:,:)
83 character(len=*),
intent(in) :: dim_type
84 character(len=*),
intent(in) :: zcoord
85 logical,
intent(in) :: fill_halo
86 real(
dp),
intent(out) :: dsc(:)
87 end subroutine truncate_2d
92 subroutine truncate_3d( src, dim_type, zcoord, fill_halo, dsc )
94 real(
rp),
intent(in) :: src(:,:,:)
95 character(len=*),
intent(in) :: dim_type
96 character(len=*),
intent(in) :: zcoord
97 logical,
intent(in) :: fill_halo
98 real(
dp),
intent(out) :: dsc(:)
99 end subroutine truncate_3d
104 subroutine truncate_4d( src, dim_type, zcoord, fill_halo, dsc )
106 real(
rp),
intent(in) :: src(:,:,:,:)
107 character(len=*),
intent(in) :: dim_type
108 character(len=*),
intent(in) :: zcoord
109 logical,
intent(in) :: fill_halo
110 real(
dp),
intent(out) :: dsc(:)
111 end subroutine truncate_4d
117 interface file_history_set_associatedcoordinate
121 end interface file_history_set_associatedcoordinate
123 interface file_history_set_attribute
129 module procedure file_history_set_attribute_float_ary
131 module procedure file_history_set_attribute_double_ary
132 end interface file_history_set_attribute
148 private :: file_history_create
149 private :: file_history_close
150 private :: file_history_add_variable
151 private :: file_history_write_axes
152 private :: file_history_write_onevar
153 private :: file_history_output_list
154 private :: file_history_check
161 integer,
parameter :: i_none = 0, i_mean = 1, i_min = 2, i_max = 3
162 character(len=4),
parameter :: op_name(0:3) = (/
"none",
"mean",
"min ",
"max "/)
164 character(len=H_SHORT) :: name
165 character(len=H_SHORT) :: outname
166 character(len=H_LONG) :: basename
167 logical :: postfix_timelabel
168 character(len=H_SHORT) :: zcoord
172 character(len=H_SHORT) :: cell_measures
173 logical :: registered
177 character(len=H_SHORT) :: name
178 character(len=H_SHORT) :: outname
179 character(len=H_LONG) :: basename
180 logical :: postfix_timelabel
181 character(len=H_SHORT) :: zcoord
189 character(len=H_LONG) :: desc
190 character(len=H_SHORT) :: units
191 character(len=H_SHORT) :: standard_name
193 character(len=H_SHORT) :: cell_measures
195 integer :: laststep_write
196 integer :: laststep_put
197 logical :: flag_clear
200 real(
dp),
allocatable :: varsum(:)
204 integer,
parameter :: file_history_variant_max = 10
206 character(len=H_SHORT) :: name
208 integer :: variants(file_history_variant_max)
212 character(len=H_SHORT) :: name
215 character(len=H_SHORT),
allocatable :: dims(:,:)
216 integer ,
allocatable :: start(:,:)
217 integer ,
allocatable :: count(:,:)
218 integer ,
allocatable :: size(:)
219 character(len=H_SHORT),
allocatable :: zcoords(:)
220 character(len=H_SHORT) :: mapping
221 character(len=H_SHORT) :: area
222 character(len=H_SHORT) :: area_x
223 character(len=H_SHORT) :: area_y
224 character(len=H_SHORT) :: volume
225 character(len=H_SHORT) :: location
226 character(len=H_SHORT) :: grid
230 character(len=H_SHORT) :: name
231 character(len=H_LONG) :: desc
232 character(len=H_SHORT) :: units
233 character(len=H_SHORT) :: dim
235 real(
dp),
allocatable :: var(:)
236 real(
dp),
allocatable :: bounds(:,:)
243 character(len=H_SHORT) :: name
244 character(len=H_LONG) :: desc
245 character(len=H_SHORT) :: units
247 character(len=H_SHORT) :: dims(4)
249 real(
dp),
allocatable :: var(:)
254 integer,
parameter :: i_text = 1, i_int = 2, i_float = 3, i_double = 4
256 character(len=H_SHORT) :: varname
257 character(len=H_MID) :: key
259 character(len=H_LONG) :: text
260 integer,
allocatable :: int(:)
261 real(
sp),
allocatable ::
float(:)
263 logical :: add_variable
267 integer :: file_history_myrank
270 real(
dp) :: file_history_startdaysec
271 real(
dp) :: file_history_dtsec
272 character(len=H_MID) :: file_history_time_since
275 character(len=H_MID) :: file_history_title
276 character(len=H_MID) :: file_history_source
277 character(len=H_MID) :: file_history_institution
279 character(len=H_MID) :: file_history_time_units
280 character(len=H_SHORT) :: file_history_calendar
281 logical :: file_history_output_step0 = .false.
282 integer :: file_history_output_wait_step
283 integer :: file_history_output_switch_step
284 integer :: file_history_output_switch_laststep
285 logical :: file_history_error_putmiss = .true.
288 integer,
parameter :: file_history_req_max = 1000
289 integer :: file_history_nreqs = 0
290 type(request),
allocatable :: file_history_req(:)
292 integer :: file_history_nitems = 0
293 type(var_out),
allocatable :: file_history_vars(:)
295 integer :: file_history_nvar_inputs
296 type(var_in),
allocatable :: file_history_var_inputs(:)
298 integer,
parameter :: file_history_dim_max = 30
299 integer :: file_history_ndims = 0
300 type(dim) :: file_history_dims(file_history_dim_max)
302 integer,
parameter :: file_history_axis_max = 100
303 integer :: file_history_naxes = 0
304 type(axis) :: file_history_axes(file_history_axis_max)
306 integer,
parameter :: file_history_assoc_max = 40
307 integer :: file_history_nassocs = 0
308 type(assoc) :: file_history_assocs(file_history_assoc_max)
310 integer,
parameter :: file_history_attr_max = 200
311 integer :: file_history_nattrs = 0
312 type(attr) :: file_history_attrs(file_history_attr_max)
314 integer :: file_history_nowdate(6)
315 real(
dp) :: file_history_nowsubsec
316 integer :: file_history_nowstep
318 character(len=H_MID) :: file_history_options =
''
321 logical :: file_history_disabled = .true.
323 integer :: laststep_write = -1
324 logical :: list_outputed = .false.
325 logical :: debug = .false.
333 title, source, institution, &
334 time_start, time_interval, &
335 time_units, time_since, calendar, &
337 default_postfix_timelabel, &
354 character(len=*),
intent(in) :: title
355 character(len=*),
intent(in) :: source
356 character(len=*),
intent(in) :: institution
357 real(
dp),
intent(in) :: time_start
358 real(
dp),
intent(in) :: time_interval
360 character(len=*),
intent(in),
optional :: time_units
361 character(len=*),
intent(in),
optional :: time_since
362 character(len=*),
intent(in),
optional :: calendar
363 character(len=*),
intent(in),
optional :: default_basename
364 logical,
intent(in),
optional :: default_postfix_timelabel
365 character(len=*),
intent(in),
optional :: default_zcoord
366 real(
dp),
intent(in),
optional :: default_tinterval
367 character(len=*),
intent(in),
optional :: default_tunit
368 logical,
intent(in),
optional :: default_taverage
369 character(len=*),
intent(in),
optional :: default_tstats_op
370 character(len=*),
intent(in),
optional :: default_datatype
371 integer,
intent(in),
optional :: myrank
373 character(len=H_LONG) :: file_history_default_basename
374 logical :: file_history_default_postfix_timelabel
375 character(len=H_SHORT) :: file_history_default_zcoord
376 real(
dp) :: file_history_default_tinterval
377 character(len=H_SHORT) :: file_history_default_tunit
378 logical :: file_history_default_taverage
379 character(len=4) :: file_history_default_tstats_op
380 character(len=5) :: file_history_default_datatype
383 real(
dp) :: file_history_output_wait
384 character(len=H_SHORT) :: file_history_output_wait_tunit
385 real(
dp) :: file_history_output_switch_tinterval
386 character(len=H_SHORT) :: file_history_output_switch_tunit
388 namelist / param_file_history / &
389 file_history_title, &
390 file_history_source, &
391 file_history_institution, &
392 file_history_time_units, &
393 file_history_default_basename, &
394 file_history_default_postfix_timelabel, &
395 file_history_default_zcoord, &
396 file_history_default_tinterval, &
397 file_history_default_tunit, &
398 file_history_default_taverage, &
399 file_history_default_tstats_op, &
400 file_history_default_datatype, &
401 file_history_output_step0, &
402 file_history_output_wait, &
403 file_history_output_wait_tunit, &
404 file_history_output_switch_tinterval, &
405 file_history_output_switch_tunit, &
406 file_history_error_putmiss, &
408 file_history_options, &
411 character(len=H_SHORT) :: name
412 character(len=H_SHORT) :: outname
413 character(len=H_LONG) :: basename
414 logical :: postfix_timelabel
415 character(len=H_SHORT) :: zcoord
416 real(
dp) :: tinterval
417 character(len=H_SHORT) :: tunit
419 character(len=4) :: tstats_op
420 character(len=5) :: datatype
422 namelist / history_item / &
446 log_info(
"FILE_HISTORY_Setup",*)
'Setup'
449 if (
present(myrank) )
then
450 file_history_myrank = myrank
452 file_history_myrank = 0
455 file_history_startdaysec = time_start
456 file_history_dtsec = time_interval
457 if (
present(time_since) )
then
458 file_history_time_since = time_since
460 file_history_time_since =
''
463 if (
present(calendar) )
then
464 file_history_calendar = calendar
466 file_history_calendar =
""
469 file_history_time_units =
'seconds'
470 file_history_default_basename =
''
471 file_history_default_postfix_timelabel = .false.
472 file_history_default_zcoord =
''
473 file_history_default_tinterval = -1.0_dp
474 file_history_default_tunit =
'SEC'
475 file_history_default_taverage = .false.
476 file_history_default_tstats_op =
"none"
477 file_history_default_datatype =
'REAL4'
478 file_history_output_wait = 0.0_dp
479 file_history_output_wait_tunit =
'SEC'
480 file_history_output_switch_tinterval = -1.0_dp
481 file_history_output_switch_tunit =
'SEC'
486 file_history_title = title
487 file_history_source = source
488 file_history_institution = institution
489 if(
present(time_units) ) file_history_time_units = time_units
490 if(
present(default_basename) ) file_history_default_basename = default_basename
491 if(
present(default_postfix_timelabel) ) file_history_default_postfix_timelabel = default_postfix_timelabel
492 if(
present(default_zcoord) ) file_history_default_zcoord = default_zcoord
493 if(
present(default_tinterval) ) file_history_default_tinterval = default_tinterval
494 if(
present(default_tunit) ) file_history_default_tunit = default_tunit
495 if(
present(default_taverage) ) file_history_default_taverage = default_taverage
496 if(
present(default_tstats_op) ) file_history_default_tstats_op = default_tstats_op
497 if(
present(default_datatype) ) file_history_default_datatype = default_datatype
501 read(
io_fid_conf,nml=param_file_history,iostat=ierr)
503 log_info(
"FILE_HISTORY_Setup",*)
'Not found namelist. Default used.'
504 elseif( ierr > 0 )
then
505 log_error(
"FILE_HISTORY_Setup",*)
'Not appropriate names in namelist PARAM_FILE_HISTORY. Check!'
508 log_nml(param_file_history)
512 if ( file_history_output_wait >= 0.0_dp )
then
513 call calendar_unit2sec( dtsec, file_history_output_wait, file_history_output_wait_tunit )
514 file_history_output_wait_step = int( dtsec / file_history_dtsec )
516 log_error(
"FILE_HISTORY_Setup",*)
'FILE_HISTORY_OUTPUT_WAIT must be positive. STOP'
520 if ( file_history_output_switch_tinterval >= 0.0_dp )
then
521 call calendar_unit2sec( dtsec, file_history_output_switch_tinterval, file_history_output_switch_tunit )
522 file_history_output_switch_step = int( dtsec / file_history_dtsec )
524 file_history_output_switch_step = -1
526 file_history_output_switch_laststep = 0
530 file_history_nreqs = 0
532 do n = 1, file_history_req_max
534 outname =
'undefined'
535 basename = file_history_default_basename
539 if( basename ==
'' .OR. name ==
'' .OR. outname ==
'' ) cycle
541 file_history_nreqs = file_history_nreqs + 1
544 if ( file_history_nreqs > file_history_req_max )
then
545 log_error(
"FILE_HISTORY_Setup",*)
'request of history file is exceed! n >', file_history_req_max
547 elseif( file_history_nreqs == 0 )
then
548 log_info(
"FILE_HISTORY_Setup",*)
'No history file specified.'
552 allocate( file_history_req(file_history_nreqs) )
557 do n = 1, file_history_req_max
560 outname =
'undefined'
561 basename = file_history_default_basename
562 postfix_timelabel = file_history_default_postfix_timelabel
563 zcoord = file_history_default_zcoord
564 tinterval = file_history_default_tinterval
565 tunit = file_history_default_tunit
566 taverage = file_history_default_taverage
567 tstats_op = file_history_default_tstats_op
568 datatype = file_history_default_datatype
573 elseif( ierr > 0 )
then
574 log_error(
"FILE_HISTORY_Setup",*)
'Not appropriate names in namelist HISTORY_ITEM. Check!'
577 if( basename ==
'' .OR. name ==
'' .OR. outname ==
'' ) cycle
579 log_nml(history_item)
582 if ( outname ==
'undefined' ) outname = name
584 if ( file_history_req(id)%outname == outname )
then
585 log_error(
"FILE_HISTORY_Setup",*)
'Same name of history output is already registered. Check!', trim(outname)
592 file_history_req(reqid)%name = name
593 file_history_req(reqid)%outname = outname
594 file_history_req(reqid)%basename = basename
595 file_history_req(reqid)%postfix_timelabel = postfix_timelabel
596 if( file_history_output_switch_step >= 0 ) file_history_req(reqid)%postfix_timelabel = .true.
597 file_history_req(reqid)%zcoord = zcoord
598 select case ( tstats_op )
599 case (
"none",
"NONE",
"" )
600 file_history_req(reqid)%tstats_op = i_none
601 case (
"mean",
"MEAN",
"average",
"AVERAGE" )
602 file_history_req(reqid)%tstats_op = i_mean
603 case (
"min",
"MIN" )
604 file_history_req(reqid)%tstats_op = i_min
605 case (
"max",
"MAX" )
606 file_history_req(reqid)%tstats_op = i_max
608 log_error(
"FILE_HISTORY_Setup",*)
'TSTATS_OP is invalid (none, mean, min, or max) ,', trim(tstats_op)
612 log_warn(
"FILE_HISTORY_Setup",*)
'TAVERAGE is obsolete. Use TSTATS_OP instead'
613 if ( file_history_req(reqid)%tstats_op > 1 )
then
614 log_error(
"FILE_HISTORY_Setup",*)
'TSTATS_OP and TAVERAGE are conflicted'
617 file_history_req(reqid)%tstats_op = i_mean
621 dstep = int( dtsec / file_history_dtsec )
623 if ( dtsec <= 0.d0 )
then
624 log_error(
"FILE_HISTORY_Setup",*)
'Not appropriate time interval. Check!', trim(name), tinterval, trim(tunit)
628 if ( abs(dtsec-real(dstep,kind=
dp)*file_history_dtsec) > dtsec*1.e-3_dp )
then
629 log_error(
"FILE_HISTORY_Setup",*)
'time interval must be a multiple of delta t. (interval,dt)=', dtsec, file_history_dtsec
633 file_history_req(reqid)%dstep = dstep
635 if ( datatype ==
'REAL4' )
then
637 elseif( datatype ==
'REAL8' )
then
640 log_error(
"FILE_HISTORY_Setup",*)
'Not appropriate DATATYPE. Check!', datatype
644 file_history_req(reqid)%registered = .false.
648 log_info(
"FILE_HISTORY_Setup",*)
'Number of requested history item : ', file_history_nreqs
649 log_info(
"FILE_HISTORY_Setup",*)
'Output default data type : ', trim(file_history_default_datatype)
650 log_info(
"FILE_HISTORY_Setup",*)
'Output value at the initial step? : ', file_history_output_step0
651 if ( file_history_output_wait_step > 0 )
then
652 log_info(
"FILE_HISTORY_Setup",*)
'Time when the output is suppressed [step] : ', file_history_output_wait_step
654 if ( file_history_output_switch_step >= 0 )
then
655 log_info(
"FILE_HISTORY_Setup",*)
'Interval for switching the file [step] : ', file_history_output_switch_step
657 log_info(
"FILE_HISTORY_Setup",*)
'Check if requested item is not registered? : ', file_history_error_putmiss
659 file_history_nitems = 0
660 allocate( file_history_vars(file_history_nreqs) )
662 file_history_nvar_inputs = 0
663 allocate( file_history_var_inputs(file_history_nreqs) )
670 file_history_disabled = .false.
687 character(len=*),
intent(in) :: name
688 character(len=*),
intent(in) :: desc
689 character(len=*),
intent(in) :: unit
691 integer,
intent(out) :: itemid
693 character(len=*),
intent(in),
optional :: standard_name
694 integer,
intent(in),
optional :: ndims
695 character(len=*),
intent(in),
optional :: dim_type
696 character(len=*),
intent(in),
optional :: cell_measures
697 logical,
intent(in),
optional :: fill_halo
699 character(len=H_SHORT) :: standard_name_
700 character(len=H_SHORT) :: cell_measures_
701 integer :: dimid, iid
706 if ( file_history_nreqs == 0 )
return
708 itemid = file_history_find_id( name )
709 if ( itemid > 0 )
return
713 if ( len_trim(name) >=
h_short )
then
714 log_error(
"FILE_HISTORY_reg",
'(1x,A,I2,A,A)')
'Length of history name should be <= ',
h_short-1 ,
' chars. name=', trim(name)
719 if (
present(standard_name) )
then
720 standard_name_ = standard_name
726 if ( file_history_ndims < 1 )
then
727 log_error(
"FILE_HISTORY_reg",*)
'at least one dim_type must be registerd with FILE_HISTORY_set_dim. name=', trim(name)
731 if (
present(dim_type) )
then
732 do n = 1, file_history_ndims
733 if ( file_history_dims(n)%name == dim_type )
then
738 if ( dimid == -1 )
then
739 log_error(
"FILE_HISTORY_reg",*)
'dim_type must be registerd with FILE_HISTORY_set_dim: ', trim(dim_type) ,
' name=', trim(name)
742 else if (
present(ndims) )
then
743 do n = 1, file_history_ndims
744 if ( file_history_dims(n)%ndims == ndims )
then
749 if ( dimid == -1 )
then
750 log_error(
"FILE_HISTORY_reg",
'(a,i1,a)')
'dim_type of ', ndims,
'D must be registerd with FILE_HISTORY_set_dim. name=', trim(name)
755 do n = 1, file_history_ndims
756 if ( file_history_dims(n)%ndims == 3 )
then
761 if ( dimid == -1 )
then
762 log_error(
"FILE_HISTORY_reg",
'(a,i1,a)')
'dim_type or ndims must be specified. name=', trim(name)
767 if (
present(cell_measures) )
then
768 select case ( cell_measures )
770 if ( file_history_dims(dimid)%area ==
"" )
then
771 log_error(
"FILE_HISTORY_reg",*)
'area is not supported for cell_measures. name=', trim(name)
775 if ( file_history_dims(dimid)%area ==
"" )
then
776 log_error(
"FILE_HISTORY_reg",*)
'area_z is not supported for cell_measures. name=', trim(name)
780 if ( file_history_dims(dimid)%area_x ==
"" )
then
781 log_error(
"FILE_HISTORY_reg",*)
'area_x is not supported for cell_measures. name=', trim(name)
785 if ( file_history_dims(dimid)%area_y ==
"" )
then
786 log_error(
"FILE_HISTORY_reg",*)
'area_y is not supported for cell_measures. name=', trim(name)
790 if ( file_history_dims(dimid)%volume ==
"" )
then
791 log_error(
"FILE_HISTORY_reg",*)
'volume is not supported for cell_measures. name=', trim(name)
795 log_error(
"FILE_HISTORY_reg",*)
'cell_measures must be "area" or "volume". name=', trim(name)
798 cell_measures_ = cell_measures
799 else if ( file_history_dims(dimid)%ndims == 2 )
then
800 cell_measures_ =
"area"
801 else if ( file_history_dims(dimid)%ndims == 3 )
then
802 cell_measures_ =
"volume"
807 if ( file_history_dims(dimid)%nzcoords > 1 )
then
810 do n = 1, file_history_dims(dimid)%nzcoords
811 if ( file_history_dims(dimid)%zcoords(n) ==
"model" )
then
812 call file_history_add_variable( name, desc, unit, standard_name_, &
814 file_history_dims(dimid)%zcoords(n), &
816 cell_measures = cell_measures_, &
817 fill_halo = fill_halo )
819 call file_history_add_variable( name, desc, unit, standard_name_, &
821 file_history_dims(dimid)%zcoords(n), &
823 fill_halo = fill_halo )
825 if ( iid > 0 ) itemid = iid
830 call file_history_add_variable( name, desc, unit, standard_name_, &
834 cell_measures = cell_measures_, &
835 fill_halo = fill_halo )
846 subroutine file_history_put_0d( &
860 integer,
intent(in) :: itemid
861 real(
rp),
intent(in) :: var
864 real(
dp),
allocatable :: buffer(:)
874 if ( file_history_disabled )
return
875 if ( itemid < 0 )
return
877 call file_history_query( itemid, do_put )
878 if ( .not. do_put )
return
886 do i = 1, file_history_var_inputs(itemid)%nvariants
887 id = file_history_var_inputs(itemid)%variants(
i)
889 dt = ( file_history_nowstep - file_history_vars(id)%laststep_put ) * file_history_dtsec
891 if ( dt < eps .AND. file_history_vars(id)%tstats_op == 0 )
then
892 if ( file_history_var_inputs(itemid)%nvariants == 1 )
then
893 log_error(
"FILE_HISTORY_Put_0D",*)
'variable was put two times before output!: ', &
894 trim(file_history_vars(id)%name), file_history_nowstep, file_history_vars(id)%laststep_put
901 if ( file_history_vars(id)%flag_clear )
then
902 file_history_vars(id)%timesum = 0.0_dp
903 select case ( file_history_vars(id)%tstats_op )
906 file_history_vars(id)%varsum(:) = 0.0_dp
910 file_history_vars(id)%varsum(:) = huge
914 file_history_vars(id)%varsum(:) = - huge
919 dimid = file_history_vars(id)%dimid
921 if ( file_history_vars(id)%tstats_op > i_none )
then
922 if ( file_history_vars(id)%varsum(1) /= rmiss )
then
923 if ( var /= undef )
then
924 select case ( file_history_vars(id)%tstats_op )
926 file_history_vars(id)%varsum(1) = file_history_vars(id)%varsum(1) + var * dt
928 if ( var < file_history_vars(id)%varsum(1) ) file_history_vars(id)%varsum(1) = var
930 if ( var > file_history_vars(id)%varsum(1) ) file_history_vars(id)%varsum(1) = var
933 file_history_vars(id)%varsum(1) = rmiss
936 file_history_vars(id)%timesum = file_history_vars(id)%timesum + dt
938 file_history_vars(id)%varsum(1) = var
939 file_history_vars(id)%timesum = 0.0_dp
942 file_history_vars(id)%laststep_put = file_history_nowstep
943 file_history_vars(id)%flag_clear = .false.
950 end subroutine file_history_put_0d
962 real(RP),
intent(in) :: var
963 character(len=*),
intent(in) :: name
964 character(len=*),
intent(in) :: desc
965 character(len=*),
intent(in) :: unit
967 character(len=*),
intent(in),
optional :: standard_name
968 character(len=*),
intent(in),
optional :: dim_type
970 logical,
parameter :: fill_halo = .false.
972 integer,
parameter :: ndim = 0
977 if ( file_history_disabled )
return
982 standard_name=standard_name, &
985 fill_halo=fill_halo )
987 if ( itemid < 0 )
return
990 call file_history_query( itemid, do_put )
992 if ( do_put )
call file_history_put( itemid, var )
998 subroutine file_history_put_1d( &
1012 integer,
intent(in) :: itemid
1013 real(RP),
intent(in) :: var(:)
1016 real(DP),
allocatable :: buffer(:)
1026 if ( file_history_disabled )
return
1027 if ( itemid < 0 )
return
1029 call file_history_query( itemid, do_put )
1030 if ( .not. do_put )
return
1036 do i = 1, file_history_var_inputs(itemid)%nvariants
1037 id = file_history_var_inputs(itemid)%variants(i)
1039 dt = ( file_history_nowstep - file_history_vars(id)%laststep_put ) * file_history_dtsec
1041 if ( dt < eps .AND. file_history_vars(id)%tstats_op == 0 )
then
1042 if ( file_history_var_inputs(itemid)%nvariants == 1 )
then
1043 log_error(
"FILE_HISTORY_Put_1D",*)
'variable was put two times before output!: ', &
1044 trim(file_history_vars(id)%name), file_history_nowstep, file_history_vars(id)%laststep_put
1051 if ( file_history_vars(id)%flag_clear )
then
1052 file_history_vars(id)%timesum = 0.0_dp
1053 select case ( file_history_vars(id)%tstats_op )
1056 file_history_vars(id)%varsum(:) = 0.0_dp
1060 file_history_vars(id)%varsum(:) = huge
1064 file_history_vars(id)%varsum(:) = - huge
1069 dimid = file_history_vars(id)%dimid
1071 if ( file_history_vars(id)%tstats_op > i_none )
then
1072 allocate( buffer( file_history_vars(id)%size ) )
1074 file_history_dims(dimid)%name, &
1075 file_history_vars(id)%zcoord, &
1076 file_history_vars(id)%fill_halo, &
1078 select case ( file_history_vars(id)%tstats_op )
1081 do idx = 1, file_history_vars(id)%size
1082 if ( file_history_vars(id)%varsum(idx) /= rmiss )
then
1083 if ( buffer(idx) /= undef )
then
1084 file_history_vars(id)%varsum(idx) = file_history_vars(id)%varsum(idx) + buffer(idx) * dt
1086 file_history_vars(id)%varsum(idx) = rmiss
1092 do idx = 1, file_history_vars(id)%size
1093 if ( file_history_vars(id)%varsum(idx) /= rmiss )
then
1094 if ( buffer(idx) /= undef )
then
1095 if ( buffer(idx) < file_history_vars(id)%varsum(idx) ) file_history_vars(id)%varsum(idx) = buffer(idx)
1097 file_history_vars(id)%varsum(idx) = rmiss
1103 do idx = 1, file_history_vars(id)%size
1104 if ( file_history_vars(id)%varsum(idx) /= rmiss )
then
1105 if ( buffer(idx) /= undef )
then
1106 if ( buffer(idx) > file_history_vars(id)%varsum(idx) ) file_history_vars(id)%varsum(idx) = buffer(idx)
1108 file_history_vars(id)%varsum(idx) = rmiss
1113 deallocate( buffer )
1114 file_history_vars(id)%timesum = file_history_vars(id)%timesum + dt
1117 file_history_dims(dimid)%name, &
1118 file_history_vars(id)%zcoord, &
1119 file_history_vars(id)%fill_halo, &
1120 file_history_vars(id)%varsum(:) )
1121 file_history_vars(id)%timesum = 0.0_dp
1124 file_history_vars(id)%laststep_put = file_history_nowstep
1125 file_history_vars(id)%flag_clear = .false.
1132 end subroutine file_history_put_1d
1144 real(RP),
intent(in) :: var(:)
1145 character(len=*),
intent(in) :: name
1146 character(len=*),
intent(in) :: desc
1147 character(len=*),
intent(in) :: unit
1149 character(len=*),
intent(in),
optional :: standard_name
1150 character(len=*),
intent(in),
optional :: dim_type
1152 logical,
parameter :: fill_halo = .false.
1154 integer,
parameter :: ndim = 1
1159 if ( file_history_disabled )
return
1164 standard_name=standard_name, &
1166 dim_type=dim_type, &
1167 fill_halo=fill_halo )
1169 if ( itemid < 0 )
return
1172 call file_history_query( itemid, do_put )
1174 if ( do_put )
call file_history_put( itemid, var(:) )
1180 subroutine file_history_put_2d( &
1194 integer,
intent(in) :: itemid
1195 real(RP),
intent(in) :: var(:,:)
1198 real(DP),
allocatable :: buffer(:)
1208 if ( file_history_disabled )
return
1209 if ( itemid < 0 )
return
1211 call file_history_query( itemid, do_put )
1212 if ( .not. do_put )
return
1218 do i = 1, file_history_var_inputs(itemid)%nvariants
1219 id = file_history_var_inputs(itemid)%variants(i)
1221 dt = ( file_history_nowstep - file_history_vars(id)%laststep_put ) * file_history_dtsec
1223 if ( dt < eps .AND. file_history_vars(id)%tstats_op == 0 )
then
1224 if ( file_history_var_inputs(itemid)%nvariants == 1 )
then
1225 log_error(
"FILE_HISTORY_Put_2D",*)
'variable was put two times before output!: ', &
1226 trim(file_history_vars(id)%name), file_history_nowstep, file_history_vars(id)%laststep_put
1233 if ( file_history_vars(id)%flag_clear )
then
1234 file_history_vars(id)%timesum = 0.0_dp
1235 select case ( file_history_vars(id)%tstats_op )
1238 file_history_vars(id)%varsum(:) = 0.0_dp
1242 file_history_vars(id)%varsum(:) = huge
1246 file_history_vars(id)%varsum(:) = - huge
1251 dimid = file_history_vars(id)%dimid
1253 if ( file_history_vars(id)%tstats_op > i_none )
then
1254 allocate( buffer( file_history_vars(id)%size ) )
1256 file_history_dims(dimid)%name, &
1257 file_history_vars(id)%zcoord, &
1258 file_history_vars(id)%fill_halo, &
1260 select case ( file_history_vars(id)%tstats_op )
1263 do idx = 1, file_history_vars(id)%size
1264 if ( file_history_vars(id)%varsum(idx) /= rmiss )
then
1265 if ( buffer(idx) /= undef )
then
1266 file_history_vars(id)%varsum(idx) = file_history_vars(id)%varsum(idx) + buffer(idx) * dt
1268 file_history_vars(id)%varsum(idx) = rmiss
1274 do idx = 1, file_history_vars(id)%size
1275 if ( file_history_vars(id)%varsum(idx) /= rmiss )
then
1276 if ( buffer(idx) /= undef )
then
1277 if ( buffer(idx) < file_history_vars(id)%varsum(idx) ) file_history_vars(id)%varsum(idx) = buffer(idx)
1279 file_history_vars(id)%varsum(idx) = rmiss
1285 do idx = 1, file_history_vars(id)%size
1286 if ( file_history_vars(id)%varsum(idx) /= rmiss )
then
1287 if ( buffer(idx) /= undef )
then
1288 if ( buffer(idx) > file_history_vars(id)%varsum(idx) ) file_history_vars(id)%varsum(idx) = buffer(idx)
1290 file_history_vars(id)%varsum(idx) = rmiss
1295 deallocate( buffer )
1296 file_history_vars(id)%timesum = file_history_vars(id)%timesum + dt
1299 file_history_dims(dimid)%name, &
1300 file_history_vars(id)%zcoord, &
1301 file_history_vars(id)%fill_halo, &
1302 file_history_vars(id)%varsum(:) )
1303 file_history_vars(id)%timesum = 0.0_dp
1306 file_history_vars(id)%laststep_put = file_history_nowstep
1307 file_history_vars(id)%flag_clear = .false.
1314 end subroutine file_history_put_2d
1327 real(RP),
intent(in) :: var(:,:)
1328 character(len=*),
intent(in) :: name
1329 character(len=*),
intent(in) :: desc
1330 character(len=*),
intent(in) :: unit
1332 character(len=*),
intent(in),
optional :: standard_name
1333 character(len=*),
intent(in),
optional :: dim_type
1334 logical,
intent(in),
optional :: fill_halo
1336 integer,
parameter :: ndim = 2
1341 if ( file_history_disabled )
return
1346 standard_name=standard_name, &
1348 dim_type=dim_type, &
1349 fill_halo=fill_halo )
1351 if ( itemid < 0 )
return
1354 call file_history_query( itemid, do_put )
1356 if ( do_put )
call file_history_put( itemid, var(:,:) )
1362 subroutine file_history_put_3d( &
1376 integer,
intent(in) :: itemid
1377 real(RP),
intent(in) :: var(:,:,:)
1380 real(DP),
allocatable :: buffer(:)
1390 if ( file_history_disabled )
return
1391 if ( itemid < 0 )
return
1393 call file_history_query( itemid, do_put )
1394 if ( .not. do_put )
return
1400 do i = 1, file_history_var_inputs(itemid)%nvariants
1401 id = file_history_var_inputs(itemid)%variants(i)
1403 dt = ( file_history_nowstep - file_history_vars(id)%laststep_put ) * file_history_dtsec
1405 if ( dt < eps .AND. file_history_vars(id)%tstats_op == 0 )
then
1406 if ( file_history_var_inputs(itemid)%nvariants == 1 )
then
1407 log_error(
"FILE_HISTORY_Put_3D",*)
'variable was put two times before output!: ', &
1408 trim(file_history_vars(id)%name), file_history_nowstep, file_history_vars(id)%laststep_put
1415 if ( file_history_vars(id)%flag_clear )
then
1416 file_history_vars(id)%timesum = 0.0_dp
1417 select case ( file_history_vars(id)%tstats_op )
1420 file_history_vars(id)%varsum(:) = 0.0_dp
1424 file_history_vars(id)%varsum(:) = huge
1428 file_history_vars(id)%varsum(:) = - huge
1433 dimid = file_history_vars(id)%dimid
1435 if ( file_history_vars(id)%tstats_op > i_none )
then
1436 allocate( buffer( file_history_vars(id)%size ) )
1438 file_history_dims(dimid)%name, &
1439 file_history_vars(id)%zcoord, &
1440 file_history_vars(id)%fill_halo, &
1442 select case ( file_history_vars(id)%tstats_op )
1445 do idx = 1, file_history_vars(id)%size
1446 if ( file_history_vars(id)%varsum(idx) /= rmiss )
then
1447 if ( buffer(idx) /= undef )
then
1448 file_history_vars(id)%varsum(idx) = file_history_vars(id)%varsum(idx) + buffer(idx) * dt
1450 file_history_vars(id)%varsum(idx) = rmiss
1456 do idx = 1, file_history_vars(id)%size
1457 if ( file_history_vars(id)%varsum(idx) /= rmiss )
then
1458 if ( buffer(idx) /= undef )
then
1459 if ( buffer(idx) < file_history_vars(id)%varsum(idx) ) file_history_vars(id)%varsum(idx) = buffer(idx)
1461 file_history_vars(id)%varsum(idx) = rmiss
1467 do idx = 1, file_history_vars(id)%size
1468 if ( file_history_vars(id)%varsum(idx) /= rmiss )
then
1469 if ( buffer(idx) /= undef )
then
1470 if ( buffer(idx) > file_history_vars(id)%varsum(idx) ) file_history_vars(id)%varsum(idx) = buffer(idx)
1472 file_history_vars(id)%varsum(idx) = rmiss
1477 deallocate( buffer )
1478 file_history_vars(id)%timesum = file_history_vars(id)%timesum + dt
1481 file_history_dims(dimid)%name, &
1482 file_history_vars(id)%zcoord, &
1483 file_history_vars(id)%fill_halo, &
1484 file_history_vars(id)%varsum(:) )
1485 file_history_vars(id)%timesum = 0.0_dp
1488 file_history_vars(id)%laststep_put = file_history_nowstep
1489 file_history_vars(id)%flag_clear = .false.
1496 end subroutine file_history_put_3d
1509 real(RP),
intent(in) :: var(:,:,:)
1510 character(len=*),
intent(in) :: name
1511 character(len=*),
intent(in) :: desc
1512 character(len=*),
intent(in) :: unit
1514 character(len=*),
intent(in),
optional :: standard_name
1515 character(len=*),
intent(in),
optional :: dim_type
1516 logical,
intent(in),
optional :: fill_halo
1518 integer,
parameter :: ndim = 3
1523 if ( file_history_disabled )
return
1528 standard_name=standard_name, &
1530 dim_type=dim_type, &
1531 fill_halo=fill_halo )
1533 if ( itemid < 0 )
return
1536 call file_history_query( itemid, do_put )
1538 if ( do_put )
call file_history_put( itemid, var(:,:,:) )
1544 subroutine file_history_put_4d( &
1558 integer,
intent(in) :: itemid
1559 real(RP),
intent(in) :: var(:,:,:,:)
1562 real(DP),
allocatable :: buffer(:)
1572 if ( file_history_disabled )
return
1573 if ( itemid < 0 )
return
1575 call file_history_query( itemid, do_put )
1576 if ( .not. do_put )
return
1582 do i = 1, file_history_var_inputs(itemid)%nvariants
1583 id = file_history_var_inputs(itemid)%variants(i)
1585 dt = ( file_history_nowstep - file_history_vars(id)%laststep_put ) * file_history_dtsec
1587 if ( dt < eps .AND. file_history_vars(id)%tstats_op == 0 )
then
1588 if ( file_history_var_inputs(itemid)%nvariants == 1 )
then
1589 log_error(
"FILE_HISTORY_Put_4D",*)
'variable was put two times before output!: ', &
1590 trim(file_history_vars(id)%name), file_history_nowstep, file_history_vars(id)%laststep_put
1597 if ( file_history_vars(id)%flag_clear )
then
1598 file_history_vars(id)%timesum = 0.0_dp
1599 select case ( file_history_vars(id)%tstats_op )
1602 file_history_vars(id)%varsum(:) = 0.0_dp
1606 file_history_vars(id)%varsum(:) = huge
1610 file_history_vars(id)%varsum(:) = - huge
1615 dimid = file_history_vars(id)%dimid
1617 if ( file_history_vars(id)%tstats_op > i_none )
then
1618 allocate( buffer( file_history_vars(id)%size ) )
1620 file_history_dims(dimid)%name, &
1621 file_history_vars(id)%zcoord, &
1622 file_history_vars(id)%fill_halo, &
1624 select case ( file_history_vars(id)%tstats_op )
1627 do idx = 1, file_history_vars(id)%size
1628 if ( file_history_vars(id)%varsum(idx) /= rmiss )
then
1629 if ( buffer(idx) /= undef )
then
1630 file_history_vars(id)%varsum(idx) = file_history_vars(id)%varsum(idx) + buffer(idx) * dt
1632 file_history_vars(id)%varsum(idx) = rmiss
1638 do idx = 1, file_history_vars(id)%size
1639 if ( file_history_vars(id)%varsum(idx) /= rmiss )
then
1640 if ( buffer(idx) /= undef )
then
1641 if ( buffer(idx) < file_history_vars(id)%varsum(idx) ) file_history_vars(id)%varsum(idx) = buffer(idx)
1643 file_history_vars(id)%varsum(idx) = rmiss
1649 do idx = 1, file_history_vars(id)%size
1650 if ( file_history_vars(id)%varsum(idx) /= rmiss )
then
1651 if ( buffer(idx) /= undef )
then
1652 if ( buffer(idx) > file_history_vars(id)%varsum(idx) ) file_history_vars(id)%varsum(idx) = buffer(idx)
1654 file_history_vars(id)%varsum(idx) = rmiss
1659 deallocate( buffer )
1660 file_history_vars(id)%timesum = file_history_vars(id)%timesum + dt
1663 file_history_dims(dimid)%name, &
1664 file_history_vars(id)%zcoord, &
1665 file_history_vars(id)%fill_halo, &
1666 file_history_vars(id)%varsum(:) )
1667 file_history_vars(id)%timesum = 0.0_dp
1670 file_history_vars(id)%laststep_put = file_history_nowstep
1671 file_history_vars(id)%flag_clear = .false.
1678 end subroutine file_history_put_4d
1691 real(RP),
intent(in) :: var(:,:,:,:)
1692 character(len=*),
intent(in) :: name
1693 character(len=*),
intent(in) :: desc
1694 character(len=*),
intent(in) :: unit
1696 character(len=*),
intent(in),
optional :: standard_name
1697 character(len=*),
intent(in),
optional :: dim_type
1698 logical,
intent(in),
optional :: fill_halo
1700 integer,
parameter :: ndim = 4
1705 if ( file_history_disabled )
return
1710 standard_name=standard_name, &
1712 dim_type=dim_type, &
1713 fill_halo=fill_halo )
1715 if ( itemid < 0 )
return
1718 call file_history_query( itemid, do_put )
1720 if ( do_put )
call file_history_put( itemid, var(:,:,:,:) )
1735 area, area_x, area_y, &
1740 character(len=*),
intent(in) :: name
1741 integer,
intent(in) :: ndims
1742 integer,
intent(in) :: nzcoords
1743 character(len=*),
intent(in) :: dims(ndims,nzcoords)
1744 character(len=*),
intent(in) :: zcoords(nzcoords)
1745 integer,
intent(in) :: start(ndims,nzcoords)
1746 integer,
intent(in) :: count(ndims,nzcoords)
1748 character(len=*),
intent(in),
optional :: mapping
1749 character(len=*),
intent(in),
optional :: area
1750 character(len=*),
intent(in),
optional :: area_x
1751 character(len=*),
intent(in),
optional :: area_y
1752 character(len=*),
intent(in),
optional :: volume
1753 character(len=*),
intent(in),
optional :: location
1754 character(len=*),
intent(in),
optional :: grid
1757 integer :: size, n, m
1759 if ( file_history_ndims >= file_history_dim_max )
then
1760 log_error(
"FILE_HISTORY_Set_Dim",*)
'number of dimension exceed max limit: ', file_history_dim_max
1763 file_history_ndims = file_history_ndims + 1
1764 id = file_history_ndims
1766 allocate( file_history_dims(id)%dims (max(ndims,1),nzcoords) )
1767 allocate( file_history_dims(id)%start(max(ndims,1),nzcoords) )
1768 allocate( file_history_dims(id)%count(max(ndims,1),nzcoords) )
1769 allocate( file_history_dims(id)%zcoords(nzcoords) )
1770 allocate( file_history_dims(id)%size(nzcoords) )
1772 file_history_dims(id)%name = name
1773 file_history_dims(id)%ndims = ndims
1774 file_history_dims(id)%nzcoords = nzcoords
1775 file_history_dims(id)%zcoords(:) = zcoords(:)
1776 if ( ndims > 0 )
then
1777 file_history_dims(id)%dims(:,:) = dims(:,:)
1778 file_history_dims(id)%start(:,:) = start(:,:)
1779 file_history_dims(id)%count(:,:) = count(:,:)
1781 file_history_dims(id)%dims(1,1) =
""
1782 file_history_dims(id)%start(1,1) = 1
1783 file_history_dims(id)%count(1,1) = 1
1789 size =
size * count(n,m)
1791 file_history_dims(id)%size(m) =
size
1794 if (
present(mapping) )
then
1795 file_history_dims(id)%mapping = mapping
1797 file_history_dims(id)%mapping =
""
1800 if (
present(area) )
then
1801 file_history_dims(id)%area = area
1803 file_history_dims(id)%area =
""
1805 if (
present(area_x) )
then
1806 file_history_dims(id)%area_x = area_x
1808 file_history_dims(id)%area_x =
""
1810 if (
present(area_y) )
then
1811 file_history_dims(id)%area_y = area_y
1813 file_history_dims(id)%area_y =
""
1815 if (
present(volume) )
then
1816 file_history_dims(id)%volume = volume
1818 file_history_dims(id)%volume =
""
1821 if (
present(location) )
then
1822 file_history_dims(id)%location = location
1823 if (
present(grid) )
then
1824 file_history_dims(id)%grid =
"grid_"//trim(grid)
1826 file_history_dims(id)%grid =
"grid"
1829 file_history_dims(id)%location =
""
1830 file_history_dims(id)%grid =
""
1840 name, desc, units, &
1849 character(len=*),
intent(in) :: name
1850 character(len=*),
intent(in) :: desc
1851 character(len=*),
intent(in) :: units
1852 character(len=*),
intent(in) :: dim
1853 real(
rp),
intent(in) :: var(:)
1855 real(
rp),
intent(in),
optional :: bounds(:,:)
1856 logical,
intent(in),
optional :: down
1857 integer,
intent(in),
optional :: gsize
1858 integer,
intent(in),
optional :: start
1866 dim_size =
size(var)
1868 if ( file_history_naxes >= file_history_axis_max )
then
1869 log_error(
"FILE_HISTORY_Set_Axis",*)
'Number of axis exceeds the limit.'
1873 file_history_naxes = file_history_naxes + 1
1874 id = file_history_naxes
1876 allocate( file_history_axes(id)%var(dim_size) )
1878 file_history_axes(id)%name = name
1879 file_history_axes(id)%desc = desc
1880 file_history_axes(id)%units = units
1881 file_history_axes(id)%dim = dim
1882 file_history_axes(id)%dim_size = dim_size
1883 file_history_axes(id)%var(:) = var(:)
1885 if (
present(down) )
then
1886 file_history_axes(id)%down = down
1888 file_history_axes(id)%down = .false.
1890 if (
present(gsize) )
then
1891 file_history_axes(id)%gdim_size = gsize
1893 file_history_axes(id)%gdim_size = -1
1895 if (
present(start) )
then
1896 file_history_axes(id)%start = start
1898 file_history_axes(id)%start = 1
1901 if (
present(bounds) )
then
1902 allocate( file_history_axes(id)%bounds(2,dim_size) )
1903 file_history_axes(id)%bounds(:,:) = bounds(:,:)
1916 integer :: fid, prev_fid
1920 if ( file_history_disabled )
return
1925 do id = 1, file_history_nitems
1926 call file_history_write_onevar( id, file_history_nowstep )
1932 do id = 1, file_history_nitems
1933 fid = file_history_vars(id)%fid
1934 if ( fid > 0 .AND. fid /= prev_fid )
then
1941 if ( file_history_output_switch_step >= 0 &
1942 .AND. file_history_nowstep-file_history_output_switch_laststep > file_history_output_switch_step )
then
1944 call file_history_close
1946 log_info(
"FILE_HISTORY_Write",*)
'FILE_HISTORY file is switched.'
1948 do id = 1, file_history_nitems
1949 file_history_vars(id)%fid = -1
1950 file_history_vars(id)%vid = -1
1953 file_history_output_switch_laststep = file_history_nowstep - 1
1965 integer,
intent(in) :: nowdate(:)
1966 real(
dp),
intent(in) :: nowsubsec
1967 integer,
intent(in) :: nowstep
1969 file_history_nowdate(:) = nowdate(:)
1970 file_history_nowsubsec = nowsubsec
1971 file_history_nowstep = nowstep
1982 logical,
intent(in) ::
switch
1985 file_history_disabled =
switch
1997 call file_history_close
2000 list_outputed = .false.
2002 do id = 1, file_history_nitems
2003 deallocate( file_history_vars(id)%varsum )
2005 file_history_nitems = 0
2007 do id = 1, file_history_ndims
2008 deallocate( file_history_dims(id)%dims )
2009 deallocate( file_history_dims(id)%start )
2010 deallocate( file_history_dims(id)%count )
2011 deallocate( file_history_dims(id)%zcoords )
2012 deallocate( file_history_dims(id)%size )
2014 file_history_ndims = 0
2016 do id = 1, file_history_naxes
2017 deallocate( file_history_axes(id)%var )
2018 if (
allocated( file_history_axes(id)%bounds ) ) &
2019 deallocate( file_history_axes(id)%bounds )
2021 file_history_naxes = 0
2023 do id = 1, file_history_nassocs
2024 deallocate( file_history_assocs(id)%var )
2026 file_history_nassocs = 0
2028 do id = 1, file_history_nattrs
2029 if (
allocated(file_history_attrs(id)%int ) ) &
2030 deallocate( file_history_attrs(id)%int )
2031 if (
allocated(file_history_attrs(id)%float ) ) &
2032 deallocate( file_history_attrs(id)%float )
2033 if (
allocated(file_history_attrs(id)%double ) ) &
2034 deallocate( file_history_attrs(id)%double )
2036 file_history_nattrs = 0
2039 if ( file_history_nreqs > 0 )
then
2040 deallocate( file_history_req )
2041 deallocate( file_history_vars )
2042 deallocate( file_history_var_inputs )
2044 file_history_nreqs = 0
2053 subroutine file_history_check( &
2058 character(len=*),
intent(in) :: name
2059 character(len=*),
intent(in) :: zcoord
2060 integer,
intent(out) :: itemid
2066 do itemid = 1, file_history_nvar_inputs
2067 if ( name == file_history_var_inputs(itemid)%name )
then
2068 do i = 1, file_history_var_inputs(itemid)%nvariants
2069 id = file_history_var_inputs(itemid)%variants(
i)
2071 if ( file_history_vars(id)%zcoord == zcoord )
return
2078 end subroutine file_history_check
2081 subroutine file_history_add_variable( &
2082 name, desc, units, &
2092 character(len=*),
intent(in) :: name
2093 character(len=*),
intent(in) :: desc
2094 character(len=*),
intent(in) :: units
2095 character(len=*),
intent(in) :: standard_name
2096 integer,
intent(in) :: dimid
2097 character(len=*),
intent(in) :: zcoord
2098 integer,
intent(out) :: itemid
2099 character(len=*),
intent(in),
optional :: cell_measures
2100 logical,
intent(in),
optional :: fill_halo
2102 integer :: reqid, zid, id
2109 call file_history_check( name, zcoord, &
2112 if ( itemid > 0 )
return
2114 do reqid = 1, file_history_nreqs
2116 if ( file_history_req(reqid)%registered ) cycle
2117 if ( name /= file_history_req(reqid)%name ) cycle
2119 if ( file_history_dims(dimid)%nzcoords == 1 .or. &
2120 zcoord == file_history_req(reqid)%zcoord )
then
2122 file_history_req(reqid)%registered = .true.
2124 file_history_nitems = file_history_nitems + 1
2125 id = file_history_nitems
2127 file_history_vars(id)%name = file_history_req(reqid)%name
2128 file_history_vars(id)%outname = file_history_req(reqid)%outname
2129 file_history_vars(id)%basename = file_history_req(reqid)%basename
2130 file_history_vars(id)%postfix_timelabel = file_history_req(reqid)%postfix_timelabel
2131 file_history_vars(id)%zcoord = zcoord
2132 file_history_vars(id)%dstep = file_history_req(reqid)%dstep
2133 file_history_vars(id)%tstats_op = file_history_req(reqid)%tstats_op
2134 file_history_vars(id)%dtype = file_history_req(reqid)%dtype
2136 file_history_vars(id)%zid = -1
2137 do zid = 1, file_history_dims(dimid)%nzcoords
2138 if ( file_history_dims(dimid)%zcoords(zid) == file_history_vars(id)%zcoord )
then
2139 file_history_vars(id)%zid = zid
2144 log_error(
"FILE_HISTORY_Add_Variable",*)
'z-coordinate ', trim(file_history_vars(id)%zcoord),
' is not found for dimension ', trim(file_history_dims(dimid)%name)
2148 file_history_vars(id)%fid = -1
2149 file_history_vars(id)%vid = -1
2150 file_history_vars(id)%desc = desc
2151 file_history_vars(id)%units = units
2152 file_history_vars(id)%standard_name = standard_name
2153 file_history_vars(id)%dimid = dimid
2154 if (
present(cell_measures) )
then
2155 file_history_vars(id)%cell_measures = cell_measures
2157 file_history_vars(id)%cell_measures =
""
2159 if (
present(fill_halo) )
then
2160 file_history_vars(id)%fill_halo = fill_halo
2162 file_history_vars(id)%fill_halo = .false.
2165 file_history_vars(id)%waitstep = file_history_output_wait_step
2166 if ( file_history_output_step0 .AND. file_history_nowstep == 1 )
then
2167 file_history_vars(id)%laststep_write = 1 - file_history_vars(id)%dstep
2169 file_history_vars(id)%laststep_write = 1
2171 file_history_vars(id)%laststep_put = file_history_vars(id)%laststep_write
2172 file_history_vars(id)%flag_clear = .true.
2173 file_history_vars(id)%size = file_history_dims(dimid)%size(zid)
2174 allocate( file_history_vars(id)%varsum( file_history_vars(id)%size ) )
2176 file_history_vars(id)%timesum = 0.0_dp
2179 log_info(
"FILE_HISTORY_Add_Variable",*)
'[HISTORY] Item registration No.= ', id
2180 log_info_cont(*)
'Item name : ', trim(file_history_vars(id)%name)
2181 log_info_cont(*)
'Output name : ', trim(file_history_vars(id)%outname)
2182 log_info_cont(*)
'Description : ', trim(file_history_vars(id)%desc)
2183 log_info_cont(*)
'Unit : ', trim(file_history_vars(id)%units)
2184 log_info_cont(*)
'Basename of output file : ', trim(file_history_vars(id)%basename)
2185 log_info_cont(*)
'Add timelabel to the filename? : ', file_history_vars(id)%postfix_timelabel
2186 log_info_cont(*)
'Zcoord : ', trim(file_history_vars(id)%zcoord)
2187 log_info_cont(*)
'Interval [step] : ', file_history_vars(id)%dstep
2188 log_info_cont(*)
'Time Statistics operator : ', op_name(file_history_vars(id)%tstats_op)
2189 log_info_cont(*)
'Datatype : ', trim(
file_dtypelist(file_history_vars(id)%dtype))
2190 log_info_cont(*)
'axis name : ', ( trim(file_history_dims(dimid)%dims(n,zid))//
" ", n=1, file_history_dims(dimid)%ndims )
2194 do m = 1, file_history_nvar_inputs
2195 if ( file_history_var_inputs(m)%name == name )
then
2196 file_history_var_inputs(m)%nvariants = file_history_var_inputs(m)%nvariants + 1
2197 if ( file_history_var_inputs(m)%nvariants > file_history_variant_max )
then
2198 log_error(
"FILE_HISTORY_Add_Variable",*)
'Number of variant for ', trim(name),
' excees limit!'
2201 file_history_var_inputs(m)%variants(file_history_var_inputs(m)%nvariants) = id
2207 if ( .not. existed )
then
2208 file_history_nvar_inputs = file_history_nvar_inputs + 1
2209 itemid = file_history_nvar_inputs
2210 file_history_var_inputs(itemid)%name = name
2211 file_history_var_inputs(itemid)%nvariants = 1
2212 file_history_var_inputs(itemid)%variants(1) = id
2220 end subroutine file_history_add_variable
2223 subroutine file_history_create( &
2238 file_add_variable, &
2244 integer,
intent(in) :: id
2246 character(len=*),
intent(in) :: options
2249 character(len=H_MID) :: tunits
2250 character(len=H_LONG) :: basename_mod
2251 logical :: fileexisted
2252 integer(8) :: array_size
2255 integer :: dimid, zid
2257 character(len=H_SHORT) :: dims(3)
2260 character(len=H_MID) :: timelabel
2262 integer :: ic, ie, is, lo
2266 fid = file_history_vars(id)%fid
2268 if ( fid >= 0 )
return
2270 if ( file_history_time_since ==
'' )
then
2271 tunits = trim(file_history_time_units)
2273 tunits = trim(file_history_time_units)//
' since '//trim(file_history_time_since)
2276 if ( file_history_vars(id)%postfix_timelabel )
then
2279 basename_mod = trim(file_history_vars(id)%basename)//
'_'//trim(timelabel)
2281 basename_mod = trim(file_history_vars(id)%basename)
2285 file_history_title, &
2286 file_history_source, &
2287 file_history_institution, &
2289 rankid = file_history_myrank, &
2291 time_units = tunits, &
2292 calendar = file_history_calendar )
2294 if ( .not. fileexisted )
then
2300 lo = len_trim(options)
2303 if ( m == lo+1 .OR. options(m:m) ==
'&' )
then
2304 if ( ic == -1 .OR. ie == -1 )
then
2305 log_error(
"FILE_HISTORY_Create",*)
'option is invalid: ', trim(options)
2308 call file_set_option( fid, options(is:ic-1), options(ic+1:ie-1), options(ie+1:m -1) )
2312 elseif( options(m:m) ==
':' )
then
2314 elseif( options(m:m) ==
'=' )
then
2320 if (
rp ==
dp )
then
2328 do m = 1, file_history_naxes
2330 dim_size = file_history_axes(m)%gdim_size
2331 if ( dim_size < 1 )
then
2332 log_error(
"FILE_HISTORY_Create",*)
'gsize is not set by FILE_HISTORY_Set_Axis'
2333 log_error_cont(*)
'It is necessary for aggregate file'
2337 dim_size = file_history_axes(m)%dim_size
2340 file_history_axes(m)%name, &
2341 file_history_axes(m)%desc, &
2342 file_history_axes(m)%units, &
2343 file_history_axes(m)%dim, &
2345 bounds=
allocated(file_history_axes(m)%bounds) )
2346 if ( file_history_axes(m)%down )
then
2347 call file_set_attribute( fid, file_history_axes(m)%name,
'positive',
'down' )
2353 do m = 1, file_history_nassocs
2354 ndims = file_history_assocs(m)%ndims
2356 file_history_assocs(m)%name, &
2357 file_history_assocs(m)%desc, &
2358 file_history_assocs(m)%units, &
2359 file_history_assocs(m)%dims(1:ndims), &
2360 file_history_assocs(m)%dtype )
2364 do m = 1, file_history_nattrs
2366 if ( file_history_attrs(m)%add_variable )
then
2371 select case ( file_history_attrs(m)%type )
2373 call file_set_attribute( fid, &
2374 file_history_attrs(m)%varname, &
2375 file_history_attrs(m)%key, &
2376 file_history_attrs(m)%text )
2378 call file_set_attribute( fid, &
2379 file_history_attrs(m)%varname, &
2380 file_history_attrs(m)%key, &
2381 file_history_attrs(m)%int(:) )
2383 call file_set_attribute( fid, &
2384 file_history_attrs(m)%varname, &
2385 file_history_attrs(m)%key, &
2386 file_history_attrs(m)%float(:) )
2388 call file_set_attribute( fid, &
2389 file_history_attrs(m)%varname, &
2390 file_history_attrs(m)%key, &
2391 file_history_attrs(m)%double(:) )
2401 do m = 1, file_history_nitems
2402 if ( file_history_vars(id)%basename == file_history_vars(m)%basename .and. &
2403 file_history_vars(m)%fid < 0 )
then
2405 file_history_vars(m)%fid = fid
2406 dtsec = real(file_history_vars(m)%dstep,kind=
dp) * file_history_dtsec
2407 dimid = file_history_vars(m)%dimid
2408 zid = file_history_vars(m)%zid
2409 ndims = file_history_dims(dimid)%ndims
2410 dims(1:ndims) = file_history_dims(dimid)%dims(1:ndims,zid)
2411 call file_add_variable( file_history_vars(m)%fid, &
2412 file_history_vars(m)%outname, &
2413 file_history_vars(m)%desc, &
2414 file_history_vars(m)%units, &
2415 file_history_vars(m)%standard_name, &
2417 file_history_vars(m)%dtype, &
2419 file_history_vars(m)%vid, &
2420 time_stats=op_name(file_history_vars(m)%tstats_op) )
2421 if ( file_history_dims(dimid)%mapping /=
"" )
then
2422 call file_set_attribute( file_history_vars(m)%fid, file_history_vars(m)%outname, &
2423 'grid_mapping', file_history_dims(dimid)%mapping )
2426 select case( file_history_vars(m)%cell_measures )
2427 case (
"area",
"area_z" )
2428 if ( file_history_dims(dimid)%area /=
"" )
then
2429 call file_set_attribute( file_history_vars(m)%fid, file_history_vars(m)%outname, &
2430 'cell_measures',
"area: "//trim(file_history_dims(dimid)%area) )
2433 if ( file_history_dims(dimid)%area_x /=
"" )
then
2434 call file_set_attribute( file_history_vars(m)%fid, file_history_vars(m)%outname, &
2435 'cell_measures',
"area: "//trim(file_history_dims(dimid)%area_x) )
2438 if ( file_history_dims(dimid)%area_x /=
"" )
then
2439 call file_set_attribute( file_history_vars(m)%fid, file_history_vars(m)%outname, &
2440 'cell_measures',
"area: "//trim(file_history_dims(dimid)%area_y) )
2443 if ( file_history_dims(dimid)%area_x /=
"" )
then
2444 call file_set_attribute( file_history_vars(m)%fid, file_history_vars(m)%outname, &
2445 'cell_measures',
"volume: "//trim(file_history_dims(dimid)%volume) )
2449 if ( file_history_dims(dimid)%location /=
"" )
then
2450 if ( file_history_vars(m)%zcoord ==
"model" )
then
2451 call file_set_attribute( file_history_vars(m)%fid, file_history_vars(m)%outname, &
2452 'grid', file_history_dims(dimid)%grid )
2454 call file_set_attribute( file_history_vars(m)%fid, file_history_vars(m)%outname, &
2455 'grid', trim(file_history_dims(dimid)%grid)//
'_'//trim(file_history_vars(id)%zcoord) )
2457 call file_set_attribute( file_history_vars(m)%fid, file_history_vars(m)%outname, &
2458 'location', file_history_dims(dimid)%location )
2467 do m = 1, file_history_nitems
2468 if ( file_history_vars(m)%fid == file_history_vars(id)%fid )
then
2469 array_size = array_size + file_history_vars(m)%size
2475 if ( .not. fileexisted )
call file_history_write_axes(id)
2478 end subroutine file_history_create
2480 subroutine file_history_close
2486 integer :: fid, prev_fid
2491 do id = 1, file_history_nitems
2492 fid = file_history_vars(id)%fid
2493 file_history_vars(id)%fid = -1
2494 if ( fid > 0 .AND. fid /= prev_fid )
then
2502 end subroutine file_history_close
2520 character(len=*),
intent(in) :: name
2521 character(len=*),
intent(in) :: desc
2522 character(len=*),
intent(in) :: units
2523 character(len=*),
intent(in) :: dims(:)
2524 real(RP),
intent(in) :: var(:)
2525 character(len=*),
intent(in),
optional :: datatype
2526 integer,
intent(in),
optional :: start(:)
2532 intrinsic size, shape, reshape
2535 if (
present(datatype) )
then
2536 if ( datatype ==
'REAL4' )
then
2538 elseif( datatype ==
'REAL8' )
then
2541 log_error(
"FILE_HISTORY_Set_AssociatedCoordinate_1D",*)
'Not appropriate datatype. Check!', datatype
2544 else if ( rp ==
sp )
then
2550 dim_size =
size(var)
2552 if ( file_history_nassocs < file_history_assoc_max )
then
2553 file_history_nassocs = file_history_nassocs + 1
2554 id = file_history_nassocs
2556 allocate( file_history_assocs(id)%var(dim_size) )
2558 file_history_assocs(id)%name = name
2559 file_history_assocs(id)%desc = desc
2560 file_history_assocs(id)%units = units
2561 file_history_assocs(id)%ndims = 1
2562 file_history_assocs(id)%dims(:) =
''
2563 file_history_assocs(id)%dims(1:1) = dims(1:1)
2564 file_history_assocs(id)%dtype = dtype
2565 file_history_assocs(id)%var(:) = real(reshape( var, (/ dim_size /) ),kind=
dp)
2569 file_history_assocs(id)%count(1:1) = shape(var)
2570 if (
present(start) )
then
2571 file_history_assocs(id)%start(1:1) = start(1:1)
2573 file_history_assocs(id)%start = (/ 1, 1, 1, 1 /)
2576 log_error(
"FILE_HISTORY_Set_AssociatedCoordinate_1D",*)
'Number of associate coordinates exceeds the limit.'
2597 character(len=*),
intent(in) :: name
2598 character(len=*),
intent(in) :: desc
2599 character(len=*),
intent(in) :: units
2600 character(len=*),
intent(in) :: dims(:)
2601 real(RP),
intent(in) :: var(:,:)
2602 character(len=*),
intent(in),
optional :: datatype
2603 integer,
intent(in),
optional :: start(:)
2609 intrinsic size, shape, reshape
2612 if (
present(datatype) )
then
2613 if ( datatype ==
'REAL4' )
then
2615 elseif( datatype ==
'REAL8' )
then
2618 log_error(
"FILE_HISTORY_Set_AssociatedCoordinate_2D",*)
'Not appropriate datatype. Check!', datatype
2621 else if ( rp ==
sp )
then
2627 dim_size =
size(var)
2629 if ( file_history_nassocs < file_history_assoc_max )
then
2630 file_history_nassocs = file_history_nassocs + 1
2631 id = file_history_nassocs
2633 allocate( file_history_assocs(id)%var(dim_size) )
2635 file_history_assocs(id)%name = name
2636 file_history_assocs(id)%desc = desc
2637 file_history_assocs(id)%units = units
2638 file_history_assocs(id)%ndims = 2
2639 file_history_assocs(id)%dims(:) =
''
2640 file_history_assocs(id)%dims(1:2) = dims(1:2)
2641 file_history_assocs(id)%dtype = dtype
2642 file_history_assocs(id)%var(:) = real(reshape( var, (/ dim_size /) ),kind=
dp)
2646 file_history_assocs(id)%count(1:2) = shape(var)
2647 if (
present(start) )
then
2648 file_history_assocs(id)%start(1:2) = start(1:2)
2650 file_history_assocs(id)%start = (/ 1, 1, 1, 1 /)
2653 log_error(
"FILE_HISTORY_Set_AssociatedCoordinate_2D",*)
'Number of associate coordinates exceeds the limit.'
2674 character(len=*),
intent(in) :: name
2675 character(len=*),
intent(in) :: desc
2676 character(len=*),
intent(in) :: units
2677 character(len=*),
intent(in) :: dims(:)
2678 real(RP),
intent(in) :: var(:,:,:)
2679 character(len=*),
intent(in),
optional :: datatype
2680 integer,
intent(in),
optional :: start(:)
2686 intrinsic size, shape, reshape
2689 if (
present(datatype) )
then
2690 if ( datatype ==
'REAL4' )
then
2692 elseif( datatype ==
'REAL8' )
then
2695 log_error(
"FILE_HISTORY_Set_AssociatedCoordinate_3D",*)
'Not appropriate datatype. Check!', datatype
2698 else if ( rp ==
sp )
then
2704 dim_size =
size(var)
2706 if ( file_history_nassocs < file_history_assoc_max )
then
2707 file_history_nassocs = file_history_nassocs + 1
2708 id = file_history_nassocs
2710 allocate( file_history_assocs(id)%var(dim_size) )
2712 file_history_assocs(id)%name = name
2713 file_history_assocs(id)%desc = desc
2714 file_history_assocs(id)%units = units
2715 file_history_assocs(id)%ndims = 3
2716 file_history_assocs(id)%dims(:) =
''
2717 file_history_assocs(id)%dims(1:3) = dims(1:3)
2718 file_history_assocs(id)%dtype = dtype
2719 file_history_assocs(id)%var(:) = real(reshape( var, (/ dim_size /) ),kind=
dp)
2723 file_history_assocs(id)%count(1:3) = shape(var)
2724 if (
present(start) )
then
2725 file_history_assocs(id)%start(1:3) = start(1:3)
2727 file_history_assocs(id)%start = (/ 1, 1, 1, 1 /)
2730 log_error(
"FILE_HISTORY_Set_AssociatedCoordinate_3D",*)
'Number of associate coordinates exceeds the limit.'
2749 character(len=*),
intent(in) :: varname
2750 character(len=*),
intent(in) :: key
2751 character(len=*),
intent(in) :: val
2752 logical,
intent(in),
optional :: add_variable
2757 file_history_nattrs = file_history_nattrs + 1
2758 if ( file_history_nattrs > file_history_attr_max )
then
2759 log_error(
"FILE_HISTORY_Set_Attribute_Text",*)
'number of attributes exceeds the limit'
2763 id = file_history_nattrs
2765 file_history_attrs(id)%varname = varname
2766 file_history_attrs(id)%key = key
2767 file_history_attrs(id)%text = val
2768 file_history_attrs(id)%type = i_text
2770 if (
present(add_variable) )
then
2771 file_history_attrs(id)%add_variable = add_variable
2773 file_history_attrs(id)%add_variable = .false.
2786 character(len=*),
intent(in) :: varname
2787 character(len=*),
intent(in) :: key
2788 logical,
intent(in) :: val
2789 logical,
intent(in),
optional :: add_variable
2791 character(len=5) :: buf
2815 character(len=*),
intent(in) :: varname
2816 character(len=*),
intent(in) :: key
2817 integer,
intent(in) :: val(:)
2818 logical,
intent(in),
optional :: add_variable
2825 file_history_nattrs = file_history_nattrs + 1
2826 if ( file_history_nattrs > file_history_attr_max )
then
2827 log_error(
"FILE_HISTORY_Set_Attribute_Int",*)
'number of attributes exceeds the limit'
2831 id = file_history_nattrs
2833 allocate( file_history_attrs(id)%int(
size(val) ) )
2835 file_history_attrs(id)%varname = varname
2836 file_history_attrs(id)%key = key
2837 file_history_attrs(id)%int(:) = val(:)
2838 file_history_attrs(id)%type = i_int
2840 if (
present(add_variable) )
then
2841 file_history_attrs(id)%add_variable = add_variable
2843 file_history_attrs(id)%add_variable = .false.
2855 character(len=*),
intent(in) :: varname
2856 character(len=*),
intent(in) :: key
2857 integer,
intent(in) :: val
2858 logical,
intent(in),
optional :: add_variable
2866 add_variable=add_variable )
2872 subroutine file_history_set_attribute_float_ary( &
2881 character(len=*),
intent(in) :: varname
2882 character(len=*),
intent(in) :: key
2883 real(SP),
intent(in) :: val(:)
2884 logical,
intent(in),
optional :: add_variable
2891 file_history_nattrs = file_history_nattrs + 1
2892 if ( file_history_nattrs > file_history_attr_max )
then
2893 log_error(
"FILE_HISTORY_Set_Attribute_Float",*)
'number of attributes exceeds the limit'
2897 id = file_history_nattrs
2899 allocate( file_history_attrs(id)%float(
size(val) ) )
2901 file_history_attrs(id)%varname = varname
2902 file_history_attrs(id)%key = key
2903 file_history_attrs(id)%float(:) = val(:)
2904 file_history_attrs(id)%type = i_float
2906 if (
present(add_variable) )
then
2907 file_history_attrs(id)%add_variable = add_variable
2909 file_history_attrs(id)%add_variable = .false.
2913 end subroutine file_history_set_attribute_float_ary
2920 character(len=*),
intent(in) :: varname
2921 character(len=*),
intent(in) :: key
2922 real(SP),
intent(in) :: val
2923 logical,
intent(in),
optional :: add_variable
2928 call file_history_set_attribute_float_ary( varname, &
2935 subroutine file_history_set_attribute_double_ary( &
2944 character(len=*),
intent(in) :: varname
2945 character(len=*),
intent(in) :: key
2946 real(DP),
intent(in) :: val(:)
2947 logical,
intent(in),
optional :: add_variable
2954 file_history_nattrs = file_history_nattrs + 1
2955 if ( file_history_nattrs > file_history_attr_max )
then
2956 log_error(
"FILE_HISTORY_Set_Attribute_Double",*)
'number of attributes exceeds the limit'
2960 id = file_history_nattrs
2962 allocate( file_history_attrs(id)%double(
size(val) ) )
2964 file_history_attrs(id)%varname = varname
2965 file_history_attrs(id)%key = key
2966 file_history_attrs(id)%double(:) = val(:)
2967 file_history_attrs(id)%type = i_double
2969 if (
present(add_variable) )
then
2970 file_history_attrs(id)%add_variable = add_variable
2972 file_history_attrs(id)%add_variable = .false.
2976 end subroutine file_history_set_attribute_double_ary
2983 character(len=*),
intent(in) :: varname
2984 character(len=*),
intent(in) :: key
2985 real(DP),
intent(in) :: val
2986 logical,
intent(in),
optional :: add_variable
2991 call file_history_set_attribute_double_ary( varname, &
3001 subroutine file_history_query_id( &
3004 integer,
intent(in) :: itemid
3005 logical,
intent(out) :: answer
3010 if ( file_history_disabled )
return
3011 if ( itemid < 0 )
return
3013 do i = 1, file_history_var_inputs(itemid)%nvariants
3014 id = file_history_var_inputs(itemid)%variants(i)
3015 if ( file_history_vars(id)%tstats_op > i_none )
then
3018 else if ( file_history_nowstep >= file_history_vars(id)%laststep_write + file_history_vars(id)%dstep )
then
3025 end subroutine file_history_query_id
3027 subroutine file_history_query_name( &
3032 character(len=*),
intent(in) :: name
3034 logical,
intent(out) :: answer
3040 if ( file_history_disabled )
return
3042 do itemid = 1, file_history_nvar_inputs
3043 if ( file_history_var_inputs(itemid)%name == name )
then
3044 call file_history_query_id( itemid, answer )
3050 end subroutine file_history_query_name
3053 subroutine file_history_write_axes(id)
3058 file_write_associatedcoordinate
3062 integer,
intent(in) :: id
3068 if ( id < 0 )
return
3070 fid = file_history_vars(id)%fid
3074 do m = 1, file_history_naxes
3075 if ( file_history_axes(m)%start > 0 )
then
3076 start(1) = file_history_axes(m)%start
3078 call file_write_axis( fid, &
3079 file_history_axes(m)%name, &
3080 file_history_axes(m)%var, &
3083 if (
allocated(file_history_axes(m)%bounds) )
then
3084 call file_write_associatedcoordinate( fid, &
3085 trim(file_history_axes(m)%name)//
'_bnds', &
3086 file_history_axes(m)%bounds(:,:), &
3093 do m = 1, file_history_nassocs
3094 call file_write_associatedcoordinate( fid, &
3095 file_history_assocs(m)%name, &
3096 file_history_assocs(m)%var, &
3097 file_history_assocs(m)%start, &
3098 file_history_assocs(m)%count, &
3099 file_history_assocs(m)%ndims )
3106 end subroutine file_history_write_axes
3109 subroutine file_history_write_onevar( &
3120 integer,
intent(in) :: id
3121 integer,
intent(in) :: step_now
3123 integer :: dimid, zid
3124 real(DP) :: time_str, time_end
3125 real(DP) :: sec_str, sec_end
3129 if( file_history_nreqs == 0 )
return
3131 if ( step_now < file_history_vars(id)%laststep_write + file_history_vars(id)%dstep )
then
3135 if ( file_history_vars(id)%flag_clear )
then
3136 if ( file_history_output_step0 .AND. file_history_nowstep == 1 )
then
3138 do i = 1, file_history_vars(id)%size
3139 file_history_vars(id)%varsum(i) = rmiss
3141 else if ( file_history_error_putmiss )
then
3142 log_error(
"FILE_HISTORY_Write_OneVar",*)
'The time interval of history output ', trim(file_history_vars(id)%name), &
3143 ' and the time interval of its related scheme are inconsistent.'
3144 log_error_cont(*)
'Please check the namelist PARAM_TIME, PARAM_FILE_HISTORY, and HISTORY_ITEM.'
3145 log_error_cont(*)
'Please set FILE_HISTORY_ERROR_PUTMISS in the namelist PARAM_FILE_HISTORY to .false.', &
3146 ' when you want to disable this check.'
3147 log_error_cont(*)
'The time interval of history output ', trim(file_history_vars(id)%name), &
3148 ' and the time interval of its related scheme are inconsistent.', &
3149 ' Please see detail in log file.'
3152 log_warn(
"FILE_HISTORY_Write_OneVar",*)
'Output value is not updated in this step.', &
3153 ' NAME = ', trim(file_history_vars(id)%name), &
3154 ', OUTNAME = ', trim(file_history_vars(id)%outname)
3156 do i = 1, file_history_vars(id)%size
3157 file_history_vars(id)%varsum(i) = rmiss
3160 else if( file_history_output_step0 .and. file_history_nowstep == 1 .and. file_history_vars(id)%tstats_op .ne. i_none )
then
3162 do i = 1, file_history_vars(id)%size
3163 file_history_vars(id)%varsum(i) = rmiss
3165 else if ( file_history_vars(id)%tstats_op == i_mean )
then
3167 do i = 1, file_history_vars(id)%size
3168 if ( file_history_vars(id)%varsum(i) /= rmiss )
then
3169 file_history_vars(id)%varsum(i) = file_history_vars(id)%varsum(i) / file_history_vars(id)%timesum
3174 call file_history_output_list
3176 if ( step_now > file_history_vars(id)%waitstep )
then
3177 if ( laststep_write < step_now )
then
3178 log_progress(*)
'output history'
3183 call file_history_create( id, options = file_history_options )
3185 sec_str = file_history_startdaysec + real(file_history_vars(id)%laststep_write-1,kind=dp) * file_history_dtsec
3186 sec_end = file_history_startdaysec + real(step_now -1,kind=dp) * file_history_dtsec
3192 dimid = file_history_vars(id)%dimid
3193 zid = file_history_vars(id)%zid
3194 if ( file_history_dims(dimid)%count(1,zid) > 0 )
then
3201 call file_write( file_history_vars(id)%vid, &
3202 file_history_vars(id)%varsum(:), &
3205 ndims=file_history_dims(dimid)%ndims, &
3206 count=file_history_dims(dimid)%count(:,zid), &
3207 start=file_history_dims(dimid)%start(:,zid) )
3210 if ( laststep_write < step_now )
then
3211 log_progress(*)
'history output is suppressed'
3215 file_history_vars(id)%laststep_write = step_now
3216 file_history_vars(id)%flag_clear = .true.
3218 laststep_write = step_now
3221 end subroutine file_history_write_onevar
3224 subroutine file_history_output_list
3231 if ( list_outputed )
then
3235 if ( file_history_nitems /= file_history_nreqs )
then
3237 if ( .not. ( file_history_output_step0 .and. file_history_nowstep == 1 ) )
then
3239 log_info(
"FILE_HISTORY_Output_List",*)
'[HISTORY] All of requested variable by the namelist HISTORY_ITEM did not find.'
3240 do id = 1, file_history_nreqs
3241 log_info(
"FILE_HISTORY_Output_List",
'(A,A24,A,L1)')
'NAME : ', file_history_req(id)%name, &
3242 ', registered? : ', file_history_req(id)%registered
3244 log_info(
"FILE_HISTORY_Output_List",*)
'Please set FILE_HISTORY_ERROR_PUTMISS in the namelist PARAM_FILE_HISTORY to .false.', &
3245 ' when you want to disable this check.'
3247 if ( file_history_error_putmiss )
then
3248 log_error(
"FILE_HISTORY_Output_List",*)
'Requested variables by the namelist HISTORY_ITEM did not find. Please see detail in log file.'
3256 log_info(
"FILE_HISTORY_Output_List",*)
'[HISTORY] Output item list '
3257 log_info_cont(
'(1x,A,I4)')
'Number of history item :', file_history_nreqs
3258 log_info_cont(*)
'ITEM :OUTNAME ', &
3259 ': size:interval[sec]: step:stats_op:zcoord'
3260 log_info_cont(*)
'=================================================', &
3261 '================================================='
3264 do id = 1, file_history_nitems
3265 dtsec = real(file_history_vars(id)%dstep,kind=dp) * file_history_dtsec
3267 log_info_cont(
'(1x,A24,1x,A24,1x,I8,1x,F13.3,1x,I8,1x,A8,1x,A8)') &
3268 file_history_vars(id)%name, &
3269 file_history_vars(id)%outname, &
3270 file_history_vars(id)%size, &
3272 file_history_vars(id)%dstep, &
3273 op_name(file_history_vars(id)%tstats_op), &
3274 file_history_vars(id)%zcoord
3277 log_info_cont(*)
'=================================================', &
3278 '================================================='
3280 list_outputed = .true.
3283 end subroutine file_history_output_list
3285 function file_history_find_id( name )
3286 character(len=*),
intent(in) :: name
3287 integer :: FILE_HISTORY_find_id
3291 do itemid = 1, file_history_nvar_inputs
3292 if ( file_history_var_inputs(itemid)%name == name )
then
3293 file_history_find_id = itemid
3298 file_history_find_id = -1
3301 end function file_history_find_id
3303 function file_history_get_size( &
3305 character(len=*),
intent(in) :: dims(:)
3306 integer,
intent(in) :: ndims
3307 integer :: FILE_HISTORY_get_size
3312 file_history_get_size = 1
3315 do i = 1, file_history_naxes
3316 if ( file_history_axes(i)%name == dims(n) )
then
3317 len = file_history_axes(i)%dim_size
3322 log_error(
"FILE_HISTORY_get_size",*)
'dimension name is not found: ', dims(n)
3325 file_history_get_size = file_history_get_size * len
3329 end function file_history_get_size
3331 subroutine file_history_truncate_1d_default( &
3333 dim_type, zcoord, fill_halo, &
3335 real(RP),
intent(in) :: src(:)
3336 character(len=*),
intent(in) :: dim_type
3337 character(len=*),
intent(in) :: zcoord
3338 logical,
intent(in) :: fill_halo
3339 real(DP),
intent(out) :: dsc(:)
3344 end subroutine file_history_truncate_1d_default
3345 subroutine file_history_truncate_2d_default( &
3347 dim_type, zcoord, fill_halo, &
3349 real(RP),
intent(in) :: src(:,:)
3350 character(len=*),
intent(in) :: dim_type
3351 character(len=*),
intent(in) :: zcoord
3352 logical,
intent(in) :: fill_halo
3353 real(DP),
intent(out) :: dsc(:)
3361 do j = 1,
size(src,2)
3362 do i = 1,
size(src,1)
3363 dsc(idx) = src(i, j)
3369 end subroutine file_history_truncate_2d_default
3370 subroutine file_history_truncate_3d_default( &
3372 dim_type, zcoord, fill_halo, &
3374 real(RP),
intent(in) :: src(:,:,:)
3375 character(len=*),
intent(in) :: dim_type
3376 character(len=*),
intent(in) :: zcoord
3377 logical,
intent(in) :: fill_halo
3378 real(DP),
intent(out) :: dsc(:)
3386 do j = 1,
size(src,3)
3387 do i = 1,
size(src,2)
3388 do k = 1,
size(src,1)
3389 dsc(idx) = src(k, i, j)
3396 end subroutine file_history_truncate_3d_default
3397 subroutine file_history_truncate_4d_default( &
3399 dim_type, zcoord, fill_halo, &
3401 real(RP),
intent(in) :: src(:,:,:,:)
3402 character(len=*),
intent(in) :: dim_type
3403 character(len=*),
intent(in) :: zcoord
3404 logical,
intent(in) :: fill_halo
3405 real(DP),
intent(out) :: dsc(:)
3407 integer :: l, k, i, j
3413 do j = 1,
size(src,4)
3414 do i = 1,
size(src,3)
3415 do k = 1,
size(src,2)
3416 do l = 1,
size(src,1)
3417 dsc(idx) = src(l, k, i, j)
3425 end subroutine file_history_truncate_4d_default