142 #define STATIC static
218 for (samp = sc_evolution->
num_samples - 1 ; samp > -1 ; samp--) {
236 int const number_of_scans,
239 const uint16 ss_cp_mode[]
317 static double const arcsec_to_rad =
PGS_PI/(180.0*3600.0);
326 int last_qcount = INT_MAX;
329 static char filefunc[] = __FILE__
", GEO_prepare_ancil_data";
332 typedef double double3_t[3];
333 static double3_t *sc_position;
334 static double3_t *sc_velocity;
335 static double3_t *sc_attit;
336 static double3_t *sc_xyzRotRates;
339 static ancil_flags_t *ancil_flags;
342 static int firstRun = 1;
346 sc_position = (double3_t*) calloc(
MAX_SCAN_NUMBER*2,
sizeof(double3_t));
347 sc_velocity = (double3_t*) calloc(
MAX_SCAN_NUMBER*2,
sizeof(double3_t));
349 sc_xyzRotRates = (double3_t*) calloc(
MAX_SCAN_NUMBER*2,
sizeof(double3_t));
351 ancil_flags = (ancil_flags_t*) calloc(
QFL_IDXS,
sizeof(ancil_flags_t));
359 sc_ancillary_data==
NULL || ss_cp_mode==
NULL)
361 sprintf(msgbuf,
"number_of_scans:%d, params:%p, ancil_scale_factors:%p "
362 "ss_cp_mode:%p", number_of_scans, (
void*)
params,
363 (
void*)sc_ancillary_data, (
void*)ss_cp_mode);
368 if(number_of_scans==0)
369 return PGS_S_SUCCESS;
377 if (strcmp(
params->spacecraft_ID,
"Aqua") == 0) {
379 return PGS_S_SUCCESS;
395 double pos2_sum=0.0, vel2_sum=0.0, ang_mom2_sum=0.0;
396 double pos_mag, vel_mag, ang_mag;
400 for(eci = 0; eci < 3; eci++)
403 if(sc_ancillary_data[pack].attit_angvel[
scan][eci] <
404 params->attit_valid_params.att_valid_range[0] ||
405 params->attit_valid_params.att_valid_range[1] <
408 ancil_flags[
ATT_IDX][cmb] |= PGSd_NO_DATA;
413 sc_position[cmb][eci] =
414 (
double)sc_ancillary_data[pack].posvel[
scan][eci]
415 *
params->ancil_params.ancil_scale_factors.S_position;
416 sc_velocity[cmb][eci] =
417 (
double)sc_ancillary_data[pack].
posvel[
scan][eci+3]
418 *
params->ancil_params.ancil_scale_factors.S_velocity;
420 (
double)sc_ancillary_data[pack].attit_angvel[
scan][eci]
421 *
params->ancil_params.ancil_scale_factors.S_attitude;
422 sc_xyzRotRates[cmb][eci] =
424 *
params->ancil_params.ancil_scale_factors.S_angvel;
426 pos2_sum += sc_position[cmb][eci]* sc_position[cmb][eci];
427 vel2_sum += sc_velocity[cmb][eci]* sc_velocity[cmb][eci];
430 if(sc_position[cmb][eci] <
431 params->orbit_valid_params.position_abs_limit[0])
436 else if(
params->orbit_valid_params.position_abs_limit[1] <
437 sc_position[cmb][eci])
443 if(sc_velocity[cmb][eci] <
444 params->orbit_valid_params.velocity_abs_limit[0])
449 else if(
params->orbit_valid_params.velocity_abs_limit[1] <
450 sc_velocity[cmb][eci])
456 if(sc_attit[cmb][eci] <
457 params->attit_valid_params.attitude_abs_limit[0])
462 else if(
params->attit_valid_params.attitude_abs_limit[1] <
469 if(sc_xyzRotRates[cmb][eci] <
470 params->attit_valid_params.angvel_abs_limit[0])
475 else if(
params->attit_valid_params.angvel_abs_limit[1] <
476 sc_xyzRotRates[cmb][eci])
484 GEO_vec_mul3(sc_position[cmb], sc_velocity[cmb], ang_mom);
486 for(eci = 0; eci < 3; eci++)
487 ang_mom2_sum += ang_mom[eci]*ang_mom[eci];
489 pos_mag = sqrt(pos2_sum);
490 vel_mag = sqrt(vel2_sum);
491 ang_mag = sqrt(ang_mom2_sum);
494 if(pos_mag < params->orbit_valid_params.position_mag_limit[0])
499 else if(
params->orbit_valid_params.position_mag_limit[1] < pos_mag)
505 if(vel_mag < params->orbit_valid_params.velocity_mag_limit[0])
510 else if(
params->orbit_valid_params.velocity_mag_limit[1] < vel_mag)
516 if(ang_mag < params->orbit_valid_params.ang_mom_limit[0])
521 else if(
params->orbit_valid_params.ang_mom_limit[1] < ang_mag)
527 if(ang_mom[2] <
params->orbit_valid_params.ang_mom_z_limit[0])
532 else if(
params->orbit_valid_params.ang_mom_z_limit[1] < ang_mom[2])
553 PGSt_IO_L0_SecPktHdrEOS_AM AM_packet;
558 sizeof(AM_packet.scTime));
571 if (PGS_TD_EOSAMtoTAI(AM_packet.scTime, &time_stamp[cmb])
575 sprintf(msgbuf,
"PGS_TD_EOSAMtoTAI() for scan:%d pack:%d",
scan, pack);
583 delta = time_stamp[cmb] -
587 if(qcount[cmb] < last_qcount)
591 delta = time_stamp[cmb] -
604 if(
params->orbit_valid_params.eph_max_short_gap <
delta)
618 if(
params->attit_valid_params.att_max_short_gap <
delta)
634 last_qcount = qcount[cmb];
642 for (eci = 0; eci < 3; eci++)
646 sc_position[cmb][eci];
648 sc_velocity[cmb][eci];
654 sc_xyzRotRates[cmb][eci];
676 for(samp=0; samp < sc_evolution->
num_samples-1; samp++)
683 for(eci = 0; eci < 3; eci++)
689 if(
params->orbit_valid_params.orbit_consistency < del)
706 for(eci = 0; eci < 3; eci++)
720 params->attit_valid_params.attitude_del_limit *
delta ||
722 params->attit_valid_params.angvel_del_limit *
delta ||
724 params->attit_valid_params.attit_consistency *
delta)
738 for(samp=0; samp < sc_evolution->
num_samples; samp++)
739 for(eci = 0; eci < 3; eci++)
742 return PGS_S_SUCCESS;
748 PGSt_integer numValues,
750 PGSt_double target_time,
751 const PGSt_double offsets[],
755 PGSt_scTagInfo *scTagInfo
855 static double position_coef[3][
CUBIC]={0.0};
857 static int attlo, atthi;
858 static char ea_source[PGSd_PC_LINE_LENGTH_MAX]=
"";
859 PGSt_SMF_status PGS_error_code = PGS_S_SUCCESS;
860 PGSt_SMF_status retval = PGS_S_SUCCESS;
861 PGSt_integer qualityFlags[
MAX_PADDED][2] = {0};
866 char msgbuf[PGS_SMF_MAX_MSGBUF_SIZE] =
"";
867 static char filefunc[] = __FILE__
", GEO_interp_ephemeris_attitude";
869 static const unsigned EPH_CRITERIA=(PGSd_NO_DATA|PGSd_PLATFORM_FATAL);
873 sample_quality ==
NULL || scTagInfo ==
NULL)
875 sprintf(msgbuf,
"sc_state = %p, offsets = %p, params=%p, \n"
876 "sample_quality=%p, scTagInfo = %p",
877 (
void *)sc_state, (
void *)offsets, (
void*)
params,
878 (
void*)sample_quality, (
void*)scTagInfo);
883 *sc_state = empty_sc;
886 if (ea_source[0]==
'\0') {
888 if (PGS_error_code!=PGS_S_SUCCESS) {
895 if(scTagInfo->eulerAngleOrder[0] < 0)
897 if (PGS_EPH_GetSpacecraftData(sc_evolution->
spacecraftTag,
"",
898 PGSe_TAG_SEARCH, scTagInfo) != PGS_S_SUCCESS)
900 modsmf(
MODIS_E_GEO,
"PGS_EPH_GetSpacecraftData()", filefunc);
908 if (PGS_error_code != PGS_S_SUCCESS &&
910 sprintf(msgbuf,
"GEO_check_ea_headers(%s)", asciiUTC);
917 sprintf(msgbuf,
"numValues: %ld", (
long)numValues);
923 return PGS_S_SUCCESS;
925 PGS_error_code = PGS_EPH_EphemAttit(sc_evolution->
spacecraftTag,
926 (PGSt_integer)numValues, asciiUTC, (PGSt_double*)offsets, PGS_TRUE,
927 PGS_TRUE, qualityFlags, positionECI, velocityECI, eulerAngles,
928 xyzRotRates, attitQuat);
930 if (PGS_error_code != PGS_S_SUCCESS &&
931 PGS_error_code != PGSEPH_W_BAD_EPHEM_VALUE)
933 if (PGS_error_code != PGSEPH_E_NO_SC_EPHEM_FILE)
939 sprintf(msgbuf,
"PGS_EPH_EphemAttit(%s)", asciiUTC);
948 for (samp = 0; samp < numValues; samp++)
949 sc_state[samp].position[0] = PGSd_GEO_ERROR_VALUE;
953 for (samp = 0; samp < numValues; samp++)
957 sc_state[samp].
time = target_time + offsets[samp];
958 for (
i = 0;
i < 3;
i++)
960 sc_state[samp].
position[
i] = positionECI[samp][
i];
961 sc_state[samp].
velocity[
i] = velocityECI[samp][
i];
963 sc_state[samp].
eulerAngles[0] = eulerAngles[samp][1];
964 sc_state[samp].
eulerAngles[1] = eulerAngles[samp][2];
965 sc_state[samp].
eulerAngles[2] = eulerAngles[samp][0];
966 if ( ((
unsigned)qualityFlags[samp][
ATT_IDX] |
967 (
unsigned)qualityFlags[samp][
EPH_IDX]) & EPH_CRITERIA )
968 sc_state[samp].
position[0] = PGSd_GEO_ERROR_VALUE;
969 sample_quality[samp][
ATT_IDX] =
970 (uint32)qualityFlags[samp][
ATT_IDX];
971 sample_quality[samp][
EPH_IDX] =
972 (uint32)qualityFlags[samp][
EPH_IDX];
987 memset(sample_quality, 0, numValues *
sizeof *sample_quality);
988 for (samp = 0; samp < numValues; samp++)
991 sc_state[samp].
time = target_time + offsets[samp];
1003 sc_state[samp].
time <
1007 for(eph = 0; sc_state[samp].
time >=
1019 sprintf(msgbuf,
"%.6f for samp = %d is more than %.3f "
1020 "seconds outside the range from %.6f to %.6f\n",
1021 sc_state[samp].
time, samp,
params->max_extrap,
1026 sc_state[samp].
position[0] = PGSd_GEO_ERROR_VALUE;
1027 sample_quality[samp][
EPH_IDX] |= PGSd_NO_DATA;
1033 for (eci = 0; retval==
SUCCESS && eci < 3; ++eci)
1041 position_coef[eci]);
1044 if (sc_state[samp].position[0] < PGSd_GEO_ERROR_VALUE)
1049 t_norm = (sc_state[samp].
time -
1053 for (eci = 0; retval==
SUCCESS && eci < 3; eci++)
1056 &sc_state[samp].position[eci]);
1057 sc_state[samp].
velocity[eci] = (position_coef[eci][1] +
1058 2*position_coef[eci][2]*t_norm +
1059 3*position_coef[eci][3]*t_norm*t_norm) /
1068 sc_state[samp].
position[0] = PGSd_GEO_ERROR_VALUE;
1071 if(sc_state[samp].time <= sc_evolution->sc_state[eph].
time)
1072 sample_quality[samp][
EPH_IDX] =
1075 <= sc_state[samp].
time)
1076 sample_quality[samp][
EPH_IDX] =
1080 sample_quality[samp][
EPH_IDX] =
1091 for(attlo = eph; attlo > -1 &&
1093 PGSd_NO_DATA; attlo--);
1094 for(atthi = eph + 1; atthi < sc_evolution->
num_samples &&
1096 PGSd_NO_DATA; atthi++);
1097 if(attlo < 0 || attlo >= sc_evolution->
num_samples)
1099 sample_quality[samp][
ATT_IDX] |= PGSd_NO_DATA;
1100 sc_state[samp].
position[0] = PGSd_GEO_ERROR_VALUE;
1104 if(attlo + 1 < atthi)
1106 t_norm = (sc_state[samp].
time -
1113 if(sc_state[samp].
time <=
1115 sample_quality[samp][
ATT_IDX] = sc_evolution->
1117 else if(sc_state[samp].
time >=
1119 sample_quality[samp][
ATT_IDX] = sc_evolution->
1123 sample_quality[samp][
ATT_IDX] = sc_evolution->
1126 qualityFlags[
ATT_IDX] | PGSd_INTERPOLATED_POINT;
1133 for (eci = 0; retval==
SUCCESS && eci < 3; eci++)
1144 for(efat = 0; efat <
QFL_IDXS; efat++)
1146 if(sample_quality[samp][efat] &&
1147 sample_quality[samp][efat] != PGSd_NO_DATA)
1149 if(sample_quality[samp][efat] & PGSd_NO_DATA-1)
1150 sample_quality[samp][efat] |=
EPH_DATA;