xp_comm_proj/fftn/FFTn_vxp.c
/*-FFTn_build_array-------------------------------------------------------------
 *  Description: construct an array for use with FFT routines
 *   Parameters: int    ndim    No. dimensions
 *               int    *dims   Array of dimensions
 *               int    veclen  Vector length (1/2)
 *               int    type    Data type
 *               void   *data   Pointer to data
 * Return value: pointer to the array or NULL for failure
 */
FFTn_build_array
Description: construct an array for use with FFT routines
Parameters: int    ndim    No. dimensions
int    *dims   Array of dimensions
int    veclen  Vector length (1/2)
int    type    Data type
void   *data   Pointer to data
Return value: pointer to the array or NULL for failure
FFTn_build_array Description : construct an array for use with FFT routines Parameters : int ndim No . dimensions int * dims Array of dimensions int veclen Vector length ( 1 / 2 ) int type Data type void * data Pointer to data Return value : pointer to the array or NULL for failure
static float *
FFTbuild_array(int ndim, 
	       int *dims,
	       int veclen,
	       int type,
	       void *data)
{
  int size, i;
  float *array, *arrPtr;
  unsigned char *bytePtr;
  short *shortPtr;
  int *intPtr;
  float *floatPtr;
  double *doublePtr;
  for (size = 1, i = 0;
       i < ndim;
       i++)
    {
      size *= dims[i];
    }
  array = (float *)ARRalloc(NULL, DTYPE_FLOAT, size * 2, NULL);
  if (array)
    {
      float bVal;
      if (veclen == 1)
	{
	  switch (type)
	    {
	    case DTYPE_CHAR:
	    case DTYPE_BYTE:
	      bytePtr = (unsigned char *)data;
	      arrPtr = array;
	      for (i = 0;
		   i < size;
		   i++)
		{
		  bVal = *bytePtr++;
		  *arrPtr++ = bVal;
		  *arrPtr++ = 0.;
		}
	      break;
	    case DTYPE_SHORT:
	      shortPtr = (short *)data;
	      arrPtr = array;
	      for (i = 0;
		   i < size;
		   i++)
		{
		  *arrPtr++ = *shortPtr++;
		  *arrPtr++ = 0.;
		}
	      break;
	    case DTYPE_INT:
	      intPtr = (int *)data;
	      arrPtr = array;
	      for (i = 0;
		   i < size;
		   i++)
		{
		  *arrPtr++ = *intPtr++;
		  *arrPtr++ = 0.;
		}
	      break;
	    case DTYPE_FLOAT:
	      floatPtr = (float *)data;
	      arrPtr = array;
	      for (i = 0;
		   i < size;
		   i++)
		{
		  *arrPtr++ = *floatPtr++;
		  *arrPtr++ = 0.;
		}
	      break;
	    case DTYPE_DOUBLE:
	      doublePtr = (double *)data;
	      arrPtr = array;
	      for (i = 0;
		   i < size;
		   i++)
		{
		  *arrPtr++ = *doublePtr++;
		  *arrPtr++ = 0.;
		}
	      break;
	    default:
	      ARRfree(array);
	      set_avs_err("Invalid data type");
	      array = NULL;
	    }
	}
      else if (veclen == 2)
	{
	  switch (type)
	    {
	    case DTYPE_CHAR:
	    case DTYPE_BYTE:
	      bytePtr = (unsigned char *)data;
	      arrPtr = array;
	      for (i = 0;
		   i < size;
		   i++)
		{
		  bVal = *bytePtr++;
		  *arrPtr++ = bVal;
		  bVal = *bytePtr++;
		  *arrPtr++ = bVal;
		}
	      break;
	    case DTYPE_SHORT:
	      shortPtr = (short *)data;
	      arrPtr = array;
	      for (i = 0;
		   i < size;
		   i++)
		{
		  *arrPtr++ = *shortPtr++;
		  *arrPtr++ = *shortPtr++;
		}
	      break;
	    case DTYPE_INT:
	      intPtr = (int *)data;
	      arrPtr = array;
	      for (i = 0;
		   i < size;
		   i++)
		{
		  *arrPtr++ = *intPtr++;
		  *arrPtr++ = *intPtr++;
		}
	      break;
	    case DTYPE_FLOAT:
	      floatPtr = (float *)data;
	      arrPtr = array;
	      for (i = 0;
		   i < size;
		   i++)
		{
		  *arrPtr++ = *floatPtr++;
		  *arrPtr++ = *floatPtr++;
		}
	      break;
	    case DTYPE_DOUBLE:
	      doublePtr = (double *)data;
	      arrPtr = array;
	      for (i = 0;
		   i < size;
		   i++)
		{
		  *arrPtr++ = *doublePtr++;
		  *arrPtr++ = *doublePtr++;
		}
	      break;
	    default:
	      ARRfree(array);
	      set_avs_err("Invalid data type");
	      array = NULL;
	    }
	}
      else
	{
	  ARRfree(array);
	  set_avs_err("Vector length must be 1 or 2");
	  array = NULL;
	}
    }
  else
    {
      set_avs_err("Could not allocate node data");
    }
  return array;
}
static float * FFTbuild_array ( int ndim , int * dims , int veclen , int type , void * data ) { int size , i ; float * array , * arrPtr ; unsigned char * bytePtr ; short * shortPtr ; int * intPtr ; float * floatPtr ; double * doublePtr ; for ( size = 1 , i = 0 ; i < ndim ; i ++ ) { size *= dims [ i ] ; } array = ( float * ) ARRalloc ( NULL , DTYPE_FLOAT , size * 2 , NULL ) ; if ( array ) { float bVal ; if ( veclen == 1 ) { switch ( type ) { case DTYPE_CHAR : case DTYPE_BYTE : bytePtr = ( unsigned char * ) data ; arrPtr = array ; for ( i = 0 ; i < size ; i ++ ) { bVal = * bytePtr ++ ; * arrPtr ++ = bVal ; * arrPtr ++ = 0. ; } break ; case DTYPE_SHORT : shortPtr = ( short * ) data ; arrPtr = array ; for ( i = 0 ; i < size ; i ++ ) { * arrPtr ++ = * shortPtr ++ ; * arrPtr ++ = 0. ; } break ; case DTYPE_INT : intPtr = ( int * ) data ; arrPtr = array ; for ( i = 0 ; i < size ; i ++ ) { * arrPtr ++ = * intPtr ++ ; * arrPtr ++ = 0. ; } break ; case DTYPE_FLOAT : floatPtr = ( float * ) data ; arrPtr = array ; for ( i = 0 ; i < size ; i ++ ) { * arrPtr ++ = * floatPtr ++ ; * arrPtr ++ = 0. ; } break ; case DTYPE_DOUBLE : doublePtr = ( double * ) data ; arrPtr = array ; for ( i = 0 ; i < size ; i ++ ) { * arrPtr ++ = * doublePtr ++ ; * arrPtr ++ = 0. ; } break ; default : ARRfree ( array ) ; set_avs_err ( " " ) ; array = NULL ; } } else if ( veclen == 2 ) { switch ( type ) { case DTYPE_CHAR : case DTYPE_BYTE : bytePtr = ( unsigned char * ) data ; arrPtr = array ; for ( i = 0 ; i < size ; i ++ ) { bVal = * bytePtr ++ ; * arrPtr ++ = bVal ; bVal = * bytePtr ++ ; * arrPtr ++ = bVal ; } break ; case DTYPE_SHORT : shortPtr = ( short * ) data ; arrPtr = array ; for ( i = 0 ; i < size ; i ++ ) { * arrPtr ++ = * shortPtr ++ ; * arrPtr ++ = * shortPtr ++ ; } break ; case DTYPE_INT : intPtr = ( int * ) data ; arrPtr = array ; for ( i = 0 ; i < size ; i ++ ) { * arrPtr ++ = * intPtr ++ ; * arrPtr ++ = * intPtr ++ ; } break ; case DTYPE_FLOAT : floatPtr = ( float * ) data ; arrPtr = array ; for ( i = 0 ; i < size ; i ++ ) { * arrPtr ++ = * floatPtr ++ ; * arrPtr ++ = * floatPtr ++ ; } break ; case DTYPE_DOUBLE : doublePtr = ( double * ) data ; arrPtr = array ; for ( i = 0 ; i < size ; i ++ ) { * arrPtr ++ = * doublePtr ++ ; * arrPtr ++ = * doublePtr ++ ; } break ; default : ARRfree ( array ) ; set_avs_err ( " " ) ; array = NULL ; } } else { ARRfree ( array ) ; set_avs_err ( " " ) ; array = NULL ; } } else { set_avs_err ( " " ) ; } return array ; }
FFTn_build_array
  Description: construct an array for use with FFT routines
   Parameters: int    ndim    No.
FFTn_build_array Description : construct an array for use with FFT routines Parameters : int ndim No .
/* Calculate length of array */ /* Allocate space for array */