Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilia Platone committed Aug 6, 2022
1 parent 040d78d commit d4c82b2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 54 deletions.
20 changes: 2 additions & 18 deletions dsp/align.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,14 @@
#include "dsp.h"
#include <time.h>

int dsp_qsort_double_desc (const void *arg1, const void *arg2)
static int dsp_qsort_double_desc (const void *arg1, const void *arg2)
{
double* a1 = (double*)arg1;
double* a2 = (double*)arg2;
return ((*a1) < (*a2) ? 1 : -1);
}

int dsp_qsort_double_asc (const void *arg1, const void *arg2)
{
double* a1 = (double*)arg1;
double* a2 = (double*)arg2;
return ((*a1) > (*a2) ? 1 : -1);
}

int dsp_qsort_star_diameter_desc(const void *arg1, const void *arg2)
static int dsp_qsort_star_diameter_desc(const void *arg1, const void *arg2)
{
dsp_star* a = (dsp_star*)arg1;
dsp_star* b = (dsp_star*)arg2;
Expand All @@ -44,15 +37,6 @@ int dsp_qsort_star_diameter_desc(const void *arg1, const void *arg2)
return -1;
}

int dsp_qsort_star_diameter_asc(const void *arg1, const void *arg2)
{
dsp_star* a = (dsp_star*)arg1;
dsp_star* b = (dsp_star*)arg2;
if(a->diameter > b->diameter)
return 1;
return -1;
}

static double calc_match_score(dsp_triangle t1, dsp_triangle t2, dsp_align_info align_info)
{
int d = 0;
Expand Down
32 changes: 0 additions & 32 deletions dsp/dsp.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1512,38 +1512,6 @@ DLL_EXPORT dsp_triangle dsp_align_calc_triangle(dsp_star* stars);
*/
DLL_EXPORT int dsp_align_get_offset(dsp_stream_p ref, dsp_stream_p to_align, double tolerance, double target_score);

/**
* \brief Callback function for qsort for double type ascending ordering
* \param arg1 the first comparison element
* \param arg2 the second comparison element
* \return 1 if arg1 is greater than arg2, -1 if arg2 is greater than arg1
*/
DLL_EXPORT int dsp_qsort_double_asc (const void *arg1, const void *arg2);

/**
* \brief Callback function for qsort for double type descending ordering
* \param arg1 the first comparison element
* \param arg2 the second comparison element
* \return 1 if arg2 is greater than arg1, -1 if arg1 is greater than arg2
*/
DLL_EXPORT int dsp_qsort_double_desc (const void *arg1, const void *arg2);

/**
* \brief Callback function for qsort for dsp_star ascending ordering by their diameters
* \param arg1 the first comparison element
* \param arg2 the second comparison element
* \return 1 if arg1 diameter is greater than arg2, -1 if arg2 diameter is greater than arg1
*/
DLL_EXPORT int dsp_qsort_star_diameter_asc (const void *arg1, const void *arg2);

/**
* \brief Callback function for qsort for dsp_star descending ordering by their diameters
* \param arg1 the first comparison element
* \param arg2 the second comparison element
* \return 1 if arg2 diameter is greater than arg1, -1 if arg1 diameter is greater than arg2
*/
DLL_EXPORT int dsp_qsort_star_diameter_desc (const void *arg1, const void *arg2);

/**\}*/
/// \defgroup dsp_FitsExtensions
#include <fits_extensions.h>
Expand Down
17 changes: 13 additions & 4 deletions vlbi/astro.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@

static double SPEED_MEAN = LIGHTSPEED;

static int vlbi_qsort_star_diameter_desc(const void *arg1, const void *arg2)
{
dsp_star* a = (dsp_star*)arg1;
dsp_star* b = (dsp_star*)arg2;
if(a->diameter < b->diameter)
return 1;
return -1;
}

double vlbi_astro_mean_speed(double speed)
{
if(speed > 0.0) {
Expand Down Expand Up @@ -150,7 +159,7 @@ dsp_stream_p vlbi_astro_load_spectrum(char *filename)
dsp_stream_alloc_buffer(spectrum, 1);
free(line.center.location);
free(buf);
qsort(spectrum->stars, (size_t)spectrum->stars_count, sizeof(dsp_star), dsp_qsort_star_diameter_desc);
qsort(spectrum->stars, (size_t)spectrum->stars_count, sizeof(dsp_star), vlbi_qsort_star_diameter_desc);
return spectrum;
}

Expand Down Expand Up @@ -220,10 +229,10 @@ dsp_stream_p vlbi_astro_create_reference_catalog(dsp_stream_p *catalog, int cata
dsp_stream_alloc_buffer(stream, stream->len);
for(int c = 0; c < catalog_size; c++) {
dsp_stream_p element = catalog[c];
qsort(element->stars, (size_t)element->stars_count, sizeof(dsp_star), dsp_qsort_star_diameter_desc);
qsort(element->stars, (size_t)element->stars_count, sizeof(dsp_star), vlbi_qsort_star_diameter_desc);
for(int s = 0; s < element->stars_count; s++)
dsp_stream_add_star(stream, element->stars[s]);
qsort(stream->stars, (size_t)stream->stars_count, sizeof(dsp_star), dsp_qsort_star_diameter_desc);
qsort(stream->stars, (size_t)stream->stars_count, sizeof(dsp_star), vlbi_qsort_star_diameter_desc);
}
return stream;
}
Expand Down Expand Up @@ -270,7 +279,7 @@ void vlbi_astro_scan_spectrum(dsp_stream_p stream, int sample_size)
}
}
free(star.center.location);
qsort(stream->stars, (size_t)stream->stars_count, sizeof(dsp_star), dsp_qsort_star_diameter_desc);
qsort(stream->stars, (size_t)stream->stars_count, sizeof(dsp_star), vlbi_qsort_star_diameter_desc);
}

dsp_align_info vlbi_astro_align_spectra(dsp_stream_p spectrum, dsp_stream_p catalog, int max_lines, double decimals, double min_score)
Expand Down

0 comments on commit d4c82b2

Please sign in to comment.