// g02bt Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class G02BTE { static string datafile = "ExampleData/g02bte.d"; static void Main(String[] args) { if (args.Length == 1) { datafile = args[0]; } StartExample(); } public static void StartExample() { try { DataReader sr = new DataReader(datafile); const double one = 1.00e0; const int incx = 1; double alpha, sw, wt; int i, j, m, mm, n, nprint; string mean = ""; int ifail; Console.WriteLine("g02bt Example Program Results"); // Skip heading in data file sr.Reset(); try { sr.Reset(); mean = sr.Next(); m = int.Parse(sr.Next()); n = int.Parse(sr.Next()); nprint = int.Parse(sr.Next()); } catch { goto L40; } sw = 0.00e0; double[] c = new double[(m*m+m)/2]; double[] v = new double[(m*m+m)/2]; double[] x = new double[m*incx]; double[] xbar = new double[m]; if (m >= 1) { for (i = 1; i <= n; i++) { sr.Reset(); wt = double.Parse(sr.Next(), CultureInfo.InvariantCulture); for (j = 1; j <= m; j++) { x[j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } // // Calculate the sums of squares and cross-products matrix G02.g02bt(mean, m, wt, x, incx, ref sw, xbar, c, out ifail); if (ifail == 0) { // if (((i % nprint) == 0) || (i == n)) { Console.WriteLine(" "); Console.WriteLine(" {0}", "---------------------------------------------"); Console.WriteLine(" {0}{1,4}{2}{3,13:f4}", "Observation: ", i, " Weight = ", wt); Console.WriteLine(" {0}", "---------------------------------------------"); Console.WriteLine(" "); Console.WriteLine(" {0}", "Means"); for (j = 1; j <= m; j++) { Console.Write(" {0,10:f4}", xbar[j - 1]); } Console.WriteLine(" "); Console.WriteLine(" "); // Print the sums of squares and cross products matrix X04.x04cc("Upper", "Non-unit", m, c, "Sums of squares and cross-products", out ifail); if (sw > one) { // Calculate the variance matrix alpha = one / (sw - one); mm = (m * (m + 1)) / 2; F06.f06fd(mm, alpha, c, 1, v, 1, out ifail); // Print the variance matrix Console.WriteLine(" "); X04.x04cc("Upper", "Non-unit", m, v, "Variance matrix", out ifail); } } } else { Console.WriteLine(" "); Console.WriteLine("** g02bt failed with ifail = {0,5}", ifail); goto L40; } } } else { Console.Write(" {0}{1,5}", "M is too large. M =", m); } L40: ; // } catch (Exception e) { Console.WriteLine(e.Message); Console.Write( "Exception Raised"); } } } }