! written by nbigen.py
! *** do not edit *** (use nbigen.py instead)
 
subroutine nbi_in_dim_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer,intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'mib',mib)
  call cdf_define(icdf,'mj',mj)
  call cdf_define(icdf,'mig',mig)
  call cdf_define(icdf,'mis',mis)
  call cdf_define(icdf,'mibs',mibs)
  call cdf_define(icdf,'mimpt',mimpt)
  call cdf_define(icdf,'mmini',mmini)
  call cdf_define(icdf,'mtheta',mtheta)
  call cdf_define(icdf,'miefi',miefi)
  call cdf_define(icdf,'med2d',med2d)
  call cdf_define(icdf,'mimxba',mimxba)
  call cdf_define(icdf,'mimxbe',mimxbe)
  call cdf_define(icdf,'mgyro',mgyro)
  call cdf_define(icdf,'mimxba0',mimxba0)
  call cdf_define(icdf,'mimxbe0',mimxbe0)
  call cdf_define(icdf,'miboxm',miboxm)
  call cdf_define(icdf,'mitubem',mitubem)
  call cdf_define(icdf,'mituben',mituben)
  call cdf_define(icdf,'mnkaep',mnkaep)
  call cdf_define(icdf,'mjeqv',mjeqv)
  call cdf_define(icdf,'mjzb',mjzb)
  call cdf_define(icdf,'mjzc',mjzc)
  call cdf_define(icdf,'mtbl',mtbl)
  call cdf_define(icdf,'mjr',mjr)
  call cdf_define(icdf,'mmaxion',mmaxion)
  call cdf_define(icdf,'miz',miz)
  call cdf_define(icdf,'minbs',minbs)
  call cdf_define(icdf,'mimaxz',mimaxz)
  call cdf_define(icdf,'mireact',mireact)
  call cdf_define(icdf,'miplot',miplot)
  call cdf_define(icdf,'mimxbe1',mimxbe1)
  call cdf_define(icdf,'nthspl',nthspl)
  call cdf_define(icdf,'nthpmin',nthpmin)
  call cdf_define(icdf,'nthpmax',nthpmax)
  call cdf_define(icdf,'minspl',minspl)
  call cdf_define(icdf,'minbplt',minbplt)
  call cdf_define(icdf,'mtrk',mtrk)
 
end subroutine nbi_in_dim_def
 
subroutine nbi_in_dim_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer,intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'mib',mib)
  call cdf_write(icdf,'mj',mj)
  call cdf_write(icdf,'mig',mig)
  call cdf_write(icdf,'mis',mis)
  call cdf_write(icdf,'mibs',mibs)
  call cdf_write(icdf,'mimpt',mimpt)
  call cdf_write(icdf,'mmini',mmini)
  call cdf_write(icdf,'mtheta',mtheta)
  call cdf_write(icdf,'miefi',miefi)
  call cdf_write(icdf,'med2d',med2d)
  call cdf_write(icdf,'mimxba',mimxba)
  call cdf_write(icdf,'mimxbe',mimxbe)
  call cdf_write(icdf,'mgyro',mgyro)
  call cdf_write(icdf,'mimxba0',mimxba0)
  call cdf_write(icdf,'mimxbe0',mimxbe0)
  call cdf_write(icdf,'miboxm',miboxm)
  call cdf_write(icdf,'mitubem',mitubem)
  call cdf_write(icdf,'mituben',mituben)
  call cdf_write(icdf,'mnkaep',mnkaep)
  call cdf_write(icdf,'mjeqv',mjeqv)
  call cdf_write(icdf,'mjzb',mjzb)
  call cdf_write(icdf,'mjzc',mjzc)
  call cdf_write(icdf,'mtbl',mtbl)
  call cdf_write(icdf,'mjr',mjr)
  call cdf_write(icdf,'mmaxion',mmaxion)
  call cdf_write(icdf,'miz',miz)
  call cdf_write(icdf,'minbs',minbs)
  call cdf_write(icdf,'mimaxz',mimaxz)
  call cdf_write(icdf,'mireact',mireact)
  call cdf_write(icdf,'miplot',miplot)
  call cdf_write(icdf,'mimxbe1',mimxbe1)
  call cdf_write(icdf,'nthspl',nthspl)
  call cdf_write(icdf,'nthpmin',nthpmin)
  call cdf_write(icdf,'nthpmax',nthpmax)
  call cdf_write(icdf,'minspl',minspl)
  call cdf_write(icdf,'minbplt',minbplt)
  call cdf_write(icdf,'mtrk',mtrk)
 
end subroutine nbi_in_dim_wr
 
subroutine nbi_in_dim_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer,intent(in) :: icdf  ! NetCDF file id
  integer,intent(out) :: ierr ! Completion code 0=OK
 
  call cdf_read(icdf,'mib',mib,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mj',mj,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mig',mig,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mis',mis,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mibs',mibs,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mimpt',mimpt,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mmini',mmini,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mtheta',mtheta,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'miefi',miefi,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'med2d',med2d,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mimxba',mimxba,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mimxbe',mimxbe,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mgyro',mgyro,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mimxba0',mimxba0,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mimxbe0',mimxbe0,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'miboxm',miboxm,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mitubem',mitubem,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mituben',mituben,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mnkaep',mnkaep,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mjeqv',mjeqv,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mjzb',mjzb,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mjzc',mjzc,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mtbl',mtbl,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mjr',mjr,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mmaxion',mmaxion,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'miz',miz,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'minbs',minbs,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mimaxz',mimaxz,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mireact',mireact,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'miplot',miplot,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mimxbe1',mimxbe1,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nthspl',nthspl,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nthpmin',nthpmin,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nthpmax',nthpmax,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'minspl',minspl,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'minbplt',minbplt,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mtrk',mtrk,ierr)
  if(ierr.ne.0) return
 
  if(.not.nbi_init_flag) call nbi_alloc_init
 
end subroutine nbi_in_dim_rd
 
subroutine nbi_inputs_write(icdf)
 
  ! write file of NUBEAM inputs.
  implicit NONE
  integer,intent(in) :: icdf  ! NetCDF file id
 
  call nbi_in_dim_def(icdf)
  call nbi_in_sys_def(icdf)
  call nbi_in_times_def(icdf)
  call nbi_in_grid_def(icdf)
  call nbi_in_beams_def(icdf)
  call nbi_in_impurity_def(icdf)
  call nbi_in_minority_def(icdf)
  call nbi_in_powers_def(icdf)
  call nbi_in_fusion_def(icdf)
  call nbi_in_fpp_def(icdf)
  call nbi_in_num_def(icdf)
  call nbi_in_atomic_def(icdf)
  call nbi_in_collid_def(icdf)
  call nbi_in_flr_def(icdf)
  call nbi_in_saw_def(icdf)
  call nbi_in_adif_def(icdf)
  call nbi_in_ripple_def(icdf)
  call nbi_in_outcon_def(icdf)
  call nbi_in_fishbone_def(icdf)
  call nbi_in_box_def(icdf)
  call nbi_in_tube_def(icdf)
  call nbi_in_misc_def(icdf)
  call nbi_in_profiles_def(icdf)
 
  call nbi_in_dim_wr(icdf)
  call nbi_in_sys_wr(icdf)
  call nbi_in_times_wr(icdf)
  call nbi_in_grid_wr(icdf)
  call nbi_in_beams_wr(icdf)
  call nbi_in_impurity_wr(icdf)
  call nbi_in_minority_wr(icdf)
  call nbi_in_powers_wr(icdf)
  call nbi_in_fusion_wr(icdf)
  call nbi_in_fpp_wr(icdf)
  call nbi_in_num_wr(icdf)
  call nbi_in_atomic_wr(icdf)
  call nbi_in_collid_wr(icdf)
  call nbi_in_flr_wr(icdf)
  call nbi_in_saw_wr(icdf)
  call nbi_in_adif_wr(icdf)
  call nbi_in_ripple_wr(icdf)
  call nbi_in_outcon_wr(icdf)
  call nbi_in_fishbone_wr(icdf)
  call nbi_in_box_wr(icdf)
  call nbi_in_tube_wr(icdf)
  call nbi_in_misc_wr(icdf)
  call nbi_in_profiles_wr(icdf)
 
end subroutine nbi_inputs_write
 
