CElement.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace OTSDataType
  7. {
  8. public static class GlobalMembersElement
  9. {
  10. public static readonly string[] ELEMENT_NAMES = { "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hq", "TI", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Mc", "No", "Lr" };
  11. public static readonly double[] ELEMENT_ATOMIC_WEIGHT_VALUES =
  12. {
  13. 1.008,4.003,
  14. 6.941,9.012,10.811,12.011,14.007,15.999,18.998,20.180,
  15. 22.990,24.305,26.982,28.086,30.974,32.066,35.453,39.948,
  16. 39.098,40.08,44.956,47.88,50.942,51.996,54.938,55.847,58.933,58.70,63.546,65.39,69.72,72.61,74.922,78.96,79.904,83.80,
  17. 85.468,87.62,88.906,91.22,92.906,95.94,98.00,101.07,102.906,106.42,107.868,112.41,114.82,118.71,121.76,127.60,126.905,131.29,
  18. 132.905,137.33,138.906,
  19. 140.12,140.908,144.24,145.0,150.36,151.97,157.25,158.925,162.50,64.93,167.26,168.934,173.04,174.967,
  20. 178.49,180.948,183.85,186.207,190.20,192.22,195.08,196.967,200.59,204.38,207.2,208.980,209.00,210.00,222.00,
  21. 223.00,226.025,227.028,
  22. };
  23. public static readonly double[] ELEMENT_ENERGY_VALUES_K =
  24. {
  25. 0.0,0.0,
  26. 0.0,0.108,0.185,0.277,0.392,0.523,0.677,0.848,
  27. 1.040,1.254,1.486,1.740,2.013,2.307,2.622,2.957,
  28. 2.313,3.691,4.090,4.510,4.952,5.414,5.898,6.403,6.929,7.477,8.040,8.637,9.250,9.885,10.542,11.220,11.922,12.649,
  29. 13.393,14.163,14.955,15.776,16.617,17.481,18.368,19.282,20.217,21.180,22.166,23.175,24.209,25.272,26.359,27.471,28.615,29.779,
  30. 30.971,32.196,33.441,
  31. 34.717,36.031,37.358,38.725,40.118,41.534,42.992,44.476,45.997,47.534,49.100,50.730,52.362,54.078,
  32. 55.801,57.450,59.305,61.122,62.989,64.906,66.834,68.804,70.806,72.769,74.989,77.091,79.272,81.513,83.771,
  33. 86.098,88.480,90.880,
  34. 93.382,95.886,98.434,100.800,103.320,105.970,109.737,111.676,114.776,0.0,0.0,0.0,0.0,0.0
  35. };
  36. public static readonly double[] ELEMENT_ENERGY_VALUES_L =
  37. {
  38. 0.0,0.0,
  39. 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
  40. 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
  41. 0.0,0.341,0.395,0.452,0.511,0.573,0.637,0.705,0.776,0.851,0.930,1.012,1.098,1.188,1.282,1.379,1.480,1.586,
  42. 1.694,1.806,1.922,2.042,2.166,2.293,2.424,2.558,2.696,2.838,2.984,3.133,3.286,3.443,3.604,3.768,3.937,4.109,
  43. 4.286,4.465,4.650,
  44. 4.839,5.033,5.229,5.432,5.636,5.845,6.056,6.272,6.494,6.719,6.947,7.179,7.414,7.654,
  45. 7.898,8.145,8.396,8.651,8.910,9.174,9.441,9.712,9.987,10.256,10.550,10.837,11.129,11.425,11.725,
  46. 12.029,12.338,12.650,
  47. 12.967,13.288,13.612,13.941,14.275,14.615,14.961,15.309,15.661,16.018,0.0,0.0,0.0,0.0
  48. };
  49. public static readonly double[] ELEMENT_ENERGY_VALUES_M =
  50. {
  51. 0.0,0.0,
  52. 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
  53. 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
  54. 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
  55. 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
  56. 0.0,0.779,0.833,
  57. 0.883,0.929,0.978,1.032,1.081,1.137,1.185,1.240,1.293,1.347,1.405,1.462,1.521,1.581,
  58. 1.644,1.709,1.774,1.842,1.910,1.978,2.048,2.120,2.191,2.268,2.342,2.419,2.505,2.585,2.665,
  59. 2.747,2.830,2.915,
  60. 2.991,3.077,3.165,3.253,3.344,3.435,3.539,3.634,3.731,3.829,0.0,0.0,0.0,0.0
  61. };
  62. }
  63. public class CElementChemistry
  64. {
  65. // name
  66. protected string m_strName;
  67. // percentage (element)
  68. public double m_dPercentage;
  69. public CElementChemistry() // constructor
  70. {
  71. // initialization
  72. Init();
  73. }
  74. public CElementChemistry(string a_strName, double a_dPercentage) // constructor
  75. {
  76. m_strName = a_strName;
  77. m_dPercentage = a_dPercentage;
  78. }
  79. // copy constructor
  80. public CElementChemistry(CElementChemistry a_oSource)
  81. {
  82. // can't copy itself
  83. if (a_oSource == this)
  84. {
  85. return;
  86. }
  87. // copy data over
  88. Duplicate(a_oSource);
  89. }
  90. public bool Equals(CElementChemistry a_oSource)
  91. {
  92. // return test result
  93. return String.Compare(m_strName, a_oSource.m_strName) == 0 && Math.Abs(m_dPercentage - a_oSource.m_dPercentage) < otsdataconst.MIN_DOUBLE_VALUE;
  94. }
  95. // name
  96. public string GetName()
  97. {
  98. return m_strName;
  99. }
  100. public void SetName(string a_strName)
  101. {
  102. m_strName = a_strName;
  103. }
  104. // percentage
  105. public double GetPercentage()
  106. {
  107. return m_dPercentage;
  108. }
  109. public void SetPercentage(double a_dPercentage)
  110. {
  111. m_dPercentage = a_dPercentage;
  112. }
  113. // MolarRatio
  114. public double GetMolarPercentage()
  115. {
  116. // molar percentage
  117. double dMolarPercentage = 0.0;
  118. // get atomic weight of the element
  119. double dAtomWeight = CElement.GetAtomWeight(m_strName);
  120. // make sure atomic weight is valid
  121. if (dAtomWeight > 0.0)
  122. {
  123. // calculate molar percentage
  124. dMolarPercentage = m_dPercentage / dAtomWeight;
  125. }
  126. return dMolarPercentage;
  127. }
  128. public void SetMolarPercentage(double a_dMolarPer)
  129. {
  130. // get atomic weight of the element
  131. double dAtomWeight = CElement.GetAtomWeight(m_strName);
  132. // set percentage
  133. m_dPercentage = a_dMolarPer * dAtomWeight / 100.0;
  134. }
  135. // cleanup
  136. protected void Cleanup()
  137. {
  138. // nothing needs to be done at the moment
  139. }
  140. // initialization
  141. protected void Init()
  142. {
  143. m_strName = "";
  144. m_dPercentage = 0.0;
  145. }
  146. // duplication
  147. protected void Duplicate(CElementChemistry a_oSource)
  148. {
  149. // initialization
  150. Init();
  151. // copy data over
  152. m_strName = a_oSource.m_strName;
  153. m_dPercentage = a_oSource.m_dPercentage;
  154. }
  155. }
  156. public class CElementArea
  157. {
  158. // element chemistry list
  159. protected List<CElementChemistry> m_listCElementChemistries = new List<CElementChemistry>();
  160. // area (element)
  161. protected double m_dArea;
  162. public CElementArea()
  163. {
  164. // initialization
  165. Init();
  166. }
  167. public CElementArea(CElementArea a_oSource)
  168. {
  169. // can't copy itself
  170. if (a_oSource == this)
  171. {
  172. return;
  173. }
  174. // copy data over
  175. Duplicate(a_oSource);
  176. }
  177. public virtual void Dispose() //virtual ~CElementArea(); // detractor
  178. {
  179. Cleanup();
  180. }
  181. public bool Equals(CElementArea a_oSource)
  182. {
  183. // element chemistry list
  184. if (m_listCElementChemistries.Count() != a_oSource.m_listCElementChemistries.Count())
  185. {
  186. return false;
  187. }
  188. for (int i = 0; i <m_listCElementChemistries.Count(); i++)
  189. {
  190. if (!(m_listCElementChemistries[i] == a_oSource.m_listCElementChemistries[i]))
  191. {
  192. return false;
  193. }
  194. }
  195. if (Math.Abs(m_dArea - a_oSource.m_dArea) >= otsdataconst.MIN_DOUBLE_VALUE)
  196. {
  197. return false;
  198. }
  199. return true;
  200. }
  201. // element chemistry list
  202. public List<CElementChemistry> GetElementList()
  203. {
  204. return m_listCElementChemistries;
  205. }
  206. // element chemistry list
  207. public void SetElementList(List<CElementChemistry> a_listElementChemistries)
  208. {
  209. foreach (var pElementChemisty in a_listElementChemistries)
  210. {
  211. CElementChemistry pElementChemistyNew = new CElementChemistry(pElementChemisty);
  212. m_listCElementChemistries.Add(pElementChemistyNew);
  213. }
  214. }
  215. // area (element)
  216. public double GetArea()
  217. {
  218. return m_dArea;
  219. }
  220. public void SetArea(double a_dArea)
  221. {
  222. m_dArea = a_dArea;
  223. }
  224. // cleanup
  225. protected void Cleanup()
  226. {
  227. m_listCElementChemistries.Clear();
  228. }
  229. // initialization
  230. protected void Init()
  231. {
  232. m_listCElementChemistries.Clear();
  233. }
  234. // duplication
  235. protected void Duplicate(CElementArea a_oSource)
  236. {
  237. // initialization
  238. Init();
  239. // copy data over
  240. m_dArea = a_oSource.m_dArea;
  241. SetElementList(a_oSource.m_listCElementChemistries);
  242. }
  243. }
  244. public class CElement
  245. {
  246. // atomic number
  247. protected long m_nAtomNum;
  248. // percentage
  249. protected double m_dPercentage;
  250. protected static List<string> m_theElementNameVector = new List<string>();
  251. //static const CString theElementNameList;
  252. protected readonly string theElementNameList = "H,He,Li,Be,B,C,N,O,F,Ne,Na,Mg,Al,Si,P,S,Cl,Ar,K,Ca,Sc,Ti,V,Cr,Mn,Fe,Co,Ni,Cu,Zn,Ga,Ge,As,Se,Br,Kr,Rb,Sr,Y,Zr,Nb,Mo,Tc,Ru,Rh,Pd,Ag,Cd,In,Sn,Sb,Te,I,Xe,Cs,Ba,La,Ce,Pr,Nd,Pm,Sm,Eu,Gd,Tb,Dy,Ho,Er,Tm,Yb,Lu,Hf,Ta,W,Re,Os,Ir,Pt,Au,Hg,Tl,Pb,Bi,Po,At,Rn,Fr,Ra,Ac,Th,Pa,U,Np,Pu,Am,Cm,Bk,Cf,Es,Fm,Md,No,Lr";
  253. // constructor
  254. public CElement()
  255. {
  256. // initialization
  257. Init();
  258. }
  259. public CElement(long a_nAtomNum)
  260. {
  261. // initialization
  262. Init();
  263. // assign class member
  264. if (a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MIN && a_nAtomNum <= otsdataconst.ATOMIC_NUMBER_MAX)
  265. {
  266. m_nAtomNum = a_nAtomNum;
  267. }
  268. }
  269. public CElement(string a_strName)
  270. {
  271. // initialization
  272. Init();
  273. // try to find matched name
  274. //InitNamesList();
  275. for (int i = 0; i < otsdataconst.ATOMIC_NUMBER_MAX; ++i)
  276. {
  277. if (GlobalMembersElement.ELEMENT_NAMES[i].Equals(a_strName))
  278. {
  279. // got it
  280. m_nAtomNum = i + 1;
  281. break;
  282. }
  283. }
  284. }
  285. // copy constructor
  286. public CElement(CElement a_poSource)
  287. {
  288. // input check
  289. //Debug.Assert(a_poSource);
  290. if (a_poSource == null)
  291. {
  292. return;
  293. }
  294. // copy data over
  295. Duplicate(a_poSource);
  296. }
  297. public bool Equals(CElement a_oSource) //BOOL operator==(const CElement&); // ==operator
  298. {
  299. if (m_nAtomNum == a_oSource.m_nAtomNum && Math.Abs(m_dPercentage - a_oSource.m_dPercentage) < otsdataconst.MIN_DOUBLE_VALUE)
  300. {
  301. return true;
  302. }
  303. else
  304. {
  305. return false;
  306. }
  307. }
  308. // valid element
  309. public bool IsValid()
  310. {
  311. return IsValidAtomNum(m_nAtomNum);
  312. }
  313. // atomic number
  314. public int GetAtomNum() //int GetAtomNum() const { return m_nAtomNum; }
  315. {
  316. return (int)m_nAtomNum;
  317. }
  318. public void SetAtomNum(long a_nAtomNum)
  319. {
  320. m_nAtomNum = a_nAtomNum;
  321. }
  322. // percentage
  323. public double GetPercentage() //double GetPercentage() const { return m_dPercentage; }
  324. {
  325. return m_dPercentage;
  326. }
  327. // percentage
  328. public void SetPercentage(double a_dPercentage)
  329. {
  330. if (a_dPercentage >= otsdataconst.PERCENTAGE_MIN && a_dPercentage <= otsdataconst.PERCENTAGE_MAX)
  331. {
  332. m_dPercentage = a_dPercentage;
  333. }
  334. }
  335. public double GetMolarPercentage()
  336. {
  337. double dMolarPercentage = otsdataconst.MIN_DOUBLE_VALUE;
  338. if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  339. {
  340. double dAtomWeight = GetAtomWeight();
  341. dMolarPercentage = m_dPercentage / dAtomWeight;
  342. }
  343. return dMolarPercentage;
  344. }
  345. // name
  346. public string GetName()
  347. {
  348. string strName = "";
  349. if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  350. {
  351. return strName;
  352. }
  353. strName = GlobalMembersElement.ELEMENT_NAMES[m_nAtomNum - 1];
  354. return strName;
  355. }
  356. public static string GetName(long a_nAtomNum)
  357. {
  358. string strName = "";
  359. if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  360. {
  361. return strName;
  362. }
  363. strName = GlobalMembersElement.ELEMENT_NAMES[a_nAtomNum - 1];
  364. return strName;
  365. }
  366. public static long GetAtomicNum(string a_strName)
  367. {
  368. long nNum = -1;
  369. for (int i = 0; i < otsdataconst.ATOMIC_NUMBER_MAX; i++)
  370. {
  371. if (a_strName==GlobalMembersElement.ELEMENT_NAMES[i])
  372. {
  373. nNum = (i + 1);
  374. break;
  375. }
  376. }
  377. return nNum;
  378. }
  379. // atomic weight
  380. public double GetAtomWeight()
  381. {
  382. double dAtomWeight = otsdataconst.ATOMIC_WEIGHT_INVALID;
  383. if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  384. {
  385. return dAtomWeight;
  386. }
  387. dAtomWeight = GlobalMembersElement.ELEMENT_ATOMIC_WEIGHT_VALUES[m_nAtomNum - 1];
  388. return dAtomWeight;
  389. }
  390. public static double GetAtomWeight(int a_nAtomNum)
  391. {
  392. double dAtomWeight = otsdataconst.ATOMIC_WEIGHT_INVALID;
  393. if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  394. {
  395. return dAtomWeight;
  396. }
  397. dAtomWeight = GlobalMembersElement.ELEMENT_ATOMIC_WEIGHT_VALUES[a_nAtomNum - 1];
  398. return dAtomWeight;
  399. }
  400. public static double GetAtomWeight(string a_strName)
  401. {
  402. double dAtomWeight = otsdataconst.ATOMIC_WEIGHT_INVALID;
  403. for (int i = 0; i < otsdataconst.ATOMIC_NUMBER_MAX; i++)
  404. {
  405. if (a_strName==GlobalMembersElement.ELEMENT_NAMES[i])
  406. {
  407. dAtomWeight = GlobalMembersElement.ELEMENT_ATOMIC_WEIGHT_VALUES[i];
  408. break;
  409. }
  410. }
  411. return dAtomWeight;
  412. }
  413. // energy values
  414. public double GetEnergyValueK()
  415. {
  416. double dEnergyValueK = otsdataconst.ENERGY_VALUE_INVALID;
  417. if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  418. {
  419. return dEnergyValueK;
  420. }
  421. dEnergyValueK = GlobalMembersElement.ELEMENT_ENERGY_VALUES_K[m_nAtomNum - 1];
  422. return dEnergyValueK;
  423. }
  424. public static double GetEnergyValueK(int a_nAtomNum)
  425. {
  426. double dEnergyValueK = otsdataconst.ENERGY_VALUE_INVALID;
  427. if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  428. {
  429. return dEnergyValueK;
  430. }
  431. dEnergyValueK = GlobalMembersElement.ELEMENT_ENERGY_VALUES_K[a_nAtomNum - 1];
  432. return dEnergyValueK;
  433. }
  434. public double GetEnergyValueL()
  435. {
  436. double dEnergyValueL = otsdataconst.ENERGY_VALUE_INVALID;
  437. if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  438. {
  439. return dEnergyValueL;
  440. }
  441. dEnergyValueL = GlobalMembersElement.ELEMENT_ENERGY_VALUES_L[m_nAtomNum - 1];
  442. return dEnergyValueL;
  443. }
  444. public static double GetEnergyValueL(int a_nAtomNum)
  445. {
  446. double dEnergyValueL = otsdataconst.ENERGY_VALUE_INVALID;
  447. if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  448. {
  449. return dEnergyValueL;
  450. }
  451. dEnergyValueL = GlobalMembersElement.ELEMENT_ENERGY_VALUES_L[a_nAtomNum - 1];
  452. return dEnergyValueL;
  453. }
  454. public double GetEnergyValueM()
  455. {
  456. double dEnergyValueM = otsdataconst.ENERGY_VALUE_INVALID;
  457. if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  458. {
  459. return dEnergyValueM;
  460. }
  461. dEnergyValueM = GlobalMembersElement.ELEMENT_ENERGY_VALUES_M[m_nAtomNum - 1];
  462. return dEnergyValueM;
  463. }
  464. public static double GetEnergyValueM(int a_nAtomNum)
  465. {
  466. double dEnergyValueM = otsdataconst.ENERGY_VALUE_INVALID;
  467. if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  468. {
  469. return dEnergyValueM;
  470. }
  471. dEnergyValueM = GlobalMembersElement.ELEMENT_ENERGY_VALUES_M[a_nAtomNum - 1];
  472. return dEnergyValueM;
  473. }
  474. public List<double> GetEnergyValues()
  475. {
  476. List<double> vEnergyValues = new List<double>();
  477. if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  478. {
  479. return vEnergyValues;
  480. }
  481. double dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_K[m_nAtomNum - 1];
  482. vEnergyValues.Add(dEnergyValue);
  483. dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_L[m_nAtomNum - 1];
  484. vEnergyValues.Add(dEnergyValue);
  485. dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_M[m_nAtomNum - 1];
  486. vEnergyValues.Add(dEnergyValue);
  487. return vEnergyValues;
  488. }
  489. public static List<double> GetEnergyValues(int a_nAtomNum)
  490. {
  491. List<double> vEnergyValues = new List<double>();
  492. if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
  493. {
  494. return vEnergyValues;
  495. }
  496. double dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_K[a_nAtomNum - 1];
  497. vEnergyValues.Add(dEnergyValue);
  498. dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_L[a_nAtomNum - 1];
  499. vEnergyValues.Add(dEnergyValue);
  500. dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_M[a_nAtomNum - 1];
  501. vEnergyValues.Add(dEnergyValue);
  502. return vEnergyValues;
  503. }
  504. // atomic number validation
  505. public static bool IsValidAtomNum(long a_nAtomNum)
  506. {
  507. return a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MIN && a_nAtomNum <= otsdataconst.ATOMIC_NUMBER_MAX;
  508. }
  509. public List<string> GetElementNameList()
  510. {
  511. if (m_theElementNameVector.Count == 0)
  512. {
  513. int tokenPos = 0;
  514. var strToken = theElementNameList.Split(',')[tokenPos]; //auto strToken = theElementNameList.Tokenize(",", tokenPos);
  515. while (strToken!=null)
  516. {
  517. m_theElementNameVector.Add(strToken);
  518. strToken = theElementNameList.Split(',')[tokenPos]; //strToken = theElementNameList.Tokenize(_T(","), tokenPos);
  519. }
  520. }
  521. return m_theElementNameVector;
  522. }
  523. public List<CElementChemistry> ExtractElementChemistrys(string a_strSource)
  524. {
  525. List<CElementChemistry> listElementChemistrys = new List<CElementChemistry>();
  526. List<string> vElementNames = GetElementNameList();
  527. // separate the source strings into strings
  528. string strSeperator = "\n";
  529. List<string> vLineStrings = SplitString(a_strSource, strSeperator);
  530. // strings to elements
  531. const int ELEMENT_STRING_NUMBER = 3;
  532. const int EXTRA_CHAR_NUMBER = 6;
  533. //int count = 1;
  534. foreach (var str in vLineStrings)
  535. {
  536. str.Trim('\n');
  537. if (str.Length<= EXTRA_CHAR_NUMBER)
  538. {
  539. continue;
  540. }
  541. strSeperator = ",";
  542. List<string> vStrings = SplitString(str, strSeperator);
  543. if (vStrings.Count == ELEMENT_STRING_NUMBER)
  544. {
  545. // create an element chemistry data
  546. CElementChemistry oElementChemistry = new CElementChemistry();
  547. // name (extra char "Quant=")
  548. string strTemp = vStrings[0];
  549. int nNameStringLength = strTemp.Length;
  550. // invalid name string?
  551. if (nNameStringLength <= EXTRA_CHAR_NUMBER)
  552. {
  553. continue;
  554. }
  555. // element name
  556. string strName = strTemp.Substring(nNameStringLength - EXTRA_CHAR_NUMBER);
  557. // make sure the element name is valid
  558. if (!vElementNames.Contains(strName)) //auto itr = std::find(vElementNames.begin(), vElementNames.end(), strName); if (itr == vElementNames.end())
  559. {
  560. // invalid element name
  561. continue;
  562. }
  563. oElementChemistry.SetName(strName);
  564. // percentage
  565. double dPercentge = double.Parse(vStrings[2]);
  566. oElementChemistry.SetPercentage(dPercentge);
  567. listElementChemistrys.Add(oElementChemistry);
  568. }
  569. }
  570. return listElementChemistrys;
  571. }
  572. // cleanup
  573. // cleanup
  574. protected void Cleanup()
  575. {
  576. // nothing needs to be done at the moment
  577. }
  578. // initialization
  579. protected void Init()
  580. {
  581. m_nAtomNum = otsdataconst.ATOMIC_NUMBER_INVALID;
  582. m_dPercentage = otsdataconst.PERCENTAGE_DEFAULT;
  583. }
  584. // duplication
  585. protected void Duplicate(CElement a_oSource)
  586. {
  587. // initialization
  588. Init();
  589. // copy data over
  590. m_nAtomNum = a_oSource.m_nAtomNum;
  591. m_dPercentage = a_oSource.m_dPercentage;
  592. }
  593. // const CString& a_sSource
  594. // LPCTSTR a_sSep -- separator
  595. protected static List<string> SplitString(string a_strSource, string a_strSep) //std::vector<CString> CElement::SplitString(const CString& a_strSource, LPCTSTR a_strSep)
  596. {
  597. // string list
  598. List<string> listString = new List<string>();
  599. // source string
  600. string strSource = a_strSource;
  601. // find the first separator
  602. int nPosLast = 0;
  603. var nPos = strSource.IndexOf(a_strSep, nPosLast); //var nPos = strSource.Find(a_strSep, nPosLast);
  604. // found the separator?
  605. while (nPos >= nPosLast)
  606. {
  607. // there is no string between two seperator if nPos == nPosLast
  608. if (nPos == nPosLast)
  609. {
  610. listString.Add("");
  611. nPosLast++;
  612. }
  613. else
  614. {
  615. // get the string between two separator
  616. string strValue = strSource.Substring(nPosLast, nPos - nPosLast); //string strValue = strSource.Mid(nPosLast, nPos - nPosLast);
  617. strValue.Trim();
  618. // add the string into the string list
  619. listString.Add(strValue);
  620. nPosLast = nPos + 1;
  621. }
  622. // try to find the next separator
  623. nPos = strSource.IndexOf(a_strSep, nPosLast); //nPos = strSource.Find(a_strSep, nPosLast);
  624. }
  625. // push the last one into the string list
  626. string strLastValue = strSource.Substring(strSource.Length - nPosLast);
  627. strLastValue.Trim();
  628. listString.Add(strLastValue);
  629. // return the string list
  630. return listString;
  631. }
  632. }
  633. }