1 |
|
2 |
#ifdef HAVE_CONFIG_H
|
3 |
#include <config.h>
|
4 |
#endif
|
5 |
|
6 |
/***************MAIN********************************************/
|
7 |
#include "descript.h"
|
8 |
#include "flag.h"
|
9 |
|
10 |
//mikhailov 06. 12. 2004. : initialization of global parameteres for time sync. it is used
|
11 |
//in in sort.cpp to convert OBT of Pamela to Moscow Time .
|
12 |
//this information is apdated in RunHeaderReader
|
13 |
long int RTtoMT,RT,Timesync,OBTtimesync; // Resurs time to moscow, Resurs time, ...
|
14 |
|
15 |
void read(char [], char [], char [], char [], char [], char [],
|
16 |
char[], float [], int[], int &);
|
17 |
void verify(char [], char[], char [], char [], char [], char [], char [],
|
18 |
char [], int[], float, int, int[]);
|
19 |
void confluence(char [], char [], char [], char [], char [], int[]);
|
20 |
void sort(char [], char [], char [], char[], char [], int[]);
|
21 |
|
22 |
char MYSQL[120];
|
23 |
char database[120];
|
24 |
char arina[120];
|
25 |
float YODA_flag;
|
26 |
float transmit_flag;
|
27 |
int print_flag;
|
28 |
char timesync[120];
|
29 |
|
30 |
int main(int argc, char *argv[])
|
31 |
{
|
32 |
|
33 |
// char stop;
|
34 |
float IndexQ, quality[100]; /*Quality index*/
|
35 |
int real_route[64];
|
36 |
int rc=0;
|
37 |
int r_counter; /*Route counter*/
|
38 |
|
39 |
char MainPath[120]; /* /home/pamelaprod/rawreader/ */
|
40 |
|
41 |
char INF[80]; /*Full out information file name nnnnn_cln1.inf*/
|
42 |
char fni[80]; /*Full initial file name nnnnnmmm.pam*/
|
43 |
char fno[80]; /*Full out helping file name nnnnn_work.dat*/
|
44 |
char path[80]; /*Initial path*/
|
45 |
char name[80]; /*Initial file name nnnnnmmm.pam*/
|
46 |
char protocol[80]; /*Full out file name nnnnn_protocol.txt*/
|
47 |
char nnnnn_TMP[80]; /*Directory for processed data*/
|
48 |
char command[180]; /*DOS command*/
|
49 |
char str_del[80]; /*Delete Cln1 directory in case of good quality*/
|
50 |
char temp[120]; /*For temporary file*/
|
51 |
char temp1[80]; /*For temporary file*/
|
52 |
char temp2[80]; /*For temporary file*/
|
53 |
char temp3[80]; /*For temporary file*/
|
54 |
char temp4[80];
|
55 |
|
56 |
char fni2[100]; /*Initial file mmm_nnnnn_cln1.pam*/
|
57 |
char inf2[100]; /*File name mmm_nnnnn_cln2.inf*/
|
58 |
char pam2[100]; /*File name mmm_nnnnn_cln2.pam*/
|
59 |
char name2[100]; /*Initial file name mmm_counter_nnnnn_cln1.pam*/
|
60 |
char log2[100]; /*File name mmm_nnnnn_cln2.log*/
|
61 |
char name_ql[80]; /*File name mmm_nnnnn_ql.log*/
|
62 |
char fno2[80]; /*Out help file mmm_nnnnn_work.dat*/
|
63 |
char path2[80]; /*Path for ...Temp/nnnnn_TMP/mmm/Cln2/*/
|
64 |
char mmm[80]; /*For route number*/
|
65 |
char name_route[4]; /*Route number in the file name*/
|
66 |
|
67 |
char path3[100]; /*Path for ...Level0/nnnnn_mmm_L0/*/
|
68 |
char exten[10]; /*Extension for the raw initial file*/
|
69 |
char temporary[80], Tymesync[80];
|
70 |
int Rcount=0; /*Number of Routes*/
|
71 |
int packet_type[NumberPack]={0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x16, 0x17, 0x18, 0x19,
|
72 |
0x1A, 0x1B, 0x1C, 0x1D, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x30, 0x50, 0x51, 0x52, 0x53,
|
73 |
0x54, 0x55, 0x60, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x81, 0x82, 0x83, 0x84,
|
74 |
0x85, 0x86, 0x88, 0x89, 0x8A, 0xA1, 0xAB, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4};/*PAMELA packet type code*/
|
75 |
int i, j;
|
76 |
int stop;
|
77 |
|
78 |
for (i=0;i<100;i++) quality[i]=0;
|
79 |
for (i=0;i<64;i++) real_route[i]=0;
|
80 |
|
81 |
FILE *ftime_sync;
|
82 |
FILE *fff, *tmp, *tmp1, *tmp2, *tmp3, *tmp4;
|
83 |
ifstream fpath;
|
84 |
|
85 |
//Read parameters from the initial file
|
86 |
fpath.open("/home/pamelaprod/rawreader/bin/parameters.dat", ios::out);
|
87 |
if (!fpath) {cout<<"can not open file with input parameters \n"; exit(1);}
|
88 |
fpath.getline(MainPath,100,'\n');
|
89 |
sscanf(MainPath,"%s",MainPath);
|
90 |
fpath.getline(timesync,100,'\n');
|
91 |
sscanf(timesync,"%s",timesync);
|
92 |
fpath.getline(arina,100,'\n');
|
93 |
sscanf(arina,"%s",arina);
|
94 |
fpath.getline(MYSQL,100,'\n');
|
95 |
sscanf(MYSQL,"%s",MYSQL);
|
96 |
fpath.getline(database,100,'\n');
|
97 |
sscanf(database,"%s",database);
|
98 |
fpath.getline(temp,120,'\n');
|
99 |
sscanf(temp,"%f",&YODA_flag);
|
100 |
fpath.getline(temp,120,'\n');
|
101 |
sscanf(temp,"%f",&transmit_flag);
|
102 |
fpath.getline(temp,120,'\n');
|
103 |
sscanf(temp,"%i",&print_flag);
|
104 |
|
105 |
/* cout<<"MainPath="<<MainPath<<" "<<strlen(MainPath)<<"\n";
|
106 |
cout<<"timesync="<<timesync<<" "<<strlen(timesync)<<"\n";
|
107 |
cout<<"arina="<<arina<<" "<<strlen(arina)<<"\n";
|
108 |
cout<<"MYSQL="<<MYSQL<<" "<<strlen(MYSQL)<<"\n";
|
109 |
cout<<"database="<<database<<" "<<strlen(database)<<"\n";
|
110 |
cout<<"YODA_flag="<<YODA_flag<<"\n";
|
111 |
cout<<"transmit_flag="<<transmit_flag<<"\n";
|
112 |
cout<<"print_flag="<<print_flag<<"\n";*/
|
113 |
|
114 |
fpath.close();
|
115 |
|
116 |
// mikhailov 06.12.2004
|
117 |
ftime_sync=fopen(timesync,"r+");
|
118 |
if (!ftime_sync) {cout<<"can not open file with time synchronization \n"; exit(1);}
|
119 |
while(feof(ftime_sync)==0)
|
120 |
{fscanf(ftime_sync,"%u%[ ]%u%[ ]%u%[ ]%u\n",&RTtoMT, temp, &RT, temp, &Timesync, temp, &OBTtimesync);}
|
121 |
fclose(ftime_sync);
|
122 |
// end mikhailov
|
123 |
|
124 |
if (print_flag>0) cout<<"global_err="<<GLOBAL_LEN_ER<<"\n";
|
125 |
strcpy(name,argv[2]);
|
126 |
name_route[0]=name[5];
|
127 |
name_route[1]=name[6];
|
128 |
name_route[2]=name[7];
|
129 |
name_route[3]='\0';
|
130 |
|
131 |
for(i=0;i<3;i++)
|
132 |
{exten[i]=name[i+9];}
|
133 |
exten[3]='\0';
|
134 |
|
135 |
if ((strlen(argv[2])!=12)||(strncmp(exten,"pam",3)!=0)) {cout<<"WRONG RAW FILE NAME\n"; exit(1);}
|
136 |
|
137 |
strcpy(fni,argv[1]);
|
138 |
strcat(fni,argv[2]);
|
139 |
|
140 |
/**************Creation directory nnnnn**********************/
|
141 |
strncat(strcpy(nnnnn_TMP,MainPath),argv[2],5);
|
142 |
strcpy(temp,nnnnn_TMP);
|
143 |
strcat(temp,"/tmp.dat");
|
144 |
|
145 |
if ((tmp=fopen(temp,"w"))==0)
|
146 |
{
|
147 |
strcpy(command,"mkdir ");
|
148 |
strcat(command,nnnnn_TMP);
|
149 |
system(command);
|
150 |
}
|
151 |
else
|
152 |
{
|
153 |
printf("directory %s already exists - rewriting \n",strncat(strcpy(temp1," "),argv[2],5));
|
154 |
fclose(tmp);
|
155 |
remove(temp);
|
156 |
// exit(1);
|
157 |
}
|
158 |
/****************************************************************/
|
159 |
|
160 |
strcat(strncat(strcat( strcpy(INF,nnnnn_TMP),"/"),name,8),"_cln1.inf");
|
161 |
strcat(strcpy(path,nnnnn_TMP),"/");
|
162 |
strcat(strncat(strcat(strcpy(fno,nnnnn_TMP),"/"),name,8),"_work.dat");
|
163 |
strcat(strncat(strcat(strcpy(protocol,nnnnn_TMP),"/"),name,8),"_protocol.txt");
|
164 |
|
165 |
if (VRL_HEADER>0)
|
166 |
{
|
167 |
/*Creation of directories nnnnn_TMP\mmm_counter and ...\Cln1 in filename.cpp*/
|
168 |
read(fni, fno, INF, protocol, path, name, nnnnn_TMP, quality, real_route, Rcount); ////////////////// //////////////
|
169 |
}
|
170 |
else
|
171 |
{
|
172 |
temp[0]=name[5];
|
173 |
temp[1]=name[6];
|
174 |
temp[2]=name[7];
|
175 |
temp[3]='\0';
|
176 |
strcat(strcat(strcpy(temp1,nnnnn_TMP),"/"),temp);
|
177 |
strcat(strcpy(command,"mkdir "),temp1);
|
178 |
|
179 |
system(command);
|
180 |
strcat(temp1,"/Cln1");
|
181 |
strcat(strcpy(command,"mkdir "),temp1);
|
182 |
system(command);
|
183 |
/**********Copy file to directory nnnnn_TMP\mmm\Cln1*************/
|
184 |
strcat(strcat(strcat(strcat(strcat(strcpy(command,"cp "),fni)," "),temp1),"/"),name);
|
185 |
|
186 |
system(command);
|
187 |
strcat(strcat(strcpy(temp2,temp1),"/"),name);
|
188 |
strcat(strcat(strcat(strcpy(temp3,temp1),"/"),temp),"_");
|
189 |
strcat(strncat(temp3,name,5),"_cln1.pam");
|
190 |
rename(temp2,temp3);
|
191 |
}
|
192 |
|
193 |
if (CLN2_FLAG>0)
|
194 |
{
|
195 |
for(i=0;i<256;i++)
|
196 |
{
|
197 |
sprintf(temp4,"%03i",i);
|
198 |
sscanf(temp4,"%3s",mmm); mmm[3]='\0';
|
199 |
strcat(strcat(strcat(strcat(strcat(strcpy(temp1,nnnnn_TMP),"/"),name_route),"_"),mmm),"/tmp.dat");
|
200 |
|
201 |
if ((tmp1=fopen(temp1,"w"))!=0)
|
202 |
{
|
203 |
fclose(tmp1);
|
204 |
remove(temp1);
|
205 |
name2[0]='\0';
|
206 |
strcat(strcat(strcat(strcat(strcat(strncat(name2,name,5),"_"),name_route),"_"),mmm),"_cln1.pam");
|
207 |
if (CLN1_MEPHI==0)
|
208 |
{strcat(strcat(strcat(strcat(strcat(strcat(strcpy(fni2,nnnnn_TMP),"/"),name_route),"_"),mmm),"/Cln1/"),name2);}
|
209 |
else
|
210 |
{strcat(strcat(strncat(strcpy(fni2,""),nnnnn_TMP,strlen(nnnnn_TMP)-5),"Cln1/"),name2);}
|
211 |
strcpy(temp4,path);
|
212 |
strcat(strcat(strcat(strcat(temp4,name_route),"_"),mmm),"/Cln2/tmp.dat");
|
213 |
if ((tmp4=fopen(temp4,"w"))==0)
|
214 |
{
|
215 |
/**************Creation directory nnnnn\xxx_mmm\Cln2****************/
|
216 |
strcat(strcat(strcat(strcat(strcat(strcat(strcpy(command,"mkdir "),nnnnn_TMP),"/"),name_route),"_"),mmm),"/Cln2");
|
217 |
system(command);
|
218 |
/*******************************************************************/
|
219 |
}
|
220 |
else
|
221 |
{
|
222 |
fclose(tmp4);
|
223 |
remove(temp4);
|
224 |
}
|
225 |
strcat(strcat(strcat(strcat(strcat(strcpy(path2,nnnnn_TMP),"/"),name_route),"_"),mmm),"/Cln2/");
|
226 |
strcat(strncat(strcpy(inf2,path2),name2,13),"_cln2.inf");
|
227 |
strcat(strncat(strcpy(log2,path2),name2,13),"_cln2.log");
|
228 |
strcat(strncat(strcpy(pam2,path2),name2,13),"_cln2.pam");
|
229 |
strcat(strncat(strcpy(fno2,path2),name2,13),"_work.dat");
|
230 |
|
231 |
IndexQ=quality[i-1];
|
232 |
r_counter=i;
|
233 |
verify(fni2, inf2, log2, pam2, fno2, path2, name, name2, packet_type, IndexQ, r_counter, real_route); /////////////////////////////////
|
234 |
strcat(strcat(strcat(strcat(strcat(strcat(strcpy(fni2,nnnnn_TMP),"/"),name_route),"_"),mmm),"/Cln1/"),name2);
|
235 |
//Delete Cln1
|
236 |
if (IndexQ>0.999)
|
237 |
{strcpy(str_del,"rm -r -f ");
|
238 |
strncat(str_del,fni2,strlen(fni2)-22);
|
239 |
if (system(str_del)) cout<<"Can not delete Cln1 for counter="<<r_counter<<"\n";
|
240 |
}
|
241 |
strcat(strcat(strcat(strcat(strcat(strncat(strcpy(path3,MainPath),argv[2],5),"/"),name_route),"_"),mmm),"/packets");
|
242 |
|
243 |
strcat(strcpy(temp2,path3),"/tmpM.dat");
|
244 |
if ((tmp2=fopen(temp2,"w"))==0)
|
245 |
{
|
246 |
/**************Creation directory level0\nnnnn\counter_mmm\packets***************/
|
247 |
strcat(strcpy(command,"mkdir "),path3);
|
248 |
system(command);
|
249 |
/*******************************************************************/
|
250 |
}
|
251 |
else
|
252 |
{
|
253 |
fclose(tmp2);
|
254 |
remove(temp2);
|
255 |
printf("directory for file %s already exists - rewriting \n",
|
256 |
strcat(strcat(strcat(strcat(strncat(strcpy(temp3," "),argv[2],5),"_"),name_route),"_"),mmm));
|
257 |
}
|
258 |
strcat(path3,"/");
|
259 |
sort(log2, pam2, path2, path3, name2, packet_type); /////////////////////////////////////
|
260 |
strcat(strncat(strcat(strcat(strcpy(name_ql,path3),mmm),"_"),argv[2],5),"_ql.log");
|
261 |
strcpy(temp3,"/home/pamelaprod/rawreader/bin/coordinate.exe");
|
262 |
if ((tmp3=fopen(temp3,"r"))==0)
|
263 |
{printf("file %s does not exist\n",temp3);}
|
264 |
else
|
265 |
{
|
266 |
fclose(tmp3);
|
267 |
strcat(strcat(strcpy(command,temp3)," "),name_ql);
|
268 |
// system(command);
|
269 |
}
|
270 |
}
|
271 |
}
|
272 |
}
|
273 |
|
274 |
return 0;
|
275 |
}
|