
exit_if_not_exist $(tkprog_X_path)/ATLAS

[ATLAS].select
join_path section_root_dir "$(tkprog_X_path)" ATLAS
chdir "$(section_root_dir)"

add_tooltip  1 "Copy of sedatools shortcut" #FFFF00 #0000ff
add_tooltip  4 "Helper dialog for C-Interpreter" #FFFF00 #0000ff
End


[ATLAS_cmd]
chdir "$(atlas_dir)"
$(start_cmd_k)
End

[ATLAS_explorer]
chdir "$(atlas_dir)"
$(start) "$(filer_path)" "$(atlas_dir")
End

[ATLAS_deckbiuld]
join_path app_path "$(atlas_dir)" $(atlas_bin_dirname) deckbuild
$(start) "$(app_path)"
End
join_path app_path "$(atlas_dir)" etc GuiAppStarter.exe
$(start) "$(app_path)" -lib-dir-name deckbuild -exe-name deckbuild
End

[ATLAS_License_Server_Status]
join_path app_path "$(atlas_dir)" $(atlas_bin_dirname) sflm
$(start) "$(app_path)"
End
join_path app_path "$(atlas_dir)" exe sflm.exe
$(start) "$(app_path)" -status -wait-for-key
End

[ATLAS_SFLM_Access]
join_path app_path "$(atlas_dir)" $(atlas_bin_dirname) sflm_access
$(start) "$(app_path)"
End
join_path app_path "$(atlas_dir)" etc GuiAppStarter.exe
$(start) "$(app_path)" -lib-dir-name sflm_access -exe-name sflm_access
End

[ATLAS_TonyPlot]
join_path app_path "$(atlas_dir)" $(atlas_bin_dirname) tonyplot
$(start) "$(app_path)"
End
join_path app_path "$(atlas_dir)" etc GuiAppStarter.exe
$(start) "$(app_path)" -lib-dir-name tonyplot3d -exe-name tonyplot
End

[ATLAS_TonyPlot3D]
join_path app_path "$(atlas_dir)" $(atlas_bin_dirname) topyplot3d
$(start) "$(app_path)"
End
join_path app_path "$(atlas_dir)" etc GuiAppStarter.exe
$(start) "$(app_path)" -lib-dir-name tonyplot3d -exe-name tonyplot3d
End

[ATLAS_UserConfig]
join_path app_path "$(atlas_dir)" exe sflm_monitord.exe
$(start) "$(app_path)" -wait-for-key -env
End

[ATLAS_CurrentUsers]
join_path app_path "$(atlas_dir)" exe sflm.exe
$(start) "$(app_path)" -users -wait-for-key
End

[ATLAS_Management_Console]
join_path app_path "$(atlas_dir)" $(atlas_bin_dirname) sman
$(start) "$(app_path)"
End
join_path app_path "$(atlas_dir)" etc GuiAppStarter.exe
$(start) "$(app_path)" -lib-dir-name sman -exe-name sman
End

[ATLAS_DevEdit]
join_path app_path "$(atlas_dir)" etc GuiAppStarter.exe
$(start) "$(app_path)" -lib-dir-name devedit -exe-name devedit
End

[ATLAS_Editor]
join_path app_path "$(atlas_dir)" $(atlas_bin_dirname) sedit
$(start) "$(app_path)"
End
join_path app_path "$(atlas_dir)" etc GuiAppStarter.exe
$(start) "$(app_path)" -lib-dir-name sedit -exe-name sedit
End

[ATLAS_shocrtcuts]
join_path shortcut_path "$(atlas_dir)" Shortcuts
$(start) "$(filer_path)" "$(shortcut_path)"
End

[ATLAS_show_atlas_apps]
Caption=ATLAS apps

read_ini $i "ATLAS" "deckbuild_path" deckbuild_path "deckbuild"
get_app_path deckbuild_path $(exe_fmask) "deckbuildの場所を指定してください"
write_ini $i "ATLAS" "deckbuild_path" "$(deckbuild_path)"

get_directory "$(deckbuild_path)" atlas_exe_dir
get_upper_directory "$(atlas_exe_dir)" atlas_dir
echo atlas_exe_dir: $(atlas_exe_dir)
echo atlas_dir: $(atlas_dir)

set_title ATLAS configuration: $(atlas_dir)

new_dialog

