This file is indexed.

/usr/include/BALL/MATHS/FFT1D.h is in libball1.4-dev 1.4.1+20111206-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#ifndef BALL_MATHS_TFFT1D_H
#define BALL_MATHS_TFFT1D_H

#ifndef BALL_COMMON_EXCEPTION_H
# include <BALL/COMMON/exception.h>
#endif

#ifndef BALL_DATATYPE_REGULARDATA1D_H
# include <BALL/DATATYPE/regularData1D.h>
#endif

#include <math.h>
#include <complex>
#include <fftw3.h>

#include <BALL/MATHS/fftwCommon.h>

namespace BALL
{
	/**  \addtogroup  FFT */
	//@{


	/** A class to perform Fast Fourier Transforms and inverse Fast Fourier Transforms
			on regularly spaced one dimensional data.  \par
			This class makes use of the freely available library <b>FFTW</b>, which can be
			found at http://www.fftw.org
			coordinate system can be handled automatically. The normaliztion is chosen
			symmetrically.
	 */
	template <typename ComplexTraits>
	class TFFT1D 
		: public TRegularData1D<std::complex<typename ComplexTraits::ComplexPrecision> >
	{
		public:

		typedef std::complex<typename ComplexTraits::ComplexPrecision> Complex;
		typedef TRegularData1D<std::complex<typename ComplexTraits::ComplexPrecision> >	ComplexVector;

		BALL_CREATE(TFFT1D)

		/**  @name Constructors and Destructors
		 */
		//@{

		/// Default constructor
		TFFT1D();

		/// Copy constructor
		TFFT1D(const TFFT1D &data);

		/** Detailed constructor.  \par
				@param ldn The binary logarithm of the number of grid points (we use the logarithm to
									 ensure that the number of points is a power of two, which is important for
									 the FFT)
				@param stepPhys The step width in physical space
				@param origin The origin of the coordinate system
				@param inFourierSpace Flag to decide whether the data is assumed to be in physical or fourier
															space
		 */
		 // AR: ldn is not any longer the binary logarithm but the absolute number of grid points
		TFFT1D(Size ldn, double stepPhys = 1., double origin = 0., bool inFourierSpace = false);
		
		/// Destructor
		virtual ~TFFT1D();
		
		//@}

		/** @name Assignment
		 */
		//@{

		/// Assignment operator
		const TFFT1D& operator = (const TFFT1D& fft1d);
		
		/** Clear the contents.
		 */
		virtual void clear();
		
		/** Clear the contents and reset all attributes.
		 */
		virtual void destroy();

		//@}

		/** @name Predicates
		 */
		//@{

		/** Equality operator.
		 */
		bool operator == (const TFFT1D& fft1d) const;
		//@}
		
		// @name Accessors
		
		/** Perform a single fast fourier transform on the data.
		 */
		void doFFT();

		/** Perform a single inverse fourier transform on the data.
		 */
		void doiFFT();

		/** Translate the origin in physical space about <b>  transOrigin </b>.
			If the result is out of bounds, the function does nothing and
			returns <b>  false </b>.
		 */
		bool translate(double trans_origin);

		/** Set the step width in physical space to <b>  newWidth </b>.
			The step width in fourier space is automatically adjusted
			accordingly. <b>  newWidth </b> must be positive, otherwise
			the function does nothing and retuns <b>  false </b>.
		 */
		bool setPhysStepWidth(double new_width);

		/** Returns the step width in physical space.
		 */
		double getPhysStepWidth() const;

		/** Returns the step width in fourier space.
		 */
		double getFourierStepWidth() const;

		/** Returns the minimal position of the grid in physical space.
		 */
		double getPhysSpaceMin() const;

		/** Returns the maximal position of the grid in physical space.
		 */
		double getPhysSpaceMax() const;

		/** Returns the minimal position of the grid in fourier space.
		 */
		double getFourierSpaceMin() const;

		/** Returns the maximal position of the grid in fourier space.
		 */
		double getFourierSpaceMax() const;
			
		/** AR: Return the largest grid position direction. 
		 		This method returns the maximum position allowed in the grid. As the point 
				in the origin has the indices 0, this method returns the number of 
				points minus one.
		 */
		Size getMaxIndex() const;

		/** AR: Return the number of inverse transforms that have been carried out using this class.
			 	This is an important factor for the normalization of the data.
			 */
		Size getNumberOfInverseTransforms() const;
	
		/** AR: Returns the grid coordinate corresponding to the position.
		 */
		double getGridCoordinates(Position position) const;

		/** Returns the data at the grid position closest to <b>  pos </b>,
		 *	and automatically includes
		 * 	the correct phase factor and normalization.
		 *
		 *  @throw Exception::OutOfGrid if pos is outside the grid boundaries
		 */
		Complex getData(const double pos) const;

		/** Returns the data at point <b>pos</b>. If <b>pos</b> is not a 
		 *	point on the grid, the data is linearly interpolated.
		 *	This method automatically includes the correct phase factor
		 *	and normalization.
		 *
		 *  @throw Exception::OutOfGrid if pos is outside the grid boundaries
		 */
		Complex getInterpolatedValue(const double pos) const;

		/** Sets the data point at the grid position closest to <b>  pos </b>
		 *	to the value <b>  val </b>, and -- if called in fourier space --
		 *	automatically includes the correct phase factor and normalization.
		 *
		 *  @throw Exception::OutOfGrid if pos is outside the grid boundaries
		 */
		void setData(double pos, Complex val);

		/** Access the data at the grid position closest to <b>  pos </b>.
		 *  This function returns the "raw" data at that position.
		 *
		 *  @throw Exception::OutOfGrid if pos is outside the grid boundaries
		 */
		Complex& operator [] (const double pos);

		/** Access the data at the grid position closest to <b>  pos </b>.
		 *  This function returns the "raw" data at that position.
		 *
		 *  @throw Exception::OutOfGrid if pos is outside the grid boundaries
		 */
		const Complex& operator [] (const double pos) const;
		
		/** Access the (raw) data at Position pos
		 *
		 *  @throw Exception::OutOfGrid if pos is outside the grid boundaries
		 */
		Complex& operator[](const Position& pos)
		{
			return TRegularData1D<Complex>::operator[](pos);
		}
			
		/** Access the (raw) data at Position pos. Const method.
		 *
		 *  @throw Exception::OutOfGrid if pos is outside the grid boundaries
		 */
		const Complex& operator[](const Position& pos) const
		{
			return TRegularData1D<Complex>::operator[](pos);
		} 
		
		void setNumberOfFFTTransforms(Size num)
		{
			numPhysToFourier_ = num;
		}
			
		void setNumberOfiFFTTransforms(Size num)
		{
			numFourierToPhys_ = num;
		}
		
		/** AR: Returns <b>true</b> if the data is considered to be in Fourier space,
		    <b>false</b> otherwise.
		 */
		bool isInFourierSpace() const;
		
		/** Compute the phase factor.
			This computes the phase factor in fourier space that results
			if the origin of the coordinate system in physical space
			is not in the "lower left corner".
		 */
		Complex phase(const double pos) const;

		protected:

		Size length_;
		bool inFourierSpace_;
		Size numPhysToFourier_;
		Size numFourierToPhys_;
		double origin_;
		double stepPhys_;
		double stepFourier_;
		double minPhys_;
		double maxPhys_;
		double minFourier_;
		double maxFourier_;

		typename ComplexTraits::FftwPlan planForward_;
		typename ComplexTraits::FftwPlan planBackward_;
		
		// AR: to control plan calculation with new fftw3
		Complex *dataAdress_;
		bool planCalculated_;
	};
  //@}
  
