MODULE arrays
	USE xsection
	USE input
	IMPLICIT NONE
	INTEGER::n,m
	CONTAINS
	SUBROUTINE making_arrays(nuc_density,events,disc_r,disc_v,cooling_E,cooling_b,xsec,density)
		IMPLICIT NONE
		INTEGER,ALLOCATABLE,INTENT(in out)::events(:,:,:)
		REAL(8),ALLOCATABLE,INTENT(in out)::nuc_density(:,:,:)
		REAL(8),ALLOCATABLE,INTENT(in out)::disc_r(:),disc_v(:),cooling_E(:),cooling_b(:),xsec(:,:,:,:,:,:)
		REAL(4),ALLOCATABLE,INTENT(in out)::density(:,:,:,:)
		INTEGER::i,e,CDR,FNLENGTH
		REAL(8)::null
		CHARACTER ::FILENAME*21
		OPEN(UNIT=20,FILE='disk velocity.csv')		!see Olling&Merrifiled 1998 for data
		n=0
		READ(20,*)
		DO
			READ(20,*,END=22)
			n=n+1
		END DO
		22 REWIND(20)
		ALLOCATE(disc_r(1:n))
		disc_r=0
		ALLOCATE(disc_v(1:n))
		disc_v=0
		READ(20,*)
		DO i=1,n
			READ(20,*)disc_r(i),disc_v(i)
		END DO
		CLOSE(20)
		SELECT CASE(plot)
			CASE('PAMELA','electrons')
				OPEN(UNIT=23,FILE='electron cooling.csv')		!see Kobayashi et al.2004 for data
				m=0
				READ(23,*)
				DO
					READ(23,*,END=25)
					m=m+1
				END DO
				25 REWIND(23)
				ALLOCATE(cooling_E(1:m))
				cooling_E=0
				ALLOCATE(cooling_b(1:m))
				cooling_b=0
				READ(23,*)
				DO i=1,m
					READ(23,*)cooling_E(i),cooling_b(i)
				END DO
				CLOSE(23)
		END SELECT 
		SELECT CASE(calculate)
			CASE('S/P')
				ALLOCATE(nuc_density(min_Z:max_Z,min_A:max_A,min_cell_E:max_cell_E))
				nuc_density=0
				ALLOCATE(events(min_Z:max_Z,min_A:max_A,min_cell_E:max_cell_E))
				events=0
				ALLOCATE(xsec(min_Z:max_Z,min_A:max_A,min_cell_E:max_cell_E,min_Z:max_Z,min_A:max_A,min_cell_E:max_cell_E))
				xsec=0
				OPEN(UNIT=10,FILE='energy.out')
				SELECT CASE(crossection)
					CASE('WEBBER')
						CDR=200
						FNLENGTH=21
						FILENAME='WNEWTR_082693.CDR.dat'
						CALL SET_SIGMA(CDR,FILENAME,FNLENGTH)
				END SELECT 
				SELECT CASE(plot)
					CASE('B/C')
						DO e=min_cell_E,max_cell_E
							CALL xsections_BC(e,xsec)
							WRITE (10,*)10**(energy_grid*e)
						END DO
					CASE('Iron')
						DO e=min_cell_E,max_cell_E
							CALL xsections_Iron(e,xsec)
							WRITE (10,*)10**(energy_grid*e)
						END DO
					CASE('PAMELA')
						DO e=min_cell_E,max_cell_E
							CALL xsections_PAMELA(e,xsec)
							WRITE (10,*)10**(energy_grid*e)
						END DO
				END SELECT 
			CASE('galaxy')
				ALLOCATE(density(-cell_XY:cell_XY,-cell_XY:cell_XY,-cell_Z:cell_Z,min_cell_E:max_cell_E))
				density=0
		END SELECT
		CLOSE(10)
	END SUBROUTINE making_arrays
END MODULE arrays