add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "text=DeckBuild" "command=call [ATLAS_deckbiuld]"
add_dialog button dummy "text=TonyPlot" "command=call [ATLAS_TonyPlot]"
add_dialog button dummy "text=TonyPlot3D" "command=call [ATLAS_TonyPlot3D]"
add_dialog button dummy "text=DevEdit" "command=call [ATLAS_DevEdit]"
add_dialog button dummy "text=SEdit" "command=call [ATLAS_Editor]"
add_dialog pack_frame dummy

add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "text=Management console" "command=call [ATLAS_Management_Console]"
add_dialog pack_frame dummy

add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "text=Current users" "command=call [ATLAS_CurrentUsers]"
add_dialog button dummy "text=User config" "command=call [ATLAS_UserConfig]"
add_dialog button dummy "text=SFLM access" "command=call [ATLAS_SFLM_Access]"
add_dialog button dummy "text=License server status" "command=call [ATLAS_License_Server_Status]"
add_dialog pack_frame dummy

add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "text=shortcuts" "command=call [ATLAS_shocrtcuts]"
add_dialog pack_frame dummy

add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "text=cmd" "command=call [ATLAS_cmd]"
add_dialog button dummy "text=explorer" "command=call [ATLAS_explorer]"
add_dialog pack_frame dummy

custom_dialog "ATLAS: C-Interpreter" close

End

[ATLAS_run]
$(start_cmd_c) "$(deckbuild_path)" -run "$(input_path)"
End

[ATLAS_optimize]
$(start_cmd_c) "$(deckbuild_path)" -run "$(input_path)" -opt "$(xml_path)"
End

[ATLAS_compare]
join_path script_path "$(tkprog_X_path)" ATLAS plot_ATLAS.py
set mode=compare

$(start_cmd_c) "$(python_path)" "$(script_path)" $(mode) "$(parameter_path)" "$(measure_path)" "$(fitting_path)"
End

[ATLAS_compare2]
join_path script_path "$(tkprog_X_path)" ATLAS compare.py

$(start_cmd_c) "$(python_path)" "$(script_path)" "$(measure_path)" "$(fitting_path)"
End

[ATLAS_plot_DOS]
join_path script_path "$(tkprog_X_path)" ATLAS plot_DOS.py

$(start_cmd_c) "$(python_path)" "$(script_path)" "$(dos_path1)" "$(dos_path2)"
End

[ATLAS_plot_convergence]
get_filename "$(xml_path)" filename
get_directory "$(xml_path)" dirname
chdir "$(dirname)"
#join_path progress_path "$(dirname)" progress.opt
#join_path results_path "$(dirname)" results.opt

join_path script_path "$(tkprog_X_path)" ATLAS plot_convergence.py

#$(start_cmd_c) "$(python_path)" "$(script_path)" "$(xml_path)" "$(progress_path)" "$(results_path)"
$(start_cmd_c) "$(python_path)" "$(script_path)" "$(filename)" progress.opt results.opt
End

[C-Interpreter_initialize]
set mode=init
call [C-Interpreter_execute]
End

[C-Interpreter_initialize_debug]
set mode=init
call [C-Interpreter_execute_debug]
End

[C-Interpreter_simulate]
set mode=sim
call [C-Interpreter_execute]
End

[C-Interpreter_fit]
set mode=fit
call [C-Interpreter_execute]
End

[C-Interpreter_cmd]
get_directory "$(input_path)" dir_name
write_ini $i "ATLAS" "work_dir" "$(dir_name)"
chdir "$(dir_name)"
$(start_cmd_k)
End

[C-Interpreter_explorer]
get_directory "$(input_path)" dir_name
write_ini $i "ATLAS" "work_dir" "$(dir_name)"
chdir "$(dir_name)"
$(start) "$(filer_path)" "$(dir_name")
End

[C-Interpreter_save]
get_directory "$(input_path)" dir_name
get_filename "$(input_path)" file_name
join_path parameter_path "$(dir_name)" "$(file_name)"
write_ini $i "ATLAS" "work_dir" "$(dir_name)"

write_ini $i "ATLAS" "deckbuild_path" "$(deckbuild_path)"
write_ini $i "ATLAS" "gcc_path" "$(gcc_path)"
End


[C-Interpreter_make]
get_directory "$(c_path)" dir_name
get_filebody "$(c_path)" file_body
set dll_path=$(file_body).dll

join_path mk_path "$(tkprog_X_path)" ATLAS mk$(batch_ext)

$(start_cmd_k) "$(mk_path)" "$(file_body)"
End

[C-Interpreter_run_exe]
get_directory "$(c_path)" dir_name
get_filebody "$(c_path)" file_body

