// g13cb Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; namespace NagDotNetExamples { public class G13CBE { static string datafile = "ExampleData/g13cbe.d"; static void Main(String[] args) { if (args.Length == 1) { datafile = args[0]; } StartExample(); } public static void StartExample() { try { DataReader sr = new DataReader(datafile); double pw, px; int i, kc, l, lg, mtx, mw, ng, nx; double[] stats = new double[4]; int ifail; Console.WriteLine("g13cb Example Program Results"); // Skip heading in data file sr.Reset(); sr.Reset(); nx = int.Parse(sr.Next()); mtx = 1; px = 0.20e0; mw = (int)nx; pw = 0.50e0; kc = 400; l = 100; lg = 1; int lxg = Math.Max(kc, nx); double[] xg = new double[lxg]; double[] xh = new double[lxg]; if (nx > 0) { sr.Reset(); for (i = 1; i <= nx; i++) { xh[i - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } L20: ; try { sr.Reset(); mw = int.Parse(sr.Next()); } catch { goto L60; } if ((mw > 0) && (mw <= nx)) { for (i = 1; i <= nx; i++) { xg[i - 1] = xh[i - 1]; } // G13.g13cb(nx, mtx, px, mw, pw, l, kc, lg, xg, out ng, stats, out ifail); // if (mw == nx) { Console.WriteLine(" {0}", "No smoothing"); } else { Console.WriteLine(" {0}{1,5}", "Frequency width of smoothing window = 1/", mw); } Console.WriteLine(""); if (ifail < 0) { Console.WriteLine(""); Console.WriteLine("** g13cb failed with ifail = {0,5}", ifail); } else { if (ifail != 0) { Console.WriteLine(" {0}{1,5}", "g13cb fails. ifail =", ifail); Console.WriteLine(""); } if ((ifail == 0) || (ifail >= (4))) { Console.WriteLine(" {0}{1,4:f1}{2}{3,7:f4}", "Degrees of freedom =", stats[0], " Bandwidth =", stats[3]); Console.WriteLine(""); Console.WriteLine(" {0}{1,7:f4}{2}{3,7:f4}", "95 percent confidence limits - Lower =", stats[1], " Upper =", stats[2]); Console.WriteLine(""); Console.WriteLine(" {0}", " Spectrum Spectrum Spectrum Spectrum"); Console.WriteLine(" {0}", " estimate estimate estimate estimate"); Console.WriteLine(""); for (i = 1; i <= ng; i++) { Console.Write(" {0,3} {1,10:f4}{2}", i, xg[i - 1], i % 4 == 0 || i == ng ? "\n" : " "); } Console.WriteLine(""); ; } } goto L20; } } L60: ; // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Exception Raised"); } } } }