// g02bw Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class G02BWE { static string datafile = "ExampleData/g02bwe.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 sw = 0.0; int j, k, m, n; string mean = "", weight = ""; int ifail; Console.WriteLine("g02bw Example Program Results"); // Skip heading in data file sr.Reset(); try { sr.Reset(); mean = sr.Next(); weight = sr.Next(); m = int.Parse(sr.Next()); n = int.Parse(sr.Next()); } catch { goto L20; } double[] r = new double[(m*m+m)/2]; double[] wmean = new double[m]; double[] wt = new double[n]; double[,] x = new double[n, m]; if (m >=1 && n >= 1) { sr.Reset(); for (j = 1; j <= n; j++) { wt[j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } sr.Reset(); for (j = 1; j <= n; j++) { for (k = 1; k <= m; k++) { x[j - 1, k - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } } // // Calculate the sums of squares and cross-products matrix G02.g02bu(mean, weight, n, m, x, wt, out sw, wmean, r, out ifail); // if (ifail == 0) { // // Calculate the correlation matrix G02.g02bw(m, r, out ifail); // // Print the correlation matrix if (ifail == 0) { Console.WriteLine(" "); X04.x04cc("Upper", "Non-unit", m, r, "Correlation matrix", out ifail); } else if (ifail == 2) { Console.WriteLine(" "); Console.Write(" {0}", " NOTE: some variances are zero"); Console.WriteLine(" "); X04.x04cc("Upper", "Non-unit", m, r, "Correlation matrix", out ifail); } else { Console.WriteLine(" "); Console.WriteLine("** g02bw failed with ifail = {0,5}", ifail); } } else { Console.WriteLine(" "); Console.WriteLine("** g02bu failed with ifail = {0,5}", ifail); } } else { Console.Write(" {0}{1,6}{2}{3,6}", "M or N is too large. M =", m, ", N =", n); } L20: ; // } catch (Exception e) { Console.WriteLine(e.Message); Console.Write( "Exception Raised"); } } } }