subroutine nbi_inputs_read(icdf,ierr)
 
  ! read file of NUBEAM inputs.
  implicit NONE
  integer,intent(in) :: icdf  ! NetCDF file id
  integer,intent(out) :: ierr ! completion code, 0=OK
 
  call nbi_in_dim_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_sys_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_times_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_grid_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_beams_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_impurity_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_minority_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_powers_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_fusion_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_fpp_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_num_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_atomic_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_collid_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_flr_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_saw_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_adif_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_ripple_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_outcon_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_fishbone_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_box_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_tube_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_misc_rd(icdf,ierr)
  if(ierr.ne.0) return
  call nbi_in_profiles_rd(icdf,ierr)
  if(ierr.ne.0) return
 
end subroutine nbi_inputs_read
 
subroutine nbi_in_sys_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'runid',runid)
  call cdf_define(icdf,'mission',mission)
  call cdf_define(icdf,'workpath',workpath)
  call cdf_define(icdf,'nonlin',nonlin)
  call cdf_define(icdf,'nseed',nseed)
  call cdf_define(icdf,'nlbout',nlbout)
  call cdf_define(icdf,'lunnbx',lunnbx)
  call cdf_define(icdf,'lunres',lunres)
  call cdf_define(icdf,'mrstrt',mrstrt)
  call cdf_define(icdf,'nclass',nclass)
  call cdf_define(icdf,'only_io',only_io)
  call cdf_define(icdf,'ref_namelist',ref_namelist)
  call cdf_define(icdf,'quasi_check',quasi_check)
  call cdf_define(icdf,'nltest_output',nltest_output)
  call cdf_define(icdf,'BLK_MPI_BCAST_INT',BLK_MPI_BCAST_INT)
  call cdf_define(icdf,'BLK_MPI_BCAST_R8',BLK_MPI_BCAST_R8)
 
end subroutine nbi_in_sys_def
 
subroutine nbi_in_times_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'tbm1',tbm1)
  call cdf_define(icdf,'tbm2',tbm2)
 
end subroutine nbi_in_times_def
 
subroutine nbi_in_grid_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'nzones',nzones)
  call cdf_define(icdf,'nzone_fb',nzone_fb)
  call cdf_define(icdf,'nlsym2b',nlsym2b)
  call cdf_define(icdf,'nth0',nth0)
  call cdf_define(icdf,'xbmbnd',xbmbnd)
  call cdf_define(icdf,'id_mcgrid',id_mcgrid)
  call cdf_define(icdf,'nthets',nthets)
  call cdf_define(icdf,'ebdmax',ebdmax)
  call cdf_define(icdf,'xplasma_in_memory',xplasma_in_memory)
  call cdf_define(icdf,'nznbma',nznbma)
  call cdf_define(icdf,'nznbme',nznbme)
  call cdf_define(icdf,'nznbma0',nznbma0)
  call cdf_define(icdf,'nznbme0',nznbme0)
  call cdf_define(icdf,'ngyro',ngyro)
 
end subroutine nbi_in_grid_def
 
subroutine nbi_in_beams_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'ngmax',ngmax)
  call cdf_define(icdf,'backz',backz)
  call cdf_define(icdf,'aplasm',aplasm)
  call cdf_define(icdf,'nbeam',nbeam)
  call cdf_define(icdf,'xzbeama',xzbeama)
  call cdf_define(icdf,'abeama',abeama)
  call cdf_define(icdf,'nlco',nlco)
  call cdf_define(icdf,'ntrace',ntrace)
  call cdf_define(icdf,'rtcena',rtcena)
  call cdf_define(icdf,'xlbtna',xlbtna)
  call cdf_define(icdf,'xybsca',xybsca)
  call cdf_define(icdf,'xbzeta',xbzeta)
  call cdf_define(icdf,'nbshapa',nbshapa)
  call cdf_define(icdf,'bmwidra',bmwidra)
  call cdf_define(icdf,'bmwidza',bmwidza)
  call cdf_define(icdf,'divra',divra)
  call cdf_define(icdf,'divza',divza)
  call cdf_define(icdf,'foclra',foclra)
  call cdf_define(icdf,'foclza',foclza)
  call cdf_define(icdf,'nbapsha',nbapsha)
  call cdf_define(icdf,'rapedga',rapedga)
  call cdf_define(icdf,'xzpedga',xzpedga)
  call cdf_define(icdf,'xlbapa',xlbapa)
  call cdf_define(icdf,'xybapa',xybapa)
  call cdf_define(icdf,'xrapoffa',xrapoffa)
  call cdf_define(icdf,'xzapoffa',xzapoffa)
  call cdf_define(icdf,'nbapsh2',nbapsh2)
  call cdf_define(icdf,'rapedg2',rapedg2)
  call cdf_define(icdf,'xzpedg2',xzpedg2)
  call cdf_define(icdf,'xlbapa2',xlbapa2)
  call cdf_define(icdf,'xrapoff2',xrapoff2)
  call cdf_define(icdf,'xzapoff2',xzapoff2)
 
end subroutine nbi_in_beams_def
 
subroutine nbi_in_impurity_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'nrhix',nrhix)
  call cdf_define(icdf,'xzimpx',xzimpx)
  call cdf_define(icdf,'aimpx',aimpx)
 
end subroutine nbi_in_impurity_def
 
subroutine nbi_in_minority_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'nmini',nmini)
  call cdf_define(icdf,'xzmini',xzmini)
  call cdf_define(icdf,'amini',amini)
  call cdf_define(icdf,'nthrf',nthrf)
 
end subroutine nbi_in_minority_def
 
subroutine nbi_in_powers_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'einjmin',einjmin)
  call cdf_define(icdf,'einja',einja)
  call cdf_define(icdf,'pinja',pinja)
  call cdf_define(icdf,'ffulla',ffulla)
  call cdf_define(icdf,'fhalfa',fhalfa)
  call cdf_define(icdf,'orbrzv_toric_Prftot0',orbrzv_toric_Prftot0)
  call cdf_define(icdf,'orbrzv_toric_frnm',orbrzv_toric_frnm)
 
end subroutine nbi_in_powers_def
 
subroutine nbi_in_fusion_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'nlfhe3',nlfhe3)
  call cdf_define(icdf,'nlfhe4',nlfhe4)
  call cdf_define(icdf,'nlfst',nlfst)
  call cdf_define(icdf,'nlfsp',nlfsp)
  call cdf_define(icdf,'nlfsp14',nlfsp14)
  call cdf_define(icdf,'nlusf3',nlusf3)
  call cdf_define(icdf,'xdatsf3',xdatsf3)
  call cdf_define(icdf,'nlusfa',nlusfa)
  call cdf_define(icdf,'xdatsfa',xdatsfa)
  call cdf_define(icdf,'nlusft',nlusft)
  call cdf_define(icdf,'xdatsft',xdatsft)
  call cdf_define(icdf,'nlusfp',nlusfp)
  call cdf_define(icdf,'xdatsfp',xdatsfp)
  call cdf_define(icdf,'nlusfp14',nlusfp14)
  call cdf_define(icdf,'xdatsp3',xdatsp3)
  call cdf_define(icdf,'plfhe3',plfhe3)
  call cdf_define(icdf,'plfhe4',plfhe4)
  call cdf_define(icdf,'plfst',plfst)
  call cdf_define(icdf,'plfsp',plfsp)
  call cdf_define(icdf,'plfsp14',plfsp14)
  call cdf_define(icdf,'nlfatom',nlfatom)
 
end subroutine nbi_in_fusion_def
 
subroutine nbi_in_fpp_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'nlbfpp',nlbfpp)
 
end subroutine nbi_in_fpp_def
 
