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

Diff of /rawreader/src/Read.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by cafagna, Fri Sep 1 10:56:22 2006 UTC revision 1.2 by cafagna, Sun Dec 10 12:21:23 2006 UTC
# Line 1  Line 1 
1  #include "descript.h"  #include "descript.h"
2    #include "flag.h"
3    
4  void filename(char [], char [], char [], char[], int, char[]);  void filename(char [], char [], char [], char[], int, char[]);
5  void FindRoute(int[], int*);  void FindRoute(int[], int*);
# Line 8  int restrict(int [], long long int[], in Line 9  int restrict(int [], long long int[], in
9  void read(char fni[], char fno[], char INF[],  void read(char fni[], char fno[], char INF[],
10                    char protocol[], char path[], char name[], char nnnnn_TMP[], float quality[], int real_route[], int &Rcount)                    char protocol[], char path[], char name[], char nnnnn_TMP[], float quality[], int real_route[], int &Rcount)
11  {  {
12   FILE *fo, *fo1, *fout, *foRout, *foMiss, *fo_log_kadr, *fo_route;   FILE *fo, *fout, *foRout, *foMiss, *fo_log_kadr, *fo_route;
13   ifstream fin;   ifstream fin;
14   ofstream fo_cln1, fokadr_cln1;   ofstream fo_cln1, fokadr_cln1;
15    
16   char buf[1024];   char buf[1024];
17   //  char stop1;   //  char stop1;
18   char ch1,ch2,ch3, ch, file_name_prot[80];   char ch1,ch2,ch3, ch;
19   char file_route[80];  /*protocol binary filesm mmm_counter_nnnnn_cln1Er.log*/   char file_route[80];  /*protocol binary filesm mmm_counter_nnnnn_cln1Er.log*/
20   char miss_file[80];   /*protocol files mmm_counter_nnnnn_mis_cln1.dat*/   char miss_file[80];   /*protocol files mmm_counter_nnnnn_mis_cln1.dat*/
21   char cln1_file[80];   /*route binary data files mmm_counter_nnnnn_cln1.pam*/   char cln1_file[80];   /*route binary data files mmm_counter_nnnnn_cln1.pam*/
# Line 57  void read(char fni[], char fno[], char I Line 58  void read(char fni[], char fno[], char I
58   int adr2=0;                     /* Last byte of kadr in cln2.bin*/   int adr2=0;                     /* Last byte of kadr in cln2.bin*/
59   int tmp=0;   int tmp=0;
60   int numPack[4];                 /* Number of kadr in given route*/   int numPack[4];                 /* Number of kadr in given route*/
61     int good_pack=0;
62     int good_number=0;
63     int good_route=0;
64   int adress[4];   int adress[4];
65   int R_er[100];           /* Rout errors number in given rout*/   int R_er[100];           /* Rout errors number in given rout*/
66   int R_er_interf1[100];   /* Interface Rout error at begin of rout*/   int R_er_interf1[100];   /* Interface Rout error at begin of rout*/
67   int R_er_interf2[100];   /* Interface Rout error at end of rout*/   int R_er_interf2[100];   /* Interface Rout error at end of rout*/
68   int Mis_group[1000];     /* Number of missed kadrs group   int Mis_group[1000];     /* Number of missed kadrs group
69                               for each rout*/                               for each route*/
70   int Pack_Er[1000];       /* Number of packets with packet number   int Pack_Er[1000];       /* Number of packets with packet number
71                               error for each rout*/                               error for each route*/
72   int CRC_bad_kadr[3];     /* Current CRC bad kadr number*/   int CRC_bad_kadr[3];     /* Current CRC bad kadr number*/
73   int flag_pack[3];        /* Flag for error in packet number*/   int flag_pack[3];        /* Flag for error in packet number*/
74   int flag_rout[3];        /* Flag for error in rout number*/   int flag_rout[3];        /* Flag for error in rout number*/
# Line 107  void read(char fni[], char fno[], char I Line 111  void read(char fni[], char fno[], char I
111   //open output file "nnnnnmmm_protocol.txt"   //open output file "nnnnnmmm_protocol.txt"
112   fo=fopen(protocol, "wb");   fo=fopen(protocol, "wb");
113   if(fo==0) {cerr<<"can not open protocol file"; exit(0);}   if(fo==0) {cerr<<"can not open protocol file"; exit(0);}
  //open output file "nnnnnmmm_cln1.inf"  
  fo1=fopen(INF, "wb");  
  if(fo1==0) {cerr<<"can not open inf file"; exit(0);}  
114   //open output file "nnnnnmmm_route.log"   //open output file "nnnnnmmm_route.log"
115   strncpy(log_route,INF,strlen(INF)-9);   strncpy(log_route,INF,strlen(INF)-9);
116   log_route[strlen(INF)-9]='\0';   log_route[strlen(INF)-9]='\0';
# Line 159  void read(char fni[], char fno[], char I Line 160  void read(char fni[], char fno[], char I
160               ||               ||
161    (ch1!=(char)(CODE1)&&ch2!=(char)(CODE2)&&ch3!=(char)(CODE3)))    (ch1!=(char)(CODE1)&&ch2!=(char)(CODE2)&&ch3!=(char)(CODE3)))
162    {fin.get(ch);    {fin.get(ch);
163     if (fin.eof()) {/*cerr<<"\n"<<"gopa";*/ break;}     if (fin.eof()) {break;}
164     ch1=ch2; ch2=ch3; ch3=Short_Buf[0];     ch1=ch2; ch2=ch3; ch3=Short_Buf[0];
165     for (i=0;i<4;i++) Short_Buf[i]=Short_Buf[i+1]; Short_Buf[4]=ch;     for (i=0;i<4;i++) Short_Buf[i]=Short_Buf[i+1]; Short_Buf[4]=ch;
166     icount_total+=1; count_tot[Rcount-1]+=1;     icount_total+=1; count_tot[Rcount-1]+=1;
# Line 173  void read(char fni[], char fno[], char I Line 174  void read(char fni[], char fno[], char I
174     remove(fno);     remove(fno);
175     fclose(fo);     fclose(fo);
176     remove(protocol);     remove(protocol);
    fclose(fo1);  
177     remove(INF);     remove(INF);
178     exit(0);     exit(0);
179    }    }
 //      cout<<"icount_total="<<icount_total<<" "<<N1<<"\n";  
 //      printf("%x %x %x \n",(int)(unsigned char)(ch1),(int)(unsigned char)(ch2),(int)(unsigned char)(ch3));  
 //      printf("%x %x %x %x %x\n",(int)(unsigned char)(Short_Buf[0]),(int)(unsigned char)(Short_Buf[1]),  
 //                                    (int)(unsigned char)(Short_Buf[2]),(int)(unsigned char)(Short_Buf[3]),  
 //                                                        (int)(unsigned char)(Short_Buf[4]));  
 //      printf("buffer3[3]= %x\n",(int)(unsigned char)buffer3[3]);  
 //      printf("numP[2]+1= %x tmpP= %x\n",numP[2]+1, tmpP);  
 //      printf("buffer3[1023]= %x\n",(int)(unsigned char)buffer3[1023], tmpP);  
