C
x
125
1
2
3
4
5
6
char fileName[200];
7
FILE *myFile;
8
int K, cols;
9
long double * binomialProbability;//pow(2,K)
10
long double p;
11
int * temp, * zeta;//K * pow(2,K)
12
13
void allocatePatternsWProbability(void);
14
void generateAllBinaryStrings(int col, int row);
15
void putInZeta(int i);
16
void printStrings(void);
17
18
/***************************************************************************************************/
19
int main( int argc , char * argv[] ){
20
int i, j, offset;
21
22
if ( argc != 3 ){
23
printf("Usage: K p\n");
24
exit(-9);
25
}
26
K = (int) atoi(argv[1]);
27
p = (long double) atof(argv[2]);
28
cols = pow(2,K);
29
30
allocatePatternsWProbability();
31
32
sprintf(fileName, "binaryStrings_K%d_p%Lg.dat", K, p);
33
myFile=fopen(fileName,"w");
34
if(myFile == NULL){
35
printf("myFile fopen failed ABORT\n");
36
exit(-9);
37
}
38
39
fprintf(myFile,"# binary_strings.c generates binary strings of lenght K\n");
40
fprintf(myFile,"# along with their binomial probability in the case there is a probability p of having a +1 bit.\n");
41
42
for(i=0; i<cols; i++){
43
fprintf(myFile, "%Lg ", binomialProbability[i]);
44
}
45
fprintf(myFile, "\n");
46
for(i=0; i<cols; i++){
47
for(j=0; j<K; j++){
48
offset = i + cols * j;
49
fprintf(myFile, "%d ", zeta[offset]);
50
}
51
fprintf(myFile, "\n");
52
}
53
54
fclose(myFile);
55
56
return 0;
57
}
58
59
/***************************************************************************************************/
60
61
void allocatePatternsWProbability(void){
62
int i, j, sum, offset, n;
63
64
temp = (int *)malloc(K * sizeof(int));
65
if(temp == NULL){
66
printf("temp malloc failed ABORT\n");
67
fprintf(myFile, "temp malloc failed ABORT\n");
68
exit(-9);
69
}
70
zeta = (int *)malloc(K * cols * sizeof(int));
71
if(zeta == NULL){
72
printf("zeta malloc failed ABORT\n");
73
fprintf(myFile, "zeta malloc failed ABORT\n");
74
exit(-9);
75
}
76
77
binomialProbability = (long double *)malloc(cols * sizeof(long double));
78
if(binomialProbability == NULL){
79
printf("binomialProbability malloc failed ABORT\n");
80
fprintf(myFile, "binomialProbability malloc failed ABORT\n");
$ gcc prog.c -Wall -Wextra -O2 -march=native -std=c99 -pedantic "-lm"
Start
temp 0 = -1 and zeta 0 = -1 temp 1 = -1 and zeta 4 = -1 temp 0 = -1 and zeta 0 = -1 temp 1 = 1 and zeta 4 = 1 temp 0 = 1 and zeta 0 = 1 temp 1 = -1 and zeta 4 = -1 temp 0 = 1 and zeta 0 = 1 temp 1 = 1 and zeta 4 = 1 zeta 0 = 1 zeta 4 = 1 n 2 binomialProbability 0.0625 zeta 1 = 0 zeta 5 = 0 n 1 binomialProbability 0.1875 zeta 2 = 0 zeta 6 = 0 n 1 binomialProbability 0.1875 zeta 3 = 0 zeta 7 = 0 n 1 binomialProbability 0.1875
0
Finish