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
213 dzdx = atan2( cnvtopo_smooth_maxslope_ratio * cdz(
k), dxl(i) ) / d2r
214 dzdy = atan2( cnvtopo_smooth_maxslope_ratio * cdz(
k), dyl(j) ) / d2r
215 minslope(
is,
js) = min( minslope(
is,
js), dzdx, dzdy )
224 dzdx = atan2( cnvtopo_smooth_maxslope_ratio * cdz(
k), dxl(i) ) / d2r
225 dzdy = atan2( cnvtopo_smooth_maxslope_ratio * cdz(
k), dyl(j) ) / d2r
226 minslope(i,
js) = min( minslope(i,
js), dzdx, dzdy )
238 dzdx = atan2( cnvtopo_smooth_maxslope_ratio * cdz(
k), dxl(i) ) / d2r
239 dzdy = atan2( cnvtopo_smooth_maxslope_ratio * cdz(
k), dyl(j) ) / d2r
240 minslope(
is,j) = min( minslope(
is,j), dzdx, dzdy )
252 dzdx = atan2( cnvtopo_smooth_maxslope_ratio * cdz(
k), dxl(i) ) / d2r
253 dzdy = atan2( cnvtopo_smooth_maxslope_ratio * cdz(
k), dyl(j) ) / d2r
254 minslope(i,j) = min( minslope(i,j), dzdx, dzdy )
260 call statistics_horizontal_min(
ia,
is,
ie,
ja,
js,
je, &
261 minslope(:,:), cnvtopo_smooth_maxslope_limit )
291 if ( cnvtopo_donothing )
then
293 log_progress(*)
'skip convert topography data'
296 log_progress(*)
'start convert topography data'
308 if ( cnvtopo_usegtopo30 )
then
312 if ( cnvtopo_usegmted2010 )
then
316 if ( cnvtopo_usedem50m )
then
320 if ( cnvtopo_useuserfile )
then
329 log_progress(*)
'end convert topography data'
338 subroutine cnvtopo_gtopo30( TOPO_Zsfc )
347 real(rp),
intent(inout) :: topo_zsfc(
ia,
ja)
349 character(len=H_LONG) :: gtopo30_in_dir =
'.'
350 character(len=H_LONG) :: gtopo30_in_catalogue =
''
352 namelist / param_cnvtopo_gtopo30 / &
357 real(rp),
parameter :: gtopo30_dlat = 30.0_rp / 60.0_rp / 60.0_rp
358 real(rp),
parameter :: gtopo30_dlon = 30.0_rp / 60.0_rp / 60.0_rp
361 real(rp) :: zsfc(
ia,
ja)
369 read(
io_fid_conf,nml=param_cnvtopo_gtopo30,iostat=ierr)
371 log_info(
"CNVTOPO_GTOPO30",*)
'Not found namelist. Default used.'
372 elseif( ierr > 0 )
then
373 log_error(
"CNVTOPO_GTOPO30",*)
'Not appropriate names in namelist PARAM_CNVTOPO_GTOPO30. Check!'
376 log_nml(param_cnvtopo_gtopo30)
380 gtopo30_dlat, gtopo30_dlon, &
381 gtopo30_in_dir, gtopo30_in_catalogue, &
384 call cnv2d_exec( zsfc(:,:), min_value = -9000.0_rp, yrevers = .true. )
390 if ( zsfc(i,j) /= undef ) topo_zsfc(i,j) = zsfc(i,j)
396 end subroutine cnvtopo_gtopo30
400 subroutine cnvtopo_gmted2010( TOPO_Zsfc )
402 real(rp),
intent(inout) :: topo_zsfc(
ia,
ja)
406 end subroutine cnvtopo_gmted2010
410 subroutine cnvtopo_dem50m( TOPO_Zsfc )
419 real(rp),
intent(inout) :: topo_zsfc(
ia,
ja)
421 character(len=H_LONG) :: dem50m_in_dir =
'.'
422 character(len=H_LONG) :: dem50m_in_catalogue =
''
424 namelist / param_cnvtopo_dem50m / &
428 real(rp),
parameter :: dem50m_dlat = 5.0_rp / 60.0_rp / 200.0_rp
429 real(rp),
parameter :: dem50m_dlon = 7.5_rp / 60.0_rp / 200.0_rp
432 real(rp) :: zsfc(
ia,
ja)
440 read(
io_fid_conf,nml=param_cnvtopo_dem50m,iostat=ierr)
442 log_info(
"CNVTOPO_DEM50M",*)
'Not found namelist. Default used.'
443 elseif( ierr > 0 )
then
444 log_error(
"CNVTOPO_DEM50M",*)
'Not appropriate names in namelist PARAM_CNVTOPO_DEM50M. Check!'
447 log_nml(param_cnvtopo_dem50m)
450 dem50m_dlat, dem50m_dlon, &
451 dem50m_in_dir, dem50m_in_catalogue, &
454 call cnv2d_exec( zsfc(:,:), min_value = -900.0_rp )
460 if ( zsfc(i,j) /= undef ) topo_zsfc(i,j) = zsfc(i,j)
466 end subroutine cnvtopo_dem50m
470 subroutine cnvtopo_userfile( TOPO_Zsfc )
480 real(rp),
intent(inout) :: topo_zsfc(
ia,
ja)
482 character(len=H_SHORT) :: userfile_type =
''
485 character(len=H_SHORT) :: userfile_dtype =
'REAL4'
486 real(rp) :: userfile_dlat = -1.0_rp
487 real(rp) :: userfile_dlon = -1.0_rp
488 character(len=H_LONG) :: userfile_dir =
'.'
489 character(len=H_LONG) :: userfile_catalogue =
''
490 logical :: userfile_yrevers = .false.
491 real(rp) :: userfile_minval = 0.0_rp
494 character(len=H_LONG) :: userfile_grads_filename =
''
495 character(len=H_SHORT) :: userfile_grads_varname =
'topo'
496 character(len=H_SHORT) :: userfile_grads_latname =
'lat'
497 character(len=H_SHORT) :: userfile_grads_lonname =
'lon'
498 character(len=H_SHORT) :: userfile_interp_type =
'LINEAR'
499 integer :: userfile_interp_level = 5
502 namelist / param_cnvtopo_userfile / &
507 userfile_catalogue, &
511 userfile_grads_filename, &
512 userfile_grads_varname, &
513 userfile_grads_latname, &
514 userfile_grads_lonname, &
515 userfile_interp_type, &
516 userfile_interp_level
519 real(rp) :: zsfc(
ia,
ja)
521 character(len=H_LONG) :: fname
531 read(
io_fid_conf,nml=param_cnvtopo_userfile,iostat=ierr)
533 log_info(
"CNVTOPO_USERFILE",*)
'Not found namelist. Default used.'
534 elseif( ierr > 0 )
then
535 log_error(
"CNVTOPO_USERFILE",*)
'Not appropriate names in namelist PARAM_CNVTOPO_USERFILE. Check!'
538 log_nml(param_cnvtopo_userfile)
541 select case ( userfile_type )
544 if ( userfile_dlat <= 0.0_rp )
then
545 log_error(
"CNVTOPO_USERFILE",*)
'USERFILE_DLAT (width (deg.) of latitude tile) should be positive. Check! ', userfile_dlat
548 if ( userfile_dlon <= 0.0_rp )
then
549 log_error(
"CNVTOPO_USERFILE",*)
'USERFILE_DLON (width (deg.) of longitude tile) should be positive. Check! ', userfile_dlon
552 if ( userfile_catalogue ==
'' )
then
553 log_error(
"CNVTOPO_USERFILE",*)
'Catalogue file does not specified. Check!'
558 userfile_dlat, userfile_dlon, &
559 userfile_dir, userfile_catalogue, &
564 if ( userfile_grads_filename ==
'' )
then
565 log_error(
"CNVTOPO_USERFILE",*)
'GrADS file name does not specified. Check!'
570 userfile_grads_varname, &
571 userfile_grads_latname, &
572 userfile_grads_lonname, &
573 userfile_interp_type, &
574 userfile_interp_level )
577 log_error(
"CNVTOPO_USERFILE",*)
'USERFILE_TYPE is invalid: ',trim(userfile_type)
578 log_error_cont(*)
'It must be "TILE" or "GrADS"'
583 min_value = userfile_minval, yrevers = userfile_yrevers )
589 if ( zsfc(i,j) /= undef ) topo_zsfc(i,j) = zsfc(i,j)
595 end subroutine cnvtopo_userfile
599 subroutine cnvtopo_smooth( &
611 statistics_horizontal_max
620 real(rp),
intent(inout) :: zsfc(
ia,
ja)
622 real(rp) :: dzsfc_dxy(
ia,
ja,2)
624 real(rp) :: dxl(
ia-1)
625 real(rp) :: dyl(
ja-1)
627 real(rp) :: flx_x(
ia,
ja)
628 real(rp) :: flx_y(
ia,
ja)
630 real(rp) :: slope(
ia,
ja)
632 real(rp),
pointer :: topo_sign(:,:)
633 real(rp),
allocatable,
target :: topo_sign_t(:,:)
634 real(rp) :: flag, ocean_flag
636 character(len=8),
parameter :: varname(2) = (/
"DZsfc_DX",
"DZsfc_DY" /)
643 if ( cnvtopo_smooth_type ==
'OFF' )
then
645 log_info(
"CNVTOPO_smooth",*)
'Do not apply smoothing.'
650 log_info(
"CNVTOPO_smooth",*)
'Apply smoothing.'
651 log_info_cont(*)
'Slope limit = ', cnvtopo_smooth_maxslope_limit
652 log_info_cont(*)
'Smoothing type = ', cnvtopo_smooth_type
653 log_info_cont(*)
'Smoothing locally = ', cnvtopo_smooth_local
660 if ( cnvtopo_smooth_trim_ocean )
then
661 allocate( topo_sign_t(
ia,
ja) )
662 topo_sign => topo_sign_t
670 * ( 0.5_rp + sign( 0.5_rp, eps - abs(zsfc(i,j)) ) )
671 topo_sign(i,j) = sign( 1.0_rp, zsfc(i,j) ) * ( 1.0_rp - ocean_flag )
682 do ite = 1, cnvtopo_smooth_itelim+1
683 log_progress(*)
'smoothing itelation : ', ite
691 dzsfc_dxy(i,j,1) = atan2( ( zsfc(i+1,j)-zsfc(i,j) ), dxl(i) ) / d2r
696 dzsfc_dxy(
ia,:,1) = 0.0_rp
702 dzsfc_dxy(i,j,2) = atan2( ( zsfc(i,j+1)-zsfc(i,j) ), dyl(j) ) / d2r
707 dzsfc_dxy(:,
ja,2) = 0.0_rp
711 slope(:,:) = max( abs(dzsfc_dxy(:,:,1)), abs(dzsfc_dxy(:,:,2)) )
713 call statistics_horizontal_max(
ia,
is,
ie,
ja,
js,
je, &
714 slope(:,:), maxslope )
716 log_progress(*)
'maximum slope [deg] : ', maxslope
718 if( maxslope < cnvtopo_smooth_maxslope_limit )
exit
721 varname(:), dzsfc_dxy(:,:,:) )
723 select case( cnvtopo_smooth_type )
732 zsfc(i,j) = ( 0.2500_rp * zsfc(i ,j ) &
733 + 0.1250_rp * zsfc(i-1,j ) &
734 + 0.1250_rp * zsfc(i+1,j ) &
735 + 0.1250_rp * zsfc(i ,j-1) &
736 + 0.1250_rp * zsfc(i ,j+1) &
737 + 0.0625_rp * zsfc(i-1,j-1) &
738 + 0.0625_rp * zsfc(i+1,j-1) &
739 + 0.0625_rp * zsfc(i-1,j+1) &
740 + 0.0625_rp * zsfc(i+1,j+1) )
751 flx_x(i,j) = zsfc(i+1,j) - zsfc(i,j)
767 flx_y(i,j) = zsfc(i,j+1) - zsfc(i,j)
780 if ( cnvtopo_smooth_local )
then
787 + sign(0.5_rp, max( abs(dzsfc_dxy(i+1,j ,1)), &
788 abs(dzsfc_dxy(i ,j ,1)), &
789 abs(dzsfc_dxy(i-1,j ,1)), &
790 abs(dzsfc_dxy(i+1,j ,2)), &
791 abs(dzsfc_dxy(i+1,j-1,2)), &
792 abs(dzsfc_dxy(i ,j ,2)), &
793 abs(dzsfc_dxy(i ,j-1,2)) &
794 ) - cnvtopo_smooth_maxslope_limit )
795 flx_x(i,j) = flx_x(i,j) * flag
805 + sign(0.5_rp, max( abs(dzsfc_dxy(i ,j+1,2)), &
806 abs(dzsfc_dxy(i ,j ,2)), &
807 abs(dzsfc_dxy(i ,j-1,2)), &
808 abs(dzsfc_dxy(i ,j+1,1)), &
809 abs(dzsfc_dxy(i-1,j+1,1)), &
810 abs(dzsfc_dxy(i ,j ,1)), &
811 abs(dzsfc_dxy(i-1,j ,1)) &
812 ) - cnvtopo_smooth_maxslope_limit )
813 flx_y(i,j) = flx_y(i,j) * flag
823 zsfc(i,j) = zsfc(i,j) &
824 + 0.1_rp * ( ( flx_x(i,j) - flx_x(i-1,j) ) &
825 + ( flx_y(i,j) - flx_y(i,j-1) ) )
831 log_error(
"CNVTOPO_smooth",*)
'Invalid smoothing type'
835 if ( cnvtopo_smooth_trim_ocean )
then
840 zsfc(i,j) = sign( max( zsfc(i,j) * topo_sign(i,j), 0.0_rp ), topo_sign(i,j) )
848 if ( ite > cnvtopo_smooth_itelim )
then
849 log_error(
"CNVTOPO_smooth",*)
'Smoothing did not converge until ', cnvtopo_smooth_itelim,
' times of iteration.'
851 log_error_cont(*)
'Please try different parameters of PARAM_CNVTOPO.'
852 log_error_cont(*)
'- Number limit of iteration (CNVTOPO_smooth_itelim) = ', cnvtopo_smooth_itelim
853 log_error_cont(*)
'- Maximum ratio of slope dZ/dX, dZ/dY (CNVTOPO_smooth_maxslope_ratio) = ', cnvtopo_smooth_maxslope_ratio
854 log_error_cont(*)
' Or, Maximum of slope with degree (CNVTOPO_smooth_maxslope) = ', cnvtopo_smooth_maxslope
855 log_error_cont(*)
'- Smoothing type LAPLACIAN/GAUSSIAN/OFF (CNVTOPO_smooth_type) = ', trim(cnvtopo_smooth_type)
859 log_info(
"CNVTOPO_smooth",*)
'smoothing complete.'
864 if ( cnvtopo_smooth_hypdiff_niter > 0 )
then
867 log_info(
"CNVTOPO_smooth",*)
'Apply hyperdiffusion.'
871 cnvtopo_smooth_hypdiff_order, cnvtopo_smooth_hypdiff_niter, &
872 limiter_sign = topo_sign(:,:) )
880 dzsfc_dxy(i,j,1) = atan2( ( zsfc(i+1,j)-zsfc(i,j) ), dxl(i) ) / d2r
885 dzsfc_dxy(
ia,:,1) = 0.0_rp
891 dzsfc_dxy(i,j,2) = atan2( ( zsfc(i,j+1)-zsfc(i,j) ), dyl(j) ) / d2r
896 dzsfc_dxy(:,
ja,2) = 0.0_rp
900 slope(:,:) = max( abs(dzsfc_dxy(:,:,1)), abs(dzsfc_dxy(:,:,2)) )
902 call statistics_horizontal_max(
ia,
is,
ie,
ja,
js,
je, &
903 slope(:,:), maxslope )
905 log_info(
"CNVTOPO_smooth",*)
'maximum slope [deg] : ', maxslope
912 varname(:), dzsfc_dxy(:,:,:) )
915 if ( cnvtopo_smooth_trim_ocean )
then
923 end subroutine cnvtopo_smooth