exit_if_not_exist $(tkprog_X_path)/electrical/

[Diode].select
join_path section_root_dir $(tkprog_X_path) electrical

add_tooltip 1 "Make alpha(E) spectrum Excel file from U-4100 T&R data" #dcfbfe #0000ff
add_tooltip 2 "Analyze PV parameters from dark/photo IV" #dcfbfe #0000ff
add_tooltip 3 "View help web for pvanalyze.py" #dcfbfe #0000ff
add_tooltip 5 "Fitting to IV data with diode equivalent circuit model" #dcfbfe #0000ff
add_tooltip 6 "View help web for pvfit.py" #dcfbfe #0000ff

add_tooltip 10 "Simulate Schottky diode IV" #dcfbfe #0000ff
add_tooltip 12 "View help web for schottky.py" #dcfbfe #0000ff
add_tooltip 13 "Simulate p/n diode IV" #dcfbfe #0000ff
add_tooltip 15 "View help web for pnjunction.py" #dcfbfe #0000ff

End


[Button1.Diode]
Caption=make alpha

read_ini $i "diode" "work_dir" last_dir "."
chdir "$(last_dir)"

get_open_file_name "*.txt" "$(last_dir)" "Choose U-4100 transmission file (.txt)"
set input_T_path=$o
get_directory "$(input_T_path)" dir_name
get_filebody "$(input_T_path)" filebody
chdir "$(dir_name)"

get_open_file_name "*.txt" "$(dir_name)" "Choose U-4100 refectance file (.txt)"
set input_R_path=$o
get_directory "$(input_R_path)" dir_name
get_filebody "$(input_R_path)" filebody

write_ini $i "diode" "work_dir" "$(dir_name)"
chdir "$(dir_name)"

set outprefix="$(filebody)"

set_title make alpha: Configure

new_dialog

add_dialog choose_file\
	input_T_path\
	"label_head=T file:"\
	entry_width=50\
	"def_val=$(input_T_path)"\
	show_path_button=1\
	"file_type=U-4100 Files:*.txt"\
	"label_tail="

add_dialog choose_file\
	input_R_path\
	"label_head=R file:"\
	entry_width=50\
	"def_val=$(input_R_path)"\
	show_path_button=1\
	"file_type=U-4100 Files:*.txt"\
	"label_tail="

add_dialog entry\
  outprefix\
  "label_head=outfile prefix:"\
  width=50\
  "def_val=$(outprefix)"\
  "help_text="\
  "label_tail="

add_dialog frame dummy "bg=#ececec" "relief=groove"
add_dialog button dummy "text=make alpha xlsx" "command=call [makealpha_make]"
add_dialog button dummy "text=plot alpha" "command=call [makealpha_plot]"
add_dialog button dummy "text=view _alpha.xlsx" "command=call [makealpha_view_alpha]"
add_dialog button dummy "text=view output" "command=call [makealpha_view_output]"
add_dialog button dummy "text=view png" "command=call [makealpha_view_png]"
add_dialog pack_frame dummy

add_dialog frame dummy "bg=#ececec" "relief=groove"
add_dialog button dummy "text=explorer" "command=call [explorer]"
add_dialog button dummy "text=cmd" "command=call [cmd]"
add_dialog button dummy "text=edit source"  "command=call [pvanalyze_edit_source]"
add_dialog pack_frame dummy

custom_dialog "textbook Settings" close

End

[pvanalyze_edit_source]"
join_path script "$(tkprog_X_path)" electrical pvanalyze.py
$(start) "$(script)"
End

[makealpha_make]
get_directory "$(input_R_path)" dir_name
write_ini $i "diode" "work_dir" "$(dir_name)"
chdir "$(dir_name)"

join_path script "$(tkprog_X_path)" electrical pvanalyze.py
$(start_cmd_c) "$(python3_path)" "$(script)" --mode=make_alpha --Tr="$(input_T_path)" --R="$(input_R_path)" \
  --outprefix="$(outprefix)"
End

[makealpha_plot]
get_directory "$(input_R_path)" dir_name
write_ini $i "diode" "work_dir" "$(dir_name)"
chdir "$(dir_name)"

join_path alpha_path "$(dir_name)" "$(outprefix)_alpha.xlsx"

join_path script "$(tkprog_X_path)" electrical pvanalyze.py
$(start_cmd_c) "$(python3_path)" "$(script)" --mode=alpha --alpha="$(alpha_path)" \
  --outprefix="$(outprefix)"
End