join_path exe_path "$(dir_name)" "$(file_body)"

$(start_cmd_k) "$(exe_path)"
End

[C-Interpreter_plot_dll]
get_directory "$(c_path)" dir_name
get_filebody "$(c_path)" file_body

join_path script_path "$(tkprog_X_path)" ATLAS plot_dll.py
join_path dll_path "$(dir_name)" "$(file_body)$(dll_ext)"

$(start_cmd_c) "$(python_path)" "$(script_path)" "$(dll_path)"
End

[C-Interpreter_convert_input]
join_path convert_script "$(tkprog_X_path)" convert_ATLAS.py
set convert_mode=input

set args=log_file=$(log_file) cal_file=$(cal_file)
set args=$(args) nta1=1.0e17 wta1=0.004
set args=$(args) ntd1=1.0e17 wtd1=0.3
set args=$(args) nga1=1.0e17 ega1=0.0 wga1=0.7
set args=$(args) ngd1=1.0e17 egd1=0.2 wgd1=0.12
set args=$(args) temp=303
set args=$(args) qf1=1.0e5

$(start_cmd_c) "$(python_path)" "$(convert_script)" $(convert_mode) \
	"$(template_dir)" "$(template_file)" "$(parameter_path)" "$(input_file)" $(args)
End


[C-Interpreter_convert_C]
join_path convert_script "$(tkprog_X_path)" convert_ATLAS.py
set convert_mode=input
End

[C-Interpreter_run_executable]
set dll_path=IGOX.dll
get_directory "$(dll_path)" dir_name
get_filebody "$(dll_path)" file_body

join_path dll_filebody_path "$(dir_name)" "$(file_body)"

$(start_cmd_c) "$(dll_body_path)"
End

[C-Interpreter_execute]
set ATLAS_dir=c:/sedatools/exe
:set ATLAS_version=5.0.10.R
:set ATLAS_version=5.2.8.R
:set ATLAS_version=5.2.23.R

set convert_script=../bin/convert_ATLAS.py
set convert_mode=input

set template_dir=./template
set parameter_path=303K_Vd01.prm
set template_file=303K_Vd01.in

set output_file=303K_Vd01.out
set input_file=%template_file%
set log_file=id-vg_vd=001.log

set measure_file=idvg_meas.dat
set cal_file=idvg_calc_1sub.dat

:goto END


echo.
echo "run [%ATLAS_dir%/deckbuild -run %input_file%]"
%ATLAS_dir%/deckbuild -run %input_file% -outfile %output_file%
End


[C-Interpreter_compare]
get_directory "$(input_path)" dir_name
#get_directory "$(measurement_data_path)" dir_name
write_ini $i "ATLAS" "work_dir" "$(dir_name)"

join_path script_path "$(tkprog_X_path)" ATLAS plot_ATLAS.py
set mode=IV

$(start_cmd_c) "$(python_path)" "$(script_path)" $(mode) "$(measurement_data_path)" "$(sim_path1)" "$(sim_path2)"
End

[ATLAS_XML_Viewer]
join_path script "$(tkprog_X_path)" Viewer XMLView.py
$(start_cmd_c) "$(python3_path)" "$(script)" "$(xml_path)"
End

[ATLAS_XML_Viewer2]
join_path script "$(tkprog_X_path)" Viewer xml_viewer.py
$(start_cmd_c) "$(python3_path)" "$(script)" "$(xml_path)"
End

[Button1.ATLAS]
Caption=ATLAS apps
call [ATLAS_show_atlas_apps]
End

[Button4.ATLAS]
Caption=optimize_ATLAS

read_ini $i "ATLAS" "deckbuild_path" deckbuild_path "deckbuild"
read_ini $i "ATLAS" "work_dir" work_dir "."
read_ini $i "ATLAS" "template_dir" ATLAS_template_dir ""
read_ini $i "ATLAS" "ATLAS_template_in_path" ATLAS_template_in_path ""
read_ini $i "ATLAS" "ATLAS_template_c_path"  ATLAS_template_c_path ""
chdir $(work_dir)

get_app_path deckbuild_path $(exe_fmask) "deckbuildの場所を指定してください"
write_ini $i "ATLAS" "deckbuild_path" "$(deckbuild_path)"

join_path script $(tkprog_X_path) electrical mu-T-Fit2.py

