! written by nbigen.py
! *** do not edit *** (use nbigen.py instead)
 
subroutine nbi_state_write(icdf)
  integer, intent(in) :: icdf
 
  call nbi_state_userdef(icdf)
  call nbi_state_define0(icdf)
  call nbi_state_define1(icdf)
  call nbi_state_define2(icdf)
  call nbi_state_define3(icdf)
 
  call nbi_state_userout(icdf)
  call nbi_state_output0(icdf)
  call nbi_state_output1(icdf)
  call nbi_state_output2(icdf)
  call nbi_state_output3(icdf)
 
end subroutine nbi_state_write
 
subroutine nbi_state_read(icdf)
  integer, intent(in) :: icdf
 
  call nbi_state_useread(icdf)
  call nbi_state_read0(icdf)
  call nbi_state_read1(icdf)
  call nbi_state_read2(icdf)
  call nbi_state_read3(icdf)
 
end subroutine nbi_state_read
subroutine nbi_state_write_ptcl(icdf)
  integer, intent(in) :: icdf
 
  call nbi_state_define2_ptcl(icdf)
 
  call nbi_state_output2_ptcl(icdf)
 
end subroutine nbi_state_write_ptcl
 
subroutine nbi_state_read_ptcl(icdf)
  integer, intent(in) :: icdf
 
  call nbi_state_read2_ptcl(icdf)
 
end subroutine nbi_state_read_ptcl
subroutine nbi_state_define0(icdf)
 
  use nbi_com
  use ezcdf
 
  implicit NONE
 
  integer, intent(in) :: icdf  ! NetCDF file id
 
  integer :: idm(3),i1,i2,i3,i4
  character*4 zvartype
  integer, dimension(:), allocatable :: intarr
 
  idm = (/ 0, 0, 0/)
 
  call cdfDefVar(icdf, 'mib', idm, 'INT')
  call cdfDefVar(icdf, 'mj', idm, 'INT')
  call cdfDefVar(icdf, 'mig', idm, 'INT')
  call cdfDefVar(icdf, 'mis', idm, 'INT')
  call cdfDefVar(icdf, 'mibs', idm, 'INT')
  call cdfDefVar(icdf, 'mimpt', idm, 'INT')
  call cdfDefVar(icdf, 'mmini', idm, 'INT')
  call cdfDefVar(icdf, 'mtheta', idm, 'INT')
  call cdfDefVar(icdf, 'miefi', idm, 'INT')
  call cdfDefVar(icdf, 'med2d', idm, 'INT')
  call cdfDefVar(icdf, 'mimxba', idm, 'INT')
  call cdfDefVar(icdf, 'mimxbe', idm, 'INT')
  call cdfDefVar(icdf, 'mgyro', idm, 'INT')
  call cdfDefVar(icdf, 'mimxba0', idm, 'INT')
  call cdfDefVar(icdf, 'mimxbe0', idm, 'INT')
  call cdfDefVar(icdf, 'miboxm', idm, 'INT')
  call cdfDefVar(icdf, 'mitubem', idm, 'INT')
  call cdfDefVar(icdf, 'mituben', idm, 'INT')
  call cdfDefVar(icdf, 'mnkaep', idm, 'INT')
  call cdfDefVar(icdf, 'mjeqv', idm, 'INT')
  call cdfDefVar(icdf, 'mjzb', idm, 'INT')
  call cdfDefVar(icdf, 'mjzc', idm, 'INT')
  call cdfDefVar(icdf, 'mtbl', idm, 'INT')
  call cdfDefVar(icdf, 'mjr', idm, 'INT')
  call cdfDefVar(icdf, 'mmaxion', idm, 'INT')
  call cdfDefVar(icdf, 'miz', idm, 'INT')
  call cdfDefVar(icdf, 'minbs', idm, 'INT')
  call cdfDefVar(icdf, 'mimaxz', idm, 'INT')
  call cdfDefVar(icdf, 'mireact', idm, 'INT')
  call cdfDefVar(icdf, 'miplot', idm, 'INT')
  call cdfDefVar(icdf, 'mimxbe1', idm, 'INT')
  call cdfDefVar(icdf, 'nthspl', idm, 'INT')
  call cdfDefVar(icdf, 'nthpmin', idm, 'INT')
  call cdfDefVar(icdf, 'nthpmax', idm, 'INT')
  call cdfDefVar(icdf, 'minspl', idm, 'INT')
  call cdfDefVar(icdf, 'minbplt', idm, 'INT')
  call cdfDefVar(icdf, 'mtrk', idm, 'INT')
  call cdfDefVar(icdf, 'mimxbz', idm, 'INT')
  call cdfDefVar(icdf, 'mimxbzf', idm, 'INT')
  call cdfDefVar(icdf, 'mdep0', idm, 'INT')
  call cdfDefVar(icdf, 'mibs_use', idm, 'INT')
  call cdfDefVar(icdf, 'mtrk0', idm, 'INT')
 
end subroutine nbi_state_define0
 
subroutine nbi_state_output0(icdf)
 
  use nbi_com
  use ezcdf
 
  implicit NONE
 
  integer, intent(in) :: icdf  ! NetCDF file id
 
  integer :: idm(3),i1,i2,i3,i4
  character*4 zvartype
  integer, dimension(:), allocatable :: intarr
 
  call cdfPutVar(icdf, 'mib', mib)
  call cdfPutVar(icdf, 'mj', mj)
  call cdfPutVar(icdf, 'mig', mig)
  call cdfPutVar(icdf, 'mis', mis)
  call cdfPutVar(icdf, 'mibs', mibs)
  call cdfPutVar(icdf, 'mimpt', mimpt)
  call cdfPutVar(icdf, 'mmini', mmini)
  call cdfPutVar(icdf, 'mtheta', mtheta)
  call cdfPutVar(icdf, 'miefi', miefi)
  call cdfPutVar(icdf, 'med2d', med2d)
  call cdfPutVar(icdf, 'mimxba', mimxba)
  call cdfPutVar(icdf, 'mimxbe', mimxbe)
  call cdfPutVar(icdf, 'mgyro', mgyro)
  call cdfPutVar(icdf, 'mimxba0', mimxba0)
  call cdfPutVar(icdf, 'mimxbe0', mimxbe0)
  call cdfPutVar(icdf, 'miboxm', miboxm)
  call cdfPutVar(icdf, 'mitubem', mitubem)
  call cdfPutVar(icdf, 'mituben', mituben)
  call cdfPutVar(icdf, 'mnkaep', mnkaep)
  call cdfPutVar(icdf, 'mjeqv', mjeqv)
  call cdfPutVar(icdf, 'mjzb', mjzb)
  call cdfPutVar(icdf, 'mjzc', mjzc)
  call cdfPutVar(icdf, 'mtbl', mtbl)
  call cdfPutVar(icdf, 'mjr', mjr)
  call cdfPutVar(icdf, 'mmaxion', mmaxion)
  call cdfPutVar(icdf, 'miz', miz)
  call cdfPutVar(icdf, 'minbs', minbs)
  call cdfPutVar(icdf, 'mimaxz', mimaxz)
  call cdfPutVar(icdf, 'mireact', mireact)
  call cdfPutVar(icdf, 'miplot', miplot)
  call cdfPutVar(icdf, 'mimxbe1', mimxbe1)
  call cdfPutVar(icdf, 'nthspl', nthspl)
  call cdfPutVar(icdf, 'nthpmin', nthpmin)
  call cdfPutVar(icdf, 'nthpmax', nthpmax)
  call cdfPutVar(icdf, 'minspl', minspl)
  call cdfPutVar(icdf, 'minbplt', minbplt)
  call cdfPutVar(icdf, 'mtrk', mtrk)
  call cdfPutVar(icdf, 'mimxbz', mimxbz)
  call cdfPutVar(icdf, 'mimxbzf', mimxbzf)
  call cdfPutVar(icdf, 'mdep0', mdep0)
  call cdfPutVar(icdf, 'mibs_use', mibs_use)
  call cdfPutVar(icdf, 'mtrk0', mtrk0)
 
end subroutine nbi_state_output0
 
subroutine nbi_state_read0(icdf)
 
  use nbi_com
  use ezcdf
 
  implicit NONE
 
  integer, intent(in) :: icdf  ! NetCDF file id
 
  integer :: idm(3),i1,i2,i3,i4
  character*4 zvartype
  integer, dimension(:), allocatable :: intarr
 
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mib', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mib', mib)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MIB; default value set.'
     mib = 32
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mj', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mj', mj)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MJ; default value set.'
     mj = 55
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mig', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mig', mig)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MIG; default value set.'
     mig = 7
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mis', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mis', mis)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MIS; default value set.'
     mis = 21
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mibs', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mibs', mibs)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MIBS; default value set.'
     mibs = 7
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mimpt', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mimpt', mimpt)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MIMPT; default value set.'
     mimpt = 300
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mmini', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mmini', mmini)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MMINI; default value set.'
     mmini = 3
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mtheta', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mtheta', mtheta)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MTHETA; default value set.'
     mtheta = 64
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'miefi', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'miefi', miefi)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MIEFI; default value set.'
     miefi = 5
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'med2d', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'med2d', med2d)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MED2D; default value set.'
     med2d = 10
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mimxba', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mimxba', mimxba)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MIMXBA; default value set.'
     mimxba = 50
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mimxbe', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mimxbe', mimxbe)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MIMXBE; default value set.'
     mimxbe = 100
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mgyro', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mgyro', mgyro)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MGYRO; default value set.'
     mgyro = 4
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mimxba0', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mimxba0', mimxba0)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MIMXBA0; default value set.'
     mimxba0 = 20
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mimxbe0', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mimxbe0', mimxbe0)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MIMXBE0; default value set.'
     mimxbe0 = 100
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'miboxm', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'miboxm', miboxm)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MIBOXM; default value set.'
     miboxm = 12
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mitubem', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mitubem', mitubem)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MITUBEM; default value set.'
     mitubem = 3
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mituben', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mituben', mituben)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MITUBEN; default value set.'
     mituben = 100
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mnkaep', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mnkaep', mnkaep)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MNKAEP; default value set.'
     mnkaep = 10
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mjeqv', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mjeqv', mjeqv)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MJEQV; cleared to ZERO.'
     mjeqv = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mjzb', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mjzb', mjzb)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MJZB; cleared to ZERO.'
     mjzb = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mjzc', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mjzc', mjzc)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MJZC; cleared to ZERO.'
     mjzc = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mtbl', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mtbl', mtbl)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MTBL; cleared to ZERO.'
     mtbl = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mjr', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mjr', mjr)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MJR; cleared to ZERO.'
     mjr = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mmaxion', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mmaxion', mmaxion)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MMAXION; cleared to ZERO.'
     mmaxion = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'miz', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'miz', miz)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MIZ; cleared to ZERO.'
     miz = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'minbs', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'minbs', minbs)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MINBS; cleared to ZERO.'
     minbs = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mimaxz', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mimaxz', mimaxz)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MIMAXZ; cleared to ZERO.'
     mimaxz = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mireact', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mireact', mireact)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MIREACT; cleared to ZERO.'
     mireact = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'miplot', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'miplot', miplot)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MIPLOT; cleared to ZERO.'
     miplot = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mimxbe1', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mimxbe1', mimxbe1)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MIMXBE1; cleared to ZERO.'
     mimxbe1 = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'nthspl', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'nthspl', nthspl)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: NTHSPL; cleared to ZERO.'
     nthspl = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'nthpmin', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'nthpmin', nthpmin)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: NTHPMIN; cleared to ZERO.'
     nthpmin = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'nthpmax', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'nthpmax', nthpmax)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: NTHPMAX; cleared to ZERO.'
     nthpmax = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'minspl', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'minspl', minspl)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MINSPL; cleared to ZERO.'
     minspl = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'minbplt', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'minbplt', minbplt)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MINBPLT; cleared to ZERO.'
     minbplt = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mtrk', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mtrk', mtrk)
  else
     write(nonlin,*) ' ** DIMENSION (init) not in state file: MTRK; cleared to ZERO.'
     mtrk = 0
  endif
 
  call nbi_alloc_init
 
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mimxbz', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mimxbz', mimxbz)
  else
     write(nonlin,*) ' ** DIMENSION (fin) not in state file: MIMXBZ; cleared to ZERO'
     mimxbz = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mimxbzf', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mimxbzf', mimxbzf)
  else
     write(nonlin,*) ' ** DIMENSION (fin) not in state file: MIMXBZF; cleared to ZERO'
     mimxbzf = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mdep0', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mdep0', mdep0)
  else
     write(nonlin,*) ' ** DIMENSION (fin) not in state file: MDEP0; cleared to ZERO'
     mdep0 = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mibs_use', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mibs_use', mibs_use)
  else
     write(nonlin,*) ' ** DIMENSION (fin) not in state file: MIBS_USE; cleared to ZERO'
     mibs_use = 0
  endif
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'mtrk0', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'mtrk0', mtrk0)
  else
     write(nonlin,*) ' ** DIMENSION (fin) not in state file: MTRK0; cleared to ZERO'
     mtrk0 = 0
  endif
 
 
end subroutine nbi_state_read0
 
