Reads input namelist file and stores the results into inputs, nbi, and beam_grid 20 for suffixes and seperators e.g. /, _npa.h5, ...
subroutine read_inputs
!+ Reads input namelist file and stores the results into [[libfida:inputs]],
!+ [[libfida:nbi]], and [[libfida:beam_grid]]
character(charlim) :: runid,result_dir, tables_file
character(charlim) :: distribution_file, equilibrium_file
character(charlim) :: geometry_file, neutrals_file
integer :: pathlen, calc_neutron
integer :: calc_brems,calc_bes,calc_fida,calc_npa
integer :: calc_birth,calc_fida_wght,calc_npa_wght
integer :: load_neutrals,verbose,dump_dcx,no_flr
integer(Int64) :: n_fida,n_npa,n_nbi,n_halo,n_dcx,n_birth
integer(Int32) :: shot,nlambda,ne_wght,np_wght,nphi_wght,nlambda_wght
real(Float64) :: time,lambdamin,lambdamax,emax_wght
real(Float64) :: lambdamin_wght,lambdamax_wght
real(Float64) :: ai,ab,pinj,einj,current_fractions(3)
integer(Int32) :: impurity_charge
integer(Int32) :: nx,ny,nz
real(Float64) :: xmin,xmax,ymin,ymax,zmin,zmax
real(Float64) :: alpha,beta,gamma,origin(3)
logical :: exis, error
NAMELIST /fidasim_inputs/ result_dir, tables_file, distribution_file, &
geometry_file, equilibrium_file, neutrals_file, shot, time, runid, &
calc_brems, calc_bes, calc_fida, calc_npa, calc_birth, no_flr, &
calc_fida_wght, calc_npa_wght, load_neutrals, dump_dcx, verbose, &
calc_neutron, n_fida,n_npa, n_nbi, n_halo, n_dcx, n_birth, &
ab, pinj, einj, current_fractions, ai, impurity_charge, &
nx, ny, nz, xmin, xmax, ymin, ymax, zmin, zmax, &
origin, alpha, beta, gamma, &
ne_wght, np_wght, nphi_wght, &
nlambda, lambdamin,lambdamax,emax_wght, &
nlambda_wght,lambdamin_wght,lambdamax_wght
inquire(file=namelist_file,exist=exis)
if(.not.exis) then
write(*,'(a,a)') 'READ_INPUTS: Input file does not exist: ', trim(namelist_file)
stop
endif
!!Set Defaults TODO: remove at next major release
no_flr = 0
calc_neutron = 0
open(13,file=namelist_file)
read(13,NML=fidasim_inputs)
close(13)
!!General Information
inputs%shot_number=shot
inputs%time=time
inputs%runid=runid
inputs%result_dir=result_dir
!!Input Files
inputs%tables_file=tables_file
inputs%geometry_file=geometry_file
inputs%equilibrium_file=equilibrium_file
inputs%distribution_file=distribution_file
inputs%neutrals_file=neutrals_file
!!Simulation Switches
if((calc_brems+calc_bes+calc_fida).gt.0) then
inputs%calc_spec=1
else
inputs%calc_spec=0
endif
inputs%calc_brems=calc_brems
inputs%calc_bes=calc_bes
inputs%calc_fida=calc_fida
inputs%calc_npa=calc_npa
inputs%calc_birth=calc_birth
inputs%calc_fida_wght=calc_fida_wght
inputs%calc_npa_wght=calc_npa_wght
inputs%calc_neutron=calc_neutron
inputs%load_neutrals=load_neutrals
inputs%dump_dcx=dump_dcx
inputs%verbose=verbose
inputs%no_flr = no_flr
!!Monte Carlo Settings
inputs%n_fida=max(10,n_fida)
inputs%n_npa=max(10,n_npa)
inputs%n_nbi=max(10,n_nbi)
inputs%n_halo=max(10,n_halo)
inputs%n_dcx=max(10,n_dcx)
inputs%n_birth= max(1,nint(n_birth/real(n_nbi)))
!!Plasma Settings
inputs%ai=ai
inputs%impurity_charge=impurity_charge
!!Neutral Beam Settings
inputs%ab=ab
nbi%current_fractions=current_fractions
nbi%einj=einj
nbi%pinj=pinj
!!Weight Function Settings
inputs%ne_wght=ne_wght
inputs%np_wght=np_wght
inputs%nphi_wght=nphi_wght
inputs%emax_wght=emax_wght
inputs%nlambda_wght = nlambda_wght
inputs%lambdamin_wght=lambdamin_wght
inputs%lambdamax_wght=lambdamax_wght
!!Wavelength Grid Settings
inputs%nlambda=nlambda
inputs%lambdamin=lambdamin
inputs%lambdamax=lambdamax
inputs%dlambda=(inputs%lambdamax-inputs%lambdamin)/inputs%nlambda
!!Beam Grid Settings
beam_grid%nx=nx
beam_grid%ny=ny
beam_grid%nz=nz
beam_grid%xmin=xmin
beam_grid%xmax=xmax
beam_grid%ymin=ymin
beam_grid%ymax=ymax
beam_grid%zmin=zmin
beam_grid%zmax=zmax
beam_grid%alpha=alpha
beam_grid%beta=beta
beam_grid%gamma=gamma
beam_grid%origin=origin
if(inputs%verbose.ge.1) then
write(*,'(a)') "---- Shot settings ----"
write(*,'(T2,"Shot: ",i8)') inputs%shot_number
write(*,'(T2,"Time: ",i4," [ms]")') int(inputs%time*1.d3)
write(*,'(T2,"Runid: ",a)') trim(adjustl(inputs%runid))
write(*,*) ''
write(*,'(a)') "---- Input files ----"
endif
error = .False.
inquire(file=inputs%tables_file,exist=exis)
if(exis) then
if(inputs%verbose.ge.1) then
write(*,'(T2,"Tables file: ",a)') trim(inputs%tables_file)
endif
else
if(inputs%verbose.ge.0) then
write(*,'(a,a)') 'READ_INPUTS: Tables file does not exist: ', &
trim(inputs%tables_file)
endif
error = .True.
endif
inquire(file=inputs%geometry_file,exist=exis)
if(exis) then
if(inputs%verbose.ge.1) then
write(*,'(T2,"Geometry file: ",a)') trim(inputs%geometry_file)
endif
else
if(inputs%verbose.ge.0) then
write(*,'(a,a)') 'READ_INPUTS: Geometry file does not exist: ', &
trim(inputs%geometry_file)
endif
error = .True.
endif
inquire(file=inputs%equilibrium_file,exist=exis)
if(exis) then
if(inputs%verbose.ge.1) then
write(*,'(T2,"Equilibrium file: ",a)') trim(inputs%equilibrium_file)
endif
else
if(inputs%verbose.ge.0) then
write(*,'(a,a)') 'READ_INPUTS: Equilibrium file does not exist: ', &
trim(inputs%equilibrium_file)
endif
error = .True.
endif
inquire(file=inputs%distribution_file,exist=exis)
if(exis) then
if(inputs%verbose.ge.1) then
write(*,'(T2,"Distribution file: ",a)') trim(inputs%distribution_file)
endif
else
if(inputs%verbose.ge.0) then
write(*,'(a,a)') 'READ_INPUTS: Distribution file does not exist: ', &
trim(inputs%distribution_file)
endif
error = .True.
endif
pathlen = len_trim(inputs%result_dir)+len_trim(inputs%runid) + 20
!+20 for suffixes and seperators e.g. /, _npa.h5, ...
if(pathlen.gt.charlim) then
if(inputs%verbose.ge.0) then
write(*,'(a,i3,a,i3)') 'READ_INPUTS: Result directory path + runID use too many characters: ', &
pathlen-20,'>', charlim-20
endif
error = .True.
endif
if(inputs%verbose.ge.1) then
write(*,*) ''
endif
if(error) then
stop
endif
end subroutine read_inputs