program f90_rectmesh
    implicit none
    integer::nn,mm
    integer::NODT,NELT
    integer,allocatable::kakom(:,:)
    real(8),allocatable::x(:),y(:)
    real(8)::aa,bb,x0,y0
    integer::i,j,k,ne,i0
    character(len=50)::dummy


    call getarg(1,dummy);read(dummy,*) aa
    call getarg(2,dummy);read(dummy,*) bb
    call getarg(3,dummy);read(dummy,*) nn
    call getarg(4,dummy);read(dummy,*) mm
    call getarg(5,dummy);read(dummy,*) x0
    call getarg(6,dummy);read(dummy,*) y0

    NODT = (nn + 1) * (mm + 1)
    NELT = nn * mm
    allocate(kakom(1:NELT, 1:4))
    allocate(x(1:NODT),y(1:NODT))

    k = 0
    do i = 0,mm
        do j = 0,nn
            k = k + 1
            x(k) = aa / dble(nn) * dble(j) + x0
            y(k) = bb / dble(mm) * dble(i) + y0
        end do
    end do
    ne = 0
    do k = 0,mm - 1
        i0 = 1 + (nn + 1) * k
        do j = 0,nn - 1
            i = i0 + j
            ne = ne + 1
            kakom(ne, 1) = i
            kakom(ne, 2) = i + 1
            kakom(ne, 3) = kakom(ne, 2) + nn + 1
            kakom(ne, 4) = kakom(ne, 3) - 1
        end do
    end do

    write(6,'(2(i10))') NODT,NELT
    do ne=1,NELT
        write(6,'(5(i10))') (kakom(ne,j),j=1,4),ne
    end do
    do i=1,NODT
        write(6,'(2(e15.7),i10)') x(i),y(i),i
    end do

end program f90_rectmesh
