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

Contents of /rawreader/source/sort.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show 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 ///////////////PAMELA PACKETS SORT///////////////////////////////////
2 #include "descript.h"
3 void RunHeaderReader(char *buf);
4 extern long int OBTtimesync;
5 extern long int Timesync;
6 struct Names
7 {
8 char a[80]; /*Full name for mmm_nnnnn_counter_xx.bin*/
9 char a_short[80]; /*Short name for mmm_nnnnn_counter_xx.bin*/
10 FILE *fo_a;
11 };
12
13 void sort(char log[], char pam[], char path[], char path3[],
14 char file_init[], int packet_type[])
15
16 {
17 FILE *fo_log, *fo_ql, *fo_work2, *f_temp;
18
19 Names data[NumberPack+1];
20 char fno2[80]; /* Out help file mm_nnnnn_work2.dat*/
21 char ql[80];
22 char tmp[80], tmp1[80], numer[10];
23 char arina[80];
24 // char buffer[10];
25 char *packet=new char[Nmax];
26 unsigned int type=0; /*PAMELA packet type*/
27 unsigned int error=0; /*PAMELA packet error flag*/
28 int Length=0; /*Length of filename*/
29 long int counter[NumberPack+1];/*Counter for PAMELA packets in each dat file*/
30 unsigned long int adr1=0; /*First byte of PAMELA packet in _cln2.pam*/
31 unsigned long int adr2=0; /*Last byte of PAMELA packet in _cln2.pam*/
32 long int time=0; /*PAMELA packet time*/
33 long int moscowtime=0; /*moscow time of packets*/
34 long int first[NumberPack+1]; /*First byte for PAMELA packets of given type*/
35 long int last[NumberPack+1]; /*Last byte for PAMELA packets of given type*/
36 long int temp=0;
37 int Hex_first[4];
38 int Hex_last[4];
39 int i=0, j=0, stop=0;
40
41 for (i=0;i<4;i++)
42 {Hex_first[i]=0;
43 Hex_last[i]=0;}
44
45 for (i=0;i<NumberPack+1;i++)
46 {counter[i]=0;
47 first[i]=0;
48 last[i]=0;}
49
50 Length=(int)(strlen(file_init));
51 strncat(strcpy(tmp,"\0"),file_init,Length-8);
52 strcat(strcpy(tmp1,path),"tmp.dat");
53 f_temp=fopen(tmp1,"wb+");
54
55 for (i=0;i<NumberPack+1;i++)
56 {
57 if (i==0) {fprintf(f_temp,"%02i",i);}
58 else {fprintf(f_temp,"%02X",packet_type[i-1]);}
59 fseek(f_temp,0,0);
60 fgets(numer,10,f_temp);
61 fseek(f_temp,0,0);
62 /*************Open files /home/pamelaprod/rawreader/level0/nnnnn/mmm_counter/packets/mmm_nnnnn_counter_xx.bin*******/
63 strncat(strcpy(data[i].a,path3),file_init,Length-8);
64 strcat(data[i].a,numer);
65 strcat(data[i].a,".bin");
66 //form the 'mmm_'
67 for (j=0;j<4;j++) tmp[j]=data[i].a[strlen(data[i].a)-(20-j)];
68 //form the 'mmm_nnnnn_'
69 for (j=0;j<6;j++) tmp[j+4]=data[i].a[strlen(data[i].a)-(12-j)];
70 //form the 'mmm_nnnnn_ccc_'
71 for (j=0;j<4;j++) tmp[j+10]=data[i].a[strlen(data[i].a)-(16-j)];
72 //form the 'mmm_nnnnn_ccc_XX.bin'
73 for (j=0;j<6;j++) tmp[j+14]=data[i].a[strlen(data[i].a)-(6-j)]; tmp[20]='\0';
74 /*********************Create names mmm_nnnnn_counter_xx.bin********************/
75 for (j=0;j<20;j++)
76 {data[i].a_short[j]=tmp[j]; data[i].a_short[20]='\0';
77 data[i].a[strlen(data[i].a)-(20-j)]=tmp[j];
78 }
79
80 data[i].fo_a=fopen(data[i].a,"wb");
81 if(data[i].fo_a==NULL)
82 {cerr<<"can not open _%s.dat file",numer; exit(1);}
83
84 }
85 fclose(f_temp);
86 remove(tmp1);
87 /**********************OPEN NECESSARY FILES************************/
88 /******************************************************************/
89 ifstream fo_pam;
90 fo_pam.open(pam,ios::binary); //open input file "mmm_counter_nnnnn_cln2.pam"
91 if(fo_pam.good()==0) {cerr<<"can not open pam file"; exit(1);}
92
93 ofstream fo_arina;
94 strcpy(arina,"/home/arina/orientation/");
95 strcat(arina,data[28].a_short); cout<<arina<<"\n";
96 fo_arina.open(arina,ios::binary);
97 if(fo_arina.good()==0) {cerr<<"can not open arina file"; exit(1);}
98
99 fo_log=fopen(log, "rb"); //open input file "mmm_counter_nnnnn_cln2.log"
100 if(fo_log==NULL) {cerr<<"can not open log file"; exit(1);}
101
102 strcpy(fno2,path3);
103 strncat(fno2,file_init,strlen(file_init)-8);
104 fo_work2=fopen(strcat(fno2,"work2.dat"), "wb");
105 fo_work2=fopen(fno2, "wb"); //open output help file "work_cln2.dat"
106 if(fo_work2==NULL) {cerr<<"can not open outputfile"; exit(1);}
107
108 strncat(strcpy(ql,path3),file_init,Length-8);
109 strcat(ql,"ql.log");
110 fo_ql=fopen(ql, "wb"); //open output file "mmm_counter_nnnnn_ql.log"
111 if(fo_ql==NULL) {cerr<<"can not open ql file"; exit(1);}
112
113 /******************************************************************/
114 /******************************************************************/
115 while(feof(fo_log)==0)
116 {
117 //read PAMELA packet information from Route_cln2.log
118 fscanf(fo_log,"%1c",&type);
119 if (feof(fo_log)!=0) break;
120 fscanf(fo_log,"%4c",&adr1);
121 if (feof(fo_log)!=0) break;
122 fscanf(fo_log,"%4c",&adr2);
123 if (feof(fo_log)!=0) break;
124 fscanf(fo_log,"%1c",&error);
125 if (feof(fo_log)!=0) break;
126
127 // cout<<bitset<8>(error)<<"\n";
128 // cout<<bitset<8>(error).test(0)<<"\n";
129 if ( ( (bitset<8>(error).test(7))||(error==0)||
130 ((bitset<8>(error).test(0))&&(!bitset<8>(error).test(1))&&(!bitset<8>(error).test(2))&&
131 (!bitset<8>(error).test(3))&&(!bitset<8>(error).test(4))&&(!bitset<8>(error).test(5))&&
132 (!bitset<8>(error).test(6))) )&&
133 (type>0)&&(type<NumberPack+1) )
134 {
135 /*Place file pointer in Route_cln2.pam on packet begin*/
136 fo_pam.seekg(adr1-1,ios::beg);
137 //read PAMELA packet from Route_cln2.pam
138 fo_pam.read(packet,adr2-adr1+1);
139
140 /*OBT of Pamela*/
141 time=(long int)(unsigned char)(packet[11])+
142 256*(long int)(unsigned char)(packet[10])+
143 256*256*(long int)(unsigned char)(packet[9])+
144 256*256*256*(long int)(unsigned char)(packet[8]);
145
146 /* mikhailov time goes to moscow time 08 12 2004*/
147
148 moscowtime=time-(OBTtimesync-Timesync);
149
150 if(type == 11) cout<<"time ="<<time<<" moscowtime ="<<moscowtime<<"\n";
151 /*temp is packet number*/
152 temp=(long int)(unsigned char)(packet[7])+
153 256*(long int)(unsigned char)(packet[6])+
154 256*256*(long int)(unsigned char)(packet[5]);
155 if ((fmod((float)(temp),(float)(10000.))==0.)&&(temp!=0)) cout<<"sorting "<<temp<<"\n";
156 /*unpacking several packets.... mikhailov
157 unpackingPamelaPacket(packet,type)*/
158
159 // if (type == 10) RunHeaderReader(packet);
160 if( type == 11){RunHeaderReader(packet);}
161 /*******************Packet with type "type"***********************/
162 counter[type]+=1;
163 //write PAMELA packet in mmm_nnnnn_counter_xx.bin
164 if (type!=4) fwrite(packet,adr2-adr1+1,1,data[type].fo_a);
165 //write for ARINA
166 if (type==28) fo_arina.write(packet,adr2-adr1+1);
167 first[type]=last[type]+1;
168 last[type]+=adr2-adr1+1;
169 temp=first[type];
170 for (i=0;i<4;i++) Hex_first[i]=0;
171 for (i=0;i<4;i++)
172 {if (temp/(long int)(pow(256.,3-i))>=1)
173 {Hex_first[3-i]=(int)(temp/(long int)(pow(256.,3-i)));
174 temp=temp-(long int)pow(256.,3-i)*
175 (int)(temp/(long int)(pow(256.,3-i)));}}
176 temp=last[type];
177 for (i=0;i<4;i++) Hex_last[i]=0;
178 for (i=0;i<4;i++)
179 {if (temp/(long int)(pow(256.,3-i))>=1)
180 {Hex_last[3-i]=(int)(temp/(long int)(pow(256.,3-i)));
181 temp=temp-(long int)pow(256.,3-i)*
182 (int)(temp/(long int)(pow(256.,3-i)));}
183 }
184 //write information about PAMELA packet in mmm_counter_nnnnn_ql.log
185 if (type!=4)
186 {
187 fprintf(fo_ql,"%1c",char(type));
188 for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(Hex_first[i]));
189 // for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(Hex_last[i]));
190 fprintf(fo_ql,"%1c",char(error));
191 // for (i=8;i<12;i++) fprintf(fo_ql,"%1c",packet[i]); //!!!!temporary
192
193
194 /* mikhailov time goes to moscow time* 08 12 2004*/
195 for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(time>>((3-i)*8)&0XFF));
196 for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(moscowtime>>((3-i)*8)&0XFF));
197 for (i=0;i<3;i++) fprintf(fo_ql,"%1c",packet[i+5]);
198 for (i=0;i<15;i++) fprintf(fo_ql,"%1c",char(0XFF)); //added to fill 32 bytes
199 }
200 }
201 else
202 {
203 /*******************Packets with errors***************************/
204 char *er_pack=new char [adr2-adr1+1];
205 /*Place file pointer in mmm_counter_nnnnn_cln2.pam on error packet begin*/
206 fo_pam.seekg(adr1-1,ios::beg);
207 //read PAMELA error packet from mmm_counter_nnnnn_cln2.pam
208 fo_pam.read(er_pack,adr2-adr1+1);
209 time=(long int)(unsigned char)(er_pack[11])+
210 256*(long int)(unsigned char)(er_pack[10])+
211 256*256*(long int)(unsigned char)(er_pack[9])+
212 256*256*256*(long int)(unsigned char)(er_pack[8]);
213 counter[0]+=1;
214 //write PAMELA packet in mmm_nnnnn_conter_00.bin
215 fwrite(er_pack,adr2-adr1+1,1,data[0].fo_a);
216 first[0]=last[0]+1;
217 last[0]+=adr2-adr1+1;
218 temp=first[0];
219 for (i=0;i<4;i++) Hex_first[i]=0;
220 for (i=0;i<4;i++)
221 {if (temp/(long int)(pow(256.,3-i))>=1)
222 {Hex_first[3-i]=(int)(temp/(long int)(pow(256.,3-i)));
223 temp=temp-(long int)pow(256.,3-i)*
224 (int)(temp/(long int)(pow(256.,3-i)));}
225 }
226 temp=last[0];
227 for (i=0;i<4;i++) Hex_last[i]=0;
228 for (i=0;i<4;i++)
229 {if (temp/(long int)(pow(256.,3-i))>=1)
230 {Hex_last[3-i]=(int)(temp/(long int)(pow(256.,3-i)));
231 temp=temp-(long int)pow(256.,3-i)*
232 (int)(temp/(long int)(pow(256.,3-i)));}
233 }
234 if (type!=4)
235 {//write information about PAMELA packet in mmm_counter_nnnnn_ql.log
236 fprintf(fo_ql,"%1c",(char)(type));
237 for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(Hex_first[i]));
238 // for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(Hex_last[i])); //temporary
239 fprintf(fo_ql,"%1c",char(error));
240 // for (i=8;i<12;i++) fprintf(fo_ql,"%1c",er_pack[i]);
241 /* mikhailov time goes to moscow time 08 12 2004*/
242 for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(time>>((3-i)*8)&0XFF));
243 for (i=0;i<4;i++) fprintf(fo_ql,"%1c",char(moscowtime>>((3-i)*8)&0XFF));
244 for (i=0;i<3;i++) fprintf(fo_ql,"%1c",er_pack[i+5]);
245 for (i=0;i<15;i++) fprintf(fo_ql,"%1c",char(0XFF)); //added to fill 32 bytes
246
247 delete [] er_pack;
248 }
249 }
250 }
251
252 for (i=0;i<NumberPack+1;i++)
253 fprintf(fo_work2,"Number of packets in %s file = %i\n",data[i].a_short,counter[i]);
254
255 fo_pam.close();
256 fo_arina.close();
257 fclose(fo_log);
258 fclose(fo_work2);
259
260 for(i=0;i<NumberPack+1;i++) fclose(data[i].fo_a);
261 fclose(fo_ql);
262 delete [] packet;
263 }

  ViewVC Help
Powered by ViewVC 1.1.23