  /**	Default type
	*/
	typedef TFFT1D<BALL_FFTW_DEFAULT_TRAITS> FFT1D;
  
  // AR:
	/** Global assignment operator from FFT2D to TRegularData2D<Complex>
	 */
//	const TRegularData1D<Complex>& operator << (TRegularData1D<Complex>& to, const TFFT1D& from)
	//; ?????
	
	/** Global assignment operator from FFT3D to TRegularData3D<float>.
	 		This operator assigns the <b>real</b> part of the complex FFT2D-data to the
			TRegularData2D<float> to.
	 */
//	const RegularData1D& operator << (RegularData1D& to, const TFFT1D& from)
//; ???????



  template <typename ComplexTraits>
	TFFT1D<ComplexTraits>::TFFT1D()
		: TRegularData1D<Complex>(0, 0, 1.),  // AR: old case: This is necessary because FFTW_COMPLEX has no default constructor
			length_(0),
			inFourierSpace_(false),
			dataAdress_(0),
			planCalculated_(false)
	{
	}
		

	template <typename ComplexTraits>
	bool TFFT1D<ComplexTraits>::operator == (const TFFT1D<ComplexTraits>& fft1d) const
	{
		if (ComplexVector::size() == fft1d.size() &&
				origin_ == fft1d.origin_ &&
				stepPhys_ == fft1d.stepPhys_ &&
				stepFourier_ == fft1d.stepFourier_ &&
				minPhys_ == fft1d.minPhys_ &&
				maxPhys_ == fft1d.maxPhys_ &&
				minFourier_ == fft1d.minFourier_ &&
				maxFourier_ == fft1d.maxFourier_ &&
				inFourierSpace_ == fft1d.inFourierSpace_ &&
				numPhysToFourier_ == fft1d.numPhysToFourier_ &&
				numFourierToPhys_ == fft1d.numFourierToPhys_ &&
				planCalculated_ == fft1d.planCalculated_)
		{
			double min  = inFourierSpace_ ?  minFourier_ :  minPhys_;
			double max  = inFourierSpace_ ?  maxFourier_ :  maxPhys_;
			double step = inFourierSpace_ ? stepFourier_ : stepPhys_;
				
			for (double pos=min; pos<=max; pos+=step)
			{
				if (getData(pos) != fft1d.getData(pos))
				{
					return false;
				}
			}
			
			return true;
		}
	
		return false;
	}	

