private bool ParseElectricalResistivity(string v, Qualities q) { ValueQualifier vq = DoubleValue.FindQualifier(ref v); string[] UNITS = { "nΩ·m", "Ω·m", "µΩ·m" }; double f = 1; for (int i = 0; i < UNITS.Length; ++i) { string s = UNITS[i]; int ndx = v.IndexOf(s); if (ndx > 0) { v = v.Substring(0, ndx - 1).Trim(); switch (i) { case 0: f = 0.001; break; case 1: f = 1000000; break; } } double d; if (UnitValue.TryParse(v, out d)) { q.ElectricalResistivity = new UnitValue(d * f, UNITS[2], vq); return(true); } } return(false); }
private bool ParseCovalentRadius(string s, Qualities q) { const string UNIT = Units.PicoMeter; ValueQualifier vq = DoubleValue.FindQualifier(ref s); int n = s.IndexOf(UNIT); if (n > 0) { s = s.Substring(0, n - 1).Trim(); int n2 = s.IndexOf("–"); if (n2 > 0) { string[] parts = s.Split('–'); double d1, d2; if (UnitValue.TryParse(parts[0], out d1) && UnitValue.TryParse(parts[1], out d2)) { q.CovalentRadius = new UnitValue((d1 + d2) / 2, UNIT, vq); return(true); } } if (s.StartsWith("sp3")) { s = s.Substring(5); } double d; if (UnitValue.TryParse(s, out d)) { q.CovalentRadius = new UnitValue(d, UNIT, vq); return(true); } } return(false); }
public QualifiedPhase(string p) { Qualifier = DoubleValue.FindQualifier(ref p); switch (p.Trim().ToLower()) { case "solid": Phase = Phase.Solid; break; case "liquid": Phase = Phase.Liquid; break; case "gas": Phase = Phase.Gas; break; } }
private bool ParseElectronConfiguration(string s, Qualities q) { s = StringEx.RemoveReferences(s); const string LB = "or\n"; ValueQualifier vq = DoubleValue.FindQualifier(ref s); if (s.IndexOf(LB) > 0) { s = s.Replace(LB, ";"); } q.ElectronConfiguration = new QualifiedString(s.Trim(), vq); return(true); }
private bool ParseDU(string v, string unitName, Qualities q) { if (String.IsNullOrEmpty(v)) { return(false); } v = StringEx.RemoveReferences(v); ValueQualifier vq = DoubleValue.FindQualifier(ref v); double d; if (UnitValue.TryParse(v, unitName, out d)) { UnitValue uv = new UnitValue(d, unitName, vq); return(SetValue(q, uv)); } return(false); }
private bool ParseAtomicRadius(string s, Qualities q) { const string UNIT = Units.PicoMeter; ValueQualifier vq = DoubleValue.FindQualifier(ref s); int ndx = s.IndexOf(UNIT); if (ndx > 0) { s = s.Substring(0, ndx - 1).Trim(); double d; if (UnitValue.TryParse(s, out d)) { q.AtomicRadius = new UnitValue(d, UNIT, vq); return(true); } } return(false); }
private bool ParseVanDerWaalsRadius(string s, Qualities q) { const string UNIT = "pm"; ValueQualifier vq = DoubleValue.FindQualifier(ref s); int n = s.IndexOf(UNIT); if (n > 0) { s = s.Substring(0, n - 1).Trim(); double d; if (UnitValue.TryParse(s, out d)) { q.VanDerWaalsRadius = new UnitValue(d, UNIT, vq); return(true); } } return(false); }
private bool ParseMeltingPoint(string s, Qualities q) { const string UNIT = "K"; ValueQualifier vq = DoubleValue.FindQualifier(ref s); if (s.StartsWith("?")) { vq = ValueQualifier.Extrapolated; s = s.Substring(1).Trim(); } int n = s.IndexOf(UNIT); if (n > 0) { s = s.Substring(0, n - 1).Trim(); double d; if (UnitValue.TryParse(s, out d)) { q.MeltingPoint = new UnitValue(d, UNIT, vq); return(true); } } return(false); }
private bool ParseHeatOfFusion(string s, Qualities q) { string UNIT = "kJ/mol"; int n = 0; ValueQualifier vq = DoubleValue.FindQualifier(ref s); if (s.StartsWith("(")) { n = s.IndexOf(')'); s = s.Substring(n + 1); } n = s.IndexOf(UNIT); if (n > 0) { s = s.Substring(0, n - 1).Trim(); double d; if (UnitValue.TryParse(s, out d)) { q.HeatOfFusion = new UnitValue(d, UNIT, vq); return(true); } } return(false); }
private bool ParseDensity(string v, Qualities q) { const string GPL = "g/L", GCM3 = Units.GramsPerCC, GRPH = "graphite:", BLK = "black:"; if (String.IsNullOrEmpty(v)) { return(false); } int ndx, ndx2; // General vars ValueQualifier vq = DoubleValue.FindQualifier(ref v); v = StringEx.RemoveReferences(v); Action <string> getAllotrope = (string n) => { ndx = v.IndexOf(n) + n.Length; ndx2 = v.IndexOf(GCM3, ndx); v = v.Substring(ndx); if (ndx2 > ndx) { ndx2 -= ndx; ndx2 += GCM3.Length; while (ndx2 > v.Length) { ndx2--; } v = v.Substring(0, ndx2); } v = v.Trim(); vq = ValueQualifier.MostStableAllotrope; }; switch (q.Element.Symbol) { // Choose most stable allotropes: case "C": getAllotrope(GRPH); break; case "P": getAllotrope(BLK); break; case "S": getAllotrope("alpha:"); break; case "Se": getAllotrope("gray:"); break; case "Sn": getAllotrope("gray, α:"); break; case "Po": getAllotrope("alpha:"); break; // special case case "Br": v = v.Remove(0, "Br2, liquid:".Length).Trim(); break; } double d; string u; if (UnitValue.TryParse(v, out d, out u)) { if (u == GPL) { d /= 1000; u = GCM3; } q.Density = new UnitValue(d, u, vq); return(true); } return(false); }