subroutine nbi_state_define1(icdf)
 
  use nbi_com
  use ezcdf
 
  implicit NONE
 
  integer, intent(in) :: icdf  ! NetCDF file id
 
  integer :: idm(3),i1,i2,i3,i4
  character*4 zvartype
  integer, dimension(:), allocatable :: intarr
 
  ! --------------> block: sys
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_sys', idm, 'INT')
  idm = (/ len(runid), 0, 0 /)
  call cdfDefVar(icdf, 'runid', idm, 'CHAR')
  idm = (/ len(mission), 0, 0 /)
  call cdfDefVar(icdf, 'mission', idm, 'CHAR')
  idm = (/ len(workpath), 0, 0 /)
  call cdfDefVar(icdf, 'workpath', idm, 'CHAR')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nonlin', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nseed', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlbout', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'lunnbx', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'lunres', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'mrstrt', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nclass', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'only_io', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'ref_namelist', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'quasi_check', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nltest_output', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'BLK_MPI_BCAST_INT', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'BLK_MPI_BCAST_R8', idm, 'INT')
  ! --------------> block: times
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_times', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'tbm1', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'tbm2', idm, 'R8')
  ! --------------> block: grid
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_grid', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nzones', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nzone_fb', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlsym2b', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nth0', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xbmbnd', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nthets', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'ebdmax', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xplasma_in_memory', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nznbma', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nznbme', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nznbma0', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nznbme0', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'ngyro', idm, 'INT')
  ! --------------> block: beams
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_beams', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'ngmax', idm, 'INT')
  idm = (/ mig, 0, 0 /)
  call cdfDefVar(icdf, 'backz', idm, 'R8')
  idm = (/ mig, 0, 0 /)
  call cdfDefVar(icdf, 'aplasm', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nbeam', idm, 'INT')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'xzbeama', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'abeama', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'nlco', idm, 'INT')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'ntrace', idm, 'INT')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'rtcena', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'xlbtna', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'xybsca', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'xbzeta', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'nbshapa', idm, 'INT')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'bmwidra', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'bmwidza', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'divra', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'divza', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'foclra', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'foclza', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'nbapsha', idm, 'INT')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'rapedga', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'xzpedga', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'xlbapa', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'xybapa', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'xrapoffa', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'xzapoffa', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'nbapsh2', idm, 'INT')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'rapedg2', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'xzpedg2', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'xlbapa2', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'xrapoff2', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'xzapoff2', idm, 'R8')
  ! --------------> block: impurity
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_impurity', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nrhix', idm, 'INT')
  idm = (/ mimpt, 0, 0 /)
  call cdfDefVar(icdf, 'xzimpx', idm, 'R8')
  idm = (/ mimpt, 0, 0 /)
  call cdfDefVar(icdf, 'aimpx', idm, 'R8')
  ! --------------> block: minority
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_minority', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nmini', idm, 'INT')
  idm = (/ mmini, 0, 0 /)
  call cdfDefVar(icdf, 'xzmini', idm, 'R8')
  idm = (/ mmini, 0, 0 /)
  call cdfDefVar(icdf, 'amini', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nthrf', idm, 'INT')
  ! --------------> block: powers
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_powers', idm, 'INT')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'einjmin', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'einja', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'pinja', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'ffulla', idm, 'R8')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'fhalfa', idm, 'R8')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'orbrzv_toric_Prftot0', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'orbrzv_toric_frnm', idm, 'R8')
  ! --------------> block: fusion
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_fusion', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlfhe3', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlfhe4', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlfst', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlfsp', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlfsp14', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlusf3', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xdatsf3', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlusfa', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xdatsfa', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlusft', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xdatsft', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlusfp', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xdatsfp', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlusfp14', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xdatsp3', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'plfhe3', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'plfhe4', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'plfst', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'plfsp', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'plfsp14', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlfatom', idm, 'INT')
  ! --------------> block: fpp
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_fpp', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlbfpp', idm, 'INT')
  ! --------------> block: num
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_num', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'cxsplt', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'dxbsmoo', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'dxbsm_nc', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nptcls', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nptclf', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nptclh', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'NFAST_MAP', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xpand_nptcl', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'frac_depmax', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'frac_dep_lim', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'frac_depmin', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'frac_orbrr', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nptcl_max', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nltrk_dep0', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'NLDEP0_GATHER', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'ndep0', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'NDEP0_MAX', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'ndep_set_beam', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'ndep_set_ien', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nbbcal', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'ncx0', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nper_cx', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'LEV_NBIDEP', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'LEV_TTNUK', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'LEVMOD_HALO', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'NSPLT', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'NSPLT_GEO', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'NSPLT_KIN', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'NSPLT_GEN', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nmimp', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'AIMP', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'XZIMP', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'NTEST_MAX', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'BI_MAX_PL', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'BI_MAX_PR', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'wghta', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'goocon', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'NGOOCON_VPVBIN', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'NGOOCON_EBIN', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'NGOOCON_RBIN', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'cxpcon', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'fppcon', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'fdtnxy', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nchdvp', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'dtn', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'dt_acc', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'orbrzv_option', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'orbrzv_rf_option', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlmcrf_on', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'orbrzv_nr', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'orbrzv_nz', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'orbrzv_zzerr_con', idm, 'R8')
  ! --------------> block: atomic
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_atomic', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nsmax', idm, 'INT')
  idm = (/ mis, 0, 0 /)
  call cdfDefVar(icdf, 'khalo', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'dn0out', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nmsigx', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlminsv', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlebei', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nsigexc', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xdepmod', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlbbcx', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nbbcx_avg', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nbbcx_bb', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nbfallgr', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlbeamcx', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlhvion', idm, 'INT')
  ! --------------> block: collid
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_collid', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xcfanbi', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xdfanbi', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xefanbi', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xcfafus', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xdfafus', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xefafus', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlbcde', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlbcoh', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlbcpa', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlorbo', idm, 'INT')
  ! --------------> block: flr
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_flr', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlbflr', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlfbmflr', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlbgflr', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'gflr_min', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'gflr_rl', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'gflr_ll', idm, 'R8')
  idm = (/ 2, 0, 0 /)
  call cdfDefVar(icdf, 'gflr_xv', idm, 'R8')
  idm = (/ 15, 0, 0 /)
  call cdfDefVar(icdf, 'gflr_op', idm, 'R8')
  ! --------------> block: saw
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_saw', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'sawflag', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlsawb', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlsawf', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xswfrac_allfast', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xswfrac_beam', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xswfrac_fusn', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nmix_kdsaw', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'fporcelli', idm, 'R8')
  ! --------------> block: adif
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_adif', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nkaep', idm, 'INT')
  idm = (/ mnkaep, 0, 0 /)
  call cdfDefVar(icdf, 'AEP_ASCALE', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'AEP_USCALE', idm, 'R8')
  idm = (/ mnkaep, 0, 0 /)
  call cdfDefVar(icdf, 'TAEP_FAC', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nmdifb', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nkdifb', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'ndifbe', idm, 'INT')
  idm = (/ 20, 0, 0 /)
  call cdfDefVar(icdf, 'fdifbe', idm, 'R8')
  idm = (/ 20, 0, 0 /)
  call cdfDefVar(icdf, 'edifbe', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'x_qlim0', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'ndifbe_2d', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'dif2d_conv', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'dif2d_dpa', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'ngradd_opt', idm, 'INT')
  ! --------------> block: ripple
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_ripple', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nrip', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'taurip', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'ncoils', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'ncoils_2', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'asrd', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'bsrd', idm, 'R8')
  ! --------------> block: outcon
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_outcon', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nerngfi', idm, 'INT')
  idm = (/ miefi, mibs, 0 /)
  call cdfDefVar(icdf, 'erngfi', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nsdbgb', idm, 'INT')
  ! --------------> block: fishbone
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_fishbone', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlfbon', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'fbemin', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'fbemax', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'fvpvmn', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'fvpvmx', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'fbltim', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'fshper', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'fshwid', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'tfshon', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'tfshof', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xfishmin', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xfishmax', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nfbon_vpvopt', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'fbtrap_depth', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nfbon_species', idm, 'INT')
  ! --------------> block: box
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_box', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nbbox', idm, 'INT')
  idm = (/ miboxm, 0, 0 /)
  call cdfDefVar(icdf, 'nbsbox', idm, 'INT')
  idm = (/ miboxm, 0, 0 /)
  call cdfDefVar(icdf, 'nsample_box', idm, 'INT')
  idm = (/ miboxm, 0, 0 /)
  call cdfDefVar(icdf, 'xninja_box', idm, 'R8')
  idm = (/ miboxm, 0, 0 /)
  call cdfDefVar(icdf, 'xninjs_box', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xninj_box', idm, 'R8')
  idm = (/ miboxm, 0, 0 /)
  call cdfDefVar(icdf, 'nbebox', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nxbox', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nybox', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlbox', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xboxhw', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'yboxhw', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xlbox1', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xlbox2', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'ndepbox', idm, 'INT')
  ! --------------> block: tube
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_tube', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nbtube', idm, 'INT')
  idm = (/ mitubem, 0, 0 /)
  call cdfDefVar(icdf, 'nbstube', idm, 'INT')
  idm = (/ mitubem, 0, 0 /)
  call cdfDefVar(icdf, 'nbetube', idm, 'INT')
  idm = (/ mitubem, 0, 0 /)
  call cdfDefVar(icdf, 'Rtube', idm, 'R8')
  idm = (/ mitubem, 0, 0 /)
  call cdfDefVar(icdf, 'Ytube', idm, 'R8')
  idm = (/ mitubem, 0, 0 /)
  call cdfDefVar(icdf, 'XZETAtube', idm, 'R8')
  idm = (/ mitubem, 0, 0 /)
  call cdfDefVar(icdf, 'PHItube', idm, 'R8')
  idm = (/ mitubem, 0, 0 /)
  call cdfDefVar(icdf, 'THETAtube', idm, 'R8')
  idm = (/ mitubem, 0, 0 /)
  call cdfDefVar(icdf, 'LMIDtube', idm, 'INT')
  idm = (/ mitubem, 0, 0 /)
  call cdfDefVar(icdf, 'XL1tube', idm, 'R8')
  idm = (/ mitubem, 0, 0 /)
  call cdfDefVar(icdf, 'XL2tube', idm, 'R8')
  idm = (/ mitubem, 0, 0 /)
  call cdfDefVar(icdf, 'NSEGtube', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'RHOtube', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'NDEPtube', idm, 'INT')
  ! --------------> block: misc
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_misc', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'plhgt', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlcprb', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlpsirz', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'edbfac', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nmcurb', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nlfdep', idm, 'INT')
  ! --------------> block: profiles
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_profiles', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'ng', idm, 'INT')
 
end subroutine nbi_state_define1
 
subroutine nbi_state_output1(icdf)
 
  use nbi_com
  use ezcdf
 
  implicit NONE
 
  integer, intent(in) :: icdf  ! NetCDF file id
 
  integer :: idm(3),i1,i2,i3,i4
  character*4 zvartype
  integer, dimension(:), allocatable :: intarr
 
  ! --------------> block: sys
  call cdfPutVar(icdf, 'init_sys', log2int(init_sys))
  call cdfPutVar(icdf, 'runid', runid)
  call cdfPutVar(icdf, 'mission', mission)
  call cdfPutVar(icdf, 'workpath', workpath)
  call cdfPutVar(icdf, 'nonlin', nonlin)
  call cdfPutVar(icdf, 'nseed', nseed)
  call cdfPutVar(icdf, 'nlbout', log2int(nlbout))
  call cdfPutVar(icdf, 'lunnbx', lunnbx)
  call cdfPutVar(icdf, 'lunres', lunres)
  call cdfPutVar(icdf, 'mrstrt', mrstrt)
  call cdfPutVar(icdf, 'nclass', nclass)
  call cdfPutVar(icdf, 'only_io', log2int(only_io))
  call cdfPutVar(icdf, 'ref_namelist', log2int(ref_namelist))
  call cdfPutVar(icdf, 'quasi_check', log2int(quasi_check))
  call cdfPutVar(icdf, 'nltest_output', log2int(nltest_output))
  call cdfPutVar(icdf, 'BLK_MPI_BCAST_INT', BLK_MPI_BCAST_INT)
  call cdfPutVar(icdf, 'BLK_MPI_BCAST_R8', BLK_MPI_BCAST_R8)
  ! --------------> block: times
  call cdfPutVar(icdf, 'init_times', log2int(init_times))
  call cdfPutVar(icdf, 'tbm1', tbm1)
  call cdfPutVar(icdf, 'tbm2', tbm2)
  ! --------------> block: grid
  call cdfPutVar(icdf, 'init_grid', log2int(init_grid))
  call cdfPutVar(icdf, 'nzones', nzones)
  call cdfPutVar(icdf, 'nzone_fb', nzone_fb)
  call cdfPutVar(icdf, 'nlsym2b', log2int(nlsym2b))
  call cdfPutVar(icdf, 'nth0', nth0)
  call cdfPutVar(icdf, 'xbmbnd', xbmbnd)
  call cdfPutVar(icdf, 'nthets', nthets)
  call cdfPutVar(icdf, 'ebdmax', ebdmax)
  call cdfPutVar(icdf, 'xplasma_in_memory', xplasma_in_memory)
  call cdfPutVar(icdf, 'nznbma', nznbma)
  call cdfPutVar(icdf, 'nznbme', nznbme)
  call cdfPutVar(icdf, 'nznbma0', nznbma0)
  call cdfPutVar(icdf, 'nznbme0', nznbme0)
  call cdfPutVar(icdf, 'ngyro', ngyro)
  ! --------------> block: beams
  call cdfPutVar(icdf, 'init_beams', log2int(init_beams))
  call cdfPutVar(icdf, 'ngmax', ngmax)
  call cdfPutVar(icdf, 'backz', backz)
  call cdfPutVar(icdf, 'aplasm', aplasm)
  call cdfPutVar(icdf, 'nbeam', nbeam)
  call cdfPutVar(icdf, 'xzbeama', xzbeama)
  call cdfPutVar(icdf, 'abeama', abeama)
  allocate(intarr(mib))
  call nbi_log2int(nlco, intarr, mib)
  call cdfPutVar(icdf, 'nlco', intarr)
  deallocate(intarr)
  call cdfPutVar(icdf, 'ntrace', ntrace)
  call cdfPutVar(icdf, 'rtcena', rtcena)
  call cdfPutVar(icdf, 'xlbtna', xlbtna)
  call cdfPutVar(icdf, 'xybsca', xybsca)
  call cdfPutVar(icdf, 'xbzeta', xbzeta)
  call cdfPutVar(icdf, 'nbshapa', nbshapa)
  call cdfPutVar(icdf, 'bmwidra', bmwidra)
  call cdfPutVar(icdf, 'bmwidza', bmwidza)
  call cdfPutVar(icdf, 'divra', divra)
  call cdfPutVar(icdf, 'divza', divza)
  call cdfPutVar(icdf, 'foclra', foclra)
  call cdfPutVar(icdf, 'foclza', foclza)
  call cdfPutVar(icdf, 'nbapsha', nbapsha)
  call cdfPutVar(icdf, 'rapedga', rapedga)
  call cdfPutVar(icdf, 'xzpedga', xzpedga)
  call cdfPutVar(icdf, 'xlbapa', xlbapa)
  call cdfPutVar(icdf, 'xybapa', xybapa)
  call cdfPutVar(icdf, 'xrapoffa', xrapoffa)
  call cdfPutVar(icdf, 'xzapoffa', xzapoffa)
  call cdfPutVar(icdf, 'nbapsh2', nbapsh2)
  call cdfPutVar(icdf, 'rapedg2', rapedg2)
  call cdfPutVar(icdf, 'xzpedg2', xzpedg2)
  call cdfPutVar(icdf, 'xlbapa2', xlbapa2)
  call cdfPutVar(icdf, 'xrapoff2', xrapoff2)
  call cdfPutVar(icdf, 'xzapoff2', xzapoff2)
  ! --------------> block: impurity
  call cdfPutVar(icdf, 'init_impurity', log2int(init_impurity))
  call cdfPutVar(icdf, 'nrhix', nrhix)
  call cdfPutVar(icdf, 'xzimpx', xzimpx)
  call cdfPutVar(icdf, 'aimpx', aimpx)
  ! --------------> block: minority
  call cdfPutVar(icdf, 'init_minority', log2int(init_minority))
  call cdfPutVar(icdf, 'nmini', nmini)
  call cdfPutVar(icdf, 'xzmini', xzmini)
  call cdfPutVar(icdf, 'amini', amini)
  call cdfPutVar(icdf, 'nthrf', nthrf)
  ! --------------> block: powers
  call cdfPutVar(icdf, 'init_powers', log2int(init_powers))
  call cdfPutVar(icdf, 'einjmin', einjmin)
  call cdfPutVar(icdf, 'einja', einja)
  call cdfPutVar(icdf, 'pinja', pinja)
  call cdfPutVar(icdf, 'ffulla', ffulla)
  call cdfPutVar(icdf, 'fhalfa', fhalfa)
  call cdfPutVar(icdf, 'orbrzv_toric_Prftot0', orbrzv_toric_Prftot0)
  call cdfPutVar(icdf, 'orbrzv_toric_frnm', orbrzv_toric_frnm)
  ! --------------> block: fusion
  call cdfPutVar(icdf, 'init_fusion', log2int(init_fusion))
  call cdfPutVar(icdf, 'nlfhe3', log2int(nlfhe3))
  call cdfPutVar(icdf, 'nlfhe4', log2int(nlfhe4))
  call cdfPutVar(icdf, 'nlfst', log2int(nlfst))
  call cdfPutVar(icdf, 'nlfsp', log2int(nlfsp))
  call cdfPutVar(icdf, 'nlfsp14', log2int(nlfsp14))
  call cdfPutVar(icdf, 'nlusf3', log2int(nlusf3))
  call cdfPutVar(icdf, 'xdatsf3', xdatsf3)
  call cdfPutVar(icdf, 'nlusfa', log2int(nlusfa))
  call cdfPutVar(icdf, 'xdatsfa', xdatsfa)
  call cdfPutVar(icdf, 'nlusft', log2int(nlusft))
  call cdfPutVar(icdf, 'xdatsft', xdatsft)
  call cdfPutVar(icdf, 'nlusfp', log2int(nlusfp))
  call cdfPutVar(icdf, 'xdatsfp', xdatsfp)
  call cdfPutVar(icdf, 'nlusfp14', log2int(nlusfp14))
  call cdfPutVar(icdf, 'xdatsp3', xdatsp3)
  call cdfPutVar(icdf, 'plfhe3', plfhe3)
  call cdfPutVar(icdf, 'plfhe4', plfhe4)
  call cdfPutVar(icdf, 'plfst', plfst)
  call cdfPutVar(icdf, 'plfsp', plfsp)
  call cdfPutVar(icdf, 'plfsp14', plfsp14)
  call cdfPutVar(icdf, 'nlfatom', log2int(nlfatom))
  ! --------------> block: fpp
  call cdfPutVar(icdf, 'init_fpp', log2int(init_fpp))
  call cdfPutVar(icdf, 'nlbfpp', log2int(nlbfpp))
  ! --------------> block: num
  call cdfPutVar(icdf, 'init_num', log2int(init_num))
  call cdfPutVar(icdf, 'cxsplt', cxsplt)
  call cdfPutVar(icdf, 'dxbsmoo', dxbsmoo)
  call cdfPutVar(icdf, 'dxbsm_nc', dxbsm_nc)
  call cdfPutVar(icdf, 'nptcls', nptcls)
  call cdfPutVar(icdf, 'nptclf', nptclf)
  call cdfPutVar(icdf, 'nptclh', nptclh)
  call cdfPutVar(icdf, 'NFAST_MAP', NFAST_MAP)
  call cdfPutVar(icdf, 'xpand_nptcl', xpand_nptcl)
  call cdfPutVar(icdf, 'frac_depmax', frac_depmax)
  call cdfPutVar(icdf, 'frac_dep_lim', frac_dep_lim)
  call cdfPutVar(icdf, 'frac_depmin', frac_depmin)
  call cdfPutVar(icdf, 'frac_orbrr', frac_orbrr)
  call cdfPutVar(icdf, 'nptcl_max', nptcl_max)
  call cdfPutVar(icdf, 'nltrk_dep0', log2int(nltrk_dep0))
  call cdfPutVar(icdf, 'NLDEP0_GATHER', log2int(NLDEP0_GATHER))
  call cdfPutVar(icdf, 'ndep0', ndep0)
  call cdfPutVar(icdf, 'NDEP0_MAX', NDEP0_MAX)
  call cdfPutVar(icdf, 'ndep_set_beam', ndep_set_beam)
  call cdfPutVar(icdf, 'ndep_set_ien', ndep_set_ien)
  call cdfPutVar(icdf, 'nbbcal', nbbcal)
  call cdfPutVar(icdf, 'ncx0', ncx0)
  call cdfPutVar(icdf, 'nper_cx', nper_cx)
  call cdfPutVar(icdf, 'LEV_NBIDEP', LEV_NBIDEP)
  call cdfPutVar(icdf, 'LEV_TTNUK', LEV_TTNUK)
  call cdfPutVar(icdf, 'LEVMOD_HALO', LEVMOD_HALO)
  call cdfPutVar(icdf, 'NSPLT', NSPLT)
  call cdfPutVar(icdf, 'NSPLT_GEO', NSPLT_GEO)
  call cdfPutVar(icdf, 'NSPLT_KIN', NSPLT_KIN)
  call cdfPutVar(icdf, 'NSPLT_GEN', NSPLT_GEN)
  call cdfPutVar(icdf, 'nmimp', nmimp)
  call cdfPutVar(icdf, 'AIMP', AIMP)
  call cdfPutVar(icdf, 'XZIMP', XZIMP)
  call cdfPutVar(icdf, 'NTEST_MAX', NTEST_MAX)
  call cdfPutVar(icdf, 'BI_MAX_PL', BI_MAX_PL)
  call cdfPutVar(icdf, 'BI_MAX_PR', BI_MAX_PR)
  call cdfPutVar(icdf, 'wghta', wghta)
  call cdfPutVar(icdf, 'goocon', goocon)
  call cdfPutVar(icdf, 'NGOOCON_VPVBIN', NGOOCON_VPVBIN)
  call cdfPutVar(icdf, 'NGOOCON_EBIN', NGOOCON_EBIN)
  call cdfPutVar(icdf, 'NGOOCON_RBIN', NGOOCON_RBIN)
  call cdfPutVar(icdf, 'cxpcon', cxpcon)
  call cdfPutVar(icdf, 'fppcon', fppcon)
  call cdfPutVar(icdf, 'fdtnxy', fdtnxy)
  call cdfPutVar(icdf, 'nchdvp', nchdvp)
  call cdfPutVar(icdf, 'dtn', dtn)
  call cdfPutVar(icdf, 'dt_acc', dt_acc)
  call cdfPutVar(icdf, 'orbrzv_option', orbrzv_option)
  call cdfPutVar(icdf, 'orbrzv_rf_option', orbrzv_rf_option)
  call cdfPutVar(icdf, 'nlmcrf_on', log2int(nlmcrf_on))
  call cdfPutVar(icdf, 'orbrzv_nr', orbrzv_nr)
  call cdfPutVar(icdf, 'orbrzv_nz', orbrzv_nz)
  call cdfPutVar(icdf, 'orbrzv_zzerr_con', orbrzv_zzerr_con)
  ! --------------> block: atomic
  call cdfPutVar(icdf, 'init_atomic', log2int(init_atomic))
  call cdfPutVar(icdf, 'nsmax', nsmax)
  call cdfPutVar(icdf, 'khalo', khalo)
  call cdfPutVar(icdf, 'dn0out', dn0out)
  call cdfPutVar(icdf, 'nmsigx', nmsigx)
  call cdfPutVar(icdf, 'nlminsv', log2int(nlminsv))
  call cdfPutVar(icdf, 'nlebei', log2int(nlebei))
  call cdfPutVar(icdf, 'nsigexc', nsigexc)
  call cdfPutVar(icdf, 'xdepmod', xdepmod)
  call cdfPutVar(icdf, 'nlbbcx', log2int(nlbbcx))
  call cdfPutVar(icdf, 'nbbcx_avg', nbbcx_avg)
  call cdfPutVar(icdf, 'nbbcx_bb', nbbcx_bb)
  call cdfPutVar(icdf, 'nbfallgr', nbfallgr)
  call cdfPutVar(icdf, 'nlbeamcx', log2int(nlbeamcx))
  call cdfPutVar(icdf, 'nlhvion', log2int(nlhvion))
  ! --------------> block: collid
  call cdfPutVar(icdf, 'init_collid', log2int(init_collid))
  call cdfPutVar(icdf, 'xcfanbi', xcfanbi)
  call cdfPutVar(icdf, 'xdfanbi', xdfanbi)
  call cdfPutVar(icdf, 'xefanbi', xefanbi)
  call cdfPutVar(icdf, 'xcfafus', xcfafus)
  call cdfPutVar(icdf, 'xdfafus', xdfafus)
  call cdfPutVar(icdf, 'xefafus', xefafus)
  call cdfPutVar(icdf, 'nlbcde', log2int(nlbcde))
  call cdfPutVar(icdf, 'nlbcoh', log2int(nlbcoh))
  call cdfPutVar(icdf, 'nlbcpa', log2int(nlbcpa))
  call cdfPutVar(icdf, 'nlorbo', log2int(nlorbo))
  ! --------------> block: flr
  call cdfPutVar(icdf, 'init_flr', log2int(init_flr))
  call cdfPutVar(icdf, 'nlbflr', log2int(nlbflr))
  call cdfPutVar(icdf, 'nlfbmflr', log2int(nlfbmflr))
  call cdfPutVar(icdf, 'nlbgflr', log2int(nlbgflr))
  call cdfPutVar(icdf, 'gflr_min', gflr_min)
  call cdfPutVar(icdf, 'gflr_rl', gflr_rl)
  call cdfPutVar(icdf, 'gflr_ll', gflr_ll)
  call cdfPutVar(icdf, 'gflr_xv', gflr_xv)
  call cdfPutVar(icdf, 'gflr_op', gflr_op)
  ! --------------> block: saw
  call cdfPutVar(icdf, 'init_saw', log2int(init_saw))
  call cdfPutVar(icdf, 'sawflag', log2int(sawflag))
  call cdfPutVar(icdf, 'nlsawb', log2int(nlsawb))
  call cdfPutVar(icdf, 'nlsawf', log2int(nlsawf))
  call cdfPutVar(icdf, 'xswfrac_allfast', xswfrac_allfast)
  call cdfPutVar(icdf, 'xswfrac_beam', xswfrac_beam)
  call cdfPutVar(icdf, 'xswfrac_fusn', xswfrac_fusn)
  call cdfPutVar(icdf, 'nmix_kdsaw', nmix_kdsaw)
  call cdfPutVar(icdf, 'fporcelli', fporcelli)
  ! --------------> block: adif
  call cdfPutVar(icdf, 'init_adif', log2int(init_adif))
  call cdfPutVar(icdf, 'nkaep', nkaep)
  call cdfPutVar(icdf, 'AEP_ASCALE', AEP_ASCALE)
  call cdfPutVar(icdf, 'AEP_USCALE', AEP_USCALE)
  call cdfPutVar(icdf, 'TAEP_FAC', TAEP_FAC)
  call cdfPutVar(icdf, 'nmdifb', nmdifb)
  call cdfPutVar(icdf, 'nkdifb', nkdifb)
  call cdfPutVar(icdf, 'ndifbe', ndifbe)
  call cdfPutVar(icdf, 'fdifbe', fdifbe)
  call cdfPutVar(icdf, 'edifbe', edifbe)
  call cdfPutVar(icdf, 'x_qlim0', x_qlim0)
  call cdfPutVar(icdf, 'ndifbe_2d', ndifbe_2d)
  call cdfPutVar(icdf, 'dif2d_conv', dif2d_conv)
  call cdfPutVar(icdf, 'dif2d_dpa', dif2d_dpa)
  call cdfPutVar(icdf, 'ngradd_opt', ngradd_opt)
  ! --------------> block: ripple
  call cdfPutVar(icdf, 'init_ripple', log2int(init_ripple))
  call cdfPutVar(icdf, 'nrip', nrip)
  call cdfPutVar(icdf, 'taurip', taurip)
  call cdfPutVar(icdf, 'ncoils', ncoils)
  call cdfPutVar(icdf, 'ncoils_2', ncoils_2)
  call cdfPutVar(icdf, 'asrd', asrd)
  call cdfPutVar(icdf, 'bsrd', bsrd)
  ! --------------> block: outcon
  call cdfPutVar(icdf, 'init_outcon', log2int(init_outcon))
  call cdfPutVar(icdf, 'nerngfi', nerngfi)
  call cdfPutVar(icdf, 'erngfi', erngfi)
  call cdfPutVar(icdf, 'nsdbgb', nsdbgb)
  ! --------------> block: fishbone
  call cdfPutVar(icdf, 'init_fishbone', log2int(init_fishbone))
  call cdfPutVar(icdf, 'nlfbon', log2int(nlfbon))
  call cdfPutVar(icdf, 'fbemin', fbemin)
  call cdfPutVar(icdf, 'fbemax', fbemax)
  call cdfPutVar(icdf, 'fvpvmn', fvpvmn)
  call cdfPutVar(icdf, 'fvpvmx', fvpvmx)
  call cdfPutVar(icdf, 'fbltim', fbltim)
  call cdfPutVar(icdf, 'fshper', fshper)
  call cdfPutVar(icdf, 'fshwid', fshwid)
  call cdfPutVar(icdf, 'tfshon', tfshon)
  call cdfPutVar(icdf, 'tfshof', tfshof)
  call cdfPutVar(icdf, 'xfishmin', xfishmin)
  call cdfPutVar(icdf, 'xfishmax', xfishmax)
  call cdfPutVar(icdf, 'nfbon_vpvopt', nfbon_vpvopt)
  call cdfPutVar(icdf, 'fbtrap_depth', fbtrap_depth)
  call cdfPutVar(icdf, 'nfbon_species', nfbon_species)
  ! --------------> block: box
  call cdfPutVar(icdf, 'init_box', log2int(init_box))
  call cdfPutVar(icdf, 'nbbox', nbbox)
  call cdfPutVar(icdf, 'nbsbox', nbsbox)
  call cdfPutVar(icdf, 'nsample_box', nsample_box)
  call cdfPutVar(icdf, 'xninja_box', xninja_box)
  call cdfPutVar(icdf, 'xninjs_box', xninjs_box)
  call cdfPutVar(icdf, 'xninj_box', xninj_box)
  call cdfPutVar(icdf, 'nbebox', nbebox)
  call cdfPutVar(icdf, 'nxbox', nxbox)
  call cdfPutVar(icdf, 'nybox', nybox)
  call cdfPutVar(icdf, 'nlbox', nlbox)
  call cdfPutVar(icdf, 'xboxhw', xboxhw)
  call cdfPutVar(icdf, 'yboxhw', yboxhw)
  call cdfPutVar(icdf, 'xlbox1', xlbox1)
  call cdfPutVar(icdf, 'xlbox2', xlbox2)
  call cdfPutVar(icdf, 'ndepbox', ndepbox)
  ! --------------> block: tube
  call cdfPutVar(icdf, 'init_tube', log2int(init_tube))
  call cdfPutVar(icdf, 'nbtube', nbtube)
  call cdfPutVar(icdf, 'nbstube', nbstube)
  call cdfPutVar(icdf, 'nbetube', nbetube)
  call cdfPutVar(icdf, 'Rtube', Rtube)
  call cdfPutVar(icdf, 'Ytube', Ytube)
  call cdfPutVar(icdf, 'XZETAtube', XZETAtube)
  call cdfPutVar(icdf, 'PHItube', PHItube)
  call cdfPutVar(icdf, 'THETAtube', THETAtube)
  call cdfPutVar(icdf, 'LMIDtube', LMIDtube)
  call cdfPutVar(icdf, 'XL1tube', XL1tube)
  call cdfPutVar(icdf, 'XL2tube', XL2tube)
  call cdfPutVar(icdf, 'NSEGtube', NSEGtube)
  call cdfPutVar(icdf, 'RHOtube', RHOtube)
  call cdfPutVar(icdf, 'NDEPtube', NDEPtube)
  ! --------------> block: misc
  call cdfPutVar(icdf, 'init_misc', log2int(init_misc))
  call cdfPutVar(icdf, 'plhgt', plhgt)
  call cdfPutVar(icdf, 'nlcprb', log2int(nlcprb))
  call cdfPutVar(icdf, 'nlpsirz', log2int(nlpsirz))
  call cdfPutVar(icdf, 'edbfac', edbfac)
  call cdfPutVar(icdf, 'nmcurb', nmcurb)
  call cdfPutVar(icdf, 'nlfdep', log2int(nlfdep))
  ! --------------> block: profiles
  call cdfPutVar(icdf, 'init_profiles', log2int(init_profiles))
  call cdfPutVar(icdf, 'ng', ng)
 
  contains
 
    integer function log2int(ilog)
      logical, intent(in) :: ilog
      if(ilog) then
        log2int=1
      else
        log2int=0
      endif
    end function log2int
 