[makealpha_view_alpha]
get_directory "$(input_R_path)" dir_name
write_ini $i "diode" "work_dir" "$(dir_name)"
chdir "$(dir_name)"

join_path alpha_path "$(dir_name)" "$(outprefix)_alpha.xlsx"

$(start) "$(alpha_path)"
End

[makealpha_view_output]
get_directory "$(input_R_path)" dir_name
write_ini $i "diode" "work_dir" "$(dir_name)"
chdir "$(dir_name)"

join_path output_path "$(dir_name)" "$(outprefix)_alpha.txt"

$(start) "$(editor_path)" "$(output_path)"
End

[makealpha_view_png]
get_directory "$(input_R_path)" dir_name
write_ini $i "diode" "work_dir" "$(dir_name)"
chdir "$(dir_name)"

join_path png_path "$(dir_name)" "$(outprefix)_alpha_E.png"

$(start) "$(png_path)"
End


[Button2.Diode]
Caption=pvanalyze

read_ini $i "diode" "work_dir" last_dir "."
chdir "$(last_dir)"

get_open_file_name "*.csv" "$(last_dir)" "Choose dark IV 4155/6C CSV file (.txt)"
set input_dark_path=$o
get_directory "$(input_dark_path)" dir_name
chdir "$(dir_name)"

get_open_file_name "*.csv" "$(dir_name)" "Choose photo IV 4155/6C CSV file (.txt)"
set input_photo_path=$o
get_directory "$(input_photo_path)" dir_name
get_filebody "$(input_photo_path)" filebody
chdir "$(dir_name)"

get_open_file_name "*.xlsx" "$(dir_name)" "Choose alpha spectrum Excel file (.xlsx)"
set alpha_path=$o
chdir "$(dir_name)"

write_ini $i "diode" "work_dir" "$(dir_name)"

set outprefix="$(filebody)"

set_title make alpha: Configure

new_dialog

add_dialog choose_file\
	input_dark_path\
	"label_head=dark IV file:"\
	entry_width=50\
	"def_val=$(input_dark_path)"\
	show_path_button=1\
	"file_type=4155/6C CSV Files:*.csv"\
	"label_tail="

add_dialog choose_file\
	input_light_path\
	"label_head=photo IV file:"\
	entry_width=50\
	"def_val=$(input_photo_path)"\
	show_path_button=1\
	"file_type=4155/6C CSV Files:*.csv"\
	"label_tail="

add_dialog choose_file\
	alpha_path\
	"label_head=optical absorption spectrum:"\
	entry_width=50\
	"def_val=$(alpha_path)"\
	show_path_button=1\
	"file_type=alpha Excel Files:*.xlsx"\
	"label_tail="

add_dialog entry\
  outprefix\
  "label_head=outfile prefix:"\
  width=50\
  "def_val=$(outprefix)"\
  "help_text="\
  "label_tail="


add_dialog message\
  dummy\
  "relief=raised"\
  width=1000\
  fg=red\
  "text=Input P0 to override F0"

set_if_blank F0 F0=1.95804e18
add_dialog frame dummy "bg=#ececec" "relief=groove"
add_dialog entry\
  F0\
  "label_head=Incident photon: flux (F0):"\
  width=15\
  "def_val=$(F0)"\
  "help_text="\
  "label_tail=cm^-2 s^-1"

set_if_blank photon_E photon_E=1.099
add_dialog entry\
  photon_E\
  "label_head=Energy:"\
  width=15\
  "def_val=$(photon_E)"\
  "help_text="\
  "label_tail=eV"
add_dialog pack_frame dummy

set_if_blank P0 P0=
add_dialog entry\
  P0\
  "label_head=Incident photon power density (P0):"\
  width=15\
  "def_val=$(P0)"\
  "help_text="\
  "label_tail=W/cm^2"

set_if_blank area area=1.0
add_dialog entry\
  area\
  "label_head=Electrode area:"\
  width=15\
  "def_val=$(area)"\
  "help_text="\
  "label_tail=cm-2"

set_if_blank temperature temperature=300.0
add_dialog entry\
  temperature\
  "label_head=Temperature:"\
  width=15\
  "def_val=$(temperature)"\
  "help_text="\
  "label_tail=K"

add_dialog frame dummy "bg=#ececec" "relief=groove"
add_dialog button dummy "text=analyze" "command=call [pvanalyze_analyze]"
add_dialog button dummy "text=view output" "command=call [pvanalyze_view_output]"
add_dialog button dummy "text=view png" "command=call [pvanalyze_view_png]"
add_dialog pack_frame dummy