180    
181    /*****************************************************************/    /*****************************************************************/
182    /*********************data reading********************************/    /*********************data reading********************************/
# Line 283  void read(char fni[], char fno[], char I Line 275  void read(char fni[], char fno[], char I
275              CRC_1[2]=(int)(unsigned char)(ch);                  CRC_1[2]=(int)(unsigned char)(ch);    
276             }             }
277    }      }  
278    //  if (fmod(N1,10000)==0.) cout<<N1<<"\n";      //  if (fmod(N1,10000)==0.) cout<<N1<<"\n";      
 // Caf mod on 31 Aug 2006  
   if ((N1%10000)==0 && N1>0) cout<<N1<<"\n";        
   // end mod  
279    
280  /******************CRC ERROR ANALYSIS***************************/  /******************CRC ERROR ANALYSIS***************************/
281    CalcCheckSum=CRC(buffer3);    CalcCheckSum=CRC(buffer3);
# Line 299  void read(char fni[], char fno[], char I Line 288  void read(char fni[], char fno[], char I
288          printf("%x %x %x %x",buffer3[1020],buffer3[1021],buffer3[1022],buffer3[1023]);          printf("%x %x %x %x",buffer3[1020],buffer3[1021],buffer3[1022],buffer3[1023]);
289      cin>>i;}*/      cin>>i;}*/
290     fprintf(fout,"CRC = %x (%x) error in kadr %i\n", buffer3[1023],CalcCheckSum,numP[2]);     //write in file nnnnn_work.dat     fprintf(fout,"CRC = %x (%x) error in kadr %i\n", buffer3[1023],CalcCheckSum,numP[2]);     //write in file nnnnn_work.dat
291  //      cerr<<"checksum error "<<Rcount<<" Cadre="<<numP[2]<<  
 //                " "<<buffer3[3]<<"\n";  
