Skip to content

Commit 4cb4e08

Browse files
author
Anupama Shashikala Rajendra
committed
Add metastable_states to nucname namespace
1 parent 45d8849 commit 4cb4e08

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/nucname.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@
66
#ifndef PYNE_IS_AMALGAMATED
77
#include "nucname.h"
88
#include "state_map.cpp"
9+
#include <cctype>
10+
#include <algorithm>
911
#endif
1012

13+
/***String used to check for metastable states***/
14+
std::string pyne::nucname::metastable_states = "mnopqrstuvxyz";
15+
//Capitalize all letters in the metastable states string
16+
std::string upper_metastable = metastable_states;
17+
std::transform(upper_metastable.begin(), upper_metastable.end(), upper_metastable.begin(),
18+
[](char c){ return std::toupper(c); });
1119

1220
/*** Constructs the LL to zz Dictionary ***/
1321
pyne::nucname::name_zz_t pyne::nucname::get_name_zz() {
@@ -586,8 +594,7 @@ int pyne::nucname::id(std::string nuc) {
586594

587595
// Figure out if we are meta-stable or not
588596
std::string end_char = pyne::last_char(nucstr);
589-
std::string metastable_states = "MNOPQRSTUVWXYZ";
590-
size_t pos = metastable_states.find(end_char);
597+
size_t pos = upper_metastable.find(end_char);
591598

592599
if (pos != std::string::npos) {
593600
newnuc = (10000 * anum) + static_cast<int>(pos) + 1;
@@ -675,9 +682,8 @@ std::string pyne::nucname::name(int nuc) {
675682
newnuc += pyne::to_str(aaa);
676683

677684
// Add meta-stable flag
678-
std::string metastable_states = "MNOPQRSTUVWXYZ";
679685
if (0 < ssss)
680-
newnuc += metastable_states[ssss - 1];
686+
newnuc += upper_metastable[ssss - 1];
681687

682688
return newnuc;
683689
}
@@ -840,9 +846,8 @@ std::string pyne::nucname::zzllaaam(int nuc) {
840846
if (0 < aaassss)
841847
newnuc += pyne::to_str(aaa);
842848
// Add meta-stable flag
843-
std::string metastable_states = "mnopqrstuvwxyz";
844849
if (0 < ssss)
845-
newnuc += metastable_states[ssss - 1];
850+
newnuc += pyne::nucname::metastable_states[ssss - 1];
846851
return newnuc;
847852
}
848853

@@ -893,8 +898,7 @@ int pyne::nucname::zzllaaam_to_id(std::string nuc) {
893898

894899
// Figure out if we are meta-stable or not
895900
std::string end_char = pyne::last_char(nucstr);
896-
std::string metastable_states = "MNOPQRSTUVWXYZ";
897-
size_t pos = metastable_states.find(end_char);
901+
size_t pos = upper_metastable.find(end_char);
898902
if (pos != std::string::npos) {
899903
nucid = (10000 * anum) + static_cast<int>(pos) + 1;
900904
}
@@ -1119,9 +1123,8 @@ std::string pyne::nucname::serpent(int nuc) {
11191123
newnuc += "nat";
11201124

11211125
// Add meta-stable flag
1122-
std::string metastable_states = "mnopqrstuvwxyz";
11231126
if (0 < ssss)
1124-
char meta_char = metastable_states[ssss - 1];
1127+
char meta_char = pyne::nucname::metastable_states[ssss - 1];
11251128
newnuc += meta_char;
11261129
return newnuc;
11271130
}
@@ -1175,8 +1178,7 @@ int pyne::nucname::serpent_to_id(std::string nuc) {
11751178

11761179
// Figure out if we are meta-stable or not
11771180
std::string end_char = pyne::last_char(nucstr);
1178-
std::string metastable_states = "MNOPQRSTUVWXYZ";
1179-
size_t pos = metastable_states.find(end_char);
1181+
size_t pos = upper_metastable.find(end_char);
11801182
if (pos != std::string::npos)
11811183
nucid = (10000 * anum) + static_cast<int>(pos) + 1;
11821184
else if (pyne::contains_substring(pyne::digits, end_char))

src/nucname.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace pyne
1919
//! Nuclide naming conventions
2020
namespace nucname
2121
{
22+
extern std::string metastable_states;
2223
typedef std::string name_t; ///< name type
2324
typedef int zz_t; ///< Z number type
2425

0 commit comments

Comments
 (0)