add_dialog frame dummy "bg=#ececec" "relief=groove"
add_dialog button dummy "text=explorer" "command=call [pvanalyze_explorer]"
add_dialog button dummy "text=cmd" "command=call [pvanalyze_cmd]"
add_dialog button dummy "text=edit source"  "command=call [pvanalyze_edit_source]"
add_dialog pack_frame dummy

custom_dialog "textbook Settings" close

End

[pvanalyze_explorer]
get_directory "$(input_dark_path)" work_dir
write_ini $i "diode" "work_dir" "$(work_dir)"
chdir "$(last_dir)"
$(start) "$(filer_path)" "$(work_dir)"
End

[pvanalyze_cmd]
get_directory "$(input_dark_path)" work_dir
write_ini $i "diode" "work_dir" "$(work_dir)"
chdir "$(work_dir)"
$(start) "$(shell_path)"
End

[pvanalyze_edit_source]
join_path script "$(tkprog_X_path)" electrical pvanalyze.py
$(start) "$(script)"
End

[pvanalyze_analyze]
get_directory "$(input_photo_path)" dir_name
write_ini $i "diode" "work_dir" "$(dir_name)"
chdir "$(dir_name)"

join_path script "$(tkprog_X_path)" electrical pvanalyze.py
$(start_cmd_c) "$(python3_path)" "$(script)" --mode=analyze --dark="$(input_dark_path)" --light="$(input_photo_path)" \
  --alpha="$(alpha_path)" --outprefix="$(outprefix)" \
  --F0=$(F0) --E=$(photon_E) --P0=$(P0) --S=$(area) --T=$(temperature)
End

[pvanalyze_view_output]
get_directory "$(input_dark_path)" dir_name
write_ini $i "diode" "work_dir" "$(dir_name)"
chdir "$(dir_name)"

join_path output_path "$(dir_name)" "$(outprefix)_analyze.txt"

$(start) "$(editor_path)" "$(output_path)"
End

[pvanalyze_view_png]
get_directory "$(input_dark_path)" dir_name
write_ini $i "diode" "work_dir" "$(dir_name)"
chdir "$(dir_name)"

join_path png_path "$(dir_name)" "$(outprefix)_iv.png"

$(start) "$(png_path)"
End

[pvanalyze_explorer]
get_directory "$(input_dark_path)" dir_name
write_ini $i "diode" "work_dir" "$(dir_name)"
chdir "$(dir_name)"
$(start) "$(filer_path)" "$(dir_name)"
End

[pvanalyze_cmd]
get_directory "$(input_dark_path)" dir_name
write_ini $i "diode" "work_dir" "$(dir_name)"
chdir "$(dir_name)"
$(start_cmd_k)
End

[Button3.Diode]
Caption=pvanalyze help(Sphinx)
start $(sphinx_url_base)tkProg/electrical/pvanalyze_index.html
End

[Button5.Diode]
Caption=pvfit

read_ini $i "diode" "work_dir" last_dir "."
chdir "$(last_dir)"

get_open_file_name "*.csv" "$(last_dir)" "Choose IV 4155/6C CSV file (.txt)"
set input_path=$o
get_directory "$(input_path)" dir_name
get_filebody "$(input_path)" filebody

write_ini $i "diode" "work_dir" "$(dir_name)"
chdir "$(dir_name)"

set outprefix="$(filebody)"

set_title pvfit: Configure

new_dialog

add_dialog message\
	dummy\
	"relief=raised"\
	fg=blue\
	width=800\
	"text=diodeの暗電流・光電流IV特性に対して等価回路モデルのフィッティングをします。\
	初期化、.iniファイルの編集、非線形フィッティングの順番に行います"

add_dialog choose_file\
	input_path\
	"label_head=input IV path:"\
	entry_width=80\
	"def_val=$(input_path)"\
	state=readonly\
	show_path_button=0\
	"label_tail="

add_dialog entry\
  outprefix\
  "label_head=outfile prefix:"\
  width=80\
  "def_val=$(outprefix)"\
  "help_text="\
  "label_tail="

add_dialog frame dummy "bg=#ececec" "relief=groove"
set_if_blank reverseIV_model reverseIV_model=diode
add_dialog combobox\
	reverseIV_model\
	"label_head=reverse IV model:"\
	state=readonly\
	width=30\
	height=5\
	"init_val=$(reverseIV_model)"\
	"diode"\
	"diode+tfe"\
	"diode+nf"\
	"label_tail"