292     flag_CRC[2]=1;     flag_CRC[2]=1;
293     Num_bad_kadrs[Rcount-1]+=1;     Num_bad_kadrs[Rcount-1]+=1;
294     CRC_bad_kadr[2]=numP[2];     CRC_bad_kadr[2]=numP[2];
295     counter=restrict(buffer3,numP,buffer2[3]);     counter=restrict(buffer3,numP,buffer2[3]);
296     if (counter!=0)     if (counter!=0)
297     {fprintf(fout," truncate byte=%i",counter);     {fprintf(fout," truncate byte=%i",counter);
298      cout<<" truncate counter="<<counter<<" route="<<buffer2[3]<<" "<<buffer3[3]<<" kadr="<<numP[2]<<" "<<numP[1]<<" "<<numP[0]<<"\n";  //    cout<<" truncate counter="<<counter<<" route="<<buffer2[3]<<" "<<buffer3[3]<<" kadr="<<numP[2]<<" "<<numP[1]<<" "<<numP[0]<<"\n";
299      fin.seekg(-(1024-counter),ios::cur);      fin.seekg(-(1024-counter),ios::cur);
300      icount-=1024;      icount-=1024;
301      count_ident[Rcount-1]-=1024;      count_ident[Rcount-1]-=1024;
# Line 391  void read(char fni[], char fno[], char I Line 379  void read(char fni[], char fno[], char I
379    {Mis_group[Rcount-1]+=1;    {Mis_group[Rcount-1]+=1;
380     fprintf(foMiss,"%9i%9i -1\n",numP[0]+1,numP[2]-1);     fprintf(foMiss,"%9i%9i -1\n",numP[0]+1,numP[2]-1);
381     count_missed[Rcount-1]+=numP[2]-numP[0]-1-1;}     count_missed[Rcount-1]+=numP[2]-numP[0]-1-1;}
382      /**route number:10 (10 10 10) 10 10 ******************************/
383      /**kadr number:  1 (11 12 13) 14 15 ******************************/
384      /**number of missed kadrs: 10       ******************************/  
385      else if ((N1>1)&&(abs(numP[2]-good_pack-2)>abs(Num_kadrs[Rcount-1]-good_number))&&
386               (buffer2[3]==good_route)&&(flag_tr[2]==0)&&(flag_pack[2]==0))
387      {Mis_group[Rcount-1]+=1;
388       fprintf(foMiss,"%9i%9i \n",good_pack+1,numP[2]-1);
389       count_missed[Rcount-1]+=numP[2]-good_pack-1;
390      }
391    //truncate kadr    //truncate kadr
392    /**route number: 10 (10 10 10) 10 ******************************/    /**route number: 10 (10 10 10) 10 ******************************/
393    /**kadr number:  11 (12 13 14) 15 ******************************/    /**kadr number:  11 (12 13 14) 15 ******************************/
# Line 403  void read(char fni[], char fno[], char I Line 400  void read(char fni[], char fno[], char I
400     count_missed[Rcount-1]+=numP[2]-numP[0]-1;}     count_missed[Rcount-1]+=numP[2]-numP[0]-1;}
401    /***************************************************************/    /***************************************************************/
402    
403      if (flag_CRC[2]!=1) {good_pack=numP[2]; good_route=buffer3[3]; good_number=Num_kadrs[Rcount-1];}
404    
405    /******************ROUTE NUMBER ANALYSIS**************************/    /******************ROUTE NUMBER ANALYSIS**************************/
406    if ((buffer2[3]!=buffer1[3])&&(buffer2[3]!=buffer3[3])&&(buffer1[3]!=buffer3[3])&&    if ((buffer2[3]!=buffer1[3])&&(buffer2[3]!=buffer3[3])&&(buffer1[3]!=buffer3[3])&&
407        (flag_pack[2]==0)&&(flag_pack[1]==0)&&(flag_pack[0]==0))        (flag_pack[2]==0)&&(flag_pack[1]==0)&&(flag_pack[0]==0))
408    {    {
409     /******************Interface route error 1***********************/  
    /**route number:7   7  ( 7   4  8) 8 8 **************************/  
    /**kadr number:197 198 (199 200 1) 2 3 **************************/  
    /*if ((numP[1]==numP[0]+1)&&(numP[2]<numP[0]))        
    {Rcount+=1; flag_rout[1]=1;  
     packet_last[Rcount-2]=numP[1];  
     packet_first[Rcount-1]=numP[2];  
     Num_kadrs[Rcount-1]+=1;  
     Num_kadrs[Rcount-2]-=1;                        
     R_er[Rcount-2]+=1;  
     R_er_interf2[Rcount-2]+=1;  
     M_er=N1-1;  
     count_ident[Rcount-1]+=1024; count_ident[Rcount-2]-=1024;  
     count_tot[Rcount-1]+=1024; count_tot[Rcount-2]-=1024;  
     NumRout[Rcount-1]=Rcount;  
     cout<<"\n interface1 "<<NumRout[Rcount-1]<<" "<<Rcount;  
     //    cin>>stop1;  
     if ((CRC_bad_kadr[1]==numP[1])&&(numP[1]!=0))  
     {  
     //Correct error route number//////////////////////////////////////////  
          buffer2[3]=buffer1[3];  
          if (buffer2[1023]==(int)(CRC(buffer2))) flag_CRC_cor[1]=1;  
      ////////////////////////////////////////////////////////////////////  
          flags=(short int)(pow((float)(2*flag_name[1]),4)+  
                pow((float)(2*flag_rout[1]),1)+  
                pow((float)(2*flag_pack[1]),2)+  
                pow((float)(2*flag_CRC0[1]),3)+  
                    pow((float)(2*flag_CRC[1]),5)+  
                    pow((float)(2*flag_CRC_cor[1]),6));  
      fprintf(foRout,"%1c%1c%1c%1c",(char)(buffer2[4]),  
                  (char)(buffer2[5]),(char)(buffer2[6]),(char)(flags));  
      fprintf(fout,"%i Interface route error 1 %i\n",CRC_bad_kadr[1],flags);  
      CRC_bad_kadr[1]=0;  
     }  
     // CREATE FILE NAMES            
         filename(file_route, miss_file, cln1_file, path,  
                  NumRout[Rcount-1], name);                        
         strncpy(cln1_kadr,cln1_file,strlen(cln1_file)-3);  
         cln1_kadr[strlen(cln1_file)-3]='\0';  
         strcat(cln1_kadr,"bin");  
         strncpy(log_kadr,file_route,strlen(file_route)-6);  
         log_kadr[strlen(file_route)-6]='\0';  
         strcat(log_kadr,"_bin.log");  
         fclose(foRout);                    //Close files  
         fo_cln1.close();                   //for old  
         fclose(foMiss);                    //route  
         fokadr_cln1.close();  
         fclose(fo_log_kadr);  
     //Open files for new route  
         foRout=fopen(file_route, "wb");          //mmm_nnnnn_cln1Er.log  
         foMiss=fopen(miss_file, "wb");           //mmm_nnnnn_mis_cln1.dat  
         fo_cln1.open(cln1_file, ios::binary);    //mmm_nnnnn_cln1.pam    
         fokadr_cln1.open(cln1_kadr,ios::binary); //mmm_nnnnn_cln1.bin  
         fo_log_kadr=fopen(log_kadr,"wb");        //mmm_nnnnn_cln1_bin.log  
    }*/  
    /******************Interface route error 2***********************/  
    /**route number:7   7  ( 7  4 8) 8 ******************************/  
    /**kadr number:198 199 (200 1 2) 3 ******************************/  
    /*if ((numP[1]==numP[2]-1)&&(numP[1]<numP[0])&&(buffer2[3]!=0))  
    {Rcount+=1; flag_rout[1]=1;  
     packet_last[Rcount-2]=numP[0];  
     packet_first[Rcount-1]=numP[1];  
     Num_kadrs[Rcount-1]+=2;  
     Num_kadrs[Rcount-2]-=2;  
     R_er[Rcount-1]+=1;  
     R_er_interf1[Rcount-1]+=1;  
     M_er=N1-1;  
     count_ident[Rcount-1]+=2048; count_ident[Rcount-2]-=2048;  
     count_tot[Rcount-1]+=2048; count_tot[Rcount-2]-=2048;  
     NumRout[Rcount-1]=Rcount;  
     cout<<"\n interface2 "<<NumRout[Rcount-1]<<" "<<Rcount;  
 //        cin>>stop1;  
     // CREATE FILE NAMES  
         filename(file_route, miss_file, cln1_file, path,  
                  NumRout[Rcount-1], name);        
         strncpy(cln1_kadr,cln1_file,strlen(cln1_file)-3);  
         cln1_kadr[strlen(cln1_file)-3]='\0';  
         strcat(cln1_kadr,"bin");  
         strncpy(log_kadr,file_route,strlen(file_route)-6);  
         log_kadr[strlen(file_route)-6]='\0';  
         strcat(log_kadr,"_bin.log");  
         fclose(foRout);                    //Close files  
         fo_cln1.close();                   //for old  
         fclose(foMiss);                    //route  
         fokadr_cln1.close();  
         fclose(fo_log_kadr);  
     //Open files for new route  
         foRout=fopen(file_route, "wb");          //mmm_nnnnn_cln1Er.log  
         foMiss=fopen(miss_file, "wb");           //mmm_nnnnn_mis_cln1.dat  
         fo_cln1.open(cln1_file, ios::binary);    //mmm_nnnnn_cln1.pam  
         fokadr_cln1.open(cln1_kadr,ios::binary); //mmm_nnnnn_cln1.bin  
         fo_log_kadr=fopen(log_kadr,"wb");        //mmm_nnnnn_cln1_bin.log  
         if ((CRC_bad_kadr[1]==numP[1])&&(numP[1]!=0))  
         {Num_bad_kadrs[Rcount-1]+=1; Num_bad_kadrs[Rcount-2]-=1;  
      //Correct error rout number//////////////////////////////////////////  
          buffer2[3]=buffer3[3];  
          if (buffer2[1023]==(int)(CRC(buffer2))) flag_CRC_cor[1]=1;  
      ////////////////////////////////////////////////////////////////////  
          flags=(short int)(pow((float)(2*flag_name[1]),4)+  
                 pow((float)(2*flag_rout[1]),1)+  
                 pow((float)(2*flag_pack[1]),2)+  
                 pow((float)(2*flag_CRC0[1]),3)+  
                 pow((float)(2*flag_CRC[1]),5)+  
                 pow((float)(2*flag_CRC_cor[1]),6));  
          fprintf(foRout,"%1c%1c%1c%1c",(char)(buffer2[4]),(char)(buffer2[5]),(char)(buffer2[6]),(char)(flags));  
          fprintf(fout,"%i Interface route error 2 %i\n",CRC_bad_kadr[1],flags);  
          CRC_bad_kadr[1]=0;}  
    }*/  
    /******************Interface route error 3************************/  
    /**route number:7   7  ( 7  8 4) 8 8******************************/  
    /**kadr number:198 199 (200 1 2) 3 4******************************/  
 /*   if ((numP[1]==numP[2]-1)&&(flag_CRC[1]==0)&&(flag_CRC[2]==1))  
    {Rcount+=1;  
     packet_last[Rcount-2]=numP[0];  
     packet_first[Rcount-1]=numP[1];  
     NumRout[Rcount-1]=Rcount;  
     Num_kadrs[Rcount-2]-=2;  
     Num_kadrs[Rcount-1]+=2;  
     count_ident[Rcount-1]+=2048; count_ident[Rcount-2]-=2048;  
     count_tot[Rcount-1]+=2048; count_tot[Rcount-2]-=2048;  
     Num_bad_kadrs[Rcount-1]+=1; Num_bad_kadrs[Rcount-2]-=1;  
     cout<<"\n interface3 "<<NumRout[Rcount-1]<<" "<<Rcount;  
 //        cin>>stop1;  
     // CREATE FILE NAMES  
         filename(file_route, miss_file, cln1_file, path,  
                  NumRout[Rcount-1], name);                        
         strncpy(cln1_kadr,cln1_file,strlen(cln1_file)-3);  
         cln1_kadr[strlen(cln1_file)-3]='\0';  
         strcat(cln1_kadr,"bin");  
         strncpy(log_kadr,file_route,strlen(file_route)-6);  
         log_kadr[strlen(file_route)-6]='\0';  
         strcat(log_kadr,"_bin.log");  
         fclose(foRout);                    //Close files  
         fo_cln1.close();                   //for old  
         fclose(foMiss);                    //route  
         fokadr_cln1.close();  
         fclose(fo_log_kadr);  
     //Open files for new route  
         foRout=fopen(file_route, "wb");          //mmm_nnnnn_cln1Er.log  
         foMiss=fopen(miss_file, "wb");           //mmm_nnnnn_mis_cln1.dat    
         fo_cln1.open(cln1_file, ios::binary);    //mmm_nnnnn_cln1.pam  
         fokadr_cln1.open(cln1_kadr,ios::binary); //mmm_nnnnn_cln1.bin  
         fo_log_kadr=fopen(log_kadr,"wb");        //mmm_nnnnn_cln1_bin.log    
         flags=(short int)(pow((float)(2*flag_name[1]),4)+  
                pow((float)(2*flag_rout[1]),1)+  
                pow((float)(2*flag_pack[1]),2)+  
                pow((float)(2*flag_CRC0[1]),3)+  
                pow((float)(2*flag_CRC[1]),5)+  
                pow((float)(2*flag_CRC_cor[1]),6));  
         fprintf(foRout,"%1c%1c%1c%1c",(char)(buffer2[4]),(char)(buffer2[5]),(char)(buffer2[6]),(char)(flags));  
         fprintf(fout,"%i Interface route error 3 %i\n",CRC_bad_kadr[1],flags);  
         CRC_bad_kadr[1]=0;  
    }*/  
410    }    }
   /**************Return to old route*******************************/  
   /**route number: 7 (8 4 8) 8*************************************/  
   /*if ((buffer2[3]!=buffer1[3])&&(buffer2[3]!=buffer3[3])&&  
       (buffer1[3]==buffer3[3])&&(buffer2[3]!=0)&&(N1>2))  
   {                
    R_er[Rcount-1]+=1; flag_rout[1]=1;  
    M_er=N1-1;  
    if ((CRC_bad_kadr[1]==numP[1])&&(numP[1]!=0))  
    {  
     //Correct error route number//////////////////////////////////////////  
     buffer2[3]=buffer1[3];  
     if (buffer2[1023]==(int)(CRC(buffer2))) flag_CRC_cor[1]=1;  
     ////////////////////////////////////////////////////////////////////  
     flags=(short int)(pow((float)(2*flag_name[1]),4)+  
                pow((float)(2*flag_rout[1]),1)+  
                pow((float)(2*flag_pack[1]),2)+  
                pow((float)(2*flag_CRC0[1]),3)+  
                pow((float)(2*flag_CRC[1]),5)+  
                pow((float)(2*flag_CRC_cor[1]),6));  
     fprintf(foRout,"%1c%1c%1c%1c",(char)(buffer2[4]),(char)(buffer2[5]),(char)(buffer2[6]),(char)(flags));  
     fprintf(fout,"%i Old route error %i\n",CRC_bad_kadr[1],flags);  
     CRC_bad_kadr[1]=0;}  
    cout<<"\n"<<Rcount<<" old "<<NumRout[Rcount-1]<<" "<<buffer1[3]<<" "<<buffer2[3]<<" "<<buffer3[3]<<" N1="<<N1-1<<"\n";  
   }*/  