subroutine nbi_in_num_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'cxsplt',cxsplt)
  call cdf_define(icdf,'dxbsmoo',dxbsmoo)
  call cdf_define(icdf,'dxbsm_nc',dxbsm_nc)
  call cdf_define(icdf,'nptcls',nptcls)
  call cdf_define(icdf,'nptclf',nptclf)
  call cdf_define(icdf,'nptclh',nptclh)
  call cdf_define(icdf,'NFAST_MAP',NFAST_MAP)
  call cdf_define(icdf,'xpand_nptcl',xpand_nptcl)
  call cdf_define(icdf,'frac_depmax',frac_depmax)
  call cdf_define(icdf,'frac_dep_lim',frac_dep_lim)
  call cdf_define(icdf,'frac_depmin',frac_depmin)
  call cdf_define(icdf,'frac_orbrr',frac_orbrr)
  call cdf_define(icdf,'nptcl_max',nptcl_max)
  call cdf_define(icdf,'nltrk_dep0',nltrk_dep0)
  call cdf_define(icdf,'NLDEP0_GATHER',NLDEP0_GATHER)
  call cdf_define(icdf,'ndep0',ndep0)
  call cdf_define(icdf,'NDEP0_MAX',NDEP0_MAX)
  call cdf_define(icdf,'ndep_set_beam',ndep_set_beam)
  call cdf_define(icdf,'ndep_set_ien',ndep_set_ien)
  call cdf_define(icdf,'nbbcal',nbbcal)
  call cdf_define(icdf,'ncx0',ncx0)
  call cdf_define(icdf,'nper_cx',nper_cx)
  call cdf_define(icdf,'LEV_NBIDEP',LEV_NBIDEP)
  call cdf_define(icdf,'LEV_TTNUK',LEV_TTNUK)
  call cdf_define(icdf,'LEVMOD_HALO',LEVMOD_HALO)
  call cdf_define(icdf,'NSPLT',NSPLT)
  call cdf_define(icdf,'NSPLT_GEO',NSPLT_GEO)
  call cdf_define(icdf,'NSPLT_KIN',NSPLT_KIN)
  call cdf_define(icdf,'NSPLT_GEN',NSPLT_GEN)
  call cdf_define(icdf,'nmimp',nmimp)
  call cdf_define(icdf,'AIMP',AIMP)
  call cdf_define(icdf,'XZIMP',XZIMP)
  call cdf_define(icdf,'NTEST_MAX',NTEST_MAX)
  call cdf_define(icdf,'BI_MAX_PL',BI_MAX_PL)
  call cdf_define(icdf,'BI_MAX_PR',BI_MAX_PR)
  call cdf_define(icdf,'wghta',wghta)
  call cdf_define(icdf,'goocon',goocon)
  call cdf_define(icdf,'NGOOCON_VPVBIN',NGOOCON_VPVBIN)
  call cdf_define(icdf,'NGOOCON_EBIN',NGOOCON_EBIN)
  call cdf_define(icdf,'NGOOCON_RBIN',NGOOCON_RBIN)
  call cdf_define(icdf,'cxpcon',cxpcon)
  call cdf_define(icdf,'fppcon',fppcon)
  call cdf_define(icdf,'fdtnxy',fdtnxy)
  call cdf_define(icdf,'nchdvp',nchdvp)
  call cdf_define(icdf,'dtn',dtn)
  call cdf_define(icdf,'dt_acc',dt_acc)
  call cdf_define(icdf,'orbrzv_option',orbrzv_option)
  call cdf_define(icdf,'orbrzv_rf_option',orbrzv_rf_option)
  call cdf_define(icdf,'nlmcrf_on',nlmcrf_on)
  call cdf_define(icdf,'orbrzv_nr',orbrzv_nr)
  call cdf_define(icdf,'orbrzv_nz',orbrzv_nz)
  call cdf_define(icdf,'orbrzv_zzerr_con',orbrzv_zzerr_con)
 
end subroutine nbi_in_num_def
 
subroutine nbi_in_atomic_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'nsmax',nsmax)
  call cdf_define(icdf,'khalo',khalo)
  call cdf_define(icdf,'dn0out',dn0out)
  call cdf_define(icdf,'nmsigx',nmsigx)
  call cdf_define(icdf,'nlminsv',nlminsv)
  call cdf_define(icdf,'nlebei',nlebei)
  call cdf_define(icdf,'nsigexc',nsigexc)
  call cdf_define(icdf,'xdepmod',xdepmod)
  call cdf_define(icdf,'nlbbcx',nlbbcx)
  call cdf_define(icdf,'nbbcx_avg',nbbcx_avg)
  call cdf_define(icdf,'nbbcx_bb',nbbcx_bb)
  call cdf_define(icdf,'nbfallgr',nbfallgr)
  call cdf_define(icdf,'nlbeamcx',nlbeamcx)
  call cdf_define(icdf,'nlhvion',nlhvion)
 
end subroutine nbi_in_atomic_def
 
subroutine nbi_in_collid_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'xcfanbi',xcfanbi)
  call cdf_define(icdf,'xdfanbi',xdfanbi)
  call cdf_define(icdf,'xefanbi',xefanbi)
  call cdf_define(icdf,'xcfafus',xcfafus)
  call cdf_define(icdf,'xdfafus',xdfafus)
  call cdf_define(icdf,'xefafus',xefafus)
  call cdf_define(icdf,'nlbcde',nlbcde)
  call cdf_define(icdf,'nlbcoh',nlbcoh)
  call cdf_define(icdf,'nlbcpa',nlbcpa)
  call cdf_define(icdf,'nlorbo',nlorbo)
 
end subroutine nbi_in_collid_def
 
subroutine nbi_in_flr_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'nlbflr',nlbflr)
  call cdf_define(icdf,'nlfbmflr',nlfbmflr)
  call cdf_define(icdf,'nlbgflr',nlbgflr)
  call cdf_define(icdf,'gflr_min',gflr_min)
  call cdf_define(icdf,'gflr_rl',gflr_rl)
  call cdf_define(icdf,'gflr_ll',gflr_ll)
  call cdf_define(icdf,'gflr_xv',gflr_xv)
  call cdf_define(icdf,'gflr_op',gflr_op)
 
end subroutine nbi_in_flr_def
 
subroutine nbi_in_saw_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'sawflag',sawflag)
  call cdf_define(icdf,'nlsawb',nlsawb)
  call cdf_define(icdf,'nlsawf',nlsawf)
  call cdf_define(icdf,'xswfrac_allfast',xswfrac_allfast)
  call cdf_define(icdf,'xswfrac_beam',xswfrac_beam)
  call cdf_define(icdf,'xswfrac_fusn',xswfrac_fusn)
  call cdf_define(icdf,'nmix_kdsaw',nmix_kdsaw)
  call cdf_define(icdf,'fporcelli',fporcelli)
 
end subroutine nbi_in_saw_def
 
subroutine nbi_in_adif_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'nkaep',nkaep)
  call cdf_define(icdf,'AEP_ASCALE',AEP_ASCALE)
  call cdf_define(icdf,'AEP_USCALE',AEP_USCALE)
  call cdf_define(icdf,'TAEP_FAC',TAEP_FAC)
  call cdf_define(icdf,'nmdifb',nmdifb)
  call cdf_define(icdf,'nkdifb',nkdifb)
  call cdf_define(icdf,'ndifbe',ndifbe)
  call cdf_define(icdf,'fdifbe',fdifbe)
  call cdf_define(icdf,'edifbe',edifbe)
  call cdf_define(icdf,'x_qlim0',x_qlim0)
  call cdf_define(icdf,'ndifbe_2d',ndifbe_2d)
  call cdf_define(icdf,'dif2d_conv',dif2d_conv)
  call cdf_define(icdf,'dif2d_dpa',dif2d_dpa)
  call cdf_define(icdf,'ngradd_opt',ngradd_opt)
 
end subroutine nbi_in_adif_def
 
subroutine nbi_in_ripple_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'nrip',nrip)
  call cdf_define(icdf,'taurip',taurip)
  call cdf_define(icdf,'id_ripple',id_ripple)
  call cdf_define(icdf,'id_ripple2',id_ripple2)
  call cdf_define(icdf,'ncoils',ncoils)
  call cdf_define(icdf,'ncoils_2',ncoils_2)
  call cdf_define(icdf,'asrd',asrd)
  call cdf_define(icdf,'bsrd',bsrd)
 
end subroutine nbi_in_ripple_def
 
subroutine nbi_in_outcon_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'nerngfi',nerngfi)
  call cdf_define(icdf,'erngfi',erngfi)
  call cdf_define(icdf,'nsdbgb',nsdbgb)
 
end subroutine nbi_in_outcon_def
 