get_open_file_name "*.xlsx" "$(work_dir)"  ATLAS 入力データファイル (*.xlsx) を選択してください
echo file:$o
set input_path=$o
get_directory "$o" work_dir
get_filebody  "$o" data_file_fbody
get_filename  "$o" data_file_name
get_last_directory "$(work_dir)" work_last_dir
write_ini $i "ATLAS" "work_dir" "$(work_dir)"

read_labels $(input_path) labels

join_path parameter_path "$(work_dir)" "$(data_file_fbody)_parameters.csv"

set_title optimize_ATLAS: $(work_dir)

set_if_blank method_ATLAS method_ATLAS=nelder-mead
set_if_blank x_label x_label=Vg
set_if_blank y_label y_label=Id

# Fitting
set_if_blank tol tol=1.0e-8
set_if_blank nmaxiter nmaxiter=1000
set_if_blank y_scale_ATLAS y_scale_ATLAS=log

new_dialog

add_dialog message\
	dummy\
	"relief=raised"\
	width=800\
	fg=blue\
	"text=optimize_ATLAS.pyを利用したTFTシミュレーションの最適化"

add_dialog choose_file\
	deckbuild_path\
	"label_head=deckbuild path:"\
	entry_width=50\
	"def_val=$(deckbuild_path)"\
	initialdir=.\
	"file_type=Exec:$(exe_fmask)"\
	"label_tail="

set_if_blank input_path input_path=
add_dialog choose_file\
	input_path\
	"label_head=IV data path:"\
	entry_width=50\
	"def_val=$(input_path)"\
	initialdir=.\
	"file_type=IV data file:*.xlsx"\
	"label_tail="

set_if_blank ATLAS_template_dir ATLAS_template_dir=
add_dialog choose_dir\
	ATLAS_template_dir\
	"label_head=template path:"\
	entry_width=50\
	initialdir=$(ATLAS_template_dir)\
	state=readonly\
	show_path_button=1\
	"label_tail="

set_if_blank ATLAS_template_in_path ATLAS_template_in_path=
add_dialog choose_file\
	ATLAS_template_in_path\
	"label_head=ATLAS input template path:"\
	entry_width=50\
	"def_val=$(ATLAS_template_in_path)"\
	initialdir=.\
	"file_type=ATLAS input:*.in"\
	"label_tail="

set_if_blank ATLAS_template_c_path ATLAS_template_c_path=
add_dialog choose_file\
	ATLAS_template_c_path\
	"label_head=C-Interprter template path:"\
	entry_width=50\
	"def_val=$(ATLAS_template_c_path)"\
	initialdir=.\
	"file_type=C source:*.c"\
	"label_tail="

set_if_blank parameter_path parameter_path=
add_dialog choose_file\
	parameter_path\
	"label_head=parameter path:"\
	entry_width=50\
	"def_val=$(parameter_path)"\
	initialdir=.\
	"file_type=parameter:*.prm"\
	"label_tail="

add_dialog label label1 "text=アルゴリズム:"\
	"fg=red"\
	"style=bold"

add_dialog combobox\
	method_ATLAS\
	"label_head=method:"\
	state=readonly\
	width=80\
	height=15\
	"init_val=nelder-mead"\
	"def_val=$(method_ATLAS)"\
	"nelder-mead # Downhill simplex"\
	"cg          # conjugate gradient"\
	"bfgs        # BFGS法"\
	"label_tail="

add_dialog label label1 "text=データを選択:"\
	"fg=red"\
	"style=bold"

add_dialog frame dummy "relief=groove"
add_dialog combobox\
	x_label\
	width=40\
	height=5\
	state=readonly\
	"label_head=x:"\
	"init_val=$(x_label)"\
	"values=$(labels)"\ 
	"label_tail="

add_dialog combobox\
	y_label\
	"label_head=y:"\
	state=readonly\
	width=40\
	height=5\
	"init_val=$(y_label)"\
	"values=$(labels)"\ 
	"label_tail="
add_dialog pack_frame dummy

add_dialog label label1 "text=フィッティング条件:"\
	"fg=red"\
	"style=bold"

add_dialog frame dummy "relief=groove"
add_dialog entry \
	tol\
	"label_head=tol:"\
	width=15\
	"def_val=1.0e-8"\
	"init_val=$(tol)"\
	"help_text=収束判定条件"\
	"label_tail=収束判定条件"

add_dialog spinbox \
	nmaxiter\
	var_type=int\
	"label_head=nmaxiter:"\
	entry_width=5\
	"def_val=1000"\
	"init_val=$(nmaxiter)"\
	from=10\
	to=3000\
	increment=100\
	"help_text=最大繰り返し回数"\
	"label_tail=最大繰り返し回数"