set_if_blank forwardIV_model forwardIV_model=diode
add_dialog combobox\
	forwardIV_model\
	"label_head=forward IV model:"\
	state=readonly\
	width=30\
	height=5\
	"init_val=$(forwardIV_model)"\
	"diode"\
	"diode+tfe"\
	"diode+nf"\
	"diode+scfc"\
	"label_tail"
add_dialog pack_frame dummy

set_if_blank temperature temperature=300.0
add_dialog entry\
  temperature\
  "label_head=Temperature:"\
  width=15\
  "def_val=$(temperature)"\
  "help_text="\
  "label_tail=K"

add_dialog frame dummy "bg=#ececec" "relief=groove"
set_if_blank fit_xmin fit_xmin=-1.0e100
add_dialog entry \
	fit_xmin\
	"label_head=fit V range:"\
	width=10\
	"init_val=$(fit_xmin)"\
	"def_val=-1.0e100"\
	"help_text=フィッティングに入れる最小電圧"\
	"label_tail="

set_if_blank fit_xmax fit_xmax=1.0e100
add_dialog entry \
	fit_xmax\
	"label_head=-"\
	width=10\
	"init_val=$(fit_xmax)"\
	"def_val=1.0e100"\
	"help_text=フィッティングに入れる最大電圧"\
	"label_tail=V"
add_dialog pack_frame dummy

set_if_blank ndataskip ndataskip=0
add_dialog spinbox \
	ndataskip\
	var_type=int\
	"label_head=# of data to skip:"\
	entry_width=5\
	"def_val=0"\
	"init_val=$(ndataskip)"\
	from=0\
	to=100\
	increment=1\
	"help_text=読み込みデータを間引きする数"\
	"label_tail="

add_dialog label label1 "text=最適化条件:"\
	"fg=red"\
	"style=bold"

set_if_blank method_pvfit method_pvfit=nelder-mead
add_dialog combobox\
	method_pvfit\
	"label_head=method:"\
	state=readonly\
	width=40\
	height=15\
	"init_val=$(method_pvfit)"\
	"def_val=$(method_pvfit)"\
	"nelder-mead # Downhill simplex"\
	"powell      # Modified Powell"\
	"cg          # conjugate gradient"\
	"bfgs        # BFGS"\
	"label_tail=非線形最適化のアルゴリズム"

add_dialog frame dummy "bg=#ececec" "relief=groove"
set_if_blank nmaxiter nmaxiter=2000
add_dialog spinbox \
	nmaxiter\
	var_type=int\
	"label_head=# of max iter:"\
	entry_width=5\
	"def_val=100"\
	"init_val=$(nmaxiter)"\
	from=1\
	to=10000\
	increment=50\
	"help_text=最大繰り返し回数"\
	"label_tail="

set_if_blank tol tol=1.0e-5
add_dialog entry \
	tol\
	"label_head=tol:"\
	width=8\
	"init_val=$(tol)"\
	"def_val=1.0e-5"\
	"help_text=収束判定条件"\
	"label_tail="
add_dialog pack_frame dummy

add_dialog message\
	dummy\
	"relief=raised"\
	width=800\
	fg=blue\
	"text=最初に analyze and mk prm を実行して初期値決定と -parameters.csvファイルの作成を行います。\
	 その結果を見てedit prmで編集し、fitで非線形最小二乗法を実行します。\
	 結果を見て必要であればedit prmでパラメータを再編集し、十分な収束結果が得られるまで\
	 fitを繰り返します。"

add_dialog frame dummy "bg=#ececec" "relief=groove"
add_dialog button dummy "text=analyze"            "command=call [pvfit_analyze]"
add_dialog button dummy "text=analyze and mk prm" "command=call [pvfit_initialize]"
add_dialog button dummy "text=simulate"           "command=call [pvfit_simulate]"
add_dialog button dummy "text=edit prm"           "command=call [pvfit_edit_param]"
add_dialog button dummy "text=fit"                "command=call [pvfit_fit]"
add_dialog button dummy "text=view last output"   "command=call [pvfit_view_output]"
add_dialog button dummy "text=view fitted Excel"  "command=call [pvfit_view_fitted_excel]"
add_dialog pack_frame dummy

add_dialog frame dummy "bg=#ececec" "relief=groove"
add_dialog button dummy "text=explorer" "command=call [pvfit_explorer]"
add_dialog button dummy "text=cmd" "command=call [pvfit_cmd]"
add_dialog button dummy "text=edit source"  "command=call [pvfit_edit_source]"
add_dialog pack_frame dummy