411    /**************First route***************************************/    /**************First route***************************************/
412    /**route number: (0 4) 4*****************************************/    /**route number: (0 4) 4*****************************************/
413    /**kadr number:  (0 1) 2*****************************************/    /**kadr number:  (0 1) 2*****************************************/
# Line 602  void read(char fni[], char fno[], char I Line 425  void read(char fni[], char fno[], char I
425     log_kadr[strlen(file_route)-6]='\0';     log_kadr[strlen(file_route)-6]='\0';
426     strcat(log_kadr,"_bin.log");     strcat(log_kadr,"_bin.log");
427     //Open files for new route     //Open files for new route
428     foRout=fopen(file_route, "wb");          //mmm_nnnnn_cln1Er.log     foRout=fopen(file_route, "wb");          //xxx_mmm_nnnnn_cln1Er.log
429     foMiss=fopen(miss_file, "wb");           //mmm_nnnnn_mis_cln1.dat     foMiss=fopen(miss_file, "wb");           //xxx_mmm_nnnnn_mis_cln1.dat
430     fo_cln1.open(cln1_file, ios::binary);    //mmm_nnnnn_cln1.pam     fo_cln1.open(cln1_file, ios::binary);    //xxx_mmm_nnnnn_cln1.pam
431     if (!fo_cln1) cout<<"can not open "<<cln1_file<<"\n";     if (!fo_cln1) cout<<"can not open "<<cln1_file<<"\n";
432     fokadr_cln1.open(cln1_kadr,ios::binary); //mmm_nnnnn_cln1.bin     fokadr_cln1.open(cln1_kadr,ios::binary); //xxx_mmm_nnnnn_cln1.bin
433     if (!fokadr_cln1) cout<<"can not open "<<cln1_kadr<<"\n";     if (!fokadr_cln1) cout<<"can not open "<<cln1_kadr<<"\n";
434     fo_log_kadr=fopen(log_kadr,"wb");        //mmm_nnnnn_cln1_bin.log     fo_log_kadr=fopen(log_kadr,"wb");        //xxx_mmm_nnnnn_cln1_bin.log
    //  cout<<"\n"<<Rcount<<" old "<<NumRout[Rcount-1]<<" "<<numP[1]<<" N1="<<N1-1;  
