diff --git a/src/input_xml.F90 b/src/input_xml.F90 index e6355af801..aae806b7b6 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -2168,22 +2168,15 @@ contains ! Get pointer to tally xml node node_tal = node_tal_list(i) - ! Copy tally id + ! Copy and set tally id if (check_for_node(node_tal, "id")) then call get_node_value(node_tal, "id", tally_id) + err = openmc_tally_set_id(i_start + i - 1, tally_id) + if (err /= 0) call fatal_error(to_f_string(openmc_err_msg)) else call fatal_error("Must specify id for tally in tally XML file.") end if - ! Check to make sure 'id' hasn't been used - if (tally_dict % has(t % id)) then - call fatal_error("Two or more tallies use the same unique ID: " & - // to_str(tally_id)) - end if - - ! Set tally id - err = openmc_tally_set_id(i_start + i - 1, tally_id) - ! Copy tally name if (check_for_node(node_tal, "name")) & call get_node_value(node_tal, "name", t % name) diff --git a/src/tallies/tally_header.F90 b/src/tallies/tally_header.F90 index 9e1c56944c..32f094f89e 100644 --- a/src/tallies/tally_header.F90 +++ b/src/tallies/tally_header.F90 @@ -777,11 +777,17 @@ contains if (index >= 1 .and. index <= n_tallies) then if (allocated(tallies(index) % obj)) then - tallies(index) % obj % id = id - call tally_dict % set(id, index) - if (id > largest_tally_id) largest_tally_id = id + if (tally_dict % has(id)) then + call set_errmsg("Two or more tallies use the same unique ID: " & + // to_str(id)) + err = E_INVALID_ID + else + tallies(index) % obj % id = id + call tally_dict % set(id, index) + if (id > largest_tally_id) largest_tally_id = id - err = 0 + err = 0 + end if else err = E_ALLOCATE call set_errmsg("Tally type has not been set yet.")