end subroutine nbi_state_output1
 
subroutine nbi_state_read1(icdf)
 
  use nbi_com
  use ezcdf
 
  implicit NONE
 
  integer, intent(in) :: icdf  ! NetCDF file id
 
  integer :: idm(3),i1,i2,i3,i4
  character*4 zvartype
  integer, dimension(:), allocatable :: intarr
 
  ! --------------> block: sys
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_sys', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_sys', i1); init_sys = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_SYS; default value set.'
    init_sys =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'runid', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'runid', runid)
  else
    write(nonlin,*) ' %variable not in state file: RUNID; default value set.'
    runid =  "NUBEAM"
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'mission', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'mission', mission)
  else
    write(nonlin,*) ' %variable not in state file: MISSION; default value set.'
    mission =   "standard"
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'workpath', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'workpath', workpath)
  else
    write(nonlin,*) ' %variable not in state file: WORKPATH; default value set.'
    workpath =   " "
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nonlin', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nonlin', nonlin)
  else
    write(nonlin,*) ' %variable not in state file: NONLIN; default value set.'
    nonlin =  6
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nseed', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nseed', nseed)
  else
    write(nonlin,*) ' %variable not in state file: NSEED; default value set.'
    nseed =  1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlbout', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlbout', i1); nlbout = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLBOUT; default value set.'
    nlbout =  .TRUE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'lunnbx', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'lunnbx', lunnbx)
  else
    write(nonlin,*) ' %variable not in state file: LUNNBX; default value set.'
    lunnbx =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'lunres', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'lunres', lunres)
  else
    write(nonlin,*) ' %variable not in state file: LUNRES; default value set.'
    lunres =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'mrstrt', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'mrstrt', mrstrt)
  else
    write(nonlin,*) ' %variable not in state file: MRSTRT; default value set.'
    mrstrt =  1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nclass', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nclass', nclass)
  else
    write(nonlin,*) ' %variable not in state file: NCLASS; default value set.'
    nclass =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'only_io', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'only_io', i1); only_io = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: ONLY_IO; default value set.'
    only_io =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ref_namelist', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'ref_namelist', i1); ref_namelist = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: REF_NAMELIST; default value set.'
    ref_namelist =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'quasi_check', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'quasi_check', i1); quasi_check = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: QUASI_CHECK; default value set.'
    quasi_check =  .TRUE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nltest_output', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nltest_output', i1); nltest_output = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLTEST_OUTPUT; default value set.'
    nltest_output =  .TRUE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'BLK_MPI_BCAST_INT', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'BLK_MPI_BCAST_INT', BLK_MPI_BCAST_INT)
  else
    write(nonlin,*) ' %variable not in state file: BLK_MPI_BCAST_INT; default value set.'
    BLK_MPI_BCAST_INT =   2000000
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'BLK_MPI_BCAST_R8', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'BLK_MPI_BCAST_R8', BLK_MPI_BCAST_R8)
  else
    write(nonlin,*) ' %variable not in state file: BLK_MPI_BCAST_R8; default value set.'
    BLK_MPI_BCAST_R8 =    30000000
  endif
  ! --------------> block: times
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_times', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_times', i1); init_times = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_TIMES; default value set.'
    init_times =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'tbm1', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'tbm1', tbm1, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: TBM1; default value set.'
    tbm1 =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'tbm2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'tbm2', tbm2, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: TBM2; default value set.'
    tbm2 =  0.0_fp
  endif
  ! --------------> block: grid
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_grid', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_grid', i1); init_grid = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_GRID; default value set.'
    init_grid =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nzones', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nzones', nzones)
  else
    write(nonlin,*) ' %variable not in state file: NZONES; default value set.'
    nzones =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nzone_fb', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nzone_fb', nzone_fb)
  else
    write(nonlin,*) ' %variable not in state file: NZONE_FB; default value set.'
    nzone_fb =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlsym2b', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlsym2b', i1); nlsym2b = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLSYM2B; default value set.'
    nlsym2b =   .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nth0', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nth0', nth0)
  else
    write(nonlin,*) ' %variable not in state file: NTH0; default value set.'
    nth0 =   2
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xbmbnd', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xbmbnd', xbmbnd, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XBMBND; default value set.'
    xbmbnd =  1.3
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nthets', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nthets', nthets)
  else
    write(nonlin,*) ' %variable not in state file: NTHETS; default value set.'
    nthets =  64
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ebdmax', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'ebdmax', ebdmax, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EBDMAX; default value set.'
    ebdmax =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xplasma_in_memory', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'xplasma_in_memory', xplasma_in_memory)
  else
    write(nonlin,*) ' %variable not in state file: XPLASMA_IN_MEMORY; default value set.'
    xplasma_in_memory =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nznbma', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nznbma', nznbma)
  else
    write(nonlin,*) ' %variable not in state file: NZNBMA; default value set.'
    nznbma =  50
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nznbme', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nznbme', nznbme)
  else
    write(nonlin,*) ' %variable not in state file: NZNBME; default value set.'
    nznbme =  100
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nznbma0', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nznbma0', nznbma0)
  else
    write(nonlin,*) ' %variable not in state file: NZNBMA0; default value set.'
    nznbma0 =  10
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nznbme0', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nznbme0', nznbme0)
  else
    write(nonlin,*) ' %variable not in state file: NZNBME0; default value set.'
    nznbme0 =  50
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ngyro', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'ngyro', ngyro)
  else
    write(nonlin,*) ' %variable not in state file: NGYRO; default value set.'
    ngyro =  4
  endif
  ! --------------> block: beams
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_beams', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_beams', i1); init_beams = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_BEAMS; default value set.'
    init_beams =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ngmax', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'ngmax', ngmax)
  else
    write(nonlin,*) ' %variable not in state file: NGMAX; default value set.'
    ngmax =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'backz', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'backz', backz, mig, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BACKZ; default value set.'
    backz =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'aplasm', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'aplasm', aplasm, mig, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: APLASM; default value set.'
    aplasm =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbeam', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbeam', nbeam)
  else
    write(nonlin,*) ' %variable not in state file: NBEAM; default value set.'
    nbeam =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xzbeama', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xzbeama', xzbeama, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XZBEAMA; default value set.'
    xzbeama =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'abeama', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'abeama', abeama, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: ABEAMA; default value set.'
    abeama =  0.0_fp
  endif
  allocate(intarr(mib)); intarr=0
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlco', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlco', intarr)
  else
    write(nonlin,*) ' %variable not in state file: NLCO; default value set.'
    nlco =  .TRUE.
  endif
  call nbi_int2log(intarr, nlco, mib)
  deallocate(intarr)
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ntrace', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'ntrace', ntrace)
  else
    write(nonlin,*) ' %variable not in state file: NTRACE; default value set.'
    ntrace =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'rtcena', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'rtcena', rtcena, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: RTCENA; default value set.'
    rtcena =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xlbtna', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xlbtna', xlbtna, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XLBTNA; default value set.'
    xlbtna =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xybsca', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xybsca', xybsca, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XYBSCA; default value set.'
    xybsca =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xbzeta', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xbzeta', xbzeta, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XBZETA; default value set.'
    xbzeta =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbshapa', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbshapa', nbshapa)
  else
    write(nonlin,*) ' %variable not in state file: NBSHAPA; default value set.'
    nbshapa =  1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bmwidra', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'bmwidra', bmwidra, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BMWIDRA; default value set.'
    bmwidra =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bmwidza', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'bmwidza', bmwidza, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BMWIDZA; default value set.'
    bmwidza =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'divra', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'divra', divra, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: DIVRA; default value set.'
    divra =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'divza', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'divza', divza, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: DIVZA; default value set.'
    divza =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'foclra', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'foclra', foclra, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FOCLRA; default value set.'
    foclra =  1.0e+6_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'foclza', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'foclza', foclza, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FOCLZA; default value set.'
    foclza =  1.0e+6_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbapsha', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbapsha', nbapsha)
  else
    write(nonlin,*) ' %variable not in state file: NBAPSHA; default value set.'
    nbapsha =  1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'rapedga', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'rapedga', rapedga, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: RAPEDGA; default value set.'
    rapedga =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xzpedga', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xzpedga', xzpedga, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XZPEDGA; default value set.'
    xzpedga =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xlbapa', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xlbapa', xlbapa, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XLBAPA; default value set.'
    xlbapa =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xybapa', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xybapa', xybapa, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XYBAPA; default value set.'
    xybapa =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xrapoffa', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xrapoffa', xrapoffa, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XRAPOFFA; default value set.'
    xrapoffa =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xzapoffa', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xzapoffa', xzapoffa, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XZAPOFFA; default value set.'
    xzapoffa =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbapsh2', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbapsh2', nbapsh2)
  else
    write(nonlin,*) ' %variable not in state file: NBAPSH2; default value set.'
    nbapsh2 =  1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'rapedg2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'rapedg2', rapedg2, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: RAPEDG2; default value set.'
    rapedg2 =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xzpedg2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xzpedg2', xzpedg2, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XZPEDG2; default value set.'
    xzpedg2 =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xlbapa2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xlbapa2', xlbapa2, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XLBAPA2; default value set.'
    xlbapa2 =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xrapoff2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xrapoff2', xrapoff2, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XRAPOFF2; default value set.'
    xrapoff2 =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xzapoff2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xzapoff2', xzapoff2, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XZAPOFF2; default value set.'
    xzapoff2 =  0.0_fp
  endif
  ! --------------> block: impurity
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_impurity', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_impurity', i1); init_impurity = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_IMPURITY; default value set.'
    init_impurity =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nrhix', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nrhix', nrhix)
  else
    write(nonlin,*) ' %variable not in state file: NRHIX; default value set.'
    nrhix =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xzimpx', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xzimpx', xzimpx, mimpt, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XZIMPX; default value set.'
    xzimpx =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'aimpx', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'aimpx', aimpx, mimpt, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: AIMPX; default value set.'
    aimpx =  0.0_fp
  endif
  ! --------------> block: minority
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_minority', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_minority', i1); init_minority = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_MINORITY; default value set.'
    init_minority =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nmini', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nmini', nmini)
  else
    write(nonlin,*) ' %variable not in state file: NMINI; default value set.'
    nmini =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xzmini', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xzmini', xzmini, mmini, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XZMINI; default value set.'
    xzmini =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'amini', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'amini', amini, mmini, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: AMINI; default value set.'
    amini =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nthrf', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nthrf', nthrf)
  else
    write(nonlin,*) ' %variable not in state file: NTHRF; default value set.'
    nthrf =  1
  endif
  ! --------------> block: powers
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_powers', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_powers', i1); init_powers = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_POWERS; default value set.'
    init_powers =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'einjmin', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'einjmin', einjmin, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EINJMIN; default value set.'
    einjmin =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'einja', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'einja', einja, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EINJA; default value set.'
    einja =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'pinja', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'pinja', pinja, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: PINJA; default value set.'
    pinja =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ffulla', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'ffulla', ffulla, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FFULLA; default value set.'
    ffulla =  0.98_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'fhalfa', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'fhalfa', fhalfa, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FHALFA; default value set.'
    fhalfa =  0.01_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'orbrzv_toric_Prftot0', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'orbrzv_toric_Prftot0', orbrzv_toric_Prftot0, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: ORBRZV_TORIC_PRFTOT0; default value set.'
    orbrzv_toric_Prftot0 =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'orbrzv_toric_frnm', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'orbrzv_toric_frnm', orbrzv_toric_frnm, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: ORBRZV_TORIC_FRNM; default value set.'
    orbrzv_toric_frnm =  1.0_fp
  endif
  ! --------------> block: fusion
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_fusion', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_fusion', i1); init_fusion = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_FUSION; default value set.'
    init_fusion =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlfhe3', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlfhe3', i1); nlfhe3 = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLFHE3; default value set.'
    nlfhe3 =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlfhe4', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlfhe4', i1); nlfhe4 = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLFHE4; default value set.'
    nlfhe4 =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlfst', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlfst', i1); nlfst = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLFST; default value set.'
    nlfst =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlfsp', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlfsp', i1); nlfsp = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLFSP; default value set.'
    nlfsp =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlfsp14', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlfsp14', i1); nlfsp14 = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLFSP14; default value set.'
    nlfsp14 =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlusf3', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlusf3', i1); nlusf3 = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLUSF3; default value set.'
    nlusf3 =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xdatsf3', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xdatsf3', xdatsf3, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XDATSF3; default value set.'
    xdatsf3 =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlusfa', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlusfa', i1); nlusfa = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLUSFA; default value set.'
    nlusfa =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xdatsfa', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xdatsfa', xdatsfa, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XDATSFA; default value set.'
    xdatsfa =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlusft', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlusft', i1); nlusft = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLUSFT; default value set.'
    nlusft =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xdatsft', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xdatsft', xdatsft, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XDATSFT; default value set.'
    xdatsft =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlusfp', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlusfp', i1); nlusfp = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLUSFP; default value set.'
    nlusfp =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xdatsfp', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xdatsfp', xdatsfp, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XDATSFP; default value set.'
    xdatsfp =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlusfp14', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlusfp14', i1); nlusfp14 = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLUSFP14; default value set.'
    nlusfp14 =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xdatsp3', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xdatsp3', xdatsp3, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XDATSP3; default value set.'
    xdatsp3 =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'plfhe3', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'plfhe3', plfhe3, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: PLFHE3; default value set.'
    plfhe3 =  100.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'plfhe4', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'plfhe4', plfhe4, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: PLFHE4; default value set.'
    plfhe4 =  10000.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'plfst', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'plfst', plfst, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: PLFST; default value set.'
    plfst =  100.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'plfsp', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'plfsp', plfsp, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: PLFSP; default value set.'
    plfsp =  100.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'plfsp14', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'plfsp14', plfsp14, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: PLFSP14; default value set.'
    plfsp14 =  100.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlfatom', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlfatom', i1); nlfatom = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLFATOM; default value set.'
    nlfatom =  .TRUE.
  endif
  ! --------------> block: fpp
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_fpp', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_fpp', i1); init_fpp = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_FPP; default value set.'
    init_fpp =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlbfpp', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlbfpp', i1); nlbfpp = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLBFPP; default value set.'
    nlbfpp =  .FALSE.
  endif
  ! --------------> block: num
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_num', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_num', i1); init_num = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_NUM; default value set.'
    init_num =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'cxsplt', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'cxsplt', cxsplt, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: CXSPLT; default value set.'
    cxsplt =  2.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'dxbsmoo', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'dxbsmoo', dxbsmoo, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: DXBSMOO; default value set.'
    dxbsmoo =  0.05_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'dxbsm_nc', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'dxbsm_nc', dxbsm_nc, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: DXBSM_NC; default value set.'
    dxbsm_nc =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nptcls', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nptcls', nptcls)
  else
    write(nonlin,*) ' %variable not in state file: NPTCLS; default value set.'
    nptcls =  1000
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nptclf', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nptclf', nptclf)
  else
    write(nonlin,*) ' %variable not in state file: NPTCLF; default value set.'
    nptclf =  1000
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nptclh', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nptclh', nptclh)
  else
    write(nonlin,*) ' %variable not in state file: NPTCLH; default value set.'
    nptclh =  500
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'NFAST_MAP', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'NFAST_MAP', NFAST_MAP)
  else
    write(nonlin,*) ' %variable not in state file: NFAST_MAP; default value set.'
    NFAST_MAP =  1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xpand_nptcl', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xpand_nptcl', xpand_nptcl, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XPAND_NPTCL; default value set.'
    xpand_nptcl =  3.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'frac_depmax', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'frac_depmax', frac_depmax, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FRAC_DEPMAX; default value set.'
    frac_depmax =  0.25_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'frac_dep_lim', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'frac_dep_lim', frac_dep_lim, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FRAC_DEP_LIM; default value set.'
    frac_dep_lim =  1.5_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'frac_depmin', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'frac_depmin', frac_depmin, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FRAC_DEPMIN; default value set.'
    frac_depmin =  0.01_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'frac_orbrr', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'frac_orbrr', frac_orbrr, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FRAC_ORBRR; default value set.'
    frac_orbrr =  0.10_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nptcl_max', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nptcl_max', nptcl_max)
  else
    write(nonlin,*) ' %variable not in state file: NPTCL_MAX; default value set.'
    nptcl_max =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nltrk_dep0', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nltrk_dep0', i1); nltrk_dep0 = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLTRK_DEP0; default value set.'
    nltrk_dep0 =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'NLDEP0_GATHER', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'NLDEP0_GATHER', i1); NLDEP0_GATHER = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLDEP0_GATHER; default value set.'
    NLDEP0_GATHER =   .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ndep0', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'ndep0', ndep0)
  else
    write(nonlin,*) ' %variable not in state file: NDEP0; default value set.'
    ndep0 =  500
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'NDEP0_MAX', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'NDEP0_MAX', NDEP0_MAX)
  else
    write(nonlin,*) ' %variable not in state file: NDEP0_MAX; default value set.'
    NDEP0_MAX =     100000
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ndep_set_beam', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'ndep_set_beam', ndep_set_beam)
  else
    write(nonlin,*) ' %variable not in state file: NDEP_SET_BEAM; default value set.'
    ndep_set_beam =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ndep_set_ien', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'ndep_set_ien', ndep_set_ien)
  else
    write(nonlin,*) ' %variable not in state file: NDEP_SET_IEN; default value set.'
    ndep_set_ien =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbbcal', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbbcal', nbbcal)
  else
    write(nonlin,*) ' %variable not in state file: NBBCAL; default value set.'
    nbbcal =  1000000
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ncx0', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'ncx0', ncx0)
  else
    write(nonlin,*) ' %variable not in state file: NCX0; default value set.'
    ncx0 =  100
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nper_cx', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nper_cx', nper_cx)
  else
    write(nonlin,*) ' %variable not in state file: NPER_CX; default value set.'
    nper_cx =  4
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'LEV_NBIDEP', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'LEV_NBIDEP', LEV_NBIDEP)
  else
    write(nonlin,*) ' %variable not in state file: LEV_NBIDEP; default value set.'
    LEV_NBIDEP =   1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'LEV_TTNUK', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'LEV_TTNUK', LEV_TTNUK)
  else
    write(nonlin,*) ' %variable not in state file: LEV_TTNUK; default value set.'
    LEV_TTNUK =   0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'LEVMOD_HALO', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'LEVMOD_HALO', LEVMOD_HALO)
  else
    write(nonlin,*) ' %variable not in state file: LEVMOD_HALO; default value set.'
    LEVMOD_HALO =   0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'NSPLT', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'NSPLT', NSPLT)
  else
    write(nonlin,*) ' %variable not in state file: NSPLT; default value set.'
    NSPLT =   100
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'NSPLT_GEO', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'NSPLT_GEO', NSPLT_GEO)
  else
    write(nonlin,*) ' %variable not in state file: NSPLT_GEO; default value set.'
    NSPLT_GEO =   1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'NSPLT_KIN', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'NSPLT_KIN', NSPLT_KIN)
  else
    write(nonlin,*) ' %variable not in state file: NSPLT_KIN; default value set.'
    NSPLT_KIN =   1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'NSPLT_GEN', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'NSPLT_GEN', NSPLT_GEN)
  else
    write(nonlin,*) ' %variable not in state file: NSPLT_GEN; default value set.'
    NSPLT_GEN =   1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nmimp', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nmimp', nmimp)
  else
    write(nonlin,*) ' %variable not in state file: NMIMP; default value set.'
    nmimp =   1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'AIMP', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'AIMP', AIMP, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: AIMP; default value set.'
    AIMP =     16._fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'XZIMP', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'XZIMP', XZIMP, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XZIMP; default value set.'
    XZIMP =     8._fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'NTEST_MAX', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'NTEST_MAX', NTEST_MAX)
  else
    write(nonlin,*) ' %variable not in state file: NTEST_MAX; default value set.'
    NTEST_MAX =   0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'BI_MAX_PL', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'BI_MAX_PL', BI_MAX_PL, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BI_MAX_PL; default value set.'
    BI_MAX_PL =   1._fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'BI_MAX_PR', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'BI_MAX_PR', BI_MAX_PR, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BI_MAX_PR; default value set.'
    BI_MAX_PR =   1._fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'wghta', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'wghta', wghta, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: WGHTA; default value set.'
    wghta =  1.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'goocon', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'goocon', goocon, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: GOOCON; default value set.'
    goocon =  10.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'NGOOCON_VPVBIN', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'NGOOCON_VPVBIN', NGOOCON_VPVBIN)
  else
    write(nonlin,*) ' %variable not in state file: NGOOCON_VPVBIN; default value set.'
    NGOOCON_VPVBIN =   0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'NGOOCON_EBIN', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'NGOOCON_EBIN', NGOOCON_EBIN)
  else
    write(nonlin,*) ' %variable not in state file: NGOOCON_EBIN; default value set.'
    NGOOCON_EBIN =   1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'NGOOCON_RBIN', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'NGOOCON_RBIN', NGOOCON_RBIN)
  else
    write(nonlin,*) ' %variable not in state file: NGOOCON_RBIN; default value set.'
    NGOOCON_RBIN =   1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'cxpcon', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'cxpcon', cxpcon, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: CXPCON; default value set.'
    cxpcon =  20.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'fppcon', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'fppcon', fppcon, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FPPCON; default value set.'
    fppcon =  8.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'fdtnxy', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'fdtnxy', fdtnxy, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FDTNXY; default value set.'
    fdtnxy =  0.5_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nchdvp', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nchdvp', nchdvp)
  else
    write(nonlin,*) ' %variable not in state file: NCHDVP; default value set.'
    nchdvp =  3
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'dtn', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'dtn', dtn, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: DTN; default value set.'
    dtn =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'dt_acc', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'dt_acc', dt_acc, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: DT_ACC; default value set.'
    dt_acc =  1.0e-4
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'orbrzv_option', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'orbrzv_option', orbrzv_option)
  else
    write(nonlin,*) ' %variable not in state file: ORBRZV_OPTION; default value set.'
    orbrzv_option =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'orbrzv_rf_option', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'orbrzv_rf_option', orbrzv_rf_option)
  else
    write(nonlin,*) ' %variable not in state file: ORBRZV_RF_OPTION; default value set.'
    orbrzv_rf_option =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlmcrf_on', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlmcrf_on', i1); nlmcrf_on = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLMCRF_ON; default value set.'
    nlmcrf_on =  .false.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'orbrzv_nr', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'orbrzv_nr', orbrzv_nr)
  else
    write(nonlin,*) ' %variable not in state file: ORBRZV_NR; default value set.'
    orbrzv_nr =  160
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'orbrzv_nz', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'orbrzv_nz', orbrzv_nz)
  else
    write(nonlin,*) ' %variable not in state file: ORBRZV_NZ; default value set.'
    orbrzv_nz =  160
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'orbrzv_zzerr_con', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'orbrzv_zzerr_con', orbrzv_zzerr_con, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: ORBRZV_ZZERR_CON; default value set.'
    orbrzv_zzerr_con =  1.0e-4_fp
  endif
  ! --------------> block: atomic
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_atomic', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_atomic', i1); init_atomic = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_ATOMIC; default value set.'
    init_atomic =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nsmax', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nsmax', nsmax)
  else
    write(nonlin,*) ' %variable not in state file: NSMAX; default value set.'
    nsmax =  21
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'khalo', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'khalo', khalo)
  else
    write(nonlin,*) ' %variable not in state file: KHALO; default value set.'
    khalo =   -1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'dn0out', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'dn0out', dn0out, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: DN0OUT; default value set.'
    dn0out =  1.0e+11_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nmsigx', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nmsigx', nmsigx)
  else
    write(nonlin,*) ' %variable not in state file: NMSIGX; default value set.'
    nmsigx =  2
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlminsv', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlminsv', i1); nlminsv = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLMINSV; default value set.'
    nlminsv =  .TRUE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlebei', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlebei', i1); nlebei = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLEBEI; default value set.'
    nlebei =  .TRUE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nsigexc', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nsigexc', nsigexc)
  else
    write(nonlin,*) ' %variable not in state file: NSIGEXC; default value set.'
    nsigexc =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xdepmod', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xdepmod', xdepmod, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XDEPMOD; default value set.'
    xdepmod =  1.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlbbcx', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlbbcx', i1); nlbbcx = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLBBCX; default value set.'
    nlbbcx =  .TRUE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbbcx_avg', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbbcx_avg', nbbcx_avg)
  else
    write(nonlin,*) ' %variable not in state file: NBBCX_AVG; default value set.'
    nbbcx_avg =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbbcx_bb', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbbcx_bb', nbbcx_bb)
  else
    write(nonlin,*) ' %variable not in state file: NBBCX_BB; default value set.'
    nbbcx_bb =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbfallgr', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbfallgr', nbfallgr)
  else
    write(nonlin,*) ' %variable not in state file: NBFALLGR; default value set.'
    nbfallgr =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlbeamcx', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlbeamcx', i1); nlbeamcx = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLBEAMCX; default value set.'
    nlbeamcx =  .TRUE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlhvion', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlhvion', i1); nlhvion = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLHVION; default value set.'
    nlhvion =  .TRUE.
  endif
  ! --------------> block: collid
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_collid', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_collid', i1); init_collid = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_COLLID; default value set.'
    init_collid =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xcfanbi', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xcfanbi', xcfanbi, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XCFANBI; default value set.'
    xcfanbi =  1.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xdfanbi', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xdfanbi', xdfanbi, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XDFANBI; default value set.'
    xdfanbi =  1.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xefanbi', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xefanbi', xefanbi, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XEFANBI; default value set.'
    xefanbi =  1.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xcfafus', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xcfafus', xcfafus, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XCFAFUS; default value set.'
    xcfafus =  1.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xdfafus', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xdfafus', xdfafus, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XDFAFUS; default value set.'
    xdfafus =  1.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xefafus', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xefafus', xefafus, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XEFAFUS; default value set.'
    xefafus =  1.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlbcde', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlbcde', i1); nlbcde = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLBCDE; default value set.'
    nlbcde =  .true.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlbcoh', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlbcoh', i1); nlbcoh = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLBCOH; default value set.'
    nlbcoh =  .true.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlbcpa', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlbcpa', i1); nlbcpa = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLBCPA; default value set.'
    nlbcpa =  .true.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlorbo', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlorbo', i1); nlorbo = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLORBO; default value set.'
    nlorbo =  .false.
  endif
  ! --------------> block: flr
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_flr', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_flr', i1); init_flr = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_FLR; default value set.'
    init_flr =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlbflr', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlbflr', i1); nlbflr = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLBFLR; default value set.'
    nlbflr =  .TRUE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlfbmflr', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlfbmflr', i1); nlfbmflr = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLFBMFLR; default value set.'
    nlfbmflr =  .TRUE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlbgflr', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlbgflr', i1); nlbgflr = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLBGFLR; default value set.'
    nlbgflr =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'gflr_min', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'gflr_min', gflr_min, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: GFLR_MIN; default value set.'
    gflr_min =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'gflr_rl', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'gflr_rl', gflr_rl, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: GFLR_RL; default value set.'
    gflr_rl =  1.0e+6_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'gflr_ll', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'gflr_ll', gflr_ll, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: GFLR_LL; default value set.'
    gflr_ll =  30.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'gflr_xv', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'gflr_xv', gflr_xv, 2, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: GFLR_XV; default value set.'
    gflr_xv =   (/1.5_fp, 0.4_fp/)
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'gflr_op', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'gflr_op', gflr_op, 15, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: GFLR_OP; default value set.'
    gflr_op =   (/0._fp,1.e-4_fp,1.e-5_fp,0._fp,3._fp,10._fp,1._fp,0.2_fp,0.05_fp,1._fp,2._fp,0._fp,0._fp,0._fp,0._fp/)
  endif
  ! --------------> block: saw
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_saw', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_saw', i1); init_saw = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_SAW; default value set.'
    init_saw =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'sawflag', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'sawflag', i1); sawflag = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: SAWFLAG; default value set.'
    sawflag =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlsawb', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlsawb', i1); nlsawb = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLSAWB; default value set.'
    nlsawb =  .TRUE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlsawf', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlsawf', i1); nlsawf = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLSAWF; default value set.'
    nlsawf =  .TRUE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xswfrac_allfast', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xswfrac_allfast', xswfrac_allfast, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XSWFRAC_ALLFAST; default value set.'
    xswfrac_allfast =  1.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xswfrac_beam', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xswfrac_beam', xswfrac_beam, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XSWFRAC_BEAM; default value set.'
    xswfrac_beam =  1.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xswfrac_fusn', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xswfrac_fusn', xswfrac_fusn, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XSWFRAC_FUSN; default value set.'
    xswfrac_fusn =  1.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nmix_kdsaw', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nmix_kdsaw', nmix_kdsaw)
  else
    write(nonlin,*) ' %variable not in state file: NMIX_KDSAW; default value set.'
    nmix_kdsaw =  1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'fporcelli', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'fporcelli', fporcelli, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FPORCELLI; default value set.'
    fporcelli =  1.0_fp
  endif
  ! --------------> block: adif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_adif', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_adif', i1); init_adif = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_ADIF; default value set.'
    init_adif =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nkaep', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nkaep', nkaep)
  else
    write(nonlin,*) ' %variable not in state file: NKAEP; default value set.'
    nkaep =   0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'AEP_ASCALE', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'AEP_ASCALE', AEP_ASCALE, mnkaep, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: AEP_ASCALE; default value set.'
    AEP_ASCALE =   0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'AEP_USCALE', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'AEP_USCALE', AEP_USCALE, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: AEP_USCALE; default value set.'
    AEP_USCALE =   1.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'TAEP_FAC', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'TAEP_FAC', TAEP_FAC, mnkaep, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: TAEP_FAC; default value set.'
    TAEP_FAC =   0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nmdifb', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nmdifb', nmdifb)
  else
    write(nonlin,*) ' %variable not in state file: NMDIFB; default value set.'
    nmdifb =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nkdifb', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nkdifb', nkdifb)
  else
    write(nonlin,*) ' %variable not in state file: NKDIFB; default value set.'
    nkdifb =  3
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ndifbe', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'ndifbe', ndifbe)
  else
    write(nonlin,*) ' %variable not in state file: NDIFBE; default value set.'
    ndifbe =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'fdifbe', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'fdifbe', fdifbe, 20, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FDIFBE; default value set.'
    fdifbe =  1.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'edifbe', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'edifbe', edifbe, 20, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EDIFBE; default value set.'
    edifbe =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'x_qlim0', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'x_qlim0', x_qlim0, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: X_QLIM0; default value set.'
    x_qlim0 =   0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ndifbe_2d', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'ndifbe_2d', ndifbe_2d)
  else
    write(nonlin,*) ' %variable not in state file: NDIFBE_2D; default value set.'
    ndifbe_2d =   1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'dif2d_conv', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'dif2d_conv', dif2d_conv, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: DIF2D_CONV; default value set.'
    dif2d_conv =   0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'dif2d_dpa', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'dif2d_dpa', dif2d_dpa, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: DIF2D_DPA; default value set.'
    dif2d_dpa =   0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ngradd_opt', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'ngradd_opt', ngradd_opt)
  else
    write(nonlin,*) ' %variable not in state file: NGRADD_OPT; default value set.'
    ngradd_opt =   0
  endif
  ! --------------> block: ripple
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_ripple', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_ripple', i1); init_ripple = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_RIPPLE; default value set.'
    init_ripple =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nrip', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nrip', nrip)
  else
    write(nonlin,*) ' %variable not in state file: NRIP; default value set.'
    nrip =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'taurip', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'taurip', taurip, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: TAURIP; default value set.'
    taurip =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ncoils', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'ncoils', ncoils)
  else
    write(nonlin,*) ' %variable not in state file: NCOILS; default value set.'
    ncoils =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ncoils_2', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'ncoils_2', ncoils_2)
  else
    write(nonlin,*) ' %variable not in state file: NCOILS_2; default value set.'
    ncoils_2 =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'asrd', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'asrd', asrd, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: ASRD; default value set.'
    asrd =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bsrd', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'bsrd', bsrd, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BSRD; default value set.'
    bsrd =  0.0_fp
  endif
  ! --------------> block: outcon
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_outcon', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_outcon', i1); init_outcon = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_OUTCON; default value set.'
    init_outcon =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nerngfi', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nerngfi', nerngfi)
  else
    write(nonlin,*) ' %variable not in state file: NERNGFI; default value set.'
    nerngfi =  1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'erngfi', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'erngfi', erngfi, miefi,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: ERNGFI; default value set.'
    erngfi =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nsdbgb', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nsdbgb', nsdbgb)
  else
    write(nonlin,*) ' %variable not in state file: NSDBGB; default value set.'
    nsdbgb =  1
  endif
  ! --------------> block: fishbone
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_fishbone', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_fishbone', i1); init_fishbone = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_FISHBONE; default value set.'
    init_fishbone =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlfbon', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlfbon', i1); nlfbon = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLFBON; default value set.'
    nlfbon =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'fbemin', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'fbemin', fbemin, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FBEMIN; default value set.'
    fbemin =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'fbemax', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'fbemax', fbemax, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FBEMAX; default value set.'
    fbemax =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'fvpvmn', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'fvpvmn', fvpvmn, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FVPVMN; default value set.'
    fvpvmn =   0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'fvpvmx', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'fvpvmx', fvpvmx, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FVPVMX; default value set.'
    fvpvmx =   0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'fbltim', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'fbltim', fbltim, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FBLTIM; default value set.'
    fbltim =   1.0e-7_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'fshper', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'fshper', fshper, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FSHPER; default value set.'
    fshper =   5.0e-3_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'fshwid', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'fshwid', fshwid, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FSHWID; default value set.'
    fshwid =   1.0e-3_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'tfshon', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'tfshon', tfshon, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: TFSHON; default value set.'
    tfshon =   -1000.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'tfshof', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'tfshof', tfshof, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: TFSHOF; default value set.'
    tfshof =   +1.0e+34_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xfishmin', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xfishmin', xfishmin, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XFISHMIN; default value set.'
    xfishmin =   0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xfishmax', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xfishmax', xfishmax, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XFISHMAX; default value set.'
    xfishmax =   1.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nfbon_vpvopt', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nfbon_vpvopt', nfbon_vpvopt)
  else
    write(nonlin,*) ' %variable not in state file: NFBON_VPVOPT; default value set.'
    nfbon_vpvopt =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'fbtrap_depth', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'fbtrap_depth', fbtrap_depth, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FBTRAP_DEPTH; default value set.'
    fbtrap_depth =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nfbon_species', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nfbon_species', nfbon_species)
  else
    write(nonlin,*) ' %variable not in state file: NFBON_SPECIES; default value set.'
    nfbon_species =  3
  endif
  ! --------------> block: box
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_box', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_box', i1); init_box = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_BOX; default value set.'
    init_box =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbbox', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbbox', nbbox)
  else
    write(nonlin,*) ' %variable not in state file: NBBOX; default value set.'
    nbbox =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbsbox', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbsbox', nbsbox)
  else
    write(nonlin,*) ' %variable not in state file: NBSBOX; default value set.'
    nbsbox =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nsample_box', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nsample_box', nsample_box)
  else
    write(nonlin,*) ' %variable not in state file: NSAMPLE_BOX; default value set.'
    nsample_box =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xninja_box', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xninja_box', xninja_box, miboxm, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XNINJA_BOX; default value set.'
    xninja_box =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xninjs_box', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xninjs_box', xninjs_box, miboxm, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XNINJS_BOX; default value set.'
    xninjs_box =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xninj_box', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xninj_box', xninj_box, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XNINJ_BOX; default value set.'
    xninj_box =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbebox', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbebox', nbebox)
  else
    write(nonlin,*) ' %variable not in state file: NBEBOX; default value set.'
    nbebox =  1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nxbox', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nxbox', nxbox)
  else
    write(nonlin,*) ' %variable not in state file: NXBOX; default value set.'
    nxbox =  1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nybox', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nybox', nybox)
  else
    write(nonlin,*) ' %variable not in state file: NYBOX; default value set.'
    nybox =  1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlbox', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlbox', nlbox)
  else
    write(nonlin,*) ' %variable not in state file: NLBOX; default value set.'
    nlbox =  100
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xboxhw', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xboxhw', xboxhw, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XBOXHW; default value set.'
    xboxhw =  5.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'yboxhw', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'yboxhw', yboxhw, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: YBOXHW; default value set.'
    yboxhw =  5.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xlbox1', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xlbox1', xlbox1, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XLBOX1; default value set.'
    xlbox1 =  100.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xlbox2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xlbox2', xlbox2, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XLBOX2; default value set.'
    xlbox2 =  500.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ndepbox', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'ndepbox', ndepbox)
  else
    write(nonlin,*) ' %variable not in state file: NDEPBOX; default value set.'
    ndepbox =  500
  endif
  ! --------------> block: tube
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_tube', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_tube', i1); init_tube = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_TUBE; default value set.'
    init_tube =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbtube', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbtube', nbtube)
  else
    write(nonlin,*) ' %variable not in state file: NBTUBE; default value set.'
    nbtube =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbstube', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbstube', nbstube)
  else
    write(nonlin,*) ' %variable not in state file: NBSTUBE; default value set.'
    nbstube =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbetube', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbetube', nbetube)
  else
    write(nonlin,*) ' %variable not in state file: NBETUBE; default value set.'
    nbetube =  1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'Rtube', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'Rtube', Rtube, mitubem, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: RTUBE; default value set.'
    Rtube =  0.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'Ytube', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'Ytube', Ytube, mitubem, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: YTUBE; default value set.'
    Ytube =  0.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'XZETAtube', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'XZETAtube', XZETAtube, mitubem, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XZETATUBE; default value set.'
    XZETAtube =  0.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'PHItube', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'PHItube', PHItube, mitubem, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: PHITUBE; default value set.'
    PHItube =  0.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'THETAtube', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'THETAtube', THETAtube, mitubem, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: THETATUBE; default value set.'
    THETAtube =  0.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'LMIDtube', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'LMIDtube', LMIDtube)
  else
    write(nonlin,*) ' %variable not in state file: LMIDTUBE; default value set.'
    LMIDtube =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'XL1tube', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'XL1tube', XL1tube, mitubem, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XL1TUBE; default value set.'
    XL1tube =  0.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'XL2tube', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'XL2tube', XL2tube, mitubem, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XL2TUBE; default value set.'
    XL2tube =  0.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'NSEGtube', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'NSEGtube', NSEGtube)
  else
    write(nonlin,*) ' %variable not in state file: NSEGTUBE; default value set.'
    NSEGtube =  100
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'RHOtube', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'RHOtube', RHOtube, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: RHOTUBE; default value set.'
    RHOtube =   1._fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'NDEPtube', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'NDEPtube', NDEPtube)
  else
    write(nonlin,*) ' %variable not in state file: NDEPTUBE; default value set.'
    NDEPtube =  500
  endif
  ! --------------> block: misc
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_misc', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_misc', i1); init_misc = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_MISC; default value set.'
    init_misc =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'plhgt', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'plhgt', plhgt, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: PLHGT; default value set.'
    plhgt =  0.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlcprb', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlcprb', i1); nlcprb = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLCPRB; default value set.'
    nlcprb =  .TRUE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlpsirz', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlpsirz', i1); nlpsirz = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLPSIRZ; default value set.'
    nlpsirz =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'edbfac', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'edbfac', edbfac, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EDBFAC; default value set.'
    edbfac =  10.0_fp
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nmcurb', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nmcurb', nmcurb)
  else
    write(nonlin,*) ' %variable not in state file: NMCURB; default value set.'
    nmcurb =  1
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlfdep', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlfdep', i1); nlfdep = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NLFDEP; default value set.'
    nlfdep =  .FALSE.
  endif
  ! --------------> block: profiles
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_profiles', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_profiles', i1); init_profiles = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: INIT_PROFILES; default value set.'
    init_profiles =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ng', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'ng', ng)
  else
    write(nonlin,*) ' %variable not in state file: NG; default value set.'
    ng =  0
  endif
 
  call nbi_alloc2_init
  contains
 
    logical function int2log(iint)
      integer, intent(in) :: iint
      if(iint.eq.1) then
        int2log=.TRUE.
      else
        int2log=.FALSE.
      endif
    end function int2log
 
