/[PAMELA software]/rawreader/source/Read.cpp
ViewVC logotype

Annotation of /rawreader/source/Read.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (download) (vendor branch)
Thu Aug 31 14:06:14 2006 UTC (18 years, 3 months ago) by pam-fi
Branch: rawreader, MAIN
CVS Tags: R0v00, HEAD
Changes since 1.1: +0 -0 lines
First rawreader release

1 pam-fi 1.1 #include "descript.h"
2    
3     void filename(char [], char [], char [], char[], int, char[]);
4     void FindRoute(int[], int*);
5     short int CRC(int []);
6     int restrict(int [], long long int[], int);
7    
8     void read(char fni[], char fno[], char INF[],
9     char protocol[], char path[], char name[], char nnnnn_TMP[], float quality[], int real_route[], int &Rcount)
10     {
11     FILE *fo, *fo1, *fout, *foRout, *foMiss, *fo_log_kadr, *fo_route;
12     ifstream fin;
13     ofstream fo_cln1, fokadr_cln1;
14    
15     char buf[1024];
16     // char stop1;
17     char ch1,ch2,ch3, ch, file_name_prot[80];
18     char file_route[80]; /*protocol binary filesm mmm_counter_nnnnn_cln1Er.log*/
19     char miss_file[80]; /*protocol files mmm_counter_nnnnn_mis_cln1.dat*/
20     char cln1_file[80]; /*route binary data files mmm_counter_nnnnn_cln1.pam*/
21     char cln1_kadr[80]; /*route binary data files mmm_counter_nnnnn_cln1.bin*/
22     char log_kadr[80]; /*log binary data files mmm_counter_nnnnn_cln1.log*/
23     char log_route[80]; /*log binary file for number of routes*/
24     char Short_Buf[8], Name_Buf[4];
25     short int CalcCheckSum;
26    
27     int LenthBuf=1015, flag_help=0;
28     int i, j, k, file_length=0, Hex[3];
29     int N_er=0; /*Number of kadr with name error*/
30     int CRC0_er=0; /*Number of kadr with CRC0 error*/
31     int P_er=0; /*Number of kadr with packet error number*/
32     int M_er=0; /*Number of kadr with rout error number*/
33     int end=0; /*End of last pamela packet*/
34     // Buffers for Kadr analysis
35     int buffer1[1024], buffer2[1024], buffer3[1024];
36     int rr=0;
37    
38     int header1, header2, header3, CRC_0[3], CRC_1[3];
39     long long int icount_int;
40     long long int icount_frac, tmpP, numP[3];
41     long int N1=0; /* Number of identified kadrs*/
42     long long int icount=0; /* Number of bytes in identified kadrs*/
43     long long int icount_total=0; /* Total number of bytes*/
44     long long int packet_first[100];/*First kadr number for each route*/
45     long long int packet_last[100]; /*Second kadr number for each route*/
46     long int count_missed[100]; /* Number of missed kadrs in each route*/
47     long int count_sec_missed[100];
48     unsigned long long int count_ident[100]; /* Number of good bytes in each rout*/
49     unsigned long long int count_tot[100]; /* Total number of bytes in each rout*/
50     int NumRout[1000]; /* Number of Route*/
51     long long int Num_kadrs[1000]; /* Number of identified kadrs in each rout*/
52     long int Num_good_kadrs[1000]; /* Number of normal kadrs in each rout*/
53     long long int Num_bad_kadrs[1000]; /* Bad kadrs number in each rout*/
54     // float quality[100]; /* File quality pointer*/
55     int counter=0; /* Last byte position in truncated kadr*/
56     int adr1=0; /* Initial byte of kadr in cln1.bin*/
57     int adr2=0; /* Last byte of kadr in cln2.bin*/
58     int tmp=0;
59     int numPack[4]; /* Number of kadr in given route*/
60     int adress[4];
61     int R_er[100]; /* Rout errors number in given rout*/
62     int R_er_interf1[100]; /* Interface Rout error at begin of rout*/
63     int R_er_interf2[100]; /* Interface Rout error at end of rout*/
64     int Mis_group[1000]; /* Number of missed kadrs group
65     for each rout*/
66     int Pack_Er[1000]; /* Number of packets with packet number
67     error for each rout*/
68     int CRC_bad_kadr[3]; /* Current CRC bad kadr number*/
69     int flag_pack[3]; /* Flag for error in packet number*/
70     int flag_rout[3]; /* Flag for error in rout number*/
71     int flag_name[3]; /* Flag for name error*/
72     int flag_CRC0[3]; /* Flag for CRC0 error*/
73     int flag_CRC[3]; /* Flag for CRC error*/
74     int flag_CRC_cor[3]; /* Flag for CRC error correction*/
75     int flag_tr[3]; /* Truncate flag*/
76     short int flags; /* Number for all errors*/
77    
78     for (j=0; j<4; j++) {adress[j]=0; numPack[j]=0;}
79     for (j=0; j<1024; j++)
80     {buffer1[j]=0; buffer2[j]=0; buffer3[j]=0;}
81     for (i=0; i<100; i++)
82     {Num_kadrs[i]=0;
83     NumRout[i]=0;
84     packet_first[i]=0;
85     packet_last[i]=0;
86     count_missed[i]=0;
87     count_sec_missed[i]=0;
88     count_ident[i]=0;
89     count_tot[i]=0;
90     R_er[i]=0;
91     R_er_interf1[i]=0;
92     Num_bad_kadrs[i]=0;
93     Num_good_kadrs[i]=0;
94     quality[i]=0; Mis_group[i]=0; Pack_Er[i]=0;
95     R_er_interf2[i]=0;}
96     for (i=0; i<3; i++)
97     {numP[i]=0; CRC_bad_kadr[i]=0; Hex[i]=0;
98     flag_pack[i]=0; flag_rout[i]=0;
99     flag_name[i]=0; flag_CRC0[i]=0; flag_tr[i]=0;
100     flag_CRC[i]=0; flag_CRC_cor[i]=0;}
101     // open input file "nnnnnmmm.pam"
102     fin.open(fni, ifstream::binary);
103     if(fin.good()==0) {cerr<<"can not open input file"; exit(0);}
104     //open output file "nnnnnmmm_work.dat"
105     fout=fopen(fno, "wb");
106     if(fout==0) {cerr<<"can not open outputfile"; exit(0);}
107     //open output file "nnnnnmmm_protocol.txt"
108     fo=fopen(protocol, "wb");
109     if(fo==0) {cerr<<"can not open protocol file"; exit(0);}
110     //open output file "nnnnnmmm_cln1.inf"
111     fo1=fopen(INF, "wb");
112     if(fo1==0) {cerr<<"can not open inf file"; exit(0);}
113     //open output file "nnnnnmmm_route.log"
114     strncpy(log_route,INF,strlen(INF)-9);
115     log_route[strlen(INF)-9]='\0';
116     strcat(log_route,"_route.log");
117     fo_route=fopen(log_route, "wb");
118     if(fo_route==0) {cerr<<"can not open file for routes number"; exit(0);}
119     /////////////////////////////////////////////////////////////////
120     // cin>>stop1;
121     k=0;
122     while(fin.eof()==0)
123     {
124     counter=0; //pounter for position of kadr truncation
125     N_er=0;
126     M_er=0;
127     P_er=0;
128     CRC0_er=0;
129     if (N1==0) Rcount=1;
130     /**********************data reading********************************/
131     fin.read(Name_Buf,3);
132     if (fin.eof()) break;
133     fin.read(Short_Buf,5);
134     if (fin.eof()) break;
135     ch1=Name_Buf[0];
136     ch2=Name_Buf[1];
137     ch3=Name_Buf[2];
138     tmpP=(long int)(unsigned char)(Short_Buf[1])+
139     256*(long int)(unsigned char)(Short_Buf[2])+
140     256*256*(long int)(unsigned char)(Short_Buf[3]);
141     icount+=8; icount_total+=8;
142     count_ident[Rcount-1]+=8; count_tot[Rcount-1]+=8;
143    
144     while((ch1!=(char)(CODE1)&&ch2!=(char)(CODE2)&&
145     (N1==0||buffer3[1023]!=(int)(unsigned char)(Short_Buf[4])||buffer3[3]!=(int)(unsigned char)(Short_Buf[0])))
146     ||
147     (ch2!=(char)(CODE2)&&ch3!=(char)(CODE3)&&(buffer3[1023]!=(int)(unsigned char)(Short_Buf[4])||(numP[2]+1)!=tmpP))
148     ||
149     (ch3!=(char)(CODE3)&&ch1!=(char)(CODE1)&&((numP[2]+1)!=tmpP||buffer3[1023]!=(int)(unsigned char)(Short_Buf[4])))
150     ||
151     (ch1!=(char)(CODE1)&&
152     (buffer3[1023]!=(int)(unsigned char)(Short_Buf[4])||buffer3[3]!=(int)(unsigned char)(Short_Buf[0])||(numP[2]+1)!=tmpP))
153     ||
154     (ch2!=(char)(CODE2)&&
155     (buffer3[1023]!=(int)(unsigned char)(Short_Buf[4])||buffer3[3]!=(int)(unsigned char)(Short_Buf[0])||(numP[2]+1)!=tmpP))
156     ||
157     (ch3!=(char)(CODE3)&&
158     (buffer3[1023]!=(int)(unsigned char)(Short_Buf[4])||buffer3[3]!=(int)(unsigned char)(Short_Buf[0])||(numP[2]+1)!=tmpP))
159     ||
160     (ch1!=(char)(CODE1)&&ch2!=(char)(CODE2)&&ch3!=(char)(CODE3)))
161     {fin.get(ch);
162     if (fin.eof()) {/*cerr<<"\n"<<"gopa";*/ break;}
163     ch1=ch2; ch2=ch3; ch3=Short_Buf[0];
164     for (i=0;i<4;i++) Short_Buf[i]=Short_Buf[i+1]; Short_Buf[4]=ch;
165     icount_total+=1; count_tot[Rcount-1]+=1;
166     tmpP=(long int)(unsigned char)(Short_Buf[1])+
167     256*(long int)(unsigned char)(Short_Buf[2])+
168     256*256*(long int)(unsigned char)(Short_Buf[3]);
169     }
170     if ((fin.eof())&&(N1==0))
171     {
172     fclose(fout);
173     remove(fno);
174     fclose(fo);
175     remove(protocol);
176     fclose(fo1);
177     remove(INF);
178     exit(0);
179     }
180     // cout<<"icount_total="<<icount_total<<" "<<N1<<"\n";
181     // printf("%x %x %x \n",(int)(unsigned char)(ch1),(int)(unsigned char)(ch2),(int)(unsigned char)(ch3));
182     // printf("%x %x %x %x %x\n",(int)(unsigned char)(Short_Buf[0]),(int)(unsigned char)(Short_Buf[1]),
183     // (int)(unsigned char)(Short_Buf[2]),(int)(unsigned char)(Short_Buf[3]),
184     // (int)(unsigned char)(Short_Buf[4]));
185     // printf("buffer3[3]= %x\n",(int)(unsigned char)buffer3[3]);
186     // printf("numP[2]+1= %x tmpP= %x\n",numP[2]+1, tmpP);
187     // printf("buffer3[1023]= %x\n",(int)(unsigned char)buffer3[1023], tmpP);
188    
189     /*****************************************************************/
190     /*********************data reading********************************/
191     fin.read(buf,LenthBuf);
192     if (fin.eof()) break;
193     icount+=1015; icount_total+=1015;
194     count_ident[Rcount-1]+=1015; count_tot[Rcount-1]+=1015;
195     /****************************************************************/
196     /********************data reading********************************/
197     fin.get(ch);
198     icount+=1; icount_total+=1;
199     count_ident[Rcount-1]+=1; count_tot[Rcount-1]+=1;
200     if (fin.eof()) break;
201     /***************************************************************/
202     N1+=1; Num_kadrs[Rcount-1]+=1;
203    
204     /**********************DATA ANALYSIS****************************/
205     /***************************************************************/
206     header1=(unsigned char)(ch1);
207     header2=(unsigned char)(ch2);
208     header3=(unsigned char)(ch3);
209     switch (N1)
210     {
211     case 1:{
212     buffer3[0]=(int)(unsigned char)(ch1);
213     buffer3[1]=(int)(unsigned char)(ch2);
214     buffer3[2]=(int)(unsigned char)(ch3);
215     buffer3[3]=(int)(unsigned char)(Short_Buf[0]);
216     buffer3[4]=(int)(unsigned char)(Short_Buf[1]);
217     buffer3[5]=(int)(unsigned char)(Short_Buf[2]);
218     buffer3[6]=(int)(unsigned char)(Short_Buf[3]);
219     buffer3[7]=(int)(unsigned char)(Short_Buf[4]);
220     for (i=0; i<1015; i++)
221     {buffer3[i+8]=(int)(unsigned char)(buf[i]);}
222     buffer3[1023]=(int)(unsigned char)(ch);
223     for (i=0; i<1024; i++)
224     {buffer1[i]=buffer3[i];buffer2[i]=buffer3[i];}
225    
226     NumRout[Rcount-1]=1;
227     numP[2]=(long int)(unsigned char)(Short_Buf[1])+
228     256*(long int)(unsigned char)(Short_Buf[2])+
229     256*256*(long int)(unsigned char)(Short_Buf[3]);
230     CRC_bad_kadr[2]=0;
231     flag_pack[2]=0; flag_rout[2]=0;
232     flag_name[2]=0; flag_CRC0[2]=0; flag_tr[2]=0;
233     flag_CRC[2]=0; flag_CRC_cor[2]=0;
234     for (i=0; i<2; i++)
235     {numP[i]=numP[2];CRC_bad_kadr[i]=CRC_bad_kadr[2];
236     flag_pack[i]=flag_pack[2]; flag_rout[i]=flag_rout[2];
237     flag_name[i]=flag_name[2]; flag_CRC0[i]=flag_CRC0[2];
238     flag_CRC[i]=flag_CRC[2]; flag_tr[i]=flag_tr[2];
239     flag_CRC_cor[i]=flag_CRC_cor[2];}
240     CRC_0[2]=(int)(unsigned char)(Short_Buf[4]);
241     for (i=0; i<2; i++)
242     {CRC_0[i]=CRC_0[2];}
243     CRC_1[2]=(int)(unsigned char)(ch);
244     for (i=0; i<2; i++)
245     {CRC_1[i]=CRC_1[2];}
246     packet_first[Rcount-1]=numP[2];
247     break;
248     }
249     default:{
250     for (i=0; i<1024; i++)
251     {buffer1[i]=buffer2[i];buffer2[i]=buffer3[i];}
252     buffer3[0]=(int)(unsigned char)(ch1);
253     buffer3[1]=(int)(unsigned char)(ch2);
254     buffer3[2]=(int)(unsigned char)(ch3);
255     buffer3[3]=(int)(unsigned char)(Short_Buf[0]);
256     buffer3[4]=(int)(unsigned char)(Short_Buf[1]);
257     buffer3[5]=(int)(unsigned char)(Short_Buf[2]);
258     buffer3[6]=(int)(unsigned char)(Short_Buf[3]);
259     buffer3[7]=(int)(unsigned char)(Short_Buf[4]);
260     for (i=0; i<1015; i++)
261     {buffer3[i+8]=(int)(unsigned char)(buf[i]);}
262     buffer3[1023]=(int)(unsigned char)(ch);
263    
264     for (i=0; i<2; i++)
265     {numP[i]=numP[i+1]; CRC_bad_kadr[i]=CRC_bad_kadr[i+1];
266     flag_pack[i]=flag_pack[i+1];
267     flag_rout[i]=flag_rout[i+1];
268     flag_name[i]=flag_name[i+1];
269     flag_CRC0[i]=flag_CRC0[i+1];
270     flag_tr[i]=flag_tr[i+1];
271     flag_CRC[i]=flag_CRC[i+1];
272     flag_CRC_cor[i]=flag_CRC_cor[i+1];}
273     numP[2]=(long int)(unsigned char)(Short_Buf[1])+
274     256*(long int)(unsigned char)(Short_Buf[2])+
275     256*256*(long int)(unsigned char)(Short_Buf[3]);
276     CRC_bad_kadr[2]=0;
277     flag_pack[2]=0; flag_rout[2]=0;
278     flag_name[2]=0; flag_CRC0[2]=0;
279     flag_CRC[2]=0; flag_CRC_cor[2]=0; flag_tr[2]=0;
280     for (i=0; i<2; i++) CRC_0[i]=CRC_0[i+1];
281     CRC_0[2]=(int)(unsigned char)(Short_Buf[4]);
282     for (i=0; i<2; i++) {CRC_1[i]=CRC_1[i+1];}
283     CRC_1[2]=(int)(unsigned char)(ch);
284     }
285     }
286     if (fmod(N1,10000)==0.) cout<<N1<<"\n";
287    
288     /******************CRC ERROR ANALYSIS***************************/
289     CalcCheckSum=CRC(buffer3);
290     if (CalcCheckSum!=(short int)(buffer3[1023]))
291     {
292     /*if (numP[2]==1026)
293     {for (i=0;i<8;i++) printf(" %x ",buffer3[i]); printf("\n");
294     for (i=8;i<16;i++) printf(" %x ",buffer3[i]); printf("\n");
295     for (i=1000;i<1008;i++) printf(" %x ",buffer3[i]); printf("\n");
296     printf("%x %x %x %x",buffer3[1020],buffer3[1021],buffer3[1022],buffer3[1023]);
297     cin>>i;}*/
298     fprintf(fout,"CRC = %x (%x) error in kadr %i\n", buffer3[1023],CalcCheckSum,numP[2]); //write in file nnnnn_work.dat
299     // cerr<<"checksum error "<<Rcount<<" Cadre="<<numP[2]<<
300     // " "<<buffer3[3]<<"\n";
301     flag_CRC[2]=1;
302     Num_bad_kadrs[Rcount-1]+=1;
303     CRC_bad_kadr[2]=numP[2];
304     counter=restrict(buffer3,numP,buffer2[3]);
305     if (counter!=0)
306     {fprintf(fout," truncate byte=%i",counter);
307     cout<<" truncate counter="<<counter<<" route="<<buffer2[3]<<" "<<buffer3[3]<<" kadr="<<numP[2]<<" "<<numP[1]<<" "<<numP[0]<<"\n";
308     fin.seekg(-(1024-counter),ios::cur);
309     icount-=1024;
310     count_ident[Rcount-1]-=1024;
311     count_tot[Rcount-1]-=1024-counter;
312     icount_total-=1024-counter;
313     N1-=1;
314     CRC_bad_kadr[2]=0;
315     flag_tr[2]=1;
316     Num_kadrs[Rcount-1]-=1;
317     Num_bad_kadrs[Rcount-1]-=1;}
318     }
319    
320     /******************HEADER ANALYSIS*******************************/
321     if ((header1!=(int)(CODE1))||(header2!=(int)(CODE2))||(header3!=(int)(CODE3)))
322     {flag_name[2]=1; N_er=N1;}
323     /****************************************************************/
324    
325     /******************CRC0 ANALYSIS*********************************/
326     if ((buffer2[7]!=buffer1[1023])&&
327     ((numP[1]==numP[0]+1)||(numP[1]==numP[2]-1))&&(flag_tr[1]!=1)&&(flag_tr[0]!=1)&&(N1>2))
328     {flag_CRC0[1]=1; CRC0_er=N1-1;}
329     /****************************************************************/
330    
331     /******************KADR NUMBER ANALYSIS**************************/
332     if ((numP[1]!=(numP[0]+1))&&(numP[1]!=(numP[2]-1))&&(N1!=1)&&(CRC_bad_kadr[1]==numP[1])&&(numP[1]!=0))
333     {P_er=N1-1; flag_pack[1]=1;
334     //Correct error packet number//
335     tmpP=numP[0]+1;
336     for (i=0;i<3;i++) Hex[i]=0;
337     for (i=0;i<3;i++)
338     {if (tmpP/(long int)(pow(256.,2-i))>=1)
339     {Hex[2-i]=(int)(tmpP/(long int)(pow(256.,2-i)));
340     tmpP=tmpP-(long int)pow(256.,2-i)*(int)(tmpP/(long int)(pow(256.,2-i)));}}
341     for (i=4;i<7;i++) (buffer2[i]=Hex[i-4]);
342     if (buffer2[1023]==(int)(CRC(buffer2))) flag_CRC_cor[1]=1;
343    
344     tmpP=numP[2]-1;
345     for (i=0;i<3;i++) Hex[i]=0;
346     for (i=0;i<3;i++)
347     {if (tmpP/(long int)(pow(256.,2-i))>=1)
348     {Hex[2-i]=(int)(tmpP/(long int)(pow(256.,2-i)));
349     tmpP=tmpP-(long int)pow(256.,2-i)*(int)(tmpP/(long int)(pow(256.,2-i)));}}
350     for (i=4;i<7;i++) (buffer2[i]=Hex[i-4]);
351     if (buffer2[1023]==(int)(CRC(buffer2))) flag_CRC_cor[1]=1;
352     }
353     /////////////////////////////////////////////////////////////////////
354     if ((numP[2]!=(numP[1]+1))&&(N1!=1)&&(buffer3[3]==buffer2[3])&&(CRC_bad_kadr[2]==numP[2])&&(numP[2]!=0)) flag_pack[2]=1;
355     if (flag_pack[2]!=1) packet_last[Rcount-1]=numP[2];
356     ////////Missing kadr analysis////////////////////////////////////
357     /**route number: 10 (10 19 10) 10 ******************************/
358     /**kadr number: 21 (22 17 18) 19 ******************************/
359     /**missed kadrs: 21 20 19 18 17 ******************************/
360     if ((numP[1]<numP[0])&&(numP[1]==numP[2]-1)&&(buffer1[3]==buffer3[3])&&(flag_tr[1]==0)&&
361     (flag_pack[0]==0)&&(flag_pack[1]==0)&&(flag_pack[2]==0))
362     {Mis_group[Rcount-1]+=1;
363     fprintf(foMiss,"secondary transmitted kadres may be %9i%9i\n",numP[1]+1,numP[0]-1);
364     count_sec_missed[Rcount-1]+=numP[0]-1-numP[1]-1;}
365     /**route number: 10 (10 19 10) 10 ******************************/
366     /**kadr number: 11 (12 15 20) 21 ******************************/
367     /**missed kadrs: 16 17 18 19 ******************************/
368     if ((numP[1]>numP[0]+1)&&(numP[1]<numP[2]-1)&&(buffer1[3]==buffer3[3])&&(flag_tr[1]==0)&&
369     (flag_pack[0]==0)&&(flag_pack[1]==0)&&(flag_pack[2]==0))
370     {Mis_group[Rcount-1]+=1;
371     fprintf(foMiss,"%9i%9i\n",numP[1]+1,numP[2]-1);
372     count_missed[Rcount-1]+=numP[2]-numP[1]-1;}
373     /**route number: (10 10 10) 10 10 ******************************/
374     /**kadr number: (11 12 15) 20 21 ******************************/
375     /**missed kadrs: 13 14 ******************************/
376     else if ((numP[1]>=numP[0]+1)&&(numP[1]<numP[2]-1)&&
377     (buffer1[3]==buffer3[3])&&(buffer1[3]==buffer2[3])&&
378     (flag_tr[1]==0)&&(flag_pack[2]==0)&&(flag_pack[1]==0)&&(flag_pack[0]==0))
379     {Mis_group[Rcount-1]+=1;
380     fprintf(foMiss,"%9i%9i\n",numP[0]+2,numP[2]-1);
381     count_missed[Rcount-1]+=numP[2]-numP[0]-1-1;}
382     /**route number: (10 10 10) 10 10 ******************************/
383     /**kadr number: (11 29 15) 14 15 ******************************/
384     /**number of missed kadrs:2 ******************************/
385     else if (((numP[1]<numP[0]+1)||(numP[1]>numP[2]-1))&&(numP[2]-numP[0]>2)&&
386     (buffer1[3]==buffer3[3])&&(buffer1[3]==buffer2[3])&&(flag_tr[1]==0)&&
387     (flag_pack[2]==0)&&(flag_pack[1]==1)&&(flag_pack[0]==0))
388     {Mis_group[Rcount-1]+=1;
389     fprintf(foMiss,"%9i%9i -1\n",numP[0]+1,numP[2]-1);
390     count_missed[Rcount-1]+=numP[2]-numP[0]-1-1;}
391     //truncate kadr
392     /**route number: 10 (10 10 10) 10 ******************************/
393     /**kadr number: 11 (12 13 14) 15 ******************************/
394     /**missed truncate kadr:13 ******************************/
395     else if ((numP[0]<numP[2]-1)&&(buffer1[3]==buffer3[3])&&
396     (flag_tr[0]==0)&&(flag_tr[1]==1)&&(flag_tr[2]==0)&&
397     (flag_pack[2]==0)&&(flag_pack[1]==0)&&(flag_pack[0]==0))
398     {Mis_group[Rcount-1]+=1;
399     fprintf(foMiss,"%9i%9i\n",numP[0]+1,numP[2]-1);
400     count_missed[Rcount-1]+=numP[2]-numP[0]-1;}
401     /***************************************************************/
402    
403     /******************ROUTE NUMBER ANALYSIS**************************/
404     if ((buffer2[3]!=buffer1[3])&&(buffer2[3]!=buffer3[3])&&(buffer1[3]!=buffer3[3])&&
405     (flag_pack[2]==0)&&(flag_pack[1]==0)&&(flag_pack[0]==0))
406     {
407     /******************Interface route error 1***********************/
408     /**route number:7 7 ( 7 4 8) 8 8 **************************/
409     /**kadr number:197 198 (199 200 1) 2 3 **************************/
410     /*if ((numP[1]==numP[0]+1)&&(numP[2]<numP[0]))
411     {Rcount+=1; flag_rout[1]=1;
412     packet_last[Rcount-2]=numP[1];
413     packet_first[Rcount-1]=numP[2];
414     Num_kadrs[Rcount-1]+=1;
415     Num_kadrs[Rcount-2]-=1;
416     R_er[Rcount-2]+=1;
417     R_er_interf2[Rcount-2]+=1;
418     M_er=N1-1;
419     count_ident[Rcount-1]+=1024; count_ident[Rcount-2]-=1024;
420     count_tot[Rcount-1]+=1024; count_tot[Rcount-2]-=1024;
421     NumRout[Rcount-1]=Rcount;
422     cout<<"\n interface1 "<<NumRout[Rcount-1]<<" "<<Rcount;
423     // cin>>stop1;
424     if ((CRC_bad_kadr[1]==numP[1])&&(numP[1]!=0))
425     {
426     //Correct error route number//////////////////////////////////////////
427     buffer2[3]=buffer1[3];
428     if (buffer2[1023]==(int)(CRC(buffer2))) flag_CRC_cor[1]=1;
429     ////////////////////////////////////////////////////////////////////
430     flags=(short int)(pow((float)(2*flag_name[1]),4)+
431     pow((float)(2*flag_rout[1]),1)+
432     pow((float)(2*flag_pack[1]),2)+
433     pow((float)(2*flag_CRC0[1]),3)+
434     pow((float)(2*flag_CRC[1]),5)+
435     pow((float)(2*flag_CRC_cor[1]),6));
436     fprintf(foRout,"%1c%1c%1c%1c",(char)(buffer2[4]),
437     (char)(buffer2[5]),(char)(buffer2[6]),(char)(flags));
438     fprintf(fout,"%i Interface route error 1 %i\n",CRC_bad_kadr[1],flags);
439     CRC_bad_kadr[1]=0;
440     }
441     // CREATE FILE NAMES
442     filename(file_route, miss_file, cln1_file, path,
443     NumRout[Rcount-1], name);
444     strncpy(cln1_kadr,cln1_file,strlen(cln1_file)-3);
445     cln1_kadr[strlen(cln1_file)-3]='\0';
446     strcat(cln1_kadr,"bin");
447     strncpy(log_kadr,file_route,strlen(file_route)-6);
448     log_kadr[strlen(file_route)-6]='\0';
449     strcat(log_kadr,"_bin.log");
450     fclose(foRout); //Close files
451     fo_cln1.close(); //for old
452     fclose(foMiss); //route
453     fokadr_cln1.close();
454     fclose(fo_log_kadr);
455     //Open files for new route
456     foRout=fopen(file_route, "wb"); //mmm_nnnnn_cln1Er.log
457     foMiss=fopen(miss_file, "wb"); //mmm_nnnnn_mis_cln1.dat
458     fo_cln1.open(cln1_file, ios::binary); //mmm_nnnnn_cln1.pam
459     fokadr_cln1.open(cln1_kadr,ios::binary); //mmm_nnnnn_cln1.bin
460     fo_log_kadr=fopen(log_kadr,"wb"); //mmm_nnnnn_cln1_bin.log
461     }*/
462     /******************Interface route error 2***********************/
463     /**route number:7 7 ( 7 4 8) 8 ******************************/
464     /**kadr number:198 199 (200 1 2) 3 ******************************/
465     /*if ((numP[1]==numP[2]-1)&&(numP[1]<numP[0])&&(buffer2[3]!=0))
466     {Rcount+=1; flag_rout[1]=1;
467     packet_last[Rcount-2]=numP[0];
468     packet_first[Rcount-1]=numP[1];
469     Num_kadrs[Rcount-1]+=2;
470     Num_kadrs[Rcount-2]-=2;
471     R_er[Rcount-1]+=1;
472     R_er_interf1[Rcount-1]+=1;
473     M_er=N1-1;
474     count_ident[Rcount-1]+=2048; count_ident[Rcount-2]-=2048;
475     count_tot[Rcount-1]+=2048; count_tot[Rcount-2]-=2048;
476     NumRout[Rcount-1]=Rcount;
477     cout<<"\n interface2 "<<NumRout[Rcount-1]<<" "<<Rcount;
478     // cin>>stop1;
479     // CREATE FILE NAMES
480     filename(file_route, miss_file, cln1_file, path,
481     NumRout[Rcount-1], name);
482     strncpy(cln1_kadr,cln1_file,strlen(cln1_file)-3);
483     cln1_kadr[strlen(cln1_file)-3]='\0';
484     strcat(cln1_kadr,"bin");
485     strncpy(log_kadr,file_route,strlen(file_route)-6);
486     log_kadr[strlen(file_route)-6]='\0';
487     strcat(log_kadr,"_bin.log");
488     fclose(foRout); //Close files
489     fo_cln1.close(); //for old
490     fclose(foMiss); //route
491     fokadr_cln1.close();
492     fclose(fo_log_kadr);
493     //Open files for new route
494     foRout=fopen(file_route, "wb"); //mmm_nnnnn_cln1Er.log
495     foMiss=fopen(miss_file, "wb"); //mmm_nnnnn_mis_cln1.dat
496     fo_cln1.open(cln1_file, ios::binary); //mmm_nnnnn_cln1.pam
497     fokadr_cln1.open(cln1_kadr,ios::binary); //mmm_nnnnn_cln1.bin
498     fo_log_kadr=fopen(log_kadr,"wb"); //mmm_nnnnn_cln1_bin.log
499     if ((CRC_bad_kadr[1]==numP[1])&&(numP[1]!=0))
500     {Num_bad_kadrs[Rcount-1]+=1; Num_bad_kadrs[Rcount-2]-=1;
501     //Correct error rout number//////////////////////////////////////////
502     buffer2[3]=buffer3[3];
503     if (buffer2[1023]==(int)(CRC(buffer2))) flag_CRC_cor[1]=1;
504     ////////////////////////////////////////////////////////////////////
505     flags=(short int)(pow((float)(2*flag_name[1]),4)+
506     pow((float)(2*flag_rout[1]),1)+
507     pow((float)(2*flag_pack[1]),2)+
508     pow((float)(2*flag_CRC0[1]),3)+
509     pow((float)(2*flag_CRC[1]),5)+
510     pow((float)(2*flag_CRC_cor[1]),6));
511     fprintf(foRout,"%1c%1c%1c%1c",(char)(buffer2[4]),(char)(buffer2[5]),(char)(buffer2[6]),(char)(flags));
512     fprintf(fout,"%i Interface route error 2 %i\n",CRC_bad_kadr[1],flags);
513     CRC_bad_kadr[1]=0;}
514     }*/
515     /******************Interface route error 3************************/
516     /**route number:7 7 ( 7 8 4) 8 8******************************/
517     /**kadr number:198 199 (200 1 2) 3 4******************************/
518     /* if ((numP[1]==numP[2]-1)&&(flag_CRC[1]==0)&&(flag_CRC[2]==1))
519     {Rcount+=1;
520     packet_last[Rcount-2]=numP[0];
521     packet_first[Rcount-1]=numP[1];
522     NumRout[Rcount-1]=Rcount;
523     Num_kadrs[Rcount-2]-=2;
524     Num_kadrs[Rcount-1]+=2;
525     count_ident[Rcount-1]+=2048; count_ident[Rcount-2]-=2048;
526     count_tot[Rcount-1]+=2048; count_tot[Rcount-2]-=2048;
527     Num_bad_kadrs[Rcount-1]+=1; Num_bad_kadrs[Rcount-2]-=1;
528     cout<<"\n interface3 "<<NumRout[Rcount-1]<<" "<<Rcount;
529     // cin>>stop1;
530     // CREATE FILE NAMES
531     filename(file_route, miss_file, cln1_file, path,
532     NumRout[Rcount-1], name);
533     strncpy(cln1_kadr,cln1_file,strlen(cln1_file)-3);
534     cln1_kadr[strlen(cln1_file)-3]='\0';
535     strcat(cln1_kadr,"bin");
536     strncpy(log_kadr,file_route,strlen(file_route)-6);
537     log_kadr[strlen(file_route)-6]='\0';
538     strcat(log_kadr,"_bin.log");
539     fclose(foRout); //Close files
540     fo_cln1.close(); //for old
541     fclose(foMiss); //route
542     fokadr_cln1.close();
543     fclose(fo_log_kadr);
544     //Open files for new route
545     foRout=fopen(file_route, "wb"); //mmm_nnnnn_cln1Er.log
546     foMiss=fopen(miss_file, "wb"); //mmm_nnnnn_mis_cln1.dat
547     fo_cln1.open(cln1_file, ios::binary); //mmm_nnnnn_cln1.pam
548     fokadr_cln1.open(cln1_kadr,ios::binary); //mmm_nnnnn_cln1.bin
549     fo_log_kadr=fopen(log_kadr,"wb"); //mmm_nnnnn_cln1_bin.log
550     flags=(short int)(pow((float)(2*flag_name[1]),4)+
551     pow((float)(2*flag_rout[1]),1)+
552     pow((float)(2*flag_pack[1]),2)+
553     pow((float)(2*flag_CRC0[1]),3)+
554     pow((float)(2*flag_CRC[1]),5)+
555     pow((float)(2*flag_CRC_cor[1]),6));
556     fprintf(foRout,"%1c%1c%1c%1c",(char)(buffer2[4]),(char)(buffer2[5]),(char)(buffer2[6]),(char)(flags));
557     fprintf(fout,"%i Interface route error 3 %i\n",CRC_bad_kadr[1],flags);
558     CRC_bad_kadr[1]=0;
559     }*/
560     }
561     /**************Return to old route*******************************/
562     /**route number: 7 (8 4 8) 8*************************************/
563     /*if ((buffer2[3]!=buffer1[3])&&(buffer2[3]!=buffer3[3])&&
564     (buffer1[3]==buffer3[3])&&(buffer2[3]!=0)&&(N1>2))
565     {
566     R_er[Rcount-1]+=1; flag_rout[1]=1;
567     M_er=N1-1;
568     if ((CRC_bad_kadr[1]==numP[1])&&(numP[1]!=0))
569     {
570     //Correct error route number//////////////////////////////////////////
571     buffer2[3]=buffer1[3];
572     if (buffer2[1023]==(int)(CRC(buffer2))) flag_CRC_cor[1]=1;
573     ////////////////////////////////////////////////////////////////////
574     flags=(short int)(pow((float)(2*flag_name[1]),4)+
575     pow((float)(2*flag_rout[1]),1)+
576     pow((float)(2*flag_pack[1]),2)+
577     pow((float)(2*flag_CRC0[1]),3)+
578     pow((float)(2*flag_CRC[1]),5)+
579     pow((float)(2*flag_CRC_cor[1]),6));
580     fprintf(foRout,"%1c%1c%1c%1c",(char)(buffer2[4]),(char)(buffer2[5]),(char)(buffer2[6]),(char)(flags));
581     fprintf(fout,"%i Old route error %i\n",CRC_bad_kadr[1],flags);
582     CRC_bad_kadr[1]=0;}
583     cout<<"\n"<<Rcount<<" old "<<NumRout[Rcount-1]<<" "<<buffer1[3]<<" "<<buffer2[3]<<" "<<buffer3[3]<<" N1="<<N1-1<<"\n";
584     }*/
585     /**************First route***************************************/
586     /**route number: (0 4) 4*****************************************/
587     /**kadr number: (0 1) 2*****************************************/
588     if (N1==2)
589     {packet_first[Rcount-1]=numP[1];
590     packet_last[Rcount-1]=numP[2];
591     NumRout[Rcount-1]=1;
592     // CREATE FILE NAMES
593     filename(file_route, miss_file, cln1_file, path,
594     NumRout[Rcount-1], name);
595     strncpy(cln1_kadr,cln1_file,strlen(cln1_file)-3);
596     cln1_kadr[strlen(cln1_file)-3]='\0';
597     strcat(cln1_kadr,"bin");
598     strncpy(log_kadr,file_route,strlen(file_route)-6);
599     log_kadr[strlen(file_route)-6]='\0';
600     strcat(log_kadr,"_bin.log");
601     //Open files for new route
602     foRout=fopen(file_route, "wb"); //mmm_nnnnn_cln1Er.log
603     foMiss=fopen(miss_file, "wb"); //mmm_nnnnn_mis_cln1.dat
604     fo_cln1.open(cln1_file, ios::binary); //mmm_nnnnn_cln1.pam
605     if (!fo_cln1) cout<<"can not open "<<cln1_file<<"\n";
606     fokadr_cln1.open(cln1_kadr,ios::binary); //mmm_nnnnn_cln1.bin
607     if (!fokadr_cln1) cout<<"can not open "<<cln1_kadr<<"\n";
608     fo_log_kadr=fopen(log_kadr,"wb"); //mmm_nnnnn_cln1_bin.log
609     // cout<<"\n"<<Rcount<<" old "<<NumRout[Rcount-1]<<" "<<numP[1]<<" N1="<<N1-1;
610     }
611     /***************New route***************************************/
612     /**route number: 7 ( 7 0 8) 8*********************************/
613     /**kadr number: 199 (200 0 1) 2*********************************/
614     /**route number: 7 ( 7 8 8) 8*********************************/
615     /**kadr number: 199 (200 0 1) 2*********************************/
616     if ( ((buffer1[3]!=buffer3[3])&&(buffer2[3]==0)&&(N1>3)&&(numP[1]!=numP[0]+1)&&(numP[1]<10))||
617     ((buffer1[3]!=buffer2[3])&&(buffer2[3]==buffer3[3])&&(buffer1[3]!=0)&&(numP[1]!=numP[0]+1)&&(numP[1]<10))||
618     ((numP[2]==numP[1]+1)&&(numP[1]==0)&&(Num_kadrs[Rcount-1]>1000000)) )
619     {Rcount+=1;
620     packet_last[Rcount-2]=numP[0];
621     packet_first[Rcount-1]=numP[1];
622     NumRout[Rcount-1]=Rcount;
623     cout<<"New route="<<Rcount<<" "<<buffer1[3]<<" "<<buffer2[3]<<" "<<buffer3[3]<<"\n";
624     cout<<numP[0]<<" "<<numP[1]<<" "<<numP[2]<<"\n";
625     if (flag_tr[1]==0)
626     {Num_kadrs[Rcount-2]-=2;
627     Num_kadrs[Rcount-1]+=2;
628     count_ident[Rcount-1]+=2048; count_ident[Rcount-2]-=2048;
629     count_tot[Rcount-1]+=2048; count_tot[Rcount-2]-=2048;}
630     else
631     {Num_kadrs[Rcount-2]-=1;
632     Num_kadrs[Rcount-1]+=1;
633     count_ident[Rcount-1]+=1024; count_ident[Rcount-2]-=1024;
634     count_tot[Rcount-1]+=1024; count_tot[Rcount-2]-=1024;}
635     // CREATE FILE NAMES
636     filename(file_route, miss_file, cln1_file, path,
637     NumRout[Rcount-1], name);
638     strncpy(cln1_kadr,cln1_file,strlen(cln1_file)-3);
639     cln1_kadr[strlen(cln1_file)-3]='\0';
640     strcat(cln1_kadr,"bin");
641     strncpy(log_kadr,file_route,strlen(file_route)-6);
642     log_kadr[strlen(file_route)-6]='\0';
643     strcat(log_kadr,"_bin.log");
644     fclose(foRout); //Close files
645     fo_cln1.close(); //for old
646     fclose(foMiss); //route
647     fokadr_cln1.close();
648     fclose(fo_log_kadr);
649     //Open files for new route
650     foRout=fopen(file_route, "wb"); //mmm_nnnnn_cln1Er.log
651     foMiss=fopen(miss_file, "wb"); //mmm_nnnnn_mis_cln1.dat
652     fo_cln1.open(cln1_file, ios::binary); //mmm_nnnnn_cln1.pam
653     fokadr_cln1.open(cln1_kadr,ios::binary); //mmm_nnnnn_cln1.bin
654     fo_log_kadr=fopen(log_kadr,"wb"); //mmm_nnnnn_cln1_bin.log
655     if ((CRC_bad_kadr[2]==numP[2])&&(numP[2]!=0)) {Num_bad_kadrs[Rcount-1]+=1; Num_bad_kadrs[Rcount-2]-=1;}
656     if ((CRC_bad_kadr[1]==numP[1])&&(numP[1]!=0))
657     {Num_bad_kadrs[Rcount-1]+=1; Num_bad_kadrs[Rcount-2]-=1;
658     flags=(short int)(pow((float)(2*flag_name[1]),4)+
659     pow((float)(2*flag_rout[1]),1)+
660     pow((float)(2*flag_pack[1]),2)+
661     pow((float)(2*flag_CRC0[1]),3)+
662     pow((float)(2*flag_CRC[1]),5)+
663     pow((float)(2*flag_CRC_cor[1]),6));
664     fprintf(foRout,"%1c%1c%1c%1c",(char)(buffer2[4]),(char)(buffer2[5]),(char)(buffer2[6]),(char)(flags));
665     fprintf(fout,"%i New route %i\n",CRC_bad_kadr[1],flags);
666     CRC_bad_kadr[1]=-1;}
667     // cout<<Rcount<<" New "<<NumRout[Rcount-1]<<" "<<numP[1]<<"\n";
668     }
669    
670     if ((numP[1]==0)&&(N1>1))
671     {rr=0;
672     FindRoute(buffer2, &rr);
673     if (rr>0)
674     {
675     real_route[Rcount]=rr;
676     }
677     else
678     {
679     real_route[Rcount]=0;
680     }
681     }
682     /***************************************************************/
683     if (CRC_bad_kadr[1]==numP[1])
684     {
685     //Correct CRC0 error/////////////////////////////////////////////////
686     buffer2[7]=buffer1[1023];
687     if (buffer2[1023]==(int)(CRC(buffer2))) flag_CRC_cor[1]=1;
688     //Correct name error/////////////////////////////////////////////////
689     buffer2[0]=(int)(CODE1);
690     buffer2[1]=(int)(CODE2);
691     buffer2[2]=(int)(CODE3);
692     if (buffer2[1023]==(int)(CRC(buffer2))) flag_CRC_cor[1]=1;
693     }
694     ////////////////////////////////////////////////////////////////////
695     /*******************************************************************/
696     if ((CRC_bad_kadr[1]==numP[1])&&(numP[1]!=0)&&(N1>1))
697     {
698     flags=(short int)(pow((float)(2*flag_name[1]),4)+
699     pow((float)(2*flag_rout[1]),1)+
700     pow((float)(2*flag_pack[1]),2)+
701     pow((float)(2*flag_CRC0[1]),3)+
702     pow((float)(2*flag_CRC[1]),5)+
703     pow((float)(2*flag_CRC_cor[1]),6));
704     fprintf(foRout,"%1c%1c%1c%1c",(char)(buffer2[4]),
705     (char)(buffer2[5]),(char)(buffer2[6]),(char)(flags));
706     fprintf(fout,"%i flags=%i\n",CRC_bad_kadr[1],flags);}
707    
708     /***************************************************************/
709     // cout <<"\nCalcChekSum="<<dec <<right<<CalcCheckSum
710     // <<"\npacket.CheckSum1="<<right<<packet.CheckSum1;
711     // cout <<"\nPacket number="<<packet.Pckt_Num<<" "<<endl;
712     //*Packet analysis**********************************************
713     if (N_er!=0) fprintf(fout,"Name error %i in kadr %i\n",numP[2],N_er);
714     if (M_er!=0) fprintf(fout,"Root number error %i in kadr %i\n",numP[1],M_er);
715     if (P_er!=0) fprintf(fout,"Number packet error %i in kadr %i\n",numP[1], P_er);
716     if (CRC0_er!=0) fprintf(fout,"CRC0 error %i in kadr %i\n",numP[1], CRC0_er);
717    
718     /***************PAMELA data extracting for each route***********/
719     // if (N1!=1&&(flag_CRC[1]==0||(flag_rout[1]==0&&flag_pack[1]==0)||
720     // (flag_CRC[1]!=0&&flag_CRC_cor[1]==1)))
721     if (N1!=1)
722     {end=0;
723     if (buffer2[3]!=buffer1[3]||buffer2[3]!=buffer3[3])
724     {for (i=8;i<1020;i++)
725     {
726     // if (fmodf(float((Num_kadrs[Rcount-1]-1)*1015+i-8),float(64))==0.&&buffer2[i]==0&&buffer2[i+1]==0&&
727     // buffer2[i+2]==0&&buffer2[i+3]==0) end=1;
728     if (end!=1) fo_cln1<<(unsigned char)buffer2[i];
729     }
730     if (end!=1) for(i=1020;i<1023;i++) {fo_cln1<<(unsigned char)buffer2[i];}
731     }
732     else {for(i=8;i<1023;i++) fo_cln1<<(unsigned char)buffer2[i];}
733     for (i=0;i<1024;i++) {fokadr_cln1<<(unsigned char)buffer2[i];}
734     //Write in file mmm_counter_nnnnn_cln1_bin.log
735     tmp=numP[1];
736     for (k=0;k<4;k++) numPack[k]=0;
737     for (k=0;k<4;k++)
738     {if (tmp/(long int)(pow(256.,3-k))>=1)
739     {numPack[3-k]=(int)(tmp/(long int)(pow(256.,3-k)));
740     tmp=tmp-(long int)pow(256.,3-k)*(int)(tmp/(long int)(pow(256.,3-k)));}}
741     for (i=0;i<4;i++) fputc((int)(unsigned char)(numPack[i]),fo_log_kadr);
742     adr1=icount-1024*2;
743     for (k=0;k<4;k++) adress[k]=0;
744     for (k=0;k<4;k++)
745     {if (adr1/(long int)(pow(256.,3-k))>=1)
746     {adress[3-k]=(int)(adr1/(long int)(pow(256.,3-k)));
747     adr1=adr1-(long int)pow(256.,3-k)*
748     (int)(adr1/(long int)(pow(256.,3-k)));}}
749     for (i=0;i<4;i++) fputc((int)(unsigned char)(adress[i]),fo_log_kadr);
750     adr2=icount-1024;
751     for (k=0;k<4;k++) adress[k]=0;
752     for (k=0;k<4;k++)
753     {if (adr2/(long int)(pow(256.,3-k))>=1)
754     {adress[3-k]=(int)(adr2/(long int)(pow(256.,3-k)));
755     adr2=adr2-(long int)pow(256.,3-k)*
756     (int)(adr2/(long int)(pow(256.,3-k)));}}
757     for (i=0;i<4;i++) fputc((int)(unsigned char)(adress[i]),fo_log_kadr);
758     fputc(flags,fo_log_kadr);
759     }
760     }
761     /***************************************************************/
762     /***************************************************************/
763     if (flag_CRC[2]==0||(flag_rout[2]==0&&flag_pack[2]==0)||
764     (flag_CRC[2]!=0&&flag_CRC_cor[2]==1))
765     {end=0;
766     for (i=0;i<1024;i++) fokadr_cln1<<(unsigned char)buffer3[i];
767     //Write in file mmm_counter_nnnnn_cln1_bin.log
768     tmp=numP[2];
769     for (k=0;k<4;k++) numPack[k]=0;
770     for (k=0;k<4;k++)
771     {if (tmp/(long int)(pow(256.,3-k))>=1)
772     {numPack[3-k]=(int)(tmp/(long int)(pow(256.,3-k)));
773     tmp=tmp-(long int)pow(256.,3-k)*
774     (int)(tmp/(long int)(pow(256.,3-k)));}}
775     for (i=0;i<4;i++) fputc((int)(unsigned char)(numPack[i]),fo_log_kadr);
776     adr1=icount-1024;
777     for (k=0;k<4;k++) adress[k]=0;
778     for (k=0;k<4;k++)
779     {if (adr1/(long int)(pow(256.,3-k))>=1)
780     {adress[3-k]=(int)(adr1/(long int)(pow(256.,3-k)));
781     adr1=adr1-(long int)pow(256.,3-k)*
782     (int)(adr1/(long int)(pow(256.,3-k)));}}
783     for (i=0;i<4;i++) fputc((int)(unsigned char)(adress[i]),fo_log_kadr);
784     adr2=icount;
785     for (k=0;k<4;k++) adress[k]=0;
786     for (k=0;k<4;k++)
787     {if (adr2/(long int)(pow(256.,3-k))>=1)
788     {adress[3-k]=(int)(adr2/(long int)(pow(256.,3-k)));
789     adr2=adr2-(long int)pow(256.,3-k)*
790     (int)(adr2/(long int)(pow(256.,3-k)));}}
791     for (i=0;i<4;i++) fputc((int)(unsigned char)(adress[i]),fo_log_kadr);
792     fputc(flags,fo_log_kadr);
793    
794     for (i=8;i<1019;i++)
795     {
796     // if (fmodf(float((Num_kadrs[Rcount-1]-1)*1015+i-8),
797     // float(64))==0.&&buffer3[i]==0&&buffer3[i+1]==0&&
798     // buffer3[i+2]==0&&buffer3[i+3]==0&&buffer3[i+4]==0) end=1;
799     if (end!=1) fo_cln1<<(unsigned char)buffer3[i];
800     }
801     if (end!=1) {for(i=1019;i<1023;i++) {fo_cln1<<(unsigned char)buffer3[i];}}
802     }
803    
804     icount_int = (int)(icount/1024);
805     icount_frac= icount%1024;
806     // cout<<"\nfile size="<<icount_total<<" Byte "<<N1
807     // <<" identified cadrs Number of routs="<<Rcount<<"\n";
808     // cout<<" size of identified cadrs="<<icount<<" bytes "<<count_ident[0]<<"\n";
809    
810     //***protocol file***********************************************
811     strcpy(file_name_prot, path);
812     strcat(file_name_prot, name);
813     file_length=(int)(strlen(name));
814     fprintf(fo,"file name=%s\n",file_name_prot);
815     fprintf(fo,"file size= %i,%i kByte \n", icount_int,
816     icount_frac);
817     for (i=0;i<Rcount;i++)
818     {fprintf(fo,"route=%i;",NumRout[i]);
819     fprintf(fo," size of identified cadrs =%lli bytes;",count_ident[i]);
820     fprintf(fo," total size of route=%lli bytes;\n",count_tot[i]);
821     fprintf(fo,"number of errors=%i;\n",Num_bad_kadrs[i]);
822     }
823    
824     //***route's number log file**************************************
825     for (i=0;i<Rcount;i++) {fprintf(fo_route,"%1c",(char)(NumRout[i]));}
826    
827     //***cln1.inf file*************************************************
828     fprintf(fo1,"file name=");
829     fprintf(fo1,"%s%s",path,name);
830     fprintf(fo1,"\nfile size= %i,%i kByte \n", icount_int,
831     icount_frac);
832     fprintf(fo1,"number identified kadrs= %i\n", N1);
833     fprintf(fo1,"number of routes= %i\n", Rcount);
834    
835     for (i=0;i<Rcount;i++)
836     {
837     Num_good_kadrs[i]=Num_kadrs[i]-Num_bad_kadrs[i];
838     quality[i]=(float)(1.)-(float)(Num_bad_kadrs[i])/(float)(Num_kadrs[i]);
839     fprintf(fo1,"\nRoute number=%i: number of normal kadrs= %i:\n",
840     NumRout[i],Num_good_kadrs[i]);
841     fprintf(fo1,"first kadre number= %lli:", packet_first[i]);
842     fprintf(fo1," last kadre number= %lli:", packet_last[i]);
843     fprintf(fo1," Number of missed kadrs= %i:\n", count_missed[i]);
844     // fprintf(fo1,"Number of double transmitted kadrs= %i:\n", count_sec_missed[i]);
845     fprintf(fo1,"number of identified kadres=%lli: quality index=%f\n", Num_kadrs[i], quality[i]);
846     }
847     //***************************************************************
848     fin.close();
849     fclose(fout);
850     fclose(fo);
851     fclose(fo1);
852     fclose(foRout);
853     fclose(foMiss);
854     fo_cln1.close();
855     fclose(fo_log_kadr);
856     fokadr_cln1.close();
857     fclose(fo_route);
858     }
859    

  ViewVC Help
Powered by ViewVC 1.1.23