// g13af Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; namespace NagDotNetExamples { public class G13AFE { static string datafile = "ExampleData/g13afe.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 c, s; int i, ipd, iqd, ires, itc, j, kfc, kpiv, ndf, nit, npar, nppc, nres, nst, nx; int[] isf = new int[4]; int[] mr = new int[7]; int ifail; Console.WriteLine("g13af Example Program Results"); // Skip heading in data file sr.Reset(); sr.Reset(); nx = int.Parse(sr.Next()); double[] st = new double[nx]; double[] x = new double[nx]; for (i = 1; i <= 7; i++) { mr[i - 1] = int.Parse(sr.Next()); } Console.WriteLine(""); if (nx > 0) { sr.Reset(); for (i = 1; i <= nx; i++) { x[i - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } npar = mr[0] + mr[2] + mr[3] + mr[5]; double[] par = new double[npar]; if (npar > 0) { for (i = 1; i <= npar; i++) { par[i - 1] = 0.00e0; } kfc = 1; c = 0.00e0; nppc = npar + kfc; double[,] cm = new double[nppc, nppc]; double[] sd = new double[nppc]; // * Set kpiv to 1 to obtain monitoring information * kpiv = 0; nit = 50; iqd = mr[5] * mr[6] + mr[2]; ipd = mr[3] * mr[6] + mr[0]; ires = 15 * iqd + 11 * nx + 13 * nppc + 8 * ipd + 12 + 2 * ((iqd + nppc)) * ((iqd + nppc)); double[] res = new double[ires]; if (ires > 0) { // G13.g13af(mr, par, ref c, kfc, x, nx, out s, out ndf, sd, nppc, cm, st, out nst, kpiv, nit, out itc, isf, res, out nres, out ifail); // if (ifail < 0) { Console.WriteLine(""); Console.WriteLine(" {0}{1,5}", (" ** g13af returned with") + (" ifail = "), ifail); } else { if (ifail != 0) { Console.WriteLine(" {0}{1,5}", "g13af fails. ifail = ", ifail); } if ((ifail == 0) || (ifail >= (7))) { Console.WriteLine(" {0}{1,3}{2}", ("Convergence was achieved") + (" after"), itc, " cycles"); Console.WriteLine(""); Console.WriteLine(" {0}", "Final values of the PAR parameters and the constant are as follows"); for (i = 1; i <= npar; i++) { Console.Write(" {0:0.0000}", par[i - 1]); } Console.WriteLine(" {0:0.0000}", c); Console.WriteLine(""); ; Console.WriteLine(""); Console.WriteLine(" {0}{1,10:f3}{2}{3,4}{4}", "Residual sum of squares is", s, " with", ndf, " degrees of freedom\r\n"); if ((((ifail == 0) || (ifail == 9))) && (itc > 0)) { Console.WriteLine(""); Console.WriteLine(" {0:0.0000}", ("The corresponding SD array") + (" holds\r\n")); for (i = 1; i <= nppc; i++) { Console.Write(" {0:0.0000}", sd[i - 1]); } Console.WriteLine(""); ; Console.WriteLine(""); Console.WriteLine(" {0}", "The correlation matrix is as follows\r\n"); for (i = 1; i <= nppc; i++) { for (j = 1; j <= nppc; j++) { Console.Write(" {0,8:f3}", cm[i - 1, j - 1]); } Console.WriteLine(""); ; } } if ((ifail == 0) || (ifail == 9)) { Console.WriteLine(""); Console.WriteLine(" {0}{1,4}{2}", "The residuals consist of", nres, " values\r\n"); for (i = 1; i <= nres; i++) { Console.Write(" {0,8:f4}{1}", res[i - 1], i % 5 == 0 || i == nres ? "\n" : " "); } Console.WriteLine(""); ; Console.WriteLine(""); Console.WriteLine(" {0}{1,3}{2}", "The state set consists of", nst, " values\r\n"); for (i = 1; i <= nst; i++) { Console.Write(" {0:0.000} ", st[i - 1]); if (i % 5 == 0) { Console.WriteLine(""); ; } } Console.WriteLine(""); ; } } } } } } // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Exception Raised"); } } } }