add_dialog pack_frame dummy


add_dialog frame dummy "relief=groove"
add_dialog combobox\
	y_scale_ATLAS\
	"label_head=Y scale:"\
	state=readonly\
	width=10\
	height=15\
	"init_val=log"\
	"def_val=$(y_scale_ATLAS)"\
	"linear"\
	"log"\
	"label_tail="
add_dialog pack_frame dummy

add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "text=plot" "command=call [ATLAS_plot]"
add_dialog button dummy "text=init" "command=call [ATLAS_init]"
add_dialog button dummy "text=edit in file" "command=call [ATLAS_edit_in]"
add_dialog button dummy "text=edit parameters" "command=call [ATLAS_edit_parameters]"
add_dialog button dummy "text=sim" "command=call [ATLAS_sim]"
add_dialog button dummy "text=nl fit for linear params" "command=call [ATLAS_fitlp]"
add_dialog button dummy "text=nonliner fit" "command=call [ATLAS_fit]"
add_dialog button dummy "text=error" "command=call [ATLAS_error]"
add_dialog button dummy "text=plot IV" "command=call [ATLAS_plot_IV]"
add_dialog button dummy "text=plot DOS" "command=call [ATLAS_plot_DOS]"
add_dialog button dummy "text=plot DLL" "command=call [ATLAS_plot_DLL]"
add_dialog pack_frame dummy

add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "text=update" "command=call [ATLAS_update]"
add_dialog button dummy "text=edit ATLAS input file" "command=call [ATLAS_edit_ATLAS_in]"
add_dialog button dummy "text=edit C-Interpreter file" "command=call [ATLAS_edit_ATLAS_C]"
add_dialog pack_frame dummy

add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "text=edit ATLAS input template file" "command=call [ATLAS_edit_ATLAS_in_template]"
add_dialog button dummy "text=edit C-Interpreter template file" "command=call [ATLAS_edit_ATLAS_C_template]"
add_dialog button dummy "text=input example" "command=call [ATLAS_input_example]"
add_dialog pack_frame dummy

add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "text=ATLAS apps" "command=call [ATLAS_show_atlas_apps]"
add_dialog button dummy "text=DeckBuild" "command=call [ATLAS_deckbiuld]"
add_dialog button dummy "text=cmd" "command=call [cmd_ATLAS]"
add_dialog button dummy "text=explorer" "command=call [explorer_ATLAS]"
add_dialog pack_frame dummy

custom_dialog "ATLAS: C-Interpreter" close

End

[ATLAS_input_example]
join_path file_path $(tkprog_X_path) ATLAS optimize_ATLAS TFT_simpole input_data.xlsx
$(start) "$(file_path)"
End

[cmd_ATLAS]
get_directory "$(input_path)" dir_name
chdir "$(dir_name)"
$(start_cmd_k)
End

[explorer_ATLAS]
get_directory "$(input_path)" dir_name
chdir "$(dir_name)"
$(start) "$(filer_path)" "$(dir_name)"
End

[ATLAS_edit_ATLAS_in_template]
write_ini $i "ATLAS" "template_dir" "$(ATLAS_template_dir)"
write_ini $i "ATLAS" "ATLAS_template_in_path" "$(ATLAS_template_in_path)"
write_ini $i "ATLAS" "ATLAS_template_c_path" "$(ATLAS_template_c_path)"
$(start) "$(editor_path)" "$(ATLAS_template_in_path)"
End

[ATLAS_edit_ATLAS_C_template]
write_ini $i "ATLAS" "template_dir" "$(ATLAS_template_dir)"
write_ini $i "ATLAS" "ATLAS_template_in_path" "$(ATLAS_template_in_path)"
write_ini $i "ATLAS" "ATLAS_template_c_path" "$(ATLAS_template_c_path)"
$(start) "$(editor_path)" "$(ATLAS_template_c_path)"
End

[ATLAS_edit_ATLAS_in]
get_filename  "$(ATLAS_template_in_path)" filename
write_ini $i "ATLAS" "template_dir" "$(ATLAS_template_dir)"
write_ini $i "ATLAS" "ATLAS_template_in_path" "$(ATLAS_template_in_path)"
write_ini $i "ATLAS" "ATLAS_template_c_path" "$(ATLAS_template_c_path)"
join_path ATLAS_input_path "$(dir_name)" "$(filename)"
$(start) "$(editor_path)" "$(ATLAS_input_path)"
End