end subroutine nbi_state_read1
 
 
!=======================
subroutine nbi_id_save
  use nbi_com
  implicit NONE
 
  ! --------------> block: ripple
  call nbi_save_id0('id_ripple',id_ripple)
  call nbi_save_id0('id_ripple2',id_ripple2)
  ! --------------> block: profiles
  call nbi_save_id0('id_te',id_te)
  call nbi_save_id0('id_ti',id_ti)
  call nbi_save_id0('id_tifusn',id_tifusn)
  call nbi_save_id0('id_ne',id_ne)
  call nbi_save_id1('id_nh',id_nh,mig)
  call nbi_save_id1('id_nimp',id_nimp,mimpt)
  call nbi_save_id1('id_nrf',id_nrf,mmini)
  call nbi_save_id1('id_eperpmin',id_eperpmin,mmini)
  call nbi_save_id1('id_epllmin',id_epllmin,mmini)
  call nbi_save_id1('id_nfast',id_nfast,mibs)
  call nbi_save_id1('id_eperpfast',id_eperpfast,mibs)
  call nbi_save_id1('id_epllfast',id_epllfast,mibs)
  call nbi_save_id0('id_aimp',id_aimp)
  call nbi_save_id0('id_zimp',id_zimp)
  call nbi_save_id0('id_omega',id_omega)
  call nbi_save_id0('id_epot',id_epot)
  call nbi_save_id0('id_vpoh',id_vpoh)
  call nbi_save_id0('id_curt',id_curt)
  call nbi_save_id0('id_difb',id_difb)
  call nbi_save_id0('id_velb',id_velb)
  call nbi_save_id0('id_difb_bi',id_difb_bi)
  call nbi_save_id0('id_velb_bi',id_velb_bi)
  call nbi_save_id0('id_difb_fi',id_difb_fi)
  call nbi_save_id0('id_velb_fi',id_velb_fi)
  call nbi_save_id1('id_fd0',id_fd0,mibs)
  call nbi_save_id1('id_fdb',id_fdb,mibs)
  call nbi_save_id1('id_fdp',id_fdp,mibs)
  call nbi_save_id1('id_fdq',id_fdq,mibs)
  call nbi_save_id1('id_fdr',id_fdr,mibs)
  call nbi_save_id1('id_fds',id_fds,mibs)
  call nbi_save_id2('id_n0',id_n0,mis,mig)
  call nbi_save_id2('id_t0',id_t0,mis,mig)
  call nbi_save_id2('id_omeg0',id_omeg0,mis,mig)
 
