subroutine read_namelist(params,infile,echo_in,outdir)
TYPE(KORC_PARAMS), INTENT(IN) :: params
CHARACTER(*), INTENT(IN) :: infile,outdir
LOGICAL, INTENT(IN) :: echo_in
INTEGER :: read_stat,nc
INTEGER :: number_of_namelists=0,il,inst
INTEGER, DIMENSION(20) :: namel_order=0
CHARACTER(20) :: tempfile
CHARACTER(128) :: ctmp
CHARACTER(128) :: outfile
LOGICAL :: reading
INTEGER :: mpierr
INTEGER :: tmp
!! Namelist declarations
NAMELIST /input_parameters/ restart,field_model,magnetic_field_filename, &
simulation_time,snapshot_frequency,dt,num_species,radiation, &
collisions,collisions_model,outputs_list,minimum_particle_energy, &
HDF5_error_handling,orbit_model,field_eval,proceed,profile_model, &
restart_overwrite_frequency,FokPlan,GC_rad_model,bound_electron_model,&
FO_GC_compare,SameRandSeed,SC_E,reinit,SC_E_add,time_slice,rmax, &
rmin,zmax,zmin,pchunk,magnetic_field_directory,magnetic_field_list,&
LargeCollisions,load_balance
NAMELIST /plasma_species/ ppp,q,m,Eno,etao,Eo_lims,etao_lims,runaway, &
spatial_distribution,energy_distribution,pitch_distribution,Ro, &
PHIo,Zo,r_inner,r_outter,falloff_rate,shear_factor,sigmaR,sigmaZ, &
theta_gauss,psi_max,Xtrace,Spong_b,Spong_w,Spong_dlam,dth,dR,dZ,dgam,&
pinit
NAMELIST /analytical_fields_params/ Bo,minor_radius,major_radius,&
qa,qo,Eo,current_direction,nR,nZ,nPHI,dim_1D,dt_E_SC,Ip_exp, &
E_dyn,E_pulse,E_width,E_profile,Ero,rmn,sigmamn
NAMELIST /externalPlasmaModel/ Efield, Bfield, Bflux,Bflux3D,dBfield, &
axisymmetric_fields, Eo,E_dyn,E_pulse,E_width,res_double, &
dim_1D,dt_E_SC,Ip_exp,PSIp_lim,Dim2x1t,t0_2x1t,E_2x1t,ReInterp_2x1t, &
ind0_2x1t,PSIp_0,B1field,psip_conv,MARS_AMP_Scale,Analytic_IWL, &
ntiles,circumradius,AORSA_AMP_Scale,AORSA_freq,AORSA_nmode,E1field, &
useLCFS
NAMELIST /plasmaProfiles/ radius_profile,ne_profile,neo,n_ne,a_ne, &
Te_profile,Teo,n_Te,a_Te,n_REr0,n_tauion,n_lamfront,n_lamback, &
Zeff_profile,Zeffo,n_Zeff,a_Zeff,filename,axisymmetric, &
n_lamshelf,n_shelfdelay,n_tauin,n_tauout,n_shelf,psiN_0
NAMELIST /CollisionParamsSingleSpecies/ Te_sing,Ti_sing,ne_sing, &
Zeff_sing,dTau_sing,p_therm,ConserveLA,Clog_model,sample_test,&
min_secRE,pmin_scale,energy_diffusion,LAC_gam_resolution, &
FP_bremsstrahlung,pitch_diffusion,ngrid1,Clog_const
NAMELIST /CollisionParamsMultipleSpecies/ num_impurity_species,Te_mult, &
ne_mult,Zo_mult,Zj_mult,nz_mult,IZj_mult,neut_prof
NAMELIST /AvalancheGenerationPDF/ max_pitch_angle_aval, &
min_pitch_angle_aval,max_energy_aval,min_energy_aval,ne_aval, &
Zeff_aval,Epar_aval,Te_aval,dth_aval,dp_aval,dR_aval,dZ_aval
NAMELIST /ExperimentalPDF/ max_pitch_angle_expt,min_pitch_angle_expt, &
max_energy_expt,min_energy_expt,Zeff_expt,E_expt,k_expt,t_expt, &
Bo_expt,lambda_expt,A_fact_expt,filename_exp
NAMELIST /HollmannPDF/ E_Hollmann,Zeff_Hollmann,max_pitch_angle_Hollmann, &
min_pitch_angle_Hollmann,max_energy_Hollmann, &
min_energy_Hollmann,filename_Hollmann,Bo_Hollmann,lambda_Hollmann, &
current_direction_Hollmann,A_fact_Hollmann,sigma_E_Hollmann, &
sigma_Z_Hollmann,Eo_Hollmann,rho_ind,gam_min_from_col
NAMELIST /SimpleEquilibriumPDF/ max_pitch_angle_simple, &
min_pitch_angle_simple,Zeff_simple,E_simple, &
Bo_simple,lambda_simple
NAMELIST /EnergyGammaPDF/ max_energy_gamma,min_energy_gamma,k_gamma,t_gamma
!!-----------------------------------------------------------------------
!! open input file.
!! Remove comments from input file and put into temporary file.
!!-----------------------------------------------------------------------
tempfile='tempinput.korc'
if (params%mpi_params%rank.eq.0) then
CALL rmcoment(infile,tempfile)
end if
call MPI_BARRIER(MPI_COMM_WORLD,mpierr)
OPEN(UNIT=default_unit_open,FILE=tempfile,STATUS='OLD',POSITION='REWIND')
!!-----------------------------------------------------------------------
!! check namelist file for namelist order and number.
!!-----------------------------------------------------------------------
DO
READ(UNIT=default_unit_open,FMT='(a)',IOSTAT=read_stat) ctmp
IF (read_stat/=0) EXIT
nc=LEN_TRIM(ctmp)
IF (nc<1) CYCLE
ctmp=ADJUSTL(ctmp)
reading=.false.
IF (ctmp(1:1)=='&') THEN
number_of_namelists=number_of_namelists+1
!!-----------------------------------------------------------------------
!! trim all but the namelist name.
!!-----------------------------------------------------------------------
DO il=2,nc+1
IF (ctmp(il:il)/=' ') THEN
IF (.NOT.reading) inst=il
reading=.true.
CYCLE
ENDIF
IF (ctmp(il:il)==' '.AND.reading) THEN
ctmp=ctmp(inst:il-1)
EXIT
ENDIF
ENDDO
BACKSPACE(default_unit_open)
!!-----------------------------------------------------------------------
!! select and read namelist.
!!-----------------------------------------------------------------------
SELECT CASE(TRIM(ctmp))
CASE('input_parameters')
READ(UNIT=default_unit_open,NML=input_parameters,IOSTAT=read_stat)
CASE('plasma_species')
!write(6,*) 'reading plasma_species namelist'
ALLOCATE(runaway(num_species))
ALLOCATE(ppp(num_species))
ALLOCATE(pinit(num_species))
ALLOCATE(q(num_species))
ALLOCATE(m(num_species))
ALLOCATE(spatial_distribution(num_species))
ALLOCATE(Ro(num_species))
ALLOCATE(PHIo(num_species))
ALLOCATE(Zo(num_species))
ALLOCATE(r_inner(num_species))
ALLOCATE(r_outter(num_species))
ALLOCATE(shear_factor(num_species))
ALLOCATE(sigmaR(num_species))
ALLOCATE(sigmaZ(num_species))
ALLOCATE(theta_gauss(num_species))
ALLOCATE(psi_max(num_species))
ALLOCATE(falloff_rate(num_species))
ALLOCATE(energy_distribution(num_species))
ALLOCATE(pitch_distribution(num_species))
ALLOCATE(Eno(num_species))
ALLOCATE(etao(num_species))
ALLOCATE(Eo_lims(2_idef*num_species))
ALLOCATE(etao_lims(2_idef*num_species))
ALLOCATE(Xtrace(3_idef*num_species))
ALLOCATE(Spong_b(num_species))
ALLOCATE(Spong_w(num_species))
ALLOCATE(Spong_dlam(num_species))
ALLOCATE(dth(num_species))
ALLOCATE(dgam(num_species))
ALLOCATE(dR(num_species))
ALLOCATE(dZ(num_species))
if (num_species.eq.1) then
runaway = .FALSE.
ppp = 1E0
pinit = 0
q = -1.0
m = 1.0
spatial_distribution = 'TRACER'
Ro = 1.1
PHIo = 0.0
Zo = -0.05
r_inner = 0.0
r_outter = 0.6
shear_factor = 0.35
sigmaR = 1.e6
sigmaZ = 0.2
theta_gauss = 0.0
psi_max=.8446
falloff_rate = 0.0
energy_distribution = 'MONOENERGETIC'
pitch_distribution = 'MONOPITCH'
Eno = 10.0E6
etao = 1.0
Eo_lims = (/1.0E6,50.0E6/)
etao_lims = (/0.0,20.0 /)
Xtrace =(/1.1,0.0,0.0/)
Spong_b = 0.2
Spong_w = 0.1
Spong_dlam = 0.1
dth = 3.
dgam = 3.
dR = 0.1
dZ = 0.1
else
if (params%mpi_params%rank .EQ. 0) then
write(output_unit_write,'("Need to supply all inputs for num_species .gt. 1")')
end if
end if
READ(UNIT=default_unit_open,NML=plasma_species,IOSTAT=read_stat)
if (pinit(1).eq.0) pinit(:)=ppp(:)
! set pinit equal to ppp if no pinit input
CASE('analytical_fields_params')
READ(UNIT=default_unit_open,NML=analytical_fields_params,IOSTAT=read_stat)
CASE('externalPlasmaModel')
READ(UNIT=default_unit_open,NML=externalPlasmaModel,IOSTAT=read_stat)
CASE('plasmaProfiles')
READ(UNIT=default_unit_open,NML=plasmaProfiles,IOSTAT=read_stat)
CASE('CollisionParamsSingleSpecies')
READ(UNIT=default_unit_open,NML=CollisionParamsSingleSpecies,IOSTAT=read_stat)
CASE('CollisionParamsMultipleSpecies')
READ(UNIT=default_unit_open,NML=CollisionParamsMultipleSpecies,IOSTAT=read_stat)
CASE('AvalancheGenerationPDF')
READ(UNIT=default_unit_open,NML=AvalancheGenerationPDF,IOSTAT=read_stat)
CASE('ExperimentalPDF')
READ(UNIT=default_unit_open,NML=ExperimentalPDF,IOSTAT=read_stat)
CASE('HollmannPDF')
READ(UNIT=default_unit_open,NML=HollmannPDF,IOSTAT=read_stat)
CASE('EnergyGammaPDF')
READ(UNIT=default_unit_open,NML=EnergyGammaPDF,IOSTAT=read_stat)
CASE('SimpleEquilibriumPDF')
READ(UNIT=default_unit_open,NML=SimpleEquilibriumPDF,IOSTAT=read_stat)
CASE DEFAULT
write(output_unit_write,*) (TRIM(ctmp)//' is an unrecognized &
&namelist.')
call korc_abort(13)
END SELECT
IF (read_stat/=0) then
write(output_unit_write,*) ('Error reading namelist '//TRIM(ctmp)//'.')
call korc_abort(13)
end if
ENDIF
ENDDO
!!-----------------------------------------------------------------------
!! close input file.
!! Delete it since it is the temporary file
!!-----------------------------------------------------------------------
if (params%mpi_params%rank.ne.0) then
CLOSE(default_unit_open)
end if
call MPI_BARRIER(MPI_COMM_WORLD,mpierr)
if (params%mpi_params%rank.eq.0) then
CLOSE(default_unit_open,STATUS='DELETE')
end if
!!-----------------------------------------------------------------------
!! echo the input parameters to the output file.
!!-----------------------------------------------------------------------
IF (echo_in) THEN
if (params%mpi_params%rank .EQ. 0) then
WRITE(output_unit_write,'(a,/)') 'VALUE OF ALL INPUTS:'
WRITE(UNIT=output_unit_write,NML=input_parameters)
WRITE(output_unit_write,'(/)')
WRITE(UNIT=output_unit_write,NML=plasma_species)
WRITE(output_unit_write,'(/)')
WRITE(UNIT=output_unit_write,NML=analytical_fields_params)
WRITE(output_unit_write,'(/)')
WRITE(UNIT=output_unit_write,NML=externalPlasmaModel)
WRITE(output_unit_write,'(/)')
WRITE(UNIT=output_unit_write,NML=plasmaProfiles)
WRITE(output_unit_write,'(/)')
WRITE(UNIT=output_unit_write,NML=CollisionParamsSingleSpecies)
WRITE(output_unit_write,'(/)')
WRITE(UNIT=output_unit_write,NML=CollisionParamsMultipleSpecies)
WRITE(output_unit_write,'(/)')
WRITE(UNIT=output_unit_write,NML=AvalancheGenerationPDF)
WRITE(output_unit_write,'(/)')
WRITE(UNIT=output_unit_write,NML=ExperimentalPDF)
WRITE(output_unit_write,'(/)')
WRITE(UNIT=output_unit_write,NML=HollmannPDF)
WRITE(output_unit_write,'(/)')
WRITE(UNIT=output_unit_write,NML=EnergyGammaPDF)
WRITE(output_unit_write,'(/)')
WRITE(UNIT=output_unit_write,NML=SimpleEquilibriumPDF)
WRITE(output_unit_write,'(/)')
end if
end if
!!---------------------------------------------------------
!! some tests
!!---------------------------------------------------------
!write(6,*) TRIM(outputs_list),len(TRIM(outputs_list))
tmp=len(TRIM(outputs_list))
if (outputs_list(tmp:tmp).ne.'}') then
if(params%mpi_params%rank.eq.0) then
write(6,*) &
'Check that enough characters are allocated for&
& outputs list!'
end if
call korc_abort(13)
end if
!write(6,*) TRIM(magnetic_field_filename),len(TRIM(magnetic_field_filename))
tmp=len(TRIM(magnetic_field_filename))
if (magnetic_field_filename(tmp-2:tmp).ne.'.h5'.and. &
magnetic_field_filename(tmp-5:tmp-5).ne.'.') then
if(params%mpi_params%rank.eq.0) then
write(6,*) &
'Check that enough characters are allocated for&
& magnetic field filename!'
end if
call korc_abort(13)
end if
end subroutine read_namelist