52 use fms_mod,
only: file_exist, close_file
234 #include<file_version.h> 250 integer :: unit, ierr, io
253 call write_version_number(
"HORIZ_INTERP_MOD", version)
255 #ifdef INTERNAL_FILE_NML 259 if (file_exist(
'input.nml'))
then 260 unit = open_namelist_file( )
263 read (unit, nml=horiz_interp_nml, iostat=io, end=10)
266 10
call close_file (unit)
269 if (mpp_pe() == mpp_root_pe() )
then 271 write (unit, nml=horiz_interp_nml)
275 call mpp_error(fatal,
"horiz_interp_mod: You have overridden the default value of reproduce_siena " // &
276 "and set it to .true. in horiz_interp_nml. This is a temporary workaround to " // &
277 "allow for consistency in continuing experiments. Please remove this namelist " )
280 call horiz_interp_conserve_init
281 call horiz_interp_bilinear_init
282 call horiz_interp_bicubic_init
283 call horiz_interp_spherical_init
304 interp_method, num_nbrs, max_dist, src_modulo, &
305 grid_at_center, mask_in, mask_out)
309 type(horiz_interp_type),
intent(inout) :: Interp
310 real,
intent(in),
dimension(:) :: lon_in , lat_in
311 real,
intent(in),
dimension(:) :: lon_out, lat_out
312 integer,
intent(in),
optional :: verbose
313 character(len=*),
intent(in),
optional :: interp_method
314 integer,
intent(in),
optional :: num_nbrs
315 real,
intent(in),
optional :: max_dist
316 logical,
intent(in),
optional :: src_modulo
317 logical,
intent(in),
optional :: grid_at_center
318 real,
intent(in),
dimension(:,:),
optional :: mask_in
319 real,
intent(inout),
dimension(:,:),
optional :: mask_out
321 real,
dimension(:,:),
allocatable :: lon_src, lat_src, lon_dst, lat_dst
322 real,
dimension(:),
allocatable :: lon_src_1d, lat_src_1d, lon_dst_1d, lat_dst_1d
323 integer :: i, j, nlon_in, nlat_in, nlon_out, nlat_out
325 character(len=40) :: method
329 method =
'conservative' 330 if(
present(interp_method)) method = interp_method
332 select case (trim(method))
333 case (
"conservative")
339 if(
present(grid_at_center) ) center = grid_at_center
341 nlon_out =
size(lon_out(:)); nlat_out =
size(lat_out(:))
342 allocate(lon_dst(nlon_out,nlat_out), lat_dst(nlon_out,nlat_out))
344 lon_dst(i,:) = lon_out(i)
347 lat_dst(:,j) = lat_out(j)
352 deallocate(lon_dst, lat_dst)
354 nlon_in =
size(lon_in(:))-1; nlat_in =
size(lat_in(:))-1
355 nlon_out =
size(lon_out(:))-1; nlat_out =
size(lat_out(:))-1
356 allocate(lon_src_1d(nlon_in), lat_src_1d(nlat_in))
357 allocate(lon_dst(nlon_out,nlat_out), lat_dst(nlon_out,nlat_out))
359 lon_src_1d(i) = (lon_in(i) + lon_in(i+1)) * 0.5
362 lat_src_1d(j) = (lat_in(j) + lat_in(j+1)) * 0.5
365 lon_dst(i,:) = (lon_out(i) + lon_out(i+1)) * 0.5
368 lat_dst(:,j) = (lat_out(j) + lat_out(j+1)) * 0.5
372 deallocate(lon_src_1d, lat_src_1d, lon_dst, lat_dst)
377 if(
present(grid_at_center) ) center = grid_at_center
383 nlon_in =
size(lon_in(:))-1; nlat_in =
size(lat_in(:))-1
384 nlon_out =
size(lon_out(:))-1; nlat_out =
size(lat_out(:))-1
385 allocate(lon_src_1d(nlon_in), lat_src_1d(nlat_in))
386 allocate(lon_dst_1d(nlon_out), lat_dst_1d(nlat_out))
388 lon_src_1d(i) = (lon_in(i) + lon_in(i+1)) * 0.5
391 lat_src_1d(j) = (lat_in(j) + lat_in(j+1)) * 0.5
394 lon_dst_1d(i) = (lon_out(i) + lon_out(i+1)) * 0.5
397 lat_dst_1d(j) = (lat_out(j) + lat_out(j+1)) * 0.5
401 deallocate(lon_src_1d, lat_src_1d, lon_dst_1d, lat_dst_1d)
405 nlon_in =
size(lon_in(:)); nlat_in =
size(lat_in(:))
406 nlon_out =
size(lon_out(:)); nlat_out =
size(lat_out(:))
407 allocate(lon_src(nlon_in,nlat_in), lat_src(nlon_in,nlat_in))
408 allocate(lon_dst(nlon_out,nlat_out), lat_dst(nlon_out,nlat_out))
410 lon_src(i,:) = lon_in(i)
413 lat_src(:,j) = lat_in(j)
416 lon_dst(i,:) = lon_out(i)
419 lat_dst(:,j) = lat_out(j)
422 num_nbrs, max_dist, src_modulo)
423 deallocate(lon_src, lat_src, lon_dst, lat_dst)
425 call mpp_error(fatal,
'horiz_interp_mod: interp_method should be conservative, bilinear, bicubic, spherical')
429 interp%I_am_initialized = .true.
437 verbose, interp_method, num_nbrs, max_dist, &
438 src_modulo, grid_at_center, mask_in, mask_out, is_latlon_out )
440 type(horiz_interp_type),
intent(inout) :: Interp
441 real,
intent(in),
dimension(:) :: lon_in , lat_in
442 real,
intent(in),
dimension(:,:) :: lon_out, lat_out
443 integer,
intent(in),
optional :: verbose
444 character(len=*),
intent(in),
optional :: interp_method
445 integer,
intent(in),
optional :: num_nbrs
446 real,
intent(in),
optional :: max_dist
447 logical,
intent(in),
optional :: src_modulo
448 logical,
intent(in),
optional :: grid_at_center
449 real,
intent(in),
dimension(:,:),
optional :: mask_in
450 real,
intent(out),
dimension(:,:),
optional :: mask_out
451 logical,
intent(in),
optional :: is_latlon_out
453 real,
dimension(:,:),
allocatable :: lon_src, lat_src
454 real,
dimension(:),
allocatable :: lon_src_1d, lat_src_1d
455 integer :: i, j, nlon_in, nlat_in
456 character(len=40) :: method
458 logical :: dst_is_latlon
462 method =
'conservative' 463 if(
present(interp_method)) method = interp_method
465 select case (trim(method))
466 case (
"conservative")
469 if(
PRESENT(is_latlon_out))
then 470 dst_is_latlon = is_latlon_out
474 if(dst_is_latlon )
then 475 if(
present(mask_in))
then 476 if ( any(mask_in < -.0001) .or. any(mask_in > 1.0001) )
call mpp_error(fatal, &
477 'horiz_interp_conserve_new_1d_src(horiz_interp_conserve_mod): input mask not between 0,1')
478 allocate(interp%mask_in(
size(mask_in,1),
size(mask_in,2)) )
479 interp%mask_in = mask_in
485 verbose=verbose, mask_in=mask_in, mask_out=mask_out )
490 if(
present(grid_at_center) ) center = grid_at_center
493 verbose, src_modulo )
495 nlon_in =
size(lon_in(:))-1; nlat_in =
size(lat_in(:))-1
496 allocate(lon_src_1d(nlon_in), lat_src_1d(nlat_in))
498 lon_src_1d(i) = (lon_in(i) + lon_in(i+1)) * 0.5
501 lat_src_1d(j) = (lat_in(j) + lat_in(j+1)) * 0.5
504 verbose, src_modulo )
505 deallocate(lon_src_1d,lat_src_1d)
510 if(
present(grid_at_center) ) center = grid_at_center
513 verbose, src_modulo )
515 nlon_in =
size(lon_in(:))-1; nlat_in =
size(lat_in(:))-1
516 allocate(lon_src_1d(nlon_in), lat_src_1d(nlat_in))
518 lon_src_1d(i) = (lon_in(i) + lon_in(i+1)) * 0.5
521 lat_src_1d(j) = (lat_in(j) + lat_in(j+1)) * 0.5
524 verbose, src_modulo )
525 deallocate(lon_src_1d,lat_src_1d)
529 nlon_in =
size(lon_in(:)); nlat_in =
size(lat_in(:))
530 allocate(lon_src(nlon_in,nlat_in), lat_src(nlon_in,nlat_in))
532 lon_src(i,:) = lon_in(i)
535 lat_src(:,j) = lat_in(j)
538 num_nbrs, max_dist, src_modulo)
539 deallocate(lon_src, lat_src)
541 call mpp_error(fatal,
'interp_method should be conservative, bilinear, bicubic, spherical')
545 interp%I_am_initialized = .true.
552 verbose, interp_method, num_nbrs, max_dist, &
553 src_modulo, mask_in, mask_out, is_latlon_in, is_latlon_out )
554 type(horiz_interp_type),
intent(inout) :: Interp
555 real,
intent(in),
dimension(:,:) :: lon_in , lat_in
556 real,
intent(in),
dimension(:,:) :: lon_out, lat_out
557 integer,
intent(in),
optional :: verbose
558 character(len=*),
intent(in),
optional :: interp_method
559 integer,
intent(in),
optional :: num_nbrs
560 real,
intent(in),
optional :: max_dist
561 logical,
intent(in),
optional :: src_modulo
562 real,
intent(in),
dimension(:,:),
optional :: mask_in
563 real,
intent(out),
dimension(:,:),
optional :: mask_out
564 logical,
intent(in),
optional :: is_latlon_in, is_latlon_out
565 logical :: src_is_latlon, dst_is_latlon
566 character(len=40) :: method
571 if(
present(interp_method)) method = interp_method
573 select case (trim(method))
574 case (
"conservative")
576 if(
PRESENT(is_latlon_in))
then 577 src_is_latlon = is_latlon_in
581 if(
PRESENT(is_latlon_out))
then 582 dst_is_latlon = is_latlon_out
586 if(src_is_latlon .AND. dst_is_latlon)
then 587 if(
present(mask_in))
then 588 if ( any(mask_in < -.0001) .or. any(mask_in > 1.0001) )
call mpp_error(fatal, &
589 'horiz_interp_conserve_new_2d(horiz_interp_conserve_mod): input mask not between 0,1')
590 allocate(interp%mask_in(
size(mask_in,1),
size(mask_in,2)) )
591 interp%mask_in = mask_in
595 else if(src_is_latlon)
then 597 verbose=verbose, mask_in=mask_in, mask_out=mask_out )
598 else if(dst_is_latlon)
then 600 verbose=verbose, mask_in=mask_in, mask_out=mask_out )
603 verbose=verbose, mask_in=mask_in, mask_out=mask_out )
609 num_nbrs, max_dist, src_modulo )
613 verbose, src_modulo )
615 call mpp_error(fatal,
'when source grid are 2d, interp_method should be spherical or bilinear')
619 interp%I_am_initialized = .true.
625 verbose, interp_method, num_nbrs, max_dist, src_modulo, mask_in, mask_out, is_latlon_in )
626 type(horiz_interp_type),
intent(inout) :: Interp
627 real,
intent(in),
dimension(:,:) :: lon_in , lat_in
628 real,
intent(in),
dimension(:) :: lon_out, lat_out
629 integer,
intent(in),
optional :: verbose
630 character(len=*),
intent(in),
optional :: interp_method
631 integer,
intent(in),
optional :: num_nbrs
632 real,
intent(in),
optional :: max_dist
633 logical,
intent(in),
optional :: src_modulo
634 real,
intent(in),
dimension(:,:),
optional :: mask_in
635 real,
intent(out),
dimension(:,:),
optional :: mask_out
636 logical,
intent(in),
optional :: is_latlon_in
638 character(len=40) :: method
640 integer :: i, j, nlon_out, nlat_out
641 real,
dimension(:,:),
allocatable :: lon_dst, lat_dst
642 logical :: src_is_latlon
647 if(
present(interp_method)) method = interp_method
649 nlon_out =
size(lon_out(:)); nlat_out =
size(lat_out(:))
650 allocate(lon_dst(nlon_out,nlat_out), lat_dst(nlon_out,nlat_out))
652 lon_dst(i,:) = lon_out(i)
655 lat_dst(:,j) = lat_out(j)
658 select case (trim(method))
659 case (
"conservative")
661 if(
PRESENT(is_latlon_in))
then 662 src_is_latlon = is_latlon_in
667 if(src_is_latlon)
then 668 if(
present(mask_in))
then 669 if ( any(mask_in < -.0001) .or. any(mask_in > 1.0001) )
call mpp_error(fatal, &
670 'horiz_interp_conserve_new_1d_dst(horiz_interp_conserve_mod): input mask not between 0,1')
671 allocate(interp%mask_in(
size(mask_in,1),
size(mask_in,2)) )
672 interp%mask_in = mask_in
678 verbose=verbose, mask_in=mask_in, mask_out=mask_out )
683 verbose, src_modulo )
687 num_nbrs, max_dist, src_modulo)
689 call mpp_error(fatal,
'when source grid are 2d, interp_method should be spherical or bilinear')
692 deallocate(lon_dst,lat_dst)
695 interp%I_am_initialized = .true.
714 mask_in, mask_out, missing_value, missing_permit, &
715 err_msg, new_missing_handle )
719 real,
intent(in),
dimension(:,:) :: data_in
720 real,
intent(out),
dimension(:,:) :: data_out
721 integer,
intent(in),
optional :: verbose
722 real,
intent(in),
dimension(:,:),
optional :: mask_in
723 real,
intent(out),
dimension(:,:),
optional :: mask_out
724 real,
intent(in),
optional :: missing_value
725 integer,
intent(in),
optional :: missing_permit
726 character(len=*),
intent(out),
optional :: err_msg
727 logical,
intent(in),
optional :: new_missing_handle
729 if(
present(err_msg)) err_msg =
'' 730 if(.not.interp%I_am_initialized)
then 731 if(fms_error_handler(
'horiz_interp',
'The horiz_interp_type variable is not initialized',err_msg))
return 734 select case(interp%interp_method)
736 call horiz_interp_conserve(interp,data_in, data_out, verbose, mask_in, mask_out)
738 call horiz_interp_bilinear(interp,data_in, data_out, verbose, mask_in, mask_out, &
739 missing_value, missing_permit, new_missing_handle )
741 call horiz_interp_bicubic(interp,data_in, data_out, verbose, mask_in, mask_out, &
742 missing_value, missing_permit )
744 call horiz_interp_spherical(interp,data_in, data_out, verbose, mask_in, mask_out, &
747 call mpp_error(fatal,
'interp_method should be conservative, bilinear, bicubic, spherical')
758 missing_value, missing_permit, err_msg )
765 real,
intent(in),
dimension(:,:,:) :: data_in
766 real,
intent(out),
dimension(:,:,:) :: data_out
767 integer,
intent(in),
optional :: verbose
768 real,
intent(in),
dimension(:,:,:),
optional :: mask_in
769 real,
intent(out),
dimension(:,:,:),
optional :: mask_out
770 real,
intent(in),
optional :: missing_value
771 integer,
intent(in),
optional :: missing_permit
772 character(len=*),
intent(out),
optional :: err_msg
776 if(
present(err_msg)) err_msg =
'' 777 if(.not.interp%I_am_initialized)
then 778 if(fms_error_handler(
'horiz_interp',
'The horiz_interp_type variable is not initialized',err_msg))
return 781 do n = 1,
size(data_in,3)
782 if (
present(mask_in))
then 783 if(
present(mask_out))
then 785 verbose, mask_in(:,:,n), mask_out(:,:,n), &
786 missing_value, missing_permit )
789 verbose, mask_in(:,:,n), missing_value = missing_value, &
790 missing_permit = missing_permit )
793 if(
present(mask_out))
then 795 verbose, mask_out=mask_out(:,:,n), missing_value = missing_value, &
796 missing_permit = missing_permit )
799 verbose, missing_value = missing_value, &
800 missing_permit = missing_permit )
812 data_out, verbose, mask_in, mask_out, &
813 interp_method, missing_value, missing_permit, &
814 num_nbrs, max_dist,src_modulo, grid_at_center )
822 real,
intent(in),
dimension(:,:) :: data_in
823 real,
intent(in),
dimension(:) :: lon_in , lat_in
824 real,
intent(in),
dimension(:) :: lon_out, lat_out
825 real,
intent(out),
dimension(:,:) :: data_out
826 integer,
intent(in),
optional :: verbose
827 real,
intent(in),
dimension(:,:),
optional :: mask_in
828 real,
intent(out),
dimension(:,:),
optional :: mask_out
829 character(len=*),
intent(in),
optional :: interp_method
830 real,
intent(in),
optional :: missing_value
831 integer,
intent(in),
optional :: missing_permit
832 integer,
intent(in),
optional :: num_nbrs
833 real,
intent(in),
optional :: max_dist
834 logical,
intent(in),
optional :: src_modulo
835 logical,
intent(in),
optional :: grid_at_center
841 call horiz_interp_new ( interp, lon_in, lat_in, lon_out, lat_out, verbose, &
842 interp_method, num_nbrs, max_dist, src_modulo, grid_at_center )
844 call horiz_interp ( interp, data_in, data_out, verbose, &
845 mask_in, mask_out, missing_value, missing_permit )
855 data_out, verbose, mask_in, mask_out, &
856 interp_method, missing_value, missing_permit, &
857 num_nbrs, max_dist, src_modulo, grid_at_center )
865 real,
intent(in),
dimension(:,:) :: data_in
866 real,
intent(in),
dimension(:) :: lon_in , lat_in
867 real,
intent(in),
dimension(:,:) :: lon_out, lat_out
868 real,
intent(out),
dimension(:,:) :: data_out
869 integer,
intent(in),
optional :: verbose
870 real,
intent(in),
dimension(:,:),
optional :: mask_in
871 real,
intent(out),
dimension(:,:),
optional :: mask_out
872 character(len=*),
intent(in),
optional :: interp_method
873 real,
intent(in),
optional :: missing_value
874 integer,
intent(in),
optional :: missing_permit
875 integer,
intent(in),
optional :: num_nbrs
876 real,
intent(in),
optional :: max_dist
877 logical,
intent(in),
optional :: src_modulo
878 logical,
intent(in),
optional :: grid_at_center
882 logical :: dst_is_latlon
883 character(len=128) :: method
886 method =
'conservative' 887 if(
present(interp_method)) method = interp_method
888 dst_is_latlon = .true.
889 if(trim(method) ==
'conservative') dst_is_latlon =
is_lat_lon(lon_out, lat_out)
891 if(dst_is_latlon)
then 892 call horiz_interp_new ( interp, lon_in, lat_in, lon_out, lat_out, verbose, &
893 interp_method, num_nbrs, max_dist, src_modulo, &
894 grid_at_center, is_latlon_out = dst_is_latlon )
895 call horiz_interp ( interp, data_in, data_out, verbose, &
896 mask_in, mask_out, missing_value, missing_permit )
898 call horiz_interp_new ( interp, lon_in, lat_in, lon_out, lat_out, verbose, &
899 interp_method, num_nbrs, max_dist, src_modulo, &
900 grid_at_center, mask_in, mask_out, is_latlon_out = dst_is_latlon)
902 call horiz_interp ( interp, data_in, data_out, verbose, &
903 missing_value=missing_value, missing_permit=missing_permit )
916 verbose, mask_in, mask_out, interp_method, missing_value,&
917 missing_permit, num_nbrs, max_dist, src_modulo )
924 real,
intent(in),
dimension(:,:) :: data_in
925 real,
intent(in),
dimension(:,:) :: lon_in , lat_in
926 real,
intent(in),
dimension(:,:) :: lon_out, lat_out
927 real,
intent(out),
dimension(:,:) :: data_out
928 integer,
intent(in),
optional :: verbose
929 real,
intent(in),
dimension(:,:),
optional :: mask_in
930 real,
intent(out),
dimension(:,:),
optional :: mask_out
931 character(len=*),
intent(in),
optional :: interp_method
932 real,
intent(in),
optional :: missing_value
933 integer,
intent(in),
optional :: missing_permit
934 integer,
intent(in),
optional :: num_nbrs
935 real,
intent(in),
optional :: max_dist
936 logical,
intent(in),
optional :: src_modulo
939 logical :: dst_is_latlon, src_is_latlon
940 character(len=128) :: method
944 method =
'conservative' 945 if(
present(interp_method)) method = interp_method
946 dst_is_latlon = .true.
947 src_is_latlon = .true.
948 if(trim(method) ==
'conservative')
then 953 if(dst_is_latlon .and. src_is_latlon)
then 954 call horiz_interp_new ( interp, lon_in, lat_in, lon_out, lat_out, verbose, &
955 interp_method, num_nbrs, max_dist, src_modulo, &
956 is_latlon_in=dst_is_latlon, is_latlon_out = dst_is_latlon )
957 call horiz_interp ( interp, data_in, data_out, verbose, &
958 mask_in, mask_out, missing_value, missing_permit )
960 call horiz_interp_new ( interp, lon_in, lat_in, lon_out, lat_out, verbose, &
961 interp_method, num_nbrs, max_dist, src_modulo, &
963 is_latlon_in=dst_is_latlon, is_latlon_out = dst_is_latlon)
964 call horiz_interp ( interp, data_in, data_out, verbose, &
965 missing_value=missing_value, missing_permit=missing_permit )
977 verbose, mask_in, mask_out,interp_method,missing_value, &
978 missing_permit, num_nbrs, max_dist, src_modulo)
986 real,
intent(in),
dimension(:,:) :: data_in
987 real,
intent(in),
dimension(:,:) :: lon_in , lat_in
988 real,
intent(in),
dimension(:) :: lon_out, lat_out
989 real,
intent(out),
dimension(:,:) :: data_out
990 integer,
intent(in),
optional :: verbose
991 real,
intent(in),
dimension(:,:),
optional :: mask_in
992 real,
intent(out),
dimension(:,:),
optional :: mask_out
993 character(len=*),
intent(in),
optional :: interp_method
994 real,
intent(in),
optional :: missing_value
995 integer,
intent(in),
optional :: missing_permit
996 integer,
intent(in),
optional :: num_nbrs
997 real,
intent(in),
optional :: max_dist
998 logical,
intent(in),
optional :: src_modulo
1001 logical :: src_is_latlon
1002 character(len=128) :: method
1006 method =
'conservative' 1007 if(
present(interp_method)) method = interp_method
1008 src_is_latlon = .true.
1009 if(trim(method) ==
'conservative') src_is_latlon =
is_lat_lon(lon_in, lat_in)
1011 if(src_is_latlon)
then 1012 call horiz_interp_new ( interp, lon_in, lat_in, lon_out, lat_out, verbose, &
1013 interp_method, num_nbrs, max_dist, src_modulo, &
1014 is_latlon_in = src_is_latlon )
1015 call horiz_interp ( interp, data_in, data_out, verbose, &
1016 mask_in, mask_out, missing_value, missing_permit )
1018 call horiz_interp_new ( interp, lon_in, lat_in, lon_out, lat_out, verbose, &
1019 interp_method, num_nbrs, max_dist, src_modulo, &
1020 mask_in, mask_out, is_latlon_in = src_is_latlon)
1022 call horiz_interp ( interp, data_in, data_out, verbose, &
1023 missing_value=missing_value, missing_permit=missing_permit )
1035 lon_out, lat_out, data_out, &
1036 verbose, mask_in, mask_out)
1073 real,
intent(in),
dimension(:,:) :: data_in
1074 real,
intent(in) :: wb, sb, dx, dy
1075 real,
intent(in),
dimension(:) :: lon_out, lat_out
1076 real,
intent(out),
dimension(:,:) :: data_out
1077 integer,
intent(in),
optional :: verbose
1078 real,
intent(in),
dimension(:,:),
optional :: mask_in
1079 real,
intent(out),
dimension(:,:),
optional :: mask_out
1081 real,
dimension(size(data_in,1)+1) :: blon_in
1082 real,
dimension(size(data_in,2)+1) :: blat_in
1083 integer :: i, j, nlon_in, nlat_in
1089 nlon_in =
size(data_in,1)
1090 nlat_in =
size(data_in,2)
1093 blon_in(i) = wb + float(i-1)*dx
1095 if (abs(blon_in(nlon_in+1)-blon_in(1)-tpi) < epsilon(blon_in)) &
1096 blon_in(nlon_in+1)=blon_in(1)+tpi
1099 blat_in(j) = sb + float(j-1)*dy
1101 blat_in(1) = -0.5*
pi 1102 blat_in(nlat_in+1) = 0.5*
pi 1106 lon_out, lat_out, data_out, &
1107 verbose, mask_in, mask_out )
1145 select case(interp % interp_method)
1156 interp%I_am_initialized = .false.
1183 real,
dimension(:,:),
intent(in) :: lon, lat
1185 integer :: i, j, nlon, nlat, num
1190 loop_lat:
do j = 1, nlat
1192 if(lat(i,j) .NE. lat(1,j))
then 1200 loop_lon:
do i = 1, nlon
1202 if(lon(i,j) .NE. lon(i,1))
then 1284 #ifdef test_horiz_interp 1286 program horiz_interp_test
1289 use mpp_mod,
only : mpp_clock_id, mpp_clock_begin, mpp_clock_end
1290 use mpp_mod,
only : mpp_pe, mpp_root_pe, note, mpp_clock_sync, mpp_clock_detailed
1292 use mpp_io_mod,
only : mpp_io_init, mpp_io_exit
1302 integer :: ni_src = 360, nj_src = 180
1303 integer :: ni_dst = 144, nj_dst = 72
1305 namelist /test_horiz_interp_nml/ ni_src, nj_src, ni_dst, nj_dst
1307 real :: lon_src_beg = 0, lon_src_end = 360
1308 real :: lat_src_beg = -90, lat_src_end = 90
1309 real :: lon_dst_beg = -280, lon_dst_end = 80
1310 real :: lat_dst_beg = -90, lat_dst_end = 90
1311 real :: d2r =
pi/180.
1312 real,
parameter :: small = 1.0e-10
1315 type(horiz_interp_type) :: interp
1316 integer :: id1, id2, id3, id4
1317 integer :: isc, iec, jsc, jec, i, j
1318 integer :: nml_unit, io, ierr, layout(2)
1319 real :: dlon_src, dlat_src, dlon_dst, dlat_dst
1320 real,
allocatable,
dimension(:) :: lon1d_src, lat1d_src, lon1d_dst, lat1d_dst
1321 real,
allocatable,
dimension(:,:) :: lon2d_src, lat2d_src, lon2d_dst, lat2d_dst
1322 real,
allocatable,
dimension(:,:) :: data_src, data1_dst, data2_dst, data3_dst, data4_dst
1326 call mpp_domains_init
1328 call horiz_interp_init
1331 #ifdef INTERNAL_FILE_NML 1335 if (file_exist(
'input.nml'))
then 1337 nml_unit = open_namelist_file()
1338 do while (ierr /= 0)
1339 read(nml_unit, nml=test_horiz_interp_nml, iostat=io, end=10)
1342 10
call close_file(nml_unit)
1356 allocate(lon2d_src(ni_src+1, nj_src+1), lat2d_src(ni_src+1, nj_src+1) )
1357 allocate(lon1d_src(ni_src+1), lat1d_src(nj_src+1), data_src(ni_src, nj_src) )
1359 allocate(lon2d_dst(isc:iec+1, jsc:jec+1), lat2d_dst(isc:iec+1, jsc:jec+1) )
1360 allocate(lon1d_dst(isc:iec+1), lat1d_dst(jsc:jec+1) )
1361 allocate(data1_dst(isc:iec, jsc:jec), data2_dst(isc:iec, jsc:jec) )
1362 allocate(data3_dst(isc:iec, jsc:jec), data4_dst(isc:iec, jsc:jec) )
1365 dlon_src = (lon_src_end-lon_src_beg)/ni_src
1366 dlat_src = (lat_src_end-lat_src_beg)/nj_src
1367 dlon_dst = (lon_dst_end-lon_dst_beg)/ni_dst
1368 dlat_dst = (lat_dst_end-lat_dst_beg)/nj_dst
1371 lon1d_src(i) = lon_src_beg + (i-1)*dlon_src
1375 lat1d_src(j) = lat_src_beg + (j-1)*dlat_src
1379 lon1d_dst(i) = lon_dst_beg + (i-1)*dlon_dst
1383 lat1d_dst(j) = lat_dst_beg + (j-1)*dlat_dst
1387 lon1d_src = lon1d_src * d2r
1388 lat1d_src = lat1d_src * d2r
1389 lon1d_dst = lon1d_dst * d2r
1390 lat1d_dst = lat1d_dst * d2r
1393 lon2d_src(i,:) = lon1d_src(i)
1397 lat2d_src(:,j) = lat1d_src(j)
1401 lon2d_dst(i,:) = lon1d_dst(i)
1405 lat2d_dst(:,j) = lat1d_dst(j)
1411 data_src(i,j) = i + j*0.001
1415 id1 = mpp_clock_id(
'horiz_interp_1dx1d', flags=mpp_clock_sync+mpp_clock_detailed )
1416 id2 = mpp_clock_id(
'horiz_interp_1dx2d', flags=mpp_clock_sync+mpp_clock_detailed )
1417 id3 = mpp_clock_id(
'horiz_interp_2dx1d', flags=mpp_clock_sync+mpp_clock_detailed )
1418 id4 = mpp_clock_id(
'horiz_interp_2dx2d', flags=mpp_clock_sync+mpp_clock_detailed )
1421 call mpp_clock_begin(id1)
1422 call horiz_interp_new(interp, lon1d_src, lat1d_src, lon1d_dst, lat1d_dst, interp_method =
"conservative")
1424 call horiz_interp_del(interp)
1425 call mpp_clock_end(id1)
1428 call mpp_clock_begin(id2)
1429 call horiz_interp_new(interp, lon1d_src, lat1d_src, lon2d_dst, lat2d_dst, interp_method =
"conservative")
1431 call horiz_interp_del(interp)
1432 call mpp_clock_end(id2)
1435 call mpp_clock_begin(id3)
1436 call horiz_interp_new(interp, lon2d_src, lat2d_src, lon1d_dst, lat1d_dst, interp_method =
"conservative")
1438 call horiz_interp_del(interp)
1439 call mpp_clock_end(id3)
1442 call mpp_clock_begin(id4)
1443 call horiz_interp_new(interp, lon2d_src, lat2d_src, lon2d_dst, lat2d_dst, interp_method =
"conservative")
1445 call horiz_interp_del(interp)
1446 call mpp_clock_end(id4)
1452 if( abs(data1_dst(i,j)-data2_dst(i,j)) > small )
then 1453 print*,
"After interpolation At point (i,j) = (", i,
",", j,
"), data1 = ", data1_dst(i,j), &
1454 ", data2 = ", data2_dst(i,j),
", data1-data2 = ", data1_dst(i,j) - data2_dst(i,j)
1455 call mpp_error(fatal,
"horiz_interp_test: data1_dst does not approxiamate data2_dst")
1460 if(mpp_pe() == mpp_root_pe())
call mpp_error(note, &
1461 "The test that verify 1dx2d version horiz_interp can reproduce 1dx1d version of horiz_interp is succesful")
1466 if( abs(data1_dst(i,j)-data3_dst(i,j)) > small )
then 1467 print*,
"After interpolation At point (i,j) = (", i,
",", j,
"), data1 = ", data1_dst(i,j), &
1468 ", data2 = ", data3_dst(i,j),
", data1-data2 = ", data1_dst(i,j) - data3_dst(i,j)
1469 call mpp_error(fatal,
"horiz_interp_test: data1_dst does not approxiamate data3_dst")
1474 if(mpp_pe() == mpp_root_pe())
call mpp_error(note, &
1475 "The test that verify 2dx1d version horiz_interp can reproduce 1dx1d version of horiz_interp is succesful")
1480 if( abs(data1_dst(i,j)-data4_dst(i,j)) > small )
then 1481 print*,
"After interpolation At point (i,j) = (", i,
",", j,
"), data1 = ", data1_dst(i,j), &
1482 ", data2 = ", data4_dst(i,j),
", data1-data2 = ", data1_dst(i,j) - data4_dst(i,j)
1483 call mpp_error(fatal,
"horiz_interp_test: data1_dst does not approxiamate data4_dst")
1488 if(mpp_pe() == mpp_root_pe())
call mpp_error(note, &
1489 "The test that verify 2dx2d version horiz_interp can reproduce 1dx1d version of horiz_interp is succesful")
1494 end program horiz_interp_test
integer, parameter, public spherica
subroutine, public horiz_interp_end
subroutine horiz_interp_new_2d(Interp, lon_in, lat_in, lon_out, lat_out, verbose, interp_method, num_nbrs, max_dist, src_modulo, mask_in, mask_out, is_latlon_in, is_latlon_out)
integer, parameter, public bilinear
subroutine, public horiz_interp_spherical(Interp, data_in, data_out, verbose, mask_in, mask_out, missing_value)
subroutine, public horiz_interp_del(Interp)
subroutine, public horiz_interp_conserve(Interp, data_in, data_out, verbose, mask_in, mask_out)
subroutine horiz_interp_solo_1d_dst(data_in, lon_in, lat_in, lon_out, lat_out, data_out, verbose, mask_in, mask_out, interp_method, missing_value, missing_permit, num_nbrs, max_dist, src_modulo)
integer, parameter, public bicubic
subroutine, public horiz_interp_bilinear(Interp, data_in, data_out, verbose, mask_in, mask_out, missing_value, missing_permit, new_handle_missing)
logical function, public fms_error_handler(routine, message, err_msg)
subroutine, public horiz_interp_bilinear_del(Interp)
logical function is_lat_lon(lon, lat)
integer function, public check_nml_error(IOSTAT, NML_NAME)
subroutine, public horiz_interp_bicubic(Interp, data_in, data_out, verbose, mask_in, mask_out, missing_value, missing_permit)
subroutine horiz_interp_new_1d(Interp, lon_in, lat_in, lon_out, lat_out, verbose, interp_method, num_nbrs, max_dist, src_modulo, grid_at_center, mask_in, mask_out)
subroutine horiz_interp_solo_1d_src(data_in, lon_in, lat_in, lon_out, lat_out, data_out, verbose, mask_in, mask_out, interp_method, missing_value, missing_permit, num_nbrs, max_dist, src_modulo, grid_at_center)
character(len=input_str_length), dimension(:), allocatable, target, public input_nml_file
subroutine, public horiz_interp_conserve_del(Interp)
subroutine, public horiz_interp_spherical_init
integer, parameter, public conserve
subroutine, public horiz_interp_bicubic_del(Interp)
subroutine, public horiz_interp_bilinear_init
subroutine, public horiz_interp_conserve_init
subroutine, public horiz_interp_bicubic_init
subroutine horiz_interp_base_3d(Interp, data_in, data_out, verbose, mask_in, mask_out, missing_value, missing_permit, err_msg)
subroutine horiz_interp_new_1d_src(Interp, lon_in, lat_in, lon_out, lat_out, verbose, interp_method, num_nbrs, max_dist, src_modulo, grid_at_center, mask_in, mask_out, is_latlon_out)
subroutine, public horiz_interp_spherical_new(Interp, lon_in, lat_in, lon_out, lat_out, num_nbrs, max_dist, src_modulo)
subroutine, public horiz_interp_init
subroutine, public horiz_interp_spherical_del(Interp)
subroutine horiz_interp_new_1d_dst(Interp, lon_in, lat_in, lon_out, lat_out, verbose, interp_method, num_nbrs, max_dist, src_modulo, mask_in, mask_out, is_latlon_in)
subroutine horiz_interp_solo_2d(data_in, lon_in, lat_in, lon_out, lat_out, data_out, verbose, mask_in, mask_out, interp_method, missing_value, missing_permit, num_nbrs, max_dist, src_modulo)
subroutine horiz_interp_base_2d(Interp, data_in, data_out, verbose, mask_in, mask_out, missing_value, missing_permit, err_msg, new_missing_handle)
logical module_is_initialized
subroutine, public constants_init
dummy routine.
subroutine horiz_interp_solo_1d(data_in, lon_in, lat_in, lon_out, lat_out, data_out, verbose, mask_in, mask_out, interp_method, missing_value, missing_permit, num_nbrs, max_dist, src_modulo, grid_at_center)
real(fp), parameter, public pi
subroutine horiz_interp_solo_old(data_in, wb, sb, dx, dy, lon_out, lat_out, data_out, verbose, mask_in, mask_out)