hamnet70/impl/src/utils.c

67 lines
987 B
C
Raw Normal View History

#include <stdio.h>
#include "utils.h"
bool dump_array_cf(const float complex *data, size_t n, float T, const char *filename)
{
FILE *f = fopen(filename, "w");
if(!f) {
return false;
}
size_t written = fwrite("CPX_", 1, 4, f);
if(written != 4) {
goto err_close;
}
written = fwrite(&T, sizeof(T), 1, f);
if(written != 1) {
goto err_close;
}
written = fwrite(data, sizeof(data[0]), n, f);
if(written != n) {
goto err_close;
}
fclose(f);
return true;
err_close:
fclose(f);
return false;
}
bool dump_array_f(const float *data, size_t n, float T, const char *filename)
{
FILE *f = fopen(filename, "w");
if(!f) {
return false;
}
size_t written = fwrite("FLT_", 1, 4, f);
if(written != 4) {
goto err_close;
}
written = fwrite(&T, sizeof(T), 1, f);
if(written != 1) {
goto err_close;
}
written = fwrite(data, sizeof(data[0]), n, f);
if(written != n) {
goto err_close;
}
fclose(f);
return true;
err_close:
fclose(f);
return false;
}