435    }    }
436    /***************New route***************************************/    /***************New route***************************************/
437    /**route number: 7  ( 7  0 8) 8*********************************/    /**route number: 7  ( 7  0 8) 8*********************************/
# Line 624  void read(char fni[], char fno[], char I Line 446  void read(char fni[], char fno[], char I
446     packet_first[Rcount-1]=numP[1];     packet_first[Rcount-1]=numP[1];
447     NumRout[Rcount-1]=Rcount;     NumRout[Rcount-1]=Rcount;
448     cout<<"New route="<<Rcount<<" "<<buffer1[3]<<" "<<buffer2[3]<<" "<<buffer3[3]<<"\n";     cout<<"New route="<<Rcount<<" "<<buffer1[3]<<" "<<buffer2[3]<<" "<<buffer3[3]<<"\n";
449     cout<<numP[0]<<" "<<numP[1]<<" "<<numP[2]<<"\n";cin>>i;     cout<<numP[0]<<" "<<numP[1]<<" "<<numP[2]<<"\n";
450     if (flag_tr[1]==0)     if (flag_tr[1]==0)
451     {Num_kadrs[Rcount-2]-=2;     {Num_kadrs[Rcount-2]-=2;
452      Num_kadrs[Rcount-1]+=2;      Num_kadrs[Rcount-1]+=2;
# Line 650  void read(char fni[], char fno[], char I Line 472  void read(char fni[], char fno[], char I
472     fokadr_cln1.close();     fokadr_cln1.close();
473     fclose(fo_log_kadr);     fclose(fo_log_kadr);
474     //Open files for new route     //Open files for new route
475     foRout=fopen(file_route, "wb");          //mmm_nnnnn_cln1Er.log     foRout=fopen(file_route, "wb");          //xxx_mmm_nnnnn_cln1Er.log
476     foMiss=fopen(miss_file, "wb");           //mmm_nnnnn_mis_cln1.dat         foMiss=fopen(miss_file, "wb");           //xxx_mmm_nnnnn_mis_cln1.dat    
477     fo_cln1.open(cln1_file, ios::binary);    //mmm_nnnnn_cln1.pam     fo_cln1.open(cln1_file, ios::binary);    //xxx_mmm_nnnnn_cln1.pam
478     fokadr_cln1.open(cln1_kadr,ios::binary); //mmm_nnnnn_cln1.bin     fokadr_cln1.open(cln1_kadr,ios::binary); //xxx_mmm_nnnnn_cln1.bin
479     fo_log_kadr=fopen(log_kadr,"wb");        //mmm_nnnnn_cln1_bin.log     fo_log_kadr=fopen(log_kadr,"wb");        //xxx_mmm_nnnnn_cln1_bin.log
480     if ((CRC_bad_kadr[2]==numP[2])&&(numP[2]!=0)) {Num_bad_kadrs[Rcount-1]+=1; Num_bad_kadrs[Rcount-2]-=1;}     if ((CRC_bad_kadr[2]==numP[2])&&(numP[2]!=0)) {Num_bad_kadrs[Rcount-1]+=1; Num_bad_kadrs[Rcount-2]-=1;}
481     if ((CRC_bad_kadr[1]==numP[1])&&(numP[1]!=0))     if ((CRC_bad_kadr[1]==numP[1])&&(numP[1]!=0))
482     {Num_bad_kadrs[Rcount-1]+=1; Num_bad_kadrs[Rcount-2]-=1;     {Num_bad_kadrs[Rcount-1]+=1; Num_bad_kadrs[Rcount-2]-=1;
# Line 666  void read(char fni[], char fno[], char I Line 488  void read(char fni[], char fno[], char I
488                 pow((float)(2*flag_CRC_cor[1]),6));                 pow((float)(2*flag_CRC_cor[1]),6));
489      fprintf(foRout,"%1c%1c%1c%1c",(char)(buffer2[4]),(char)(buffer2[5]),(char)(buffer2[6]),(char)(flags));      fprintf(foRout,"%1c%1c%1c%1c",(char)(buffer2[4]),(char)(buffer2[5]),(char)(buffer2[6]),(char)(flags));
490      fprintf(fout,"%i New route %i\n",CRC_bad_kadr[1],flags);      fprintf(fout,"%i New route %i\n",CRC_bad_kadr[1],flags);
491      CRC_bad_kadr[1]=-1;}      CRC_bad_kadr[1]=-1;}
   // cout<<Rcount<<" New "<<NumRout[Rcount-1]<<" "<<numP[1]<<"\n";  