[ATLAS_edit_ATLAS_C]
get_filename  "$(ATLAS_template_c_path)" filename
write_ini $i "ATLAS" "template_dir" "$(ATLAS_template_dir)"
write_ini $i "ATLAS" "ATLAS_template_in_path" "$(ATLAS_template_in_path)"
write_ini $i "ATLAS" "ATLAS_template_c_path" "$(ATLAS_template_c_path)"
join_path ATLAS_C_path "$(dir_name)" "$(filename)"
$(start) "$(editor_path)" "$(ATLAS_C_path)"
End

[ATLAS_edit_in]
get_directory "$(input_path)" dir_name
get_filebody  "$(input_path)" fbody
write_ini $i "ATLAS" "work_dir" "$(dir_name)"

join_path infile_path "$(dir_name)" "$(fbody).in"
$(start_cmd_c) "$(editor_path)" "$(infile_path)"
End

[ATLAS_edit_parameters]
get_directory "$(input_path)" dir_name
get_filebody  "$(input_path)" fbody
write_ini $i "ATLAS" "work_dir" "$(dir_name)"

join_path parameterfile_path "$(dir_name)" "$(fbody)_parameters.csv"
$(start_cmd_c) "$(editor_path)" "$(parameterfile_path)"
End

[ATLAS_init]
set mode=init
remove_comment method_ATLAS
write_ini $i "ATLAS" "work_dir" "$(dir_name)"

call [exec_optimize_ATLAS]
End

[ATLAS_update]
set mode=update
remove_comment method_ATLAS
write_ini $i "ATLAS" "work_dir" "$(dir_name)"

call [exec_optimize_ATLAS]
End

[ATLAS_fit]
set mode=fit
remove_comment method_ATLAS
write_ini $i "ATLAS" "work_dir" "$(dir_name)"

call [exec_optimize_ATLAS]
End

[ATLAS_fitlp]
set mode=fitlp
remove_comment method_ATLAS
write_ini $i "ATLAS" "work_dir" "$(dir_name)"

call [exec_optimize_ATLAS]
End

[ATLAS_plot]
set mode=plot
remove_comment method_ATLAS
write_ini $i "ATLAS" "work_dir" "$(dir_name)"

call [exec_optimize_ATLAS]
End

[ATLAS_sim]
set mode=sim
remove_comment method_ATLAS
write_ini $i "ATLAS" "work_dir" "$(dir_name)"

call [exec_optimize_ATLAS]
End

[ATLAS_error]
set mode=error
remove_comment method_ATLAS
write_ini $i "ATLAS" "work_dir" "$(dir_name)"
call [exec_optimize_ATLAS]
End

[ATLAS_plot_DLL]
set mode=plot_dll
remove_comment method_ATLAS
write_ini $i "ATLAS" "work_dir" "$(dir_name)"
call [exec_optimize_ATLAS]
End

[ATLAS_plot_IV]
set mode=plot_iv
remove_comment method_ATLAS
write_ini $i "ATLAS" "work_dir" "$(dir_name)"
call [exec_optimize_ATLAS]
End

[ATLAS_plot_DOS]
set mode=plot_dos
remove_comment method_ATLAS
write_ini $i "ATLAS" "work_dir" "$(dir_name)"
call [exec_optimize_ATLAS]
End

[exec_optimize_ATLAS]
join_path optimize_script $(tkprog_X_path) ATLAS optimize_ATLAS optimize_ATLAS.py

$(start_cmd_c) "$(python_path)" "$(optimize_script)" $(mode) --infile="$(input_path)"\
	--xlabel="$(x_label)"\
	--ylabel="$(y_label)"\
	--method=$(method_ATLAS)\
	--nmaxiter=$(nmaxiter)\
	--tol=$(tol)\
	--y_scale=$(y_scale_ATLAS)
End

[Button5.ATLAS]
Caption=ATLAS

read_ini $i "ATLAS" "deckbuild_path" deckbuild_path "deckbuild"
read_ini $i "ATLAS" "gcc_path" gcc_path "gcc"
read_ini $i "ATLAS" "work_dir" work_dir "."
chdir $(work_dir)

get_app_path deckbuild_path $(exe_fmask) "deckbuildの場所を指定してください"
#echo deckbuild_path: $(deckbuild_path)
write_ini $i "ATLAS" "deckbuild_path" "$(deckbuild_path)"

join_path script $(tkprog_X_path) electrical mu-T-Fit2.py

