53 function get_topog_mean_1d_(blon, blat, zmean)
55 real(kind=fms_top_kind_),
intent(in),
dimension(:) :: blon
56 real(kind=fms_top_kind_),
intent(in),
dimension(:) :: blat
57 real(kind=fms_top_kind_),
intent(out),
dimension(:,:) :: zmean
59 logical :: GET_TOPOG_MEAN_1D_
60 integer,
parameter :: lkind = fms_top_kind_
63 if (.not. module_is_initialized)
call topography_init()
65 if ( any(shape(zmean(:,:)) /= (/
size(blon(:))-1,
size(blat(:))-1/)) ) &
66 call error_mesg(
'get_topog_mean_1d',
'shape(zmean) is not&
67 & equal to (/size(blon)-1,size(blat)-1/))', fatal)
69 get_topog_mean_1d_ = open_topog_file()
71 if (get_topog_mean_1d_)
call interp_topog(blon, blat, zmean)
75 end function get_topog_mean_1d_
79 function get_topog_mean_2d_(blon, blat, zmean)
81 real(kind=fms_top_kind_),
intent(in),
dimension(:,:) :: blon, blat
82 real(kind=fms_top_kind_),
intent(out),
dimension(:,:) :: zmean
83 logical :: GET_TOPOG_MEAN_2D_
84 integer,
parameter :: lkind = fms_top_kind_
86 if (.not. module_is_initialized)
call topography_init()
88 if ( any(shape(zmean(:,:)) /= (/
size(blon,1)-1,
size(blon,2)-1/)) .or. &
89 any(shape(zmean(:,:)) /= (/
size(blat,1)-1,
size(blat,2)-1/)) ) &
90 call error_mesg(
'get_topog_mean_2d',
'shape(zmean) is not&
91 & equal to (/size(blon,1)-1,size(blon,2)-1/))', fatal)
93 get_topog_mean_2d_ = open_topog_file()
95 if (get_topog_mean_2d_)
call interp_topog(blon, blat, zmean)
98 end function get_topog_mean_2d_
111 function get_topog_stdev_1d_(blon, blat, stdev)
113 real(kind=fms_top_kind_),
intent(in),
dimension(:) :: blon
114 real(kind=fms_top_kind_),
intent(in),
dimension(:) :: blat
115 real(kind=fms_top_kind_),
intent(out),
dimension(:,:) :: stdev
118 logical :: GET_TOPOG_STDEV_1D_
119 integer,
parameter :: lkind = fms_top_kind_
121 if (.not. module_is_initialized)
call topography_init()
123 if ( any(shape(stdev(:,:)) /= (/
size(blon(:))-1,
size(blat(:))-1/)) ) &
124 call error_mesg(
'get_topog_stdev',
'shape(stdev) is not&
125 & equal to (/size(blon)-1,size(blat)-1/))', fatal)
127 get_topog_stdev_1d_ = open_topog_file()
129 if (get_topog_stdev_1d_)
call interp_topog(blon, blat, &
130 stdev, flag=compute_stdev)
134 end function get_topog_stdev_1d_
138 function get_topog_stdev_2d_(blon, blat, stdev)
140 real(FMS_TOP_KIND_),
intent(in),
dimension(:,:) :: blon, blat
141 real(FMS_TOP_KIND_),
intent(out),
dimension(:,:) :: stdev
142 logical :: GET_TOPOG_STDEV_2D_
143 integer,
parameter :: lkind = fms_top_kind_
145 if (.not. module_is_initialized)
call topography_init()
147 if ( any(shape(stdev(:,:)) /= (/
size(blon,1)-1,
size(blon,2)-1/)) .or. &
148 any(shape(stdev(:,:)) /= (/
size(blat,1)-1,
size(blat,2)-1/)) ) &
149 call error_mesg(
'get_topog_stdev_2d',
'shape(stdev) is not&
150 & equal to (/size(blon,1)-1,size(blon,2)-1/))', fatal)
152 get_topog_stdev_2d_ = open_topog_file()
154 if (get_topog_stdev_2d_)
call interp_topog(blon, blat, &
155 stdev, flag=compute_stdev)
158 end function get_topog_stdev_2d_
165 function get_ocean_frac_1d_(blon, blat, ocean_frac)
167 real(FMS_TOP_KIND_),
intent(in),
dimension(:) :: blon
168 real(FMS_TOP_KIND_),
intent(in),
dimension(:) :: blat
169 real(FMS_TOP_KIND_),
intent(out),
dimension(:,:) :: ocean_frac
171 logical :: GET_OCEAN_FRAC_1D_
172 integer,
parameter :: lkind = fms_top_kind_
174 if (.not. module_is_initialized)
call topography_init()
176 if ( any(shape(ocean_frac(:,:)) /= (/
size(blon(:))-1,
size(blat(:))-1/)) ) &
177 call error_mesg(
'get_ocean_frac',
'shape(ocean_frac) is not&
178 & equal to (/size(blon)-1,size(blat)-1/))', fatal)
180 get_ocean_frac_1d_ = open_water_file()
181 if(get_ocean_frac_1d_)
call interp_water( blon, blat, &
182 ocean_frac, do_ocean=.true. )
186 end function get_ocean_frac_1d_
190 function get_ocean_frac_2d_(blon, blat, ocean_frac)
192 real(kind=fms_top_kind_),
intent(in),
dimension(:,:) :: blon, blat
193 real(kind=fms_top_kind_),
intent(out),
dimension(:,:) :: ocean_frac
194 logical :: GET_OCEAN_FRAC_2D_
195 integer,
parameter :: lkind = fms_top_kind_
197 if (.not. module_is_initialized)
call topography_init()
199 if ( any(shape(ocean_frac(:,:)) /= (/
size(blon,1)-1,
size(blon,2)-1/)) .or. &
200 any(shape(ocean_frac(:,:)) /= (/
size(blat,1)-1,
size(blat,2)-1/)) ) &
201 call error_mesg(
'get_ocean_frac_2d',
'shape(ocean_frac) is not&
202 & equal to (/size(blon,1)-1,size(blon,2)-1/))', fatal)
204 get_ocean_frac_2d_ = open_water_file()
205 if(get_ocean_frac_2d_)
call interp_water( blon, blat, &
206 ocean_frac, do_ocean=.true. )
210 end function get_ocean_frac_2d_
217 function get_ocean_mask_1d_(blon, blat, ocean_mask)
219 real(kind=fms_top_kind_),
intent(in),
dimension(:) :: blon
220 real(kind=fms_top_kind_),
intent(in),
dimension(:) :: blat
221 logical,
intent(out),
dimension(:,:) :: ocean_mask
223 logical :: GET_OCEAN_MASK_1D_
224 real(kind=fms_top_kind_),
dimension(size(ocean_mask,1),size(ocean_mask,2)) :: ocean_frac
225 integer,
parameter :: lkind = fms_top_kind_
227 if (.not. module_is_initialized)
call topography_init()
229 if (get_ocean_frac(blon, blat, ocean_frac) )
then
230 where (ocean_frac > 0.50_lkind)
235 get_ocean_mask_1d_ = .true.
237 get_ocean_mask_1d_ = .false.
241 end function get_ocean_mask_1d_
245 function get_ocean_mask_2d_(blon, blat, ocean_mask)
247 real(kind=fms_top_kind_),
intent(in),
dimension(:,:) :: blon, blat
248 logical,
intent(out),
dimension(:,:) :: ocean_mask
249 logical :: GET_OCEAN_MASK_2D_
250 real(kind=fms_top_kind_),
dimension(size(ocean_mask,1),size(ocean_mask,2)) :: ocean_frac
251 integer,
parameter :: lkind = fms_top_kind_
253 if (.not. module_is_initialized)
call topography_init()
255 if (get_ocean_frac(blon, blat, ocean_frac) )
then
256 where (ocean_frac > 0.50_lkind)
261 get_ocean_mask_2d_ = .true.
263 get_ocean_mask_2d_ = .false.
268 end function get_ocean_mask_2d_
276 function get_water_frac_1d_(blon, blat, water_frac)
277 real(kind=fms_top_kind_),
intent(in),
dimension(:) :: blon
278 real(kind=fms_top_kind_),
intent(in),
dimension(:) :: blat
279 real(kind=fms_top_kind_),
intent(out),
dimension(:,:) :: water_frac
281 logical :: GET_WATER_FRAC_1D_
282 integer,
parameter :: lkind = fms_top_kind_
285 if (.not. module_is_initialized)
call topography_init()
287 if ( any(shape(water_frac(:,:)) /= (/
size(blon(:))-1,
size(blat(:))-1/)) ) &
288 call error_mesg(
'get_water_frac_1d',
'shape(water_frac) is not&
289 & equal to (/size(blon)-1,size(blat)-1/))', fatal)
291 get_water_frac_1d_ = open_water_file()
292 if(get_water_frac_1d_)
call interp_water( blon, blat, water_frac )
296 end function get_water_frac_1d_
300 function get_water_frac_2d_(blon, blat, water_frac)
302 real(kind=fms_top_kind_),
intent(in),
dimension(:,:) :: blon
303 real(kind=fms_top_kind_),
intent(in),
dimension(:,:) :: blat
304 real(kind=fms_top_kind_),
intent(out),
dimension(:,:) :: water_frac
306 logical :: GET_WATER_FRAC_2D_
307 integer,
parameter :: lkind = fms_top_kind_
310 if (.not. module_is_initialized)
call topography_init()
312 if ( any(shape(water_frac(:,:)) /= (/
size(blon,1)-1,
size(blon,2)-1/)) .or. &
313 any(shape(water_frac(:,:)) /= (/
size(blat,1)-1,
size(blat,2)-1/)) ) &
314 call error_mesg(
'get_water_frac_2d',
'shape(water_frac) is not&
315 & equal to (/size(blon,1)-1,size(blon,2)-1/))', fatal)
317 get_water_frac_2d_ = open_water_file()
318 if(get_water_frac_2d_)
call interp_water( blon, blat, water_frac )
322 end function get_water_frac_2d_
330 function get_water_mask_1d_(blon, blat, water_mask)
332 real(kind=fms_top_kind_),
intent(in),
dimension(:) :: blon
333 real(kind=fms_top_kind_),
intent(in),
dimension(:) :: blat
334 logical,
intent(out),
dimension(:,:) :: water_mask
336 logical :: GET_WATER_MASK_1D_
338 real(kind=fms_top_kind_),
dimension(size(water_mask,1),size(water_mask,2)) :: water_frac
339 integer,
parameter :: lkind = fms_top_kind_
341 if (.not. module_is_initialized)
call topography_init()
343 if (get_water_frac(blon, blat, water_frac) )
then
344 where (water_frac > 0.50_lkind)
349 get_water_mask_1d_ = .true.
351 get_water_mask_1d_ = .false.
355 end function get_water_mask_1d_
359 function get_water_mask_2d_(blon, blat, water_mask)
361 real(kind=fms_top_kind_),
intent(in),
dimension(:,:) :: blon
362 real(kind=fms_top_kind_),
intent(in),
dimension(:,:) :: blat
363 logical,
intent(out),
dimension(:,:) :: water_mask
365 logical :: GET_WATER_MASK_2D_
366 real(kind=fms_top_kind_),
dimension(size(water_mask,1),size(water_mask,2)) :: water_frac
367 integer,
parameter :: lkind = fms_top_kind_
369 if (.not. module_is_initialized)
call topography_init()
371 if (get_water_frac(blon, blat, water_frac) )
then
372 where (water_frac > 0.50_lkind)
377 get_water_mask_2d_ = .true.
379 get_water_mask_2d_ = .false.
384 end function get_water_mask_2d_
388subroutine interp_topog_1d_( blon, blat, zout, flag)
389real(kind=fms_top_kind_),
intent(in) :: blon(:), blat(:)
390real(kind=fms_top_kind_),
intent(out) :: zout(:,:)
391integer,
intent(in),
optional :: flag
393real(kind=fms_top_kind_) :: xdat(ipts+1), ydat(jpts+1)
394real(kind=fms_top_kind_) :: zdat(ipts,jpts)
395real(kind=fms_top_kind_) :: zout2(
size(zout,1),
size(zout,2))
396integer,
parameter :: lkind = fms_top_kind_
398 call input_data(topog_index, xdat, ydat, zdat)
400 call horiz_interp( zdat, xdat, ydat, blon, blat, zout )
403 if (
present(flag))
then
404 if (flag == compute_stdev)
then
406 call horiz_interp ( zdat, xdat, ydat, blon, blat, zout2 )
407 zout = zout2 - zout*zout
408 where (zout > 0.0_lkind)
416end subroutine interp_topog_1d_
420subroutine interp_topog_2d_( blon, blat, zout, flag )
421real(kind=fms_top_kind_),
intent(in) :: blon(:,:), blat(:,:)
422real(kind=fms_top_kind_),
intent(out) :: zout(:,:)
423integer,
intent(in),
optional :: flag
425real(kind=fms_top_kind_) :: xdat(ipts+1), ydat(jpts+1)
426real(kind=fms_top_kind_) :: zdat(ipts,jpts)
427real(kind=fms_top_kind_) :: zout2(
size(zout,1),
size(zout,2))
428integer,
parameter :: lkind = fms_top_kind_
430type (horiz_interp_type) :: Interp
432 call input_data(topog_index, xdat, ydat, zdat)
434 call find_indices( minval(blat), maxval(blat), ydat, js, je )
436 call horiz_interp_new ( interp, xdat, ydat(js:je+1), blon, blat )
437 call horiz_interp ( interp, zdat(:,js:je), zout )
440 if (
present(flag))
then
441 if (flag == compute_stdev)
then
443 call horiz_interp ( interp, zdat(:,js:je), zout2 )
444 zout = zout2 - zout*zout
445 where (zout > 0.0_lkind)
453 call horiz_interp_del( interp )
455end subroutine interp_topog_2d_
459subroutine find_indices_( ybeg, yend, ydat, js, je )
460real(kind=fms_top_kind_),
intent(in) :: ybeg, yend, ydat(:)
461integer,
intent(out) :: js, je
463integer,
parameter :: lkind = fms_top_kind_
466 do j = 1,
size(ydat(:))-1
467 if (ybeg >= ydat(j) .and. ybeg <= ydat(j+1))
then
474 do j = js,
size(ydat(:))-1
475 if (yend >= ydat(j) .and. yend <= ydat(j+1))
then
483end subroutine find_indices_
486subroutine input_data_( indx, xdat, ydat, zdat )
487integer,
intent(in) :: indx
488real(kind=fms_top_kind_),
intent(out) :: xdat(ipts+1), ydat(jpts+1), zdat(ipts,jpts)
490if( file_is_opened(indx) )
then
491 call read_data(fileobj(indx),
'xdat', xdat)
492 call read_data(fileobj(indx),
'ydat', ydat)
493 call read_data(fileobj(indx),
'zdat', zdat)
496end subroutine input_data_
500subroutine interp_water_1d_( blon, blat, zout, do_ocean )
501real(kind=fms_top_kind_),
intent(in) :: blon(:), blat(:)
502real(kind=fms_top_kind_),
intent(out) :: zout(:,:)
503logical,
intent(in),
optional :: do_ocean
504real(kind=fms_top_kind_) :: xdat(ipts+1), ydat(jpts+1), zdat(ipts,jpts)
505 call input_data ( water_index, xdat, ydat, zdat )
508if (
present(do_ocean))
then
509 if (do_ocean)
call determine_ocean_points (zdat)
513call horiz_interp ( zdat, xdat, ydat, blon, blat, zout )
515end subroutine interp_water_1d_
519subroutine interp_water_2d_( blon, blat, zout, do_ocean )
520real(kind=fms_top_kind_),
intent(in) :: blon(:,:), blat(:,:)
521real(kind=fms_top_kind_),
intent(out) :: zout(:,:)
522logical,
intent(in),
optional :: do_ocean
523real(kind=fms_top_kind_) :: xdat(ipts+1), ydat(jpts+1), zdat(ipts,jpts)
525call input_data ( water_index, xdat, ydat, zdat )
528if (
present(do_ocean))
then
529 if (do_ocean)
call determine_ocean_points (zdat)
533call horiz_interp ( zdat, xdat, ydat, blon, blat, zout )
535end subroutine interp_water_2d_
539subroutine determine_ocean_points_(pctwater)
540real(kind=fms_top_kind_),
intent(inout) :: pctwater(:,:)
541logical :: ocean(size(pctwater,1),size(pctwater,2))
542integer :: i, j, m, n, im, ip, jm, jp, new
543integer,
parameter :: lkind = fms_top_kind_
544real(kind=fms_top_kind_) :: ocean_pct_crit = 0.500_lkind
556ocean = (pctwater > 0.999_lkind)
568 if (.not.ocean(i,j) .and. pctwater(i,j) > ocean_pct_crit)
then
569 im = i-1; ip = i+1; jm = j-1; jp = j+1
571 if (ip == m+1) ip = 1
573 if (jp == n+1) jp = n
575 if (ocean(im,j ) .or. ocean(ip,j ) .or. ocean(i ,jm) .or. ocean(i ,jp) .or. &
576 ocean(im,jm) .or. ocean(ip,jm) .or. ocean(ip,jp) .or. ocean(im,jp))
then
588where (.not.ocean) pctwater = 0.0_lkind
590end subroutine determine_ocean_points_