// g05kh Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class G05KHE { static void Main(String[] args) { StartExample(); } public static void StartExample() { try { const int mseed=1; const int n=3; const int nv=5; int genid, i, j, subid; double[] x = new double[nv]; int[] seed = new int[mseed]; int ifail; Console.WriteLine("g05kh Example Program Results"); Console.WriteLine(""); // Initialise the seed seed[0] = 1762543; // genid and subid identify the base generator genid = 1; subid = 1; // Prepare N streams G05.G05State[] g05State = new G05.G05State[n]; for (i = 1 ; i <= n ; i++) { // Initialise the generator to a repeatable sequence g05State[i-1] = new G05.G05State(genid, subid, seed, out ifail); if (ifail != 0) { Console.WriteLine("** Generator initialisation failed with ifail = {0,5}", ifail); goto L60; } // Prepare the I'th out of N streams G05.g05kh(n, i, g05State[i-1], out ifail); if (ifail != 0) { Console.WriteLine("** g05kh failed with ifail = {0,5}", ifail); goto L60; } } // Generate a nv variates from a uniform distribution, from each stream for (i = 1; i <= n ; i++) { Console.WriteLine(" {0} {1}", "Stream ", i); G05.g05sa(nv, g05State[i-1], x,out ifail); if (ifail != 0) { Console.WriteLine("** g05sa failed with ifail = {0,5}", ifail); goto L60; } // Display the variates for (j = 1 ; j <= nv ; j++) { Console.WriteLine(" {0,8:f4}", x[j - 1]); ; } Console.WriteLine(""); Console.WriteLine(""); } // L60: ; // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine( "Exception Raised"); } } } }