From 089aff4337344276970924a3338a05cbb68a75e7 Mon Sep 17 00:00:00 2001 From: Mario Haustein Date: Sun, 21 Dec 2025 23:06:33 +0100 Subject: [PATCH 1/5] Fix format string --- rffit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rffit.c b/rffit.c index 30104f5..00a62fa 100644 --- a/rffit.c +++ b/rffit.c @@ -188,7 +188,7 @@ int identify_satellite_from_doppler(tle_array_t *tle_array, double rmsmax) } if (rmsname) { - printf("%05d: %.3f kHz %.6f MHz | %s\n", orb.satno, tle->name, rms, d.ffit/1000.0, tle->name); + printf("%05d: %.3f kHz %.6f MHz | %s\n", orb.satno, rms, d.ffit/1000.0, tle->name); } else { printf("%05d: %.3f kHz %.6f MHz\n", orb.satno, rms, d.ffit/1000.0); } From a602d5995ed302a56cc08e796d82eef3fc27b528 Mon Sep 17 00:00:00 2001 From: "Martin Herren (HB9FXX)" Date: Tue, 12 Nov 2024 23:49:10 +0100 Subject: [PATCH 2/5] [rfio] Remove unused vars Signed-off-by: Martin Herren (HB9FXX) --- rfio.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rfio.c b/rfio.c index 3b75583..6841b55 100644 --- a/rfio.c +++ b/rfio.c @@ -8,7 +8,7 @@ struct spectrogram read_spectrogram(char *prefix,int isub,int nsub,double f0,double df0,int nbin,double foff) { - int i,j,k,l,flag=0,status,msub,ibin,nadd,nbits=-32; + int i,j,k,l,status,msub,ibin,nadd,nbits=-32; char filename[128],header[256],nfd[32]; FILE *file; struct spectrogram s; @@ -18,7 +18,6 @@ struct spectrogram read_spectrogram(char *prefix,int isub,int nsub,double f0,dou double freq,samp_rate; float length; int nchan,dummy; - float s1,s2; // Open first file to get number of channels sprintf(filename,"%s_%06d.bin",prefix,isub); From 4766390ccb1666e48a08be150a03e7e78e8cd0c9 Mon Sep 17 00:00:00 2001 From: "Martin Herren (HB9FXX)" Date: Mon, 11 Nov 2024 07:56:25 +0100 Subject: [PATCH 3/5] [rfio] Add get_subs_from_datestrings() function This function allows to get start bin number and number of integrations for a set of .bin files given start and end date/time strings. Signed-off-by: Martin Herren (HB9FXX) --- rfio.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- rfio.h | 13 +++- 2 files changed, 188 insertions(+), 17 deletions(-) diff --git a/rfio.c b/rfio.c index 6841b55..8496838 100644 --- a/rfio.c +++ b/rfio.c @@ -1,10 +1,170 @@ +#define _XOPEN_SOURCE +#include "rfio.h" +#include "rftime.h" +#include "zscale.h" +#include +#include #include #include #include +#include #include -#include "rftime.h" -#include "rfio.h" -#include "zscale.h" + + +// Get the first and last bin number matching the prefix. There is no +// guarantee that the range is continous and there is no missing bin in +// the range. +int get_bin_range(char *prefix, int *first_bin, int *last_bin) { + DIR *dp; + struct dirent *ep; + + // Both, dirname and basename, don't handle static strings and can modifiy + // their argument. So make a copy and use a pointer to the result. + char dir[256]; + char base[256]; + strncpy(dir, prefix, 256); + strncpy(base, prefix, 256); + char *dir_p = dirname(dir); + char *base_p = strcat(basename(base), "_"); + + dp = opendir(dir); + + if (dp == NULL) { + printf("Unable to open %s directory\n", dir_p); + return -1; + } + + while ((ep = readdir(dp)) != NULL) { + if (strncmp(base_p, ep->d_name, strlen(base_p)) == 0) { + int i = strtol(ep->d_name + strlen(base_p), NULL, 10); + + if ((*first_bin < 0) || (i < *first_bin)) { + *first_bin = i; + } + if ((*last_bin < 0) || (i > *last_bin)) { + *last_bin = i; + } + } + } + + closedir(dp); + + return 0; +} + +// +// If estimated bin == initial_bin, return +// If estimated bin == previous bin, return higher bin (in between) + +int get_bin_from_time(char *prefix, int initial_bin, int previous_bin, + int first_bin, int last_bin, time_t target, + int *number_subints_per_file) { + int status; + char filename[128], header[256], nfd[32]; + FILE *file; + int nch; + double freq; + double samp_rate; + float length; + struct tm mjd_tm = {0}; + time_t mjd; + + sprintf(filename, "%s_%06i.bin", prefix, initial_bin); + + file = fopen(filename, "r"); + + if (file == NULL) { + return -1; + } + + status = fread(header, sizeof(char), 256, file); + + fclose(file); + + status = + sscanf(header, + "HEADER\nUTC_START %s\nFREQ %lf Hz\nBW %lf " + "Hz\nLENGTH %f s\nNCHAN %d\nNSUB %d\n", + nfd, &freq, &samp_rate, &length, &nch, number_subints_per_file); + + strptime(nfd, "%Y-%m-%dT%T", &mjd_tm); + mjd = mktime(&mjd_tm); + + int estimated_bin = + floor(initial_bin + + difftime(target, mjd) / (length * *number_subints_per_file)); + + // Clip to file range + if (estimated_bin < first_bin) { + estimated_bin = first_bin; + } + + if (estimated_bin > last_bin) { + estimated_bin = last_bin; + } + + if (estimated_bin == initial_bin) { + return estimated_bin; + } else if (estimated_bin == previous_bin) { + // Prevent infinite ing poin + // Return higher as the target is in the gap between + return estimated_bin > initial_bin ? estimated_bin : initial_bin; + } + + return get_bin_from_time(prefix, estimated_bin, initial_bin, first_bin, + last_bin, target, number_subints_per_file); +} + +int get_subs_from_datestrings(char *prefix, char *start, char *end, + int *start_bin, int *num_integrations) { + int k, status; + char filename[128], header[256], nfd[32]; + FILE *file; + int number_subints_per_file; + int nch; + double freq; + double samp_rate; + float length; + int first_bin = -1; + int last_bin = -1; + + // Get avaiable file range to constrain search + get_bin_range(prefix, &first_bin, &last_bin); + + if (start != NULL) { + struct tm tm = {0}; + time_t t; + strptime(start, "%Y-%m-%dT%T", &tm); + t = mktime(&tm); + + int s = get_bin_from_time(prefix, first_bin, first_bin, first_bin, last_bin, + t, &number_subints_per_file); + + if (s < 0) { + return -1; + } + + *start_bin = s; + } + + if (end != NULL) { + struct tm tm = {0}; + time_t t; + strptime(end, "%Y-%m-%dT%T", &tm); + t = mktime(&tm); + + int s = get_bin_from_time(prefix, first_bin, first_bin, first_bin, last_bin, + t, &number_subints_per_file); + + if (s < *start_bin) { + return -1; + } + + *num_integrations = (s - *start_bin + 1) * number_subints_per_file; + } + + return 0; +} struct spectrogram read_spectrogram(char *prefix,int isub,int nsub,double f0,double df0,int nbin,double foff) { @@ -21,7 +181,7 @@ struct spectrogram read_spectrogram(char *prefix,int isub,int nsub,double f0,dou // Open first file to get number of channels sprintf(filename,"%s_%06d.bin",prefix,isub); - + // Open file file=fopen(filename,"r"); if (file==NULL) { @@ -39,17 +199,17 @@ struct spectrogram read_spectrogram(char *prefix,int isub,int nsub,double f0,dou nbits=8; } s.freq+=foff; - + // Close file fclose(file); // Compute plotting channel if (f0>0.0 && df0>0.0) { s.nchan=(int) (df0/s.samp_rate*(float) nch); - + j0=(int) ((f0-0.5*df0-s.freq+0.5*s.samp_rate)*(float) nch/s.samp_rate); j1=(int) ((f0+0.5*df0-s.freq+0.5*s.samp_rate)*(float) nch/s.samp_rate); - + if (j0<0 || j1>nch) { fprintf(stderr,"Requested frequency range out of limits\n"); s.nsub=0; @@ -70,9 +230,9 @@ struct spectrogram read_spectrogram(char *prefix,int isub,int nsub,double f0,dou s.nsub=nsub/nbin; s.msub=msub; s.isub=isub; - + printf("Allocating %.2f MB of memory\n",(4* (float) s.nchan * (float) s.nsub)/(1024 * 1024)); - + // Allocate s.z=(float *) malloc(sizeof(float)*s.nchan*s.nsub); s.zavg=(float *) malloc(sizeof(float)*s.nsub); @@ -127,9 +287,9 @@ struct spectrogram read_spectrogram(char *prefix,int isub,int nsub,double f0,dou } if (status==0) break; - + // Copy - for (j=0;j + struct spectrogram { int nsub,nchan,msub,isub; double *mjd; @@ -9,7 +12,15 @@ struct spectrogram { float zmin,zmax; char nfd0[32]; }; + +int get_bin_range(char *prefix, int *first_bin, int *last_bin); +int get_bin_from_time(char *prefix, int initial_bin, int previous_bin, + int first_bin, int last_bin, time_t target, + int *number_subints_per_file); +int get_subs_from_datestrings(char *prefix, char *start, char *end, + int *start_bin, int *num_integrations); struct spectrogram read_spectrogram(char *prefix,int isub,int nsub,double f0,double df0,int nbin,double foff); void write_spectrogram(struct spectrogram s,char *prefix); void free_spectrogram(struct spectrogram s); -#endif + +#endif // RFIO_H From a581bdfccda3e1fb0e6204db99cdeca036ece424 Mon Sep 17 00:00:00 2001 From: "Martin Herren (HB9FXX)" Date: Sat, 16 Nov 2024 09:39:06 +0100 Subject: [PATCH 4/5] [rfio][tests] Add tests for new get_subs_from_datestrings function Creation of test sets of 200 minutes of random 1024 S/s int16 IQ data is done automatically at first test run. Signed-off-by: Martin Herren (HB9FXX) --- Makefile.linux | 13 +- Makefile.osx | 13 +- makefile | 13 +- tests/.gitignore | 3 + tests/tests.c | 2 + tests/tests_rfio.c | 368 +++++++++++++++++++++++++++++++++++++++++++++ tests/tests_rfio.h | 14 ++ 7 files changed, 420 insertions(+), 6 deletions(-) create mode 100644 tests/.gitignore create mode 100644 tests/tests_rfio.c create mode 100644 tests/tests_rfio.h diff --git a/Makefile.linux b/Makefile.linux index a055656..091453c 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -37,10 +37,19 @@ rfplot: rfplot.o rftime.o rfio.o rftrace.o sgdp4.o satutl.o deep.o ferror.o rftl rffft: rffft.o rffft_internal.o rftime.o $(CC) -o rffft rffft.o rffft_internal.o rftime.o -lfftw3f -lm -lsox -tests/tests: tests/tests.o tests/tests_rffft_internal.o tests/tests_rftles.o rffft_internal.o rftles.o satutl.o ferror.o +tests/tests: tests/tests.o tests/tests_rffft_internal.o tests/tests_rfio.o tests/tests_rftles.o rffft_internal.o rfio.o rftime.o rftles.o satutl.o ferror.o zscale.o $(CC) -Wall -o $@ $^ -lcmocka -lm -tests: tests/tests +tests/random: + dd if=/dev/random of=tests/random bs=12288000 count=4 + +tests/bins: rffft tests/random + mkdir -p tests/bin/ + ./rffft -i tests/random -p tests/bin/ -o t10_n120_32 -f 2250000000 -s 1024 -T 2016-09-28T00:20:00 -t 10 -n 120 + ./rffft -i tests/random -p tests/bin/ -o t15_n90_8 -f 2250000000 -s 1024 -T 2016-09-28T00:20:00 -t 15 -n 90 -b + touch tests/bins + +tests: tests/tests tests/bins ./tests/tests .PHONY: clean install uninstall tests diff --git a/Makefile.osx b/Makefile.osx index f1fde31..cf5ceb1 100644 --- a/Makefile.osx +++ b/Makefile.osx @@ -51,10 +51,19 @@ rfplot: rfplot.o rftime.o rfio.o rftrace.o sgdp4.o satutl.o deep.o ferror.o vers rffft: rffft.o rffft_internal.o rftime.o $(CC) -o rffft rffft.o rffft_internal.o rftime.o -lfftw3f -lm -lsox $(LFLAGS) -tests/tests: tests/tests.o tests/tests_rffft_internal.o tests/tests_rftles.o rffft_internal.o rftles.o satutl.o ferror.o +tests/tests: tests/tests.o tests/tests_rffft_internal.o tests/tests_rfio.o tests/tests_rftles.o rffft_internal.o rfio.o rftime.o rftles.o satutl.o ferror.o zscale.o $(CC) -Wall -o $@ $^ -lcmocka -lm -tests: tests/tests +tests/random: + dd if=/dev/random of=tests/random bs=12288000 count=4 + +tests/bins: rffft tests/random + mkdir -p tests/bin/ + ./rffft -i tests/random -p tests/bin/ -o t10_n120_32 -f 2250000000 -s 1024 -T 2016-09-28T00:20:00 -t 10 -n 120 + ./rffft -i tests/random -p tests/bin/ -o t15_n90_8 -f 2250000000 -s 1024 -T 2016-09-28T00:20:00 -t 15 -n 90 -b + touch tests/bins + +tests: tests/tests tests/bins ./tests/tests .PHONY: clean install uninstall tests diff --git a/makefile b/makefile index 36bf046..d2b418b 100644 --- a/makefile +++ b/makefile @@ -40,10 +40,19 @@ rfplot: rfplot.o rftime.o rfio.o rftrace.o sgdp4.o satutl.o deep.o ferror.o vers rffft: rffft.o rffft_internal.o rftime.o $(CC) -o rffft rffft.o rffft_internal.o rftime.o -lfftw3f -lm -lsox -tests/tests: tests/tests.o tests/tests_rffft_internal.o tests/tests_rftles.o rffft_internal.o rftles.o satutl.o ferror.o +tests/tests: tests/tests.o tests/tests_rffft_internal.o tests/tests_rfio.o tests/tests_rftles.o rffft_internal.o rfio.o rftime.o rftles.o satutl.o ferror.o zscale.o $(CC) -Wall -o $@ $^ -lcmocka -lm -tests: tests/tests +tests/random: + dd if=/dev/random of=tests/random bs=12288000 count=4 + +tests/bins: rffft tests/random + mkdir -p tests/bin/ + ./rffft -i tests/random -p tests/bin/ -o t10_n120_32 -f 2250000000 -s 1024 -T 2016-09-28T00:20:00 -t 10 -n 120 + ./rffft -i tests/random -p tests/bin/ -o t15_n90_8 -f 2250000000 -s 1024 -T 2016-09-28T00:20:00 -t 15 -n 90 -b + touch tests/bins + +tests: tests/tests tests/bins ./tests/tests .PHONY: clean install uninstall tests diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..9eff713 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,3 @@ +random +bin/ +bins diff --git a/tests/tests.c b/tests/tests.c index 2d1c5d9..1c8a885 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -1,4 +1,5 @@ #include "tests_rffft_internal.h" +#include "tests_rfio.h" #include "tests_rftles.h" #include @@ -11,6 +12,7 @@ int main(void) { int failures = 0; failures += run_rffft_internal_tests(); + failures += run_io_tests(); failures += run_tle_tests(); return failures; diff --git a/tests/tests_rfio.c b/tests/tests_rfio.c new file mode 100644 index 0000000..b1cbbd1 --- /dev/null +++ b/tests/tests_rfio.c @@ -0,0 +1,368 @@ +#include "tests_rfio.h" + +#include +#include +#include +#include +#include + +#include "../rfio.h" + +// Test sets +// There are 2 test sets consisting of 200 minutes of random 1024 S/s int16 IQ +// samples, +// +// they where generated as follow +// $ dd if=/dev/random of=random bs=12288000 count=4 +// $ ./rffft -i random -p tests/bin/ -o t10_n120_32 -f 2250000000 -s 1024 -T 2016-09-28T00:20:00 -t 10 -n 120 +// $ ./rffft -i random -p tests/bin/ -o t15_n90_8 -f 2250000000 -s 1024 -T 2016-09-28T00:20:00 -t 15 -n 90 -b +// +// Those 2 sets have different integration times, number of integrations per +// file and sample format The first one has 20 minutes per file, the second 22 +// minutes and 30 seconds per file +// +// t10_n120_32 bin start times: +// 0: 00:20:00 +// 1: 00:40:00 +// 2: 01:00:00 +// 3: 01:20:00 +// 4: 01:40:00 +// 5: 02:00:00 +// 6: 02:20:00 +// 7: 02:40:00 +// 8: 03:00:00 +// 9: 03:20:00 +// 10: 03:40:00 +// +// t15_n90_8 bin start times: +// 0: 00:20:00 +// 1: 00:42:30 +// 2: 01:05:00 +// 3: 01:27:30 +// 4: 01:50:00 +// 5: 02:12:30 +// 6: 02:35:00 +// 7: 02:57:30 +// 8: 03:20:00 + +// Tests + +void IO_test_non_existent_file(void **state) { + int status; + int start_bin; + int num_integrations; + + start_bin = -1; + num_integrations = -1; + status = + get_subs_from_datestrings("tests/bin/nonexistent", "2016-09-28T00:30:10", + NULL, &start_bin, &num_integrations); + assert_int_equal(status, -1); + assert_int_equal(start_bin, -1); + assert_int_equal(num_integrations, -1); +} + +void IO_test_only_start_time_int(void **state) { + int status; + int start_bin; + int num_integrations; + + // Date before bin, so start at 0 + start_bin = -1; + num_integrations = 3600; + status = + get_subs_from_datestrings("tests/bin/t10_n120_32", "2016-09-28T00:10:20", + NULL, &start_bin, &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 0); + assert_int_equal(num_integrations, 3600); + + // Start somewhere inside the bins aligned on start of bin + start_bin = -1; + num_integrations = 42; + status = + get_subs_from_datestrings("tests/bin/t10_n120_32", "2016-09-28T01:00:00", + NULL, &start_bin, &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 2); + assert_int_equal(num_integrations, 42); + + // Start somewhere inside the bins + start_bin = -1; + num_integrations = 3; + status = + get_subs_from_datestrings("tests/bin/t10_n120_32", "2016-09-28T01:30:00", + NULL, &start_bin, &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 3); + assert_int_equal(num_integrations, 3); + + start_bin = -1; + num_integrations = 42; + status = + get_subs_from_datestrings("tests/bin/t10_n120_32", "2016-09-28T02:30:00", + NULL, &start_bin, &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 6); + assert_int_equal(num_integrations, 42); +} + +void IO_test_only_end_time_int(void **state) { + int status; + int start_bin; + int num_integrations; + + // End somewhere inside the bins aligned on start of bin + start_bin = 0; + num_integrations = -1; + status = get_subs_from_datestrings("tests/bin/t10_n120_32", NULL, + "2016-09-28T01:00:00", &start_bin, + &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 0); + assert_int_equal(num_integrations, 360); + + // End somewhere inside the bins + start_bin = 1; + num_integrations = -1; + status = get_subs_from_datestrings("tests/bin/t10_n120_32", NULL, + "2016-09-28T01:04:00", &start_bin, + &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 1); + assert_int_equal(num_integrations, 240); + + start_bin = 3; + num_integrations = -1; + status = get_subs_from_datestrings("tests/bin/t10_n120_32", NULL, + "2016-09-28T01:30:00", &start_bin, + &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 3); + assert_int_equal(num_integrations, 120); + + // End after last bin, update number of integrations to end of file + start_bin = 6; + num_integrations = 3600; + status = get_subs_from_datestrings("tests/bin/t10_n120_32", NULL, + "2016-09-28T04:30:00", &start_bin, + &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 6); + assert_int_equal(num_integrations, 600); +} + +void IO_test_only_start_time_char(void **state) { + int status; + int start_bin; + int num_integrations; + + // Date before bin, so start at 0 + start_bin = -1; + num_integrations = 3600; + status = + get_subs_from_datestrings("tests/bin/t15_n90_8", "2016-09-28T00:10:20", + NULL, &start_bin, &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 0); + assert_int_equal(num_integrations, 3600); + + // Start somewhere inside the bins aligned on start of bin + start_bin = -1; + num_integrations = 42; + status = + get_subs_from_datestrings("tests/bin/t15_n90_8", "2016-09-28T01:05:00", + NULL, &start_bin, &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 2); + assert_int_equal(num_integrations, 42); + + // Start somewhere inside the bins + start_bin = -1; + num_integrations = 3; + status = + get_subs_from_datestrings("tests/bin/t15_n90_8", "2016-09-28T01:30:05", + NULL, &start_bin, &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 3); + assert_int_equal(num_integrations, 3); + + start_bin = -1; + num_integrations = 42; + status = + get_subs_from_datestrings("tests/bin/t15_n90_8", "2016-09-28T02:30:00", + NULL, &start_bin, &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 5); + assert_int_equal(num_integrations, 42); +} + +void IO_test_only_end_time_char(void **state) { + int status; + int start_bin; + int num_integrations; + + // End somewhere inside the bins aligned on start of bin + start_bin = 0; + num_integrations = -1; + status = get_subs_from_datestrings("tests/bin/t15_n90_8", NULL, + "2016-09-28T01:05:00", &start_bin, + &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 0); + assert_int_equal(num_integrations, 270); + + // End somewhere inside the bins + start_bin = 1; + num_integrations = 42; + status = get_subs_from_datestrings("tests/bin/t15_n90_8", NULL, + "2016-09-28T01:04:00", &start_bin, + &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 1); + assert_int_equal(num_integrations, 90); + + start_bin = 3; + num_integrations = 0; + status = get_subs_from_datestrings("tests/bin/t15_n90_8", NULL, + "2016-09-28T01:30:00", &start_bin, + &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 3); + assert_int_equal(num_integrations, 90); + + // End after last bin, update number of integrations to end of file + start_bin = 6; + num_integrations = 3600; + status = get_subs_from_datestrings("tests/bin/t15_n90_8", NULL, + "2016-09-28T04:30:00", &start_bin, + &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 6); + assert_int_equal(num_integrations, 270); +} + +void IO_test_both_start_and_stop_int(void **state) { + int status; + int start_bin; + int num_integrations; + + // Start before and end after bin files + start_bin = 10; + num_integrations = 100; + status = get_subs_from_datestrings( + "tests/bin/t10_n120_32", "2016-09-28T00:00:00", "2016-09-28T03:50:00", + &start_bin, &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 00); + assert_int_equal(num_integrations, 1320); + + // Start and end corresponds to bin files + start_bin = 10; + num_integrations = 100; + status = get_subs_from_datestrings( + "tests/bin/t10_n120_32", "2016-09-28T00:20:00", "2016-09-28T03:40:00", + &start_bin, &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 0); + assert_int_equal(num_integrations, 1320); + + // Start and end inside bin + start_bin = 10; + num_integrations = 100; + status = get_subs_from_datestrings( + "tests/bin/t10_n120_32", "2016-09-28T00:30:00", "2016-09-28T03:30:00", + &start_bin, &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 0); + assert_int_equal(num_integrations, 1200); + + start_bin = 10; + num_integrations = 100; + status = get_subs_from_datestrings( + "tests/bin/t10_n120_32", "2016-09-28T00:40:00", "2016-09-28T03:20:00", + &start_bin, &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 1); + assert_int_equal(num_integrations, 1080); + + // Start and end inverted inside bin + start_bin = 10; + num_integrations = 100; + status = get_subs_from_datestrings( + "tests/bin/t10_n120_32", "2016-09-28T03:30:00", "2016-09-28T00:30:00", + &start_bin, &num_integrations); + assert_int_equal(status, -1); + assert_int_equal(start_bin, 9); + assert_int_equal(num_integrations, 100); +} + +void IO_test_both_start_and_stop_char(void **state) { + int status; + int start_bin; + int num_integrations; + + // Start before and end after bin files + start_bin = 10; + num_integrations = 100; + status = get_subs_from_datestrings( + "tests/bin/t15_n90_8", "2016-09-28T00:00:00", "2016-09-28T03:50:00", + &start_bin, &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 0); + assert_int_equal(num_integrations, 810); + + // Start and end corresponds to bin files + start_bin = 10; + num_integrations = 100; + status = get_subs_from_datestrings( + "tests/bin/t15_n90_8", "2016-09-28T00:20:00", "2016-09-28T03:20:00", + &start_bin, &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 0); + assert_int_equal(num_integrations, 810); + + // Start and end inside bin + start_bin = 10; + num_integrations = 100; + status = get_subs_from_datestrings( + "tests/bin/t15_n90_8", "2016-09-28T00:31:15", "2016-09-28T03:28:45", + &start_bin, &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 0); + assert_int_equal(num_integrations, 810); + + start_bin = 10; + num_integrations = 100; + status = get_subs_from_datestrings( + "tests/bin/t15_n90_8", "2016-09-28T00:42:30", "2016-09-28T03:17:30", + &start_bin, &num_integrations); + assert_int_equal(status, 0); + assert_int_equal(start_bin, 1); + assert_int_equal(num_integrations, 630); + + // Start and end inverted inside bin + start_bin = 10; + num_integrations = 100; + status = get_subs_from_datestrings( + "tests/bin/t15_n90_8", "2016-09-28T03:28:45", "2016-09-28T00:31:15", + &start_bin, &num_integrations); + assert_int_equal(status, -1); + assert_int_equal(start_bin, 8); + assert_int_equal(num_integrations, 100); +} + +// Entry point to run all tests +int run_io_tests() { + const struct CMUnitTest tests[] = { + cmocka_unit_test(IO_test_non_existent_file), + cmocka_unit_test(IO_test_only_start_time_int), + cmocka_unit_test(IO_test_only_end_time_int), + cmocka_unit_test(IO_test_only_start_time_char), + cmocka_unit_test(IO_test_only_end_time_char), + cmocka_unit_test(IO_test_both_start_and_stop_int), + cmocka_unit_test(IO_test_both_start_and_stop_char) + }; + + return cmocka_run_group_tests_name("IO", tests, NULL, NULL); +} diff --git a/tests/tests_rfio.h b/tests/tests_rfio.h new file mode 100644 index 0000000..41b5614 --- /dev/null +++ b/tests/tests_rfio.h @@ -0,0 +1,14 @@ +#ifndef _TESTS_RFIO_H +#define _TESTS_RFIO_H + +#ifdef __cplusplus +extern "C" { +#endif + +int run_io_tests(); + +#ifdef __cplusplus +} +#endif + +#endif /* _TESTS_RFIO_H */ From 7d17fcd299e76901e68e248f4f4643a01613d849 Mon Sep 17 00:00:00 2001 From: "Martin Herren (HB9FXX)" Date: Tue, 12 Nov 2024 07:58:27 +0100 Subject: [PATCH 5/5] [rfplot] Add -T and -E option to specify range to display given date/time strings Using the new get_subs_from_datestrings() function in rfio. Signed-off-by: Martin Herren (HB9FXX) --- rfplot.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/rfplot.c b/rfplot.c index 209e43a..48cbfe7 100644 --- a/rfplot.c +++ b/rfplot.c @@ -82,6 +82,8 @@ int main(int argc,char *argv[]) double foff=0.0,mjdgrid=0.0; int jj0,jj1; int show_names = 0; + char * start_time = NULL; + char * end_time = NULL; // Get site env=getenv("ST_COSPAR"); @@ -106,7 +108,7 @@ int main(int argc,char *argv[]) // Read arguments if (argc>1) { - while ((arg=getopt(argc,argv,"p:f:w:s:l:b:z:hc:C:gm:o:S:W:F:n"))!=-1) { + while ((arg=getopt(argc,argv,"p:f:w:s:l:b:z:hc:C:gm:o:S:W:F:nT:E:"))!=-1) { switch (arg) { case 'p': @@ -180,6 +182,14 @@ int main(int argc,char *argv[]) show_names = 1; break; + case 'T': + start_time = optarg; + break; + + case 'E': + end_time = optarg; + break; + default: usage(); return 0; @@ -190,6 +200,16 @@ int main(int argc,char *argv[]) return 0; } + if (start_time || end_time) { + status = get_subs_from_datestrings(path, start_time, end_time, &isub, &nsub); + + if (status != 0) { + printf("Failed to read files or requested period out of bin range\n"); + + return -1; + } + } + // Read data s=read_spectrogram(path,isub,nsub,f0,df0,nbin,foff); @@ -1043,6 +1063,10 @@ void usage(void) printf("-C Site ID\n"); printf("-c TLE catalog\n"); printf("-F List with frequencies [$ST_DATADIR/data/frequencies.txt]\n"); + printf("-T