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

Annotation of /rawreader/src/Main.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Sun Dec 10 13:05:54 2006 UTC (17 years, 11 months ago) by cafagna
Branch: MAIN
CVS Tags: v1r14
Changes since 1.3: +41 -41 lines
5th of December version

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

  ViewVC Help
Powered by ViewVC 1.1.23