	template <typename ComplexTraits>
	bool TFFT1D<ComplexTraits>::translate(double trans_origin)
	{
		Position internalOrigin = (int) rint(trans_origin/stepPhys_);
		if (internalOrigin <= length_)
		{
			origin_ = trans_origin;

      minPhys_ = ((-1.)*origin_);
      maxPhys_ = (((length_-1)*stepPhys_)-origin_);
      minFourier_ = ((-1.)*(length_/2.-1)*stepFourier_);
      maxFourier_ = ((length_/2.)*stepFourier_);
      
			return true;
		}
		else
		{
			return false;
		}
	}

	template <typename ComplexTraits>
	bool TFFT1D<ComplexTraits>::setPhysStepWidth(double new_width)
	{
		if (new_width < 0)
		{
			return false;
		}
		else
		{
			stepPhys_ = new_width;
			stepFourier_ = 2.*M_PI/(stepPhys_*length_);

      minPhys_ = ((-1.)*origin_);
      maxPhys_ = (((length_-1)*stepPhys_)-origin_);
      minFourier_ = ((-1.)*(length_/2.-1)*stepFourier_);
      maxFourier_ = ((length_/2.)*stepFourier_);

      return true;
		}
	}

	template <typename ComplexTraits>	
	double TFFT1D<ComplexTraits>::getPhysStepWidth() const
	{
		return stepPhys_;
	}

	template <typename ComplexTraits>
	double TFFT1D<ComplexTraits>::getFourierStepWidth() const
	{
		return stepFourier_;
	}

	template <typename ComplexTraits>
	double TFFT1D<ComplexTraits>::getPhysSpaceMin() const
	{
    return minPhys_;
  }

	template <typename ComplexTraits>
	double TFFT1D<ComplexTraits>::getPhysSpaceMax() const
	{
    return maxPhys_;
 	}

	template <typename ComplexTraits>
	double TFFT1D<ComplexTraits>::getFourierSpaceMin() const
	{
		return minFourier_;
	}

	template <typename ComplexTraits>
	double TFFT1D<ComplexTraits>::getFourierSpaceMax() const
	{
		return maxFourier_;
	}

	template <typename ComplexTraits>	
	Size TFFT1D<ComplexTraits>::getMaxIndex() const
	{
		return (length_ - 1);
	}

	template <typename ComplexTraits>	
	Size TFFT1D<ComplexTraits>::getNumberOfInverseTransforms() const
	{
		return numFourierToPhys_;
	}
	
	// AR: new 
	template <typename ComplexTraits>
	double TFFT1D<ComplexTraits>::getGridCoordinates(Position position) const
	{
		if (!inFourierSpace_)
		{
			if (position >= ComplexVector::size())
			{
				throw Exception::OutOfGrid(__FILE__, __LINE__);
			}
		
			double r;
			
			r = -origin_ + (float)position * stepPhys_;

			return r;
		}
		else
		{
			if (position >= ComplexVector::size())
			{
				throw Exception::OutOfGrid(__FILE__, __LINE__);
			}
		
			double r;
			Index x;
	
			x = position;

			if (x>=length_/2.)
			{
				x-=length_;
			}
			
			r = (float)x * stepFourier_;

			return r;
		}
	}

