subroutine frantic_prinsum(ilun)

  ! printout FRANTIC info on specified grid
  ! acquire the data via output routines; do not use frantic module

  use iso_c_binding, only: fp => c_double
  implicit none

  integer, intent(in) :: ilun    ! print on this Fortran LUN

  !----------------------------------------------------
  real(fp) :: zA,zZ,zFlux,zFluxOut,zEngy,zv_phi,zSce
  logical :: ivs_flag
  integer :: i,ik,ineut,inx

  real(fp), dimension(:), allocatable :: zn0,zT0,zvphi0,zpcx,zpii

  !  for balance checks:
  real(fp), dimension(:), allocatable :: zs,zflx,zioniz,zcx,zchk,dvols
  real(fp), dimension(:), allocatable :: zflx1,zflx2,ztmp
  real(fp) :: zssum,zflxsum,zinzsum,zcxsum,zchksum,zflxa,zflxb,zflxc,zflxd
  !----------------------------------------------------

  call frantic_get_nx_user(inx)
  allocate(zn0(inx),zT0(inx),zvphi0(inx),zpcx(inx),zpii(inx))
  allocate(zs(inx),zflx(inx),zioniz(inx),zcx(inx),zchk(inx),dvols(inx))
  allocate(zflx1(inx),zflx2(inx),ztmp(inx))

  call frantic_source_echo(zA,zZ,zFlux,zEngy,zv_phi,ivs_flag,ik)
  zFlux=1.0e-4_fp*zFlux
  zv_phi=100.0e0_fp*zv_phi

  write(ilun,*) ' '
  write(ilun,*) ' ================================================= '

  call frantic_get_inps(zflxa)
  if(ivs_flag) then
    write(ilun,'(1x,a)') ' VOLUME source (profile) '
  else
    write(ilun,'(1x,a,1x,1pe12.5)') ' EDGE source (atoms/sec): ',zflxa
  end if

  write(ilun,1001) zA,zZ,zFlux,zEngy,zv_phi
1001 format(/1x,'A=',1pd9.2,' Z=',1pd9.2,' Flux(#/cm**2/sec)=',1pd13.6, &
       ' <E>(KeV)=',1pd13.6/' <v_phi>(cm/sec)=',1pd13.6// &
       1x,'  # n0            T0            vphi0         pcx           pii'/ &
       1x,'    cm**-3        KeV           cm/sec        W/cm**3       W/cm**3'/)
1002 format(1x,i3,5(1x,1pd13.6))

  call frantic_get_n0(ik,zn0); zn0=1.0e-6_fp*zn0
  call frantic_get_t0(ik,zt0)
  call frantic_get_vphi0(ik,zvphi0); zvphi0=1.0e2_fp*zvphi0

  call frantic_get_pcx(zpcx); zpcx=1.0e-6_fp*zpcx
  call frantic_get_pii(zpii); zpii=1.0e-6_fp*zpii

  do i=1,inx
    write(ilun,1002) i,zn0(i),zt0(i),zvphi0(i),zpcx(i),zpii(i)
  end do

  write(ilun,1008)

1008 format(/1x,' neutral species summary:'/ &
       1x,' #  A         Z         influx        outflux       Source        <E>out'/ &
       1x,'                        #/cm2/sec     #/cm2/sec     #/cm2/sec     KeV'/)
1009 format(1x,i2,2(1x,1pd9.2),4(1x,1pd13.6))

  call frantic_nneut_echo(ineut)
  zflxb=0.0_fp
  zflxc=0.0_fp
  zflxd=0.0_fp
  do ik=1,ineut
    call frantic_za_echo(ik,zA,zZ,zFlux)
    zFlux=1.0e-4_fp*zFlux
    zflxb=zflxb+zZ*zFlux
    zflxd=zflxb+zFlux
    call frantic_get_outflux(ik,zFluxOut,zEngy)
    zFluxout=1.0e-4_fp*zFluxout
    zflxc=zflxc+zZ*zFluxout
    call frantic_get_totalSce(ik,Zsce)
    zSce=1.0d-4*zSce
    write(ilun,1009) ik,zA,zZ,zFlux,zFluxOut,zSce,zEngy
  end do

  if(.not.ivs_flag) then
    zZ=zflxb/zflxd
    zflxd = zz*zflxa*(1.0e0_fp-zflxc/zflxb)
    write(ilun,'(1x,a,1pe12.5)') ' estimated net electron influx: ',zflxd
  end if

  ! balance information (sums over neutral species)

  call frantic_get_dvol(dvols); dvols = dvols*1.0e6_fp  ! -> cm^3

  !---------------
  ! e-ptcl bal

  call frantic_get_vsor_Z(zs); zs = zs*1.0e-6_fp

  call frantic_get_sflx01(zflx1); zflx1 = zflx1*1.0e-6_fp
  call frantic_get_sflx02(zflx2); zflx2 = zflx2*1.0e-6_fp
  zflx = zflx2 - zflx1

  call frantic_get_se(zioniz); zioniz = zioniz*1.0e-6_fp
  call frantic_get_seb(zcx); zcx = zcx*1.0e-6_fp

  zssum = 0; zflxsum = 0; zinzsum = 0; zcxsum = 0; zchksum = 0

  write(ilun,1101)
