29 public :: file_external_input_update
31 interface file_external_input_update
35 end interface file_external_input_update
38 subroutine get_dims1d( &
44 integer,
intent(out) :: dim1_max
45 integer,
intent(out) :: dim1_s
46 integer,
intent(out) :: dim1_e
47 character(len=*),
intent(in) :: varname
48 character(len=*),
intent(in) :: axistype
49 end subroutine get_dims1d
51 subroutine get_dims2d( &
61 integer,
intent(out) :: dim1_max
62 integer,
intent(out) :: dim1_s
63 integer,
intent(out) :: dim1_e
64 integer,
intent(out) :: dim2_max
65 integer,
intent(out) :: dim2_s
66 integer,
intent(out) :: dim2_e
67 logical,
intent(out) :: transpose
68 character(len=*),
intent(in) :: varname
69 character(len=*),
intent(in) :: axistype
70 end subroutine get_dims2d
72 subroutine get_dims3d( &
85 integer,
intent(out) :: dim1_max
86 integer,
intent(out) :: dim1_s
87 integer,
intent(out) :: dim1_e
88 integer,
intent(out) :: dim2_max
89 integer,
intent(out) :: dim2_s
90 integer,
intent(out) :: dim2_e
91 integer,
intent(out) :: dim3_max
92 integer,
intent(out) :: dim3_s
93 integer,
intent(out) :: dim3_e
94 logical,
intent(out) :: transpose
95 character(len=*),
intent(in) :: varname
96 character(len=*),
intent(in) :: axistype
97 end subroutine get_dims3d
117 private :: file_external_input_time_advance
123 integer,
private,
parameter :: i_prev = 1
124 integer,
private,
parameter :: i_next = 2
126 integer,
private,
parameter :: i_periodic_year = 1
127 integer,
private,
parameter :: i_periodic_month = 2
128 integer,
private,
parameter :: i_periodic_day = 3
130 integer,
private,
parameter :: file_external_input_item_limit = 1000
131 integer,
private,
parameter :: file_external_input_step_limit = 10000
132 integer,
private,
parameter :: file_external_input_dim_limit = 3
133 integer,
private,
parameter :: file_external_input_att_limit = 10
135 type,
private :: itemcontainer
136 character(len=H_SHORT) :: varname
138 integer :: file_current
139 character(len=H_LONG),
allocatable :: basename(:)
142 integer :: dim_size(file_external_input_dim_limit)
143 integer,
allocatable :: dim_start(:)
144 integer :: step_limit
146 real(DP),
allocatable :: time(:)
147 logical :: fixed_step
148 integer :: flag_periodic
150 integer :: data_step_prev
151 integer :: data_step_next
152 integer :: data_step_offset
153 real(RP),
allocatable ::
value(:,:,:,:)
154 character(len=H_SHORT) :: axistype
156 end type itemcontainer
158 integer,
private :: file_external_input_item_count = 0
159 type(itemcontainer),
private :: file_external_input_item(file_external_input_item_limit)
173 character(len=H_SHORT) :: varname
174 character(len=H_SHORT) :: axistype
175 integer :: step_limit
176 integer :: step_fixed
177 logical :: enable_periodic_year
178 logical :: enable_periodic_month
179 logical :: enable_periodic_day
182 logical :: check_coordinates
184 namelist / external_item / &
190 enable_periodic_year, &
191 enable_periodic_month, &
192 enable_periodic_day, &
202 log_info(
"FILE_EXTERNAL_INPUT_setup",*)
'Setup' 206 do count = 1, file_external_input_item_limit
208 step_limit = file_external_input_step_limit
213 enable_periodic_year = .false.
214 enable_periodic_month = .false.
215 enable_periodic_day = .false.
218 check_coordinates = .false.
224 elseif( ierr > 0 )
then 225 log_error(
"FILE_EXTERNAL_INPUT_setup",*)
'Not appropriate names in namelist EXTERNAL_ITEM. Check!', count
228 log_nml(external_item)
233 enable_periodic_year, &
234 enable_periodic_month, &
235 enable_periodic_day, &
252 enable_periodic_year, &
253 enable_periodic_month, &
254 enable_periodic_day, &
265 file_get_all_datainfo, &
284 file_cartesc_check_coordinates
288 character(len=*),
intent(in) :: varname
289 character(len=*),
intent(in) :: axistype
290 integer,
intent(in) :: step_fixed
291 logical,
intent(in) :: enable_periodic_year
292 logical,
intent(in) :: enable_periodic_month
293 logical,
intent(in) :: enable_periodic_day
294 real(RP),
intent(in) :: offset
295 real(RP),
intent(in) :: defval
297 logical,
intent(in),
optional :: check_coordinates
298 integer,
intent(in),
optional :: step_limit
299 logical,
intent(out),
optional :: exist
302 character(len=H_MID) :: description
303 character(len=H_SHORT) :: unit
304 character(len=H_MID) :: standard_name
307 character(len=H_SHORT) :: dim_name (file_external_input_dim_limit)
308 integer :: dim_size (file_external_input_dim_limit)
310 character(len=H_SHORT) :: att_name (file_external_input_att_limit)
311 integer :: att_type (file_external_input_att_limit)
312 integer :: att_len (file_external_input_att_limit)
313 real(DP) :: time_start(file_external_input_step_limit)
314 real(DP) :: time_end (file_external_input_step_limit)
315 character(len=H_MID) :: time_units
316 character(len=H_SHORT) :: calendar
318 integer :: datadate(6)
319 real(DP) :: datasubsec
322 integer :: offset_year
324 integer :: dim1_max, dim1_S, dim1_E
325 integer :: dim2_max, dim2_S, dim2_E
326 integer :: dim3_max, dim3_S, dim3_E
328 integer :: step_limit_
334 if (
present(step_limit) )
then 335 if ( step_limit > 0 )
then 336 step_limit_ = step_limit
338 step_limit_ = file_external_input_step_limit
341 step_limit_ = file_external_input_step_limit
344 do nid = 1, file_external_input_item_count
345 if ( file_external_input_item(nid)%varname == varname )
then 346 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'Data is already registered! basename,varname = ', trim(basename(1)),
', ', trim(varname)
351 file_external_input_item_count = file_external_input_item_count + 1
353 if ( file_external_input_item_count > file_external_input_item_limit )
then 354 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'Number of EXT data exceedes the limit', file_external_input_item_count, file_external_input_item_limit
363 call file_get_all_datainfo( fid, varname, &
365 description, unit, standard_name, &
367 dim_rank, dim_name(:), dim_size(:), &
368 natts, att_name(:), att_type(:), att_len(:), &
369 time_start(1:step_limit_), time_end(1:step_limit_), &
370 time_units, calendar )
372 if ( step_nmax > 0 )
then 373 if (
present(exist) )
then 377 if (
present(exist) )
then 381 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'Data not found! basename,varname = ', trim(basename(1)),
', ', trim(varname)
390 nid = file_external_input_item_count
393 if( basename(n) ==
'' )
exit 395 file_external_input_item(nid)%nfile = n - 1
396 file_external_input_item(nid)%file_current = 1
397 file_external_input_item(nid)%data_step_offset = 0
399 allocate( file_external_input_item(nid)%basename(file_external_input_item(nid)%nfile) )
400 file_external_input_item(nid)%basename(1:file_external_input_item(nid)%nfile) = basename(1:file_external_input_item(nid)%nfile)
403 file_external_input_item(nid)%fid = fid
404 file_external_input_item(nid)%varname = varname
405 file_external_input_item(nid)%dim_size(:) = dim_size(:)
406 file_external_input_item(nid)%step_num = step_nmax
407 file_external_input_item(nid)%step_limit = step_limit_
409 if ( enable_periodic_day )
then 410 file_external_input_item(nid)%flag_periodic = i_periodic_day
411 elseif( enable_periodic_month )
then 412 file_external_input_item(nid)%flag_periodic = i_periodic_month
413 elseif( enable_periodic_year )
then 414 file_external_input_item(nid)%flag_periodic = i_periodic_year
416 file_external_input_item(nid)%flag_periodic = 0
419 allocate( file_external_input_item(nid)%value(dim_size(1),dim_size(2),dim_size(3),2) )
420 file_external_input_item(nid)%value(:,:,:,:) = defval
421 file_external_input_item(nid)%offset = offset
423 allocate( file_external_input_item(nid)%time(step_limit_) )
424 file_external_input_item(nid)%time(:) = 0.0_dp
426 do n = 1, file_external_input_item(nid)%step_num
430 if ( file_external_input_item(nid)%step_num == 1 )
then 432 file_external_input_item(nid)%fixed_step = .true.
433 file_external_input_item(nid)%data_step_prev = 1
434 file_external_input_item(nid)%data_step_next = 1
436 else if ( step_fixed > 0 )
then 438 file_external_input_item(nid)%fixed_step = .true.
439 file_external_input_item(nid)%data_step_prev = step_fixed
440 file_external_input_item(nid)%data_step_next = step_fixed
444 file_external_input_item(nid)%fixed_step = .false.
447 file_external_input_item(nid)%data_step_next = 1
448 do n = 1, file_external_input_item(nid)%step_num
449 if ( file_external_input_item(nid)%time(n) >
time_nowdaysec )
exit 450 file_external_input_item(nid)%data_step_next = n + 1
453 file_external_input_item(nid)%data_step_prev = file_external_input_item(nid)%data_step_next - 1
455 if ( file_external_input_item(nid)%flag_periodic > 0 )
then 457 if ( file_external_input_item(nid)%data_step_next == 1 )
then 460 file_external_input_item(nid)%data_step_prev = file_external_input_item(nid)%step_num
462 elseif( file_external_input_item(nid)%data_step_next == file_external_input_item(nid)%step_num+1 )
then 465 file_external_input_item(nid)%data_step_next = 1
468 do n = 1, file_external_input_item(nid)%step_num
470 datasec = file_external_input_item(nid)%time(n)
480 if ( file_external_input_item(nid)%flag_periodic == i_periodic_day )
then 482 elseif( file_external_input_item(nid)%flag_periodic == i_periodic_month )
then 484 elseif( file_external_input_item(nid)%flag_periodic == i_periodic_year )
then 497 log_info(
"FILE_EXTERNAL_INPUT_regist",*)
'data time is updated.' 502 if ( file_external_input_item(nid)%data_step_next == 1 &
503 .OR. file_external_input_item(nid)%data_step_next == file_external_input_item(nid)%step_num+1 )
then 504 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'Current time is out of period of external data! ', trim(varname)
513 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A15)')
'Initial read of external data : ', trim(varname)
515 if ( dim_size(1) >= 1 &
516 .AND. dim_size(2) == 1 &
517 .AND. dim_size(3) == 1 )
then 522 file_external_input_item(nid)%ndim = 1
523 file_external_input_item(nid)%transpose = .false.
524 allocate( file_external_input_item(nid)%dim_start(1) )
525 file_external_input_item(nid)%dim_start(1) = dim1_s
527 if ( dim1_max /= dim_size(1) )
then 528 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'data length does not match! ', trim(axistype),
' item:', trim(varname)
529 log_error_cont(*)
'dim 1 (data,requested) : ', dim_size(1), dim1_max
534 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
535 'Read 1D var : ', trim(file_external_input_item(nid)%varname), &
536 ' (step= ', file_external_input_item(nid)%data_step_prev,
')' 538 call file_read( file_external_input_item(nid)%fid, &
539 file_external_input_item(nid)%varname, &
540 file_external_input_item(nid)%value(:,1,1,i_prev), &
541 step=file_external_input_item(nid)%data_step_prev )
543 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
544 'Read 1D var : ', trim(file_external_input_item(nid)%varname), &
545 ' (step= ', file_external_input_item(nid)%data_step_next,
')' 547 call file_read( file_external_input_item(nid)%fid, &
548 file_external_input_item(nid)%varname, &
549 file_external_input_item(nid)%value(:,1,1,i_next), &
550 step=file_external_input_item(nid)%data_step_next )
552 elseif( dim_size(1) >= 1 &
553 .AND. dim_size(2) > 1 &
554 .AND. dim_size(3) == 1 )
then 557 dim2_max, dim2_s, dim2_e, &
558 file_external_input_item(nid)%transpose, &
561 file_external_input_item(nid)%ndim = 2
562 allocate( file_external_input_item(nid)%dim_start(2) )
563 file_external_input_item(nid)%dim_start(1) = dim1_s
564 file_external_input_item(nid)%dim_start(2) = dim2_s
566 if ( dim1_max /= dim_size(1) &
567 .OR. dim2_max /= dim_size(2) )
then 568 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'data length does not match! ', trim(axistype),
' item:', trim(varname)
569 log_error_cont(*)
'dim 1 (data,requested) : ', dim_size(1), dim1_max
570 log_error_cont(*)
'dim 2 (data,requested) : ', dim_size(2), dim2_max
575 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
576 'Read 2D var : ', trim(file_external_input_item(nid)%varname), &
577 ' (step= ', file_external_input_item(nid)%data_step_prev,
')' 579 call file_read( file_external_input_item(nid)%fid, &
580 file_external_input_item(nid)%varname, &
581 file_external_input_item(nid)%value(:,:,1,i_prev), &
582 step=file_external_input_item(nid)%data_step_prev )
584 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
585 'Read 2D var : ', trim(file_external_input_item(nid)%varname), &
586 ' (step= ', file_external_input_item(nid)%data_step_next,
')' 588 call file_read( file_external_input_item(nid)%fid, &
589 file_external_input_item(nid)%varname, &
590 file_external_input_item(nid)%value(:,:,1,i_next), &
591 step=file_external_input_item(nid)%data_step_next )
593 elseif( dim_size(1) >= 1 &
594 .AND. dim_size(2) > 1 &
595 .AND. dim_size(3) > 1 )
then 598 dim2_max, dim2_s, dim2_e, &
599 dim3_max, dim3_s, dim3_e, &
600 file_external_input_item(nid)%transpose, &
603 file_external_input_item(nid)%ndim = 3
604 allocate( file_external_input_item(nid)%dim_start(3) )
605 file_external_input_item(nid)%dim_start(1) = dim1_s
606 file_external_input_item(nid)%dim_start(2) = dim2_s
607 file_external_input_item(nid)%dim_start(3) = dim3_s
609 if ( dim1_max /= dim_size(1) &
610 .OR. dim2_max /= dim_size(2) &
611 .OR. dim3_max /= dim_size(3) )
then 612 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'data length does not match! ', trim(axistype),
' item:', trim(varname)
613 log_error_cont(*)
'dim 1 (data,requested) : ', dim_size(1), dim1_max
614 log_error_cont(*)
'dim 2 (data,requested) : ', dim_size(2), dim2_max
615 log_error_cont(*)
'dim 3 (data,requested) : ', dim_size(3), dim3_max
620 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
621 'Read 3D var : ', trim(file_external_input_item(nid)%varname), &
622 ' (step= ', file_external_input_item(nid)%data_step_prev,
')' 624 call file_read( file_external_input_item(nid)%fid, &
625 file_external_input_item(nid)%varname, &
626 file_external_input_item(nid)%value(:,:,:,i_prev), &
627 step=file_external_input_item(nid)%data_step_prev )
630 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
631 'Read 3D var : ', trim(file_external_input_item(nid)%varname), &
632 ' (step= ', file_external_input_item(nid)%data_step_next,
')' 634 call file_read( file_external_input_item(nid)%fid, &
635 file_external_input_item(nid)%varname, &
636 file_external_input_item(nid)%value(:,:,:,i_next), &
637 step=file_external_input_item(nid)%data_step_next )
640 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'Unexpected dimsize: ', dim_size(:)
644 if (
present(check_coordinates) )
then 645 if ( check_coordinates )
then 646 call file_cartesc_check_coordinates( fid, &
647 atmos = file_external_input_item(nid)%ndim==3, &
648 transpose = file_external_input_item(nid)%transpose )
667 character(len=*),
intent(in) :: varname
668 real(DP),
intent(in) :: time_current
669 real(RP),
intent(out) :: var(:)
670 logical,
intent(out) :: error
674 logical :: do_readfile
686 do n = 1, file_external_input_item_count
687 if( varname == file_external_input_item(n)%varname ) nid = n
691 log_info(
"FILE_EXTERNAL_INPUT_update_1D",*)
'Variable was not registered: ', trim(varname)
695 if ( file_external_input_item(nid)%ndim /= 1 )
then 696 log_error(
"FILE_EXTERNAL_INPUT_update_1D",*)
'Data is not 1D var: ', trim(file_external_input_item(nid)%varname)
700 call file_external_input_time_advance( nid, &
705 if ( do_readfile )
then 706 step_next = file_external_input_item(nid)%data_step_next - file_external_input_item(nid)%data_step_offset
708 log_info(
"FILE_EXTERNAL_INPUT_update_1D",
'(1x,A,A,A,I4,A,I4,A)') &
709 'Read 1D var : ', trim(file_external_input_item(nid)%varname), &
710 ' (step= ', file_external_input_item(nid)%data_step_next,
', file step=', step_next,
')' 713 file_external_input_item(nid)%value(:,:,:,i_prev) = file_external_input_item(nid)%value(:,:,:,i_next)
716 call file_read( file_external_input_item(nid)%fid, &
717 file_external_input_item(nid)%varname, &
718 file_external_input_item(nid)%value(:,1,1,i_next), &
723 do n1 = 1, file_external_input_item(nid)%dim_size(1)
724 nn1 = n1 + file_external_input_item(nid)%dim_start(1) - 1
726 var(nn1) = ( 1.0_rp-weight ) * file_external_input_item(nid)%value(n1,1,1,i_prev) &
727 + ( weight ) * file_external_input_item(nid)%value(n1,1,1,i_next)
745 character(len=*),
intent(in) :: varname
746 real(DP),
intent(in) :: time_current
747 real(RP),
intent(out) :: var(:,:)
748 logical,
intent(out) :: error
752 logical :: do_readfile
764 do n = 1, file_external_input_item_count
765 if( varname == file_external_input_item(n)%varname ) nid = n
769 log_info(
"FILE_EXTERNAL_INPUT_update_2D",*)
'Variable was not registered: ', trim(varname)
773 call file_external_input_time_advance( nid, &
778 if ( do_readfile )
then 780 step_next = file_external_input_item(nid)%data_step_next - file_external_input_item(nid)%data_step_offset
782 log_info(
"FILE_EXTERNAL_INPUT_update_2D",
'(1x,A,A,A,I4,A,I4,A)') &
783 'Read 2D var : ', trim(file_external_input_item(nid)%varname), &
784 ' (step= ', file_external_input_item(nid)%data_step_next,
', file step=', step_next,
')' 787 file_external_input_item(nid)%value(:,:,:,i_prev) = file_external_input_item(nid)%value(:,:,:,i_next)
790 call file_read( file_external_input_item(nid)%fid, &
791 file_external_input_item(nid)%varname, &
792 file_external_input_item(nid)%value(:,:,1,i_next), &
796 if ( file_external_input_item(nid)%transpose )
then 798 do n1 = 1, file_external_input_item(nid)%dim_size(1)
799 nn1 = n1 + file_external_input_item(nid)%dim_start(1) - 1
801 do n2 = 1, file_external_input_item(nid)%dim_size(2)
802 nn2 = n2 + file_external_input_item(nid)%dim_start(2) - 1
804 var(nn2,nn1) = ( 1.0_rp-weight ) * file_external_input_item(nid)%value(n1,n2,1,i_prev) &
805 + ( weight ) * file_external_input_item(nid)%value(n1,n2,1,i_next)
810 do n2 = 1, file_external_input_item(nid)%dim_size(2)
811 nn2 = n2 + file_external_input_item(nid)%dim_start(2) - 1
813 do n1 = 1, file_external_input_item(nid)%dim_size(1)
814 nn1 = n1 + file_external_input_item(nid)%dim_start(1) - 1
816 var(nn1,nn2) = ( 1.0_rp-weight ) * file_external_input_item(nid)%value(n1,n2,1,i_prev) &
817 + ( weight ) * file_external_input_item(nid)%value(n1,n2,1,i_next)
837 character(len=*),
intent(in) :: varname
838 real(DP),
intent(in) :: time_current
839 real(RP),
intent(out) :: var(:,:,:)
840 logical,
intent(out) :: error
844 logical :: do_readfile
848 integer :: n1, n2, n3
849 integer :: nn1, nn2, nn3
856 do n = 1, file_external_input_item_count
857 if( varname == file_external_input_item(n)%varname ) nid = n
861 log_info(
"FILE_EXTERNAL_INPUT_update_3D",*)
'Variable was not registered: ', trim(varname)
865 call file_external_input_time_advance( nid, &
870 if ( do_readfile )
then 872 step_next = file_external_input_item(nid)%data_step_next - file_external_input_item(nid)%data_step_offset
874 log_info(
"FILE_EXTERNAL_INPUT_update_3D",
'(1x,A,A,A,I4,A,I4,A)') &
875 'Read 3D var : ', trim(file_external_input_item(nid)%varname), &
876 ' (step= ', file_external_input_item(nid)%data_step_next,
', file step=', step_next,
')' 879 file_external_input_item(nid)%value(:,:,:,i_prev) = file_external_input_item(nid)%value(:,:,:,i_next)
882 call file_read( file_external_input_item(nid)%fid, &
883 file_external_input_item(nid)%varname, &
884 file_external_input_item(nid)%value(:,:,:,i_next), &
888 if ( file_external_input_item(nid)%transpose )
then 890 do n2 = 1, file_external_input_item(nid)%dim_size(2)
891 nn2 = n2 + file_external_input_item(nid)%dim_start(2) - 1
893 do n1 = 1, file_external_input_item(nid)%dim_size(1)
894 nn1 = n1 + file_external_input_item(nid)%dim_start(1) - 1
896 do n3 = 1, file_external_input_item(nid)%dim_size(3)
897 nn3 = n3 + file_external_input_item(nid)%dim_start(3) - 1
899 var(nn3,nn1,nn2) = ( 1.0_rp-weight ) * file_external_input_item(nid)%value(n1,n2,n3,i_prev) &
900 + ( weight ) * file_external_input_item(nid)%value(n1,n2,n3,i_next)
906 do n3 = 1, file_external_input_item(nid)%dim_size(3)
907 nn3 = n3 + file_external_input_item(nid)%dim_start(3) - 1
909 do n2 = 1, file_external_input_item(nid)%dim_size(2)
910 nn2 = n2 + file_external_input_item(nid)%dim_start(2) - 1
912 do n1 = 1, file_external_input_item(nid)%dim_size(1)
913 nn1 = n1 + file_external_input_item(nid)%dim_start(1) - 1
915 var(nn1,nn2,nn3) = ( 1.0_rp-weight ) * file_external_input_item(nid)%value(n1,n2,n3,i_prev) &
916 + ( weight ) * file_external_input_item(nid)%value(n1,n2,n3,i_next)
929 subroutine file_external_input_time_advance( &
938 file_get_all_datainfo
956 integer,
intent(in) :: nid
957 real(DP),
intent(in) :: time_current
958 real(RP),
intent(out) :: weight
959 logical,
intent(out) :: do_readfile
962 character(len=H_MID) :: description
963 character(len=H_SHORT) :: unit
964 character(len=H_MID) :: standard_name
967 character(len=H_SHORT) :: dim_name (file_external_input_dim_limit)
968 integer :: dim_size (file_external_input_dim_limit)
970 character(len=H_SHORT) :: att_name (file_external_input_att_limit)
971 integer :: att_type (file_external_input_att_limit)
972 integer :: att_len (file_external_input_att_limit)
973 real(DP) :: time_start(file_external_input_step_limit)
974 real(DP) :: time_end (file_external_input_step_limit)
975 character(len=H_MID) :: time_units
976 character(len=H_SHORT) :: calendar
978 integer :: datadate(6)
979 real(DP) :: datasubsec
982 integer :: offset_year
984 real(DP) :: time_prev, time_next
985 integer :: step_prev, step_next
991 do_readfile = .false.
993 if ( file_external_input_item(nid)%fixed_step )
then 997 if ( time_current > file_external_input_item(nid)%time( file_external_input_item(nid)%data_step_next ) )
then 1001 log_info(
"FILE_EXTERNAL_INPUT_time_advance",
'(1x,A,A15)')
'Update external input : ', trim(file_external_input_item(nid)%varname)
1004 file_external_input_item(nid)%data_step_prev = file_external_input_item(nid)%data_step_prev + 1
1005 file_external_input_item(nid)%data_step_next = file_external_input_item(nid)%data_step_next + 1
1007 if ( file_external_input_item(nid)%flag_periodic > 0 )
then 1009 if ( file_external_input_item(nid)%data_step_next == file_external_input_item(nid)%step_num+1 )
then 1012 file_external_input_item(nid)%data_step_next = 1
1015 do t = 1, file_external_input_item(nid)%step_num
1017 datasec = file_external_input_item(nid)%time(t)
1027 if ( file_external_input_item(nid)%flag_periodic == i_periodic_day )
then 1029 elseif( file_external_input_item(nid)%flag_periodic == i_periodic_month )
then 1031 elseif( file_external_input_item(nid)%flag_periodic == i_periodic_year )
then 1047 if ( file_external_input_item(nid)%data_step_next == file_external_input_item(nid)%step_num+1 )
then 1049 if ( file_external_input_item(nid)%file_current < file_external_input_item(nid)%nfile )
then 1051 file_external_input_item(nid)%file_current = file_external_input_item(nid)%file_current + 1
1053 call file_open( file_external_input_item(nid)%basename(file_external_input_item(nid)%file_current), &
1058 call file_get_all_datainfo( fid, file_external_input_item(nid)%varname, &
1060 description, unit, standard_name, &
1062 dim_rank, dim_name(:), dim_size(:), &
1063 natts, att_name(:), att_type(:), att_len(:), &
1064 time_start(1:file_external_input_item(nid)%step_limit), &
1065 time_end(1:file_external_input_item(nid)%step_limit), &
1066 time_units, calendar )
1068 if ( step_nmax == 0 )
then 1069 log_error(
"FILE_EXTERNAL_INPUT_time_advance",*)
'Data not found! basename = ', trim(file_external_input_item(nid)%basename(file_external_input_item(nid)%file_current)), &
1070 ', varname = ', trim(file_external_input_item(nid)%varname)
1075 if ( file_external_input_item(nid)%dim_size(n) /= dim_size(n) )
then 1076 log_error(
"FILE_EXTERNAL_INPUT_time_advance",*)
'The size of dimension', n,
' is inconsistent! ' 1077 log_error_cont(*)
'size (previous,current) = ', file_external_input_item(nid)%dim_size(n), dim_size(n)
1078 log_error_cont(*)
'basename = ', trim(file_external_input_item(nid)%basename(file_external_input_item(nid)%file_current)), &
1079 ', varname = ', trim(file_external_input_item(nid)%varname)
1085 nn = file_external_input_item(nid)%step_num + n
1089 if ( file_external_input_item(nid)%time(file_external_input_item(nid)%data_step_prev) > file_external_input_item(nid)%time(file_external_input_item(nid)%data_step_next) )
then 1090 log_error(
"FILE_EXTERNAL_INPUT_time_advance",*)
'Time in new file is earlier than last time of previous file! stop' 1091 log_error_cont(*)
'Time (previous,current) = ', file_external_input_item(nid)%time(file_external_input_item(nid)%data_step_prev), &
1092 file_external_input_item(nid)%time(file_external_input_item(nid)%data_step_next)
1093 log_error_cont(*)
'Data not found! basename = ', trim(file_external_input_item(nid)%basename(file_external_input_item(nid)%file_current)), &
1094 ', varname = ', trim(file_external_input_item(nid)%varname)
1098 file_external_input_item(nid)%fid = fid
1099 file_external_input_item(nid)%data_step_offset = file_external_input_item(nid)%step_num
1100 file_external_input_item(nid)%step_num = file_external_input_item(nid)%step_num + step_nmax
1103 log_error(
"FILE_EXTERNAL_INPUT_time_advance",*)
'Current time is out of period of external data! ' 1116 if ( file_external_input_item(nid)%fixed_step )
then 1120 elseif( file_external_input_item(nid)%data_step_next == 1 )
then 1122 step_prev = file_external_input_item(nid)%data_step_prev
1123 step_next = file_external_input_item(nid)%data_step_next
1126 datasec = file_external_input_item(nid)%time( step_prev )
1136 if ( file_external_input_item(nid)%flag_periodic == i_periodic_day )
then 1138 elseif( file_external_input_item(nid)%flag_periodic == i_periodic_month )
then 1140 elseif( file_external_input_item(nid)%flag_periodic == i_periodic_year )
then 1151 time_next = file_external_input_item(nid)%time( step_next )
1153 weight = ( time_current - time_prev ) &
1154 / ( time_next - time_prev )
1158 step_prev = file_external_input_item(nid)%data_step_prev
1159 step_next = file_external_input_item(nid)%data_step_next
1161 time_prev = file_external_input_item(nid)%time( step_prev )
1162 time_next = file_external_input_item(nid)%time( step_next )
1164 weight = ( time_current - time_prev ) &
1165 / ( time_next - time_prev )
1170 end subroutine file_external_input_time_advance
integer, parameter, public i_month
[index] month
integer, parameter, public i_year
[index] year
real(dp) function, public calendar_combine_daysec(absday, abssec)
Combine day and second.
real(dp), public time_nowdaysec
second of current time [sec]
real(dp), public time_startdaysec
second of start time [sec]
integer, public io_fid_conf
Config file ID.
subroutine, public file_open(basename, fid, mode, single, aggregate, rankid, postfix)
real(rp), public const_undef
subroutine, public calendar_adjust_daysec(absday, abssec)
Adjust day and second.
integer, parameter, public file_fread
real(dp) function, public calendar_cfunits2sec(cftime, cfunits, offset_year, startdaysec)
Convert time in units of the CF convention to second.
integer, public time_offset_year
time offset [year]
integer, public prc_myrank
process num in local communicator
subroutine, public prc_abort
Abort Process.
integer, parameter, public i_day
[index] day
subroutine, public calendar_daysec2date(ymdhms, subsec, absday, abssec, offset_year)
Convert from gregorian date to absolute day/second.
subroutine, public calendar_date2daysec(absday, abssec, ymdhms, subsec, offset_year)
Convert from gregorian date to absolute day/second.