kopia lustrzana https://github.com/Dsplib/libdspl-2.0
73 wiersze
1.7 KiB
C
73 wiersze
1.7 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <time.h>
|
||
|
#include "dspl.h"
|
||
|
|
||
|
int main(int argc, char* argv[])
|
||
|
{
|
||
|
void* hdspl; /* DSPL handle */
|
||
|
complex_t *pxd = NULL;
|
||
|
complex_t *pyd = NULL;
|
||
|
|
||
|
int nx, ny, tx, err, verr;
|
||
|
double derr;
|
||
|
|
||
|
random_t rnd = {0}; /* random structure */
|
||
|
|
||
|
hdspl = dspl_load(); /* Load DSPL function */
|
||
|
|
||
|
printf("writebin and readbin for complex data:.........");
|
||
|
|
||
|
err = random_init(&rnd, RAND_TYPE_MRG32K3A, NULL);
|
||
|
if(err != RES_OK)
|
||
|
goto exit_error_code;
|
||
|
|
||
|
err = randi(&nx, 1, 1, 1000000, &rnd);
|
||
|
if(err != RES_OK)
|
||
|
goto exit_error_code;
|
||
|
|
||
|
pxd = (complex_t*) malloc(nx * sizeof(complex_t));
|
||
|
|
||
|
err = randn((double*)pxd, 2*nx, 1.0, 10.0, &rnd);
|
||
|
if(err != RES_OK)
|
||
|
goto exit_error_code;
|
||
|
|
||
|
err = writebin((void*)pxd, nx, DAT_COMPLEX, "dat/x.dat");
|
||
|
if(err != RES_OK)
|
||
|
goto exit_error_code;
|
||
|
|
||
|
err = system("octave octave/writebin_readbin_verification.m");
|
||
|
|
||
|
err = readbin("dat/y.dat", (void**)(&pyd), &ny, &tx);
|
||
|
if(err != RES_OK)
|
||
|
goto exit_error_code;
|
||
|
if(tx!=DAT_COMPLEX)
|
||
|
{
|
||
|
err = ERROR_DAT_TYPE;
|
||
|
goto exit_error_code;
|
||
|
}
|
||
|
verr = verif_cmplx(pxd, pyd, ny, 1E-12, &derr);
|
||
|
if(verr != DSPL_VERIF_SUCCESS)
|
||
|
goto exit_error_verif;
|
||
|
|
||
|
printf("ok (err = %12.4E)\n", derr);
|
||
|
goto exit_label;
|
||
|
|
||
|
exit_error_code:
|
||
|
printf("FAILED (with code = 0x%8x)\n", err);
|
||
|
goto exit_label;
|
||
|
exit_error_verif:
|
||
|
printf("FAILED (err = %12.4E)\n", derr);
|
||
|
|
||
|
exit_label:
|
||
|
if(pxd)
|
||
|
free(pxd);
|
||
|
if(pyd)
|
||
|
free(pyd);
|
||
|
/* free dspl handle */
|
||
|
dspl_free(hdspl);
|
||
|
return 0;
|
||
|
}
|
||
|
|