123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OTSDataType
- {
- public static class GlobalMembersElement
- {
- 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" };
- public static readonly double[] ELEMENT_ATOMIC_WEIGHT_VALUES =
- {
- 1.008,4.003,
- 6.941,9.012,10.811,12.011,14.007,15.999,18.998,20.180,
- 22.990,24.305,26.982,28.086,30.974,32.066,35.453,39.948,
- 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,
- 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,
- 132.905,137.33,138.906,
- 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,
- 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,
- 223.00,226.025,227.028,
- };
- public static readonly double[] ELEMENT_ENERGY_VALUES_K =
- {
- 0.0,0.0,
- 0.0,0.108,0.185,0.277,0.392,0.523,0.677,0.848,
- 1.040,1.254,1.486,1.740,2.013,2.307,2.622,2.957,
- 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,
- 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.971,32.196,33.441,
- 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,
- 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,
- 86.098,88.480,90.880,
- 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
- };
- public static readonly double[] ELEMENT_ENERGY_VALUES_L =
- {
- 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,
- 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,
- 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,
- 4.286,4.465,4.650,
- 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,
- 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,
- 12.029,12.338,12.650,
- 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
- };
- public static readonly double[] ELEMENT_ENERGY_VALUES_M =
- {
- 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,
- 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,
- 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,
- 0.0,0.779,0.833,
- 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,
- 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,
- 2.747,2.830,2.915,
- 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
- };
- }
- public class CElementChemistry
- {
- // name
- protected string m_strName;
- // percentage (element)
- public double m_dPercentage;
- public CElementChemistry() // constructor
- {
- // initialization
- Init();
- }
- public CElementChemistry(string a_strName, double a_dPercentage) // constructor
- {
- m_strName = a_strName;
- m_dPercentage = a_dPercentage;
- }
- // copy constructor
- public CElementChemistry(CElementChemistry a_oSource)
- {
- // can't copy itself
- if (a_oSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(a_oSource);
- }
- //c#无指针
- //CElementChemistry(CElementChemistry*); // copy constructor
- // ==operator
- //public static bool operator ==(CElementChemistry ImpliedObject, CElementChemistry a_oSource)
- //{
- // // return test result
- // return String.Compare(ImpliedObject.m_strName,a_oSource.m_strName) == 0 && Math.Abs(ImpliedObject.m_dPercentage - a_oSource.m_dPercentage) < 0.00000000001;
- //}
- //// ==和!= 重载必须成对出现
- //public static bool operator !=(CElementChemistry ImpliedObject, CElementChemistry a_oSource)
- //{
- // // return test result
- // return String.Compare(ImpliedObject.m_strName,a_oSource.m_strName) != 0 || Math.Abs(ImpliedObject.m_dPercentage - a_oSource.m_dPercentage) < 0.00000000001;
- //}
- public bool Equals(CElementChemistry a_oSource)
- {
- // return test result
- return String.Compare(m_strName, a_oSource.m_strName) == 0 && Math.Abs(m_dPercentage - a_oSource.m_dPercentage) < otsdataconst.MIN_DOUBLE_VALUE;
- }
- //无实际操作
- //virtual ~CElementChemistry(); // detractor
- // serialization
- //void Serialize(bool isStoring, tinyxml2::XMLDocument* classDoc, tinyxml2::XMLElement* rootNode);
- // name
- public string GetName()
- {
- return m_strName;
- }
- public void SetName(string a_strName)
- {
- m_strName = a_strName;
- }
- // percentage
- public double GetPercentage()
- {
- return m_dPercentage;
- }
- public void SetPercentage(double a_dPercentage)
- {
- m_dPercentage = a_dPercentage;
- }
- // MolarRatio
- public double GetMolarPercentage()
- {
- // molar percentage
- double dMolarPercentage = 0.0;
- // get atomic weight of the element
- double dAtomWeight = CElement.GetAtomWeight(m_strName);
- // make sure atomic weight is valid
- if (dAtomWeight > 0.0)
- {
- // calculate molar percentage
- dMolarPercentage = m_dPercentage / dAtomWeight;
- }
- return dMolarPercentage;
- }
- public void SetMolarPercentage(double a_dMolarPer)
- {
- // get atomic weight of the element
- double dAtomWeight = CElement.GetAtomWeight(m_strName);
- // set percentage
- m_dPercentage = a_dMolarPer * dAtomWeight / 100.0;
- }
- // cleanup
- protected void Cleanup()
- {
- // nothing needs to be done at the moment
- }
- // initialization
- protected void Init()
- {
- m_strName = "";
- m_dPercentage = 0.0;
- }
- // duplication
- protected void Duplicate(CElementChemistry a_oSource)
- {
- // initialization
- Init();
- // copy data over
- m_strName = a_oSource.m_strName;
- m_dPercentage = a_oSource.m_dPercentage;
- }
- }
- public class CElementArea
- {
- // element chemistry list
- protected List<CElementChemistry> m_listCElementChemistries = new List<CElementChemistry>();
- // area (element)
- protected double m_dArea;
- public CElementArea()
- {
- // initialization
- Init();
- }
- public CElementArea(CElementArea a_oSource)
- {
- // can't copy itself
- if (a_oSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(a_oSource);
- }
- //CElementArea(CElementArea*); // copy constructor
- //public CElementArea CopyFrom(CElementArea a_oSource) //CElementArea& operator=(const CElementArea&); // =operator
- //{
- // // cleanup
- // Cleanup();
- // // copy the class data over
- // Duplicate(a_oSource);
- // // return class
- // return this;
- //}
- public virtual void Dispose() //virtual ~CElementArea(); // detractor
- {
- Cleanup();
- }
- //public static bool operator ==(CElementArea ImpliedObject, CElementArea a_oSource)
- //{
- // // element chemistry list
- // if ((int)ImpliedObject.m_listCElementChemistries.Count() != (int)a_oSource.m_listCElementChemistries.Count())
- // {
- // return false;
- // }
- // for (int i = 0; i < (int)ImpliedObject.m_listCElementChemistries.Count(); i++)
- // {
- // if (!(ImpliedObject.m_listCElementChemistries[i] == a_oSource.m_listCElementChemistries[i]))
- // {
- // return false;
- // }
- // }
- // if (Math.Abs(ImpliedObject.m_dArea - a_oSource.m_dArea) >= 0.00000000001)
- // {
- // return false;
- // }
- // return true;
- //}
- //public static bool operator !=(CElementArea ImpliedObject, CElementArea a_oSource)
- //{
- // // element chemistry list
- // if ((int)ImpliedObject.m_listCElementChemistries.Count() != (int)a_oSource.m_listCElementChemistries.Count())
- // {
- // return true;
- // }
- // for (int i = 0; i < (int)ImpliedObject.m_listCElementChemistries.Count(); i++)
- // {
- // if (!(ImpliedObject.m_listCElementChemistries[i] == a_oSource.m_listCElementChemistries[i]))
- // {
- // return true;
- // }
- // }
- // if(Math.Abs(ImpliedObject.m_dArea - a_oSource.m_dArea) >= 0.00000000001)
- // {
- // return true;
- // }
- // return false;
- //}
- public bool Equals(CElementArea a_oSource)
- {
- // element chemistry list
- if (m_listCElementChemistries.Count() != a_oSource.m_listCElementChemistries.Count())
- {
- return false;
- }
- for (int i = 0; i <m_listCElementChemistries.Count(); i++)
- {
- if (!(m_listCElementChemistries[i] == a_oSource.m_listCElementChemistries[i]))
- {
- return false;
- }
- }
- if (Math.Abs(m_dArea - a_oSource.m_dArea) >= otsdataconst.MIN_DOUBLE_VALUE)
- {
- return false;
- }
- return true;
- }
- // element chemistry list
- public List<CElementChemistry> GetElementList()
- {
- return m_listCElementChemistries;
- }
- // element chemistry list
- public void SetElementList(List<CElementChemistry> a_listElementChemistries)
- {
- foreach (var pElementChemisty in a_listElementChemistries)
- {
- CElementChemistry pElementChemistyNew = new CElementChemistry(pElementChemisty);
- m_listCElementChemistries.Add(pElementChemistyNew);
- }
- }
- // area (element)
- public double GetArea()
- {
- return m_dArea;
- }
- public void SetArea(double a_dArea)
- {
- m_dArea = a_dArea;
- }
- // cleanup
- protected void Cleanup()
- {
- m_listCElementChemistries.Clear();
- }
- // initialization
- protected void Init()
- {
- m_listCElementChemistries.Clear();
- }
-
- // duplication
- protected void Duplicate(CElementArea a_oSource)
- {
- // initialization
- Init();
- // copy data over
- m_dArea = a_oSource.m_dArea;
- SetElementList(a_oSource.m_listCElementChemistries);
- }
- }
- public class CElement
- {
- // atomic number
- protected long m_nAtomNum;
- // percentage
- protected double m_dPercentage;
- protected static List<string> m_theElementNameVector = new List<string>();
- //static const CString theElementNameList;
- 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";
- // constructor
- public CElement()
- {
- // initialization
- Init();
- }
- public CElement(long a_nAtomNum)
- {
- // initialization
- Init();
- // assign class member
- if (a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MIN && a_nAtomNum <= otsdataconst.ATOMIC_NUMBER_MAX)
- {
- m_nAtomNum = a_nAtomNum;
- }
- }
- public CElement(string a_strName)
- {
- // initialization
- Init();
- // try to find matched name
- //InitNamesList();
- for (int i = 0; i < otsdataconst.ATOMIC_NUMBER_MAX; ++i)
- {
- if (GlobalMembersElement.ELEMENT_NAMES[i].Equals(a_strName))
- {
- // got it
- m_nAtomNum = i + 1;
- break;
- }
- }
- }
- // copy constructor
- public CElement(CElement a_poSource)
- {
- // input check
- //Debug.Assert(a_poSource);
- if (a_poSource == null)
- {
- return;
- }
- // copy data over
- Duplicate(a_poSource);
- }
- //public CElement CopyFrom(CElement a_oSource) //ORIGINAL LINE: CElement& operator =(const CElement& a_oSource)
- //{
- // // cleanup
- // Cleanup();
- // // copy the class data over
- // Duplicate(a_oSource);
- // // return class
- // return this;
- //}
- public bool Equals(CElement a_oSource) //BOOL operator==(const CElement&); // ==operator
- {
- if (m_nAtomNum == a_oSource.m_nAtomNum && Math.Abs(m_dPercentage - a_oSource.m_dPercentage) < otsdataconst.MIN_DOUBLE_VALUE)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- // destructor
- //public virtual void Dispose() //virtual ~CElement(); // detractor
- //{
- // // cleanup
- // Cleanup();
- //}
- // valid element
- public bool IsValid()
- {
- return IsValidAtomNum(m_nAtomNum);
- }
- // atomic number
- public int GetAtomNum() //int GetAtomNum() const { return m_nAtomNum; }
- {
- return (int)m_nAtomNum;
- }
- public void SetAtomNum(long a_nAtomNum)
- {
- m_nAtomNum = a_nAtomNum;
- }
- // percentage
- public double GetPercentage() //double GetPercentage() const { return m_dPercentage; }
- {
- return m_dPercentage;
- }
- // percentage
- public void SetPercentage(double a_dPercentage)
- {
- if (a_dPercentage >= otsdataconst.PERCENTAGE_MIN && a_dPercentage <= otsdataconst.PERCENTAGE_MAX)
- {
- m_dPercentage = a_dPercentage;
- }
- }
- public double GetMolarPercentage()
- {
- double dMolarPercentage = otsdataconst.MIN_DOUBLE_VALUE;
- if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
- {
- double dAtomWeight = GetAtomWeight();
- dMolarPercentage = m_dPercentage / dAtomWeight;
- }
- return dMolarPercentage;
- }
- // name
- public string GetName()
- {
- string strName = "";
- if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
- {
- return strName;
- }
- strName = GlobalMembersElement.ELEMENT_NAMES[m_nAtomNum - 1];
- return strName;
- }
- public static string GetName(long a_nAtomNum)
- {
- string strName = "";
- if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
- {
- return strName;
- }
- strName = GlobalMembersElement.ELEMENT_NAMES[a_nAtomNum - 1];
- return strName;
- }
- public static long GetAtomicNum(string a_strName)
- {
- long nNum = -1;
- for (int i = 0; i < otsdataconst.ATOMIC_NUMBER_MAX; i++)
- {
- if (a_strName==GlobalMembersElement.ELEMENT_NAMES[i])
- {
- nNum = (i + 1);
- break;
- }
- }
- return nNum;
- }
- // atomic weight
- public double GetAtomWeight()
- {
- double dAtomWeight = otsdataconst.ATOMIC_WEIGHT_INVALID;
- if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
- {
- return dAtomWeight;
- }
- dAtomWeight = GlobalMembersElement.ELEMENT_ATOMIC_WEIGHT_VALUES[m_nAtomNum - 1];
- return dAtomWeight;
- }
- public static double GetAtomWeight(int a_nAtomNum)
- {
- double dAtomWeight = otsdataconst.ATOMIC_WEIGHT_INVALID;
- if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
- {
- return dAtomWeight;
- }
- dAtomWeight = GlobalMembersElement.ELEMENT_ATOMIC_WEIGHT_VALUES[a_nAtomNum - 1];
- return dAtomWeight;
- }
- public static double GetAtomWeight(string a_strName)
- {
- double dAtomWeight = otsdataconst.ATOMIC_WEIGHT_INVALID;
- for (int i = 0; i < otsdataconst.ATOMIC_NUMBER_MAX; i++)
- {
- if (a_strName==GlobalMembersElement.ELEMENT_NAMES[i])
- {
- dAtomWeight = GlobalMembersElement.ELEMENT_ATOMIC_WEIGHT_VALUES[i];
- break;
- }
- }
- return dAtomWeight;
- }
- // energy values
- public double GetEnergyValueK()
- {
- double dEnergyValueK = otsdataconst.ENERGY_VALUE_INVALID;
- if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
- {
- return dEnergyValueK;
- }
- dEnergyValueK = GlobalMembersElement.ELEMENT_ENERGY_VALUES_K[m_nAtomNum - 1];
- return dEnergyValueK;
- }
- public static double GetEnergyValueK(int a_nAtomNum)
- {
- double dEnergyValueK = otsdataconst.ENERGY_VALUE_INVALID;
- if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
- {
- return dEnergyValueK;
- }
- dEnergyValueK = GlobalMembersElement.ELEMENT_ENERGY_VALUES_K[a_nAtomNum - 1];
- return dEnergyValueK;
- }
- public double GetEnergyValueL()
- {
- double dEnergyValueL = otsdataconst.ENERGY_VALUE_INVALID;
- if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
- {
- return dEnergyValueL;
- }
- dEnergyValueL = GlobalMembersElement.ELEMENT_ENERGY_VALUES_L[m_nAtomNum - 1];
- return dEnergyValueL;
- }
- public static double GetEnergyValueL(int a_nAtomNum)
- {
- double dEnergyValueL = otsdataconst.ENERGY_VALUE_INVALID;
- if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
- {
- return dEnergyValueL;
- }
- dEnergyValueL = GlobalMembersElement.ELEMENT_ENERGY_VALUES_L[a_nAtomNum - 1];
- return dEnergyValueL;
- }
- public double GetEnergyValueM()
- {
- double dEnergyValueM = otsdataconst.ENERGY_VALUE_INVALID;
- if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
- {
- return dEnergyValueM;
- }
- dEnergyValueM = GlobalMembersElement.ELEMENT_ENERGY_VALUES_M[m_nAtomNum - 1];
- return dEnergyValueM;
- }
- public static double GetEnergyValueM(int a_nAtomNum)
- {
- double dEnergyValueM = otsdataconst.ENERGY_VALUE_INVALID;
- if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
- {
- return dEnergyValueM;
- }
- dEnergyValueM = GlobalMembersElement.ELEMENT_ENERGY_VALUES_M[a_nAtomNum - 1];
- return dEnergyValueM;
- }
- public List<double> GetEnergyValues()
- {
- List<double> vEnergyValues = new List<double>();
- if (m_nAtomNum < 0 || m_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
- {
- return vEnergyValues;
- }
- double dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_K[m_nAtomNum - 1];
- vEnergyValues.Add(dEnergyValue);
- dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_L[m_nAtomNum - 1];
- vEnergyValues.Add(dEnergyValue);
- dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_M[m_nAtomNum - 1];
- vEnergyValues.Add(dEnergyValue);
- return vEnergyValues;
- }
- public static List<double> GetEnergyValues(int a_nAtomNum)
- {
- List<double> vEnergyValues = new List<double>();
- if (a_nAtomNum < 0 || a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MAX)
- {
- return vEnergyValues;
- }
- double dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_K[a_nAtomNum - 1];
- vEnergyValues.Add(dEnergyValue);
- dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_L[a_nAtomNum - 1];
- vEnergyValues.Add(dEnergyValue);
- dEnergyValue = GlobalMembersElement.ELEMENT_ENERGY_VALUES_M[a_nAtomNum - 1];
- vEnergyValues.Add(dEnergyValue);
- return vEnergyValues;
- }
- // atomic number validation
- public static bool IsValidAtomNum(long a_nAtomNum)
- {
- return a_nAtomNum >= otsdataconst.ATOMIC_NUMBER_MIN && a_nAtomNum <= otsdataconst.ATOMIC_NUMBER_MAX;
- }
- public List<string> GetElementNameList()
- {
- if (m_theElementNameVector.Count == 0)
- {
- int tokenPos = 0;
- var strToken = theElementNameList.Split(',')[tokenPos]; //auto strToken = theElementNameList.Tokenize(",", tokenPos);
- while (strToken!=null)
- {
- m_theElementNameVector.Add(strToken);
- strToken = theElementNameList.Split(',')[tokenPos]; //strToken = theElementNameList.Tokenize(_T(","), tokenPos);
- }
- }
- return m_theElementNameVector;
- }
- public List<CElementChemistry> ExtractElementChemistrys(string a_strSource)
- {
- List<CElementChemistry> listElementChemistrys = new List<CElementChemistry>();
- List<string> vElementNames = GetElementNameList();
- // separate the source strings into strings
- string strSeperator = "\n";
- List<string> vLineStrings = SplitString(a_strSource, strSeperator);
- // strings to elements
- const int ELEMENT_STRING_NUMBER = 3;
- const int EXTRA_CHAR_NUMBER = 6;
- //int count = 1;
- foreach (var str in vLineStrings)
- {
- str.Trim('\n');
- if (str.Length<= EXTRA_CHAR_NUMBER)
- {
- continue;
- }
- strSeperator = ",";
- List<string> vStrings = SplitString(str, strSeperator);
- if (vStrings.Count == ELEMENT_STRING_NUMBER)
- {
- // create an element chemistry data
- CElementChemistry oElementChemistry = new CElementChemistry();
- // name (extra char "Quant=")
- string strTemp = vStrings[0];
- int nNameStringLength = strTemp.Length;
- // invalid name string?
- if (nNameStringLength <= EXTRA_CHAR_NUMBER)
- {
- continue;
- }
- // element name
- string strName = strTemp.Substring(nNameStringLength - EXTRA_CHAR_NUMBER);
- // make sure the element name is valid
- if (!vElementNames.Contains(strName)) //auto itr = std::find(vElementNames.begin(), vElementNames.end(), strName); if (itr == vElementNames.end())
- {
- // invalid element name
- continue;
- }
- oElementChemistry.SetName(strName);
- // percentage
- double dPercentge = double.Parse(vStrings[2]);
- oElementChemistry.SetPercentage(dPercentge);
- listElementChemistrys.Add(oElementChemistry);
- }
- }
- return listElementChemistrys;
- }
- // cleanup
- // cleanup
- protected void Cleanup()
- {
- // nothing needs to be done at the moment
- }
- // initialization
- protected void Init()
- {
- m_nAtomNum = otsdataconst.ATOMIC_NUMBER_INVALID;
- m_dPercentage = otsdataconst.PERCENTAGE_DEFAULT;
- }
- // duplication
- protected void Duplicate(CElement a_oSource)
- {
- // initialization
- Init();
- // copy data over
- m_nAtomNum = a_oSource.m_nAtomNum;
- m_dPercentage = a_oSource.m_dPercentage;
- }
- // const CString& a_sSource
- // LPCTSTR a_sSep -- separator
- protected static List<string> SplitString(string a_strSource, string a_strSep) //std::vector<CString> CElement::SplitString(const CString& a_strSource, LPCTSTR a_strSep)
- {
- // string list
- List<string> listString = new List<string>();
- // source string
- string strSource = a_strSource;
- // find the first separator
- int nPosLast = 0;
- var nPos = strSource.IndexOf(a_strSep, nPosLast); //var nPos = strSource.Find(a_strSep, nPosLast);
- // found the separator?
- while (nPos >= nPosLast)
- {
- // there is no string between two seperator if nPos == nPosLast
- if (nPos == nPosLast)
- {
- listString.Add("");
- nPosLast++;
- }
- else
- {
- // get the string between two separator
- string strValue = strSource.Substring(nPosLast, nPos - nPosLast); //string strValue = strSource.Mid(nPosLast, nPos - nPosLast);
- strValue.Trim();
- // add the string into the string list
- listString.Add(strValue);
- nPosLast = nPos + 1;
- }
- // try to find the next separator
- nPos = strSource.IndexOf(a_strSep, nPosLast); //nPos = strSource.Find(a_strSep, nPosLast);
- }
- // push the last one into the string list
- string strLastValue = strSource.Substring(strSource.Length - nPosLast);
- strLastValue.Trim();
- listString.Add(strLastValue);
- // return the string list
- return listString;
- }
- }
- }
|