end subroutine nbi_id_save
 
!=======================
subroutine nbi_id_restore
  use nbi_com
  implicit NONE
 
  ! --------------> block: ripple
  call nbi_restore_id0('id_ripple',id_ripple)
  call nbi_restore_id0('id_ripple2',id_ripple2)
  ! --------------> block: profiles
  call nbi_restore_id0('id_te',id_te)
  call nbi_restore_id0('id_ti',id_ti)
  call nbi_restore_id0('id_tifusn',id_tifusn)
  call nbi_restore_id0('id_ne',id_ne)
  call nbi_restore_id1('id_nh',id_nh,mig)
  call nbi_restore_id1('id_nimp',id_nimp,mimpt)
  call nbi_restore_id1('id_nrf',id_nrf,mmini)
  call nbi_restore_id1('id_eperpmin',id_eperpmin,mmini)
  call nbi_restore_id1('id_epllmin',id_epllmin,mmini)
  call nbi_restore_id1('id_nfast',id_nfast,mibs)
  call nbi_restore_id1('id_eperpfast',id_eperpfast,mibs)
  call nbi_restore_id1('id_epllfast',id_epllfast,mibs)
  call nbi_restore_id0('id_aimp',id_aimp)
  call nbi_restore_id0('id_zimp',id_zimp)
  call nbi_restore_id0('id_omega',id_omega)
  call nbi_restore_id0('id_epot',id_epot)
  call nbi_restore_id0('id_vpoh',id_vpoh)
  call nbi_restore_id0('id_curt',id_curt)
  call nbi_restore_id0('id_difb',id_difb)
  call nbi_restore_id0('id_velb',id_velb)
  call nbi_restore_id0('id_difb_bi',id_difb_bi)
  call nbi_restore_id0('id_velb_bi',id_velb_bi)
  call nbi_restore_id0('id_difb_fi',id_difb_fi)
  call nbi_restore_id0('id_velb_fi',id_velb_fi)
  call nbi_restore_id1('id_fd0',id_fd0,mibs)
  call nbi_restore_id1('id_fdb',id_fdb,mibs)
  call nbi_restore_id1('id_fdp',id_fdp,mibs)
  call nbi_restore_id1('id_fdq',id_fdq,mibs)
  call nbi_restore_id1('id_fdr',id_fdr,mibs)
  call nbi_restore_id1('id_fds',id_fds,mibs)
  call nbi_restore_id2('id_n0',id_n0,mis,mig)
  call nbi_restore_id2('id_t0',id_t0,mis,mig)
  call nbi_restore_id2('id_omeg0',id_omeg0,mis,mig)
 