subroutine nbi_in_fishbone_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'nlfbon',nlfbon)
  call cdf_define(icdf,'fbemin',fbemin)
  call cdf_define(icdf,'fbemax',fbemax)
  call cdf_define(icdf,'fvpvmn',fvpvmn)
  call cdf_define(icdf,'fvpvmx',fvpvmx)
  call cdf_define(icdf,'fbltim',fbltim)
  call cdf_define(icdf,'fshper',fshper)
  call cdf_define(icdf,'fshwid',fshwid)
  call cdf_define(icdf,'tfshon',tfshon)
  call cdf_define(icdf,'tfshof',tfshof)
  call cdf_define(icdf,'xfishmin',xfishmin)
  call cdf_define(icdf,'xfishmax',xfishmax)
  call cdf_define(icdf,'nfbon_vpvopt',nfbon_vpvopt)
  call cdf_define(icdf,'fbtrap_depth',fbtrap_depth)
  call cdf_define(icdf,'nfbon_species',nfbon_species)
 
end subroutine nbi_in_fishbone_def
 
subroutine nbi_in_box_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'nbbox',nbbox)
  call cdf_define(icdf,'nbsbox',nbsbox)
  call cdf_define(icdf,'nsample_box',nsample_box)
  call cdf_define(icdf,'xninja_box',xninja_box)
  call cdf_define(icdf,'xninjs_box',xninjs_box)
  call cdf_define(icdf,'xninj_box',xninj_box)
  call cdf_define(icdf,'nbebox',nbebox)
  call cdf_define(icdf,'nxbox',nxbox)
  call cdf_define(icdf,'nybox',nybox)
  call cdf_define(icdf,'nlbox',nlbox)
  call cdf_define(icdf,'xboxhw',xboxhw)
  call cdf_define(icdf,'yboxhw',yboxhw)
  call cdf_define(icdf,'xlbox1',xlbox1)
  call cdf_define(icdf,'xlbox2',xlbox2)
  call cdf_define(icdf,'ndepbox',ndepbox)
 
end subroutine nbi_in_box_def
 
subroutine nbi_in_tube_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'nbtube',nbtube)
  call cdf_define(icdf,'nbstube',nbstube)
  call cdf_define(icdf,'nbetube',nbetube)
  call cdf_define(icdf,'Rtube',Rtube)
  call cdf_define(icdf,'Ytube',Ytube)
  call cdf_define(icdf,'XZETAtube',XZETAtube)
  call cdf_define(icdf,'PHItube',PHItube)
  call cdf_define(icdf,'THETAtube',THETAtube)
  call cdf_define(icdf,'LMIDtube',LMIDtube)
  call cdf_define(icdf,'XL1tube',XL1tube)
  call cdf_define(icdf,'XL2tube',XL2tube)
  call cdf_define(icdf,'NSEGtube',NSEGtube)
  call cdf_define(icdf,'RHOtube',RHOtube)
  call cdf_define(icdf,'NDEPtube',NDEPtube)
 
end subroutine nbi_in_tube_def
 
subroutine nbi_in_misc_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'plhgt',plhgt)
  call cdf_define(icdf,'nlcprb',nlcprb)
  call cdf_define(icdf,'nlpsirz',nlpsirz)
  call cdf_define(icdf,'edbfac',edbfac)
  call cdf_define(icdf,'nmcurb',nmcurb)
  call cdf_define(icdf,'nlfdep',nlfdep)
 
end subroutine nbi_in_misc_def
 
subroutine nbi_in_profiles_def(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_define(icdf,'id_te',id_te)
  call cdf_define(icdf,'id_ti',id_ti)
  call cdf_define(icdf,'id_tifusn',id_tifusn)
  call cdf_define(icdf,'id_ne',id_ne)
  call cdf_define(icdf,'ng',ng)
  call cdf_define(icdf,'id_nh',id_nh)
  call cdf_define(icdf,'id_nimp',id_nimp)
  call cdf_define(icdf,'id_nrf',id_nrf)
  call cdf_define(icdf,'id_eperpmin',id_eperpmin)
  call cdf_define(icdf,'id_epllmin',id_epllmin)
  call cdf_define(icdf,'id_nfast',id_nfast)
  call cdf_define(icdf,'id_eperpfast',id_eperpfast)
  call cdf_define(icdf,'id_epllfast',id_epllfast)
  call cdf_define(icdf,'id_aimp',id_aimp)
  call cdf_define(icdf,'id_zimp',id_zimp)
  call cdf_define(icdf,'id_omega',id_omega)
  call cdf_define(icdf,'id_epot',id_epot)
  call cdf_define(icdf,'id_vpoh',id_vpoh)
  call cdf_define(icdf,'id_curt',id_curt)
  call cdf_define(icdf,'id_difb',id_difb)
  call cdf_define(icdf,'id_velb',id_velb)
  call cdf_define(icdf,'id_difb_bi',id_difb_bi)
  call cdf_define(icdf,'id_velb_bi',id_velb_bi)
  call cdf_define(icdf,'id_difb_fi',id_difb_fi)
  call cdf_define(icdf,'id_velb_fi',id_velb_fi)
  call cdf_define(icdf,'id_fd0',id_fd0)
  call cdf_define(icdf,'id_fdb',id_fdb)
  call cdf_define(icdf,'id_fdp',id_fdp)
  call cdf_define(icdf,'id_fdq',id_fdq)
  call cdf_define(icdf,'id_fdr',id_fdr)
  call cdf_define(icdf,'id_fds',id_fds)
  call cdf_define(icdf,'id_n0',id_n0)
  call cdf_define(icdf,'id_t0',id_t0)
  call cdf_define(icdf,'id_omeg0',id_omeg0)
 
end subroutine nbi_in_profiles_def
 
subroutine nbi_in_sys_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'runid',runid)
  call cdf_write(icdf,'mission',mission)
  call cdf_write(icdf,'workpath',workpath)
  call cdf_write(icdf,'nonlin',nonlin)
  call cdf_write(icdf,'nseed',nseed)
  call cdf_write(icdf,'nlbout',nlbout)
  call cdf_write(icdf,'lunnbx',lunnbx)
  call cdf_write(icdf,'lunres',lunres)
  call cdf_write(icdf,'mrstrt',mrstrt)
  call cdf_write(icdf,'nclass',nclass)
  call cdf_write(icdf,'only_io',only_io)
  call cdf_write(icdf,'ref_namelist',ref_namelist)
  call cdf_write(icdf,'quasi_check',quasi_check)
  call cdf_write(icdf,'nltest_output',nltest_output)
  call cdf_write(icdf,'BLK_MPI_BCAST_INT',BLK_MPI_BCAST_INT)
  call cdf_write(icdf,'BLK_MPI_BCAST_R8',BLK_MPI_BCAST_R8)
 
end subroutine nbi_in_sys_wr
 
subroutine nbi_in_times_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'tbm1',tbm1)
  call cdf_write(icdf,'tbm2',tbm2)
 
end subroutine nbi_in_times_wr
 
subroutine nbi_in_grid_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'nzones',nzones)
  call cdf_write(icdf,'nzone_fb',nzone_fb)
  call cdf_write(icdf,'nlsym2b',nlsym2b)
  call cdf_write(icdf,'nth0',nth0)
  call cdf_write(icdf,'xbmbnd',xbmbnd)
  call cdf_write(icdf,'id_mcgrid',id_mcgrid)
  call cdf_write(icdf,'nthets',nthets)
  call cdf_write(icdf,'ebdmax',ebdmax)
  call cdf_write(icdf,'xplasma_in_memory',xplasma_in_memory)
  call cdf_write(icdf,'nznbma',nznbma)
  call cdf_write(icdf,'nznbme',nznbme)
  call cdf_write(icdf,'nznbma0',nznbma0)
  call cdf_write(icdf,'nznbme0',nznbme0)
  call cdf_write(icdf,'ngyro',ngyro)
 
end subroutine nbi_in_grid_wr
 
