10 int const sample_number,
11 int const num_detectors,
13 double ecr_sc_sample_position[][3],
14 double ecr_sc_velocity[][3],
15 double T_inst2ecr[][3][3],
140 static PGSt_double equat=-1.0;
141 static PGSt_double polar=-1.0;
142 PGSt_double p_prime[3];
143 double p_prime_sq = 0.0;
144 PGSt_SMF_status PGS_error_code;
147 char msgbuf[128] =
"";
148 static char filefunc[] = __FILE__
", GEO_ellip_position";
156 sample_number < 0 || sample_number >=
MAX_PADDED ||
157 u_inst ==
NULL || ecr_sc_sample_position ==
NULL ||
158 ecr_sc_velocity ==
NULL || T_inst2ecr ==
NULL ||
159 ecr_sample_position ==
NULL || ellip_sample_position ==
NULL ||
160 sample_flags ==
NULL || sample_view_vec ==
NULL )
162 sprintf(msgbuf,
"scan:%d detectors:%d sample:%d u_inst:%p "
163 "ecr_sc_sample_position:%p ecr_sc_velocity:%p "
164 "T_inst2ecr:%p ecr_sample_position:%p "
165 "ellip_sample_position:%p sample_flags:%p "
166 "sample_view_vec:%p",
167 scan_number, num_detectors, sample_number, (
void *)u_inst,
168 (
void *)ecr_sc_sample_position, (
void *)ecr_sc_velocity,
169 (
void *)T_inst2ecr, (
void *)ecr_sample_position,
170 (
void *)ellip_sample_position, (
void *)sample_flags,
171 (
void *)sample_view_vec
178 if (ecr_sc_sample_position[sample_number][0] >= PGSd_GEO_ERROR_VALUE) {
179 for (det = 0; det < num_detectors; det++)
184 for (det=0; det<num_detectors ; det++)
185 sample_flags[det][sample_number] = 0;
189 PGS_error_code = PGS_CSC_GetEarthFigure(
EARTH_MODEL, &equat, &polar);
190 if (PGS_error_code!=PGS_S_SUCCESS)
199 p_prime[0] = ecr_sc_sample_position[sample_number][0] / equat;
200 p_prime[1] = ecr_sc_sample_position[sample_number][1] / equat;
201 p_prime[2] = ecr_sc_sample_position[sample_number][2] / polar;
203 for (ecr = 0; ecr < 3; ecr ++)
204 p_prime_sq += p_prime[ecr]*p_prime[ecr];
207 for (det = 0; det < num_detectors; det++)
209 PGSt_double u_prime[3];
213 double up_prod = 0.0;
214 double u_prime_sq = 0.0;
217 for (ecr = 0; ecr < 3; ecr ++) {
219 sample_view_vec[det][sample_number][ecr] = 0.0;
221 for (inst = 0; inst < 3; inst ++) {
222 sample_view_vec[det][sample_number][ecr] +=
223 T_inst2ecr[sample_number][ecr][inst]*u_inst[det][inst];
228 u_prime[0] = sample_view_vec[det][sample_number][0] / equat;
229 u_prime[1] = sample_view_vec[det][sample_number][1] / equat;
230 u_prime[2] = sample_view_vec[det][sample_number][2] / polar;
234 for (ecr = 0; ecr < 3; ecr ++) {
235 up_prod += u_prime[ecr]*p_prime[ecr];
236 u_prime_sq += u_prime[ecr]*u_prime[ecr];
239 up_prod_sq = up_prod * up_prod;
242 sqrt_arg = up_prod_sq - u_prime_sq*(p_prime_sq - 1.0);
243 if (sqrt_arg < 0.0 || up_prod>=0.0) {
248 else if ( (-up_prod - sqrt(sqrt_arg))/
DBL_MAX >= u_prime_sq)
257 PGSt_double altitude;
259 d = (-up_prod - sqrt(sqrt_arg)) / u_prime_sq;
262 for (ecr = 0; ecr < 3; ++ecr) {
263 sample_view_vec[det][sample_number][ecr] *= d;
264 ecr_sample_position[det][sample_number][ecr] =
265 ecr_sc_sample_position[sample_number][ecr] +
266 sample_view_vec[det][sample_number][ecr];
271 if (PGS_CSC_ECRtoGEO( ecr_sample_position[det][sample_number],
282 ellip_sample_position[det][sample_number][
HT_IDX] = 0.0;