B2017-168 Fixed logic to handle Fortran Formatted numbers

This commit is contained in:
Rich 2017-08-07 14:31:34 +00:00
parent 20a07c6a3e
commit a03e6903d0

View File

@ -783,19 +783,25 @@ namespace VEPROMS.CSLA.Library
}
private string DoFortranFormat(string text)
{
if (text.IndexOf(@".E") < 0) return text;
//if (text.IndexOf(@".E") < 0) return text;
// Look for text as n.Ey, where n can be null or a number, and y can be
// positive or negative. This translates into nx10x10y where y is
// superscripted. For example, .E3 -> x103 where 3 is superscripted
// and 10.E5 -> 10x10-5 where 5 is superscripted
string pat = @"(\d*).E([+-]*\d+)";
// B2017-168 Fixed Regular Expression to cover more examples
// +1.25E6 1.25E6 -1.25E6 +2.E6 2.E6 -2.E6 +1.E6 1.E6 -1.E6 .E2
string pat = @"(\d*\.\d*)E(([-+]|\\u8209\?)?\d+)";
string retstr = text;
// for each one that needs translated:
foreach (Match m in Regex.Matches(text, pat))
{
string fnum = m.Groups[1].Value;
string supnum = m.Groups[2].Value;
string newstr = string.Format(@"{0}x10\up2 {1}\up0 ", fnum, supnum);
string newstr;
if (fnum == "1.0" || fnum == "1." || fnum == ".")
newstr = string.Format(@"10\up2 {0}\up0 ", supnum);
else
newstr = string.Format(@"{0}x10\up2 {1}\up0 ", fnum, supnum);
retstr = retstr.Replace(m.Value, newstr);
}
return retstr;