subroutine nbi_in_beams_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'ngmax',ngmax)
  call cdf_write(icdf,'backz',backz)
  call cdf_write(icdf,'aplasm',aplasm)
  call cdf_write(icdf,'nbeam',nbeam)
  call cdf_write(icdf,'xzbeama',xzbeama)
  call cdf_write(icdf,'abeama',abeama)
  call cdf_write(icdf,'nlco',nlco)
  call cdf_write(icdf,'ntrace',ntrace)
  call cdf_write(icdf,'rtcena',rtcena)
  call cdf_write(icdf,'xlbtna',xlbtna)
  call cdf_write(icdf,'xybsca',xybsca)
  call cdf_write(icdf,'xbzeta',xbzeta)
  call cdf_write(icdf,'nbshapa',nbshapa)
  call cdf_write(icdf,'bmwidra',bmwidra)
  call cdf_write(icdf,'bmwidza',bmwidza)
  call cdf_write(icdf,'divra',divra)
  call cdf_write(icdf,'divza',divza)
  call cdf_write(icdf,'foclra',foclra)
  call cdf_write(icdf,'foclza',foclza)
  call cdf_write(icdf,'nbapsha',nbapsha)
  call cdf_write(icdf,'rapedga',rapedga)
  call cdf_write(icdf,'xzpedga',xzpedga)
  call cdf_write(icdf,'xlbapa',xlbapa)
  call cdf_write(icdf,'xybapa',xybapa)
  call cdf_write(icdf,'xrapoffa',xrapoffa)
  call cdf_write(icdf,'xzapoffa',xzapoffa)
  call cdf_write(icdf,'nbapsh2',nbapsh2)
  call cdf_write(icdf,'rapedg2',rapedg2)
  call cdf_write(icdf,'xzpedg2',xzpedg2)
  call cdf_write(icdf,'xlbapa2',xlbapa2)
  call cdf_write(icdf,'xrapoff2',xrapoff2)
  call cdf_write(icdf,'xzapoff2',xzapoff2)
 
end subroutine nbi_in_beams_wr
 
subroutine nbi_in_impurity_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'nrhix',nrhix)
  call cdf_write(icdf,'xzimpx',xzimpx)
  call cdf_write(icdf,'aimpx',aimpx)
 
end subroutine nbi_in_impurity_wr
 
subroutine nbi_in_minority_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'nmini',nmini)
  call cdf_write(icdf,'xzmini',xzmini)
  call cdf_write(icdf,'amini',amini)
  call cdf_write(icdf,'nthrf',nthrf)
 
end subroutine nbi_in_minority_wr
 
subroutine nbi_in_powers_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'einjmin',einjmin)
  call cdf_write(icdf,'einja',einja)
  call cdf_write(icdf,'pinja',pinja)
  call cdf_write(icdf,'ffulla',ffulla)
  call cdf_write(icdf,'fhalfa',fhalfa)
  call cdf_write(icdf,'orbrzv_toric_Prftot0',orbrzv_toric_Prftot0)
  call cdf_write(icdf,'orbrzv_toric_frnm',orbrzv_toric_frnm)
 
end subroutine nbi_in_powers_wr
 
subroutine nbi_in_fusion_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'nlfhe3',nlfhe3)
  call cdf_write(icdf,'nlfhe4',nlfhe4)
  call cdf_write(icdf,'nlfst',nlfst)
  call cdf_write(icdf,'nlfsp',nlfsp)
  call cdf_write(icdf,'nlfsp14',nlfsp14)
  call cdf_write(icdf,'nlusf3',nlusf3)
  call cdf_write(icdf,'xdatsf3',xdatsf3)
  call cdf_write(icdf,'nlusfa',nlusfa)
  call cdf_write(icdf,'xdatsfa',xdatsfa)
  call cdf_write(icdf,'nlusft',nlusft)
  call cdf_write(icdf,'xdatsft',xdatsft)
  call cdf_write(icdf,'nlusfp',nlusfp)
  call cdf_write(icdf,'xdatsfp',xdatsfp)
  call cdf_write(icdf,'nlusfp14',nlusfp14)
  call cdf_write(icdf,'xdatsp3',xdatsp3)
  call cdf_write(icdf,'plfhe3',plfhe3)
  call cdf_write(icdf,'plfhe4',plfhe4)
  call cdf_write(icdf,'plfst',plfst)
  call cdf_write(icdf,'plfsp',plfsp)
  call cdf_write(icdf,'plfsp14',plfsp14)
  call cdf_write(icdf,'nlfatom',nlfatom)
 
end subroutine nbi_in_fusion_wr
 
subroutine nbi_in_fpp_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'nlbfpp',nlbfpp)
 
end subroutine nbi_in_fpp_wr
 
subroutine nbi_in_num_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'cxsplt',cxsplt)
  call cdf_write(icdf,'dxbsmoo',dxbsmoo)
  call cdf_write(icdf,'dxbsm_nc',dxbsm_nc)
  call cdf_write(icdf,'nptcls',nptcls)
  call cdf_write(icdf,'nptclf',nptclf)
  call cdf_write(icdf,'nptclh',nptclh)
  call cdf_write(icdf,'NFAST_MAP',NFAST_MAP)
  call cdf_write(icdf,'xpand_nptcl',xpand_nptcl)
  call cdf_write(icdf,'frac_depmax',frac_depmax)
  call cdf_write(icdf,'frac_dep_lim',frac_dep_lim)
  call cdf_write(icdf,'frac_depmin',frac_depmin)
  call cdf_write(icdf,'frac_orbrr',frac_orbrr)
  call cdf_write(icdf,'nptcl_max',nptcl_max)
  call cdf_write(icdf,'nltrk_dep0',nltrk_dep0)
  call cdf_write(icdf,'NLDEP0_GATHER',NLDEP0_GATHER)
  call cdf_write(icdf,'ndep0',ndep0)
  call cdf_write(icdf,'NDEP0_MAX',NDEP0_MAX)
  call cdf_write(icdf,'ndep_set_beam',ndep_set_beam)
  call cdf_write(icdf,'ndep_set_ien',ndep_set_ien)
  call cdf_write(icdf,'nbbcal',nbbcal)
  call cdf_write(icdf,'ncx0',ncx0)
  call cdf_write(icdf,'nper_cx',nper_cx)
  call cdf_write(icdf,'LEV_NBIDEP',LEV_NBIDEP)
  call cdf_write(icdf,'LEV_TTNUK',LEV_TTNUK)
  call cdf_write(icdf,'LEVMOD_HALO',LEVMOD_HALO)
  call cdf_write(icdf,'NSPLT',NSPLT)
  call cdf_write(icdf,'NSPLT_GEO',NSPLT_GEO)
  call cdf_write(icdf,'NSPLT_KIN',NSPLT_KIN)
  call cdf_write(icdf,'NSPLT_GEN',NSPLT_GEN)
  call cdf_write(icdf,'nmimp',nmimp)
  call cdf_write(icdf,'AIMP',AIMP)
  call cdf_write(icdf,'XZIMP',XZIMP)
  call cdf_write(icdf,'NTEST_MAX',NTEST_MAX)
  call cdf_write(icdf,'BI_MAX_PL',BI_MAX_PL)
  call cdf_write(icdf,'BI_MAX_PR',BI_MAX_PR)
  call cdf_write(icdf,'wghta',wghta)
  call cdf_write(icdf,'goocon',goocon)
  call cdf_write(icdf,'NGOOCON_VPVBIN',NGOOCON_VPVBIN)
  call cdf_write(icdf,'NGOOCON_EBIN',NGOOCON_EBIN)
  call cdf_write(icdf,'NGOOCON_RBIN',NGOOCON_RBIN)
  call cdf_write(icdf,'cxpcon',cxpcon)
  call cdf_write(icdf,'fppcon',fppcon)
  call cdf_write(icdf,'fdtnxy',fdtnxy)
  call cdf_write(icdf,'nchdvp',nchdvp)
  call cdf_write(icdf,'dtn',dtn)
  call cdf_write(icdf,'dt_acc',dt_acc)
  call cdf_write(icdf,'orbrzv_option',orbrzv_option)
  call cdf_write(icdf,'orbrzv_rf_option',orbrzv_rf_option)
  call cdf_write(icdf,'nlmcrf_on',nlmcrf_on)
  call cdf_write(icdf,'orbrzv_nr',orbrzv_nr)
  call cdf_write(icdf,'orbrzv_nz',orbrzv_nz)
  call cdf_write(icdf,'orbrzv_zzerr_con',orbrzv_zzerr_con)
 
end subroutine nbi_in_num_wr
 
