Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=intkind), | intent(in) | :: | lb | Lower bound indices of the grid array |
||
integer(kind=intkind), | intent(in) | :: | 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(:) | :: | dx | Grid spacing in x-direction [m] |
type(grid_type) function constructor_1d(lb,ub,x,dx) result(grid)
integer(kind=intkind),intent(in) :: lb
!! Lower bound indices of the grid array
integer(kind=intkind),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 :: dx
!! Grid spacing in x-direction [m]
integer(kind=intkind) :: i
grid % lb(1) = lb
grid % ub(1) = ub
grid % lb(2) = 1
grid % ub(2) = 1
allocate(grid % x(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)))
if(present(x) .and. .not. present(dx))then
! x is given as input argument
grid % x(:,1) = x
! Compute dx using centered differences
grid % dx(:,1) = diff(x)
elseif(.not. present(x) .and. present(dx))then
! dx is given as input argument
grid % dx(:,1) = dx
! Compute x using dx provided as input argument
grid % x(1,1) = 0
do i = grid % lb(1)+1,grid % ub(1)
grid % x(i,1) = grid % x(i-1,1) + grid % dx(i,1)
enddo
endif
allocate(grid % y(0,0))
allocate(grid % dy(0,0))
allocate(grid % lon(0,0))
allocate(grid % lat(0,0))
endfunction constructor_1d