39 private :: cnvtopo_gtopo30
40 private :: cnvtopo_gmted2010
41 private :: cnvtopo_dem50m
42 private :: cnvtopo_userfile
43 private :: cnvtopo_smooth
49 character(len=H_SHORT),
private :: CNVTOPO_smooth_type =
'LAPLACIAN'
53 logical,
private :: CNVTOPO_DoNothing
54 logical,
private :: CNVTOPO_UseGTOPO30 = .false.
55 logical,
private :: CNVTOPO_UseGMTED2010 = .false.
56 logical,
private :: CNVTOPO_UseDEM50M = .false.
57 logical,
private :: CNVTOPO_UseUSERFILE = .false.
59 integer,
private :: CNVTOPO_smooth_hypdiff_order = 4
60 integer,
private :: CNVTOPO_smooth_hypdiff_niter = 20
61 logical,
private :: CNVTOPO_smooth_local = .true.
62 integer,
private :: CNVTOPO_smooth_itelim = 10000
63 logical,
private :: CNVTOPO_smooth_trim_ocean = .true.
64 real(RP),
private :: CNVTOPO_smooth_maxslope_ratio = 5.0_rp
65 real(RP),
private :: CNVTOPO_smooth_maxslope = -1.0_rp
66 real(RP),
private :: CNVTOPO_smooth_maxslope_limit
68 logical,
private :: CNVTOPO_copy_parent = .false.
82 statistics_horizontal_min
89 character(len=H_SHORT) :: cnvtopo_name =
'NONE'
91 namelist / param_cnvtopo / &
96 cnvtopo_useuserfile, &
97 cnvtopo_smooth_trim_ocean, &
98 cnvtopo_smooth_hypdiff_order, &
99 cnvtopo_smooth_hypdiff_niter, &
100 cnvtopo_smooth_maxslope_ratio, &
101 cnvtopo_smooth_maxslope, &
102 cnvtopo_smooth_local, &
103 cnvtopo_smooth_itelim, &
104 cnvtopo_smooth_type, &
107 real(rp) :: minslope(
ia,
ja)
108 real(rp) :: dxl(
ia-1)
109 real(rp) :: dyl(
ja-1)
110 real(rp) :: dzdx, dzdy
117 log_info(
"CNVTOPO_setup",*)
'Setup'
126 log_info(
"CNVTOPO_setup",*)
'Not found namelist. Default used.'
127 elseif( ierr > 0 )
then
128 log_error(
"CNVTOPO_setup",*)
'Not appropriate names in namelist PARAM_CNVTOPO. Check!'
131 log_nml(param_cnvtopo)
133 select case(cnvtopo_name)
137 cnvtopo_usegtopo30 = .true.
138 cnvtopo_usegmted2010 = .false.
139 cnvtopo_usedem50m = .false.
140 cnvtopo_useuserfile = .false.
147 cnvtopo_usegtopo30 = .false.
148 cnvtopo_usegmted2010 = .false.
149 cnvtopo_usedem50m = .true.
150 cnvtopo_useuserfile = .false.
152 cnvtopo_usegtopo30 = .true.
153 cnvtopo_usegmted2010 = .true.
154 cnvtopo_usedem50m = .true.
155 cnvtopo_useuserfile = .false.
158 cnvtopo_useuserfile = .true.
160 log_error(
"CNVTOPO_setup",*)
'Unsupported TYPE: ', trim(cnvtopo_name)
164 cnvtopo_donothing = .true.
166 if ( cnvtopo_usegtopo30 )
then
167 cnvtopo_donothing = .false.
168 log_info(
"CNVTOPO_setup",*)
'Use GTOPO, global 30 arcsec. data'
169 if ( cnvtopo_usegmted2010 )
then
170 log_info(
"CNVTOPO_setup",*)
'Use GMTED2010, new global 5 arcsec. data'
171 log_info(
"CNVTOPO_setup",*)
'Overwrite Existing region'
173 if ( cnvtopo_usedem50m )
then
174 log_info(
"CNVTOPO_setup",*)
'Use DEM 50m data for Japan region'
175 log_info(
"CNVTOPO_setup",*)
'Overwrite Japan region'
177 elseif ( cnvtopo_usegmted2010 )
then
178 cnvtopo_donothing = .false.
179 log_info(
"CNVTOPO_setup",*)
'Use GMTED2010, new global 5 arcsec. data'
180 if ( cnvtopo_usedem50m )
then
181 log_info(
"CNVTOPO_setup",*)
'Use DEM 50m data for Japan region'
182 log_info(
"CNVTOPO_setup",*)
'Overwrite Japan region'
184 elseif ( cnvtopo_usedem50m )
then
185 cnvtopo_donothing = .false.
186 log_info(
"CNVTOPO_setup",*)
'Use DEM 50m data, Japan region only'
187 elseif ( cnvtopo_useuserfile )
then
188 cnvtopo_donothing = .false.
189 log_info(
"CNVTOPO_setup",*)
'Use user-defined file'
192 if ( cnvtopo_donothing )
then
193 log_info(
"CNVTOPO_setup",*)
'Do nothing for topography data'
196 if( cnvtopo_smooth_maxslope > 0.0_rp )
then
198 cnvtopo_smooth_maxslope_limit = cnvtopo_smooth_maxslope
206 dzdx = atan2( cnvtopo_smooth_maxslope_ratio * cdz(
k), dxl(i) ) / d2r
207 dzdy = atan2( cnvtopo_smooth_maxslope_ratio * cdz(
k), dyl(j) ) / d2r
208 minslope(
is,
js) = min( minslope(
is,
js), dzdx, dzdy )
214 dzdx = atan2( cnvtopo_smooth_maxslope_ratio * cdz(
k), dxl(i) ) / d2r
215 dzdy = atan2( cnvtopo_smooth_maxslope_ratio * cdz(
k), dyl(j) ) / d2r
216 minslope(i,
js) = min( minslope(i,
js), dzdx, dzdy )
225 dzdx = atan2( cnvtopo_smooth_maxslope_ratio * cdz(
k), dxl(i) ) / d2r
226 dzdy = atan2( cnvtopo_smooth_maxslope_ratio * cdz(
k), dyl(j) ) / d2r
227 minslope(
is,j) = min( minslope(
is,j), dzdx, dzdy )
236 dzdx = atan2( cnvtopo_smooth_maxslope_ratio * cdz(
k), dxl(i) ) / d2r
237 dzdy = atan2( cnvtopo_smooth_maxslope_ratio * cdz(
k), dyl(j) ) / d2r
238 minslope(i,j) = min( minslope(i,j), dzdx, dzdy )
243 call statistics_horizontal_min(
ia,
is,
ie,
ja,
js,
je, &
244 minslope(:,:), cnvtopo_smooth_maxslope_limit )
271 if ( cnvtopo_donothing )
then
273 log_progress(*)
'skip convert topography data'
276 log_progress(*)
'start convert topography data'
286 if ( cnvtopo_usegtopo30 )
then
290 if ( cnvtopo_usegmted2010 )
then
294 if ( cnvtopo_usedem50m )
then
298 if ( cnvtopo_useuserfile )
then
307 log_progress(*)
'end convert topography data'
316 subroutine cnvtopo_gtopo30( TOPO_Zsfc )
325 real(rp),
intent(inout) :: topo_zsfc(
ia,
ja)
327 character(len=H_LONG) :: gtopo30_in_dir =
'.'
328 character(len=H_LONG) :: gtopo30_in_catalogue =
''
330 namelist / param_cnvtopo_gtopo30 / &
335 real(rp),
parameter :: gtopo30_dlat = 30.0_rp / 60.0_rp / 60.0_rp
336 real(rp),
parameter :: gtopo30_dlon = 30.0_rp / 60.0_rp / 60.0_rp
339 real(rp) :: zsfc(
ia,
ja)
347 read(
io_fid_conf,nml=param_cnvtopo_gtopo30,iostat=ierr)
349 log_info(
"CNVTOPO_GTOPO30",*)
'Not found namelist. Default used.'
350 elseif( ierr > 0 )
then
351 log_error(
"CNVTOPO_GTOPO30",*)
'Not appropriate names in namelist PARAM_CNVTOPO_GTOPO30. Check!'
354 log_nml(param_cnvtopo_gtopo30)
358 gtopo30_dlat, gtopo30_dlon, &
359 gtopo30_in_dir, gtopo30_in_catalogue, &
362 call cnv2d_exec( zsfc(:,:), min_value = -9000.0_rp, yrevers = .true. )
367 if ( zsfc(i,j) /= undef ) topo_zsfc(i,j) = zsfc(i,j)
372 end subroutine cnvtopo_gtopo30
376 subroutine cnvtopo_gmted2010( TOPO_Zsfc )
378 real(rp),
intent(inout) :: topo_zsfc(
ia,
ja)
382 end subroutine cnvtopo_gmted2010
386 subroutine cnvtopo_dem50m( TOPO_Zsfc )
395 real(rp),
intent(inout) :: topo_zsfc(
ia,
ja)
397 character(len=H_LONG) :: dem50m_in_dir =
'.'
398 character(len=H_LONG) :: dem50m_in_catalogue =
''
400 namelist / param_cnvtopo_dem50m / &
404 real(rp),
parameter :: dem50m_dlat = 5.0_rp / 60.0_rp / 200.0_rp
405 real(rp),
parameter :: dem50m_dlon = 7.5_rp / 60.0_rp / 200.0_rp
408 real(rp) :: zsfc(
ia,
ja)
416 read(
io_fid_conf,nml=param_cnvtopo_dem50m,iostat=ierr)
418 log_info(
"CNVTOPO_DEM50M",*)
'Not found namelist. Default used.'
419 elseif( ierr > 0 )
then
420 log_error(
"CNVTOPO_DEM50M",*)
'Not appropriate names in namelist PARAM_CNVTOPO_DEM50M. Check!'
423 log_nml(param_cnvtopo_dem50m)
426 dem50m_dlat, dem50m_dlon, &
427 dem50m_in_dir, dem50m_in_catalogue, &
430 call cnv2d_exec( zsfc(:,:), min_value = -900.0_rp )
435 if ( zsfc(i,j) /= undef ) topo_zsfc(i,j) = zsfc(i,j)
440 end subroutine cnvtopo_dem50m
444 subroutine cnvtopo_userfile( TOPO_Zsfc )
454 real(rp),
intent(inout) :: topo_zsfc(
ia,
ja)
456 character(len=H_SHORT) :: userfile_type =
''
459 character(len=H_SHORT) :: userfile_dtype =
'REAL4'
460 real(rp) :: userfile_dlat = -1.0_rp
461 real(rp) :: userfile_dlon = -1.0_rp
462 character(len=H_LONG) :: userfile_dir =
'.'
463 character(len=H_LONG) :: userfile_catalogue =
''
464 logical :: userfile_yrevers = .false.
465 real(rp) :: userfile_minval = 0.0_rp
468 character(len=H_LONG) :: userfile_grads_filename =
''
469 character(len=H_SHORT) :: userfile_grads_varname =
'topo'
470 character(len=H_SHORT) :: userfile_grads_latname =
'lat'
471 character(len=H_SHORT) :: userfile_grads_lonname =
'lon'
472 character(len=H_SHORT) :: userfile_interp_type =
'LINEAR'
473 integer :: userfile_interp_level = 5
476 namelist / param_cnvtopo_userfile / &
481 userfile_catalogue, &
485 userfile_grads_filename, &
486 userfile_grads_varname, &
487 userfile_grads_latname, &
488 userfile_grads_lonname, &
489 userfile_interp_type, &
490 userfile_interp_level
493 real(rp) :: zsfc(
ia,
ja)
495 character(len=H_LONG) :: fname
505 read(
io_fid_conf,nml=param_cnvtopo_userfile,iostat=ierr)
507 log_info(
"CNVTOPO_USERFILE",*)
'Not found namelist. Default used.'
508 elseif( ierr > 0 )
then
509 log_error(
"CNVTOPO_USERFILE",*)
'Not appropriate names in namelist PARAM_CNVTOPO_USERFILE. Check!'
512 log_nml(param_cnvtopo_userfile)
515 select case ( userfile_type )
518 if ( userfile_dlat <= 0.0_rp )
then
519 log_error(
"CNVTOPO_USERFILE",*)
'USERFILE_DLAT (width (deg.) of latitude tile) should be positive. Check! ', userfile_dlat
522 if ( userfile_dlon <= 0.0_rp )
then
523 log_error(
"CNVTOPO_USERFILE",*)
'USERFILE_DLON (width (deg.) of longitude tile) should be positive. Check! ', userfile_dlon
526 if ( userfile_catalogue ==
'' )
then
527 log_error(
"CNVTOPO_USERFILE",*)
'Catalogue file does not specified. Check!'
532 userfile_dlat, userfile_dlon, &
533 userfile_dir, userfile_catalogue, &
538 if ( userfile_grads_filename ==
'' )
then
539 log_error(
"CNVTOPO_USERFILE",*)
'GrADS file name does not specified. Check!'
544 userfile_grads_varname, &
545 userfile_grads_latname, &
546 userfile_grads_lonname, &
547 userfile_interp_type, &
548 interp_level = userfile_interp_level )
551 log_error(
"CNVTOPO_USERFILE",*)
'USERFILE_TYPE is invalid: ',trim(userfile_type)
552 log_error_cont(*)
'It must be "TILE" or "GrADS"'
557 min_value = userfile_minval, yrevers = userfile_yrevers )
562 if ( zsfc(i,j) /= undef ) topo_zsfc(i,j) = zsfc(i,j)
567 end subroutine cnvtopo_userfile
571 subroutine cnvtopo_smooth( &
583 statistics_horizontal_max
592 real(rp),
intent(inout) :: zsfc(
ia,
ja)
594 real(rp) :: dzsfc_dxy(
ia,
ja,2)
596 real(rp) :: dxl(
ia-1)
597 real(rp) :: dyl(
ja-1)
599 real(rp) :: flx_x(
ia,
ja)
600 real(rp) :: flx_y(
ia,
ja)
602 real(rp) :: slope(
ia,
ja)
604 real(rp),
pointer :: topo_sign(:,:)
605 real(rp) :: flag, ocean_flag
607 character(len=8),
parameter :: varname(2) = (/
"DZsfc_DX",
"DZsfc_DY" /)
614 if ( cnvtopo_smooth_type ==
'OFF' )
then
616 log_info(
"CNVTOPO_smooth",*)
'Do not apply smoothing.'
621 log_info(
"CNVTOPO_smooth",*)
'Apply smoothing.'
622 log_info_cont(*)
'Slope limit = ', cnvtopo_smooth_maxslope_limit
623 log_info_cont(*)
'Smoothing type = ', cnvtopo_smooth_type
624 log_info_cont(*)
'Smoothing locally = ', cnvtopo_smooth_local
631 if ( cnvtopo_smooth_trim_ocean )
then
632 allocate( topo_sign(
ia,
ja) )
638 * ( 0.5_rp + sign( 0.5_rp, eps - abs(zsfc(i,j)) ) )
639 topo_sign(i,j) = sign( 1.0_rp, zsfc(i,j) ) * ( 1.0_rp - ocean_flag )
647 do ite = 1, cnvtopo_smooth_itelim+1
648 log_progress(*)
'smoothing itelation : ', ite
655 dzsfc_dxy(i,j,1) = atan2( ( zsfc(i+1,j)-zsfc(i,j) ), dxl(i) ) / d2r
658 dzsfc_dxy(
ia,:,1) = 0.0_rp
662 dzsfc_dxy(i,j,2) = atan2( ( zsfc(i,j+1)-zsfc(i,j) ), dyl(j) ) / d2r
665 dzsfc_dxy(:,
ja,2) = 0.0_rp
667 slope(:,:) = max( abs(dzsfc_dxy(:,:,1)), abs(dzsfc_dxy(:,:,2)) )
668 call statistics_horizontal_max(
ia,
is,
ie,
ja,
js,
je, &
669 slope(:,:), maxslope )
671 log_progress(*)
'maximum slope [deg] : ', maxslope
673 if( maxslope < cnvtopo_smooth_maxslope_limit )
exit
676 varname(:), dzsfc_dxy(:,:,:) )
678 select case( cnvtopo_smooth_type )
685 zsfc(i,j) = ( 0.2500_rp * zsfc(i ,j ) &
686 + 0.1250_rp * zsfc(i-1,j ) &
687 + 0.1250_rp * zsfc(i+1,j ) &
688 + 0.1250_rp * zsfc(i ,j-1) &
689 + 0.1250_rp * zsfc(i ,j+1) &
690 + 0.0625_rp * zsfc(i-1,j-1) &
691 + 0.0625_rp * zsfc(i+1,j-1) &
692 + 0.0625_rp * zsfc(i-1,j+1) &
693 + 0.0625_rp * zsfc(i+1,j+1) )
702 flx_x(i,j) = zsfc(i+1,j) - zsfc(i,j)
716 flx_y(i,j) = zsfc(i,j+1) - zsfc(i,j)
728 if ( cnvtopo_smooth_local )
then
734 + sign(0.5_rp, max( abs(dzsfc_dxy(i+1,j ,1)), &
735 abs(dzsfc_dxy(i ,j ,1)), &
736 abs(dzsfc_dxy(i-1,j ,1)), &
737 abs(dzsfc_dxy(i+1,j ,2)), &
738 abs(dzsfc_dxy(i+1,j-1,2)), &
739 abs(dzsfc_dxy(i ,j ,2)), &
740 abs(dzsfc_dxy(i ,j-1,2)) &
741 ) - cnvtopo_smooth_maxslope_limit )
742 flx_x(i,j) = flx_x(i,j) * flag
750 + sign(0.5_rp, max( abs(dzsfc_dxy(i ,j+1,2)), &
751 abs(dzsfc_dxy(i ,j ,2)), &
752 abs(dzsfc_dxy(i ,j-1,2)), &
753 abs(dzsfc_dxy(i ,j+1,1)), &
754 abs(dzsfc_dxy(i-1,j+1,1)), &
755 abs(dzsfc_dxy(i ,j ,1)), &
756 abs(dzsfc_dxy(i-1,j ,1)) &
757 ) - cnvtopo_smooth_maxslope_limit )
758 flx_y(i,j) = flx_y(i,j) * flag
766 zsfc(i,j) = zsfc(i,j) &
767 + 0.1_rp * ( ( flx_x(i,j) - flx_x(i-1,j) ) &
768 + ( flx_y(i,j) - flx_y(i,j-1) ) )
773 log_error(
"CNVTOPO_smooth",*)
'Invalid smoothing type'
777 if ( cnvtopo_smooth_trim_ocean )
then
781 zsfc(i,j) = sign( max( zsfc(i,j) * topo_sign(i,j), 0.0_rp ), topo_sign(i,j) )
788 if ( ite > cnvtopo_smooth_itelim )
then
789 log_error(
"CNVTOPO_smooth",*)
'Smoothing did not converge until ', cnvtopo_smooth_itelim,
' times of iteration.'
791 log_error_cont(*)
'Please try different parameters of PARAM_CNVTOPO.'
792 log_error_cont(*)
'- Number limit of iteration (CNVTOPO_smooth_itelim) = ', cnvtopo_smooth_itelim
793 log_error_cont(*)
'- Maximum ratio of slope dZ/dX, dZ/dY (CNVTOPO_smooth_maxslope_ratio) = ', cnvtopo_smooth_maxslope_ratio
794 log_error_cont(*)
' Or, Maximum of slope with degree (CNVTOPO_smooth_maxslope) = ', cnvtopo_smooth_maxslope
795 log_error_cont(*)
'- Smoothing type LAPLACIAN/GAUSSIAN/OFF (CNVTOPO_smooth_type) = ', trim(cnvtopo_smooth_type)
799 log_info(
"CNVTOPO_smooth",*)
'smoothing complete.'
804 if ( cnvtopo_smooth_hypdiff_niter > 0 )
then
807 log_info(
"CNVTOPO_smooth",*)
'Apply hyperdiffusion.'
811 cnvtopo_smooth_hypdiff_order, cnvtopo_smooth_hypdiff_niter, &
812 limiter_sign = topo_sign(:,:) )
819 dzsfc_dxy(i,j,1) = atan2( ( zsfc(i+1,j)-zsfc(i,j) ), dxl(i) ) / d2r
822 dzsfc_dxy(
ia,:,1) = 0.0_rp
826 dzsfc_dxy(i,j,2) = atan2( ( zsfc(i,j+1)-zsfc(i,j) ), dyl(j) ) / d2r
829 dzsfc_dxy(:,
ja,2) = 0.0_rp
831 slope(:,:) = max( abs(dzsfc_dxy(:,:,1)), abs(dzsfc_dxy(:,:,2)) )
832 call statistics_horizontal_max(
ia,
is,
ie,
ja,
js,
je, &
833 slope(:,:), maxslope )
835 log_info(
"CNVTOPO_smooth",*)
'maximum slope [deg] : ', maxslope
842 varname(:), dzsfc_dxy(:,:,:) )
847 end subroutine cnvtopo_smooth