1101 format(/6x,'Integrated Ptcl bal (Z-weighted sum over neutral species):'/ &
       6x,'chk = vol_sourceZ0 - flux - e_source - e_bcx  (electrons/sec)'/ &
       1x,'    vol_sourceZ0 = Z0*[neutral source]'/ &
       1x,'    flux = [Z0 weighted sum of all neutral species fluxes]'/ &
       1x,'    e_source = [electron source due to neutrals ionizations]'/ &
       1x,'    e_bcx = [electrons -> beam fast neutrals by charge exch.]'/& 
       1x,'  # vol_sourceZ0  flux          e_source      e_bcx         chk')

  do i=1,inx
    zssum = zssum + zs(i)*dvols(i)
    zflxsum = zflxsum + zflx(i)*dvols(i)
    zinzsum = zinzsum + zioniz(i)*dvols(i)
    zcxsum = zcxsum + zcx(i)*dvols(i)
    zchksum = zssum - zflxsum - zinzsum - zcxsum

    write(ilun,1002) i,zssum,zflxsum,zinzsum,zcxsum,zchksum
  end do

  !----------------
  ! power balance

  call frantic_get_vsor_en(zs); zs = zs*1.0e-6_fp

  call frantic_get_pflx01(zflx1); zflx1 = zflx1*1.0e-6_fp
  call frantic_get_pflx02(zflx2); zflx2 = zflx2*1.0e-6_fp
  zflx = zflx2 - zflx1

  call frantic_get_pii(zioniz); zioniz = zioniz*1.0e-6_fp
  call frantic_get_piisf(ztmp); ztmp = ztmp*1.0e-6_fp
  zioniz = zioniz + ztmp

  call frantic_get_pcx(zcx); zcx = zcx*1.0e-6_fp
  call frantic_get_pcxsf(ztmp); ztmp = ztmp*1.0e-6_fp
  zcx = zcx - ztmp

  zssum = 0; zflxsum = 0; zinzsum = 0; zcxsum = 0; zchksum = 0

  write(ilun,1102)
1102 format(/6x,'Integrated Power Balance, all neutral species, plasma frame (Watts):'/ &
       6x,'chk = vol_source + Pcx - flux - Pii'/ &
       1x,'  # vol_source    Pcx           flux          Pii           chk')

  do i=1,inx
    zssum = zssum + zs(i)*dvols(i)
    zcxsum = zcxsum + zcx(i)*dvols(i)
    zflxsum = zflxsum + zflx(i)*dvols(i)
    zinzsum = zinzsum + zioniz(i)*dvols(i)
    zchksum = zssum +zcxsum - zflxsum - zinzsum

    write(ilun,1002) i,zssum,zcxsum,zflxsum,zinzsum,zchksum
  end do

  !----------------
  ! momentum balance

  call frantic_get_vsor_mo(zs); zs = zs*1.0e-6_fp

  call frantic_get_tqflx01(zflx1); zflx1 = zflx1*1.0e-6_fp
  call frantic_get_tqflx02(zflx2); zflx2 = zflx2*1.0e-6_fp
  zflx = zflx2 - zflx1

  call frantic_get_tqii(zioniz); zioniz = zioniz*1.0e-6_fp

  call frantic_get_tqcx(zcx); zcx = zcx*1.0e-6_fp

  zssum = 0; zflxsum = 0; zinzsum = 0; zcxsum = 0; zchksum = 0

  write(ilun,1103)
1103 format(/6x,'Integrated Angular Momentum Balance (Nt*m):'/ &
       6x,'chk = vol_source + Tqcx - flux - Tqii'/ &
       1x,'  # vol_source    Tqcx          flux          Tqii          chk')

  do i=1,inx
    zssum = zssum + zs(i)*dvols(i)
    zcxsum = zcxsum + zcx(i)*dvols(i)
    zflxsum = zflxsum + zflx(i)*dvols(i)
    zinzsum = zinzsum + zioniz(i)*dvols(i)
    zchksum = zssum +zcxsum - zflxsum - zinzsum

    write(ilun,1002) i,zssum,zcxsum,zflxsum,zinzsum,zchksum
  end do

  write(ilun,*) ' '

  deallocate(zn0,zT0,zvphi0,zpcx,zpii)
  deallocate(zs,zflx,zioniz,zcx,zchk,dvols)
  deallocate(zflx1,zflx2,ztmp)

  return
end subroutine frantic_prinsum
