///////////////PAMELA PACKETS SORT/////////////////////////////////// #include "descript.h" #include "flag.h" void RunHeaderReader(char *buf); extern long int OBTtimesync; extern long int Timesync; struct Names { char a[80]; /*Full name for mmm_nnnnn_counter_xx.bin*/ char a_short[80]; /*Short name for mmm_nnnnn_counter_xx.bin*/ FILE *fo_a; }; void sort(char log[], char pam[], char path[], char path3[], char file_init[], int packet_type[]) { FILE *fo_log, *fo_ql, *fo_work2, *f_temp; Names data[NumberPack+1]; char fno2[80]; /* Out help file mm_nnnnn_work2.dat*/ char ql[80]; char tmp[80], tmp1[80], numer[10]; char arina[80]; // char buffer[10]; char *packet=new char[Nmax]; unsigned int type=0; /*PAMELA packet type*/ unsigned int error=0; /*PAMELA packet error flag*/ int Length=0; /*Length of filename*/ long int counter[NumberPack+1];/*Counter for PAMELA packets in each dat file*/ unsigned long int adr1=0; /*First byte of PAMELA packet in _cln2.pam*/ unsigned long int adr2=0; /*Last byte of PAMELA packet in _cln2.pam*/ long int time=0; /*PAMELA packet time*/ long int moscowtime=0; /*moscow time of packets*/ long int first[NumberPack+1]; /*First byte for PAMELA packets of given type*/ long int last[NumberPack+1]; /*Last byte for PAMELA packets of given type*/ long int temp=0; int Hex_first[4]; int Hex_last[4]; int i=0, j=0, stop=0; for (i=0;i<4;i++) {Hex_first[i]=0; Hex_last[i]=0;} for (i=0;i(error).test(7))||(error==0)|| ((bitset<8>(error).test(0))&&(!bitset<8>(error).test(1))&&(!bitset<8>(error).test(2))&& (!bitset<8>(error).test(3))&&(!bitset<8>(error).test(4))&&(!bitset<8>(error).test(5))&& (!bitset<8>(error).test(6))) )&& (type>0)&&(type=1) {Hex_first[3-i]=(int)(temp/(long int)(pow(256.,3-i))); temp=temp-(long int)pow(256.,3-i)* (int)(temp/(long int)(pow(256.,3-i)));}} temp=last[type]; for (i=0;i<4;i++) Hex_last[i]=0; for (i=0;i<4;i++) {if (temp/(long int)(pow(256.,3-i))>=1) {Hex_last[3-i]=(int)(temp/(long int)(pow(256.,3-i))); temp=temp-(long int)pow(256.,3-i)* (int)(temp/(long int)(pow(256.,3-i)));} } //write information about PAMELA packet in xxx_mmm_nnnnn_ql.log if (type!=4) { fprintf(fo_ql,"%1c",char(type)); for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(Hex_first[i])); // for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(Hex_last[i])); fprintf(fo_ql,"%1c",char(error)); // for (i=8;i<12;i++) fprintf(fo_ql,"%1c",packet[i]); //!!!!temporary /* mikhailov time goes to moscow time* 08 12 2004*/ for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(time>>((3-i)*8)&0XFF)); for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(moscowtime>>((3-i)*8)&0XFF)); for (i=0;i<3;i++) fprintf(fo_ql,"%1c",packet[i+5]); for (i=0;i<15;i++) fprintf(fo_ql,"%1c",char(0XFF)); //added to fill 32 bytes } } else { /*******************Packets with errors***************************/ char *er_pack=new char [adr2-adr1+1]; /*Place file pointer in mmm_counter_nnnnn_cln2.pam on error packet begin*/ fo_pam.seekg(adr1-1,ios::beg); //read PAMELA error packet from mmm_counter_nnnnn_cln2.pam fo_pam.read(er_pack,adr2-adr1+1); time=(long int)(unsigned char)(er_pack[11])+ 256*(long int)(unsigned char)(er_pack[10])+ 256*256*(long int)(unsigned char)(er_pack[9])+ 256*256*256*(long int)(unsigned char)(er_pack[8]); counter[0]+=1; //write PAMELA packet in mmm_nnnnn_conter_00.bin fwrite(er_pack,adr2-adr1+1,1,data[0].fo_a); first[0]=last[0]+1; last[0]+=adr2-adr1+1; temp=first[0]; for (i=0;i<4;i++) Hex_first[i]=0; for (i=0;i<4;i++) {if (temp/(long int)(pow(256.,3-i))>=1) {Hex_first[3-i]=(int)(temp/(long int)(pow(256.,3-i))); temp=temp-(long int)pow(256.,3-i)* (int)(temp/(long int)(pow(256.,3-i)));} } temp=last[0]; for (i=0;i<4;i++) Hex_last[i]=0; for (i=0;i<4;i++) {if (temp/(long int)(pow(256.,3-i))>=1) {Hex_last[3-i]=(int)(temp/(long int)(pow(256.,3-i))); temp=temp-(long int)pow(256.,3-i)* (int)(temp/(long int)(pow(256.,3-i)));} } if (type!=4) {//write information about PAMELA packet in xxx_mmm_nnnnn_ql.log fprintf(fo_ql,"%1c",(char)(type)); for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(Hex_first[i])); // for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(Hex_last[i])); //temporary fprintf(fo_ql,"%1c",char(error)); // for (i=8;i<12;i++) fprintf(fo_ql,"%1c",er_pack[i]); /* mikhailov time goes to moscow time 08 12 2004*/ for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(time>>((3-i)*8)&0XFF)); for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(moscowtime>>((3-i)*8)&0XFF)); for (i=0;i<3;i++) fprintf(fo_ql,"%1c",er_pack[i+5]); for (i=0;i<15;i++) fprintf(fo_ql,"%1c",char(0XFF)); //added to fill 32 bytes delete [] er_pack; } } } for (i=0;i