	template <typename ComplexTraits>
	typename TFFT1D<ComplexTraits>::Complex TFFT1D<ComplexTraits>::getData(const double pos) const
	{
		Complex result;
		double normalization=1.;

		if (!inFourierSpace_)
		{
			result = (*this)[pos];//Complex((*this)[pos].real(), (*this)[pos].imag());
			normalization=1./pow((double)length_,(int)numFourierToPhys_);
		}
		else
		{
			result = (*this)[pos]*phase(pos);//Complex((*this)[pos].real(),(*this)[pos].imag()) * phase(pos);
			//Log.error() << pos <<  " " << phase(pos).real() <<  std::endl;
			normalization=1./(sqrt(2.*M_PI))/pow((double)length_,(int)numFourierToPhys_);
		}

		result *= normalization;
		
		return result;
	}

	template <typename ComplexTraits>
	typename TFFT1D<ComplexTraits>::Complex TFFT1D<ComplexTraits>::getInterpolatedValue(const double pos) const
	{
		Complex result;
		
		double min  = inFourierSpace_ ? minFourier_  :  minPhys_;
		double max  = inFourierSpace_ ? maxFourier_  :  maxPhys_;
		double step = inFourierSpace_ ? stepFourier_ : stepPhys_;
		
		if ((pos < min) || (pos > max))
		{
			throw Exception::OutOfGrid(__FILE__, __LINE__);
		}

		double h = pos - min;
		double mod = fmod(h,step);

		if (mod ==0) // we are on the grid
		{
			return getData(pos);
		}

		double before = floor(h/step)*step+ min;
		double after  = ceil(h/step)*step+ min;
			
		double t = (pos - before)/step;

		result  =  getData(before)*(typename ComplexTraits::ComplexPrecision)(1.-t);
		result +=  getData(after)*(typename ComplexTraits::ComplexPrecision)t; 

		return result;
	}

	template <typename ComplexTraits>
	void TFFT1D<ComplexTraits>::setData(double pos, Complex val)
	{
		Complex dummy;
		if (!inFourierSpace_)
		{
			dummy = Complex(val.real()*((typename ComplexTraits::ComplexPrecision)pow((typename ComplexTraits::ComplexPrecision)(length_),(int)numFourierToPhys_)),
											 val.imag()*((typename ComplexTraits::ComplexPrecision)pow((typename ComplexTraits::ComplexPrecision)(length_),(int)numFourierToPhys_)));
	
			(*this)[pos]=dummy;
		}
		else
		{
			val*=phase(pos)*(typename ComplexTraits::ComplexPrecision)((sqrt(2*M_PI)/stepPhys_))
										 *(typename ComplexTraits::ComplexPrecision)pow((typename ComplexTraits::ComplexPrecision)length_,(int)numFourierToPhys_);
			
			dummy = val;
			
			(*this)[pos]=dummy;
		}
	}

	template <typename ComplexTraits>
	typename TFFT1D<ComplexTraits>::Complex& TFFT1D<ComplexTraits>::operator[](const double pos) 
	{
		Index internalPos;

		if (!inFourierSpace_)
		{
			internalPos = (Index) rint((pos+origin_)/stepPhys_);
		}
		else
		{
			internalPos =  (Index) rint(pos/stepFourier_);

			if (internalPos < 0)
			{
				internalPos+=length_;
			}
		}

		if ((internalPos < 0) || (internalPos>=(Index) length_))
		{
			throw Exception::OutOfGrid(__FILE__, __LINE__);
		}
		
		return operator [] ((Position)internalPos);
	}

	template <typename ComplexTraits>
	const typename TFFT1D<ComplexTraits>::Complex& TFFT1D<ComplexTraits>::operator[](const double pos) const
	{
		Index internalPos;

		if (!inFourierSpace_)
		{
			internalPos = (Index) rint((pos+origin_)/stepPhys_);
		}
		else
		{
			internalPos =  (Index) rint(pos/stepFourier_);

			if (internalPos < 0)
			{
				internalPos+=length_;
			}
		}

		if ((internalPos < 0) || (internalPos>=(Index) length_))
		{
			throw Exception::OutOfGrid(__FILE__, __LINE__);
		}
		
		return operator [] ((Position)internalPos);
	}

	template <typename ComplexTraits>
	typename TFFT1D<ComplexTraits>::Complex TFFT1D<ComplexTraits>::phase(const double pos) const
	{
	  double phase = 2.*M_PI*(rint(pos/stepFourier_))
		                     *(rint(origin_/stepPhys_))
		                     /length_;
		Complex result = Complex(cos(phase), sin(phase));
						
		return result;
	}

