Rev 172 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 172 | Rev 181 | ||
---|---|---|---|
1 | #include "../include/sipmscan.h" |
1 | #include "../include/sipmscan.h" |
2 | #include "../include/workstation.h" |
2 | #include "../include/workstation.h" |
3 | 3 | ||
4 | #include <stdio.h> |
4 | #include <stdio.h> |
5 | #include <stdlib.h> |
5 | #include <stdlib.h> |
6 | 6 | ||
7 | // Separate functions ----------------------------------------- |
7 | // Separate functions ----------------------------------------- |
8 | void GetTime(int intime, char *outtime) |
8 | void GetTime(int intime, char *outtime) |
9 | { |
9 | { |
10 | time_t rawtime; |
10 | time_t rawtime; |
11 | struct tm * timeinfo; |
11 | struct tm * timeinfo; |
12 | if(intime < 0) |
12 | if(intime < 0) |
13 | time(&rawtime); |
13 | time(&rawtime); |
14 | else |
14 | else |
15 | rawtime = (time_t)intime; |
15 | rawtime = (time_t)intime; |
16 | timeinfo = localtime(&rawtime); |
16 | timeinfo = localtime(&rawtime); |
17 | sprintf(outtime, "%s", asctime(timeinfo)); |
17 | sprintf(outtime, "%s", asctime(timeinfo)); |
18 | int len = strlen(outtime); |
18 | int len = strlen(outtime); |
19 | if(len) outtime[len-1] = 0; |
19 | if(len) outtime[len-1] = 0; |
20 | } |
20 | } |
21 | 21 | ||
22 | void remove_ext(char *inname, char *outname) |
22 | void remove_ext(char *inname, char *outname) |
23 | { |
23 | { |
24 | char ctemp[256]; |
24 | char ctemp[256]; |
25 | for(int i = 0; i < (int)strlen(inname); i++) |
25 | for(int i = 0; i < (int)strlen(inname); i++) |
26 | { |
26 | { |
27 | if( (inname[i] == '.') && (i > (int)(strlen(inname)-6)) ) |
27 | if( (inname[i] == '.') && (i > (int)(strlen(inname)-6)) ) |
28 | { |
28 | { |
29 | ctemp[i] = '\0'; |
29 | ctemp[i] = '\0'; |
30 | sprintf(outname, "%s", ctemp); |
30 | sprintf(outname, "%s", ctemp); |
31 | break; |
31 | break; |
32 | } |
32 | } |
33 | else |
33 | else |
34 | ctemp[i] = inname[i]; |
34 | ctemp[i] = inname[i]; |
35 | } |
35 | } |
36 | 36 | ||
37 | if(DBGSIG) |
37 | if(DBGSIG) |
38 | printf("remove_ext(): Outfile = %s\n", outname); |
38 | printf("remove_ext(): Outfile = %s\n", outname); |
39 | } |
39 | } |
40 | 40 | ||
41 | void remove_from_last(char *inname, char search, char *outname) |
41 | void remove_from_last(char *inname, char search, char *outname) |
42 | { |
42 | { |
43 | char ctemp[256]; |
43 | char ctemp[256]; |
44 | int searchpos = -1; |
44 | int searchpos = -1; |
45 | for(int i = (int)strlen(inname); i >= 0; i--) |
45 | for(int i = (int)strlen(inname); i >= 0; i--) |
46 | { |
46 | { |
47 | if(inname[i] == search) |
47 | if(inname[i] == search) |
48 | { |
48 | { |
49 | searchpos = i; |
49 | searchpos = i; |
50 | break; |
50 | break; |
51 | } |
51 | } |
52 | } |
52 | } |
53 | 53 | ||
54 | for(int i = 0; i < searchpos; i++) |
54 | for(int i = 0; i < searchpos; i++) |
55 | ctemp[i] = inname[i]; |
55 | ctemp[i] = inname[i]; |
56 | 56 | ||
57 | ctemp[searchpos] = '\0'; |
57 | ctemp[searchpos] = '\0'; |
58 | sprintf(outname, "%s", ctemp); |
58 | sprintf(outname, "%s", ctemp); |
59 | 59 | ||
60 | if(DBGSIG) |
60 | if(DBGSIG) |
61 | printf("remove_from_last(): Outfile = %s\n", outname); |
61 | printf("remove_from_last(): Outfile = %s\n", outname); |
62 | } |
62 | } |
63 | 63 | ||
64 | void remove_before_last(char *inname, char search, char *outname) |
64 | void remove_before_last(char *inname, char search, char *outname) |
65 | { |
65 | { |
66 | char ctemp[256]; |
66 | char ctemp[256]; |
67 | int searchpos = -1; |
67 | int searchpos = -1; |
68 | for(int i = (int)strlen(inname); i >= 0; i--) |
68 | for(int i = (int)strlen(inname); i >= 0; i--) |
69 | { |
69 | { |
70 | if(inname[i] == search) |
70 | if(inname[i] == search) |
71 | { |
71 | { |
72 | searchpos = i; |
72 | searchpos = i; |
73 | break; |
73 | break; |
74 | } |
74 | } |
75 | } |
75 | } |
76 | 76 | ||
77 | int k = 0; |
77 | int k = 0; |
78 | for(int i = searchpos+1; i < (int)strlen(inname); i++) |
78 | for(int i = searchpos+1; i < (int)strlen(inname); i++) |
79 | { |
79 | { |
80 | ctemp[k] = inname[i]; |
80 | ctemp[k] = inname[i]; |
81 | k++; |
81 | k++; |
82 | } |
82 | } |
83 | 83 | ||
84 | ctemp[k] = '\0'; |
84 | ctemp[k] = '\0'; |
85 | sprintf(outname, "%s", ctemp); |
85 | sprintf(outname, "%s", ctemp); |
86 | 86 | ||
87 | if(DBGSIG) |
87 | if(DBGSIG) |
88 | printf("remove_before_last(): Outfile = %s\n", outname); |
88 | printf("remove_before_last(): Outfile = %s\n", outname); |
89 | } |
89 | } |
90 | 90 | ||
91 | void SeqNumber(int innum, int maxnum, char *outstr) |
91 | void SeqNumber(int innum, int maxnum, char *outstr) |
92 | { |
92 | { |
93 | int zeronum = 5; |
93 | int zeronum = 5; |
94 | 94 | ||
95 | // Check how many zeroes we need to add to get sequential numbers |
95 | // Check how many zeroes we need to add to get sequential numbers |
96 | if( (maxnum > 0) && (maxnum < 1000) ) |
96 | if( (maxnum > 0) && (maxnum < 1000) ) |
97 | zeronum = 2; |
97 | zeronum = 2; |
98 | else if( (maxnum >= 1000) && (maxnum < 10000) ) |
98 | else if( (maxnum >= 1000) && (maxnum < 10000) ) |
99 | zeronum = 3; |
99 | zeronum = 3; |
100 | else if( (maxnum >= 10000) && (maxnum < 100000) ) |
100 | else if( (maxnum >= 10000) && (maxnum < 100000) ) |
101 | zeronum = 4; |
101 | zeronum = 4; |
102 | else if( (maxnum >= 100000) && (maxnum < 1000000) ) |
102 | else if( (maxnum >= 100000) && (maxnum < 1000000) ) |
103 | zeronum = 5; |
103 | zeronum = 5; |
104 | 104 | ||
105 | // Make the sequence number depending on the number of zeroes |
105 | // Make the sequence number depending on the number of zeroes |
106 | if(zeronum == 2) |
106 | if(zeronum == 2) |
107 | { |
107 | { |
108 | if(innum < 10) |
108 | if(innum < 10) |
109 | sprintf(outstr, "00%d", innum); |
109 | sprintf(outstr, "00%d", innum); |
110 | else if( (innum >= 10) && (innum < 100) ) |
110 | else if( (innum >= 10) && (innum < 100) ) |
111 | sprintf(outstr, "0%d", innum); |
111 | sprintf(outstr, "0%d", innum); |
112 | else if( (innum >= 100) && (innum < 1000) ) |
112 | else if( (innum >= 100) && (innum < 1000) ) |
113 | sprintf(outstr, "%d", innum); |
113 | sprintf(outstr, "%d", innum); |
114 | } |
114 | } |
115 | else if(zeronum == 3) |
115 | else if(zeronum == 3) |
116 | { |
116 | { |
117 | if(innum < 10) |
117 | if(innum < 10) |
118 | sprintf(outstr, "000%d", innum); |
118 | sprintf(outstr, "000%d", innum); |
119 | else if( (innum >= 10) && (innum < 100) ) |
119 | else if( (innum >= 10) && (innum < 100) ) |
120 | sprintf(outstr, "00%d", innum); |
120 | sprintf(outstr, "00%d", innum); |
121 | else if( (innum >= 100) && (innum < 1000) ) |
121 | else if( (innum >= 100) && (innum < 1000) ) |
122 | sprintf(outstr, "0%d", innum); |
122 | sprintf(outstr, "0%d", innum); |
123 | else if( (innum >= 1000) && (innum < 10000) ) |
123 | else if( (innum >= 1000) && (innum < 10000) ) |
124 | sprintf(outstr, "%d", innum); |
124 | sprintf(outstr, "%d", innum); |
125 | } |
125 | } |
126 | else if(zeronum == 4) |
126 | else if(zeronum == 4) |
127 | { |
127 | { |
128 | if(innum < 10) |
128 | if(innum < 10) |
129 | sprintf(outstr, "0000%d", innum); |
129 | sprintf(outstr, "0000%d", innum); |
130 | else if( (innum >= 10) && (innum < 100) ) |
130 | else if( (innum >= 10) && (innum < 100) ) |
131 | sprintf(outstr, "000%d", innum); |
131 | sprintf(outstr, "000%d", innum); |
132 | else if( (innum >= 100) && (innum < 1000) ) |
132 | else if( (innum >= 100) && (innum < 1000) ) |
133 | sprintf(outstr, "00%d", innum); |
133 | sprintf(outstr, "00%d", innum); |
134 | else if( (innum >= 1000) && (innum < 10000) ) |
134 | else if( (innum >= 1000) && (innum < 10000) ) |
135 | sprintf(outstr, "0%d", innum); |
135 | sprintf(outstr, "0%d", innum); |
136 | else if( (innum >= 10000) && (innum < 100000) ) |
136 | else if( (innum >= 10000) && (innum < 100000) ) |
137 | sprintf(outstr, "%d", innum); |
137 | sprintf(outstr, "%d", innum); |
138 | } |
138 | } |
139 | else if(zeronum == 5) |
139 | else if(zeronum == 5) |
140 | { |
140 | { |
141 | if(innum < 10) |
141 | if(innum < 10) |
142 | sprintf(outstr, "00000%d", innum); |
142 | sprintf(outstr, "00000%d", innum); |
143 | else if( (innum >= 10) && (innum < 100) ) |
143 | else if( (innum >= 10) && (innum < 100) ) |
144 | sprintf(outstr, "0000%d", innum); |
144 | sprintf(outstr, "0000%d", innum); |
145 | else if( (innum >= 100) && (innum < 1000) ) |
145 | else if( (innum >= 100) && (innum < 1000) ) |
146 | sprintf(outstr, "000%d", innum); |
146 | sprintf(outstr, "000%d", innum); |
147 | else if( (innum >= 1000) && (innum < 10000) ) |
147 | else if( (innum >= 1000) && (innum < 10000) ) |
148 | sprintf(outstr, "00%d", innum); |
148 | sprintf(outstr, "00%d", innum); |
149 | else if( (innum >= 10000) && (innum < 100000) ) |
149 | else if( (innum >= 10000) && (innum < 100000) ) |
150 | sprintf(outstr, "0%d", innum); |
150 | sprintf(outstr, "0%d", innum); |
151 | else if( (innum >= 100000) && (innum < 1000000) ) |
151 | else if( (innum >= 100000) && (innum < 1000000) ) |
152 | sprintf(outstr, "%d", innum); |
152 | sprintf(outstr, "%d", innum); |
153 | } |
153 | } |
154 | } |
154 | } |
155 | 155 | ||
156 | void TimeEstimate(clock_t stopw0, time_t time0, float progress, char *retEstim, int offset) |
156 | void TimeEstimate(clock_t stopw0, time_t time0, float progress, char *retEstim, int offset) |
157 | { |
157 | { |
158 | // Calculate the remaining time |
158 | // Calculate the remaining time |
159 | clock_t clkt1; |
159 | clock_t clkt1; |
160 | char ctemp[512]; |
160 | char ctemp[512]; |
161 | 161 | ||
162 | clkt1 = clock() - stopw0; |
162 | clkt1 = clock() - stopw0; |
163 | if(DBGSIG) printf("TimeEstimate(): Startclock = %d, Midclock (%f) = %f (%d), starttime = %d, curtime = %d\n", (int)stopw0, progress, (float)clkt1/CLOCKS_PER_SEC, (int)clkt1, (int)time0, (int)time(NULL)); |
163 | if(DBGSIG) printf("TimeEstimate(): Startclock = %d, Midclock (%f) = %f (%d), starttime = %d, curtime = %d\n", (int)stopw0, progress, (float)clkt1/CLOCKS_PER_SEC, (int)clkt1, (int)time0, (int)time(NULL)); |
164 | GetTime((int)(100.*((float)clkt1/CLOCKS_PER_SEC)/progress+(int)time0+offset), ctemp); |
164 | GetTime((int)(100.*((float)clkt1/CLOCKS_PER_SEC)/progress+(int)time0+offset), ctemp); |
165 | sprintf(retEstim, "Estimated end time: %s", ctemp); |
165 | sprintf(retEstim, "Estimated end time: %s", ctemp); |
166 | } |
166 | } |
167 | 167 | ||
168 | void TimeEstimateNew(int nr, clock_t stopw0, time_t time0, int rX, int rY, int rZ, int xWait, int yWait, int zWait, char *retEstim) |
168 | void TimeEstimateNew(int nr, clock_t stopw0, time_t time0, int rX, int rY, int rZ, int xWait, int yWait, int zWait, char *retEstim) |
169 | { |
169 | { |
170 | clock_t clkt1; |
170 | clock_t clkt1; |
171 | char ctemp[512]; |
171 | char ctemp[512]; |
172 | double timeSec; |
172 | double timeSec; |
173 | double averMeasTime; |
173 | double averMeasTime; |
174 | 174 | ||
175 | clkt1 = clock() - stopw0; |
175 | clkt1 = clock() - stopw0; |
176 | if(nr == -1) |
176 | if(nr == -1) |
177 | return; |
177 | return; |
178 | else if(nr == 0) |
178 | else if(nr == 0) |
179 | averMeasTime = (double)clkt1/CLOCKS_PER_SEC; |
179 | averMeasTime = (double)clkt1/CLOCKS_PER_SEC; |
180 | else |
180 | else |
181 | averMeasTime = (averMeasTime + (double)clkt1/CLOCKS_PER_SEC)/2.0; |
181 | averMeasTime = (averMeasTime + (double)clkt1/CLOCKS_PER_SEC)/2.0; |
182 | 182 | ||
183 | // calculate the time of one row |
183 | // calculate the time of one row |
184 | timeSec = rX*(xWait + averMeasTime); |
184 | timeSec = rX*(xWait + averMeasTime); |
185 | // calculate the time of a surface scan |
185 | // calculate the time of a surface scan |
186 | timeSec = timeSec + rY*(timeSec + yWait); |
186 | timeSec = timeSec + rY*(timeSec + yWait); |
187 | // calculate the time of a zscan |
187 | // calculate the time of a zscan |
188 | if(rZ == 1) |
188 | if(rZ == 1) |
189 | timeSec = timeSec + zWait; |
189 | timeSec = timeSec + zWait; |
190 | else |
190 | else |
191 | timeSec = timeSec + rZ*(timeSec + zWait); |
191 | timeSec = timeSec + rZ*(timeSec + zWait); |
192 | 192 | ||
193 | GetTime((int)timeSec+(int)time0, ctemp); |
193 | GetTime((int)timeSec+(int)time0, ctemp); |
194 | sprintf(retEstim, "Estimated end time: %s", ctemp); |
194 | sprintf(retEstim, "Estimated end time: %s", ctemp); |
195 | 195 | ||
196 | printf("TimeEstimateNew(): Average time of measurement = %lf, Measurement time = %lf, Finishing time = %s\n", averMeasTime, timeSec, ctemp); |
196 | printf("TimeEstimateNew(): Average time of measurement = %lf, Measurement time = %lf, Finishing time = %s\n", averMeasTime, timeSec, ctemp); |
197 | } |
197 | } |
198 | 198 | ||
199 | void NormateSet(int file, int nrpoint, double *min, double *max, double *setCount, double *setAcc) |
199 | void NormateSet(int file, int nrpoint, double *min, double *max, double *setCount, double *setAcc) |
200 | { |
200 | { |
201 | int count = 0; |
201 | int count = 0; |
202 | 202 | ||
203 | // Find minimal value in set and subtract the offset |
203 | // Find minimal value in set and subtract the offset |
204 | *min = TMath::MinElement(nrpoint, setAcc); |
204 | *min = TMath::MinElement(nrpoint, setAcc); |
205 | for(int i = 0; i < nrpoint; i++) |
205 | for(int i = 0; i < nrpoint; i++) |
206 | setAcc[i] -= *min; |
206 | setAcc[i] -= *min; |
207 | 207 | ||
208 | // Find maximal value in set and normate to 1 |
208 | // Find maximal value in set and normate to 1 |
209 | *max = TMath::MaxElement(nrpoint, setAcc); |
209 | *max = TMath::MaxElement(nrpoint, setAcc); |
210 | for(int i = 0; i < nrpoint; i++) |
210 | for(int i = 0; i < nrpoint; i++) |
211 | { |
211 | { |
212 | count = file - nrpoint + i; |
212 | count = file - nrpoint + i; |
213 | setCount[count] = setAcc[i]/(*max); |
213 | setCount[count] = setAcc[i]/(*max); |
214 | if(DBGSIG) printf("NormateSet(): Integral check 2 (i=%d,za=%d,j=%d): %lf\t\%lf\n", count, i, nrpoint, setCount[count], setAcc[i]/(*max)); |
214 | if(DBGSIG) printf("NormateSet(): Integral check 2 (i=%d,za=%d,j=%d): %lf\t\%lf\n", count, i, nrpoint, setCount[count], setAcc[i]/(*max)); |
215 | } |
215 | } |
216 | } |
216 | } |
217 | 217 | ||
218 | // Estimate the next point, depending on the set of points beforehand (least squares fit) and return the error |
218 | // Estimate the next point, depending on the set of points beforehand (least squares fit) and return the error |
219 | double PointEstimate(int nrp, double *points) |
219 | double PointEstimate(int nrp, double *points) |
220 | { |
220 | { |
221 | double accx = 0, accy = 0, accxy = 0, accx2 = 0; |
221 | double accx = 0, accy = 0, accxy = 0, accx2 = 0; |
222 | double A, B; |
222 | double A, B; |
223 | double esty; |
223 | double esty; |
224 | 224 | ||
- | 225 | // printf("PointEstimate points: "); |
|
225 | for(int i = 0; i < nrp; i++) |
226 | for(int i = 0; i < nrp; i++) |
226 | { |
227 | { |
- | 228 | // printf("[%lf,%lf], ", points[2*i], points[2*i+1]); |
|
227 | accx += points[2*i]; |
229 | accx += points[2*i]; |
228 | accy += points[2*i+1]; |
230 | accy += points[2*i+1]; |
229 | accxy += points[2*i]*points[2*i+1]; |
231 | accxy += points[2*i]*points[2*i+1]; |
230 | accx2 += points[2*i]*points[2*i]; |
232 | accx2 += points[2*i]*points[2*i]; |
231 | } |
233 | } |
- | 234 | // printf("\n"); |
|
232 | 235 | ||
233 | A = (accx2*accy - accx*accxy)/(nrp*accx2 - accx*accx); |
236 | A = (accx2*accy - accx*accxy)/(nrp*accx2 - accx*accx); |
234 | B = (nrp*accxy - accx*accy)/(nrp*accx2 - accx*accx); |
237 | B = (nrp*accxy - accx*accy)/(nrp*accx2 - accx*accx); |
- | 238 | ||
- | 239 | // printf("Fiting function = %lf + %lf*x\n", A, B); |
|
235 | 240 | ||
236 | esty = A + B*points[2*nrp]; |
241 | esty = A + B*points[2*nrp]; |
237 | 242 | ||
238 | if(DBGSIG) printf("PointEstimate(): A = %lf, B = %lf, estimate = %lf, real = %lf, error = %lf\n", A, B, esty, points[2*nrp+1], abs(esty - points[2*nrp+1])/points[2*nrp+1]); |
243 | if(DBGSIG) printf("PointEstimate(): A = %lf, B = %lf, estimate = %lf, real = %lf, error = %lf\n", A, B, esty, points[2*nrp+1], abs(esty - points[2*nrp+1])/points[2*nrp+1]); |
239 | 244 | ||
240 | return abs(esty - points[2*nrp+1])/points[2*nrp+1]; |
245 | return abs(esty - points[2*nrp+1])/points[2*nrp+1]; |
241 | } |
246 | } |
242 | 247 | ||
243 | // Separate functions ----------------------------------------- |
248 | // Separate functions ----------------------------------------- |
244 | 249 |