1 |
//#include <iostream> |
2 |
#include <sys/time.h> |
3 |
#include <stdlib.h> |
4 |
//#include <stream.h> |
5 |
//#include <iostream.h> |
6 |
//#include <fstream> |
7 |
#include <stdio.h> |
8 |
//#include <string> |
9 |
#define WS_2_TABLE_MAX_ELEM 873 |
10 |
#include <errno.h> |
11 |
|
12 |
|
13 |
|
14 |
|
15 |
char ws_char[2]={'A','B'}; |
16 |
//clock_t tt; |
17 |
long lsec; |
18 |
struct timeval tv; |
19 |
struct timezone tz; |
20 |
int step; |
21 |
|
22 |
// |
23 |
|
24 |
int main(int argc, char *argv[]) |
25 |
{ |
26 |
int sec,i,n,step,mins,real_step,j,current_time,time_hole,start_time; |
27 |
FILE *F; |
28 |
const char *fname_prefix=argv[1]; |
29 |
const char *timesync=argv[2]; |
30 |
static char fname[102]; |
31 |
if (argc != 7) |
32 |
{ |
33 |
printf("Mancano i parametri!: \n fname_prefix timesync time_hole n-rows-in_table mins step\n"); |
34 |
return 1; |
35 |
} |
36 |
|
37 |
time_hole=atoi(argv[3]); |
38 |
n = atoi(argv[4]); |
39 |
if(n>WS_2_TABLE_MAX_ELEM) |
40 |
{ |
41 |
printf("n > %d\n",WS_2_TABLE_MAX_ELEM);; |
42 |
return 1; |
43 |
|
44 |
} |
45 |
|
46 |
mins = atoi(argv[5]); |
47 |
step = atoi(argv[6]); |
48 |
i = 0; |
49 |
if(step < mins) |
50 |
{ |
51 |
printf("step < mins"); |
52 |
return 5; |
53 |
} |
54 |
gettimeofday(&tv,&tz); |
55 |
srand(tv.tv_sec); |
56 |
current_time=atoi(timesync); |
57 |
for(i=0;i<16;i++) |
58 |
{ |
59 |
|
60 |
sprintf(fname,"%s%d.txt",fname_prefix,i); |
61 |
F=fopen(fname,"w+"); |
62 |
if(!F) { |
63 |
printf("error %d creating file %s",errno,fname); |
64 |
return 4; |
65 |
} |
66 |
// of.open(fname); |
67 |
start_time=current_time; |
68 |
fprintf(F,"%d\n%d\n",start_time,i); |
69 |
|
70 |
for(j=0;j<n;j++) |
71 |
{ |
72 |
/* do { |
73 |
|
74 |
real_step = lsec % step; |
75 |
} while(real_step <= mins); |
76 |
*/ |
77 |
real_step = mins+(int) ((step-mins+1)*1.0*rand()/(RAND_MAX+1.0)); |
78 |
fprintf(F,"%c %d\n",ws_char[(real_step %2)],real_step); |
79 |
current_time += real_step*8; |
80 |
} |
81 |
close(F); |
82 |
printf("txable: %d tsync: %d - stop at %d\n",i,start_time,current_time); |
83 |
current_time += time_hole; |
84 |
} |
85 |
return 0; |
86 |
} |