custom_dialog "pvfit" close
remove_comment method_pvfit
End

[pvfit_explorer]
get_directory "$(input_path)" work_dir
write_ini $i "diode" "work_dir" "$(work_dir)"
chdir "$(last_dir)"
$(start) "$(filer_path)" "$(work_dir)"
End

[pvfit_cmd]
get_directory "$(input_path)" work_dir
write_ini $i "diode" "work_dir" "$(work_dir)"
chdir "$(work_dir)"
$(start) "$(shell_path)"
End

[pvfit_edit_source]"
join_path script "$(tkprog_X_path)" electrical pvfit.py
$(start) "$(script)"
End

[pvfit_analyze]
set mode=analyze
call [pvfit_execute]
End

[pvfit_initialize]
set mode=init
call [pvfit_execute]
End

[pvfit_simulate]
set mode=sim
call [pvfit_execute]
End

[pvfit_fit]
set mode=fit
call [pvfit_execute]
End

[pvfit_execute]
remove_comment method_pvfit
get_directory "$(input_path)" dir_name
write_ini $i "diode" "work_dir" "$(dir_name)"
chdir "$(dir_name)"

join_path script "$(tkprog_X_path)" electrical pvfit.py
$(start_cmd_c) "$(python3_path)" "$(script)" --mode=$(mode) --infile="$(input_path)" \
  --outprefix="$(outprefix)" \
  --xmin=$(fit_xmin) --xmax=$(fit_xmax) --ndataskip=$(ndataskip) \
  --temperature=$(temperature) \
  --forwardIV=$(forwardIV_model) --reverseIV=$(reverseIV_model) \
  --method="$(method_pvfit)" --nmaxiter=$(nmaxiter) --tol=$(tol) 
End

[pvfit_edit_param]
get_directory "$(input_path)" dir_name
write_ini $i "diode" "work_dir" "$(dir_name)"

join_path parameter_file "$(dir_name)" "$(outprefix)-parameters.csv"
$(start) "$(editor_path)" "$(parameter_file)"
End

[pvfit_view_output]
get_directory "$(input_path)" dir_name
write_ini $i "diode" "work_dir" "$(dir_name)"
chdir "$(dir_name)"

join_path output_path "$(dir_name)" "$(outprefix)_$(mode).txt"
$(start) "$(editor_path)" "$(output_path)"
End

[pvfit_view_fitted_excel]
get_directory "$(input_path)" dir_name
write_ini $i "diode" "work_dir" "$(dir_name)"
chdir "$(dir_name)"

join_path excel_path "$(dir_name)" "$(outprefix)-fitted.xlsx"
$(start) "$(excel_path)"
End


[Button6.Diode]
Caption=pvfit help(Sphinx)
start $(sphinx_url_base)tkProg/electrical/pvfit_index.html
End

[Button10.Diode]
Caption=schottky IV sim

read_ini $i "diode" "work_dir" last_dir "."
chdir "$(last_dir)"

set_title schottky.py: Configure

new_dialog

add_dialog message\
	dummy\
	"relief=raised"\
	fg=blue\
	width=900\
	"text=Schottky diode IV characteristic simulation using schottky.py.\
	This script does not read input files. It shows calculated parameters in the console and plots IV by matplotlib."

add_dialog frame dummy "bg=#ececec" "relief=groove"

set_if_blank schottky_model schottky_model=Simple
add_dialog combobox\
	schottky_model\
	"label_head=model:"\
	state=readonly\
	width=25\
	height=10\
	"init_val=$(schottky_model)"\
	"def_val=Simple"\
	"Simple"\
	"Diffusion"\
	"Schottky"\
	"Tunneling"\
	"TFE"\
	"label_tail="
add_dialog pack_frame dummy

add_dialog frame dummy "bg=#ececec" "relief=groove"

set_if_blank schottky_temp schottky_temp=300.0
add_dialog entry\
	schottky_temp\
	"label_head=Temperature:"\
	width=12\
	"def_val=$(schottky_temp)"\
	"help_text=Simulation temperature"\
	"label_tail=K"

set_if_blank schottky_area schottky_area=0.01
add_dialog entry\
	schottky_area\
	"label_head=Area:"\
	width=12\
	"def_val=$(schottky_area)"\
	"help_text=Device area"\
	"label_tail=cm^2"

set_if_blank schottky_ndn schottky_ndn=1.0e16
add_dialog entry\
	schottky_ndn\
	"label_head=Donor density ND:"\
	width=15\
	"def_val=$(schottky_ndn)"\
	"help_text=n-type donor density"\
	"label_tail=cm^-3"
