anchor.diff:  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! Spergel Press section
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  -else if (nonlocal .eqv. .true.) then ! if nonlocal=true, use Spergel & Press regime to calculate transport
  -! the functions of interest are in nonlocalmod
  +else if (nonlocal .eqv. .true.) then ! if nonlocal=true, use Spergel & Press regime to calculate heat transport
  +! The nonlocal transport scheme: http://articles.adsabs.harvard.edu/pdf/1985ApJ...294..663S
  +! the functions of interest are in nonlocalmod. These also use https://arxiv.org/pdf/0809.1871.pdf
   !print *, "calculating spergel press"
   guess_1 = 1.0d7 ! Change these to better guesses later?
   guess_2 = 1.01d7
   tolerance = 1.0d-4
   
  -!! Convert to SI
  -!sigma_0 = sigma_0*1.0d-4 ! Convert sigma to m^2
  -!phi_SI = phi*1.0d-4 ! Convert to m^2s^-2
  -!starrho_SI = tab_starrho*1.0d3	! Convert to kg/m^3
  -
  +! Tx is the Spergel & Press one-zone WIMP temperature
   Tx = newtons_meth(Tx_integral, tab_r*Rsun, tab_T, phi, tab_starrho, mxg, nabund, AtomicNumber*mnucg, & 
   	sigma_0*sigma_N, Nwimps, nlines, niso, guess_1, guess_2, tolerance)
  +
   ! Etrans in erg/g/s
   Etrans = Etrans_nl(Tx, tab_r*Rsun, tab_T, phi, tab_starrho, mxg, nabund, AtomicNumber*mnucg, &
  -	 sigma_0*sigma_N, Nwimps, nlines, niso)
  -print *, "Transgen: Tx = ", Tx, "niso = ", niso
  +	 sigma_0*sigma_N, Nwimps, nlines, niso) ! erg/g/s
  +print *, "Transgen: Tx = ", Tx
   
   EtransTot = trapz(tab_r*Rsun, 4*pi*(tab_r*Rsun)**2*Etrans*tab_starrho, nlines)
   print *, "Transgen: total transported energy = ", EtransTot
   
  -open(10, file="/home/luke/summer_2020/mesa/captngen/Etrans_sp.txt")
  -do i=1,nlines
  -	write(10, *) tab_r(i), Etrans(i), tab_starrho(i), tab_T(i), sum(nabund(:,1))*mnucg
  -enddo
  -close(10)
  -open(10, file="/home/luke/summer_2020/mesa/captngen/nuclear_abundances.txt")
  -write(10, *) "niso =", niso
  -do i=1,nlines
  -	write(10,*) nabund(:,i)
  -enddo
  -close(10)
  -
  -print *, "Nwimps = ", Nwimps
  +! Write Etrans to file
  +!open(10, file="/home/luke/summer_2020/mesa/captngen/Etrans_sp.txt")
  +!do i=1,nlines
  +!	write(10, *) tab_r(i), Etrans(i), tab_starrho(i), tab_T(i), sum(nabund(:,1))*mnucg
  +!enddo
  +!close(10)
   
   return
   
   endif
  -!print *, "Transgen finished"
  +
   end subroutine transgen
  
positive.code: cumint(i) = cumint(i-1) + integrand*tab_dr(i)*Rsun
  end if
  nx(i) = (tab_T(i)/Tc)**(3./2.)*exp(-cumint(i))
  ! print*,nx(i)
  cumNx = cumNx + 4.*pi*tab_r(i)**2*tab_dr(i)*nx(i)*Rsun**3.
  
  nxIso(i) = Nwimps*exp(-Rsun**2*tab_r(i)**2/rchi**2)/(pi**(3./2.)*rchi**3) !normalized correctly
  ! print*,exp(-Rsun**2*tab_r(i)**2/rchi**2)
  end do
  nx = nx/cumNx*nwimps !normalize density
  ! print*, "niso 1 ", NxIso(1), tab_r(1), Nwimps, 1./(pi**(3./2.)*rchi**3)
  fgoth = 1./(1.+(K/.4)**2)
  hgoth = ((tab_r*Rsun - rchi)/rchi)**3 +1.
  hgoth(1) = 0.d0 !some floating point shenanigans.
  
negative.code: ! dLdr(nlines) = 0.d0
  ! dLdr = dLdr/Rsun
  
  
  Etrans = 1./(4.*pi*(tab_r+epso)**2*tab_starrho)*dLdR/Rsun**2;
  
  EtransTot = trapz(tab_r,abs(dLdR),nlines)
  
  ! Write Etrans to file
  ! open(55,file = "/home/luke/summer_2020/mesa/captngen/captranstest.dat")
  ! do i=1,nlines
  ! write(55,*) tab_r(i), nx(i), tab_T(i), Ltrans(i), Etrans(i), dTdR(i), dLdR(i), tab_starrho(i), tab_g(i), dphidr(i)
  ! end do
  ! close(55)
  
  return
  
  
  !
  ! open(55,file = "smallarrays.dat")
  