subroutine nbi_in_atomic_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'nsmax',nsmax)
  call cdf_write(icdf,'khalo',khalo)
  call cdf_write(icdf,'dn0out',dn0out)
  call cdf_write(icdf,'nmsigx',nmsigx)
  call cdf_write(icdf,'nlminsv',nlminsv)
  call cdf_write(icdf,'nlebei',nlebei)
  call cdf_write(icdf,'nsigexc',nsigexc)
  call cdf_write(icdf,'xdepmod',xdepmod)
  call cdf_write(icdf,'nlbbcx',nlbbcx)
  call cdf_write(icdf,'nbbcx_avg',nbbcx_avg)
  call cdf_write(icdf,'nbbcx_bb',nbbcx_bb)
  call cdf_write(icdf,'nbfallgr',nbfallgr)
  call cdf_write(icdf,'nlbeamcx',nlbeamcx)
  call cdf_write(icdf,'nlhvion',nlhvion)
 
end subroutine nbi_in_atomic_wr
 
subroutine nbi_in_collid_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'xcfanbi',xcfanbi)
  call cdf_write(icdf,'xdfanbi',xdfanbi)
  call cdf_write(icdf,'xefanbi',xefanbi)
  call cdf_write(icdf,'xcfafus',xcfafus)
  call cdf_write(icdf,'xdfafus',xdfafus)
  call cdf_write(icdf,'xefafus',xefafus)
  call cdf_write(icdf,'nlbcde',nlbcde)
  call cdf_write(icdf,'nlbcoh',nlbcoh)
  call cdf_write(icdf,'nlbcpa',nlbcpa)
  call cdf_write(icdf,'nlorbo',nlorbo)
 
end subroutine nbi_in_collid_wr
 
subroutine nbi_in_flr_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'nlbflr',nlbflr)
  call cdf_write(icdf,'nlfbmflr',nlfbmflr)
  call cdf_write(icdf,'nlbgflr',nlbgflr)
  call cdf_write(icdf,'gflr_min',gflr_min)
  call cdf_write(icdf,'gflr_rl',gflr_rl)
  call cdf_write(icdf,'gflr_ll',gflr_ll)
  call cdf_write(icdf,'gflr_xv',gflr_xv)
  call cdf_write(icdf,'gflr_op',gflr_op)
 
end subroutine nbi_in_flr_wr
 
subroutine nbi_in_saw_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'sawflag',sawflag)
  call cdf_write(icdf,'nlsawb',nlsawb)
  call cdf_write(icdf,'nlsawf',nlsawf)
  call cdf_write(icdf,'xswfrac_allfast',xswfrac_allfast)
  call cdf_write(icdf,'xswfrac_beam',xswfrac_beam)
  call cdf_write(icdf,'xswfrac_fusn',xswfrac_fusn)
  call cdf_write(icdf,'nmix_kdsaw',nmix_kdsaw)
  call cdf_write(icdf,'fporcelli',fporcelli)
 
end subroutine nbi_in_saw_wr
 
subroutine nbi_in_adif_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'nkaep',nkaep)
  call cdf_write(icdf,'AEP_ASCALE',AEP_ASCALE)
  call cdf_write(icdf,'AEP_USCALE',AEP_USCALE)
  call cdf_write(icdf,'TAEP_FAC',TAEP_FAC)
  call cdf_write(icdf,'nmdifb',nmdifb)
  call cdf_write(icdf,'nkdifb',nkdifb)
  call cdf_write(icdf,'ndifbe',ndifbe)
  call cdf_write(icdf,'fdifbe',fdifbe)
  call cdf_write(icdf,'edifbe',edifbe)
  call cdf_write(icdf,'x_qlim0',x_qlim0)
  call cdf_write(icdf,'ndifbe_2d',ndifbe_2d)
  call cdf_write(icdf,'dif2d_conv',dif2d_conv)
  call cdf_write(icdf,'dif2d_dpa',dif2d_dpa)
  call cdf_write(icdf,'ngradd_opt',ngradd_opt)
 
end subroutine nbi_in_adif_wr
 
subroutine nbi_in_ripple_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'nrip',nrip)
  call cdf_write(icdf,'taurip',taurip)
  call cdf_write(icdf,'id_ripple',id_ripple)
  call cdf_write(icdf,'id_ripple2',id_ripple2)
  call cdf_write(icdf,'ncoils',ncoils)
  call cdf_write(icdf,'ncoils_2',ncoils_2)
  call cdf_write(icdf,'asrd',asrd)
  call cdf_write(icdf,'bsrd',bsrd)
 
end subroutine nbi_in_ripple_wr
 
subroutine nbi_in_outcon_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'nerngfi',nerngfi)
  call cdf_write(icdf,'erngfi',erngfi)
  call cdf_write(icdf,'nsdbgb',nsdbgb)
 
end subroutine nbi_in_outcon_wr
 
subroutine nbi_in_fishbone_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'nlfbon',nlfbon)
  call cdf_write(icdf,'fbemin',fbemin)
  call cdf_write(icdf,'fbemax',fbemax)
  call cdf_write(icdf,'fvpvmn',fvpvmn)
  call cdf_write(icdf,'fvpvmx',fvpvmx)
  call cdf_write(icdf,'fbltim',fbltim)
  call cdf_write(icdf,'fshper',fshper)
  call cdf_write(icdf,'fshwid',fshwid)
  call cdf_write(icdf,'tfshon',tfshon)
  call cdf_write(icdf,'tfshof',tfshof)
  call cdf_write(icdf,'xfishmin',xfishmin)
  call cdf_write(icdf,'xfishmax',xfishmax)
  call cdf_write(icdf,'nfbon_vpvopt',nfbon_vpvopt)
  call cdf_write(icdf,'fbtrap_depth',fbtrap_depth)
  call cdf_write(icdf,'nfbon_species',nfbon_species)
 
end subroutine nbi_in_fishbone_wr
 
subroutine nbi_in_box_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'nbbox',nbbox)
  call cdf_write(icdf,'nbsbox',nbsbox)
  call cdf_write(icdf,'nsample_box',nsample_box)
  call cdf_write(icdf,'xninja_box',xninja_box)
  call cdf_write(icdf,'xninjs_box',xninjs_box)
  call cdf_write(icdf,'xninj_box',xninj_box)
  call cdf_write(icdf,'nbebox',nbebox)
  call cdf_write(icdf,'nxbox',nxbox)
  call cdf_write(icdf,'nybox',nybox)
  call cdf_write(icdf,'nlbox',nlbox)
  call cdf_write(icdf,'xboxhw',xboxhw)
  call cdf_write(icdf,'yboxhw',yboxhw)
  call cdf_write(icdf,'xlbox1',xlbox1)
  call cdf_write(icdf,'xlbox2',xlbox2)
  call cdf_write(icdf,'ndepbox',ndepbox)
 
end subroutine nbi_in_box_wr
 
subroutine nbi_in_tube_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'nbtube',nbtube)
  call cdf_write(icdf,'nbstube',nbstube)
  call cdf_write(icdf,'nbetube',nbetube)
  call cdf_write(icdf,'Rtube',Rtube)
  call cdf_write(icdf,'Ytube',Ytube)
  call cdf_write(icdf,'XZETAtube',XZETAtube)
  call cdf_write(icdf,'PHItube',PHItube)
  call cdf_write(icdf,'THETAtube',THETAtube)
  call cdf_write(icdf,'LMIDtube',LMIDtube)
  call cdf_write(icdf,'XL1tube',XL1tube)
  call cdf_write(icdf,'XL2tube',XL2tube)
  call cdf_write(icdf,'NSEGtube',NSEGtube)
  call cdf_write(icdf,'RHOtube',RHOtube)
  call cdf_write(icdf,'NDEPtube',NDEPtube)
 
end subroutine nbi_in_tube_wr
 
subroutine nbi_in_misc_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'plhgt',plhgt)
  call cdf_write(icdf,'nlcprb',nlcprb)
  call cdf_write(icdf,'nlpsirz',nlpsirz)
  call cdf_write(icdf,'edbfac',edbfac)
  call cdf_write(icdf,'nmcurb',nmcurb)
  call cdf_write(icdf,'nlfdep',nlfdep)
 
end subroutine nbi_in_misc_wr
 