end subroutine nbi_id_restore
 
subroutine nbi_state_define2_ptcl(icdf)
 
  use nbi_com
  use ezcdf
 
  implicit NONE
 
  integer, intent(in) :: icdf  ! NetCDF file id
 
  integer :: idm(3),i1,i2,i3,i4
  character*4 zvartype
  integer, dimension(:), allocatable :: intarr
 
  idm = (/ 0, 0, 0/)
  call cdfDefVar(icdf, 'minb', idm, 'INT')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'cxpray', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'fppray', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'goosay', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'nbndex', idm, 'INT')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'nbscay', idm, 'INT')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'nbienay', idm, 'INT')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'einjay', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'njavay', idm, 'INT')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'njavay_saw', idm, 'INT')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'nuse', idm, 'INT')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'ntotptp', idm, 'INT')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'nnewp', idm, 'INT')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'pmechay', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'pphiay', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'pinjay', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'pmechay_saw', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'pphiay_saw', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'rmjionay', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'rmjionay_saw', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'tdepay', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'tfluxay', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'tfluxay_saw', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'thay', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'thay_saw', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'vay', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'vay_saw', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'wghtay', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'xiay', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'xiay_saw', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'xistay', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'xistay_saw', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'xksidy', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'xksidy_saw', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'xmuay', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'xmuay_saw', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'xzbmay', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'xzionay', idm, 'R8')
  idm = (/ minb,  mibs, 0 /)
  call cdfDefVar(icdf, 'xzionay_saw', idm, 'R8')
 
end subroutine nbi_state_define2_ptcl
 
 
subroutine nbi_state_output2_ptcl(icdf)
 
  use nbi_com
  use ezcdf
 
  implicit NONE
 
  integer, intent(in) :: icdf  ! NetCDF file id
 
  integer :: idm(3),i1,i2,i3,i4
  character*4 zvartype
  integer, dimension(:), allocatable :: intarr
 
  call cdfPutVar(icdf, 'minb', minb)
  call cdfPutVar(icdf, 'cxpray', cxpray)
  call cdfPutVar(icdf, 'fppray', fppray)
  call cdfPutVar(icdf, 'goosay', goosay)
  call cdfPutVar(icdf, 'nbndex', nbndex)
  call cdfPutVar(icdf, 'nbscay', nbscay)
  call cdfPutVar(icdf, 'nbienay', nbienay)
  call cdfPutVar(icdf, 'einjay', einjay)
  call cdfPutVar(icdf, 'njavay', njavay)
  call cdfPutVar(icdf, 'njavay_saw', njavay_saw)
  call cdfPutVar(icdf, 'nuse', nuse)
  call cdfPutVar(icdf, 'ntotptp', ntotptp)
  call cdfPutVar(icdf, 'nnewp', nnewp)
  call cdfPutVar(icdf, 'pmechay', pmechay)
  call cdfPutVar(icdf, 'pphiay', pphiay)
  call cdfPutVar(icdf, 'pinjay', pinjay)
  call cdfPutVar(icdf, 'pmechay_saw', pmechay_saw)
  call cdfPutVar(icdf, 'pphiay_saw', pphiay_saw)
  call cdfPutVar(icdf, 'rmjionay', rmjionay)
  call cdfPutVar(icdf, 'rmjionay_saw', rmjionay_saw)
  call cdfPutVar(icdf, 'tdepay', tdepay)
  call cdfPutVar(icdf, 'tfluxay', tfluxay)
  call cdfPutVar(icdf, 'tfluxay_saw', tfluxay_saw)
  call cdfPutVar(icdf, 'thay', thay)
  call cdfPutVar(icdf, 'thay_saw', thay_saw)
  call cdfPutVar(icdf, 'vay', vay)
  call cdfPutVar(icdf, 'vay_saw', vay_saw)
  call cdfPutVar(icdf, 'wghtay', wghtay)
  call cdfPutVar(icdf, 'xiay', xiay)
  call cdfPutVar(icdf, 'xiay_saw', xiay_saw)
  call cdfPutVar(icdf, 'xistay', xistay)
  call cdfPutVar(icdf, 'xistay_saw', xistay_saw)
  call cdfPutVar(icdf, 'xksidy', xksidy)
  call cdfPutVar(icdf, 'xksidy_saw', xksidy_saw)
  call cdfPutVar(icdf, 'xmuay', xmuay)
  call cdfPutVar(icdf, 'xmuay_saw', xmuay_saw)
  call cdfPutVar(icdf, 'xzbmay', xzbmay)
  call cdfPutVar(icdf, 'xzionay', xzionay)
  call cdfPutVar(icdf, 'xzionay_saw', xzionay_saw)
 
end subroutine nbi_state_output2_ptcl
 
 
subroutine nbi_state_read2_ptcl(icdf)
 
  use nbi_com
  use ezcdf
 
  implicit NONE
 
  integer, intent(in) :: icdf  ! NetCDF file id
 
  integer :: idm(3),i1,i2,i3,i4
  character*4 zvartype
  integer, dimension(:), allocatable :: intarr
 
  idm = (/ -1, -1, -1 /)
  call cdfInqVar(icdf, 'minb', idm, zvartype)
  if(idm(1).ne.-1) then
     call cdfGetVar(icdf, 'minb', minb)
  else
     write(nonlin,*) ' ** DIMENSION (fin) not in state file: MINB; cleared to ZERO'
     minb = 0
  endif
 
  call nbi_alloc_minb
 
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'cxpray', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'cxpray', cxpray, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: CXPRAY; default value set.'
    cxpray =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'fppray', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'fppray', fppray, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FPPRAY; default value set.'
    fppray =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'goosay', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'goosay', goosay, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: GOOSAY; default value set.'
    goosay =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbndex', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbndex', nbndex)
  else
    write(nonlin,*) ' %variable not in state file: NBNDEX; default value set.'
    nbndex =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbscay', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbscay', nbscay)
  else
    write(nonlin,*) ' %variable not in state file: NBSCAY; default value set.'
    nbscay =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbienay', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbienay', nbienay)
  else
    write(nonlin,*) ' %variable not in state file: NBIENAY; default value set.'
    nbienay =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'einjay', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'einjay', einjay, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EINJAY; default value set.'
    einjay =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'njavay', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'njavay', njavay)
  else
    write(nonlin,*) ' %variable not in state file: NJAVAY; default value set.'
    njavay =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'njavay_saw', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'njavay_saw', njavay_saw)
  else
    write(nonlin,*) ' %variable not in state file: NJAVAY_SAW; default value set.'
    njavay_saw =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nuse', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nuse', nuse)
  else
    write(nonlin,*) ' %variable not in state file: NUSE; default value set.'
    nuse =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ntotptp', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'ntotptp', ntotptp)
  else
    write(nonlin,*) ' %variable not in state file: NTOTPTP; default value set.'
    ntotptp =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nnewp', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nnewp', nnewp)
  else
    write(nonlin,*) ' %variable not in state file: NNEWP; default value set.'
    nnewp =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'pmechay', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'pmechay', pmechay, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: PMECHAY; default value set.'
    pmechay =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'pphiay', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'pphiay', pphiay, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: PPHIAY; default value set.'
    pphiay =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'pinjay', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'pinjay', pinjay, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: PINJAY; default value set.'
    pinjay =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'pmechay_saw', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'pmechay_saw', pmechay_saw, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: PMECHAY_SAW; default value set.'
    pmechay_saw =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'pphiay_saw', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'pphiay_saw', pphiay_saw, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: PPHIAY_SAW; default value set.'
    pphiay_saw =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'rmjionay', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'rmjionay', rmjionay, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: RMJIONAY; default value set.'
    rmjionay =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'rmjionay_saw', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'rmjionay_saw', rmjionay_saw, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: RMJIONAY_SAW; default value set.'
    rmjionay_saw =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'tdepay', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'tdepay', tdepay, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: TDEPAY; default value set.'
    tdepay =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'tfluxay', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'tfluxay', tfluxay, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: TFLUXAY; default value set.'
    tfluxay =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'tfluxay_saw', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'tfluxay_saw', tfluxay_saw, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: TFLUXAY_SAW; default value set.'
    tfluxay_saw =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'thay', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'thay', thay, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: THAY; default value set.'
    thay =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'thay_saw', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'thay_saw', thay_saw, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: THAY_SAW; default value set.'
    thay_saw =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'vay', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'vay', vay, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: VAY; default value set.'
    vay =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'vay_saw', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'vay_saw', vay_saw, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: VAY_SAW; default value set.'
    vay_saw =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'wghtay', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'wghtay', wghtay, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: WGHTAY; default value set.'
    wghtay =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xiay', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'xiay', xiay, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XIAY; default value set.'
    xiay =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xiay_saw', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'xiay_saw', xiay_saw, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XIAY_SAW; default value set.'
    xiay_saw =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xistay', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'xistay', xistay, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XISTAY; default value set.'
    xistay =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xistay_saw', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'xistay_saw', xistay_saw, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XISTAY_SAW; default value set.'
    xistay_saw =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xksidy', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'xksidy', xksidy, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XKSIDY; default value set.'
    xksidy =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xksidy_saw', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'xksidy_saw', xksidy_saw, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XKSIDY_SAW; default value set.'
    xksidy_saw =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xmuay', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'xmuay', xmuay, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XMUAY; default value set.'
    xmuay =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xmuay_saw', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'xmuay_saw', xmuay_saw, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XMUAY_SAW; default value set.'
    xmuay_saw =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xzbmay', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'xzbmay', xzbmay, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XZBMAY; default value set.'
    xzbmay =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xzionay', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'xzionay', xzionay, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XZIONAY; default value set.'
    xzionay =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xzionay_saw', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'xzionay_saw', xzionay_saw, minb, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XZIONAY_SAW; default value set.'
    xzionay_saw =  zero
  endif
 
