// g02ha Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.IO; namespace NagDotNetExamples { public class G02HAE { static bool defaultdata = true; static string datafile = ""; static void Main(String[] args) { if (args.Length == 1) { defaultdata = false; datafile = args[0]; } StartExample(); } public static void StartExample() { try { DataReader sr = null; if (defaultdata) { sr = new DataReader("exampledata/g02hae.d"); } else { sr = new DataReader(datafile); } double cpsi, cucv, dchi, h1, h2, h3, sigma, tol; int i, indc, indw, ipsi, isigma, j, m, maxit, n, nitmon; int ifail; Console.WriteLine("g02ha Example Program Results"); // Skip heading in data file indc = 0; cpsi = 0.0; h1 = 0.0; h2 = 0.0; h3 = 0.0; cucv = 0.0; dchi = 0.0; sr.Reset(); // Read in number of observations and number of x variables sr.Reset(); n = int.Parse(sr.Next()); m = int.Parse(sr.Next()); double[,] c = new double[m, m]; double[] rs = new double[n]; double[] theta = new double[m]; double[] wgt = new double[n]; double[,] x = new double[n, m]; double[] y = new double[n]; double[] stat = new double[4]; Console.WriteLine(" "); if (n > 0 && m > 0) { // Read in x and y for (i = 1; i <= n; i++) { sr.Reset(); for (j = 1; j <= m; j++) { x[i - 1, j - 1] = double.Parse(sr.Next()); } y[i - 1] = double.Parse(sr.Next()); } // Read in control parameters sr.Reset(); indw = int.Parse(sr.Next()); ipsi = int.Parse(sr.Next()); isigma = int.Parse(sr.Next()); // Read in appropriate weight function parameters. if (indw != 0) { sr.Reset(); cucv = double.Parse(sr.Next()); indc = int.Parse(sr.Next()); } if (ipsi > 0) { if (ipsi == 1) { sr.Reset(); cpsi = double.Parse(sr.Next()); } if (ipsi == 2) { sr.Reset(); h1 = double.Parse(sr.Next()); h2 = double.Parse(sr.Next()); h3 = double.Parse(sr.Next()); } if (isigma > 0) { sr.Reset(); dchi = double.Parse(sr.Next()); } } // Set values of remaining parameters tol = 0.50e-4; maxit = 50; // Change nitmon to a positive value if monitoring information // is required nitmon = 0; sigma = 1.00e0; for (i = 1; i <= m; i++) { theta[i - 1] = 0.00e0; } // G02.g02ha(indw, ipsi, isigma, indc, n, m, x, y, cpsi, h1, h2, h3, cucv, dchi, theta, ref sigma, c, rs, wgt, tol, maxit, nitmon, stat, out ifail); // if (((ifail != 0)) && ((ifail < 7))) { Console.WriteLine(" "); Console.WriteLine("** g02ha failed with ifail = {0,5}", ifail); } else { if (ifail >= (7)) { Console.WriteLine(" {0}{1,5}", "g02ha returned ifail = ", ifail); Console.WriteLine(" {0}", " Some of the following results may be unreliable"); } Console.Write(" {0}{1,10:f4}", "Sigma = ", sigma); Console.WriteLine(" "); Console.WriteLine(" {0}", " THETA Standard"); Console.WriteLine(" {0}", " errors"); for (j = 1; j <= m; j++) { Console.WriteLine(" {0,12:f4}{1,13:f4}", theta[j - 1], c[j - 1, j - 1]); } Console.WriteLine(" "); Console.WriteLine(" {0}", " Weights Residuals"); for (i = 1; i <= n; i++) { Console.WriteLine(" {0,12:f4}{1,13:f4}", wgt[i - 1], rs[i - 1]); } } } // } catch (Exception e) { Console.WriteLine(e.Message); Console.Write( "Exception Raised"); } } } }