/*--------------------------------------------------------------------------------
入力データの読み込み
read the input data
readdata.c
*--------------------------------------------------------------------------------*/
#include "FT_surrogate.h"
complex *readdata( int *num )
{
int t;
complex *x;
if ( scanf( "%d", num ) != 1 ) {
fputs( "cannot get the data number\n", stderr );
return NULL;
}
if ( check_power_of_two( (*num) ) == 0 ) {
printf("#---------------------------------------------------------\n");
printf("# the data number is \"not\" 2^n (power of two).\n");
printf("#---------------------------------------------------------\n");
return NULL;
}
if ( ( x = (complex *)malloc( (*num) * sizeof(complex) ) ) == NULL ) {
fputs( "cannot allocate memory\n", stderr );
return NULL;
}
/* 実データには虚部が存在しない。 */
/* x[t].r のみ読み込み、x[t].i にはゼロを入力 */
for ( t = 0; t < (*num); t++ ) {
if ( scanf( "%lf", &x[t].real ) != 1 ) {
fputs( "cannot read the data\n", stderr );
return NULL;
}
x[t].imag = 0.0;
}
return x;
}
/*-----------------------------------------------------
入力値が2のべき乗のときは1を返し、
2のべき乗ではないときはゼロを返す。
-----------------------------------------------------*/
int check_power_of_two( int num )
{
return (num & (num - 1)) == 0;
}