// g13bc Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; namespace NagDotNetExamples { public class G13BCE { static string datafile = "ExampleData/g13bce.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 r0xy, r0yx, statxy, statyx, sxy, syx; int i, nl, nxy; int ifail; Console.WriteLine("g13bc Example Program Results"); // Skip heading in data file sr.Reset(); // Read series length and number of lags sr.Reset(); nxy = int.Parse(sr.Next()); nl = int.Parse(sr.Next()); double[] rxy = new double[nl]; double[] ryx = new double[nl]; double[] x = new double[nxy]; double[] y = new double[nxy]; if (nxy > 2 && nl > 0) { // Read series sr.Reset(); for (i = 1; i <= nxy; i++) { x[i - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } sr.Reset(); for (i = 1; i <= nxy; i++) { y[i - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } // Call method to calculate cross correlations between x and y // G13.g13bc(x, y, nxy, nl, out sxy, out r0xy, rxy, out statxy, out ifail); // // // Call method to calculate cross correlations between y and x G13.g13bc(y, x, nxy, nl, out syx, out r0yx, ryx, out statyx, out ifail); // Console.WriteLine(""); Console.WriteLine(" {0}", " Between Between"); Console.WriteLine(" {0}", " x and y y and x"); Console.WriteLine(""); Console.WriteLine(" {0}{1,10:f4}{2,15:f4}", "Standard deviation ratio", sxy, syx); Console.WriteLine(""); Console.WriteLine(" {0}", " Cross correlation at lag\r\n"); Console.WriteLine("{0}\t{1,8:f4}\t{2,8:f4}", "\t\t\t\t 0", r0xy, r0yx); for (i = 1; i <= nl; i++) { Console.Write("\t\t\t\t{0,2}\t{1,8:f4}\t{2,8:f4}", i, rxy[i - 1], ryx[i - 1]); Console.WriteLine(""); ; } Console.WriteLine(""); ; Console.WriteLine(""); Console.WriteLine(" {0}{1,10:f4}{2,15:f4}", "Test statistic ", statxy, statyx); } // } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Exception Raised"); } } } }