1 /*************************************************************************\
2 *
3 * Package: TestU01
4 * File: swrite.c
5 * Environment: ANSI C
6 *
7 * Copyright (c) 2002 Pierre L'Ecuyer, DIRO, Université de Montréal.
8 * e-mail: lecuyer@iro.umontreal.ca
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted without a fee for private, research,
13 * academic, or other non-commercial purposes.
14 * Any use of this software in a commercial environment requires a
15 * written licence from the copyright owner.
16 *
17 * Any changes made to this package must be clearly identified as such.
18 *
19 * In scientific publications which used this software, a reference to it
20 * would be appreciated.
21 *
22 * Redistributions of source code must retain this copyright notice
23 * and the following disclaimer.
24 *
25 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
27 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
28 *
29 \*************************************************************************/
30
31
32 #include "gdef.h"
33 #include "util.h"
34 #include "chrono.h"
35
36 #include "swrite.h"
37 #include "unif01.h"
38 #include "gofw.h"
39
40 #include <string.h>
41 #include <stdio.h>
42 #include <math.h>
43
44
45
46 #define LEN 100
47
48
49 lebool swrite_Basic = TRUE;
50 lebool swrite_Parameters = FALSE;
51 lebool swrite_Collectors = FALSE;
52 lebool swrite_Counters = FALSE;
53 lebool swrite_Classes = FALSE;
54 lebool swrite_Others = FALSE;
55
56 lebool swrite_Host = TRUE;
57
58 char swrite_ExperimentName[LEN + 1] = "";
59
60
61
62 /*=========================================================================*/
63
swrite_SetExperimentName(char Name[])64 void swrite_SetExperimentName (char Name[])
65 {
66 strncpy (swrite_ExperimentName, Name, (size_t) LEN);
67 }
68
69
70 /*=========================================================================*/
71
swrite_Head(unif01_Gen * gen,char * TestName,long N,long n,int r)72 void swrite_Head (unif01_Gen *gen, char *TestName, long N, long n, int r)
73 {
74 printf ("***********************************************************\n");
75 printf ("HOST = ");
76 if (swrite_Host) {
77 gdef_WriteHostName ();
78 printf ("\n");
79 } else
80 printf ("\n\n");
81 util_Assert (gen != NULL, "No generator has been created");
82 unif01_WriteNameGen (gen);
83 printf ("\n");
84 if (swrite_ExperimentName && strcmp (swrite_ExperimentName, "")) {
85 printf ("%s", swrite_ExperimentName);
86 printf (":\n\n");
87 }
88 printf ("%s", TestName);
89 printf (":\n-----------------------------------------------\n");
90 printf (" N = %2ld, n = %2ld, r = %2d", N, n, r);
91 util_Assert (N > 0, " N <= 0");
92 util_Assert (n > 0, " n <= 0");
93 util_Assert (r >= 0, " r < 0");
94 }
95
96
97 /*=========================================================================*/
98
swrite_Final(unif01_Gen * gen,chrono_Chrono * Timer)99 void swrite_Final (unif01_Gen *gen, chrono_Chrono *Timer)
100 {
101 printf ("-----------------------------------------------\n");
102 printf ("CPU time used : ");
103 chrono_Write (Timer, chrono_hms);
104 printf ("\n");
105 unif01_WriteState (gen);
106 printf ("\n\n\n");
107 }
108
109
110 /*=========================================================================*/
111
swrite_AddStrChi(char S[],int len,long d)112 void swrite_AddStrChi (char S[], int len, long d)
113 {
114 char str[31];
115 int j;
116 strncpy (S, "Number of degrees of freedom : ", len);
117 j = strlen (S);
118 util_Assert (len > j, "swrite_AddStrChi: len <= j");
119 sprintf (str, "%4ld", d);
120 strncat (S, str, len - j);
121 j = strlen (S);
122 util_Assert (len > j, "swrite_AddStrChi *: len <= j");
123 strncat (S, "\nChi-square statistic :", len - j);
124 S[len - 1] = '\0';
125 }
126
127
128 /*=========================================================================*/
129
swrite_NormalSumTest(long N,sres_Basic * res)130 void swrite_NormalSumTest (long N, sres_Basic *res)
131 {
132 if (N <= 1)
133 return;
134 printf ("Tests on the sum of all N observations\n");
135 printf ("Standardized normal statistic :");
136 gofw_Writep2 (res->sVal2[gofw_Sum]/sqrt((double)N), res->pVal2[gofw_Sum]);
137 printf ("Sample variance :");
138 gofw_Writep2 (res->sVal2[gofw_Var], res->pVal2[gofw_Var]);
139 }
140
141
142 /*=========================================================================*/
143 #define LENGTH 200
144
swrite_Chi2SumTest(long N,sres_Chi2 * res)145 void swrite_Chi2SumTest (long N, sres_Chi2 *res)
146 {
147 char str[LENGTH + 1];
148 if (N <= 1)
149 return;
150 printf ("Test on the sum of all N observations\n");
151 swrite_AddStrChi (str, LENGTH, N*res->degFree);
152 printf (str);
153 gofw_Writep2 (res->sVal2[gofw_Sum], res->pVal2[gofw_Sum]);
154 }
155
156
157 /*=========================================================================*/
158
swrite_Chi2SumTestb(long N,double sval,double pval,long degFree)159 void swrite_Chi2SumTestb (long N, double sval, double pval, long degFree)
160 {
161 char str[LENGTH + 1];
162 if (N <= 1)
163 return;
164 printf ("Test on the sum of all N observations\n");
165 swrite_AddStrChi (str, LENGTH, N*degFree);
166 printf (str);
167 gofw_Writep2 (sval, pval);
168 }
169
170