get_open_file_name "*.in" "$(work_dir)"  ATLAS inputファイル (*.in) を選択してください
echo file:$o
set input_path=$o
get_directory "$o" work_dir
get_filebody  "$o" data_file_fbody
get_filename  "$o" data_file_name
get_last_directory "$(work_dir)" work_last_dir

join_path parameter_path "$(work_dir)" "$(data_file_fbody).prm"

set_title ATLAS: C-Interpreter: $(work_dir)


new_dialog

set_if_blank template_dir template_dir=./template
add_dialog choose_dir\
	template_dir\
	"label_head=template dir:"\
	entry_width=50\
	"def_val=$(template_dir)"\
	initialdir=.\
	"file_type=C source:*.c"\
	"label_tail="

add_dialog label label1 "text=Convert:"\
	"fg=blue"\
	size=8\
	"style=bold"
add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "text=convert input" "command=call [C-Interpreter_convert_input]"
add_dialog pack_frame dummy


#============================================================
# Simulation
#============================================================
add_dialog tab dummy "text=simulate"

add_dialog message\
	dummy\
	"relief=raised"\
	width=800\
	fg=blue\
	"text=C-Interpreterを利用したATLASの実行を支援します"

set_if_blank parameter_path parameter_path=
add_dialog choose_file\
	parameter_path\
	"label_head=parameter path:"\
	entry_width=40\
	"def_val=$(parameter_path)"\
	state=readonly\
	show_path_button=0\
	"label_tail="

set_if_blank input_path input_path=
add_dialog choose_file\
	input_path\
	"label_head=ATLAS input path:"\
	entry_width=50\
	"def_val=$(input_path)"\
	initialdir=.\
	"file_type=ATLAS input:*.in"\
	"label_tail="

set_if_blank measurement_data_path measurement_data_path=
add_dialog choose_file\
	measurement_data_path\
	"label_head=measurement data path:"\
	entry_width=50\
	"def_val=$(measurement_data_path)"\
	initialdir=.\
	"file_type=Excel:*.xlsx"\
	"label_tail="

set_if_blank sim_path1 sim_path1=
add_dialog choose_file\
	sim_path1\
	"label_head=simulation data path1(.log):"\
	entry_width=50\
	"def_val=$(sim_path1)"\
	initialdir=.\
	"file_type=ATLAS .log:*.log"\
	"label_tail="

set_if_blank sim_path2 sim_path2=
add_dialog choose_file\
	sim_path2\
	"label_head=simulation data path2(.log):"\
	entry_width=50\
	"def_val=$(sim_path2)"\
	initialdir=.\
	"file_type=ATLAS .log:*.log"\
	"label_tail="

add_dialog label label1 "text=Simulate:"\
	"fg=blue"\
	size=8\
	"style=bold"

add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "text=simulate"        "command=call [ATLAS_run]"
#add_dialog button dummy "text=edit prm"        "command=call [C-Interpreter_edit_param]"
add_dialog button dummy "text=compare"  "command=call [C-Interpreter_compare]"
add_dialog pack_frame dummy

add_dialog reset_tab dummy


#============================================================
# Optimizer
#============================================================
add_dialog tab dummy "text=optimizer"

set_if_blank parameter_path parameter_path=
add_dialog choose_file\
	parameter_path\
	"label_head=parameter path:"\
	entry_width=50\
	"def_val=$(parameter_path)"\
	initialdir=.\
	"file_type=parameter:*.prm"\
	"label_tail="

set_if_blank input_path input_path=
add_dialog choose_file\
	input_path\
	"label_head=ATLAS input path:"\
	entry_width=50\
	"def_val=$(input_path)"\
	initialdir=.\
	"file_type=ATLAS input:*.in"\
	"label_tail="

set_if_blank measure_path measure_path=
add_dialog choose_file\
	measure_path\
	"label_head=measurement data path(.dat):"\
	entry_width=50\
	"def_val=$(measure_path)"\
	initialdir=.\
	"file_type=ATLAS .dat:*.dat"\
	"label_tail="

set_if_blank fitting_path fitting_path=
add_dialog choose_file\
	fitting_path\
	"label_head=fitting data path(.dat):"\
	entry_width=50\
	"def_val=$(fitting_path)"\
	initialdir=.\
	"file_type=ATLAS .dat:*.dat"\
	"label_tail="

