示例#1
0
int main( int argc,
	  char **argv )

{
  int i, bw, n, n3 ;
  int l, m1, m2, dummy, format ;
  double *rsignal, *isignal ;
  double *rcoeffs, *icoeffs ;
  double *workspace1, *workspace2 ;
  double tstart, tstop, runtime ;
  FILE *fp ;
  
  if (argc != 5)
    {
      fprintf(stdout,"Usage: test_soft_for bw sampleFile ");
      fprintf(stdout,"coefFile order_flag\n");
      exit(0);
    }

  bw = atoi( argv[1] );
  n = 2 * bw ;
  n3 = n * n * n ;
  format = atoi( argv[4] );

  /* real and imaginary parts of signal each need n^3 space */
  rsignal = ( double * ) malloc( sizeof( double ) * n3 ) ;
  isignal = ( double * ) malloc( sizeof( double ) * n3 ) ;

  /* real and imaginary parts of coeffs each need
     totalCoeffs_so3( bw) amount of space */
  rcoeffs = ( double * ) malloc(sizeof( double ) * totalCoeffs_so3( bw ) ) ;
  icoeffs = ( double * ) malloc(sizeof( double ) * totalCoeffs_so3( bw ) ) ;

  /* now for LOTS OF workspace */
  workspace1 = ( double * ) malloc(sizeof( double ) * 4 * n3 ) ;
  workspace2 = ( double * ) malloc(sizeof( double ) * ( 26 * bw + 2 * bw * bw) );


  if ( ( rsignal == NULL ) || ( isignal == NULL ) ||
       ( rcoeffs == NULL ) || ( icoeffs == NULL ) ||
       ( workspace1 == NULL ) || ( workspace2 == NULL ) )
    {
      perror("Error in allocating memory");
      exit( 1 ) ;
    }

  /* read in samples */
  fp = fopen( argv[2], "r" );
  for ( i = 0 ; i < n3 ; i ++ )
    {
      /* first the real part */
      fscanf(fp, "%lf", rsignal+i) ;
      /* now the imaginary part */
      fscanf(fp, "%lf", isignal+i) ;
    }
  fclose ( fp ) ;

  /* turn on stopwatch */
  tstart = csecond( ) ;

  /* now do the forward transform */
  Forward_SO3_Naive( bw,
		     rsignal, isignal,
		     rcoeffs, icoeffs,
		     workspace1, workspace2 ) ;

  /* turn off stopwatch */
  tstop = csecond( ) ;
  runtime = tstop - tstart ;

  fprintf(stdout,"runtime: %.5f seconds\n", runtime);

  /* write out coefficients to disk */
  /* ordered as the inverse transform expects the coefficients */
  if ( format == 0 )
    {
      fp = fopen( argv[ 3 ], "w" );
      for ( i = 0 ; i < totalCoeffs_so3( bw ) ; i ++ )
	fprintf(fp, "%.16f\n%.16f\n",
		rcoeffs[ i ], icoeffs[ i ] ) ;
      fclose( fp ) ;
    }
  else /* ordered in a more human friendly way */
    {
      fp = fopen( argv[ 3 ], "w" );
      for ( l = 0 ; l < bw ; l ++ )
	for ( m1 = -l ; m1 < l + 1 ; m1 ++ )
	  for ( m2 = -l ; m2 < l + 1 ; m2 ++ )
	    {
	      dummy = so3CoefLoc( m1, m2, l, bw ) ;
	      fprintf(fp, "l = %d m1 = %d m2 = %d\t%.15f\t%.15f\n",
		      l, m1, m2,
		      rcoeffs[ dummy ], icoeffs[ dummy ] ) ;
	    }
      fclose( fp ) ;
    }

  /* free up memory (and there's lots of it) */
  free( workspace2 );
  free( workspace1 );
  free( icoeffs );
  free( rcoeffs );
  free( isignal );
  free( rsignal );

  return 0 ;
}
示例#2
0
int main(int argc, char **argv)
{
  FILE *errorsfp;
  int i, j, bw, size, loops;
  int l, m, dummy, cutoff ;
  int rank, howmany_rank ;
  double *rcoeffs, *icoeffs, *rdata, *idata, *rresult, *iresult;
  double *workspace, *weights;
  double dumx, dumy ;
  double *relerror, *curmax, granderror, grandrelerror;
  double realtmp, imagtmp,origmag, tmpmag;
  double ave_error, ave_relerror, stddev_error, stddev_relerror;
  double total_time, for_time, inv_time;
  double tstart, tstop;
  time_t seed;
  fftw_plan dctPlan, idctPlan ;
  fftw_plan fftPlan, ifftPlan ;
  fftw_iodim dims[1], howmany_dims[1];

  if (argc < 3)
    {
      fprintf(stdout,"Usage: test_s2_semi_fly bw loops [error_file]\n");
      exit(0);
    }

  bw = atoi(argv[1]);
  loops = atoi(argv[2]);

  /*** ASSUMING WILL SEMINAIVE ALL ORDERS ***/
  cutoff = bw ;

  size = 2*bw;
  total_time = 0.0;
  for_time = 0.0;
  inv_time = 0.0;
  granderror = 0.0;
  grandrelerror = 0.0; 

  /*
    allocate memory
  */

  rcoeffs = (double *) malloc(sizeof(double) * (bw * bw));
  icoeffs = (double *) malloc(sizeof(double) * (bw * bw));
  rdata = (double *) malloc(sizeof(double) * (size * size));
  idata = (double *) malloc(sizeof(double) * (size * size));
  rresult = (double *) malloc(sizeof(double) * (bw * bw));
  iresult = (double *) malloc(sizeof(double) * (bw * bw));
  workspace = (double *) malloc(sizeof(double) * 
				((10 * (bw*bw)) + 
				 (24 * bw)));

  /** space for errors **/
  relerror = (double *) malloc(sizeof(double) * loops);
  curmax = (double *) malloc(sizeof(double) * loops);

  /* make array for weights */
  weights = (double *) malloc(sizeof(double) * 4 * bw);


  /****
    At this point, check to see if all the memory has been
    allocated. If it has not, there's no point in going further.
    ****/
  if ( (rdata == NULL) || (idata == NULL) ||
       (rresult == NULL) || (iresult == NULL) ||
       (rcoeffs == NULL) || (icoeffs == NULL) ||
       (workspace == NULL) || (weights == NULL) )
    {
      perror("Error in allocating memory");
      exit( 1 ) ;
    }

  /*** generate a seed, needed to generate random data ***/
  time(&seed);
  srand48( seed );

  /*
    construct fftw plans
  */

  /* make DCT plans -> note that I will be using the GURU
     interface to execute these plans within the routines*/

  /* forward DCT */
  dctPlan = fftw_plan_r2r_1d( 2*bw, weights, rdata,
			      FFTW_REDFT10, FFTW_ESTIMATE ) ;
      
  /* inverse DCT */
  idctPlan = fftw_plan_r2r_1d( 2*bw, weights, rdata,
			       FFTW_REDFT01, FFTW_ESTIMATE );

  /*
    fftw "preamble" ;
    note that this plan places the output in a transposed array
  */
  rank = 1 ;
  dims[0].n = 2*bw ;
  dims[0].is = 1 ;
  dims[0].os = 2*bw ;
  howmany_rank = 1 ;
  howmany_dims[0].n = 2*bw ;
  howmany_dims[0].is = 2*bw ;
  howmany_dims[0].os = 1 ;
  
  /* forward fft */
  fftPlan = fftw_plan_guru_split_dft( rank, dims,
				      howmany_rank, howmany_dims,
				      rdata, idata,
				      workspace, workspace+(4*bw*bw),
				      FFTW_ESTIMATE );
  
  /*
    now plan for inverse fft - note that this plans assumes
    that I'm working with a transposed array, e.g. the inputs
    for a length 2*bw transform are placed every 2*bw apart,
    the output will be consecutive entries in the array
  */
  rank = 1 ;
  dims[0].n = 2*bw ;
  dims[0].is = 2*bw ;
  dims[0].os = 1 ;
  howmany_rank = 1 ;
  howmany_dims[0].n = 2*bw ;
  howmany_dims[0].is = 1 ;
  howmany_dims[0].os = 2*bw ;

  /* inverse fft */
  ifftPlan = fftw_plan_guru_split_dft( rank, dims,
				       howmany_rank, howmany_dims,
				       rdata, idata,
				       workspace, workspace+(4*bw*bw),
				       FFTW_ESTIMATE );

  /* now make the weights */
  makeweights( bw, weights );

  /*
    now start the looping
  */
  fprintf(stdout,"about to enter loop\n\n");
  for(i=0; i<loops; i++){

    /****
	 loop to generate spherical harmonic coefficients
	 of a real-valued function
    *****/
    for(m=0;m<bw;m++)
      for(l=m;l<bw;l++){
	dumx = 2.0 * (drand48()-0.5);
	dumy = 2.0 * (drand48()-0.5);
	dummy = seanindex(m,l,bw);
	rcoeffs[dummy] = dumx;
	icoeffs[dummy] = dumy;
	dummy = seanindex(-m,l,bw);
	rcoeffs[dummy] = ((double) pow(-1.0, (double) m)) * dumx;
	icoeffs[dummy] = ((double) pow(-1.0, (double) (m + 1))) * dumy;
      }

    /* have to zero out the m=0 coefficients, since those are real */
    for(m=0;m<bw;m++)
      icoeffs[m] = 0.0;

    /* do the inverse spherical transform */
    tstart = csecond();    

    InvFST_semi_fly(rcoeffs,icoeffs,
		    rdata, idata,
		    bw,
		    workspace,
		    1,
		    cutoff,
		    &idctPlan,
		    &ifftPlan );

    tstop = csecond();
    inv_time += (tstop - tstart);
    
    fprintf(stdout,"inv time \t = %.4e\n", tstop - tstart);
    
    /* now do the forward spherical transform */
    tstart = csecond();

    FST_semi_fly(rdata, idata,
		 rresult, iresult,
		 bw,
		 workspace,
		 1,
		 cutoff,
		 &dctPlan,
		 &fftPlan,
		 weights ) ;

    tstop = csecond();    
    for_time += (tstop - tstart);
    
    fprintf(stdout,"forward time \t = %.4e\n", tstop - tstart);

    /* now to compute the error */
    relerror[i] = 0.0;
    curmax[i] = 0.0;
    for(j=0;j<(bw*bw);j++){
      realtmp = rresult[j]-rcoeffs[j];
      imagtmp = iresult[j]-icoeffs[j];
      origmag = sqrt((rcoeffs[j]*rcoeffs[j]) + (icoeffs[j]*icoeffs[j]));
      tmpmag  = sqrt((realtmp*realtmp) + (imagtmp*imagtmp));
      relerror[i] = max(relerror[i],tmpmag/(origmag + pow(10.0, -50.0)));
      curmax[i]  = max(curmax[i],tmpmag);
    }

    fprintf(stdout,"r-o error\t = %.12f\n", curmax[i]);
    fprintf(stdout,"(r-o)/o error\t = %.12f\n\n", relerror[i]);

    granderror += curmax[i];
    grandrelerror += relerror[i];
    
  }

  total_time = inv_time + for_time;

  ave_error = granderror / ( (double) loops );
  ave_relerror = grandrelerror / ( (double) loops );
  stddev_error = 0.0 ; stddev_relerror = 0.0;
  for( i = 0 ; i < loops ; i ++ )
    {
      stddev_error += pow( ave_error - curmax[i] , 2.0 );
      stddev_relerror += pow( ave_relerror - relerror[i] , 2.0 );
    }
  /*** this won't work if loops == 1 ***/
  if( loops != 1 )
    {
      stddev_error = sqrt(stddev_error / ( (double) (loops - 1) ) );
      stddev_relerror = sqrt(stddev_relerror / ( (double) (loops - 1) ) );
    }

  fprintf(stdout,"Program: test_s2_semi_fly\n");
  fprintf(stdout,"Bandwidth = %d\n", bw);

#ifndef WALLCLOCK
  fprintf(stdout,"Total elapsed cpu time :\t\t %.4e seconds.\n",
	  total_time);
  fprintf(stdout,"Average cpu forward per iteration:\t %.4e seconds.\n",
	  for_time/((double) loops));  
  fprintf(stdout,"Average cpu inverse per iteration:\t %.4e seconds.\n",
	  inv_time/((double) loops));
#else
  fprintf(stdout,"Total elapsed wall time :\t\t %.4e seconds.\n",
	  total_time);
  fprintf(stdout,"Average wall forward per iteration:\t %.4e seconds.\n",
	  for_time/((double) loops));  
  fprintf(stdout,"Average wall inverse per iteration:\t %.4e seconds.\n",
	  inv_time/((double) loops));
#endif

  fprintf(stdout,"Average r-o error:\t\t %.4e\t",
	  granderror/((double) loops));
  fprintf(stdout,"std dev: %.4e\n",stddev_error);
  fprintf(stdout,"Average (r-o)/o error:\t\t %.4e\t",
	  grandrelerror/((double) loops));
  fprintf(stdout,"std dev: %.4e\n\n",stddev_relerror);

  if (argc == 4)
    {
      errorsfp = fopen(argv[3],"w");
      for(m = 0 ; m < bw ; m++ )
	{
	  for(l = m ; l< bw ; l++ )
	    {
	      dummy = seanindex(m,l,bw);
	      fprintf(errorsfp,
		      "dummy = %d\t m = %d\tl = %d\t%.10f  %.10f\n",
		      dummy, m, l,
		      fabs(rcoeffs[dummy] - rresult[dummy]),
		      fabs(icoeffs[dummy] - iresult[dummy]));
	      
	      dummy = seanindex(-m,l,bw);	      
	      fprintf(errorsfp,
		      "dummy = %d\t m = %d\tl = %d\t%.10f  %.10f\n",
		      dummy, -m, l,
		      fabs(rcoeffs[dummy] - rresult[dummy]),
		      fabs(icoeffs[dummy] - iresult[dummy]));
	    }
	}
      fclose(errorsfp);
    }

  /* destroy fftw plans */
  fftw_destroy_plan( ifftPlan );
  fftw_destroy_plan( fftPlan );
  fftw_destroy_plan( idctPlan );
  fftw_destroy_plan( dctPlan );

  /* free memory */
  free( weights );
  free(curmax);
  free(relerror);
  free(workspace);
  free(iresult);
  free(rresult);
  free(idata);
  free(rdata);
  free(icoeffs);
  free(rcoeffs);

  return 0 ;

}
示例#3
0
int main ( int argc ,
	   char **argv )
{
  int i, j, m1, m2, bw, n ;
  int loops, m ;
  long int seed ;
  double *coeffs, *signal, *newcoeffs;
  double *wigners, *wignersTrans ;
  double *workspace, *scratch ;
  double *weights ;
  double *sinPts, *cosPts ;
  double *sinPts2, *cosPts2 ;
  double tmp_error, sum_error;
  double tmp_relerror, sum_relerror;
  double tstartA, tstopA, runtimeA ;
  double tstartB, tstopB, runtimeB ;
  double *relerror, *curmax;
  double ave_error, ave_relerror, stddev_error, stddev_relerror ;
  FILE *fp ;

  
  if (argc < 5)
    {
      fprintf(stdout,"Usage: test_Wigner_Naive m1 m2 bw loops [output_file]\n");
      exit(0);
    }

  m1 = atoi( argv[1] );
  m2 = atoi( argv[2] );
  bw = atoi( argv[3] );
  loops = atoi( argv[4] ) ;
  m = MAX( ABS( m1 ) , ABS( m2 ) ) ;
  n = 2 * bw ;
  runtimeA = 0.0 ;
  runtimeB = 0.0 ;

  weights = ( double * ) malloc(sizeof( double ) * (2*bw) ) ;
  coeffs = ( double * ) malloc(sizeof( double ) * (bw - m) ) ;
  newcoeffs = ( double * ) malloc(sizeof( double ) * (bw - m) ) ;
  signal = ( double * ) malloc(sizeof( double ) * n ) ;
  wigners = ( double * ) malloc( sizeof( double ) * ( bw - m ) * n ) ;
  wignersTrans = ( double * ) malloc( sizeof( double ) * ( bw - m ) * n ) ;
  workspace = (double *) malloc(sizeof( double ) * (4 + 6) * n ) ;
  sinPts = workspace ;
  cosPts = sinPts + n ;
  sinPts2 = cosPts + n ;
  cosPts2 = sinPts2 + n ;
  scratch = cosPts2 + n ; /* scratch needs to be of size 6*n */

  /* note that the definition of wigSpec requires that instead of
     evaluating at beta, I need to evaluate at beta/2; ergo I call
     SinEvalPts2 instead of SinEvalPts, etc etc
  */


  /* generate seed for random number generator */
  time ( &seed ) ;
  srand48( seed ) ;

  /* precompute sines and cosines appropriate for making the
     wigners */

  SinEvalPts( n, sinPts ) ;
  CosEvalPts( n, cosPts ) ;
  SinEvalPts2( n, sinPts2 ) ;
  CosEvalPts2( n, cosPts2 ) ;

  /* make quadrature weights */
  makeweights2( bw, weights );

  /* make the wigners */
  genWig_L2( m1, m2, bw,
	     sinPts, cosPts,
	     sinPts2, cosPts2,
	     wigners, scratch ) ;

  /* now make the wigners - transpose version! */
  genWigTrans_L2( m1, m2, bw,
		  sinPts, cosPts,
		  sinPts2, cosPts2,
		  wignersTrans, scratch ) ;

  /** space for errors **/
  relerror = (double *) malloc(sizeof(double) * loops);
  curmax = (double *) malloc(sizeof(double) * loops);

  sum_error = 0.0 ;
  sum_relerror = 0.0 ;

  for ( i = 0 ; i < loops ; i ++ )
    {
      /* generate random coeffs */
      for( j = 0 ; j < (bw - m) ; j++ )
	coeffs[ j ] = drand48() ;
      
      /* turn on stop watch */
      tstartA = csecond () ;

      /* now synthesize */
      wigNaiveSynthesis( m1, m2, bw, coeffs,
			 wignersTrans, signal,
			 scratch ) ;
      tstopA = csecond () ;

      runtimeA += (tstopA - tstartA);

      tstartB = csecond () ;

      /* now analyze */
      wigNaiveAnalysis( m1, m2, bw, signal,
			wigners, weights,
			newcoeffs,
			scratch ) ;

      /* turn off stop watch */
      tstopB = csecond () ;

      runtimeB += (tstopB - tstartB);

      relerror[ i ] = 0.0 ;
      curmax[ i ] = 0.0 ;
      /* now figure out errors */
      for( j = 0 ; j < bw - m ; j ++ )
	{
	  tmp_error = fabs( coeffs[j] - newcoeffs[j] );
	  tmp_relerror = tmp_error / ( fabs( coeffs[j] ) +
				       pow( 10.0, -50.0 ) );
	  curmax[ i ] = MAX( curmax[ i ], tmp_error );
	  relerror[ i ] = MAX( relerror[ i ], tmp_relerror );
	}
      sum_error += curmax[ i ] ;
      sum_relerror += relerror[ i ] ;
    }


  ave_error = sum_error / ( (double) loops );
  ave_relerror = sum_relerror / ( (double) loops );
  stddev_error = 0.0 ; stddev_relerror = 0.0;
  for( i = 0 ; i < loops ; i ++ )
    {
      stddev_error += pow( ave_error - curmax[ i ] , 2.0 );
      stddev_relerror += pow( ave_relerror - relerror[ i ] , 2.0 );
    }
  /*** this won't work if loops == 1 ***/
  if( loops != 1 )
    {
      stddev_error = sqrt(stddev_error / ( (double) (loops - 1) ) );
      stddev_relerror = sqrt(stddev_relerror / ( (double) (loops - 1) ) );
    }


  fprintf(stderr,"bw = %d\tm1 = %d\tm2 = %d\n",bw, m1, m2);
  fprintf(stderr,"total runtime: %.4e seconds\n", runtimeA+runtimeB);

  fprintf(stderr,"average forward runtime: %.4e seconds per iteration\n",
	  runtimeB/((double) loops));
  fprintf(stderr,"average inverse runtime: %.4e seconds per iteration\n",
	  runtimeA/((double) loops));


  fprintf(stderr,"Average r-o error:\t\t %.4e\t",
	  sum_error/((double) loops));
  fprintf(stderr,"std dev: %.4e\n",stddev_error);
  fprintf(stderr,"Average (r-o)/o error:\t\t %.4e\t",
	  sum_relerror/((double) loops));
  fprintf(stderr,"std dev: %.4e\n\n",stddev_relerror);



  if ( argc == 6 )
    {
      fp = fopen(argv[5], "w");
      for ( i = 0 ; i < bw - m ; i ++ )
	fprintf(fp,"%.16f\n", coeffs[i] - newcoeffs[i]);
    }


  free( curmax ) ;
  free( relerror ) ;
  free( workspace ) ;
  free( wignersTrans ) ;
  free( wigners ) ;
  free( signal ) ;
  free( newcoeffs ) ;
  free( coeffs ) ;
  free( weights ) ;

  return 0 ;
}
示例#4
0
int main( int argc,
	  char **argv )
{
  int i, bw, n, n3 ;
  int isReal ;
  int tmpInt ;
  // int l, m1, m2 ;
  // int dummy, format, isReal ;
  double tmpbuf[2] ;
  fftw_complex *signal, *coeffs ;
  double tstartI, tstopI, runtimeI ;
  FILE *fp ;
  
  if (argc < 5)
    {
      fprintf(stdout, "Usage: test_soft_fftw_inv bw coefFile ");
      fprintf(stdout, "sample_file isReal\n");
      exit(0);
    }

  bw = atoi( argv[1] );
  isReal = atoi( argv[4] );

  n = 2 * bw ;
  n3 = n * n * n ;

  /* signal */
  signal = fftw_malloc( sizeof( fftw_complex ) * n3 ) ;

  /* coefficients totalCoeffs_so3( bw) amount of space */
  coeffs = fftw_malloc(sizeof( fftw_complex ) * totalCoeffs_so3( bw ) ) ;

  /* check if any problems allocating memory */
  if ( ( signal == NULL) || ( coeffs == NULL ) )
    {
      perror("Error in allocating memory");
      exit( 1 ) ;
    }

  /* read in coeffs */
  tmpInt = totalCoeffs_so3( bw ) ;
  fp = fopen( argv[2], "r" );
  for ( i = 0 ; i < tmpInt ; i ++ )
    {
      /* first the real part */
      fscanf(fp, "%lf", tmpbuf) ;

      /* now the imaginary part */
      fscanf(fp, "%lf", tmpbuf+1);

      coeffs[i][0] = tmpbuf[0];
      coeffs[i][1] = tmpbuf[1];
    }
  fclose ( fp ) ;

  /* initialize time */
  runtimeI = 0.0 ;

  /* turn on stopwatch */
  tstartI = csecond( ) ;

  Inverse_SO3_Naive_fftw_W( bw,
			    coeffs,
			    signal,
			    isReal ) ;

  /* turn off stopwatch */
  tstopI = csecond( ) ;
  runtimeI += tstopI - tstartI ;
  fprintf(stderr,"inverse time \t = %.4e\n", tstopI - tstartI);

  /* write out samples to disk */
  fp = fopen( argv[ 3 ], "w" );
  if ( isReal ) /* strictly real */
    for ( i = 0 ; i < n3 ; i ++ )
      fprintf(fp, "%.16f\n",
	      signal[ i ][0] ) ;
  else /* complex samples */
    for ( i = 0 ; i < n3 ; i ++ )
      fprintf(fp, "%.16f\n%.16f\n",
	      signal[ i ][0], signal[ i ][1] ) ;

  fclose( fp ) ;


  fftw_free( coeffs );
  fftw_free( signal );

  return 0 ;
}
示例#5
0
int main(int argc, char **argv)
{
  FILE *fp ;
  int i ;
  int bwIn, bwOut, degOut ;
  double alpha, beta, gamma ;
  double *sigInR, *sigInI, *sigOutR, *sigOutI ;
  double *scratch ;
  double tstart, tstop;
  double *seminaive_naive_tablespace, *trans_seminaive_naive_tablespace2;
  double *seminaive_naive_tablespace2 ;
  double **seminaive_naive_table2,**seminaive_naive_table ;
  double **trans_seminaive_naive_table2;
  int splat ;

  if (argc < 9)
    {
      fprintf(stdout, "Usage: test_s2_rotate bwIn bwOut degOut ");
      fprintf(stdout, "alpha beta gamma ");
      fprintf(stdout, "input_filename output_filename\n");
      exit(0);
    }


  bwIn = atoi( argv[ 1 ] );
  bwOut = atoi( argv[ 2 ] );
  degOut = atoi( argv[ 3 ] );
  alpha = (double) atof( argv[ 4 ] );
  beta = (double) atof( argv[ 5 ] );
  gamma = (double) atof( argv[ 6 ] );

  sigInR = (double *) malloc(sizeof(double)*(4*bwIn*bwIn));
  sigInI = (double *) malloc(sizeof(double)*(4*bwIn*bwIn));
  sigOutR = (double *) malloc(sizeof(double)*(4*bwOut*bwOut));
  sigOutI = (double *) malloc(sizeof(double)*(4*bwOut*bwOut));

  if ( bwOut > bwIn )
    scratch = (double *) malloc(sizeof(double)*((14*bwOut*bwOut) + (48 * bwOut)));
  else
    scratch = (double *) malloc(sizeof(double)*((14*bwIn*bwIn) + (48 * bwIn)));

  splat = 0 ;

  seminaive_naive_tablespace =
    (double *) malloc(sizeof(double) *
		      (Reduced_Naive_TableSize(bwIn,bwIn) +
		       Reduced_SpharmonicTableSize(bwIn,bwIn)));

  trans_seminaive_naive_tablespace2 =
    (double *) malloc(sizeof(double) *
		      (Reduced_Naive_TableSize(bwOut,bwOut) +
		       Reduced_SpharmonicTableSize(bwOut,bwOut)));

  seminaive_naive_tablespace2 =
    (double *) malloc(sizeof(double) *
		      (Reduced_Naive_TableSize(bwOut,bwOut) +
		       Reduced_SpharmonicTableSize(bwOut,bwOut)));

  /****
       At this point, check to see if all the memory has been
       allocated. If it has not, there's no point in going further.
  ****/

  if ( (scratch == NULL) || 
       (sigInR == NULL ) || (sigInI == NULL ) ||
       (sigOutR == NULL ) || (sigOutI == NULL ) ||
       (seminaive_naive_tablespace == NULL) ||
       (trans_seminaive_naive_tablespace2 == NULL) )
    {
      perror("Error in allocating memory");
      exit( 1 ) ;
    }
  
  fprintf(stdout,"Generating seminaive_naive tables...\n");
  seminaive_naive_table = SemiNaive_Naive_Pml_Table(bwIn, bwIn,
						    seminaive_naive_tablespace,
						    scratch);

  fprintf(stdout,"Generating seminaive_naive tables...\n");
  seminaive_naive_table2 = SemiNaive_Naive_Pml_Table(bwOut, bwOut,
						    seminaive_naive_tablespace2,
						    scratch);

  fprintf(stdout,"Generating trans_seminaive_naive tables...\n");
  trans_seminaive_naive_table2 =
    Transpose_SemiNaive_Naive_Pml_Table(seminaive_naive_table2,
					bwOut, bwOut,
					trans_seminaive_naive_tablespace2,
					scratch);

  fprintf(stdout,"reading in signal ...\n");

  /* read in signal */
  fp = fopen(argv[7], "r");
  for ( i = 0 ; i < (4*bwIn*bwIn) ; i ++ )
    {
      fscanf(fp,"%lf",sigInR+i);
      fscanf(fp,"%lf",sigInI+i);
    }
  fclose( fp ) ;

  fprintf(stdout,"about to rotate ...\n");
  tstart = csecond();

  rotateFct( bwIn, bwOut, degOut,
	     sigInR, sigInI,
	     sigOutR, sigOutI,
	     alpha, beta, gamma,
	     scratch,
	     seminaive_naive_table,
	     trans_seminaive_naive_table2 ) ;

  tstop = csecond();
  fprintf(stdout,"finished rotating ...\n");
  fprintf(stdout,"rotation time \t = %.4e\n", tstop - tstart);

  /* write out rotated signal */
  fp = fopen(argv[8], "w");
  for ( i = 0 ; i < (4*bwOut*bwOut) ; i ++ )
    {
      fprintf(fp,"%.15f\n%.15f\n",sigOutR[i],sigOutI[i]);
    }
  fclose( fp ) ;
 
  fprintf(stdout,"finished writing ...\n");
 
  free(trans_seminaive_naive_table2);
  free(seminaive_naive_table2);
  free(seminaive_naive_table);
  free(seminaive_naive_tablespace2);
  free(trans_seminaive_naive_tablespace2);
  free(seminaive_naive_tablespace);
 
  free(scratch);
  free(sigOutI);
  free(sigOutR);
  free(sigInI);
  free(sigInR);
 
  return 0 ;
 
}