module deque_mod
    implicit none
    type deque
        integer(4),pointer:: v(:)
        integer(4):: l,r
        integer(4):: lmax, rmax
    end type
    private
    public:: deque
    public:: init_deque
    public:: append, appendleft
    public:: pop, popleft
    public:: right, left
    public:: remaining_elements
    public:: remain

contains
    subroutine init_deque(dq)
        ! 初期化
        type(deque):: dq
        dq%r=0; dq%rmax=1
        dq%l=1; dq%lmax=-1
        allocate(dq%v(dq%lmax:dq%rmax))
    end subroutine


    subroutine append(dq,num)
        ! 右端に挿入
        type(deque):: dq
        integer(4):: num
        if (dq%r+1 > dq%rmax) call add_(dq)
        dq%r=dq%r+1
        dq%v(dq%r) = num
    end subroutine

    subroutine appendleft(dq,num)
        ! 左端に挿入
        type(deque):: dq
        integer(4):: num
        if (dq%l-1 < dq%lmax) call add_(dq)
        dq%l=dq%l-1
        dq%v(dq%l) = num
    end subroutine

    subroutine add_(dq)
        ! arrayの延長
        type(deque):: dq
        integer(4):: l
        integer(4),pointer:: tmp(:)
        l = size(dq%v)
        allocate(tmp(l))
        tmp(:) = dq%v(:)
        deallocate(dq%v)
        allocate(dq%v(2*dq%lmax:2*dq%rmax))
        dq%v(dq%lmax:dq%rmax) = tmp(:)
        dq%lmax = 2*dq%lmax
        dq%rmax = 2*dq%rmax
    end subroutine


    function pop(dq) result(ret)
        ! 右端から取り出し
        type(deque):: dq
        integer(4):: ret
        ret = dq%v(dq%r)
        dq%r=dq%r-1
    end function

    function popleft(dq) result(ret)
        ! 左端から取り出し
        type(deque):: dq
        integer(4):: ret
        ret = dq%v(dq%l)
        dq%l=dq%l+1
    end function


    function right(dq) result(ret)
        ! 右端を確認
        type(deque):: dq
        integer(4):: ret
        ret = dq%v(dq%r)
    end function

    function left(dq) result(ret)
        ! 左端を確認
        type(deque):: dq
        integer(4):: ret
        ret = dq%v(dq%l)
    end function

    function remaining_elements(dq) result(ret)
        ! 残りの要素数
        type(deque):: dq
        integer(4):: ret 
        ret = dq%r - dq%l + 1
    end function

    function remain(dq) result(ret)
        ! 要素が残っているかどうか
        type(deque):: dq
        logical:: ret
        ret = remaining_elements(dq) > 0
    end function
end module

program name
    use,intrinsic :: iso_fortran_env
    use deque_mod
    implicit none
    integer(int32):: h,w,i,j
    integer(int32):: nx,ny,dx,dy
    character(1),allocatable:: a(:,:)
    integer(int64),allocatable:: dp(:,:)
    integer(int64),parameter:: md=1000000007
    logical,allocatable:: see(:,:)
    type(deque):: tdx,tdy

    call init_deque(tdx)
    call init_deque(tdy)
    read*, h,w
    allocate(a(w,h),dp(w,h),see(w,h))
    dp(:,:) = 0
    dp(1,1) = 1
    input_character : block
        character(w):: inpt_a
        do i = 1, h
            read*, inpt_a
            do j = 1, w
                a(j,i) = inpt_a(j:j)
            end do
        end do
    end block input_character


    call append(tdx,1)
    call append(tdy,1)
    see(:,:) = .false.
    see(1,1) = .true.

    do while(remain(tdx))
        nx = popleft(tdx)
        ny = popleft(tdy)
        do dy=0,1
            do dx=0,1
                if (dx==dy) cycle
                if (nx+dx > w .or. ny+dy > h) cycle
                if (a(nx+dx,ny+dy) == '#') cycle
                dp(nx+dx,ny+dy) = mod(dp(nx+dx,ny+dy)+dp(nx,ny),md)
                if (see(nx+dx,ny+dy)) cycle
                call append(tdx, nx+dx)
                call append(tdy, ny+dy)
                see(nx+dx,ny+dy) = .true.
            end do
        end do
        ! print*, '--',nx,ny
        ! do i=1,h
        !     print'(100i4)', dp(:,i)
        ! end do
    end do


    
    print'(i0)', dp(w,h)




end program name

Measured memory_bytes: 44108