Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=intkind), | intent(in), | dimension(:) | :: | lb | Lower bound indices of the grid array |
|
integer(kind=intkind), | intent(in), | dimension(:) | :: | ub | Upper bound indices of the grid array |
|
real(kind=realkind), | intent(in), | optional | dimension(:,:) | :: | x | Distance in x-direction [m] |
real(kind=realkind), | intent(in), | optional | dimension(:,:) | :: | y | Distance in y-direction [m] |
real(kind=realkind), | intent(in), | optional | dimension(:,:) | :: | dx | Grid spacing in x-direction [m] |
real(kind=realkind), | intent(in), | optional | dimension(:,:) | :: | dy | Grid spacing in y-direction [m] |
real(kind=realkind), | intent(in), | optional | dimension(:,:) | :: | lon | Longitude [rad] |
real(kind=realkind), | intent(in), | optional | dimension(:,:) | :: | lat | Latitude [rad] |
type(grid_type) function constructor_2d(lb,ub,x,y,dx,dy,lon,lat) result(grid)
integer(kind=intkind),dimension(:),intent(in) :: lb
!! Lower bound indices of the grid array
integer(kind=intkind),dimension(:),intent(in) :: ub
!! Upper bound indices of the grid array
real(kind=realkind),dimension(:,:),intent(in),optional :: x
!! Distance in x-direction [m]
real(kind=realkind),dimension(:,:),intent(in),optional :: y
!! Distance in y-direction [m]
real(kind=realkind),dimension(:,:),intent(in),optional :: dx
!! Grid spacing in x-direction [m]
real(kind=realkind),dimension(:,:),intent(in),optional :: dy
!! Grid spacing in y-direction [m]
real(kind=realkind),dimension(:,:),intent(in),optional :: lon
!! Longitude [rad]
real(kind=realkind),dimension(:,:),intent(in),optional :: lat
!! Latitude [rad]
integer(kind=intkind) :: grid_rank
integer(kind=intkind) :: idm,jdm
integer(kind=intkind) :: i,j
! Raise error if lb and ub are not of matching ranks
if(.not. size(lb) == size(ub))then
write(unit=stderr,fmt='(a)')'Error in grid constructor: size(lb) must == '&
//'size(ub)'
stop 1
endif
grid % lb = lb
grid % ub = ub
allocate(grid % x(grid % lb(1):grid % ub(1),grid % lb(2):grid % ub(2)))
allocate(grid % y(grid % lb(1):grid % ub(1),grid % lb(2):grid % ub(2)))
allocate(grid % dx(grid % lb(1):grid % ub(1),grid % lb(2):grid % ub(2)))
allocate(grid % dy(grid % lb(1):grid % ub(1),grid % lb(2):grid % ub(2)))
if(present(x) .and. present(y))then
! x and y are given as input arguments
grid % x = x
grid % y = y
! Compute dx and dy using centered differences
grid % dx = diff(x,dim=1)
grid % dy = diff(y,dim=2)
elseif(present(dx) .and. present(dy))then
! dx and dy are given as input arguments
grid % dx = dx
grid % dy = dy
! Compute x using dx provided as input argument
grid % x(1,:) = 0
do i = grid % lb(1)+1,grid % ub(1)
grid % x(i,:) = grid % x(i-1,:) + grid % dx(i,:)
enddo
! Compute y using dy provided as input argument
grid % y(:,1) = 0
do j = grid % lb(2)+1,grid % ub(2)
grid % y(:,j) = grid % y(:,j-1) + grid % dy(:,j)
enddo
endif
endfunction constructor_2d