end subroutine nbi_state_read2_ptcl
 
 
subroutine nbi_state_define2(icdf)
 
  use nbi_com
  use ezcdf
 
  implicit NONE
 
  integer, intent(in) :: icdf  ! NetCDF file id
 
  integer :: idm(3),i1,i2,i3,i4
  character*4 zvartype
  integer, dimension(:), allocatable :: intarr
 
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'debug_mpi', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nbsteps', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nsigexc_use', idm, 'INT')
  idm = (/ mimxbzf*3*mib*mibs, 0, 0 /)
  call cdfDefVar(icdf, 'ebb_rel_co', idm, 'R8')
  idm = (/ mimxbzf*3*mib*mibs, 0, 0 /)
  call cdfDefVar(icdf, 'ebb_rel2_co', idm, 'R8')
  idm = (/ mimxbzf*3*mib*mibs, 0, 0 /)
  call cdfDefVar(icdf, 'rms_ebb_co', idm, 'R8')
  idm = (/ mj*3*mib*mibs, 0, 0 /)
  call cdfDefVar(icdf, 'ebb_relx_co', idm, 'R8')
  idm = (/ mj*3*mib*mibs, 0, 0 /)
  call cdfDefVar(icdf, 'rms_ebbx_co', idm, 'R8')
  idm = (/ mimxbzf*3*mib*mibs, 0, 0 /)
  call cdfDefVar(icdf, 'ebb_rel_cnt', idm, 'R8')
  idm = (/ mimxbzf*3*mib*mibs, 0, 0 /)
  call cdfDefVar(icdf, 'ebb_rel2_cnt', idm, 'R8')
  idm = (/ mimxbzf*3*mib*mibs, 0, 0 /)
  call cdfDefVar(icdf, 'rms_ebb_cnt', idm, 'R8')
  idm = (/ mj*3*mib*mibs, 0, 0 /)
  call cdfDefVar(icdf, 'ebb_relx_cnt', idm, 'R8')
  idm = (/ mj*3*mib*mibs, 0, 0 /)
  call cdfDefVar(icdf, 'rms_ebbx_cnt', idm, 'R8')
  idm = (/ mimxbzf, 2, mibs /)
  call cdfDefVar(icdf, 'bnb_ien2', idm, 'R8')
  idm = (/ mj, 2, mibs /)
  call cdfDefVar(icdf, 'bnb_ienx', idm, 'R8')
  idm = (/ mimxbzf*3*mib*mibs, 0, 0 /)
  call cdfDefVar(icdf, 'ebb_rel_fn', idm, 'R8')
  idm = (/ mimxbzf*3*mib*mibs, 0, 0 /)
  call cdfDefVar(icdf, 'ebb_rel2_fn', idm, 'R8')
  idm = (/ mimxbzf*3*mib*mibs, 0, 0 /)
  call cdfDefVar(icdf, 'rms_ebb_fn', idm, 'R8')
  idm = (/ mj*3*mib*mibs, 0, 0 /)
  call cdfDefVar(icdf, 'ebb_relx_fn', idm, 'R8')
  idm = (/ mj*3*mib*mibs, 0, 0 /)
  call cdfDefVar(icdf, 'rms_ebbx_fn', idm, 'R8')
  idm = (/ mimxbzf, mibs, 0 /)
  call cdfDefVar(icdf, 'bnb_fn', idm, 'R8')
  idm = (/ mj, mibs, 0 /)
  call cdfDefVar(icdf, 'bnb_fnx', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'flag_dt_reset', idm, 'INT')
  idm = (/ 3, mib, 0 /)
  call cdfDefVar(icdf, 'frac_survive', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'ndepmod', idm, 'INT')
  idm = (/ mimxbz, mireact, 0 /)
  call cdfDefVar(icdf, 'bbnvol', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'bdns2p', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'be0cx2', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'be20cx2', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'be0x2p', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'bn0cx2', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'bn0x2p', idm, 'R8')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'bntots', idm, 'R8')
  idm = (/ mimxbz, mireact, 0 /)
  call cdfDefVar(icdf, 'btntn2', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'bv0cx2', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'bv0x2p', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'bvrhocx2', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'bvrhox2p', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'bvthcx2', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'bvthx2p', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'bvpllcx2', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'bvpllx2p', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'balpha_gyro', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'balpha_gyrop', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'delt', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'tbm2p', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'dvbox', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'eb2plp', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'eb2ppp', idm, 'R8')
  idm = (/ mimxbe,  mibs, 0 /)
  call cdfDefVar(icdf, 'efbm', idm, 'R8')
  idm = (/ mimxbe1,  mibs, 0 /)
  call cdfDefVar(icdf, 'efbmb', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'einj', idm, 'R8')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'einjs', idm, 'R8')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'vmins', idm, 'R8')
  idm = (/ mj,  miz, 0 /)
  call cdfDefVar(icdf, 'fbz', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'dt_adj0', idm, 'R8')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'dt_adj0s', idm, 'R8')
  idm = (/ mimxbz, mibs, mibs /)
  call cdfDefVar(icdf, 'hexbbxrp', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'init_xplasma', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'write_xplasma', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'lrunid', idm, 'INT')
  idm = (/ miboxm, 0, 0 /)
  call cdfDefVar(icdf, 'nadrbox', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nbi_init_flag', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'need_read_ptcl', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'sawflag2', idm, 'INT')
  idm = (/ 10, 0, 0 /)
  call cdfDefVar(icdf, 'nbouta', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nbs', idm, 'INT')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'nlfprod', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nout', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nreact', idm, 'INT')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'puseyp', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nwrite_global', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nznbmr', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nznbmri', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nthzsm0', idm, 'INT')
  idm = (/ mib, 0, 0 /)
  call cdfDefVar(icdf, 'phibsce', idm, 'R8')
  idm = (/ mib*3*mimxbzf*mibs, 0, 0 /)
  call cdfDefVar(icdf, 'sn00i2', idm, 'R8')
  idm = (/ mib*3*mimxbzf*mibs, 0, 0 /)
  call cdfDefVar(icdf, 'sn00x2', idm, 'R8')
  idm = (/ mimxbz, mig, mibs /)
  call cdfDefVar(icdf, 'snb0i2', idm, 'R8')
  idm = (/ mimxbz, mig, mibs /)
  call cdfDefVar(icdf, 'snbn02', idm, 'R8')
  if(levmod_halo.eq.2) then
     idm = (/ mimxbe0*mimxba0*mgyro*mimxbzf*mibs, 0, 0 /)
     call cdfDefVar(icdf, 'svn3vii_h', idm, 'R8')
  endif
  if(levmod_halo.eq.2) then
     idm = (/ mimxbe0*mimxba0*mgyro*mimxbzf*mibs, 0, 0 /)
     call cdfDefVar(icdf, 'svn3vii_he', idm, 'R8')
  endif
  if(levmod_halo.eq.2) then
     idm = (/ mimxbe0*mimxba0*mgyro*mimxbzf*mibs, 0, 0 /)
     call cdfDefVar(icdf, 'svn3vcx_h', idm, 'R8')
  endif
  if(levmod_halo.eq.2) then
     idm = (/ mimxbe0*mimxba0*mgyro*mimxbzf*mibs, 0, 0 /)
     call cdfDefVar(icdf, 'svn3vcx_he', idm, 'R8')
  endif
  idm = (/ mimxbz, mig, mibs /)
  call cdfDefVar(icdf, 'srbn02', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'tfluxp', idm, 'R8')
  idm = (/ mimxbz,  mibs, 0 /)
  call cdfDefVar(icdf, 'vbtr2p', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xibado', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'xiliml', idm, 'R8')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'ebcons', idm, 'R8')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'xwght0', idm, 'R8')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'wnlight', idm, 'R8')
  idm = (/ mj, mibs, 0 /)
  call cdfDefVar(icdf, 'wbav', idm, 'R8')
  idm = (/ mj, mibs, 0 /)
  call cdfDefVar(icdf, 'wbav_kill', idm, 'R8')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'tausl_avg', idm, 'R8')
  idm = (/ mituben, mitubem, 0 /)
  call cdfDefVar(icdf, 'tuben0', idm, 'R8')
  idm = (/ mituben, mitubem, 0 /)
  call cdfDefVar(icdf, 'tubedot', idm, 'R8')
  idm = (/ mitubem, 0, 0 /)
  call cdfDefVar(icdf, 'tubes0', idm, 'R8')
 
end subroutine nbi_state_define2
 
 
subroutine nbi_state_output2(icdf)
 
  use nbi_com
  use ezcdf
 
  implicit NONE
 
  integer, intent(in) :: icdf  ! NetCDF file id
 
  integer :: idm(3),i1,i2,i3,i4
  character*4 zvartype
  integer, dimension(:), allocatable :: intarr
 
  call cdfPutVar(icdf, 'debug_mpi', log2int(debug_mpi))
  call cdfPutVar(icdf, 'nbsteps', nbsteps)
  call cdfPutVar(icdf, 'nsigexc_use', nsigexc_use)
  call nbi_cdf4s(icdf, 'W', 'ebb_rel_co', ebb_rel_co, mimxbzf*3*mib*mibs, 'R8')
  call nbi_cdf4s(icdf, 'W', 'ebb_rel2_co', ebb_rel2_co, mimxbzf*3*mib*mibs, 'R8')
  call nbi_cdf4s(icdf, 'W', 'rms_ebb_co', rms_ebb_co, mimxbzf*3*mib*mibs, 'R8')
  call nbi_cdf4s(icdf, 'W', 'ebb_relx_co', ebb_relx_co, mj*3*mib*mibs, 'R8')
  call nbi_cdf4s(icdf, 'W', 'rms_ebbx_co', rms_ebbx_co, mj*3*mib*mibs, 'R8')
  call nbi_cdf4s(icdf, 'W', 'ebb_rel_cnt', ebb_rel_cnt, mimxbzf*3*mib*mibs, 'R8')
  call nbi_cdf4s(icdf, 'W', 'ebb_rel2_cnt', ebb_rel2_cnt, mimxbzf*3*mib*mibs, 'R8')
  call nbi_cdf4s(icdf, 'W', 'rms_ebb_cnt', rms_ebb_cnt, mimxbzf*3*mib*mibs, 'R8')
  call nbi_cdf4s(icdf, 'W', 'ebb_relx_cnt', ebb_relx_cnt, mj*3*mib*mibs, 'R8')
  call nbi_cdf4s(icdf, 'W', 'rms_ebbx_cnt', rms_ebbx_cnt, mj*3*mib*mibs, 'R8')
  call cdfPutVar(icdf, 'bnb_ien2', bnb_ien2)
  call cdfPutVar(icdf, 'bnb_ienx', bnb_ienx)
  call nbi_cdf4s(icdf, 'W', 'ebb_rel_fn', ebb_rel_fn, mimxbzf*3*mib*mibs, 'R8')
  call nbi_cdf4s(icdf, 'W', 'ebb_rel2_fn', ebb_rel2_fn, mimxbzf*3*mib*mibs, 'R8')
  call nbi_cdf4s(icdf, 'W', 'rms_ebb_fn', rms_ebb_fn, mimxbzf*3*mib*mibs, 'R8')
  call nbi_cdf4s(icdf, 'W', 'ebb_relx_fn', ebb_relx_fn, mj*3*mib*mibs, 'R8')
  call nbi_cdf4s(icdf, 'W', 'rms_ebbx_fn', rms_ebbx_fn, mj*3*mib*mibs, 'R8')
  call cdfPutVar(icdf, 'bnb_fn', bnb_fn)
  call cdfPutVar(icdf, 'bnb_fnx', bnb_fnx)
  call cdfPutVar(icdf, 'flag_dt_reset', log2int(flag_dt_reset))
  call cdfPutVar(icdf, 'frac_survive', frac_survive)
  call cdfPutVar(icdf, 'ndepmod', ndepmod)
  call cdfPutVar(icdf, 'bbnvol', bbnvol)
  call cdfPutVar(icdf, 'bdns2p', bdns2p)
  call cdfPutVar(icdf, 'be0cx2', be0cx2)
  call cdfPutVar(icdf, 'be20cx2', be20cx2)
  call cdfPutVar(icdf, 'be0x2p', be0x2p)
  call cdfPutVar(icdf, 'bn0cx2', bn0cx2)
  call cdfPutVar(icdf, 'bn0x2p', bn0x2p)
  call cdfPutVar(icdf, 'bntots', bntots)
  call cdfPutVar(icdf, 'btntn2', btntn2)
  call cdfPutVar(icdf, 'bv0cx2', bv0cx2)
  call cdfPutVar(icdf, 'bv0x2p', bv0x2p)
  call cdfPutVar(icdf, 'bvrhocx2', bvrhocx2)
  call cdfPutVar(icdf, 'bvrhox2p', bvrhox2p)
  call cdfPutVar(icdf, 'bvthcx2', bvthcx2)
  call cdfPutVar(icdf, 'bvthx2p', bvthx2p)
  call cdfPutVar(icdf, 'bvpllcx2', bvpllcx2)
  call cdfPutVar(icdf, 'bvpllx2p', bvpllx2p)
  call cdfPutVar(icdf, 'balpha_gyro', balpha_gyro)
  call cdfPutVar(icdf, 'balpha_gyrop', balpha_gyrop)
  call cdfPutVar(icdf, 'delt', delt)
  call cdfPutVar(icdf, 'tbm2p', tbm2p)
  call cdfPutVar(icdf, 'dvbox', dvbox)
  call cdfPutVar(icdf, 'eb2plp', eb2plp)
  call cdfPutVar(icdf, 'eb2ppp', eb2ppp)
  call cdfPutVar(icdf, 'efbm', efbm)
  call cdfPutVar(icdf, 'efbmb', efbmb)
  call cdfPutVar(icdf, 'einj', einj)
  call cdfPutVar(icdf, 'einjs', einjs)
  call cdfPutVar(icdf, 'vmins', vmins)
  call cdfPutVar(icdf, 'fbz', fbz)
  call cdfPutVar(icdf, 'dt_adj0', dt_adj0)
  call cdfPutVar(icdf, 'dt_adj0s', dt_adj0s)
  call cdfPutVar(icdf, 'hexbbxrp', hexbbxrp)
  call cdfPutVar(icdf, 'init_xplasma', init_xplasma)
  call cdfPutVar(icdf, 'write_xplasma', write_xplasma)
  call cdfPutVar(icdf, 'lrunid', lrunid)
  call cdfPutVar(icdf, 'nadrbox', nadrbox)
  call cdfPutVar(icdf, 'nbi_init_flag', log2int(nbi_init_flag))
  call cdfPutVar(icdf, 'need_read_ptcl', log2int(need_read_ptcl))
  call cdfPutVar(icdf, 'sawflag2', log2int(sawflag2))
  call cdfPutVar(icdf, 'nbouta', nbouta)
  call cdfPutVar(icdf, 'nbs', nbs)
  allocate(intarr(mibs))
  call nbi_log2int(nlfprod, intarr, mibs)
  call cdfPutVar(icdf, 'nlfprod', intarr)
  deallocate(intarr)
  call cdfPutVar(icdf, 'nout', nout)
  call cdfPutVar(icdf, 'nreact', nreact)
  call cdfPutVar(icdf, 'puseyp', puseyp)
  call cdfPutVar(icdf, 'nwrite_global', nwrite_global)
  call cdfPutVar(icdf, 'nznbmr', nznbmr)
  call cdfPutVar(icdf, 'nznbmri', nznbmri)
  call cdfPutVar(icdf, 'nthzsm0', nthzsm0)
  call cdfPutVar(icdf, 'phibsce', phibsce)
  call nbi_cdf4s(icdf, 'W', 'sn00i2', sn00i2, mib*3*mimxbzf*mibs, 'R8')
  call nbi_cdf4s(icdf, 'W', 'sn00x2', sn00x2, mib*3*mimxbzf*mibs, 'R8')
  call cdfPutVar(icdf, 'snb0i2', snb0i2)
  call cdfPutVar(icdf, 'snbn02', snbn02)
  if(levmod_halo.eq.2) then
     call nbi_cdf4s(icdf, 'W', 'svn3vii_h', svn3vii_h, mimxbe0*mimxba0*mgyro*mimxbzf*mibs, 'R8')
  endif
  if(levmod_halo.eq.2) then
     call nbi_cdf4s(icdf, 'W', 'svn3vii_he', svn3vii_he, mimxbe0*mimxba0*mgyro*mimxbzf*mibs, 'R8')
  endif
  if(levmod_halo.eq.2) then
     call nbi_cdf4s(icdf, 'W', 'svn3vcx_h', svn3vcx_h, mimxbe0*mimxba0*mgyro*mimxbzf*mibs, 'R8')
  endif
  if(levmod_halo.eq.2) then
     call nbi_cdf4s(icdf, 'W', 'svn3vcx_he', svn3vcx_he, mimxbe0*mimxba0*mgyro*mimxbzf*mibs, 'R8')
  endif
  call cdfPutVar(icdf, 'srbn02', srbn02)
  call cdfPutVar(icdf, 'tfluxp', tfluxp)
  call cdfPutVar(icdf, 'vbtr2p', vbtr2p)
  call cdfPutVar(icdf, 'xibado', xibado)
  call cdfPutVar(icdf, 'xiliml', xiliml)
  call cdfPutVar(icdf, 'ebcons', ebcons)
  call cdfPutVar(icdf, 'xwght0', xwght0)
  call cdfPutVar(icdf, 'wnlight', wnlight)
  call cdfPutVar(icdf, 'wbav', wbav)
  call cdfPutVar(icdf, 'wbav_kill', wbav_kill)
  call cdfPutVar(icdf, 'tausl_avg', tausl_avg)
  call cdfPutVar(icdf, 'tuben0', tuben0)
  call cdfPutVar(icdf, 'tubedot', tubedot)
  call cdfPutVar(icdf, 'tubes0', tubes0)
  contains
 
    integer function log2int(ilog)
      logical, intent(in) :: ilog
      if(ilog) then
        log2int=1
      else
        log2int=0
      endif
    end function log2int
 
end subroutine nbi_state_output2
 
 
subroutine nbi_state_read2(icdf)
 
  use nbi_com
  use ezcdf
 
  implicit NONE
 
  integer, intent(in) :: icdf  ! NetCDF file id
 
  integer :: idm(3),i1,i2,i3,i4
  character*4 zvartype
  integer, dimension(:), allocatable :: intarr
 
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'debug_mpi', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'debug_mpi', i1); debug_mpi = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: DEBUG_MPI; default value set.'
#ifdef __MPI
    debug_mpi =  nltest_output
#else
    debug_mpi =  .FALSE.
#endif
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbsteps', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbsteps', nbsteps)
  else
    write(nonlin,*) ' %variable not in state file: NBSTEPS; default value set.'
    nbsteps =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nsigexc_use', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nsigexc_use', nsigexc_use)
  else
    write(nonlin,*) ' %variable not in state file: NSIGEXC_USE; default value set.'
    nsigexc_use =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ebb_rel_co', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'ebb_rel_co', ebb_rel_co, mimxbzf*3*mib*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EBB_REL_CO; default value set.'
    ebb_rel_co =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ebb_rel2_co', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'ebb_rel2_co', ebb_rel2_co, mimxbzf*3*mib*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EBB_REL2_CO; default value set.'
    ebb_rel2_co =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'rms_ebb_co', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'rms_ebb_co', rms_ebb_co, mimxbzf*3*mib*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: RMS_EBB_CO; default value set.'
    rms_ebb_co =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ebb_relx_co', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'ebb_relx_co', ebb_relx_co, mj*3*mib*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EBB_RELX_CO; default value set.'
    ebb_relx_co =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'rms_ebbx_co', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'rms_ebbx_co', rms_ebbx_co, mj*3*mib*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: RMS_EBBX_CO; default value set.'
    rms_ebbx_co =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ebb_rel_cnt', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'ebb_rel_cnt', ebb_rel_cnt, mimxbzf*3*mib*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EBB_REL_CNT; default value set.'
    ebb_rel_cnt =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ebb_rel2_cnt', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'ebb_rel2_cnt', ebb_rel2_cnt, mimxbzf*3*mib*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EBB_REL2_CNT; default value set.'
    ebb_rel2_cnt =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'rms_ebb_cnt', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'rms_ebb_cnt', rms_ebb_cnt, mimxbzf*3*mib*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: RMS_EBB_CNT; default value set.'
    rms_ebb_cnt =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ebb_relx_cnt', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'ebb_relx_cnt', ebb_relx_cnt, mj*3*mib*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EBB_RELX_CNT; default value set.'
    ebb_relx_cnt =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'rms_ebbx_cnt', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'rms_ebbx_cnt', rms_ebbx_cnt, mj*3*mib*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: RMS_EBBX_CNT; default value set.'
    rms_ebbx_cnt =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bnb_ien2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_3(icdf, 'bnb_ien2', bnb_ien2, mimxbzf,2,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BNB_IEN2; default value set.'
    bnb_ien2 =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bnb_ienx', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_3(icdf, 'bnb_ienx', bnb_ienx, mj,2,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BNB_IENX; default value set.'
    bnb_ienx =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ebb_rel_fn', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'ebb_rel_fn', ebb_rel_fn, mimxbzf*3*mib*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EBB_REL_FN; default value set.'
    ebb_rel_fn =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ebb_rel2_fn', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'ebb_rel2_fn', ebb_rel2_fn, mimxbzf*3*mib*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EBB_REL2_FN; default value set.'
    ebb_rel2_fn =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'rms_ebb_fn', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'rms_ebb_fn', rms_ebb_fn, mimxbzf*3*mib*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: RMS_EBB_FN; default value set.'
    rms_ebb_fn =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ebb_relx_fn', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'ebb_relx_fn', ebb_relx_fn, mj*3*mib*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EBB_RELX_FN; default value set.'
    ebb_relx_fn =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'rms_ebbx_fn', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'rms_ebbx_fn', rms_ebbx_fn, mj*3*mib*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: RMS_EBBX_FN; default value set.'
    rms_ebbx_fn =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bnb_fn', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'bnb_fn', bnb_fn, mimxbzf,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BNB_FN; default value set.'
    bnb_fn =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bnb_fnx', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'bnb_fnx', bnb_fnx, mj,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BNB_FNX; default value set.'
    bnb_fnx =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'flag_dt_reset', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'flag_dt_reset', i1); flag_dt_reset = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: FLAG_DT_RESET; default value set.'
    flag_dt_reset =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'frac_survive', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'frac_survive', frac_survive, 3,mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FRAC_SURVIVE; default value set.'
    frac_survive =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ndepmod', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'ndepmod', ndepmod)
  else
    write(nonlin,*) ' %variable not in state file: NDEPMOD; default value set.'
    ndepmod =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bbnvol', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'bbnvol', bbnvol, mimxbz,mireact, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BBNVOL; default value set.'
    bbnvol =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bdns2p', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'bdns2p', bdns2p, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BDNS2P; default value set.'
    bdns2p =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'be0cx2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'be0cx2', be0cx2, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BE0CX2; default value set.'
    be0cx2 =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'be20cx2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'be20cx2', be20cx2, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BE20CX2; default value set.'
    be20cx2 =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'be0x2p', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'be0x2p', be0x2p, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BE0X2P; default value set.'
    be0x2p =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bn0cx2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'bn0cx2', bn0cx2, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BN0CX2; default value set.'
    bn0cx2 =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bn0x2p', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'bn0x2p', bn0x2p, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BN0X2P; default value set.'
    bn0x2p =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bntots', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'bntots', bntots, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BNTOTS; default value set.'
    bntots =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'btntn2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'btntn2', btntn2, mimxbz,mireact, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BTNTN2; default value set.'
    btntn2 =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bv0cx2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'bv0cx2', bv0cx2, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BV0CX2; default value set.'
    bv0cx2 =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bv0x2p', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'bv0x2p', bv0x2p, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BV0X2P; default value set.'
    bv0x2p =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bvrhocx2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'bvrhocx2', bvrhocx2, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BVRHOCX2; default value set.'
    bvrhocx2 =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bvrhox2p', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'bvrhox2p', bvrhox2p, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BVRHOX2P; default value set.'
    bvrhox2p =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bvthcx2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'bvthcx2', bvthcx2, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BVTHCX2; default value set.'
    bvthcx2 =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bvthx2p', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'bvthx2p', bvthx2p, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BVTHX2P; default value set.'
    bvthx2p =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bvpllcx2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'bvpllcx2', bvpllcx2, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BVPLLCX2; default value set.'
    bvpllcx2 =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bvpllx2p', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'bvpllx2p', bvpllx2p, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BVPLLX2P; default value set.'
    bvpllx2p =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'balpha_gyro', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'balpha_gyro', balpha_gyro, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BALPHA_GYRO; default value set.'
    balpha_gyro =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'balpha_gyrop', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'balpha_gyrop', balpha_gyrop, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BALPHA_GYROP; default value set.'
    balpha_gyrop =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'delt', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'delt', delt, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: DELT; default value set.'
    delt =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'tbm2p', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'tbm2p', tbm2p, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: TBM2P; default value set.'
    tbm2p =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'dvbox', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'dvbox', dvbox, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: DVBOX; default value set.'
    dvbox =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'eb2plp', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'eb2plp', eb2plp, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EB2PLP; default value set.'
    eb2plp =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'eb2ppp', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'eb2ppp', eb2ppp, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EB2PPP; default value set.'
    eb2ppp =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'efbm', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'efbm', efbm, mimxbe, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EFBM; default value set.'
    efbm =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'efbmb', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'efbmb', efbmb, mimxbe1, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EFBMB; default value set.'
    efbmb =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'einj', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'einj', einj, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EINJ; default value set.'
    einj =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'einjs', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'einjs', einjs, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EINJS; default value set.'
    einjs =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'vmins', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'vmins', vmins, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: VMINS; default value set.'
    vmins =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'fbz', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'fbz', fbz, mj, miz, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: FBZ; default value set.'
    fbz =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'dt_adj0', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'dt_adj0', dt_adj0, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: DT_ADJ0; default value set.'
    dt_adj0 =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'dt_adj0s', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'dt_adj0s', dt_adj0s, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: DT_ADJ0S; default value set.'
    dt_adj0s =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'hexbbxrp', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_3(icdf, 'hexbbxrp', hexbbxrp, mimxbz,mibs,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: HEXBBXRP; default value set.'
    hexbbxrp =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'init_xplasma', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'init_xplasma', init_xplasma)
  else
    write(nonlin,*) ' %variable not in state file: INIT_XPLASMA; default value set.'
    init_xplasma =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'write_xplasma', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'write_xplasma', write_xplasma)
  else
    write(nonlin,*) ' %variable not in state file: WRITE_XPLASMA; default value set.'
    write_xplasma =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'lrunid', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'lrunid', lrunid)
  else
    write(nonlin,*) ' %variable not in state file: LRUNID; default value set.'
    lrunid =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nadrbox', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nadrbox', nadrbox)
  else
    write(nonlin,*) ' %variable not in state file: NADRBOX; default value set.'
    nadrbox =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbi_init_flag', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbi_init_flag', i1); nbi_init_flag = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NBI_INIT_FLAG; default value set.'
    nbi_init_flag =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'need_read_ptcl', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'need_read_ptcl', i1); need_read_ptcl = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: NEED_READ_PTCL; default value set.'
    need_read_ptcl =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'sawflag2', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'sawflag2', i1); sawflag2 = int2log(i1)
  else
    write(nonlin,*) ' %variable not in state file: SAWFLAG2; default value set.'
    sawflag2 =  .FALSE.
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbouta', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbouta', nbouta)
  else
    write(nonlin,*) ' %variable not in state file: NBOUTA; default value set.'
    nbouta =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbs', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbs', nbs)
  else
    write(nonlin,*) ' %variable not in state file: NBS; default value set.'
    nbs =  0
  endif
  allocate(intarr(mibs)); intarr=0
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nlfprod', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nlfprod', intarr)
  else
    write(nonlin,*) ' %variable not in state file: NLFPROD; default value set.'
    nlfprod =  .FALSE.
  endif
  call nbi_int2log(intarr, nlfprod, mibs)
  deallocate(intarr)
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nout', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nout', nout)
  else
    write(nonlin,*) ' %variable not in state file: NOUT; default value set.'
    nout =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nreact', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nreact', nreact)
  else
    write(nonlin,*) ' %variable not in state file: NREACT; default value set.'
    nreact =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'puseyp', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'puseyp', puseyp, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: PUSEYP; default value set.'
    puseyp =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nwrite_global', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nwrite_global', nwrite_global)
  else
    write(nonlin,*) ' %variable not in state file: NWRITE_GLOBAL; default value set.'
    nwrite_global =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nznbmr', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nznbmr', nznbmr)
  else
    write(nonlin,*) ' %variable not in state file: NZNBMR; default value set.'
    nznbmr =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nznbmri', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nznbmri', nznbmri)
  else
    write(nonlin,*) ' %variable not in state file: NZNBMRI; default value set.'
    nznbmri =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nthzsm0', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nthzsm0', nthzsm0)
  else
    write(nonlin,*) ' %variable not in state file: NTHZSM0; default value set.'
    nthzsm0 =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'phibsce', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'phibsce', phibsce, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: PHIBSCE; default value set.'
    phibsce =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'sn00i2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'sn00i2', sn00i2, mib*3*mimxbzf*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: SN00I2; default value set.'
    sn00i2 =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'sn00x2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'sn00x2', sn00x2, mib*3*mimxbzf*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: SN00X2; default value set.'
    sn00x2 =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'snb0i2', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_3(icdf, 'snb0i2', snb0i2, mimxbz,mig,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: SNB0I2; default value set.'
    snb0i2 =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'snbn02', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_3(icdf, 'snbn02', snbn02, mimxbz,mig,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: SNBN02; default value set.'
    snbn02 =  zero
  endif
  idm = (/ -1, -1, -1 /)
  if(levmod_halo.eq.2) then
    call cdfInqVar(icdf, 'svn3vii_h', idm, zvartype)
  endif
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'svn3vii_h', svn3vii_h, mimxbe0*mimxba0*mgyro*mimxbzf*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: SVN3VII_H; ignore.'
    write(nonlin,*) ' % or levmod_halo.ne.2' 
  endif
  idm = (/ -1, -1, -1 /)
  if(levmod_halo.eq.2) then
    call cdfInqVar(icdf, 'svn3vii_he', idm, zvartype)
  endif
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'svn3vii_he', svn3vii_he, mimxbe0*mimxba0*mgyro*mimxbzf*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: SVN3VII_HE; ignore.'
    write(nonlin,*) ' % or levmod_halo.ne.2' 
  endif
  idm = (/ -1, -1, -1 /)
  if(levmod_halo.eq.2) then
    call cdfInqVar(icdf, 'svn3vcx_h', idm, zvartype)
  endif
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'svn3vcx_h', svn3vcx_h, mimxbe0*mimxba0*mgyro*mimxbzf*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: SVN3VCX_H; ignore.'
    write(nonlin,*) ' % or levmod_halo.ne.2' 
  endif
  idm = (/ -1, -1, -1 /)
  if(levmod_halo.eq.2) then
    call cdfInqVar(icdf, 'svn3vcx_he', idm, zvartype)
  endif
  if(idm(1).ne.-1) then
    call nbi_cdf4s(icdf, 'R', 'svn3vcx_he', svn3vcx_he, mimxbe0*mimxba0*mgyro*mimxbzf*mibs, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: SVN3VCX_HE; ignore.'
    write(nonlin,*) ' % or levmod_halo.ne.2' 
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'srbn02', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_3(icdf, 'srbn02', srbn02, mimxbz,mig,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: SRBN02; default value set.'
    srbn02 =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'tfluxp', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'tfluxp', tfluxp, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: TFLUXP; default value set.'
    tfluxp =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'vbtr2p', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'vbtr2p', vbtr2p, mimxbz, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: VBTR2P; default value set.'
    vbtr2p =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xibado', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xibado', xibado, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XIBADO; default value set.'
    xibado =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xiliml', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_0(icdf, 'xiliml', xiliml, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XILIML; default value set.'
    xiliml =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ebcons', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'ebcons', ebcons, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EBCONS; default value set.'
    ebcons =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xwght0', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'xwght0', xwght0, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XWGHT0; default value set.'
    xwght0 =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'wnlight', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'wnlight', wnlight, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: WNLIGHT; default value set.'
    wnlight =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'wbav', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'wbav', wbav, mj,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: WBAV; default value set.'
    wbav =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'wbav_kill', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'wbav_kill', wbav_kill, mj,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: WBAV_KILL; default value set.'
    wbav_kill =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'tausl_avg', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'tausl_avg', tausl_avg, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: TAUSL_AVG; default value set.'
    tausl_avg =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'tuben0', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'tuben0', tuben0, mituben,mitubem, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: TUBEN0; default value set.'
    tuben0 =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'tubedot', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'tubedot', tubedot, mituben,mitubem, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: TUBEDOT; default value set.'
    tubedot =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'tubes0', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'tubes0', tubes0, mitubem, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: TUBES0; default value set.'
    tubes0 =  zero
  endif
  contains
 
    logical function int2log(iint)
      integer, intent(in) :: iint
      if(iint.eq.1) then
        int2log=.TRUE.
      else
        int2log=.FALSE.
      endif
    end function int2log
 
end subroutine nbi_state_read2
 
 
subroutine nbi_state_define3(icdf)
 
  use nbi_com
  use ezcdf
 
  implicit NONE
 
  integer, intent(in) :: icdf  ! NetCDF file id
 
  integer :: idm(3),i1,i2,i3,i4
  character*4 zvartype
  integer, dimension(:), allocatable :: intarr
 
  idm = (/ mj, mibs, 0 /)
  call cdfDefVar(icdf, 'bdenss', idm, 'R8')
  idm = (/ mj, mibs, 0 /)
  call cdfDefVar(icdf, 'mc_dens', idm, 'R8')
  idm = (/ mj, mibs, 0 /)
  call cdfDefVar(icdf, 'bdenssw', idm, 'R8')
  idm = (/ mj, mibs, 0 /)
  call cdfDefVar(icdf, 'udensplw', idm, 'R8')
  idm = (/ mj, mibs, 0 /)
  call cdfDefVar(icdf, 'udensppw', idm, 'R8')
  idm = (/ mj, mibs, 0 /)
  call cdfDefVar(icdf, 'mc_newdens', idm, 'R8')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'einjav', idm, 'R8')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'nbs_step', idm, 'INT')
  idm = (/ 0, 0, 0 /)
  call cdfDefVar(icdf, 'n_outtim', idm, 'INT')
  idm = (/ mj,  3,  mib /)
  call cdfDefVar(icdf, 'bnb_ien', idm, 'R8')
  idm = (/ mj,  mibs, 0 /)
  call cdfDefVar(icdf, 'bn0cx', idm, 'R8')
  idm = (/ mj, mibs, 0 /)
  call cdfDefVar(icdf, 'ebavps', idm, 'R8')
  idm = (/ mj, mibs, 0 /)
  call cdfDefVar(icdf, 'nmc', idm, 'R8')
  idm = (/ mj, mibs, 0 /)
  call cdfDefVar(icdf, 'wnmc', idm, 'R8')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'nmctot', idm, 'INT')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'wnmctot', idm, 'R8')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'naeptot', idm, 'INT')
  idm = (/ mnkaep, mibs, 0 /)
  call cdfDefVar(icdf, 'nstep_aep', idm, 'INT')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'nnew', idm, 'INT')
  idm = (/ mj, mibs, 0 /)
  call cdfDefVar(icdf, 'omegabsw', idm, 'R8')
  idm = (/ mj, mig, mibs /)
  call cdfDefVar(icdf, 'sorbn0s', idm, 'R8')
  idm = (/ mj, mig, mibs /)
  call cdfDefVar(icdf, 'sorbn0s_dep', idm, 'R8')
  idm = (/ mj, mibs, 0 /)
  call cdfDefVar(icdf, 'xzbmav', idm, 'R8')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'pinjs_res', idm, 'R8')
  idm = (/ mibs, 0, 0 /)
  call cdfDefVar(icdf, 'bphcons', idm, 'R8')
 
