testArray_prg Program

program~~testarray_prg~~UsesGraph program~testarray_prg testArray_prg module~kinds_mod kinds_mod module~kinds_mod->program~testarray_prg module~array_mod array_mod module~kinds_mod->module~array_mod module~array_mod->program~testarray_prg
Help


Test program for array_mod

Calls

program~~testarray_prg~~CallsGraph program~testarray_prg testArray_prg proc~testmeshgrid testMeshGrid program~testarray_prg->proc~testmeshgrid proc~testtdma testTDMA program~testarray_prg->proc~testtdma proc~testmixval testMixval program~testarray_prg->proc~testmixval proc~testspan testSpan program~testarray_prg->proc~testspan proc~testlinspace testLinspace program~testarray_prg->proc~testlinspace proc~testflatten testFlatten program~testarray_prg->proc~testflatten proc~testdedup testDeDup program~testarray_prg->proc~testdedup proc~testlinearinterp testLinearInterp program~testarray_prg->proc~testlinearinterp proc~testlu testLU program~testarray_prg->proc~testlu proc~meshgridy meshGridY proc~testmeshgrid->proc~meshgridy proc~linspace linspace proc~testmeshgrid->proc~linspace proc~meshgridx meshGridX proc~testmeshgrid->proc~meshgridx proc~testtdma->proc~linspace interface~tdma TDMA proc~testtdma->interface~tdma interface~mixval mixval proc~testmixval->interface~mixval interface~span span proc~testspan->interface~span proc~testlinspace->proc~linspace interface~flatten flatten proc~testflatten->interface~flatten proc~dedup deDup proc~testdedup->proc~dedup proc~testlinearinterp->proc~linspace proc~linearinterp linearInterp proc~testlinearinterp->proc~linearinterp interface~solvelu solveLU proc~testlu->interface~solvelu proc~findinterval findInterval proc~linearinterp->proc~findinterval
Help

Source Code


Subroutines

subroutine testMixval()

Test mixval to verify operation

Arguments

None

subroutine testSpan()

Test mixval to verify operation

Arguments

None

subroutine testFlatten()

Test mixval to verify operation

Arguments

None

subroutine testDeDup()

Test deDup to verify operation

Arguments

None

subroutine testLinspace()

Test linspace to verify operation

Arguments

None

subroutine testMeshGrid()

Test meshGridX and meshGridY to verify operation

Arguments

None

subroutine testLinearInterp()

Test linearInterp to verify operation

Arguments

None

subroutine testTDMA()

Test TDMA to verify operation

Arguments

None

subroutine testLU()

Test solveLU to verify operation

Arguments

None

Source Code

program testArray_prg
	!! Test program for array_mod
	use kinds_mod
	use array_mod
	implicit none
	
	call testMixval
	call testSpan
	call testFlatten
	
	call testDeDup
	
	call testLinspace
	call testMeshGrid
	
	call testLinearInterp
	
	call testTDMA
	call testLU
	
