// s21cb Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; namespace NagDotNetExamples { public class S21CBE { static string datafile = "ExampleData/s21cbe.d"; static void Main(String[] args) { if (args.Length == 1) { datafile = args[0]; } StartExample(); } public static void StartExample() { try { PrintManager.Warning = new PrintManager.MessageLogger(discardmessage); DataReader sr = new DataReader(datafile); Complex cn = new Complex(0.0, 0.0), dn = new Complex(0.0, 0.0), sn = new Complex(0.0, 0.0), z = new Complex(0.0, 0.0); double ak2 = 0.0; int ifail; Console.WriteLine("s21cb Example Program Results"); // Skip heading in data file sr.Reset(); Console.WriteLine(""); try { while (true) { sr.Reset(); z = Complex.Parse(sr.Next()); ak2 = double.Parse(sr.Next(), CultureInfo.InvariantCulture); // S.s21cb(z, ak2, out sn, out cn, out dn, out ifail); // string formattedZ = String.Format("({0,7:f3},{1,7:f3})", z.re, z.im); string formattedSn = String.Format("({0,8:f4},{1,8:f4})", sn.re, sn.im); string formattedCn= String.Format("({0,8:f4},{1,8:f4})", cn.re, cn.im); string formattedDn = String.Format("({0,8:f4},{1,8:f4})", dn.re,dn.im); if (ifail >= 0) { Console.WriteLine(" {0} {1}", " Z AK2", " ifail"); Console.WriteLine(" {0} {1,10:f2} {2} ", formattedZ, ak2, ifail); Console.WriteLine(""); Console.WriteLine(" {0} {1}", " SN CN", " DN"); Console.WriteLine(" {0}\t\t{1}\t\t{2}", formattedSn, formattedCn, formattedDn); } else { Console.WriteLine("** s21cb failed with ifail = {0,5}", ifail); } } } catch { } // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Exception Raised"); } } static void discardmessage(String message) { } } }