// g05pz Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.IO; namespace NagDotNetExamples { public class G05PZE { static void Main(String[] args) { StartExample(); } public static void StartExample() { try { const int lrow=4; const int ncol=3; const int mseed=1; const int lr=60; int genid, i, j, rctot, subid; double[] r = new double[lr]; int[] seed = new int[mseed]; int[] totc = new int[ncol]; int[] totr = new int[lrow]; int[,] x = new int[lrow, ncol]; int ifail; Console.WriteLine("g05pz Example Program Results"); Console.WriteLine("");Console.WriteLine(""); // Set the table row and column totals totr[0] = 9; totr[1] = 11; totr[2] = 7; totr[3] = 23; totc[0] = 16; totc[1] = 17; totc[2] = 17; rctot = 50; // Initialise the seed seed[0] = 1762543; // genid and subid identify the base generator genid = 1; subid = 1; // Initialise the generator to a repeatable sequence G05.G05State g05State = new G05.G05State(genid, subid, seed, out ifail); if (ifail != 0) { Console.WriteLine("** Generator initialisation failed with ifail = {0,5}", ifail); goto L40; } // Generate the random table // Choose mode = 2 G05.g05pz(2, lrow, ncol, totr, totc,r, g05State, x, out ifail); if (ifail != 0) { Console.WriteLine("** g05pz failed with ifail = {0,5}", ifail); goto L40; } // Display the results for (i = 1 ; i <= lrow ; i++) { for (j = 1 ; j <= ncol ; j++) { Console.Write("{0,3}", x[i - 1 , j - 1]); } Console.Write("{0,3} ", " | "+totr[i - 1]); Console.WriteLine(""); } Console.WriteLine("{0}", "------------+------"); for (j = 1 ; j <= ncol ; j++) { Console.Write("{0,3}", totc[j - 1]); } Console.Write("{0,3} ", " | " + rctot); Console.WriteLine(""); // L40: ; // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine( "Exception Raised"); } } } }