set_if_blank dos_path1 dos_path1=
add_dialog choose_file\
	dos_path1\
	"label_head=DOS data path1(.out):"\
	entry_width=50\
	"def_val=$(dos_path1)"\
	initialdir=.\
	"file_type=ATLAS DOS .out:*.out"\
	"label_tail="

set_if_blank dos_path2 dos_path2=
add_dialog choose_file\
	dos_path2\
	"label_head=DOS data path2(.out):"\
	entry_width=50\
	"def_val=$(dos_path2)"\
	initialdir=.\
	"file_type=ATLAS DOS .out:*.out"\
	"label_tail="

set_if_blank xml_path xml_path=
add_dialog choose_file\
	xml_path\
	"label_head=XML path:"\
	entry_width=50\
	"def_val=$(xml_path)"\
	initialdir=.\
	"file_type=XML:*.xml"\
	"label_tail="

add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "text=optimize" "command=call [ATLAS_optimize]"
add_dialog pack_frame dummy

add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "label_head=plot:" "text=fitting result" "command=call [ATLAS_compare]"
add_dialog button dummy "text=fitting result (simple)" "command=call [ATLAS_compare2]"
add_dialog button dummy "text=DOS (simple)" "command=call [ATLAS_plot_DOS]"
add_dialog button dummy "text=convergence" "command=call [ATLAS_plot_convergence]"
add_dialog pack_frame dummy

add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "text=XML View"  "command=call [ATLAS_XML_Viewer]"
add_dialog button dummy "text=XML View2" "command=call [ATLAS_XML_Viewer2]"
add_dialog pack_frame dummy

add_dialog reset_tab dummy


#============================================================
# C-Interpreter設定
#============================================================
add_dialog tab dummy "text=C-Interplreter"

set_if_blank c_path c_path=
add_dialog choose_file\
	c_path\
	"label_head=C-Interprter source path:"\
	entry_width=80\
	"def_val=$(c_path)"\
	initialdir=.\
	"file_type=C source:*.c"\
	"label_tail="

add_dialog label label1 "text=Convert:"\
	"fg=blue"\
	size=8\
	"style=bold"
add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "text=convert C" "command=call [C-Interpreter_convert_C]"
add_dialog pack_frame dummy

add_dialog label label1 "text=C-Interpreter:"\
	"fg=blue"\
	size=8\
	"style=bold"
add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "text=make executable/dll" "command=call [C-Interpreter_make]"
add_dialog button dummy "text=run executable" "command=call [C-Interpreter_run_exe]"
add_dialog button dummy "text=plot DLL" "command=call [C-Interpreter_plot_dll]"
add_dialog pack_frame dummy

add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "text=save" "command=call [C-Interpreter_save]"
add_dialog pack_frame dummy

add_dialog reset_tab dummy


#============================================================
# ATLASのディレクトリ設定
#============================================================

add_dialog tab dummy "text=ATLAS config"

add_dialog message\
	dummy\
	"relief=raised"\
	width=800\
	fg=blue\
	"text=ATLASのディレクトリを設定"

add_dialog choose_file\
	deckbuild_path\
	"label_head=deckbuild path:"\
	entry_width=50\
	"def_val=$(deckbuild_path)"\
	initialdir=.\
	"file_type=Exec:$(exe_fmask)"\
	"label_tail="

set_if_blank gcc_path gcc_path=gcc
add_dialog choose_file\
	gcc_path\
	"label_head=gcc path:"\
	entry_width=50\
	"def_val=$(deckbuild_path)"\
	initialdir=.\
	"file_type=Exec:$(exe_fmask)"\
	"label_tail="

add_dialog reset_tab dummy


add_dialog label label1 "text=misc:"\
	"fg=blue"\
	size=8\
	"style=bold"

add_dialog frame dummy "bg=blue" "relief=groove"
add_dialog button dummy "text=ATLAS apps" "command=call [ATLAS_show_atlas_apps]"
add_dialog button dummy "text=DeckBuild" "command=call [ATLAS_deckbiuld]"
add_dialog button dummy "text=cmd" "command=call [C-Interpreter_cmd]"
add_dialog button dummy "text=explorer" "command=call [C-Interpreter_explorer]"
add_dialog pack_frame dummy

custom_dialog "ATLAS: C-Interpreter" close

get_directory "$(input_path)" dir_name
write_ini $i "ATLAS" "work_dir" "$(dir_name)"

write_ini $i "ATLAS" "deckbuild_path" "$(deckbuild_path)"
write_ini $i "ATLAS" "gcc_path" "$(gcc_path)"

End
