28 public :: file_external_input_regist
29 public :: file_external_input_update
30 public :: file_external_input_put_ref
31 public :: file_external_input_get_ref
35 interface file_external_input_regist
40 end interface file_external_input_regist
42 interface file_external_input_update
46 end interface file_external_input_update
48 interface file_external_input_put_ref
52 end interface file_external_input_put_ref
54 interface file_external_input_get_ref
56 module procedure file_external_input_get_ref_2d
57 module procedure file_external_input_get_ref_3d
58 end interface file_external_input_get_ref
61 subroutine get_dims1d( &
67 integer,
intent(out) :: dim1_size
68 integer,
intent(out) :: dim1_max
69 integer,
intent(out) :: dim1_S
70 character(len=*),
intent(in) :: varname
71 character(len=*),
intent(in) :: axistype
72 end subroutine get_dims1d
74 subroutine get_dims2d( &
84 integer,
intent(out) :: dim1_size
85 integer,
intent(out) :: dim1_max
86 integer,
intent(out) :: dim1_S
87 integer,
intent(out) :: dim2_size
88 integer,
intent(out) :: dim2_max
89 integer,
intent(out) :: dim2_S
90 logical,
intent(out) :: transpose
91 character(len=*),
intent(in) :: varname
92 character(len=*),
intent(in) :: axistype
93 end subroutine get_dims2d
95 subroutine get_dims3d( &
108 integer,
intent(out) :: dim1_size
109 integer,
intent(out) :: dim1_max
110 integer,
intent(out) :: dim1_S
111 integer,
intent(out) :: dim2_size
112 integer,
intent(out) :: dim2_max
113 integer,
intent(out) :: dim2_S
114 integer,
intent(out) :: dim3_size
115 integer,
intent(out) :: dim3_max
116 integer,
intent(out) :: dim3_S
117 logical,
intent(out) :: transpose
118 character(len=*),
intent(in) :: varname
119 character(len=*),
intent(in) :: axistype
120 end subroutine get_dims3d
122 subroutine read1d( fid, varname, dim_type, &
126 integer,
intent(in) :: fid
127 character(len=*),
intent(in) :: varname
128 character(len=*),
intent(in) :: dim_type
129 real(RP),
intent(out) :: var(:)
130 integer,
intent(in),
optional :: step
131 end subroutine read1d
133 subroutine read2d( fid, varname, dim_type, &
137 integer,
intent(in) :: fid
138 character(len=*),
intent(in) :: varname
139 character(len=*),
intent(in) :: dim_type
140 real(RP),
intent(out) :: var(:,:)
141 integer,
intent(in),
optional :: step
142 end subroutine read2d
144 subroutine read3d( fid, varname, dim_type, &
148 integer,
intent(in) :: fid
149 character(len=*),
intent(in) :: varname
150 character(len=*),
intent(in) :: dim_type
151 real(RP),
intent(out) :: var(:,:,:)
152 integer,
intent(in),
optional :: step
153 end subroutine read3d
181 private :: file_external_input_query_id
182 private :: file_external_input_time_advance
183 private :: file_external_input_init_var
184 private :: file_external_input_regist_var
190 integer,
private,
parameter :: i_periodic_year = 1
191 integer,
private,
parameter :: i_periodic_month = 2
192 integer,
private,
parameter :: i_periodic_day = 3
194 integer,
private,
parameter :: file_external_input_item_limit = 1000
195 integer,
private,
parameter :: file_external_input_step_limit = 10000
196 integer,
private,
parameter :: file_external_input_dim_limit = 3
197 integer,
private,
parameter :: file_external_input_att_limit = 10
199 type,
private :: itemcontainer
200 character(len=H_SHORT) :: varname
203 integer :: file_current
204 character(len=H_LONG),
allocatable :: basename(:)
207 integer :: dim_size(file_external_input_dim_limit)
208 integer :: dim_start(file_external_input_dim_limit)
209 integer :: dim_max(file_external_input_dim_limit)
210 integer :: var_size(file_external_input_dim_limit)
211 integer :: var_start(file_external_input_dim_limit)
212 integer :: var_max(file_external_input_dim_limit)
213 integer :: step_limit
215 real(
dp),
allocatable :: time(:)
216 logical :: fixed_step
217 integer :: flag_periodic
218 integer :: data_step_prev
219 integer :: data_step_next
220 integer :: data_step_offset
221 real(
rp),
allocatable ::
value(:,:,:,:)
222 character(len=H_SHORT) :: axistype
225 logical :: allow_missing
226 end type itemcontainer
228 integer,
private :: file_external_input_item_count = 0
229 type(itemcontainer),
private :: file_external_input_item(file_external_input_item_limit)
244 character(len=H_LONG) :: basename
245 logical :: basename_add_num
246 integer :: number_of_files
247 character(len=H_SHORT) :: varname
248 character(len=H_SHORT) :: axistype
249 integer :: step_limit
250 integer :: step_fixed
251 logical :: enable_periodic_year
252 logical :: enable_periodic_month
253 logical :: enable_periodic_day
255 logical :: check_coordinates
257 logical :: allow_missing
259 namelist / external_item / &
267 enable_periodic_year, &
268 enable_periodic_month, &
269 enable_periodic_day, &
280 log_info(
"FILE_EXTERNAL_INPUT_setup",*)
'Setup'
284 do count = 1, file_external_input_item_limit
286 step_limit = file_external_input_step_limit
288 basename_add_num = .false.
293 enable_periodic_year = .false.
294 enable_periodic_month = .false.
295 enable_periodic_day = .false.
297 check_coordinates = .false.
299 allow_missing = .false.
305 elseif( ierr > 0 )
then
306 log_error(
"FILE_EXTERNAL_INPUT_setup",*)
'Not appropriate names in namelist EXTERNAL_ITEM. Check!', count
309 log_nml(external_item)
311 call file_external_input_regist( basename, &
316 enable_periodic_year, &
317 enable_periodic_month, &
318 enable_periodic_day, &
321 check_coordinates = check_coordinates, &
323 allow_missing = allow_missing, &
324 step_limit = step_limit )
340 log_info(
"FILE_EXTERNAL_INPUT_finalize",*)
'Finalize'
342 do id = 1, file_external_input_item_count
344 deallocate( file_external_input_item(id)%value )
345 deallocate( file_external_input_item(id)%time )
346 if (
allocated( file_external_input_item(id)%basename ) ) &
347 deallocate( file_external_input_item(id)%basename )
351 file_external_input_item_count = 0
358 subroutine file_external_input_init_var( &
366 character(len=*),
intent(in) :: varname
367 character(len=*),
intent(in) :: axistype
368 logical,
intent(in),
optional :: aggregate
369 logical,
intent(in),
optional :: allow_missing
371 logical :: aggregate_
372 logical :: allow_missing_
375 if (
present(aggregate) )
then
376 aggregate_ = aggregate
381 if (
present(allow_missing) )
then
382 allow_missing_ = allow_missing
384 allow_missing_ = .false.
389 log_error(
"FILE_EXTERNAL_INPUT_init_var",*)
'Data is already registered! varname = ', trim(varname)
393 file_external_input_item_count = file_external_input_item_count + 1
395 if ( file_external_input_item_count > file_external_input_item_limit )
then
396 log_error(
"FILE_EXTERNAL_INPUT_init_var",*)
'Number of EXT data exceedes the limit', file_external_input_item_count, file_external_input_item_limit
400 nid = file_external_input_item_count
403 file_external_input_item(nid)%varname = varname
404 file_external_input_item(nid)%axistype = axistype
405 file_external_input_item(nid)%allow_missing = allow_missing_
406 file_external_input_item(nid)%aggregate = aggregate_
407 file_external_input_item(nid)%fixed_step = .false.
408 file_external_input_item(nid)%flag_periodic = 0
409 file_external_input_item(nid)%file = .false.
412 end subroutine file_external_input_init_var
416 subroutine file_external_input_regist_var( &
429 character(len=*),
intent(in) :: varname
430 character(len=*),
intent(in) :: axistype
431 integer,
intent(in) :: dim_rank
432 integer,
intent(in) :: dim_size(dim_rank)
433 integer,
intent(in) :: step_num
434 integer,
intent(in) :: file_num
435 real(
dp),
intent(in) :: time_now
436 real(
dp),
intent(in) :: time_step
437 real(
rp),
intent(in) :: defval
439 integer :: dim1_size, dim1_max, dim1_s
440 integer :: dim2_size, dim2_max, dim2_s
441 integer :: dim3_size, dim3_max, dim3_s
448 select case ( dim_rank )
455 if ( file_external_input_item(nid)%aggregate &
456 .or. ( .not. file_external_input_item(nid)%file ) )
then
457 file_external_input_item(nid)%var_size (1) = dim1_size
458 file_external_input_item(nid)%var_start(1) = dim1_s
459 file_external_input_item(nid)%var_max (1) = dim1_max
461 if ( dim1_max /= dim_size(1) )
then
462 log_error(
"FILE_EXTERNAL_INPUT_regist_var",*)
'data length does not match! ', trim(axistype),
' item:', trim(varname)
463 log_error_cont(*)
'dim 1 (data,requested) : ', dim_size(1), dim1_max
466 file_external_input_item(nid)%var_size (1) = dim1_max
467 file_external_input_item(nid)%var_start(1) = 1
468 file_external_input_item(nid)%var_max (1) = dim1_max
471 file_external_input_item(nid)%transpose = .false.
472 file_external_input_item(nid)%dim_size (1) = dim1_size
473 file_external_input_item(nid)%dim_start(1) = dim1_s
474 file_external_input_item(nid)%dim_max (1) = dim1_max
479 dim2_size, dim2_max, dim2_s, &
480 file_external_input_item(nid)%transpose, &
483 if ( file_external_input_item(nid)%aggregate &
484 .or. ( .not. file_external_input_item(nid)%file ) )
then
485 file_external_input_item(nid)%var_size (1) = dim1_size
486 file_external_input_item(nid)%var_start(1) = dim1_s
487 file_external_input_item(nid)%var_max (1) = dim1_max
488 file_external_input_item(nid)%var_size (2) = dim2_size
489 file_external_input_item(nid)%var_start(2) = dim2_s
490 file_external_input_item(nid)%var_max (2) = dim2_max
492 if ( dim1_max /= dim_size(1) .OR. dim2_max /= dim_size(2) )
then
493 log_error(
"FILE_EXTERNAL_INPUT_regist_var",*)
'data length does not match! ', trim(axistype),
' item:', trim(varname)
494 log_error_cont(*)
'dim 1 (data,requested) : ', dim_size(1), dim1_max
495 log_error_cont(*)
'dim 2 (data,requested) : ', dim_size(2), dim2_max
498 file_external_input_item(nid)%var_size (1) = dim1_max
499 file_external_input_item(nid)%var_start(1) = 1
500 file_external_input_item(nid)%var_max (1) = dim1_max
501 file_external_input_item(nid)%var_size (2) = dim2_max
502 file_external_input_item(nid)%var_start(2) = 1
503 file_external_input_item(nid)%var_max (2) = dim2_max
506 if ( file_external_input_item(nid)%transpose )
then
507 file_external_input_item(nid)%dim_size (1) = dim2_size
508 file_external_input_item(nid)%dim_start(1) = dim2_s
509 file_external_input_item(nid)%dim_max (1) = dim2_max
510 file_external_input_item(nid)%dim_size (2) = dim1_size
511 file_external_input_item(nid)%dim_start(2) = dim1_s
512 file_external_input_item(nid)%dim_max (2) = dim1_max
514 file_external_input_item(nid)%dim_size (1) = dim1_size
515 file_external_input_item(nid)%dim_start(1) = dim1_s
516 file_external_input_item(nid)%dim_max (1) = dim1_max
517 file_external_input_item(nid)%dim_size (2) = dim2_size
518 file_external_input_item(nid)%dim_start(2) = dim2_s
519 file_external_input_item(nid)%dim_max (2) = dim2_max
526 dim2_size, dim2_max, dim2_s, &
527 dim3_size, dim3_max, dim3_s, &
528 file_external_input_item(nid)%transpose, &
531 if ( file_external_input_item(nid)%aggregate &
532 .or. ( .not. file_external_input_item(nid)%file ) )
then
533 file_external_input_item(nid)%var_size (1) = dim1_size
534 file_external_input_item(nid)%var_start(1) = dim1_s
535 file_external_input_item(nid)%var_max (1) = dim1_max
536 file_external_input_item(nid)%var_size (2) = dim2_size
537 file_external_input_item(nid)%var_start(2) = dim2_s
538 file_external_input_item(nid)%var_max (2) = dim2_max
539 file_external_input_item(nid)%var_size (3) = dim3_size
540 file_external_input_item(nid)%var_start(3) = dim3_s
541 file_external_input_item(nid)%var_max (3) = dim3_max
543 if ( dim1_max /= dim_size(1) .OR. dim2_max /= dim_size(2) .OR. dim3_max /= dim_size(3) )
then
544 log_error(
"FILE_EXTERNAL_INPUT_regist_var",*)
'data length does not match! ', trim(axistype),
' item:', trim(varname)
545 log_error_cont(*)
'dim 1 (data,requested) : ', dim_size(1), dim1_max
546 log_error_cont(*)
'dim 2 (data,requested) : ', dim_size(2), dim2_max
547 log_error_cont(*)
'dim 3 (data,requested) : ', dim_size(3), dim3_max
550 file_external_input_item(nid)%var_size (1) = dim1_max
551 file_external_input_item(nid)%var_start(1) = 1
552 file_external_input_item(nid)%var_max (1) = dim1_max
553 file_external_input_item(nid)%var_size (2) = dim2_max
554 file_external_input_item(nid)%var_start(2) = 1
555 file_external_input_item(nid)%var_max (2) = dim2_max
556 file_external_input_item(nid)%var_size (3) = dim3_max
557 file_external_input_item(nid)%var_start(3) = 1
558 file_external_input_item(nid)%var_max (3) = dim3_max
561 if ( file_external_input_item(nid)%transpose )
then
562 file_external_input_item(nid)%dim_size (1) = dim3_size
563 file_external_input_item(nid)%dim_start(1) = dim3_s
564 file_external_input_item(nid)%dim_max (1) = dim3_max
565 file_external_input_item(nid)%dim_size (2) = dim1_size
566 file_external_input_item(nid)%dim_start(2) = dim1_s
567 file_external_input_item(nid)%dim_max (2) = dim1_max
568 file_external_input_item(nid)%dim_size (3) = dim2_size
569 file_external_input_item(nid)%dim_start(3) = dim2_s
570 file_external_input_item(nid)%dim_max (3) = dim2_max
572 file_external_input_item(nid)%dim_size (1) = dim1_size
573 file_external_input_item(nid)%dim_start(1) = dim1_s
574 file_external_input_item(nid)%dim_max (1) = dim1_max
575 file_external_input_item(nid)%dim_size (2) = dim2_size
576 file_external_input_item(nid)%dim_start(2) = dim2_s
577 file_external_input_item(nid)%dim_max (2) = dim2_max
578 file_external_input_item(nid)%dim_size (3) = dim3_size
579 file_external_input_item(nid)%dim_start(3) = dim3_s
580 file_external_input_item(nid)%dim_max (3) = dim3_max
584 log_error(
"FILE_EXTERNAL_INPUT_regist_var",*)
'Unexpected dim rank: ', dim_rank
589 file_external_input_item(nid)%dim_size (n) = 1
590 file_external_input_item(nid)%dim_start(n) = 1
591 file_external_input_item(nid)%dim_max (n) = 0
592 file_external_input_item(nid)%var_size (n) = 1
593 file_external_input_item(nid)%var_start(n) = 1
594 file_external_input_item(nid)%var_max (n) = 0
598 file_external_input_item(nid)%ndim = dim_rank
599 file_external_input_item(nid)%step_num = step_num
602 allocate( file_external_input_item(nid)%value(file_external_input_item(nid)%dim_size(1),file_external_input_item(nid)%dim_size(2),file_external_input_item(nid)%dim_size(3),2) )
603 file_external_input_item(nid)%value(:,:,:,:) = defval
606 allocate( file_external_input_item(nid)%time(step_num*file_num) )
607 do n = 1, file_external_input_item(nid)%step_num*file_num
608 file_external_input_item(nid)%time(n) = time_step * ( n - 1 ) + time_now
611 file_external_input_item(nid)%data_step_prev = 1
612 file_external_input_item(nid)%data_step_next = 2
615 end subroutine file_external_input_regist_var
631 character(len=*),
intent(in) :: varname
632 real(RP),
intent(in) :: var(:)
633 character(len=*),
intent(in) :: axistype
634 integer,
intent(in) :: step_nmax
635 real(DP),
intent(in) :: time_now
636 real(DP),
intent(in) :: time_step
637 logical,
intent(in),
optional :: aggregate
638 logical,
intent(in),
optional :: allow_missing
640 integer :: dim_size(1)
644 call file_external_input_init_var( &
650 dim_size(:) = shape( var )
652 call file_external_input_regist_var( &
685 character(len=*),
intent(in) :: varname
686 real(RP),
intent(in) :: var(:,:)
687 character(len=*),
intent(in) :: axistype
688 integer,
intent(in) :: step_nmax
689 real(DP),
intent(in) :: time_now
690 real(DP),
intent(in) :: time_step
691 logical,
intent(in),
optional :: aggregate
692 logical,
intent(in),
optional :: allow_missing
694 integer :: dim_size(2)
698 call file_external_input_init_var( &
704 dim_size(:) = shape( var )
706 call file_external_input_regist_var( &
739 character(len=*),
intent(in) :: varname
740 real(RP),
intent(in) :: var(:,:,:)
741 character(len=*),
intent(in) :: axistype
742 integer,
intent(in) :: step_nmax
743 real(DP),
intent(in) :: time_now
744 real(DP),
intent(in) :: time_step
745 logical,
intent(in),
optional :: aggregate
746 logical,
intent(in),
optional :: allow_missing
748 integer :: dim_size(3)
752 call file_external_input_init_var( &
758 dim_size(:) = shape( var )
760 call file_external_input_regist_var( &
787 enable_periodic_year, &
788 enable_periodic_month, &
789 enable_periodic_day, &
803 file_get_all_datainfo, &
822 file_cartesc_check_coordinates
825 character(len=*),
intent(in) :: basename
826 logical,
intent(in) :: basename_add_num
827 integer,
intent(in) :: number_of_files
828 character(len=*),
intent(in) :: varname
829 character(len=*),
intent(in) :: axistype
830 integer,
intent(in) :: step_fixed
831 logical,
intent(in) :: enable_periodic_year
832 logical,
intent(in) :: enable_periodic_month
833 logical,
intent(in) :: enable_periodic_day
834 real(RP),
intent(in) :: defval
836 logical,
intent(in),
optional :: check_coordinates
837 logical,
intent(in),
optional :: aggregate
838 logical,
intent(in),
optional :: allow_missing
839 integer,
intent(in),
optional :: step_limit
840 real(DP),
intent(out),
optional :: update_dt
841 logical,
intent(out),
optional :: exist
844 character(len=H_MID) :: description
845 character(len=H_SHORT) :: unit
846 character(len=H_MID) :: standard_name
849 character(len=H_SHORT) :: dim_name (FILE_EXTERNAL_INPUT_dim_limit)
850 integer :: dim_size (FILE_EXTERNAL_INPUT_dim_limit)
852 character(len=H_SHORT) :: att_name (FILE_EXTERNAL_INPUT_att_limit)
853 integer :: att_type (FILE_EXTERNAL_INPUT_att_limit)
854 integer :: att_len (FILE_EXTERNAL_INPUT_att_limit)
855 real(DP) :: time_start(FILE_EXTERNAL_INPUT_step_limit)
856 real(DP) :: time_end (FILE_EXTERNAL_INPUT_step_limit)
857 character(len=H_MID) :: time_units
858 character(len=H_SHORT) :: calendar
860 integer :: datadate(6)
861 real(DP) :: datasubsec
864 integer :: offset_year
866 character(len=H_LONG) :: filename
868 logical :: aggregate_
869 integer :: step_limit_
871 real(RP),
allocatable :: buf(:,:,:)
879 if (
present(aggregate) )
then
880 aggregate_ = aggregate
885 if (
present(step_limit) )
then
886 if ( step_limit > 0 )
then
887 step_limit_ = step_limit
889 step_limit_ = file_external_input_step_limit
892 step_limit_ = file_external_input_step_limit
895 call file_external_input_init_var( &
902 nid = file_external_input_item_count
904 file_external_input_item(nid)%file = .true.
905 file_external_input_item(nid)%nfile = number_of_files
906 file_external_input_item(nid)%file_current = 1
907 file_external_input_item(nid)%data_step_offset = 0
908 file_external_input_item(nid)%step_limit = step_limit_
910 allocate( file_external_input_item(nid)%basename(number_of_files) )
911 if ( number_of_files > 1 .or. basename_add_num )
then
912 do n = 1, number_of_files
913 write(filename,
'(A,A,I5.5)') trim(basename),
'_', n - 1
914 file_external_input_item(nid)%basename(n) = filename
917 file_external_input_item(nid)%basename(1) = basename
921 filename = file_external_input_item(nid)%basename(1)
924 aggregate=aggregate_, &
928 call file_get_all_datainfo( fid, varname, &
930 description, unit, standard_name, &
932 dim_rank, dim_name(:), dim_size(:), &
933 natts, att_name(:), att_type(:), att_len(:), &
934 time_start(1:step_limit_), time_end(1:step_limit_), &
935 time_units, calendar )
937 if ( step_nmax > 0 )
then
938 if (
present(exist) )
then
942 if (
present(exist) )
then
946 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'Data not found! filename,varname = ', trim(filename),
', ', trim(varname)
955 file_external_input_item(nid)%fid = fid
957 if ( enable_periodic_day )
then
958 file_external_input_item(nid)%flag_periodic = i_periodic_day
959 elseif( enable_periodic_month )
then
960 file_external_input_item(nid)%flag_periodic = i_periodic_month
961 elseif( enable_periodic_year )
then
962 file_external_input_item(nid)%flag_periodic = i_periodic_year
965 call file_external_input_regist_var( &
975 do n = 1, file_external_input_item(nid)%step_num
979 if ( file_external_input_item(nid)%step_num == 1 )
then
981 file_external_input_item(nid)%fixed_step = .true.
982 file_external_input_item(nid)%data_step_prev = 1
983 file_external_input_item(nid)%data_step_next = 1
985 else if ( step_fixed > 0 )
then
987 file_external_input_item(nid)%fixed_step = .true.
988 file_external_input_item(nid)%data_step_prev = step_fixed
989 file_external_input_item(nid)%data_step_next = step_fixed
994 file_external_input_item(nid)%data_step_next = 1
995 do n = 1, file_external_input_item(nid)%step_num
996 if ( file_external_input_item(nid)%time(n) >
time_nowdaysec )
exit
997 file_external_input_item(nid)%data_step_next = n + 1
1000 file_external_input_item(nid)%data_step_prev = file_external_input_item(nid)%data_step_next - 1
1002 if ( file_external_input_item(nid)%flag_periodic > 0 )
then
1004 if ( file_external_input_item(nid)%data_step_next == 1 )
then
1007 file_external_input_item(nid)%data_step_prev = file_external_input_item(nid)%step_num
1009 elseif( 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 n = 1, file_external_input_item(nid)%step_num
1017 datasec = file_external_input_item(nid)%time(n)
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
1044 log_info(
"FILE_EXTERNAL_INPUT_regist",*)
'data time is updated.'
1049 if ( file_external_input_item(nid)%data_step_next == 1 &
1050 .OR. file_external_input_item(nid)%data_step_next == file_external_input_item(nid)%step_num+1 )
then
1051 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'Current time is out of period of external data! ', trim(varname)
1060 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A15)')
'Initial read of external data : ', trim(varname)
1062 allocate( buf(file_external_input_item(nid)%var_size(1),file_external_input_item(nid)%var_size(2),file_external_input_item(nid)%var_size(3)) )
1065 select case ( dim_rank )
1069 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
1070 'Read 1D var : ', trim(file_external_input_item(nid)%varname), &
1071 ' (step= ', file_external_input_item(nid)%data_step_prev,
')'
1073 if ( file_external_input_item(nid)%aggregate )
then
1075 file_external_input_item(nid)%varname, &
1076 file_external_input_item(nid)%axistype, &
1078 step=file_external_input_item(nid)%data_step_prev )
1080 call file_read( file_external_input_item(nid)%fid, &
1081 file_external_input_item(nid)%varname, &
1083 step=file_external_input_item(nid)%data_step_prev )
1091 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
1092 'Read 1D var : ', trim(file_external_input_item(nid)%varname), &
1093 ' (step= ', file_external_input_item(nid)%data_step_next,
')'
1095 if ( file_external_input_item(nid)%aggregate )
then
1097 file_external_input_item(nid)%varname, &
1098 file_external_input_item(nid)%axistype, &
1100 step=file_external_input_item(nid)%data_step_next )
1102 call file_read( file_external_input_item(nid)%fid, &
1103 file_external_input_item(nid)%varname, &
1105 step=file_external_input_item(nid)%data_step_next )
1115 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
1116 'Read 2D var : ', trim(file_external_input_item(nid)%varname), &
1117 ' (step= ', file_external_input_item(nid)%data_step_prev,
')'
1119 if ( file_external_input_item(nid)%aggregate )
then
1121 file_external_input_item(nid)%varname, &
1122 file_external_input_item(nid)%axistype, &
1124 step=file_external_input_item(nid)%data_step_prev )
1126 call file_read( file_external_input_item(nid)%fid, &
1127 file_external_input_item(nid)%varname, &
1129 step=file_external_input_item(nid)%data_step_prev )
1137 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
1138 'Read 2D var : ', trim(file_external_input_item(nid)%varname), &
1139 ' (step= ', file_external_input_item(nid)%data_step_next,
')'
1141 if ( file_external_input_item(nid)%aggregate )
then
1143 file_external_input_item(nid)%varname, &
1144 file_external_input_item(nid)%axistype, &
1146 step=file_external_input_item(nid)%data_step_next )
1148 call file_read( file_external_input_item(nid)%fid, &
1149 file_external_input_item(nid)%varname, &
1151 step=file_external_input_item(nid)%data_step_next )
1161 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
1162 'Read 3D var : ', trim(file_external_input_item(nid)%varname), &
1163 ' (step= ', file_external_input_item(nid)%data_step_prev,
')'
1165 if ( file_external_input_item(nid)%aggregate )
then
1167 file_external_input_item(nid)%varname, &
1168 file_external_input_item(nid)%axistype, &
1170 step=file_external_input_item(nid)%data_step_prev )
1172 call file_read( file_external_input_item(nid)%fid, &
1173 file_external_input_item(nid)%varname, &
1175 step=file_external_input_item(nid)%data_step_prev )
1183 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
1184 'Read 3D var : ', trim(file_external_input_item(nid)%varname), &
1185 ' (step= ', file_external_input_item(nid)%data_step_next,
')'
1187 if ( file_external_input_item(nid)%aggregate )
then
1189 file_external_input_item(nid)%varname, &
1190 file_external_input_item(nid)%axistype, &
1192 step=file_external_input_item(nid)%data_step_next )
1194 call file_read( file_external_input_item(nid)%fid, &
1195 file_external_input_item(nid)%varname, &
1197 step=file_external_input_item(nid)%data_step_next )
1205 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'Unexpected dim rank: ', dim_rank
1213 if (
present(check_coordinates) )
then
1214 if ( check_coordinates )
then
1215 call file_cartesc_check_coordinates( fid, &
1216 atmos = file_external_input_item(nid)%ndim==3, &
1217 transpose = file_external_input_item(nid)%transpose )
1222 if (
present(update_dt) )
then
1223 update_dt = file_external_input_item(nid)%time(file_external_input_item(nid)%data_step_next) &
1224 - file_external_input_item(nid)%time(file_external_input_item(nid)%data_step_prev)
1243 character(len=*),
intent(in) :: varname
1244 real(DP),
intent(in) :: time_current
1245 real(RP),
intent(out) :: var(:)
1246 logical,
intent(out) :: error
1250 logical :: do_readfile
1251 integer :: step_next
1253 real(RP),
allocatable :: buf(:)
1261 if ( nid == 0 )
then
1262 log_info(
"FILE_EXTERNAL_INPUT_update_1D",*)
'Variable was not registered: ', trim(varname)
1267 if ( file_external_input_item(nid)%ndim /= 1 )
then
1268 log_info(
"FILE_EXTERNAL_INPUT_update_1D",*)
'Data is not 1D var: ', trim(file_external_input_item(nid)%varname)
1273 call file_external_input_time_advance( nid, &
1278 if ( do_readfile )
then
1280 if ( file_external_input_item(nid)%file )
then
1282 step_next = file_external_input_item(nid)%data_step_next - file_external_input_item(nid)%data_step_offset
1284 log_info(
"FILE_EXTERNAL_INPUT_update_1D",
'(1x,A,A,A,I4,A,I4,A)') &
1285 'Read 1D var : ', trim(file_external_input_item(nid)%varname), &
1286 ' (step= ', file_external_input_item(nid)%data_step_next,
', file step=', step_next,
')'
1288 allocate( buf(file_external_input_item(nid)%var_size(1)) )
1292 if ( file_external_input_item(nid)%aggregate )
then
1294 file_external_input_item(nid)%varname, &
1295 file_external_input_item(nid)%axistype, &
1297 step=file_external_input_item(nid)%data_step_next )
1299 call file_read( file_external_input_item(nid)%fid, &
1300 file_external_input_item(nid)%varname, &
1320 n1s = file_external_input_item(nid)%dim_start(1)
1321 n1e = n1s - 1 + file_external_input_item(nid)%dim_max(1)
1326 if ( file_external_input_item(nid)%allow_missing )
then
1330 if ( abs( file_external_input_item(nid)%value(n1,1,1,
i_prev) - undef ) > eps &
1331 .and. abs( file_external_input_item(nid)%value(n1,1,1,
i_next) - undef ) > eps )
then
1332 var(n1) = ( 1.0_rp-weight ) * file_external_input_item(nid)%value(n1,1,1,
i_prev) &
1333 + ( weight ) * file_external_input_item(nid)%value(n1,1,1,
i_next)
1343 var(n1) = ( 1.0_rp-weight ) * file_external_input_item(nid)%value(n1,1,1,
i_prev) &
1344 + ( weight ) * file_external_input_item(nid)%value(n1,1,1,
i_next)
1367 character(len=*),
intent(in) :: varname
1368 real(DP),
intent(in) :: time_current
1369 real(RP),
intent(out) :: var(:,:)
1370 logical,
intent(out) :: error
1374 logical :: do_readfile
1375 integer :: step_next
1377 real(RP),
allocatable :: buf(:,:)
1379 integer :: n1s, n1e, n2s, n2e
1385 if ( nid == 0 )
then
1386 log_info(
"FILE_EXTERNAL_INPUT_update_2D",*)
'Variable was not registered: ', trim(varname)
1391 if ( file_external_input_item(nid)%ndim /= 2 )
then
1392 log_info(
"FILE_EXTERNAL_INPUT_update_2D",*)
'Data is not 2D var: ', trim(file_external_input_item(nid)%varname)
1397 call file_external_input_time_advance( nid, &
1402 if ( do_readfile )
then
1404 if ( file_external_input_item(nid)%file )
then
1406 step_next = file_external_input_item(nid)%data_step_next - file_external_input_item(nid)%data_step_offset
1408 log_info(
"FILE_EXTERNAL_INPUT_update_2D",
'(1x,A,A,A,I4,A,I4,A)') &
1409 'Read 2D var : ', trim(file_external_input_item(nid)%varname), &
1410 ' (step= ', file_external_input_item(nid)%data_step_next,
', file step=', step_next,
')'
1412 allocate( buf(file_external_input_item(nid)%var_size(1),file_external_input_item(nid)%var_size(2)) )
1416 if ( file_external_input_item(nid)%aggregate )
then
1418 file_external_input_item(nid)%varname, &
1419 file_external_input_item(nid)%axistype, &
1421 step=file_external_input_item(nid)%data_step_next )
1423 call file_read( file_external_input_item(nid)%fid, &
1424 file_external_input_item(nid)%varname, &
1443 n1s = file_external_input_item(nid)%dim_start(1)
1444 n1e = n1s - 1 + file_external_input_item(nid)%dim_max(1)
1445 n2s = file_external_input_item(nid)%dim_start(2)
1446 n2e = n2s - 1 + file_external_input_item(nid)%dim_max(2)
1451 if ( file_external_input_item(nid)%allow_missing )
then
1456 if ( abs( file_external_input_item(nid)%value(n1,n2,1,
i_prev) - undef ) > eps &
1457 .and. abs( file_external_input_item(nid)%value(n1,n2,1,
i_next) - undef ) > eps )
then
1458 var(n1,n2) = ( 1.0_rp-weight ) * file_external_input_item(nid)%value(n1,n2,1,
i_prev) &
1459 + ( weight ) * file_external_input_item(nid)%value(n1,n2,1,
i_next)
1471 var(n1,n2) = ( 1.0_rp-weight ) * file_external_input_item(nid)%value(n1,n2,1,
i_prev) &
1472 + ( weight ) * file_external_input_item(nid)%value(n1,n2,1,
i_next)
1496 character(len=*),
intent(in) :: varname
1497 real(DP),
intent(in) :: time_current
1498 real(RP),
intent(out) :: var(:,:,:)
1499 logical,
intent(out) :: error
1503 logical :: do_readfile
1504 integer :: step_next
1506 real(RP),
allocatable :: buf(:,:,:)
1508 integer :: n1s, n1e, n2s, n2e, n3s, n3e
1509 integer :: n1, n2, n3
1514 if ( nid == 0 )
then
1515 log_info(
"FILE_EXTERNAL_INPUT_update_3D",*)
'Variable was not registered: ', trim(varname)
1520 if ( file_external_input_item(nid)%ndim /= 3 )
then
1521 log_info(
"FILE_EXTERNAL_INPUT_update_3D",*)
'Data is not 3D var: ', trim(file_external_input_item(nid)%varname)
1526 call file_external_input_time_advance( nid, &
1531 if ( do_readfile )
then
1533 if ( file_external_input_item(nid)%file )
then
1535 step_next = file_external_input_item(nid)%data_step_next - file_external_input_item(nid)%data_step_offset
1537 log_info(
"FILE_EXTERNAL_INPUT_update_3D",
'(1x,A,A,A,I4,A,I4,A)') &
1538 'Read 3D var : ', trim(file_external_input_item(nid)%varname), &
1539 ' (step= ', file_external_input_item(nid)%data_step_next,
', file step=', step_next,
')'
1541 allocate( buf(file_external_input_item(nid)%var_size(1),file_external_input_item(nid)%var_size(2),file_external_input_item(nid)%var_size(3)) )
1545 if ( file_external_input_item(nid)%aggregate )
then
1547 file_external_input_item(nid)%varname, &
1548 file_external_input_item(nid)%axistype, &
1550 step=file_external_input_item(nid)%data_step_next )
1552 call file_read( file_external_input_item(nid)%fid, &
1553 file_external_input_item(nid)%varname, &
1572 n1s = file_external_input_item(nid)%dim_start(1)
1573 n1e = n1s - 1 + file_external_input_item(nid)%dim_max(1)
1574 n2s = file_external_input_item(nid)%dim_start(2)
1575 n2e = n2s - 1 + file_external_input_item(nid)%dim_max(2)
1576 n3s = file_external_input_item(nid)%dim_start(3)
1577 n3e = n3s - 1 + file_external_input_item(nid)%dim_max(3)
1582 if ( file_external_input_item(nid)%allow_missing )
then
1588 if ( abs( file_external_input_item(nid)%value(n1,n2,n3,
i_prev) - undef ) > eps &
1589 .and. abs( file_external_input_item(nid)%value(n1,n2,n3,
i_next) - undef ) > eps )
then
1590 var(n1,n2,n3) = ( 1.0_rp-weight ) * file_external_input_item(nid)%value(n1,n2,n3,
i_prev) &
1591 + ( weight ) * file_external_input_item(nid)%value(n1,n2,n3,
i_next)
1593 var(n1,n2,n3) = undef
1605 var(n1,n2,n3) = ( 1.0_rp-weight ) * file_external_input_item(nid)%value(n1,n2,n3,
i_prev) &
1606 + ( weight ) * file_external_input_item(nid)%value(n1,n2,n3,
i_next)
1628 character(len=*),
intent(in) :: varname
1629 real(RP),
intent(in) :: var(:)
1630 logical,
intent(out) :: error
1633 integer :: n1, nn1, nnn1
1637 if ( nid == 0 )
then
1638 log_info(
"FILE_EXTERNAL_INPUT_put_ref_1D",*)
'Variable was not registered: ', trim(varname)
1647 file_external_input_item(nid)%value(:,:,:,
i_prev) = file_external_input_item(nid)%value(:,:,:,
i_next)
1654 do n1 = 1, file_external_input_item(nid)%dim_max(1)
1655 nn1 = n1 + file_external_input_item(nid)%dim_start(1) - 1
1656 nnn1 = n1 + file_external_input_item(nid)%var_start(1) - 1
1657 if ( .not. file_external_input_item(nid)%allow_missing )
then
1658 if ( abs( var(nnn1) - undef ) < eps )
then
1659 log_warn(
"FILE_EXTERNAL_INPUT_put_ref_1D",*)
'missing value is found in ', &
1661 file_external_input_item(nid)%varname,
' at (',nnn1,
')'
1663 trim(file_external_input_item(nid)%varname),
' at (',nnn1,
')'
1668 file_external_input_item(nid)%value(nn1,1,1,
i_next) = var(nnn1)
1683 character(len=*),
intent(in) :: varname
1684 real(RP),
intent(in) :: var(:,:)
1685 logical,
intent(out) :: error
1688 integer :: n1, n2, nn1, nn2, nnn1, nnn2
1692 if ( nid == 0 )
then
1693 log_info(
"FILE_EXTERNAL_INPUT_put_var_2D",*)
'Variable was not registered: ', trim(varname)
1702 file_external_input_item(nid)%value(:,:,:,
i_prev) = file_external_input_item(nid)%value(:,:,:,
i_next)
1706 if ( file_external_input_item(nid)%transpose )
then
1711 do n2 = 1, file_external_input_item(nid)%dim_max(2)
1714 nn2 = n2 + file_external_input_item(nid)%dim_start(2) - 1
1715 nnn2 = n2 + file_external_input_item(nid)%var_start(1) - 1
1717 do n1 = 1, file_external_input_item(nid)%dim_max(1)
1719 nn2 = n2 + file_external_input_item(nid)%dim_start(2) - 1
1720 nnn2 = n2 + file_external_input_item(nid)%var_start(1) - 1
1722 nn1 = n1 + file_external_input_item(nid)%dim_start(1) - 1
1723 nnn1 = n1 + file_external_input_item(nid)%var_start(2) - 1
1724 if ( .not. file_external_input_item(nid)%allow_missing )
then
1725 if ( abs( var(nnn2,nnn1) - undef ) < eps )
then
1726 log_warn(
"FILE_EXTERNAL_INPUT_put_ref_2D",*)
'missing value is found in ', &
1728 file_external_input_item(nid)%varname,
' at (',nnn2,
',',nnn1,
')'
1730 trim(file_external_input_item(nid)%varname),
' at (',nnn2,
',',nnn1,
')'
1735 file_external_input_item(nid)%value(nn1,nn2,1,
i_next) = var(nnn2,nnn1)
1744 do n2 = 1, file_external_input_item(nid)%dim_max(2)
1747 nn2 = n2 + file_external_input_item(nid)%dim_start(2) - 1
1748 nnn2 = n2 + file_external_input_item(nid)%var_start(2) - 1
1750 do n1 = 1, file_external_input_item(nid)%dim_max(1)
1752 nn2 = n2 + file_external_input_item(nid)%dim_start(2) - 1
1753 nnn2 = n2 + file_external_input_item(nid)%var_start(2) - 1
1755 nn1 = n1 + file_external_input_item(nid)%dim_start(1) - 1
1756 nnn1 = n1 + file_external_input_item(nid)%var_start(1) - 1
1757 if ( .not. file_external_input_item(nid)%allow_missing )
then
1758 if ( abs( var(nnn2,nnn1) - undef ) < eps )
then
1759 log_warn(
"FILE_EXTERNAL_INPUT_put_ref_2D",*)
'missing value is found in ', &
1761 file_external_input_item(nid)%varname,
' at (',nnn1,
',',nnn2,
')'
1763 trim(file_external_input_item(nid)%varname),
' at (',nnn1,
',',nnn2,
')'
1768 file_external_input_item(nid)%value(nn1,nn2,1,
i_next) = var(nnn1,nnn2)
1785 character(len=*),
intent(in) :: varname
1786 real(RP),
intent(in) :: var(:,:,:)
1787 logical,
intent(out) :: error
1790 integer :: n1, n2, n3, nn1, nn2, nn3, nnn1, nnn2, nnn3
1794 if ( nid == 0 )
then
1795 log_info(
"FILE_EXTERNAL_INPUT_put_ref_3D",*)
'Variable was not registered: ', trim(varname)
1804 file_external_input_item(nid)%value(:,:,:,
i_prev) = file_external_input_item(nid)%value(:,:,:,
i_next)
1808 if ( file_external_input_item(nid)%transpose )
then
1813 do n3 = 1, file_external_input_item(nid)%dim_max(3)
1816 nn3 = n3 + file_external_input_item(nid)%dim_start(3) - 1
1817 nnn3 = n3 + file_external_input_item(nid)%var_start(2) - 1
1819 do n2 = 1, file_external_input_item(nid)%dim_max(2)
1822 nn2 = n2 + file_external_input_item(nid)%dim_start(2) - 1
1823 nnn2 = n2 + file_external_input_item(nid)%var_start(1) - 1
1825 do n1 = 1, file_external_input_item(nid)%dim_max(1)
1827 nn3 = n3 + file_external_input_item(nid)%dim_start(3) - 1
1828 nnn3 = n3 + file_external_input_item(nid)%var_start(2) - 1
1829 nn2 = n2 + file_external_input_item(nid)%dim_start(2) - 1
1830 nnn2 = n2 + file_external_input_item(nid)%var_start(1) - 1
1832 nn1 = n1 + file_external_input_item(nid)%dim_start(1) - 1
1833 nnn1 = n1 + file_external_input_item(nid)%var_start(3) - 1
1834 if ( .not. file_external_input_item(nid)%allow_missing )
then
1835 if ( abs( var(nnn2,nnn3,nnn1) - undef ) < eps )
then
1836 log_warn(
"FILE_EXTERNAL_INPUT_put_ref_3D",*)
'missing value is found in ', &
1838 file_external_input_item(nid)%varname,
' at (',nnn2,
',',nnn3,
',',nnn1,
')'
1840 trim(file_external_input_item(nid)%varname),
' at (',nnn2,
',',nnn3,
',',nnn1,
')'
1845 file_external_input_item(nid)%value(nn1,nn2,nn3,
i_next) = var(nnn2,nnn3,nnn1)
1855 do n3 = 1, file_external_input_item(nid)%dim_max(3)
1858 nn3 = n3 + file_external_input_item(nid)%dim_start(3) - 1
1859 nnn3 = n3 + file_external_input_item(nid)%var_start(3) - 1
1861 do n2 = 1, file_external_input_item(nid)%dim_max(2)
1864 nn2 = n2 + file_external_input_item(nid)%dim_start(2) - 1
1865 nnn2 = n2 + file_external_input_item(nid)%var_start(2) - 1
1867 do n1 = 1, file_external_input_item(nid)%dim_max(1)
1869 nn3 = n3 + file_external_input_item(nid)%dim_start(3) - 1
1870 nnn3 = n3 + file_external_input_item(nid)%var_start(3) - 1
1871 nn2 = n2 + file_external_input_item(nid)%dim_start(2) - 1
1872 nnn2 = n2 + file_external_input_item(nid)%var_start(2) - 1
1874 nn1 = n1 + file_external_input_item(nid)%dim_start(1) - 1
1875 nnn1 = n1 + file_external_input_item(nid)%var_start(1) - 1
1876 if ( .not. file_external_input_item(nid)%allow_missing )
then
1877 if ( abs( var(nnn1,nnn2,nnn3) - undef ) < eps )
then
1878 log_warn(
"FILE_EXTERNAL_INPUT_put_ref_3D",*)
'missing value is found in ', &
1880 file_external_input_item(nid)%varname,
' at (',nnn1,
',',nnn2,
',',nnn3,
')'
1882 trim(file_external_input_item(nid)%varname),
' at (',nnn1,
',',nnn2,
',',nnn3,
')'
1887 file_external_input_item(nid)%value(nn1,nn2,nn3,
i_next) = var(nnn1,nnn2,nnn3)
1905 character(len=*),
intent(in) :: varname
1906 real(RP),
intent(out) :: var(:)
1907 logical,
intent(out) :: error
1909 integer,
optional,
intent(in) :: i_step
1914 if (
present(i_step) )
then
1922 if ( nid == 0 )
then
1923 log_info(
"FILE_EXTERNAL_INPUT_get_ref_1D",*)
'Variable was not registered: ', trim(varname)
1932 var(:) = file_external_input_item(nid)%value(:,1,1,i_step_)
1939 subroutine file_external_input_get_ref_2d( &
1945 character(len=*),
intent(in) :: varname
1946 real(RP),
intent(out) :: var(:,:)
1947 logical,
intent(out) :: error
1949 integer,
optional,
intent(in) :: i_step
1954 if (
present(i_step) )
then
1962 if ( nid == 0 )
then
1963 log_info(
"FILE_EXTERNAL_INPUT_get_ref_2D",*)
'Variable was not registered: ', trim(varname)
1972 var(:,:) = file_external_input_item(nid)%value(:,:,1,i_step_)
1977 end subroutine file_external_input_get_ref_2d
1981 subroutine file_external_input_get_ref_3d( &
1987 character(len=*),
intent(in) :: varname
1988 real(RP),
intent(out) :: var(:,:,:)
1989 logical,
intent(out) :: error
1991 integer,
optional,
intent(in) :: i_step
1996 if (
present(i_step) )
then
2004 if ( nid == 0 )
then
2005 log_info(
"FILE_EXTERNAL_INPUT_get_ref_3D",*)
'Variable was not registered: ', trim(varname)
2014 var(:,:,:) = file_external_input_item(nid)%value(:,:,:,i_step_)
2019 end subroutine file_external_input_get_ref_3d
2028 character(len=*),
intent(in) :: varname
2029 real(
dp),
intent(in) :: time_current
2030 logical,
intent(out) :: do_readdata
2036 call file_external_input_query_id( nid, &
2043 subroutine file_external_input_query_id( &
2048 integer,
intent(in) :: nid
2049 real(
dp),
intent(in) :: time_current
2050 logical,
intent(out) :: do_readdata
2052 if ( ( .not. file_external_input_item(nid)%fixed_step ) &
2053 .and. ( time_current > file_external_input_item(nid)%time( file_external_input_item(nid)%data_step_next ) ) &
2055 do_readdata = .true.
2057 do_readdata = .false.
2061 end subroutine file_external_input_query_id
2065 subroutine file_external_input_time_advance( &
2074 file_get_all_datainfo
2092 integer,
intent(in) :: nid
2093 real(
dp),
intent(in) :: time_current
2094 real(
rp),
intent(out) :: weight
2095 logical,
intent(out) :: do_readdata
2097 integer :: step_nmax
2098 character(len=H_MID) :: description
2099 character(len=H_SHORT) :: unit
2100 character(len=H_MID) :: standard_name
2103 character(len=H_SHORT) :: dim_name (file_external_input_dim_limit)
2104 integer :: dim_size (file_external_input_dim_limit)
2106 character(len=H_SHORT) :: att_name (file_external_input_att_limit)
2107 integer :: att_type (file_external_input_att_limit)
2108 integer :: att_len (file_external_input_att_limit)
2109 real(
dp) :: time_start(file_external_input_step_limit)
2110 real(
dp) :: time_end (file_external_input_step_limit)
2111 character(len=H_MID) :: time_units
2112 character(len=H_SHORT) :: calendar
2114 integer :: datadate(6)
2115 real(
dp) :: datasubsec
2118 integer :: offset_year
2120 real(
dp) :: time_prev, time_next
2121 integer :: step_prev, step_next
2127 call file_external_input_query_id( nid, &
2131 if ( do_readdata )
then
2133 log_info(
"FILE_EXTERNAL_INPUT_time_advance",
'(1x,A,A15)')
'Update external input : ', trim(file_external_input_item(nid)%varname)
2136 file_external_input_item(nid)%data_step_prev = file_external_input_item(nid)%data_step_next
2137 file_external_input_item(nid)%data_step_next = file_external_input_item(nid)%data_step_next + 1
2139 if ( file_external_input_item(nid)%file )
then
2141 if ( file_external_input_item(nid)%flag_periodic > 0 )
then
2143 if ( file_external_input_item(nid)%data_step_next == file_external_input_item(nid)%step_num+1 )
then
2146 file_external_input_item(nid)%data_step_next = 1
2149 do t = 1, file_external_input_item(nid)%step_num
2151 datasec = file_external_input_item(nid)%time(t)
2161 if ( file_external_input_item(nid)%flag_periodic == i_periodic_day )
then
2163 elseif( file_external_input_item(nid)%flag_periodic == i_periodic_month )
then
2165 elseif( file_external_input_item(nid)%flag_periodic == i_periodic_year )
then
2181 if ( file_external_input_item(nid)%data_step_next == file_external_input_item(nid)%step_num+1 )
then
2183 if ( file_external_input_item(nid)%file_current < file_external_input_item(nid)%nfile )
then
2185 file_external_input_item(nid)%file_current = file_external_input_item(nid)%file_current + 1
2187 call file_open( file_external_input_item(nid)%basename(file_external_input_item(nid)%file_current), &
2192 call file_get_all_datainfo( fid, file_external_input_item(nid)%varname, &
2194 description, unit, standard_name, &
2196 dim_rank, dim_name(:), dim_size(:), &
2197 natts, att_name(:), att_type(:), att_len(:), &
2198 time_start(1:file_external_input_item(nid)%step_limit), &
2199 time_end(1:file_external_input_item(nid)%step_limit), &
2200 time_units, calendar )
2202 if ( step_nmax == 0 )
then
2203 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)), &
2204 ', varname = ', trim(file_external_input_item(nid)%varname)
2209 if ( file_external_input_item(nid)%var_size(n) /= dim_size(n) )
then
2210 log_error(
"FILE_EXTERNAL_INPUT_time_advance",*)
'The size of dimension', n,
' is inconsistent! '
2211 log_error_cont(*)
'size (previous,current) = ', file_external_input_item(nid)%var_size(n), dim_size(n)
2212 log_error_cont(*)
'basename = ', trim(file_external_input_item(nid)%basename(file_external_input_item(nid)%file_current)), &
2213 ', varname = ', trim(file_external_input_item(nid)%varname)
2219 nn = file_external_input_item(nid)%step_num + n
2223 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
2224 log_error(
"FILE_EXTERNAL_INPUT_time_advance",*)
'Time in new file is earlier than last time of previous file! stop'
2225 log_error_cont(*)
'Time (previous,current) = ', file_external_input_item(nid)%time(file_external_input_item(nid)%data_step_prev), &
2226 file_external_input_item(nid)%time(file_external_input_item(nid)%data_step_next)
2227 log_error_cont(*)
'Data not found! basename = ', trim(file_external_input_item(nid)%basename(file_external_input_item(nid)%file_current)), &
2228 ', varname = ', trim(file_external_input_item(nid)%varname)
2232 file_external_input_item(nid)%fid = fid
2233 file_external_input_item(nid)%data_step_offset = file_external_input_item(nid)%step_num
2234 file_external_input_item(nid)%step_num = file_external_input_item(nid)%step_num + step_nmax
2237 log_error(
"FILE_EXTERNAL_INPUT_time_advance",*)
'Current time is out of period of external data! '
2251 if ( file_external_input_item(nid)%fixed_step )
then
2255 elseif( file_external_input_item(nid)%data_step_next == 1 )
then
2257 step_prev = file_external_input_item(nid)%data_step_prev
2258 step_next = file_external_input_item(nid)%data_step_next
2261 datasec = file_external_input_item(nid)%time( step_prev )
2271 if ( file_external_input_item(nid)%flag_periodic == i_periodic_day )
then
2273 elseif( file_external_input_item(nid)%flag_periodic == i_periodic_month )
then
2275 elseif( file_external_input_item(nid)%flag_periodic == i_periodic_year )
then
2286 time_next = file_external_input_item(nid)%time( step_next )
2288 weight = ( time_current - time_prev ) &
2289 / ( time_next - time_prev )
2293 step_prev = file_external_input_item(nid)%data_step_prev
2294 step_next = file_external_input_item(nid)%data_step_next
2296 time_prev = file_external_input_item(nid)%time( step_prev )
2297 time_next = file_external_input_item(nid)%time( step_next )
2299 weight = ( time_current - time_prev ) &
2300 / ( time_next - time_prev )
2305 end subroutine file_external_input_time_advance
2309 character(len=*),
intent(in) :: varname
2315 do n = 1, file_external_input_item_count
2316 if( varname == file_external_input_item(n)%varname )
then