PROGRAM bloch
	USE chebyshev
	USE hamiltonians
	IMPLICIT NONE
	INCLUDE "fftw3.f"
	REAL(8) :: q_period,p_period		
	INTEGER(4) :: n,m
		
	COMPLEX(8), DIMENSION(nq) :: psi
	COMPLEX(8), DIMENSION(nq), TARGET :: source_even,source_odd,transform,outcome
	TYPE (fftw) :: even,odd	
	REAL(8), PARAMETER :: timestep=10._8
	REAL(8) :: time=0._8
	INTEGER(4), PARAMETER :: n_iter=4000,n_steps=10
	REAl(8), PARAMETER :: q_init=610._8,p_init=0.2_8,deltaq_init=5._8 ! 0<=q,q_init<q_period
	REAL(8) :: emin,emax
	
	PRINT*,'1d tight-binding, hop=',hop,' force=',force
	PRINT*,'q_init=',q_init,'p_init=', p_init,'deltaq_init=', deltaq_init
	PRINT*

	dq=potential_period
	q_period=dq*nq
	p_period=h_planck*nq/q_period
	dp=p_period/np
	
	qn=(/ (dq*n, n=0,nq-1) /)
	pn=(/ (dp*n, n=0,np-1) /)
	
	emax=hop+bar_height
	emin=-hop-force*q_period

	even%inq=>source_even
	even%p=>transform
	even%outq=>outcome
	CALL dfftw_plan_dft_1d(even%planf,nq,even%inq,even%p, &
	    	FFTW_FORWARD,FFTW_MEASURE)
	CALL dfftw_plan_dft_1d(even%planr,nq,even%p,even%outq, &
	    	FFTW_BACKWARD,FFTW_MEASURE)
	odd%inq=>source_odd
	odd%p=>transform
	odd%outq=>outcome
	CALL dfftw_plan_dft_1d(odd%planf,nq,odd%inq,odd%p, &
	    	FFTW_FORWARD,FFTW_MEASURE)
	CALL dfftw_plan_dft_1d(odd%planr,nq,odd%p,odd%outq, &
	    	FFTW_BACKWARD,FFTW_MEASURE)
	
	psi=exp(-(min((qn-q_init)**2,(qn+q_period-q_init)**2,(qn-q_period-q_init)**2) &
		/(2*deltaq_init**2))+(0,1)*2*pi*p_init*qn)
	psi=psi/(sqrt(dot_product(psi,psi))*dq)
	
	even%inq=psi
	CALL print_psi()
	DO n=1,n_steps
		write(0,*) 'time=',time
		CALL cheb(psi,even,odd,timestep,tight1d,n_iter,hbar,emin,emax)
		time=time+timestep
		even%inq=psi
		CALL print_psi()
	ENDDO
	
	CONTAINS
		SUBROUTINE print_psi()
			IMPLICIT NONE
			INTEGER(4) n
			
			DO n=1,nq
				print "('q_psi(',2f22.12,' ) =',2e25.16e3)",time,qn(n),even%inq(n)
			ENDDO
			PRINT*
			
			CALL dfftw_execute(even%planf)
			even%p=even%p*dq 		
			
			DO n=1,np
				print "('p_psi(',2f22.12,' ) =',2e25.16e3)",time,pn(n),even%p(n)
			ENDDO
			PRINT*
		END SUBROUTINE print_psi
END PROGRAM bloch