	template <typename ComplexTraits>
	bool TFFT1D<ComplexTraits>::isInFourierSpace() const
	{
		return inFourierSpace_;
	}
/*	
	const TRegularData1D<Complex >& operator << (TRegularData1D<Complex >& to, const TFFT1D<ComplexTraits>& from)
	{
		// first decide if the TFFT1D data is in Fourier space.
		if (!from.isInFourierSpace())
		{
			// create a new grid
			Size lengthX = from.getMaxIndex()+1;
			
			TRegularData1D<Complex > newGrid(TRegularData1D<Complex >::IndexType(lengthX), from.getPhysSpaceMin(), from.getPhysSpaceMax());

			// and fill it
			double normalization=1./(pow((float)(lengthX),from.getNumberOfInverseTransforms()));
			
			for (Position i = 0; i < from.size(); i++)
			{
				newGrid[i] = from[i]*(ComplexTraits::ComplexPrecision)normalization;
			}

			to = newGrid;

			return to;
		}
		else
		{
			// we are in Fourier space
			
			// create a new grid
			Size lengthX = from.getMaxIndex()+1;
			//float stepPhysX = from.getPhysStepWidthX();
			float stepFourierX = from.getFourierStepWidth();

			
			TRegularData1D<Complex > newGrid(TRegularData1D<Complex >::IndexType(lengthX),
																			from.getFourierSpaceMin(), 
																			from.getFourierSpaceMax());

			// and fill it
			// AR: old double normalization=1./(sqrt(2.*M_PI))*(stepPhysX*stepPhysY*stepPhysZ)/(pow((float)(lengthX*lengthY*lengthZ),from.getNumberOfInverseTransforms()));
			double normalization=1./sqrt(2.*M_PI)/(pow((float)(lengthX),from.getNumberOfInverseTransforms()));
			
			
			Index x;
			float r;
	
			for (Position i = 0; i < from.size(); i++)
			{
				x = i;

				if (x>lengthX/2.)
				{
					x-=lengthX;
				}

				r = (float)x * stepFourierX;

				newGrid[i] = from[i]*(ComplexTraits::ComplexPrecision)normalization*from.phase(r);
			}

			to = newGrid;

			return to;
		}
	}
	*/
	
	template <typename ComplexTraits>
	const RegularData1D& operator << (RegularData1D& to, const TFFT1D<ComplexTraits>& from)
	{
		// first decide if the FFT1D data is in Fourier space.
		if (!from.isInFourierSpace())
		{
			// create a new grid
			Size lengthX = from.getMaxIndex()+1;
			
			RegularData1D newGrid(lengthX);
			newGrid.setOrigin(from.getPhysSpaceMin());
			newGrid.setDimension(from.getPhysSpaceMax()-from.getPhysSpaceMin());

			// and fill it
			double normalization = 1./(pow((float)(lengthX),from.getNumberOfInverseTransforms()));
			
			for (Position i = 0; i < from.size(); i++)
			{
				newGrid[i] = from[i].real()*normalization;
			}

			to = newGrid;

			return to;
		}
		else
		{
			// we are in Fourier space
			
			// create a new grid
			Size lengthX = from.getMaxIndex()+1;
			//float stepPhysX = from.getPhysStepWidth();
			float stepFourierX = from.getFourierStepWidth();

			RegularData1D newGrid(lengthX);
			newGrid.setOrigin(from.getFourierSpaceMin());
			newGrid.setDimension(from.getFourierSpaceMax()-from.getFourierSpaceMin());

			// and fill it
			// AR: old version double normalization=1./(sqrt(2.*M_PI))*(stepPhysX*stepPhysY*stepPhysZ)/(pow((float)(lengthX*lengthY*lengthZ),from.getNumberOfInverseTransforms()));
			double normalization=1./sqrt(2.*M_PI)/(pow((float)(lengthX),from.getNumberOfInverseTransforms()));
			
			Index x;
			signed int xp;
			float r;
	
			for (Position i = 0; i < from.size(); i++)
			{
				x =  i;
				
				xp = x;

				if (xp>=lengthX/2.)
				{
					xp-=(int)lengthX;
				}

				if (x>=lengthX/2.)
				{
					x-=(int)(lengthX/2.);
				}
				else
				{
					x+=(int)(lengthX/2.);
				}


				r = ((float)xp * stepFourierX);

				newGrid[i] = (from[i]*(typename ComplexTraits::ComplexPrecision)normalization*from.phase(r)).real();
			}

			to = newGrid;

			return to;
		}
	}
}
#endif // BALL_MATHS_TFFT1D_H