492    }    }
493        
494    if ((numP[1]==0)&&(N1>1))    if (((numP[1]==0)&&(N1>1))||(N1==2))
495    {rr=0;    {rr=0;
496     FindRoute(buffer2, &rr);     FindRoute(buffer2, &rr);
497     if (rr>0)     if (rr>0)
# Line 709  void read(char fni[], char fno[], char I Line 530  void read(char fni[], char fno[], char I
530     fprintf(fout,"%i flags=%i\n",CRC_bad_kadr[1],flags);}     fprintf(fout,"%i flags=%i\n",CRC_bad_kadr[1],flags);}
531        
532    /***************************************************************/    /***************************************************************/
 //   cout <<"\nCalcChekSum="<<dec <<right<<CalcCheckSum  
 //   <<"\npacket.CheckSum1="<<right<<packet.CheckSum1;  
 //   cout <<"\nPacket number="<<packet.Pckt_Num<<" "<<endl;  
533    //*Packet analysis**********************************************    //*Packet analysis**********************************************
534    if (N_er!=0) fprintf(fout,"Name error %i in kadr %i\n",numP[2],N_er);    if (N_er!=0) fprintf(fout,"Name error %i in kadr %i\n",numP[2],N_er);
535    if (M_er!=0) fprintf(fout,"Root number error %i in kadr %i\n",numP[1],M_er);    if (M_er!=0) fprintf(fout,"Root number error %i in kadr %i\n",numP[1],M_er);
# Line 721  void read(char fni[], char fno[], char I Line 539  void read(char fni[], char fno[], char I
539    /***************PAMELA data extracting for each route***********/    /***************PAMELA data extracting for each route***********/
540  //  if (N1!=1&&(flag_CRC[1]==0||(flag_rout[1]==0&&flag_pack[1]==0)||  //  if (N1!=1&&(flag_CRC[1]==0||(flag_rout[1]==0&&flag_pack[1]==0)||
541  //        (flag_CRC[1]!=0&&flag_CRC_cor[1]==1)))  //        (flag_CRC[1]!=0&&flag_CRC_cor[1]==1)))
542    if (N1!=1)    if ((N1!=1)&&(flag_tr[1]==0))
543    {end=0;    {end=0;
544     if (buffer2[3]!=buffer1[3]||buffer2[3]!=buffer3[3])     if (buffer2[3]!=buffer1[3]||buffer2[3]!=buffer3[3])
545     {for (i=8;i<1020;i++)     {for (i=8;i<1020;i++)
# Line 737  void read(char fni[], char fno[], char I Line 555  void read(char fni[], char fno[], char I
555     //Write in file mmm_counter_nnnnn_cln1_bin.log     //Write in file mmm_counter_nnnnn_cln1_bin.log
556     tmp=numP[1];     tmp=numP[1];
557     for (k=0;k<4;k++) numPack[k]=0;     for (k=0;k<4;k++) numPack[k]=0;
558     for (k=0;k<4;k++)     for (k=0;k<3;k++)
559     {if (tmp/(long int)(pow(256.,3-k))>=1)     {if (tmp/(long int)(pow(256.,2-k))>=1)
560          {numPack[3-k]=(int)(tmp/(long int)(pow(256.,3-k)));          {numPack[2-k]=(int)(tmp/(long int)(pow(256.,2-k)));
561           tmp=tmp-(long int)pow(256.,3-k)*(int)(tmp/(long int)(pow(256.,3-k)));}}                   tmp=tmp-(long int)pow(256.,2-k)*(int)(tmp/(long int)(pow(256.,2-k)));}}        
562     for (i=0;i<4;i++) fputc((int)(unsigned char)(numPack[i]),fo_log_kadr);     for (i=0;i<3;i++) fputc((int)(unsigned char)(numPack[i]),fo_log_kadr);
563     adr1=icount-1024*2;     adr1=icount-1024*2;
564     for (k=0;k<4;k++) adress[k]=0;     for (k=0;k<4;k++) adress[k]=0;
565     for (k=0;k<4;k++)     for (k=0;k<4;k++)
# Line 770  void read(char fni[], char fno[], char I Line 588  void read(char fni[], char fno[], char I
588    //Write in file mmm_counter_nnnnn_cln1_bin.log    //Write in file mmm_counter_nnnnn_cln1_bin.log
589    tmp=numP[2];    tmp=numP[2];
590    for (k=0;k<4;k++) numPack[k]=0;    for (k=0;k<4;k++) numPack[k]=0;
591    for (k=0;k<4;k++)    for (k=0;k<3;k++)
592     {if (tmp/(long int)(pow(256.,3-k))>=1)     {if (tmp/(long int)(pow(256.,2-k))>=1)
593      {numPack[3-k]=(int)(tmp/(long int)(pow(256.,3-k)));      {numPack[2-k]=(int)(tmp/(long int)(pow(256.,2-k)));
594       tmp=tmp-(long int)pow(256.,3-k)*       tmp=tmp-(long int)pow(256.,2-k)*
595       (int)(tmp/(long int)(pow(256.,3-k)));}}           (int)(tmp/(long int)(pow(256.,2-k)));}}    
596     for (i=0;i<4;i++) fputc((int)(unsigned char)(numPack[i]),fo_log_kadr);     for (i=0;i<3;i++) fputc((int)(unsigned char)(numPack[i]),fo_log_kadr);
597     adr1=icount-1024;     adr1=icount-1024;
598     for (k=0;k<4;k++) adress[k]=0;     for (k=0;k<4;k++) adress[k]=0;
599     for (k=0;k<4;k++)     for (k=0;k<4;k++)
# Line 806  void read(char fni[], char fno[], char I Line 624  void read(char fni[], char fno[], char I
624    
625   icount_int = (int)(icount/1024);   icount_int = (int)(icount/1024);
626   icount_frac= icount%1024;   icount_frac= icount%1024;
 // cout<<"\nfile size="<<icount_total<<" Byte   "<<N1  
 //     <<" identified cadrs   Number of routs="<<Rcount<<"\n";  
 // cout<<" size of identified cadrs="<<icount<<" bytes   "<<count_ident[0]<<"\n";  
627    
628  //***protocol file***********************************************  //***protocol file***********************************************
  strcpy(file_name_prot, path);  
  strcat(file_name_prot, name);  
629   file_length=(int)(strlen(name));   file_length=(int)(strlen(name));
630   fprintf(fo,"file name=%s\n",file_name_prot);   fprintf(fo,"file name=/home/ntsomz/downlinks/%s\n",name);
631   fprintf(fo,"file size= %i,%i kByte \n", icount_int,   fprintf(fo,"file size= %i,%i kByte \n", icount_int, icount_frac);
632                                                         icount_frac);   fprintf(fo,"number identified cadres= %i\n", N1);
633   for (i=0;i<Rcount;i++)   fprintf(fo,"number of routes= %i\n", Rcount);
634   {fprintf(fo,"route=%i;",NumRout[i]);  
635    fprintf(fo," size of identified cadrs =%lli bytes;",count_ident[i]);   for (i=0;i<Rcount;i++)
636     {
637      Num_good_kadrs[i]=Num_kadrs[i]-Num_bad_kadrs[i];
638      quality[i]=(float)(1.)-(float)(Num_bad_kadrs[i])/(float)(Num_kadrs[i]);
639      fprintf(fo,"\nRoute number=%i: number of normal cadres= %i: number of errors=%i; \n",NumRout[i],Num_good_kadrs[i],Num_bad_kadrs[i]);
640      fprintf(fo," size of identified cadres =%lli bytes;",count_ident[i]);
641    fprintf(fo," total size of route=%lli bytes;\n",count_tot[i]);    fprintf(fo," total size of route=%lli bytes;\n",count_tot[i]);
642    fprintf(fo,"number of errors=%i;\n",Num_bad_kadrs[i]);    fprintf(fo," first cadre number= %lli:", packet_first[i]);
643      fprintf(fo," last cadre number= %lli:", packet_last[i]);
644      fprintf(fo," Number of missed cadres= %i:\n", count_missed[i]);  
645      fprintf(fo,"number of identified cadres=%lli: quality index=%f\n", Num_kadrs[i], quality[i]);  
646   }   }
647    
648   //***route's number log file**************************************   //***route's number log file**************************************
649   for (i=0;i<Rcount;i++) {fprintf(fo_route,"%1c",(char)(NumRout[i]));}   for (i=0;i<Rcount;i++) {fprintf(fo_route,"%1c",(char)(NumRout[i]));}
650            
 //***cln1.inf file*************************************************  
  fprintf(fo1,"file name=");  
  fprintf(fo1,"%s%s",path,name);  
  fprintf(fo1,"\nfile size= %i,%i kByte \n", icount_int,  
                                                        icount_frac);  
  fprintf(fo1,"number identified kadrs= %i\n", N1);  
  fprintf(fo1,"number of routes= %i\n", Rcount);  
   
  for (i=0;i<Rcount;i++)  
  {  
   Num_good_kadrs[i]=Num_kadrs[i]-Num_bad_kadrs[i];  
   quality[i]=(float)(1.)-(float)(Num_bad_kadrs[i])/(float)(Num_kadrs[i]);  
   fprintf(fo1,"\nRoute number=%i: number of normal kadrs= %i:\n",  
                   NumRout[i],Num_good_kadrs[i]);  
   fprintf(fo1,"first kadre number= %lli:", packet_first[i]);  
   fprintf(fo1," last kadre number= %lli:", packet_last[i]);  
   fprintf(fo1," Number of missed kadrs= %i:\n", count_missed[i]);  
 //  fprintf(fo1,"Number of double transmitted kadrs= %i:\n", count_sec_missed[i]);    
   fprintf(fo1,"number of identified kadres=%lli: quality index=%f\n", Num_kadrs[i], quality[i]);  
  }        
651  //***************************************************************  //***************************************************************
652    fin.close();    fin.close();
653    fclose(fout);    fclose(fout);
654    fclose(fo);    fclose(fo);
   fclose(fo1);  
655    fclose(foRout);    fclose(foRout);
656    fclose(foMiss);    fclose(foMiss);
657    fo_cln1.close();    fo_cln1.close();

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.23