// File: /workspace/github_cpp_makefile_star2_O2/TBody[P]atomicpp/atomicpp/ImpuritySpecies.cpp
// Function: atomicpp::ImpuritySpecies::ImpuritySpecies(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
ImpuritySpecies::ImpuritySpecies(std::string& impurity_symbol_supplied){
	// Constructor for the ImpuritySpecies class
	// Input is a std::string, which typically should be of length 1 (i.e. "c" for carbon, "n" for nitrogen)
	// Will return an ImpuritySpecies object
	
	// Convert impurity_symbol_supplied to lowercase (this is what impurity_user_input uses as a key)
	impurity_symbol_supplied[0] = tolower(impurity_symbol_supplied[0]);

	// Declare the path to the JSON file which contains hard-coded parameters for the ADAS data corresponding to the impurities
	// std::string user_file = get_impurity_user_input();
	std::string user_file = "impurity_user_input.json";

	// Declare the path the directory which contains the JSON files created from OpenADAS .dat files
	// To convert .dat to .json, see https://github.com/TBody/OpenADAS_to_JSON (should be included as a subdirectory of SD1D)
	// std::string json_database_path = get_json_database_path();
	std::string json_database_path = "json_database/json_data";

	// Define a std::map between a recognisable key for various physics process, and the 3-letter code used by OpenADAS to represent this data
	std::map<std::string,std::string>datatype_abbrevs={
		{"ionisation",           "scd"},
		{"recombination",        "acd"},
		{"cx_rec",              "ccd"},
		{"continuum_power",      "prb"},
		{"line_power",           "plt"},
		{"cx_power",             "prc"},
		{"ionisation_potential", "ecd"} //N.b. ionisation_potential is not a rate-coefficient, but most of the methods are transferable
	};

	// Save from impurity_symbol_supplied and the hard-coded data within user_file
	symbol              = impurity_symbol_supplied;
	// retrieve from JSON and std::set attributes
	
	json j_object = retrieveFromJSON(user_file);
	auto check_symbol_in_file = j_object.find(impurity_symbol_supplied);
	if ((check_symbol_in_file != j_object.end())){
		name                = j_object[impurity_symbol_supplied]["name"];
		year                = j_object[impurity_symbol_supplied]["year"];
		has_charge_exchange = j_object[impurity_symbol_supplied]["has_charge_exchange"];
		atomic_number       = j_object[impurity_symbol_supplied]["atomic_number"];
		double mass_in_amu  = j_object[impurity_symbol_supplied]["mass"]; //in amu
		mass                = mass_in_amu;
	} else {
		std::cout << "Error: "<< impurity_symbol_supplied << " not found in " << user_file << "\n";
		throw std::invalid_argument( "Key not found in user input file" );
	};

	// Add the JSON files associated with this impurity to its .adas_files_dict attribute where the key is the (extended) process name, which std::maps to a filename (std::string)
	// Mark the physics processes which rely on charge exchange
	std::set<std::string> cx_processes{datatype_abbrevs["cx_rec"],datatype_abbrevs["cx_power"]};
	// Iterate over the key -> value pairs in datatype_abbrevs
	for (auto& kv : datatype_abbrevs) {
		std::string physics_process = kv.first;
		std::string filetype_code = kv.second;
		// Check to see if physics_process is a charge exchange process
		bool code_is_cx = find(begin(cx_processes), end(cx_processes), filetype_code) != end(cx_processes);
		// If it is, and the element doesn't have charge exchange data, then skip this process
		if (get_has_charge_exchange() or not(code_is_cx)){
			// Otherwise, add the filenames of the json files corresponding to the rate-coefficients for the physics process to .adas_files_dict
		    addJSONFiles(physics_process, filetype_code, json_database_path);
		};
	}

	// Use the .adas_file_dict files to generate RateCoefficient objects for each process
	// Uses the same keys as .adas_file_dict
	makeRateCoefficients();

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x358, %rsp            # imm = 0x358
movq %rsi, %r13
movq %rdi, %r15
callq 0x4300
leaq 0x20(%r15), %rdi
movq %rdi, -0x68(%rbp)
callq 0x4300
leaq 0x58(%r15), %r14
movq %r14, %rdi
callq 0xc3f2
leaq 0x88(%r15), %rdi
movq %rdi, -0x78(%rbp)
callq 0xc3fc
movq %r13, %rdi
xorl %esi, %esi
callq 0x4640
movsbl (%rax), %edi
callq 0x4490
movl %eax, %ebx
movq %r13, %rdi
xorl %esi, %esi
callq 0x4640
movb %bl, (%rax)
leaq -0x378(%rbp), %rbx
movq %rbx, %rdi
callq 0x4540
leaq 0x176a2(%rip), %rsi     # 0x22770
leaq -0xd8(%rbp), %rdi
movq %rbx, %rdx
callq 0x4160
leaq -0x378(%rbp), %rdi
callq 0x58aa
movq %rbx, %rdi
callq 0x4540
leaq 0x17691(%rip), %rsi     # 0x22789
leaq -0x188(%rbp), %rdi
movq %rbx, %rdx
callq 0x4160
movq %r14, -0x38(%rbp)
leaq -0x378(%rbp), %rdi
callq 0x58aa
leaq 0x15f22(%rip), %rsi     # 0x21040
leaq 0x1767c(%rip), %rdx     # 0x227a1
movq %rbx, %rdi
callq 0xc406
leaq -0x338(%rbp), %r14
leaq 0x15f10(%rip), %rsi     # 0x2104b
leaq 0x17663(%rip), %rdx     # 0x227a5
movq %r14, %rdi
callq 0xc4a0
leaq -0x2f8(%rbp), %r14
leaq 0x17651(%rip), %rsi     # 0x227a9
leaq 0x17651(%rip), %rdx     # 0x227b0
movq %r14, %rdi
callq 0xc53a
leaq -0x2b8(%rbp), %r14
leaq 0x1763f(%rip), %rsi     # 0x227b4
leaq 0x17648(%rip), %rdx     # 0x227c4
movq %r14, %rdi
callq 0xc5d4
leaq -0x278(%rbp), %r14
leaq 0x17636(%rip), %rsi     # 0x227c8
leaq 0x1763a(%rip), %rdx     # 0x227d3
movq %r14, %rdi
callq 0xc406
leaq -0x238(%rbp), %r14
leaq 0x17628(%rip), %rsi     # 0x227d7
leaq 0x1762a(%rip), %rdx     # 0x227e0
movq %r14, %rdi
callq 0xc66e
leaq -0x1f8(%rbp), %r14
leaq 0x17618(%rip), %rsi     # 0x227e4
leaq 0x17626(%rip), %rdx     # 0x227f9
movq %r14, %rdi
callq 0xc708
leaq -0xb8(%rbp), %rbx
movq %rbx, %rdi
callq 0xc7a2
leaq -0x168(%rbp), %rdi
leaq -0x378(%rbp), %rsi
pushq $0x7
popq %rdx
leaq -0x1b8(%rbp), %rcx
movq %rbx, %r8
callq 0xc7ac
leaq -0xb8(%rbp), %rdi
callq 0xc83e
movl $0x180, %ebx            # imm = 0x180
leaq (%rbx,%rbp), %rdi
addq $-0x378, %rdi           # imm = 0xFC88
callq 0x5854
addq $-0x40, %rbx
cmpq $-0x40, %rbx
jne 0xb21b
movq %r15, %rdi
movq %r13, %rsi
callq 0x4060
leaq -0x138(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x4480
movq %r15, -0x40(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x5c2c
leaq -0x138(%rbp), %rdi
callq 0x41a0
leaq -0x118(%rbp), %rdi
movq %r13, %rsi
callq 0x4480
leaq -0xb8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
leaq -0x118(%rbp), %rdx
callq 0xc844
leaq -0x118(%rbp), %rdi
callq 0x41a0
leaq -0x378(%rbp), %rbx
leaq -0x58(%rbp), %rsi
movq %rbx, %rdi
callq 0xc894
leaq -0xb8(%rbp), %rdi
movq %rbx, %rsi
callq 0xc886
testb %al, %al
je 0xb60f
leaq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x8c5e
leaq 0x1751b(%rip), %rsi     # 0x227fd
movq %rax, %rdi
callq 0xc8b4
leaq -0x378(%rbp), %rdi
movq %rax, %rsi
callq 0xc9f2
leaq -0x378(%rbp), %r12
movq -0x68(%rbp), %rdi
movq %r12, %rsi
callq 0x4420
movq %r12, %rdi
callq 0x41a0
leaq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x8c5e
leaq 0x174db(%rip), %rsi     # 0x22802
movq %rax, %rdi
callq 0xc8b4
movq %rax, %rdi
callq 0xca0a
movq -0x40(%rbp), %rcx
movl %eax, 0x40(%rcx)
leaq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x8c5e
leaq 0x174b6(%rip), %rsi     # 0x22807
movq %rax, %rdi
callq 0xc8b4
movq %rax, %rdi
callq 0xca14
movq -0x40(%rbp), %rcx
movb %al, 0x44(%rcx)
leaq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x8c5e
leaq 0x174a0(%rip), %rsi     # 0x2281b
movq %rax, %rdi
callq 0xc8b4
movq %rax, %rdi
callq 0xca0a
movq -0x40(%rbp), %rcx
movl %eax, 0x48(%rcx)
leaq -0x58(%rbp), %rdi
movq %r13, %rsi
callq 0x8c5e
leaq 0x17484(%rip), %rsi     # 0x22829
movq %rax, %rdi
callq 0xc8b4
movq %rax, %rdi
callq 0xca1e
movq -0x40(%rbp), %rax
movsd %xmm0, 0x50(%rax)
leaq -0x60(%rbp), %rbx
movq %rbx, %rdi
callq 0x4540
leaq 0x173d8(%rip), %rsi     # 0x227a9
leaq -0x98(%rbp), %rdi
movq %rbx, %rdx
callq 0x4160
leaq -0x168(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xca28
leaq -0x378(%rbp), %rdi
movq %rax, %rsi
callq 0x4480
leaq -0x358(%rbp), %r15
leaq -0x48(%rbp), %rbx
movq %rbx, %rdi
callq 0x4540
leaq 0x173bb(%rip), %rsi     # 0x227d7
leaq -0xf8(%rbp), %rdi
movq %rbx, %rdx
callq 0x4160
leaq -0x168(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0xca28
movq %r15, %rdi
movq %rax, %rsi
callq 0x4480
leaq -0x29(%rbp), %rbx
movq %rbx, %rdi
callq 0x60ac
leaq -0x1b8(%rbp), %rdi
leaq -0x378(%rbp), %rsi
pushq $0x2
popq %rdx
leaq -0x70(%rbp), %rcx
movq %rbx, %r8
callq 0xcae6
leaq -0x29(%rbp), %rdi
callq 0x60d2
pushq $0x20
popq %rbx
leaq (%rbx,%rbp), %rdi
addq $-0x378, %rdi           # imm = 0xFC88
callq 0x41a0
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0xb47e
leaq -0xf8(%rbp), %r15
movq %r15, %rdi
callq 0x41a0
leaq -0x48(%rbp), %rdi
callq 0x58aa
leaq -0x98(%rbp), %r13
movq %r13, %rdi
callq 0x41a0
leaq -0x60(%rbp), %r14
movq %r14, %rdi
callq 0x58aa
leaq -0x168(%rbp), %rbx
movq %rbx, %rdi
callq 0xcb78
movq %rax, (%r15)
movq %rbx, %rdi
callq 0xcb82
movq %rax, (%r14)
leaq -0x378(%rbp), %rbx
leaq -0x1b8(%rbp), %r12
movq %r15, %rdi
leaq -0x60(%rbp), %rsi
callq 0xcb8c
testb %al, %al
je 0xb5bb
movq %r15, %rdi
callq 0xcb9c
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4480
addq $0x20, %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x4480
movq %r12, %rdi
callq 0xcbdf
movq %rax, %r14
movq %r12, %rdi
callq 0xcbe9
movq %r14, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0xcbb8
movq %rax, -0x48(%rbp)
movq %r12, %rdi
callq 0xcbe9
movq %rax, -0x70(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xcba9
movl %eax, %r14d
movq -0x40(%rbp), %rdi
callq 0xb89c
testb %al, %al
jne 0xb582
testb %r14b, %r14b
jne 0xb59e
movq -0x40(%rbp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
leaq -0x188(%rbp), %rcx
movl $0x7cc, %r8d            # imm = 0x7CC
callq 0xb8a6
movq %r13, %rdi
callq 0x41a0
movq %rbx, %rdi
callq 0x41a0
movq %r15, %rdi
callq 0xcbf4
jmp 0xb4f6
movq -0x40(%rbp), %rdi
callq 0xbd4c
leaq -0x1b8(%rbp), %rdi
callq 0xcc12
leaq -0x58(%rbp), %rdi
callq 0x5e66
leaq -0x168(%rbp), %rdi
callq 0x5700
leaq -0x188(%rbp), %rdi
callq 0x41a0
leaq -0xd8(%rbp), %rdi
callq 0x41a0
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2e99a(%rip), %rdi     # 0x39fb0
leaq 0x17211(%rip), %rsi     # 0x2282e
callq 0x4360
movq %rax, %rdi
movq %r13, %rsi
callq 0x4320
leaq 0x17202(%rip), %rsi     # 0x22836
movq %rax, %rdi
callq 0x4360
leaq -0xd8(%rbp), %rsi
movq %rax, %rdi
callq 0x4320
leaq 0x18afa(%rip), %rsi     # 0x2414c
movq %rax, %rdi
callq 0x4360
pushq $0x10
popq %rdi
callq 0x41b0
movq %rax, %rbx
leaq 0x171d9(%rip), %rsi     # 0x22845
movq %rax, %rdi
callq 0x45e0
movq 0x2e95d(%rip), %rsi     # 0x39fd8
movq 0x2e93e(%rip), %rdx     # 0x39fc0
movq %rbx, %rdi
callq 0x4560
movq %rax, %r13
movq %rbx, %rdi
callq 0x4270
jmp 0xb83c
jmp 0xb82d
movq %rax, %r13
leaq -0x29(%rbp), %rdi
callq 0x60d2
pushq $0x20
popq %rbx
leaq (%rbx,%rbp), %rdi
addq $-0x378, %rdi           # imm = 0xFC88
callq 0x41a0
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0xb6ae
movb $0x1, %bl
jmp 0xb78a
movq %rax, %r13
xorl %ebx, %ebx
jmp 0xb796
movq %rax, %r13
xorl %ebx, %ebx
movq %r12, %r15
jmp 0xb7b9
jmp 0xb804
movq %rax, %r13
leaq -0x118(%rbp), %rdi
callq 0x41a0
jmp 0xb83c
movq %rax, %r13
leaq -0x138(%rbp), %rdi
callq 0x41a0
movq -0x40(%rbp), %r15
jmp 0xb719
jmp 0xb716
movq %rax, %r13
movq -0x38(%rbp), %r14
jmp 0xb84d
movq %rax, %r13
leaq -0xb8(%rbp), %rdi
callq 0xc83e
movl $0x180, %ebx            # imm = 0x180
leaq (%rbx,%rbp), %rdi
addq $-0x378, %rdi           # imm = 0xFC88
callq 0x5854
addq $-0x40, %rbx
cmpq $-0x40, %rbx
jne 0xb736
jmp 0xb7fe
movq %rax, %r13
jmp 0xb7fe
movq %rax, %r13
leaq -0x378(%rbp), %rdi
callq 0x58aa
jmp 0xb865
movq %rax, %r13
leaq -0x378(%rbp), %rdi
callq 0x58aa
jmp 0xb871
movq %rax, %r13
xorl %ebx, %ebx
leaq -0xf8(%rbp), %rdi
callq 0x41a0
leaq -0x48(%rbp), %rdi
callq 0x58aa
jmp 0xb7ad
movq %rax, %r13
leaq -0x378(%rbp), %r15
xorl %ebx, %ebx
leaq -0x98(%rbp), %rdi
callq 0x41a0
leaq -0x60(%rbp), %rdi
callq 0x58aa
cmpq %r15, %r12
sete %al
orb %bl, %al
jne 0xb83c
leaq -0x378(%rbp), %rbx
addq $-0x20, %r15
movq %r15, %rdi
callq 0x41a0
cmpq %rbx, %r15
jne 0xb7d3
jmp 0xb83c
jmp 0xb804
jmp 0xb804
movq %rax, %r13
addq $-0x40, %r14
movq %r14, %rdi
callq 0x5854
cmpq %rbx, %r14
jne 0xb7ed
movq -0x38(%rbp), %r14
jmp 0xb859
movq %rax, %r13
jmp 0xb83c
jmp 0xb810
movq %rax, %r13
jmp 0xb81f
movq %rax, %r13
leaq -0x98(%rbp), %rdi
callq 0x41a0
leaq -0x378(%rbp), %rdi
callq 0x41a0
jmp 0xb830
movq %rax, %r13
leaq -0x1b8(%rbp), %rdi
callq 0xcc12
movq -0x38(%rbp), %r14
leaq -0x58(%rbp), %rdi
callq 0x5e66
movq -0x40(%rbp), %r15
leaq -0x168(%rbp), %rdi
callq 0x5700
leaq -0x188(%rbp), %rdi
callq 0x41a0
leaq -0xd8(%rbp), %rdi
callq 0x41a0
movq -0x78(%rbp), %rdi
callq 0x5556
movq %r14, %rdi
callq 0x5700
movq -0x68(%rbp), %rdi
callq 0x41a0
movq %r15, %rdi
callq 0x41a0
movq %r13, %rdi
callq 0x45a0
nop