subroutine nbi_in_profiles_wr(icdf)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
 
  call cdf_write(icdf,'id_te',id_te)
  call cdf_write(icdf,'id_ti',id_ti)
  call cdf_write(icdf,'id_tifusn',id_tifusn)
  call cdf_write(icdf,'id_ne',id_ne)
  call cdf_write(icdf,'ng',ng)
  call cdf_write(icdf,'id_nh',id_nh)
  call cdf_write(icdf,'id_nimp',id_nimp)
  call cdf_write(icdf,'id_nrf',id_nrf)
  call cdf_write(icdf,'id_eperpmin',id_eperpmin)
  call cdf_write(icdf,'id_epllmin',id_epllmin)
  call cdf_write(icdf,'id_nfast',id_nfast)
  call cdf_write(icdf,'id_eperpfast',id_eperpfast)
  call cdf_write(icdf,'id_epllfast',id_epllfast)
  call cdf_write(icdf,'id_aimp',id_aimp)
  call cdf_write(icdf,'id_zimp',id_zimp)
  call cdf_write(icdf,'id_omega',id_omega)
  call cdf_write(icdf,'id_epot',id_epot)
  call cdf_write(icdf,'id_vpoh',id_vpoh)
  call cdf_write(icdf,'id_curt',id_curt)
  call cdf_write(icdf,'id_difb',id_difb)
  call cdf_write(icdf,'id_velb',id_velb)
  call cdf_write(icdf,'id_difb_bi',id_difb_bi)
  call cdf_write(icdf,'id_velb_bi',id_velb_bi)
  call cdf_write(icdf,'id_difb_fi',id_difb_fi)
  call cdf_write(icdf,'id_velb_fi',id_velb_fi)
  call cdf_write(icdf,'id_fd0',id_fd0)
  call cdf_write(icdf,'id_fdb',id_fdb)
  call cdf_write(icdf,'id_fdp',id_fdp)
  call cdf_write(icdf,'id_fdq',id_fdq)
  call cdf_write(icdf,'id_fdr',id_fdr)
  call cdf_write(icdf,'id_fds',id_fds)
  call cdf_write(icdf,'id_n0',id_n0)
  call cdf_write(icdf,'id_t0',id_t0)
  call cdf_write(icdf,'id_omeg0',id_omeg0)
 
end subroutine nbi_in_profiles_wr
 
subroutine nbi_in_sys_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'runid',runid,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mission',mission,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'workpath',workpath,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nonlin',nonlin,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nseed',nseed,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlbout',nlbout,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'lunnbx',lunnbx,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'lunres',lunres,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'mrstrt',mrstrt,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nclass',nclass,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'only_io',only_io,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'ref_namelist',ref_namelist,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'quasi_check',quasi_check,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nltest_output',nltest_output,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'BLK_MPI_BCAST_INT',BLK_MPI_BCAST_INT,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'BLK_MPI_BCAST_R8',BLK_MPI_BCAST_R8,ierr)
  if(ierr.ne.0) return
 
  init_sys = .TRUE.
 
end subroutine nbi_in_sys_rd
 
subroutine nbi_in_times_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'tbm1',tbm1,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'tbm2',tbm2,ierr)
  if(ierr.ne.0) return
 
  init_times = .TRUE.
 
end subroutine nbi_in_times_rd
 
subroutine nbi_in_grid_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'nzones',nzones,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nzone_fb',nzone_fb,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlsym2b',nlsym2b,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nth0',nth0,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xbmbnd',xbmbnd,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_mcgrid',id_mcgrid,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nthets',nthets,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'ebdmax',ebdmax,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xplasma_in_memory',xplasma_in_memory,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nznbma',nznbma,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nznbme',nznbme,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nznbma0',nznbma0,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nznbme0',nznbme0,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'ngyro',ngyro,ierr)
  if(ierr.ne.0) return
 
  init_grid = .TRUE.
 
end subroutine nbi_in_grid_rd
 
subroutine nbi_in_beams_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'ngmax',ngmax,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'backz',backz,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'aplasm',aplasm,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nbeam',nbeam,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xzbeama',xzbeama,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'abeama',abeama,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlco',nlco,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'ntrace',ntrace,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'rtcena',rtcena,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xlbtna',xlbtna,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xybsca',xybsca,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xbzeta',xbzeta,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nbshapa',nbshapa,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'bmwidra',bmwidra,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'bmwidza',bmwidza,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'divra',divra,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'divza',divza,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'foclra',foclra,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'foclza',foclza,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nbapsha',nbapsha,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'rapedga',rapedga,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xzpedga',xzpedga,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xlbapa',xlbapa,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xybapa',xybapa,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xrapoffa',xrapoffa,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xzapoffa',xzapoffa,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nbapsh2',nbapsh2,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'rapedg2',rapedg2,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xzpedg2',xzpedg2,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xlbapa2',xlbapa2,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xrapoff2',xrapoff2,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xzapoff2',xzapoff2,ierr)
  if(ierr.ne.0) return
 
  init_beams = .TRUE.
 
end subroutine nbi_in_beams_rd
 
subroutine nbi_in_impurity_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'nrhix',nrhix,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xzimpx',xzimpx,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'aimpx',aimpx,ierr)
  if(ierr.ne.0) return
 
  init_impurity = .TRUE.
 
end subroutine nbi_in_impurity_rd
 
subroutine nbi_in_minority_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'nmini',nmini,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xzmini',xzmini,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'amini',amini,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nthrf',nthrf,ierr)
  if(ierr.ne.0) return
 
  init_minority = .TRUE.
 
end subroutine nbi_in_minority_rd
 
subroutine nbi_in_powers_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'einjmin',einjmin,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'einja',einja,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'pinja',pinja,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'ffulla',ffulla,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'fhalfa',fhalfa,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'orbrzv_toric_Prftot0',orbrzv_toric_Prftot0,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'orbrzv_toric_frnm',orbrzv_toric_frnm,ierr)
  if(ierr.ne.0) return
 
  init_powers = .TRUE.
 
end subroutine nbi_in_powers_rd
 
subroutine nbi_in_fusion_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'nlfhe3',nlfhe3,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlfhe4',nlfhe4,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlfst',nlfst,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlfsp',nlfsp,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlfsp14',nlfsp14,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlusf3',nlusf3,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xdatsf3',xdatsf3,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlusfa',nlusfa,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xdatsfa',xdatsfa,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlusft',nlusft,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xdatsft',xdatsft,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlusfp',nlusfp,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xdatsfp',xdatsfp,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlusfp14',nlusfp14,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xdatsp3',xdatsp3,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'plfhe3',plfhe3,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'plfhe4',plfhe4,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'plfst',plfst,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'plfsp',plfsp,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'plfsp14',plfsp14,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlfatom',nlfatom,ierr)
  if(ierr.ne.0) return
 
  init_fusion = .TRUE.
 
end subroutine nbi_in_fusion_rd
 
subroutine nbi_in_fpp_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'nlbfpp',nlbfpp,ierr)
  if(ierr.ne.0) return
 
  init_fpp = .TRUE.
 
end subroutine nbi_in_fpp_rd
 
subroutine nbi_in_num_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'cxsplt',cxsplt,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'dxbsmoo',dxbsmoo,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'dxbsm_nc',dxbsm_nc,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nptcls',nptcls,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nptclf',nptclf,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nptclh',nptclh,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'NFAST_MAP',NFAST_MAP,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xpand_nptcl',xpand_nptcl,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'frac_depmax',frac_depmax,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'frac_dep_lim',frac_dep_lim,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'frac_depmin',frac_depmin,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'frac_orbrr',frac_orbrr,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nptcl_max',nptcl_max,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nltrk_dep0',nltrk_dep0,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'NLDEP0_GATHER',NLDEP0_GATHER,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'ndep0',ndep0,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'NDEP0_MAX',NDEP0_MAX,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'ndep_set_beam',ndep_set_beam,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'ndep_set_ien',ndep_set_ien,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nbbcal',nbbcal,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'ncx0',ncx0,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nper_cx',nper_cx,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'LEV_NBIDEP',LEV_NBIDEP,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'LEV_TTNUK',LEV_TTNUK,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'LEVMOD_HALO',LEVMOD_HALO,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'NSPLT',NSPLT,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'NSPLT_GEO',NSPLT_GEO,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'NSPLT_KIN',NSPLT_KIN,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'NSPLT_GEN',NSPLT_GEN,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nmimp',nmimp,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'AIMP',AIMP,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'XZIMP',XZIMP,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'NTEST_MAX',NTEST_MAX,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'BI_MAX_PL',BI_MAX_PL,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'BI_MAX_PR',BI_MAX_PR,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'wghta',wghta,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'goocon',goocon,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'NGOOCON_VPVBIN',NGOOCON_VPVBIN,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'NGOOCON_EBIN',NGOOCON_EBIN,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'NGOOCON_RBIN',NGOOCON_RBIN,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'cxpcon',cxpcon,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'fppcon',fppcon,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'fdtnxy',fdtnxy,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nchdvp',nchdvp,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'dtn',dtn,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'dt_acc',dt_acc,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'orbrzv_option',orbrzv_option,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'orbrzv_rf_option',orbrzv_rf_option,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlmcrf_on',nlmcrf_on,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'orbrzv_nr',orbrzv_nr,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'orbrzv_nz',orbrzv_nz,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'orbrzv_zzerr_con',orbrzv_zzerr_con,ierr)
  if(ierr.ne.0) return
 
  init_num = .TRUE.
 
