MITHaystack / digital_rf

Read, write, and interact with data in the Digital RF and Digital Metadata formats
Other
97 stars 30 forks source link

Use integer math to calculate file bounds in C library #23

Closed ryanvolz closed 3 years ago

ryanvolz commented 3 years ago

Fixes #13.

If digital_rf is compiled to use 64-bit long double values (as opposed to 80-bit or more), or other compiler flags throw off the long double sample rate math, users are likely to see write failures depending on the sample rate. Usually this results in an error message of "Failed to write data" and "Request index M before first expected index N".

The current Python tests don't trigger this condition, so they pass when using 64-bit long doubles. This PR tweaks the file cadence so that the write error is triggered in these cases, so we can be forewarned that errors are likely when writing under those compilation conditions.

Then, this PR fixes the newly-broken test by doing away with use of long doubles for calculations with the sample rate in the C library in digital_rf_get_subdir_file to determine file names and sample bounds. The reason for this change is that not all platforms support long doubles that with at least a 64-bit mantissa. This caused at least one bug on the aarch64 platform which resulted in incorrect file bounds from digital_rf_get_subdir_file. By using integer math that is implemented uniformly on all platforms, any bugs in the calculation should be more noticable.

This PR also adds two new functions that are only used internally for now: digital_rf_get_timestamp_floor and digital_rf_get_sample_ceil. These are now used to do the file sample bound calculations. A future commit will expose these externally so that other C users and the Python library can make use of them, but that will require bumping the library version.