add_dialog pack_frame dummy

add_dialog frame dummy "bg=#ececec" "relief=groove"

set_if_blank schottky_efm schottky_efm=4.4
add_dialog entry\
	schottky_efm\
	"label_head=Metal Fermi level:"\
	width=12\
	"def_val=$(schottky_efm)"\
	"help_text=Metal Fermi level"\
	"label_tail=eV"

set_if_blank schottky_ecn schottky_ecn=4.05
add_dialog entry\
	schottky_ecn\
	"label_head=Electron affinity:"\
	width=12\
	"def_val=$(schottky_ecn)"\
	"help_text=Semiconductor electron affinity"\
	"label_tail=eV"

set_if_blank schottky_men schottky_men=0.19
add_dialog entry\
	schottky_men\
	"label_head=Effective mass ratio:"\
	width=12\
	"def_val=$(schottky_men)"\
	"help_text=m*/m0 for electrons"\
	"label_tail="
add_dialog pack_frame dummy

add_dialog frame dummy "bg=#ececec" "relief=groove"

set_if_blank schottky_mun schottky_mun=1500.0
add_dialog entry\
	schottky_mun\
	"label_head=Mobility:"\
	width=12\
	"def_val=$(schottky_mun)"\
	"help_text=Electron mobility"\
	"label_tail=cm^2/Vs"

set_if_blank schottky_eps_r schottky_eps_r=11.9
add_dialog entry\
	schottky_eps_r\
	"label_head=Relative permittivity:"\
	width=12\
	"def_val=$(schottky_eps_r)"\
	"help_text=Relative permittivity"\
	"label_tail="

set_if_blank schottky_dn schottky_dn=1000.0
add_dialog entry\
	schottky_dn\
	"label_head=Semiconductor thickness:"\
	width=12\
	"def_val=$(schottky_dn)"\
	"help_text=Thickness used for series resistance"\
	"label_tail=nm"
add_dialog pack_frame dummy

add_dialog frame dummy "bg=#ececec" "relief=groove"

set_if_blank schottky_n_tunnel schottky_n_tunnel=2.0
add_dialog entry\
	schottky_n_tunnel\
	"label_head=Tunneling ideality:"\
	width=12\
	"def_val=$(schottky_n_tunnel)"\
	"help_text=Used only for model=Tunneling"\
	"label_tail="

set_if_blank schottky_v0 schottky_v0=-2.0
add_dialog entry\
	schottky_v0\
	"label_head=V start:"\
	width=10\
	"def_val=$(schottky_v0)"\
	"help_text=Start voltage"\
	"label_tail=V"

set_if_blank schottky_v1 schottky_v1=1.0
add_dialog entry\
	schottky_v1\
	"label_head=V end:"\
	width=10\
	"def_val=$(schottky_v1)"\
	"help_text=End voltage"\
	"label_tail=V"

set_if_blank schottky_step schottky_step=0.02
add_dialog entry\
	schottky_step\
	"label_head=V step:"\
	width=10\
	"def_val=$(schottky_step)"\
	"help_text=Voltage step"\
	"label_tail=V"
add_dialog pack_frame dummy

add_dialog message\
	dummy\
	"relief=raised"\
	width=900\
	fg=red\
	"text=schottky.py currently prints Model, phiB, V_bi, Js to console and shows the IV plot interactively.\
	It does not save png or txt automatically."

add_dialog frame dummy "bg=#ececec" "relief=groove"
add_dialog button dummy "text=simulate" "command=call [schottky_run]"
add_dialog button dummy "text=explorer" "command=call [explorer_schottky]"
add_dialog button dummy "text=cmd" "command=call [cmd_schottky]"
add_dialog button dummy "text=edit source"  "command=call [schottky_edit_source]"
add_dialog pack_frame dummy

custom_dialog "Schottky IV simulation" close

End

[schottky_edit_source]
join_path script "$(tkprog_X_path)" electrical schottky.py
$(start) "$(script)" 
End

[schottky_run]
write_ini $i "diode" "work_dir" "$(last_dir)"
chdir "$(last_dir)"