end subroutine nbi_in_num_rd
 
subroutine nbi_in_atomic_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'nsmax',nsmax,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'khalo',khalo,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'dn0out',dn0out,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nmsigx',nmsigx,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlminsv',nlminsv,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlebei',nlebei,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nsigexc',nsigexc,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xdepmod',xdepmod,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlbbcx',nlbbcx,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nbbcx_avg',nbbcx_avg,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nbbcx_bb',nbbcx_bb,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nbfallgr',nbfallgr,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlbeamcx',nlbeamcx,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlhvion',nlhvion,ierr)
  if(ierr.ne.0) return
 
  init_atomic = .TRUE.
 
end subroutine nbi_in_atomic_rd
 
subroutine nbi_in_collid_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'xcfanbi',xcfanbi,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xdfanbi',xdfanbi,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xefanbi',xefanbi,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xcfafus',xcfafus,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xdfafus',xdfafus,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xefafus',xefafus,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlbcde',nlbcde,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlbcoh',nlbcoh,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlbcpa',nlbcpa,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlorbo',nlorbo,ierr)
  if(ierr.ne.0) return
 
  init_collid = .TRUE.
 
end subroutine nbi_in_collid_rd
 
subroutine nbi_in_flr_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'nlbflr',nlbflr,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlfbmflr',nlfbmflr,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlbgflr',nlbgflr,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'gflr_min',gflr_min,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'gflr_rl',gflr_rl,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'gflr_ll',gflr_ll,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'gflr_xv',gflr_xv,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'gflr_op',gflr_op,ierr)
  if(ierr.ne.0) return
 
  init_flr = .TRUE.
 
end subroutine nbi_in_flr_rd
 
subroutine nbi_in_saw_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'sawflag',sawflag,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlsawb',nlsawb,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlsawf',nlsawf,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xswfrac_allfast',xswfrac_allfast,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xswfrac_beam',xswfrac_beam,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xswfrac_fusn',xswfrac_fusn,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nmix_kdsaw',nmix_kdsaw,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'fporcelli',fporcelli,ierr)
  if(ierr.ne.0) return
 
  init_saw = .TRUE.
 
end subroutine nbi_in_saw_rd
 
subroutine nbi_in_adif_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'nkaep',nkaep,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'AEP_ASCALE',AEP_ASCALE,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'AEP_USCALE',AEP_USCALE,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'TAEP_FAC',TAEP_FAC,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nmdifb',nmdifb,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nkdifb',nkdifb,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'ndifbe',ndifbe,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'fdifbe',fdifbe,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'edifbe',edifbe,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'x_qlim0',x_qlim0,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'ndifbe_2d',ndifbe_2d,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'dif2d_conv',dif2d_conv,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'dif2d_dpa',dif2d_dpa,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'ngradd_opt',ngradd_opt,ierr)
  if(ierr.ne.0) return
 
  init_adif = .TRUE.
 
end subroutine nbi_in_adif_rd
 
subroutine nbi_in_ripple_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'nrip',nrip,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'taurip',taurip,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_ripple',id_ripple,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_ripple2',id_ripple2,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'ncoils',ncoils,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'ncoils_2',ncoils_2,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'asrd',asrd,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'bsrd',bsrd,ierr)
  if(ierr.ne.0) return
 
  init_ripple = .TRUE.
 
end subroutine nbi_in_ripple_rd
 
subroutine nbi_in_outcon_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'nerngfi',nerngfi,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'erngfi',erngfi,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nsdbgb',nsdbgb,ierr)
  if(ierr.ne.0) return
 
  init_outcon = .TRUE.
 
end subroutine nbi_in_outcon_rd
 
subroutine nbi_in_fishbone_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'nlfbon',nlfbon,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'fbemin',fbemin,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'fbemax',fbemax,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'fvpvmn',fvpvmn,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'fvpvmx',fvpvmx,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'fbltim',fbltim,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'fshper',fshper,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'fshwid',fshwid,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'tfshon',tfshon,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'tfshof',tfshof,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xfishmin',xfishmin,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xfishmax',xfishmax,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nfbon_vpvopt',nfbon_vpvopt,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'fbtrap_depth',fbtrap_depth,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nfbon_species',nfbon_species,ierr)
  if(ierr.ne.0) return
 
  init_fishbone = .TRUE.
 
end subroutine nbi_in_fishbone_rd
 
subroutine nbi_in_box_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'nbbox',nbbox,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nbsbox',nbsbox,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nsample_box',nsample_box,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xninja_box',xninja_box,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xninjs_box',xninjs_box,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xninj_box',xninj_box,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nbebox',nbebox,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nxbox',nxbox,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nybox',nybox,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlbox',nlbox,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xboxhw',xboxhw,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'yboxhw',yboxhw,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xlbox1',xlbox1,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'xlbox2',xlbox2,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'ndepbox',ndepbox,ierr)
  if(ierr.ne.0) return
 
  init_box = .TRUE.
 
end subroutine nbi_in_box_rd
 
subroutine nbi_in_tube_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'nbtube',nbtube,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nbstube',nbstube,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nbetube',nbetube,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'Rtube',Rtube,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'Ytube',Ytube,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'XZETAtube',XZETAtube,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'PHItube',PHItube,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'THETAtube',THETAtube,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'LMIDtube',LMIDtube,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'XL1tube',XL1tube,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'XL2tube',XL2tube,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'NSEGtube',NSEGtube,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'RHOtube',RHOtube,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'NDEPtube',NDEPtube,ierr)
  if(ierr.ne.0) return
 
  init_tube = .TRUE.
 
end subroutine nbi_in_tube_rd
 
subroutine nbi_in_misc_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'plhgt',plhgt,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlcprb',nlcprb,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlpsirz',nlpsirz,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'edbfac',edbfac,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nmcurb',nmcurb,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'nlfdep',nlfdep,ierr)
  if(ierr.ne.0) return
 
  init_misc = .TRUE.
 
end subroutine nbi_in_misc_rd
 
subroutine nbi_in_profiles_rd(icdf,ierr)
 
  use nbi_com
  use ezcdf
  implicit NONE
  integer, intent(in) :: icdf  ! NetCDF file id
  integer, intent(out) :: ierr ! completion code, 0=OK
 
  call cdf_read(icdf,'id_te',id_te,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_ti',id_ti,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_tifusn',id_tifusn,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_ne',id_ne,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'ng',ng,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_nh',id_nh,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_nimp',id_nimp,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_nrf',id_nrf,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_eperpmin',id_eperpmin,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_epllmin',id_epllmin,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_nfast',id_nfast,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_eperpfast',id_eperpfast,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_epllfast',id_epllfast,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_aimp',id_aimp,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_zimp',id_zimp,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_omega',id_omega,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_epot',id_epot,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_vpoh',id_vpoh,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_curt',id_curt,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_difb',id_difb,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_velb',id_velb,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_difb_bi',id_difb_bi,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_velb_bi',id_velb_bi,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_difb_fi',id_difb_fi,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_velb_fi',id_velb_fi,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_fd0',id_fd0,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_fdb',id_fdb,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_fdp',id_fdp,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_fdq',id_fdq,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_fdr',id_fdr,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_fds',id_fds,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_n0',id_n0,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_t0',id_t0,ierr)
  if(ierr.ne.0) return
  call cdf_read(icdf,'id_omeg0',id_omeg0,ierr)
  if(ierr.ne.0) return
 
  init_profiles = .TRUE.
 
end subroutine nbi_in_profiles_rd
 
