27 subroutine get_mosaic_xgrid_(fileobj, i1, j1, i2, j2, area, ibegin, iend)
28 type(FmsNetcdfFile_t),
intent(in) :: fileobj
29 integer,
intent(inout) :: i1(:), j1(:), i2(:), j2(:)
30 real(kind=fms_mos_kind_),
intent(inout) :: area(:)
32 integer,
optional,
intent(in) :: ibegin, iend
34 integer :: start(4), nread(4), istart
35 real(kind=fms_mos_kind_),
dimension(2, size(i1(:))) :: tile1_cell, tile2_cell
37 real(kind=r8_kind) :: garea
38 real(kind=r8_kind) :: get_global_area
40 garea = get_global_area()
43 if(
present(ibegin) .and.
present(iend))
then
45 nxgrid = iend - ibegin + 1
46 if(nxgrid .NE.
size(i1(:)))
call mpp_error(fatal, .NE.
"get_mosaic_xgrid: nxgrid size(i1(:))")
47 if(nxgrid .NE.
size(j1(:)))
call mpp_error(fatal, .NE.
"get_mosaic_xgrid: nxgrid size(j1(:))")
48 if(nxgrid .NE.
size(i2(:)))
call mpp_error(fatal, .NE.
"get_mosaic_xgrid: nxgrid size(i2(:))")
49 if(nxgrid .NE.
size(j2(:)))
call mpp_error(fatal, .NE.
"get_mosaic_xgrid: nxgrid size(j2(:))")
50 if(nxgrid .NE.
size(area(:)))
call mpp_error(fatal, .NE.
"get_mosaic_xgrid: nxgrid size(area(:))")
57 start(1) = istart; nread(1) = nxgrid
59 call read_data(fileobj,
'xgrid_area', area, corner=start, edge_lengths=nread)
63 start(2) = istart; nread(2) = nxgrid
65 call read_data(fileobj,
'tile1_cell', tile1_cell, corner=start, edge_lengths=nread)
66 call read_data(fileobj,
'tile2_cell', tile2_cell, corner=start, edge_lengths=nread)
69 i1(n) = int(tile1_cell(1,n))
70 j1(n) = int(tile1_cell(2,n))
71 i2(n) = int(tile2_cell(1,n))
72 j2(n) = int(tile2_cell(2,n))
73 area(n) = real( real(area(n),r8_kind)/garea, fms_mos_kind_ )
78 end subroutine get_mosaic_xgrid_
88 subroutine calc_mosaic_grid_area_(lon, lat, area)
89 real(kind=fms_mos_kind_),
dimension(:,:),
intent(in) :: lon
90 real(kind=fms_mos_kind_),
dimension(:,:),
intent(in) :: lat
91 real(kind=fms_mos_kind_),
dimension(:,:),
intent(out) :: area
94 real(r8_kind) :: area_r8(size(area,1),size(area,2))
99 if(
size(lon,1) .NE. nlon+1 .OR.
size(lat,1) .NE. nlon+1 ) &
100 call mpp_error(fatal,
"mosaic_mod: size(lon,1) and size(lat,1) should equal to size(area,1)+1")
101 if(
size(lon,2) .NE. nlat+1 .OR.
size(lat,2) .NE. nlat+1 ) &
102 call mpp_error(fatal,
"mosaic_mod: size(lon,2) and size(lat,2) should equal to size(area,2)+1")
105 call get_grid_area( nlon, nlat, real(lon,r8_kind), real(lat,r8_kind), area_r8)
107 area=real(area_r8,fms_mos_kind_)
109 end subroutine calc_mosaic_grid_area_
119 subroutine calc_mosaic_grid_great_circle_area_(lon, lat, area)
120 real(kind=fms_mos_kind_),
dimension(:,:),
intent(in) :: lon
121 real(kind=fms_mos_kind_),
dimension(:,:),
intent(in) :: lat
122 real(kind=fms_mos_kind_),
dimension(:,:),
intent(inout) :: area
123 integer :: nlon, nlat
125 real(r8_kind) :: area_r8(size(area,1),size(area,2))
130 if(
size(lon,1) .NE. nlon+1 .OR.
size(lat,1) .NE. nlon+1 ) &
131 call mpp_error(fatal,
"mosaic_mod: size(lon,1) and size(lat,1) should equal to size(area,1)+1")
132 if(
size(lon,2) .NE. nlat+1 .OR.
size(lat,2) .NE. nlat+1 ) &
133 call mpp_error(fatal,
"mosaic_mod: size(lon,2) and size(lat,2) should equal to size(area,2)+1")
136 call get_grid_great_circle_area( nlon, nlat, real(lon,r8_kind), real(lat,r8_kind), area_r8)
138 area=real(area_r8, fms_mos_kind_)
140 end subroutine calc_mosaic_grid_great_circle_area_
144 function is_inside_polygon_(lon1, lat1, lon2, lat2 )
145 real(kind=fms_mos_kind_),
intent(in) :: lon1, lat1
146 real(kind=fms_mos_kind_),
intent(in) :: lon2(:), lat2(:)
147 logical :: IS_INSIDE_POLYGON_
148 integer :: npts, isinside
149 integer :: inside_a_polygon
155 isinside = inside_a_polygon(real(lon1,r8_kind), real(lat1,r8_kind), npts, real(lon2,r8_kind), real(lat2,r8_kind))
156 if(isinside == 1)
then
157 is_inside_polygon_ = .true.
159 is_inside_polygon_ = .false.
164 end function is_inside_polygon_