Regist data.
329 file_get_all_datainfo, &
348 file_cartesc_check_coordinates
351 character(len=*),
intent(in) :: basename
352 logical,
intent(in) :: basename_add_num
353 integer,
intent(in) :: number_of_files
354 character(len=*),
intent(in) :: varname
355 character(len=*),
intent(in) :: axistype
356 integer,
intent(in) :: step_fixed
357 logical,
intent(in) :: enable_periodic_year
358 logical,
intent(in) :: enable_periodic_month
359 logical,
intent(in) :: enable_periodic_day
360 real(RP),
intent(in) :: offset
361 real(RP),
intent(in) :: defval
363 logical,
intent(in),
optional :: check_coordinates
364 logical,
intent(in),
optional :: aggregate
365 logical,
intent(in),
optional :: allow_missing
366 integer,
intent(in),
optional :: step_limit
367 logical,
intent(out),
optional :: exist
370 character(len=H_MID) :: description
371 character(len=H_SHORT) :: unit
372 character(len=H_MID) :: standard_name
375 character(len=H_SHORT) :: dim_name (FILE_EXTERNAL_INPUT_dim_limit)
376 integer :: dim_size (FILE_EXTERNAL_INPUT_dim_limit)
377 integer :: var_size (FILE_EXTERNAL_INPUT_dim_limit)
379 character(len=H_SHORT) :: att_name (FILE_EXTERNAL_INPUT_att_limit)
380 integer :: att_type (FILE_EXTERNAL_INPUT_att_limit)
381 integer :: att_len (FILE_EXTERNAL_INPUT_att_limit)
382 real(DP) :: time_start(FILE_EXTERNAL_INPUT_step_limit)
383 real(DP) :: time_end (FILE_EXTERNAL_INPUT_step_limit)
384 character(len=H_MID) :: time_units
385 character(len=H_SHORT) :: calendar
387 integer :: datadate(6)
388 real(DP) :: datasubsec
391 integer :: offset_year
393 integer :: dim1_size, dim1_max, dim1_S
394 integer :: dim2_size, dim2_max, dim2_S
395 integer :: dim3_size, dim3_max, dim3_S
397 integer :: step_limit_
398 logical :: aggregate_
399 logical :: allow_missing_
401 character(len=H_LONG) :: filename
407 if (
present(step_limit) )
then
408 if ( step_limit > 0 )
then
409 step_limit_ = step_limit
411 step_limit_ = file_external_input_step_limit
414 step_limit_ = file_external_input_step_limit
417 if (
present(aggregate) )
then
418 aggregate_ = aggregate
420 aggregate_ = file_aggregate
423 if (
present(allow_missing) )
then
424 allow_missing_ = allow_missing
426 allow_missing_ = .false.
429 do nid = 1, file_external_input_item_count
430 if ( file_external_input_item(nid)%varname == varname )
then
431 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'Data is already registered! basename,varname = ', trim(basename),
', ', trim(varname)
436 file_external_input_item_count = file_external_input_item_count + 1
438 if ( file_external_input_item_count > file_external_input_item_limit )
then
439 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'Number of EXT data exceedes the limit', file_external_input_item_count, file_external_input_item_limit
443 if ( number_of_files > 1 .or. basename_add_num )
then
444 filename = trim(basename) //
'_00000'
451 aggregate=aggregate_, &
455 call file_get_all_datainfo( fid, varname, &
457 description, unit, standard_name, &
459 dim_rank, dim_name(:), dim_size(:), &
460 natts, att_name(:), att_type(:), att_len(:), &
461 time_start(1:step_limit_), time_end(1:step_limit_), &
462 time_units, calendar )
464 if ( step_nmax > 0 )
then
465 if (
present(exist) )
then
469 if (
present(exist) )
then
473 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'Data not found! filename,varname = ', trim(filename),
', ', trim(varname)
483 nid = file_external_input_item_count
485 file_external_input_item(nid)%nfile = number_of_files
486 file_external_input_item(nid)%file_current = 1
487 file_external_input_item(nid)%data_step_offset = 0
489 allocate( file_external_input_item(nid)%basename(number_of_files) )
490 if ( number_of_files > 1 .or. basename_add_num )
then
491 do n = 1, number_of_files
492 write(filename,
'(A,A,I5.5)') trim(basename),
'_', n - 1
493 file_external_input_item(nid)%basename(n) = filename
496 file_external_input_item(nid)%basename(1) = basename
500 file_external_input_item(nid)%fid = fid
501 file_external_input_item(nid)%varname = varname
502 file_external_input_item(nid)%axistype = axistype
503 file_external_input_item(nid)%ndim = dim_rank
504 file_external_input_item(nid)%step_num = step_nmax
505 file_external_input_item(nid)%step_limit = step_limit_
506 file_external_input_item(nid)%allow_missing = allow_missing_
507 file_external_input_item(nid)%aggregate = aggregate_
510 select case ( dim_rank )
513 call file_external_input_get_dims1d( dim1_size, dim1_max, dim1_s, &
516 if ( aggregate_ )
then
517 dim_size(1) = dim1_max
518 var_size(1) = dim1_size
519 file_external_input_item(nid)%var_start(1) = dim1_s
521 if ( dim1_max /= dim_size(1) )
then
522 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'data length does not match! ', trim(axistype),
' item:', trim(varname)
523 log_error_cont(*)
'dim 1 (data,requested) : ', dim_size(1), dim1_max
526 var_size(1) = dim1_max
527 file_external_input_item(nid)%var_start(1) = 1
530 file_external_input_item(nid)%transpose = .false.
531 file_external_input_item(nid)%dim_start(1) = dim1_s
535 call file_external_input_get_dims2d( dim1_size, dim1_max, dim1_s, &
536 dim2_size, dim2_max, dim2_s, &
537 file_external_input_item(nid)%transpose, &
540 if ( aggregate_ )
then
541 dim_size(1) = dim1_max
542 var_size(1) = dim1_size
543 dim_size(2) = dim2_max
544 var_size(2) = dim2_size
545 file_external_input_item(nid)%var_start(1) = dim1_s
546 file_external_input_item(nid)%var_start(1) = dim2_s
548 if ( dim1_max /= dim_size(1) &
549 .OR. dim2_max /= dim_size(2) )
then
550 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'data length does not match! ', trim(axistype),
' item:', trim(varname)
551 log_error_cont(*)
'dim 1 (data,requested) : ', dim_size(1), dim1_max
552 log_error_cont(*)
'dim 2 (data,requested) : ', dim_size(2), dim2_max
555 var_size(1) = dim1_max
556 var_size(2) = dim2_max
557 file_external_input_item(nid)%var_start(1) = 1
558 file_external_input_item(nid)%var_start(1) = 1
561 file_external_input_item(nid)%dim_start(1) = dim1_s
562 file_external_input_item(nid)%dim_start(2) = dim2_s
566 call file_external_input_get_dims3d( dim1_size, dim1_max, dim1_s, &
567 dim2_size, dim2_max, dim2_s, &
568 dim3_size, dim3_max, dim3_s, &
569 file_external_input_item(nid)%transpose, &
572 if ( aggregate_ )
then
573 dim_size(1) = dim1_max
574 var_size(1) = dim1_size
575 dim_size(2) = dim2_max
576 var_size(2) = dim2_size
577 dim_size(3) = dim3_max
578 var_size(3) = dim3_size
579 file_external_input_item(nid)%var_start(1) = dim1_s
580 file_external_input_item(nid)%var_start(2) = dim2_s
581 file_external_input_item(nid)%var_start(3) = dim3_s
583 if ( dim1_max /= dim_size(1) &
584 .OR. dim2_max /= dim_size(2) &
585 .OR. dim3_max /= dim_size(3) )
then
586 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'data length does not match! ', trim(axistype),
' item:', trim(varname)
587 log_error_cont(*)
'dim 1 (data,requested) : ', dim_size(1), dim1_max
588 log_error_cont(*)
'dim 2 (data,requested) : ', dim_size(2), dim2_max
589 log_error_cont(*)
'dim 3 (data,requested) : ', dim_size(3), dim3_max
592 var_size(1) = dim1_max
593 var_size(2) = dim2_max
594 var_size(3) = dim3_max
595 file_external_input_item(nid)%var_start(1) = 1
596 file_external_input_item(nid)%var_start(2) = 1
597 file_external_input_item(nid)%var_start(3) = 1
600 file_external_input_item(nid)%dim_start(1) = dim1_s
601 file_external_input_item(nid)%dim_start(2) = dim2_s
602 file_external_input_item(nid)%dim_start(3) = dim3_s
605 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'Unexpected dim rank: ', dim_rank
609 file_external_input_item(nid)%dim_size(:) = dim_size(:)
612 if ( enable_periodic_day )
then
613 file_external_input_item(nid)%flag_periodic = i_periodic_day
614 elseif( enable_periodic_month )
then
615 file_external_input_item(nid)%flag_periodic = i_periodic_month
616 elseif( enable_periodic_year )
then
617 file_external_input_item(nid)%flag_periodic = i_periodic_year
619 file_external_input_item(nid)%flag_periodic = 0
622 allocate( file_external_input_item(nid)%value(var_size(1),var_size(2),var_size(3),2) )
625 file_external_input_item(nid)%value(:,:,:,:) = defval
626 file_external_input_item(nid)%offset = offset
628 allocate( file_external_input_item(nid)%time(step_limit_) )
629 file_external_input_item(nid)%time(:) = 0.0_dp
631 do n = 1, file_external_input_item(nid)%step_num
635 if ( file_external_input_item(nid)%step_num == 1 )
then
637 file_external_input_item(nid)%fixed_step = .true.
638 file_external_input_item(nid)%data_step_prev = 1
639 file_external_input_item(nid)%data_step_next = 1
641 else if ( step_fixed > 0 )
then
643 file_external_input_item(nid)%fixed_step = .true.
644 file_external_input_item(nid)%data_step_prev = step_fixed
645 file_external_input_item(nid)%data_step_next = step_fixed
649 file_external_input_item(nid)%fixed_step = .false.
652 file_external_input_item(nid)%data_step_next = 1
653 do n = 1, file_external_input_item(nid)%step_num
654 if ( file_external_input_item(nid)%time(n) >
time_nowdaysec )
exit
655 file_external_input_item(nid)%data_step_next = n + 1
658 file_external_input_item(nid)%data_step_prev = file_external_input_item(nid)%data_step_next - 1
660 if ( file_external_input_item(nid)%flag_periodic > 0 )
then
662 if ( file_external_input_item(nid)%data_step_next == 1 )
then
665 file_external_input_item(nid)%data_step_prev = file_external_input_item(nid)%step_num
667 elseif( file_external_input_item(nid)%data_step_next == file_external_input_item(nid)%step_num+1 )
then
670 file_external_input_item(nid)%data_step_next = 1
673 do n = 1, file_external_input_item(nid)%step_num
675 datasec = file_external_input_item(nid)%time(n)
685 if ( file_external_input_item(nid)%flag_periodic == i_periodic_day )
then
686 datadate(i_day) = datadate(i_day) + 1
687 elseif( file_external_input_item(nid)%flag_periodic == i_periodic_month )
then
688 datadate(i_month) = datadate(i_month) + 1
689 elseif( file_external_input_item(nid)%flag_periodic == i_periodic_year )
then
690 datadate(i_year) = datadate(i_year) + 1
702 log_info(
"FILE_EXTERNAL_INPUT_regist",*)
'data time is updated.'
707 if ( file_external_input_item(nid)%data_step_next == 1 &
708 .OR. file_external_input_item(nid)%data_step_next == file_external_input_item(nid)%step_num+1 )
then
709 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'Current time is out of period of external data! ', trim(varname)
718 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A15)')
'Initial read of external data : ', trim(varname)
720 select case ( dim_rank )
724 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
725 'Read 1D var : ', trim(file_external_input_item(nid)%varname), &
726 ' (step= ', file_external_input_item(nid)%data_step_prev,
')'
728 if ( file_external_input_item(nid)%aggregate )
then
729 call file_external_input_read_1d( file_external_input_item(nid)%fid, &
730 file_external_input_item(nid)%varname, &
731 file_external_input_item(nid)%axistype, &
732 file_external_input_item(nid)%value(:,1,1,i_prev), &
733 step=file_external_input_item(nid)%data_step_prev )
735 call file_read( file_external_input_item(nid)%fid, &
736 file_external_input_item(nid)%varname, &
737 file_external_input_item(nid)%value(:,1,1,i_prev), &
738 step=file_external_input_item(nid)%data_step_prev )
742 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
743 'Read 1D var : ', trim(file_external_input_item(nid)%varname), &
744 ' (step= ', file_external_input_item(nid)%data_step_next,
')'
746 if ( file_external_input_item(nid)%aggregate )
then
747 call file_external_input_read_1d( file_external_input_item(nid)%fid, &
748 file_external_input_item(nid)%varname, &
749 file_external_input_item(nid)%axistype, &
750 file_external_input_item(nid)%value(:,1,1,i_next), &
751 step=file_external_input_item(nid)%data_step_next )
753 call file_read( file_external_input_item(nid)%fid, &
754 file_external_input_item(nid)%varname, &
755 file_external_input_item(nid)%value(:,1,1,i_next), &
756 step=file_external_input_item(nid)%data_step_next )
762 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
763 'Read 2D var : ', trim(file_external_input_item(nid)%varname), &
764 ' (step= ', file_external_input_item(nid)%data_step_prev,
')'
766 if ( file_external_input_item(nid)%aggregate )
then
767 call file_external_input_read_2d( file_external_input_item(nid)%fid, &
768 file_external_input_item(nid)%varname, &
769 file_external_input_item(nid)%axistype, &
770 file_external_input_item(nid)%value(:,:,1,i_prev), &
771 step=file_external_input_item(nid)%data_step_prev )
773 call file_read( file_external_input_item(nid)%fid, &
774 file_external_input_item(nid)%varname, &
775 file_external_input_item(nid)%value(:,:,1,i_prev), &
776 step=file_external_input_item(nid)%data_step_prev )
779 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
780 'Read 2D var : ', trim(file_external_input_item(nid)%varname), &
781 ' (step= ', file_external_input_item(nid)%data_step_next,
')'
783 if ( file_external_input_item(nid)%aggregate )
then
784 call file_external_input_read_2d( file_external_input_item(nid)%fid, &
785 file_external_input_item(nid)%varname, &
786 file_external_input_item(nid)%axistype, &
787 file_external_input_item(nid)%value(:,:,1,i_next), &
788 step=file_external_input_item(nid)%data_step_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), &
793 step=file_external_input_item(nid)%data_step_next )
799 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
800 'Read 3D var : ', trim(file_external_input_item(nid)%varname), &
801 ' (step= ', file_external_input_item(nid)%data_step_prev,
')'
803 if ( file_external_input_item(nid)%aggregate )
then
804 call file_external_input_read_3d( file_external_input_item(nid)%fid, &
805 file_external_input_item(nid)%varname, &
806 file_external_input_item(nid)%axistype, &
807 file_external_input_item(nid)%value(:,:,:,i_prev), &
808 step=file_external_input_item(nid)%data_step_prev )
810 call file_read( file_external_input_item(nid)%fid, &
811 file_external_input_item(nid)%varname, &
812 file_external_input_item(nid)%value(:,:,:,i_prev), &
813 step=file_external_input_item(nid)%data_step_prev )
817 log_info(
"FILE_EXTERNAL_INPUT_regist",
'(1x,A,A,A,I4,A)') &
818 'Read 3D var : ', trim(file_external_input_item(nid)%varname), &
819 ' (step= ', file_external_input_item(nid)%data_step_next,
')'
821 if ( file_external_input_item(nid)%aggregate )
then
822 call file_external_input_read_3d( file_external_input_item(nid)%fid, &
823 file_external_input_item(nid)%varname, &
824 file_external_input_item(nid)%axistype, &
825 file_external_input_item(nid)%value(:,:,:,i_next), &
826 step=file_external_input_item(nid)%data_step_next )
828 call file_read( file_external_input_item(nid)%fid, &
829 file_external_input_item(nid)%varname, &
830 file_external_input_item(nid)%value(:,:,:,i_next), &
831 step=file_external_input_item(nid)%data_step_next )
835 log_error(
"FILE_EXTERNAL_INPUT_regist",*)
'Unexpected dim rank: ', dim_rank
839 if (
present(check_coordinates) )
then
840 if ( check_coordinates )
then
841 call file_cartesc_check_coordinates( fid, &
842 atmos = file_external_input_item(nid)%ndim==3, &
843 transpose = file_external_input_item(nid)%transpose )