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