end subroutine nbi_state_define3
 
 
subroutine nbi_state_output3(icdf)
 
  use nbi_com
  use ezcdf
 
  implicit NONE
 
  integer, intent(in) :: icdf  ! NetCDF file id
 
  integer :: idm(3),i1,i2,i3,i4
  character*4 zvartype
  integer, dimension(:), allocatable :: intarr
 
  call cdfPutVar(icdf, 'bdenss', bdenss)
  call cdfPutVar(icdf, 'mc_dens', mc_dens)
  call cdfPutVar(icdf, 'bdenssw', bdenssw)
  call cdfPutVar(icdf, 'udensplw', udensplw)
  call cdfPutVar(icdf, 'udensppw', udensppw)
  call cdfPutVar(icdf, 'mc_newdens', mc_newdens)
  call cdfPutVar(icdf, 'einjav', einjav)
  call cdfPutVar(icdf, 'nbs_step', nbs_step)
  call cdfPutVar(icdf, 'n_outtim', n_outtim)
  call cdfPutVar(icdf, 'bnb_ien', bnb_ien)
  call cdfPutVar(icdf, 'bn0cx', bn0cx)
  call cdfPutVar(icdf, 'ebavps', ebavps)
  call cdfPutVar(icdf, 'nmc', nmc)
  call cdfPutVar(icdf, 'wnmc', wnmc)
  call cdfPutVar(icdf, 'nmctot', nmctot)
  call cdfPutVar(icdf, 'wnmctot', wnmctot)
  call cdfPutVar(icdf, 'naeptot', naeptot)
  call cdfPutVar(icdf, 'nstep_aep', nstep_aep)
  call cdfPutVar(icdf, 'nnew', nnew)
  call cdfPutVar(icdf, 'omegabsw', omegabsw)
  call cdfPutVar(icdf, 'sorbn0s', sorbn0s)
  call cdfPutVar(icdf, 'sorbn0s_dep', sorbn0s_dep)
  call cdfPutVar(icdf, 'xzbmav', xzbmav)
  call cdfPutVar(icdf, 'pinjs_res', pinjs_res)
  call cdfPutVar(icdf, 'bphcons', bphcons)
 
end subroutine nbi_state_output3
 
 
subroutine nbi_state_read3(icdf)
 
  use nbi_com
  use ezcdf
 
  implicit NONE
 
  integer, intent(in) :: icdf  ! NetCDF file id
 
  integer :: idm(3),i1,i2,i3,i4
  character*4 zvartype
  integer, dimension(:), allocatable :: intarr
 
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bdenss', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'bdenss', bdenss, mj,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BDENSS; default value set.'
    bdenss =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'mc_dens', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'mc_dens', mc_dens, mj,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: MC_DENS; default value set.'
    mc_dens =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bdenssw', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'bdenssw', bdenssw, mj,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BDENSSW; default value set.'
    bdenssw =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'udensplw', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'udensplw', udensplw, mj,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: UDENSPLW; default value set.'
    udensplw =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'udensppw', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'udensppw', udensppw, mj,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: UDENSPPW; default value set.'
    udensppw =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'mc_newdens', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'mc_newdens', mc_newdens, mj,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: MC_NEWDENS; default value set.'
    mc_newdens =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'einjav', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'einjav', einjav, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EINJAV; default value set.'
    einjav =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nbs_step', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nbs_step', nbs_step)
  else
    write(nonlin,*) ' %variable not in state file: NBS_STEP; default value set.'
    nbs_step =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'n_outtim', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'n_outtim', n_outtim)
  else
    write(nonlin,*) ' %variable not in state file: N_OUTTIM; default value set.'
    n_outtim =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bnb_ien', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_3(icdf, 'bnb_ien', bnb_ien, mj, 3, mib, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BNB_IEN; default value set.'
    bnb_ien =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bn0cx', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'bn0cx', bn0cx, mj, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BN0CX; default value set.'
    bn0cx =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'ebavps', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'ebavps', ebavps, mj,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: EBAVPS; default value set.'
    ebavps =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nmc', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'nmc', nmc, mj,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: NMC; default value set.'
    nmc =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'wnmc', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'wnmc', wnmc, mj,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: WNMC; default value set.'
    wnmc =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nmctot', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nmctot', nmctot)
  else
    write(nonlin,*) ' %variable not in state file: NMCTOT; default value set.'
    nmctot =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'wnmctot', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'wnmctot', wnmctot, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: WNMCTOT; default value set.'
    wnmctot =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'naeptot', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'naeptot', naeptot)
  else
    write(nonlin,*) ' %variable not in state file: NAEPTOT; default value set.'
    naeptot =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nstep_aep', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nstep_aep', nstep_aep)
  else
    write(nonlin,*) ' %variable not in state file: NSTEP_AEP; default value set.'
    nstep_aep =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'nnew', idm, zvartype)
  if(idm(1).ne.-1) then
    call cdfGetVar(icdf, 'nnew', nnew)
  else
    write(nonlin,*) ' %variable not in state file: NNEW; default value set.'
    nnew =  0
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'omegabsw', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'omegabsw', omegabsw, mj,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: OMEGABSW; default value set.'
    omegabsw =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'sorbn0s', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_3(icdf, 'sorbn0s', sorbn0s, mj,mig,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: SORBN0S; default value set.'
    sorbn0s =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'sorbn0s_dep', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_3(icdf, 'sorbn0s_dep', sorbn0s_dep, mj,mig,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: SORBN0S_DEP; default value set.'
    sorbn0s_dep =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'xzbmav', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_2(icdf, 'xzbmav', xzbmav, mj,mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: XZBMAV; default value set.'
    xzbmav =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'pinjs_res', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'pinjs_res', pinjs_res, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: PINJS_RES; default value set.'
    pinjs_res =  zero
  endif
  idm = (/ -1, -1, -1 /)
    call cdfInqVar(icdf, 'bphcons', idm, zvartype)
  if(idm(1).ne.-1) then
    call nbi_readCDFR8_1(icdf, 'bphcons', bphcons, mibs, idm, zvartype)
  else
    write(nonlin,*) ' %variable not in state file: BPHCONS; default value set.'
    bphcons =  zero
  endif
 
end subroutine nbi_state_read3
 