contains

	subroutine testMixval
		!! Test mixval to verify operation
		logical,dimension(1)::results
		
		integer,parameter::N = 10
		real(wp),dimension(N)::x
		real(wp),dimension(2)::test,true
		
		call random_number(x)
		
		test = mixval(x)
		true = [minval(x),maxval(x)]
		
		results(1) = all(test==true)
		
		if( .not.all(results) ) error stop "Failed mixval check"
	end subroutine testMixval

	subroutine testSpan
		!! Test mixval to verify operation
		logical,dimension(1)::results
		
		integer,parameter::N = 10
		real(wp),dimension(N)::x
		real(wp)::test,true
		
		call random_number(x)
		
		test = span(x)
		true = maxval(x)-minval(x)
		
		results(1) = test==true
		
		if( .not.all(results) ) error stop "Failed span check"
	end subroutine testSpan

	subroutine testFlatten
		!! Test mixval to verify operation
		logical,dimension(1)::results
		
		integer,parameter::N = 3
		integer,parameter::M = 4
		real(wp),dimension(N,M)::x
		real(wp),dimension(N*M)::y
		
		call random_number(x)
		y = flatten(x)
		
		results(1) = all( abs(y-reshape(x,[N*M]))<2.0_wp**4*epsilon(1.0_wp) )
		
		if( .not.all(results) ) error stop "Failed flatten check"
	end subroutine testFlatten

	subroutine testDeDup
		!! Test deDup to verify operation
		logical,dimension(1)::results
		
		results(1) = all( deDup([1,1,2,3,2,4])==[1,2,3,4] )
		
		if( .not.all(results) ) error stop "Failed deDup check"
	end subroutine testDeDup

	subroutine testLinspace
		!! Test linspace to verify operation
		logical,dimension(1)::results
		
		real(wp),dimension(:),allocatable::x,y
		integer::N,k
		
		N = 100
		x = linspace(0.0_wp,1.0_wp,N)
		y = [( real(k-1,wp)/real(N-1,wp) , k=1,N )]
		
		results(1) = norm2(x-y)<1.0E-10_wp
		
		if( .not.all(results) ) error stop "Failed linspace check"
	end subroutine testLinspace

	subroutine testMeshGrid
		!! Test meshGridX and meshGridY to verify operation
		logical,dimension(6)::results
		
		real(wp),dimension(:),allocatable::x,y
		real(wp),dimension(:,:),allocatable::XX,YY
		integer::N,M
		
		N = 5
		M = 6
		
		x = linspace(0.0_wp,1.0_wp,N)
		y = linspace(0.0_wp,1.0_wp,M)
		
		XX = meshGridX(x,y)
		YY = meshGridY(x,y)
		
		results(1) = all(XX(:,1)==x)
		results(2) = all(YY(1,:)==y)
		results(3) = all(XX(:,1)==XX(:,M))
		results(4) = all(YY(1,:)==YY(N,:))
		results(5) = all(shape(XX)==[N,M])
		results(6) = all(shape(YY)==[N,M])
		
		if( .not.all(results) ) error stop "Failed linspace check"
	end subroutine testMeshGrid

	subroutine testLinearInterp
		!! Test linearInterp to verify operation
		logical,dimension(1)::results
		
		real(wp),dimension(:),allocatable::x1,x2,y
		integer::N,k
		
		N = 100
		
		x1 = linspace(0.0_wp,5.0_wp,N)
		x2 = linspace(0.0_wp,5.0_wp,N/4)
		
		allocate(y(N))
		do k=1,N
			y(k) = linearInterp(x1(k),x2,2.0_wp*x2)
		end do
		
		results(1) = norm2(y-2.0_wp*x1)<1.0E-10_wp
		
		if( .not.all(results) ) error stop "Failed linearInterp check"
	end subroutine testLinearInterp

	subroutine testTDMA
		!! Test TDMA to verify operation
		
		real(wp),dimension(:,:),allocatable::A
		real(wp),dimension(:),allocatable::b,x,xt
		
		integer::N,k
		
		N = 10
		
		allocate( A(N,-1:+1) , x(N) , b(N) )
		xt = linspace(0.0_wp,1.0_wp,N)
		
		A(1,-1:+1) = [0.0_wp,1.0_wp,0.0_wp]
		b(   1   ) = 0.0_wp
		
		do k=2,N-1
			A(k,-1) =  1.0_wp
			A(k, 0) = -2.0_wp
			A(k,+1) =  1.0_wp
			b(  k ) =  0.0_wp
		end do
		
		A(N,-1:+1) = [0.0_wp,1.0_wp,0.0_wp]
		b(   N   ) = 1.0_wp
		
		x = TDMA(A,b)
		
		do k=1,N
			write(*,*) xt(k),x(k)
		end do
		
		write(*,*) norm2(xt-x)
	end subroutine testTDMA

	subroutine testLU
		!! Test solveLU to verify operation
		
		real(wp),dimension(:,:),allocatable::A
		real(wp),dimension(:),allocatable::x,b,bc
		integer::N
		
		do N=2,100
			if(allocated(A)) deallocate(A)
			if(allocated(b)) deallocate(b)
			
			allocate( A(N,N) , b(N) )
			
			call random_number(A)
			call random_number(b)
			
			x  = solveLU(A,b)
			bc = matmul(A,x)
			
			if( norm2(bc-b)>1.0E-10_wp ) stop 'solveLU Failed'
		end do
	end subroutine testLU

end program testArray_prg