// g13ca Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; namespace NagDotNetExamples { public class G13CAE { static string datafile = "ExampleData/g13cae.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 px = 0.0; int i, ic, iw, kc, l, lg, mtx, mw, nc, ng, nx, nxg; int ifail; Console.WriteLine("g13ca Example Program Results"); // Skip heading in data file sr.Reset(); sr.Reset(); nx = int.Parse(sr.Next()); nc = int.Parse(sr.Next()); mtx = 1; px = 0.10e0; iw = 4; mw = 100; ic = 0; kc = 360; l = 200; lg = 0; double[] c = new double[nc]; double[] stats = new double[4]; if (ic==0) { nxg = Math.Max(kc,l); } else { nxg = l; } int lxg = Math.Max(nxg, nx); double[] xg = new double[lxg]; if (nx > 0 && nx <= nxg && nc > 0) { sr.Reset(); for (i = 1; i <= nx; i++) { xg[i - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } // G13.g13ca(nx, mtx, px, iw, mw, ic, nc, c, kc, l, lg, xg, out ng, stats, out ifail); // Console.WriteLine(""); if (ifail < 0) { Console.WriteLine(""); Console.WriteLine("** g13ca failed with ifail = {0,5}", ifail); } else { if (ifail != 0) { Console.WriteLine(" {0}{1,5}", "g13ca fails. ifail =", ifail); Console.WriteLine(""); } if ((ifail == 0) || (ifail >= (4))) { Console.WriteLine(" {0}", "Covariances\r\n"); for (i = 1; i <= nc; i++) { Console.Write(" {0,11:f4}{1}", c[i - 1], i % 6 == 0 || i == nc ? "\n" : " "); } Console.WriteLine(""); ; Console.WriteLine(""); 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(""); ; } } } // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Exception Raised"); } } } }