anchor.diff:  Tc = tab_T(1)
   rhoc = tab_starrho(1)
   niso = niso_in
  -! print*, "Nwimps in ", Nwimps
   
   if (decsize .ge. nlines) stop "Major problem in transgen: your low-res size is larger than the original"
   !Check if the stellar parameters have been allocated
  
positive.code: double precision :: brcoeff(nlines), crcoeff(nlines), drcoeff(nlines) ! for spline
  double precision :: bdcoeff(decsize), cdcoeff(decsize), ddcoeff(decsize) ! for spline
  double precision :: smallgrid(decsize), smallR(decsize), smallT(decsize), smallL(decsize),smalldL(decsize),smalldT(decsize),ispline
  double precision :: Tx, guess_1, guess_2, tolerance ! For the Spergel & Press nonlocal scheme
  !print *, "transgen called"
  
  epso = tab_r(2)/10.d0 ! small number to prevent division by zero
  ! smallr = (/((i*1./dble(decsize-1)),i=1,decsize)/) - 1./dble(decsize-1)
  
negative.code: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  ! Spergel Press section
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  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
  
  ! 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) ! 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
  
  ! 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
  
  end subroutine transgen
  