// g01ae Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class G01AEE { static string datafile = "ExampleData/g01aee.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 xmax, xmin; int i, iclass, j, k, n, nprob; int ifail; Console.WriteLine("g01ae Example Program Results"); // Skip heading in data file sr.Reset(); sr.Reset(); nprob = int.Parse(sr.Next()); for (i = 1; i <= nprob; i++) { sr.Reset(); n = int.Parse(sr.Next()); iclass = int.Parse(sr.Next()); k = int.Parse(sr.Next()); double[] cb = new double[k+2]; double[] x = new double[n]; int[] ifreq = new int[k+2]; if ( n >= 1 && k >= 2) { sr.Reset(); for (j = 1; j <= n; j++) { x[j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } Console.WriteLine(""); Console.WriteLine(" {0}{1,4}", "Problem ", i); Console.WriteLine(" {0}{1,4}", "Number of cases", n); Console.WriteLine(" {0}{1,4}", "Number of classes", k); k++; if (iclass != 1) { Console.WriteLine(" {0}", "Routine-supplied class boundaries"); } else { sr.Reset(); for (j = 1; j <= k; j++) { cb[j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } Console.WriteLine(" {0}", "User-supplied class boundaries"); } k = k + 1; // G01.g01ae(n, k, x, iclass, cb, ifreq, out xmin, out xmax, out ifail); // Console.WriteLine(""); if (ifail == 0) { Console.WriteLine(" {0}", "Successful call of g01ae"); Console.WriteLine(""); Console.WriteLine(" {0}", "*** Frequency distribution ***"); Console.WriteLine(""); Console.WriteLine(" {0}", " Class Frequency"); Console.WriteLine(""); Console.WriteLine(" {0}{1,8:f2}{2,9}", " \t Up to ", cb[0], ifreq[0]); k = k - 1; if (k > 1) { for (j = 2; j <= k; j++) { Console.WriteLine("\t {0,2:f2}{1,2:f2}{2,2:f2}\t {3,5}", cb[j - 1 - 1], " to ", cb[j - 1], ifreq[j - 1]); } Console.WriteLine(""); } Console.WriteLine(" {0,8:f2}{1}{2,6}", cb[k - 1], " and over ", ifreq[k + 1 - 1]); Console.WriteLine(""); Console.WriteLine(" {0}{1,6}", "Total frequency = ", n); Console.WriteLine(" {0}{1,9:f2}", "Minimum = ", xmin); Console.WriteLine(" {0}{1,9:f2}", "Maximum = ", xmax); } else { Console.WriteLine("** g01ae failed with ifail = {0,5}", ifail); } } // } } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine( "Exception Raised"); } } } }