module M_Array_2D_to_1D
    
    contains
    
    subroutine Array_2D_to_1D ( asize, b1D )
    
        implicit none

        integer, intent(in) :: asize
        real*8, intent(in) :: b1D (asize)
        
        !LOCAL
        real*8, allocatable :: loc1D ( : )
        real*8, allocatable :: loc2D ( :, : )
        integer :: nx, ny
        integer:: i, j, ind
        integer :: ios

        print*, "--call Array_2D_to_1D start"

        allocate( loc1D ( asize ), stat = ios)

        if ( ios /= 0 ) then
            print*, "Memory can not be allocated loc1D"
            return
        endif
        
        loc1D(:) = b1D(:)
        
            !loc1D(:) = pack(b2D, .true.)
        
            !loc1D(:) = transfer(b2D, loc1D) 
            !loc1D(:) = transfer(b2D, 0.0_8, size(b2D)) 

            !nx = ubound ( b2D ( :, : ), DIM = 1 )
            !ny = ubound ( b2D ( :, : ), DIM = 2 )
            !loc1D(:) = reshape (b2D, (/nx*ny/))

            !loc2D(:,:) = reshape (loc1D, (/nx,ny/))

            !do j = 1, ny
            !    do i = 1, nx
            !        ind = ( j - 1 ) * nx + i
            !        loc1D ( ind ) = b2D ( i, j )
            !    enddo
            !enddo                

        deallocate( loc1D )

        print*, "--call Array_2D_to_1D finish"

        return
    end subroutine Array_2D_to_1D
end module M_Array_2D_to_1D