join_path script "$(tkprog_X_path)" electrical schottky.py
$(start_cmd_C) "$(python3_path)" "$(script)" \
  --model="$(schottky_model)" \
  --temp=$(schottky_temp) \
  --area=$(schottky_area) \
  --efm=$(schottky_efm) \
  --ecn=$(schottky_ecn) \
  --ndn=$(schottky_ndn) \
  --mun=$(schottky_mun) \
  --eps_r=$(schottky_eps_r) \
  --dn=$(schottky_dn) \
  --men=$(schottky_men) \
  --n_tunnel=$(schottky_n_tunnel) \
  --v0=$(schottky_v0) \
  --v1=$(schottky_v1) \
  --step=$(schottky_step)
End


[explorer_schottky]
write_ini $i "diode" "work_dir" "$(last_dir)"
chdir "$(last_dir)"
$(start) "$(filer_path)" "$(last_dir)"
End


[cmd_schottky]
write_ini $i "diode" "work_dir" "$(last_dir)"
chdir "$(last_dir)"
$(start) "$(shell_path)"
End

[Button12.Diode]
Caption=schottky help(Sphinx)
start $(sphinx_url_base)tkProg/electrical/schottky_index.html
End


[Button13.Diode]
Caption=pn junction IV sim

read_ini $i "diode" "work_dir" last_dir "."
chdir "$(last_dir)"

set_title pnjunction.py: Configure

new_dialog

add_dialog message\
	dummy\
	"relief=raised"\
	fg=blue\
	width=900\
	"text=PN junction IV characteristic simulation using pnjunction.py.\
	This script calculates Vbi and Js, and plots IV characteristics by matplotlib."

add_dialog frame dummy "bg=#ececec" "relief=groove"

set_if_blank pnj_temp pnj_temp=300.0
add_dialog entry\
	pnj_temp\
	"label_head=Temperature:"\
	width=12\
	"def_val=$(pnj_temp)"\
	"help_text=Simulation temperature"\
	"label_tail=K"

set_if_blank pnj_area pnj_area=0.01
add_dialog entry\
	pnj_area\
	"label_head=Area:"\
	width=12\
	"def_val=$(pnj_area)"\
	"help_text=Device area"\
	"label_tail=cm^2"

set_if_blank pnj_rs pnj_rs=10.0
add_dialog entry\
	pnj_rs\
	"label_head=Series resistance:"\
	width=12\
	"def_val=$(pnj_rs)"\
	"help_text=Series resistance"\
	"label_tail=ohm"
add_dialog pack_frame dummy

add_dialog message\
	dummy\
	"relief=raised"\
	fg=red\
	width=900\
	"text=n-side parameters"

add_dialog frame dummy "bg=#ececec" "relief=groove"

set_if_blank pnj_ndn pnj_ndn=1.0e16
add_dialog entry\
	pnj_ndn\
	"label_head=ND (n-side donor):"\
	width=15\
	"def_val=$(pnj_ndn)"\
	"help_text=Donor density in n region"\
	"label_tail=cm^-3"

set_if_blank pnj_ecn pnj_ecn=4.05
add_dialog entry\
	pnj_ecn\
	"label_head=EC reference:"\
	width=12\
	"def_val=$(pnj_ecn)"\
	"help_text=Conduction band reference / electron affinity-like parameter"\
	"label_tail=eV"

set_if_blank pnj_men pnj_men=0.19
add_dialog entry\
	pnj_men\
	"label_head=Electron m*/m0:"\
	width=12\
	"def_val=$(pnj_men)"\
	"help_text=Effective mass ratio on n side"\
	"label_tail="
add_dialog pack_frame dummy

add_dialog frame dummy "bg=#ececec" "relief=groove"

set_if_blank pnj_mun pnj_mun=1500.0
add_dialog entry\
	pnj_mun\
	"label_head=Electron mobility:"\
	width=12\
	"def_val=$(pnj_mun)"\
	"help_text=Electron mobility"\
	"label_tail=cm^2/Vs"

set_if_blank pnj_taun pnj_taun=1e-5
add_dialog entry\
	pnj_taun\
	"label_head=Electron lifetime:"\
	width=12\
	"def_val=$(pnj_taun)"\
	"help_text=Minority/transport lifetime parameter"\
	"label_tail=s"
add_dialog pack_frame dummy

add_dialog message\
	dummy\
	"relief=raised"\
	fg=red\
	width=900\
	"text=p-side parameters"

add_dialog frame dummy "bg=#ececec" "relief=groove"

set_if_blank pnj_nap pnj_nap=1.0e16
add_dialog entry\
	pnj_nap\
	"label_head=NA (p-side acceptor):"\
	width=15\
	"def_val=$(pnj_nap)"\
	"help_text=Acceptor density in p region"\
	"label_tail=cm^-3"

