57 if((*a1).val<(*a2).val)
return -1;
58 else if((*a1).val>(*a2).val)
return 1;
69 if((*a1).val>(*a2).val)
return -1;
70 else if((*a1).val<(*a2).val)
return 1;
81 if((*a1).val<(*a2).val)
return -1;
82 else if((*a1).val>(*a2).val)
return 1;
93 if((*a1).val>(*a2).val)
return -1;
94 else if((*a1).val<(*a2).val)
return 1;
105 if((*a1).val<(*a2).val)
return -1;
106 else if((*a1).val>(*a2).val)
return 1;
117 if((*a1).val>(*a2).val)
return -1;
118 else if((*a1).val<(*a2).val)
return 1;
136 data[i].
val=in_vec[i];
145 out_vec[i] = data[i].
val;
147 new_idices[i] = data[i].
idx;
166 data[i].
val=in_vec[i];
175 out_vec[i] = data[i].
val;
177 new_idices[i] = data[i].
idx;
196 data[i].
val=in_vec[i];
205 out_vec[i] = data[i].
val;
207 new_idices[i] = data[i].
idx;
214 float_complex* in_vec,
215 float_complex* out_vec,
220 int i, start_idx, end_idx, sFlag, eFlag;
222 const float tol = 0.0001f;
223 float* vec_real, *vec_imag;
228 vec_real =
malloc1d(len*
sizeof(
float));
229 vec_imag =
malloc1d(len*
sizeof(
float));
231 vec_real[i] = crealf(in_vec[i]);
232 sortf(vec_real, vec_real, ind, len, descendFLAG);
234 vec_imag[i] = cimagf(in_vec[ind[i]]);
239 start_idx = end_idx = -1;
240 for(i=0; i<len-1; i++){
242 if(fabsf(vec_real[i]-vec_real[i+1])<tol){
254 if(sFlag && i==len-2){
260 if( (sFlag) && (eFlag) ){
261 sortf(&vec_imag[start_idx], &vec_imag[start_idx], NULL, end_idx-start_idx+1, descendFLAG);
262 sFlag = 0; eFlag = 0;
268 out_vec[i] = cmplxf(vec_real[i], vec_imag[i]);
278 double_complex* in_vec,
279 double_complex* out_vec,
284 int i, start_idx, end_idx, sFlag, eFlag;
286 const double tol = 0.00001;
287 double* vec_real, *vec_imag;
292 vec_real =
malloc1d(len*
sizeof(
double));
293 vec_imag =
malloc1d(len*
sizeof(
double));
295 vec_real[i] = creal(in_vec[i]);
296 sortd(vec_real, vec_real, ind, len, descendFLAG);
298 vec_imag[i] = cimag(in_vec[ind[i]]);
303 start_idx = end_idx = -1;
304 for(i=0; i<len-1; i++){
306 if(fabs(vec_real[i]-vec_real[i+1])<tol){
318 if(sFlag && i==len-2){
324 if( (sFlag) && (eFlag) ){
325 sortd(&vec_imag[start_idx], &vec_imag[start_idx], NULL, end_idx-start_idx+1, descendFLAG);
326 sFlag = 0; eFlag = 0;
332 out_vec[i] = cmplx(vec_real[i], vec_imag[i]);
342 double_complex* in_vec,
343 double_complex* out_vec,
352 sortz(in_vec, out_vec, len, 0);
357 for(i=0; i<len-1-realCount; i++){
358 if(fabs(cimag(out_vec[i])) < 0.00001 ){
361 memmove(&out_vec[i], &out_vec[i+1], (len-i-1)*
sizeof(double_complex));
362 out_vec[len-1] = tmp;
381 float* grid_xyz, *target_xyz;
382 float rcoselev, max_val, current_val;
385 grid_xyz =
malloc1d(nGrid*3*
sizeof(
float));
386 target_xyz =
malloc1d(nTarget*3*
sizeof(
float));
388 for(i=0; i<nGrid; i++){
389 grid_xyz[i*3+2] = sinf(grid_dirs[i*2+1]*
SAF_PI/180.0f);
390 rcoselev = cosf( grid_dirs[i*2+1]*
SAF_PI/180.0f);
391 grid_xyz[i*3] = rcoselev * cosf(grid_dirs[i*2]*
SAF_PI/180.0f);
392 grid_xyz[i*3+1] = rcoselev * sinf(grid_dirs[i*2]*
SAF_PI/180.0f);
394 for(i=0; i<nTarget; i++){
395 target_xyz[i*3+2] = sinf(target_dirs[i*2+1]*
SAF_PI/180.0f);
396 rcoselev = cosf(target_dirs[i*2+1]*
SAF_PI/180.0f);
397 target_xyz[i*3] = rcoselev * cosf(target_dirs[i*2]*
SAF_PI/180.0f);
398 target_xyz[i*3+1] = rcoselev * sinf(target_dirs[i*2]*
SAF_PI/180.0f);
402 for(i=0; i<nGrid; i++){
403 grid_xyz[i*3+2] = sinf(grid_dirs[i*2+1]);
404 rcoselev = cosf(grid_dirs[i*2+1]);
405 grid_xyz[i*3] = rcoselev * cosf(grid_dirs[i*2]);
406 grid_xyz[i*3+1] = rcoselev * sinf(grid_dirs[i*2]);
408 for(i=0; i<nTarget; i++){
409 target_xyz[i*3+2] = sinf(target_dirs[i*2+1]);
410 rcoselev = cosf(target_dirs[i*2+1]);
411 target_xyz[i*3] = rcoselev * cosf(target_dirs[i*2]);
412 target_xyz[i*3+1] = rcoselev * sinf(target_dirs[i*2]);
417 for(i=0; i<nTarget; i++){
419 for(j=0; j<nGrid; j++){
420 current_val = grid_xyz[j*3] * target_xyz[i*3] +
421 grid_xyz[j*3+1] * target_xyz[i*3+1] +
422 grid_xyz[j*3+2] * target_xyz[i*3+2];
423 if(current_val > max_val)
425 if(current_val>max_val){
427 max_val = current_val;
429 angle_diff[i] = acosf(max_val);
435 if(dirs_closest!=NULL){
436 for(i=0; i<nTarget; i++){
437 dirs_closest[i*2] = grid_dirs[idx_closest[i]*2];
438 dirs_closest[i*2+1] = grid_dirs[idx_closest[i]*2+1];
448 float* grid_dirs_xyz,
450 float* target_dirs_xyz,
453 float* dirs_xyz_closest,
458 float max_val, current_val;
461 for(i=0; i<nTarget; i++){
463 for(j=0; j<nGrid; j++){
464 current_val = grid_dirs_xyz[j*3] * target_dirs_xyz[i*3] +
465 grid_dirs_xyz[j*3+1] * target_dirs_xyz[i*3+1] +
466 grid_dirs_xyz[j*3+2] * target_dirs_xyz[i*3+2];
467 if(current_val > max_val)
469 if(current_val>max_val){
471 max_val = current_val;
473 angle_diff[i] = acosf(max_val);
479 if(dirs_xyz_closest!=NULL){
480 for(i=0; i<nTarget; i++){
481 dirs_xyz_closest[i*3] = grid_dirs_xyz[idx_closest[i]*3];
482 dirs_xyz_closest[i*3+1] = grid_dirs_xyz[idx_closest[i]*3+1];
483 dirs_xyz_closest[i*3+2] = grid_dirs_xyz[idx_closest[i]*3+2];
#define SAF_PI
pi constant (single precision)
void sortf(float *in_vec, float *out_vec, int *new_idices, int len, int descendFLAG)
Sort a vector of floating-point values into ascending/decending order (optionally returning the new i...
void cmplxPairUp(double_complex *in_vec, double_complex *out_vec, int len)
Pairs up complex numbers and sorts them in ascending order based on their real parts first,...
void sortd(double *in_vec, double *out_vec, int *new_idices, int len, int descendFLAG)
Sort a vector of double floating-point values into ascending/decending order (optionally returning th...
void sortc(float_complex *in_vec, float_complex *out_vec, int len, int descendFLAG)
Sort a vector of complex floating-point values into ascending/decending order.
void sortz(double_complex *in_vec, double_complex *out_vec, int len, int descendFLAG)
Sort a vector of complex double floating-point values into ascending/ decending order.
void sorti(int *in_vec, int *out_vec, int *new_idices, int len, int descendFLAG)
Sort a vector of integer values into ascending/decending order (optionally returning the new indices ...
void findClosestGridPointsCartesian(float *grid_dirs_xyz, int nGrid, float *target_dirs_xyz, int nTarget, int *idx_closest, float *dirs_xyz_closest, float *angle_diff)
Finds indicies into "grid_dirs_xyz" that are the closest to "target dirs_xyz".
void findClosestGridPoints(float *grid_dirs, int nGrid, float *target_dirs, int nTarget, int degFLAG, int *idx_closest, float *dirs_closest, float *angle_diff)
Finds indicies into "grid_dirs" that are the closest to "target dirs".
void * malloc1d(size_t dim1_data_size)
1-D malloc (same as malloc, but with error checking)
Main header for the utilities module (SAF_UTILITIES_MODULE)
static int cmp_desc_float(const void *a, const void *b)
Helper function for a sorting vector of floats using 'qsort' in decending order.
static int cmp_asc_int(const void *a, const void *b)
Helper function for sorting a vector of integers using 'qsort' in ascending order.
static int cmp_desc_int(const void *a, const void *b)
Helper function for a sorting vector of integers using 'qsort' in decending order.
static int cmp_asc_double(const void *a, const void *b)
Helper function for a sorting vector of doubles using 'qsort' in ascending order.
static int cmp_desc_double(const void *a, const void *b)
Helper function for a sorting vector of doubles using 'qsort' in decending order.
static int cmp_asc_float(const void *a, const void *b)
Helper function for a sorting vector of floats using 'qsort' in ascending order.
Helper struct for sorting a vector of doubles using 'qsort'.
int idx
corresponding index, so that the sorting functions may also return the sorted indexes if required
Helper struct for sorting a vector of floats using 'qsort'.
int idx
corresponding index, so that the sorting functions may also return the sorted indexes if required
Helper struct for sorting a vector of integers using 'qsort'.
int idx
corresponding index, so that the sorting functions may also return the sorted indexes if required