9 static int compare_double(
13 const double *
left = (
double*)first;
14 const double *
right = (
double*)second;
166 const double TIME_ROLL_CORRECTION = 64000.0;
168 const int SIDEB_OFF = 2;
172 size_t best_low = 0, best_high = 0;
173 size_t num_times = 0, nnorm = 0, njump = 0;
179 double norm_sum, jump_sum, norm_sum2;
180 double jump_sum2, criterion,
phase;
183 double encoder_adjustment=0;
186 double gap_start = 0.0, gap_end = 0.0;
194 double mirr_del_limit, mirr_abs_limit[2];
195 char filefunc[] = __FILE__
", GEO_prepare_mirr_data";
196 char msgbuf[256] =
"";
199 if ((earth_encoder_times ==
NULL) || (view_sector_start ==
NULL) ||
202 sprintf(msgbuf,
"earth_encoder_times:%p, view_sector_start:%p,\n"
203 "mirr_params:%p, l1a_data:%p", (
void*)earth_encoder_times,
204 (
void*)view_sector_start, (
void*)mirr_params, (
void*)
l1a_data);
210 sprintf(msgbuf,
"num_scans:%d",
l1a_data->num_scans);
234 time_count[sample] = time_count[0];
242 (
double)((int32)earth_encoder_times[
scan][sample] -
243 (int32)earth_encoder_times[
scan][sample-1]);
244 if(time_count[sample] < 0.0)
246 time_count[sample] += TIME_ROLL_CORRECTION;
254 l1a_data->fill_values.EV_start_time)
256 sprintf(msgbuf,
"in scan %d",
scan);
263 impulse_enc[0] = (
double)view_sector_start[
scan]
266 vernier = (
int)view_sector_start[
scan]
284 mirr_abs_limit, encoder_flags+1) !=
SUCCESS
286 mirr_del_limit, encoder_flags) !=
SUCCESS)
288 sprintf(msgbuf,
"in scan %d",
scan);
295 impulse_enc[sample] = impulse_enc[sample-1] +
297 impulse_time[sample] = impulse_time[sample-1] +
298 time_count[sample-1]*mirr_params->
t_encoder;
302 sorted_times[num_times][0] =
305 sorted_times[num_times++][1] =
306 time_count[sample]*mirr_params->
t_encoder;
312 impulse_time[sample];
322 qsort(sorted_times, num_times,
sizeof(sorted_times[0]), compare_double);
323 cum_sum[0] = sorted_times[0][1];
324 cum_sum2[0] = cum_sum[0]*cum_sum[0];
325 for (low=1; low<num_times; low++)
327 cum_sum[low] = cum_sum[low-1] + sorted_times[low][1];
328 cum_sum2[low] = cum_sum2[low-1] +
329 sorted_times[low][1]*sorted_times[low][1];
335 for (low=0; low+2<num_times; low++)
337 for (high=low+1; high+2<num_times; high++)
339 if(sorted_times[low][0]+0.0175 < sorted_times[high][0] &&
340 sorted_times[high][0] < sorted_times[low][0]+0.0185)
343 nnorm = num_times - njump;
344 norm_sum = cum_sum[low] + cum_sum[num_times-1] - cum_sum[high];
345 jump_sum = cum_sum[high]-cum_sum[low];
347 cum_sum2[low] + cum_sum2[num_times-1] - cum_sum2[high];
348 jump_sum2 = cum_sum2[high]-cum_sum2[low];
353 criterion = (norm_sum2-norm_sum*norm_sum/(
double)nnorm) +
354 (jump_sum2-jump_sum*jump_sum/(
double)njump);
355 if (criterion < best)
361 norm_sum/(
double)nnorm - jump_sum/(
double)njump;
371 0.5*(sorted_times[best_low][0] + sorted_times[best_low+1][0]);
373 0.5*(sorted_times[best_high][0] + sorted_times[best_high+1][0]);
385 impulse_time[0] =
l1a_data->mirr_data[
scan].mirr_impulse_time[0];
386 impulse_enc[0] =
l1a_data->mirr_data[
scan].mirr_impulse_enc[0];
390 if (earth_encoder_times[
scan][sample] ==
391 l1a_data->fill_values.raw_mir_enc ||
392 earth_encoder_times[
scan][sample-1] ==
397 impulse_enc[sample] =
399 impulse_time[sample] = impulse_time[sample-1] +
400 factor*(
l1a_data->mirr_data[
scan].mirr_impulse_time[sample]-
408 impulse_time[sample] += encoder_adjustment;
409 time_count[sample-1] = (impulse_time[sample] -
410 impulse_time[sample-1]) / mirr_params->
t_encoder;
422 sprintf(msgbuf,
"in scan %d",
scan);
428 if( (encoder_flags[sample] ==
GOOD_DATA) ||
429 (sample && encoder_flags[sample-1] ==
GOOD_DATA) )
434 impulse_time[sample];
441 return PGS_S_SUCCESS;