set_if_blank pnj_evp pnj_evp=5.17
add_dialog entry\
	pnj_evp\
	"label_head=EV reference:"\
	width=12\
	"def_val=$(pnj_evp)"\
	"help_text=Valence band reference"\
	"label_tail=eV"

set_if_blank pnj_mhp pnj_mhp=0.16
add_dialog entry\
	pnj_mhp\
	"label_head=Hole m*/m0:"\
	width=12\
	"def_val=$(pnj_mhp)"\
	"help_text=Effective mass ratio on p side"\
	"label_tail="
add_dialog pack_frame dummy

add_dialog frame dummy "bg=#ececec" "relief=groove"

set_if_blank pnj_mup pnj_mup=500.0
add_dialog entry\
	pnj_mup\
	"label_head=Hole mobility:"\
	width=12\
	"def_val=$(pnj_mup)"\
	"help_text=Hole mobility"\
	"label_tail=cm^2/Vs"

set_if_blank pnj_taup pnj_taup=1e-5
add_dialog entry\
	pnj_taup\
	"label_head=Hole lifetime:"\
	width=12\
	"def_val=$(pnj_taup)"\
	"help_text=Minority/transport lifetime parameter"\
	"label_tail=s"
add_dialog pack_frame dummy

add_dialog message\
	dummy\
	"relief=raised"\
	fg=red\
	width=900\
	"text=Voltage sweep"

add_dialog frame dummy "bg=#ececec" "relief=groove"

set_if_blank pnj_v0 pnj_v0=-1.0
add_dialog entry\
	pnj_v0\
	"label_head=V start:"\
	width=10\
	"def_val=$(pnj_v0)"\
	"help_text=Start voltage"\
	"label_tail=V"

set_if_blank pnj_v1 pnj_v1=1.0
add_dialog entry\
	pnj_v1\
	"label_head=V end:"\
	width=10\
	"def_val=$(pnj_v1)"\
	"help_text=End voltage"\
	"label_tail=V"

set_if_blank pnj_step pnj_step=0.02
add_dialog entry\
	pnj_step\
	"label_head=V step:"\
	width=10\
	"def_val=$(pnj_step)"\
	"help_text=Voltage step"\
	"label_tail=V"
add_dialog pack_frame dummy

add_dialog message\
	dummy\
	"relief=raised"\
	width=900\
	fg=red\
	"text=pnjunction.py prints calculated Vbi and Js to console and shows the IV plot interactively.\
	It does not save png or txt automatically."

add_dialog frame dummy "bg=#ececec" "relief=groove"
add_dialog button dummy "text=simulate" "command=call [pnjunction_run]"
add_dialog button dummy "text=explorer" "command=call [explorer_pnjunction]"
add_dialog button dummy "text=cmd" "command=call [cmd_pnjunction]"
add_dialog button dummy "text=edit source"  "command=call [pnjunction_edit_source]"
add_dialog pack_frame dummy

custom_dialog "PN junction IV simulation" close

End

[pnjunction_edit_source]
join_path script "$(tkprog_X_path)" electrical pnjunction.py
$(start) "$(script)" 
End

[pnjunction_run]
write_ini $i "diode" "work_dir" "$(last_dir)"
chdir "$(last_dir)"

join_path script "$(tkprog_X_path)" electrical pnjunction.py
$(start_cmd_C) "$(python3_path)" "$(script)" \
  --temp=$(pnj_temp) \
  --area=$(pnj_area) \
  --rs=$(pnj_rs) \
  --ndn=$(pnj_ndn) \
  --ecn=$(pnj_ecn) \
  --men=$(pnj_men) \
  --mun=$(pnj_mun) \
  --taun=$(pnj_taun) \
  --nap=$(pnj_nap) \
  --evp=$(pnj_evp) \
  --mhp=$(pnj_mhp) \
  --mup=$(pnj_mup) \
  --taup=$(pnj_taup) \
  --v0=$(pnj_v0) \
  --v1=$(pnj_v1) \
  --step=$(pnj_step)
End


[explorer_pnjunction]
write_ini $i "diode" "work_dir" "$(last_dir)"
chdir "$(last_dir)"
$(start) "$(filer_path)" "$(last_dir)"
End


[cmd_pnjunction]
write_ini $i "diode" "work_dir" "$(last_dir)"
chdir "$(last_dir)"
$(start) "$(shell_path)"
End


[Button15.Diode]
Caption=pnjunction help(Sphinx)
start $(sphinx_url_base)tkProg/electrical/pnjunction_index.html
End