diff --git a/StationSim/src/ArrayConfig.cc b/StationSim/src/ArrayConfig.cc
new file mode 100644
index 0000000000000000000000000000000000000000..97e6598d165b3fabbc7cf67afbfd55c69d6af65e
--- /dev/null
+++ b/StationSim/src/ArrayConfig.cc
@@ -0,0 +1,36 @@
+//  ArrayConfig.cc
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+
+#include <DataGen/ArrayConfig.h>
+
+
+ArrayConfig::ArrayConfig (string config_file)
+{
+  ifstream s (config_file.c_str (), ifstream::in);
+
+  int n;
+
+  s >> n;
+  itsPointX.resize (n);
+  itsPointY.resize (n);
+  s >> itsPointX;
+  s >> itsPointY;
+}
diff --git a/StationSim/src/ArrayConfig.h b/StationSim/src/ArrayConfig.h
new file mode 100644
index 0000000000000000000000000000000000000000..20dc999b37f2d414d7758432504079153f2acccd
--- /dev/null
+++ b/StationSim/src/ArrayConfig.h
@@ -0,0 +1,62 @@
+//  ArrayConfig.h
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//
+
+#ifndef DATAGEN_ARRAY_CONFIG_H
+#define DATAGEN_ARRAY_CONFIG_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Common/Lorrays.h>
+#include <Common/Debug.h>
+#include <fstream.h>
+
+class ArrayConfig 
+{
+public:
+
+  ArrayConfig (string config_file);
+
+  // returns the coordinates
+  const LoVec_double& getPointX () const
+  {
+    return itsPointX;
+  }
+  
+  const LoVec_double& getPointY () const
+  {
+    return itsPointY;
+  }
+
+  int size () const 
+  {
+    return itsPointX.size ();
+  }
+
+private:
+
+  LoVec_double itsPointX;
+  LoVec_double itsPointY;
+};
+
+#endif
\ No newline at end of file
diff --git a/StationSim/src/DataGenConfig.cc b/StationSim/src/DataGenConfig.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ddcd50e368ac8cc5e1537c55785c74d3605f8aa3
--- /dev/null
+++ b/StationSim/src/DataGenConfig.cc
@@ -0,0 +1,58 @@
+//  DataGenConfig.cc
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+
+#include <DataGen/DataGenConfig.h>
+
+
+DataGenerator::DataGenerator (string config_file)
+{
+  ifstream configfile (config_file.c_str (), ifstream::in);
+  string s;
+  int i = 0;
+
+  while (!configfile.eof () && configfile.is_open ()) {
+    s = "";
+    configfile >> s;
+    if (s == "length") {
+      configfile >> s;
+      if (s == ":") {
+		configfile >> itsLength;
+	  }
+    } else if (s == "nsources") {
+      configfile >> s;
+      if (s == ":") {
+		configfile >> itsNumberOfSources;
+	  }
+    } else if (s == "SignalFilename") {
+      configfile >> s;
+      if (s == ":") {
+		configfile >> s;
+	  }
+      itsSources[i++] = new Source (s);
+    } else if (s == "ArrayFilename") {
+      configfile >> s;
+      if (s == ":") {
+		configfile >> s;
+	  }
+      itsArray = new ArrayConfig (s);
+    }
+  }
+}
diff --git a/StationSim/src/DataGenConfig.h b/StationSim/src/DataGenConfig.h
new file mode 100644
index 0000000000000000000000000000000000000000..79878be8d9df6d3d4d380deae4adb61499a79f5a
--- /dev/null
+++ b/StationSim/src/DataGenConfig.h
@@ -0,0 +1,51 @@
+//  DataGenConfig.h
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//
+
+#ifndef DATAGEN_DATAGEN_CONFIG_H
+#define DATAGEN_DATAGEN_CONFIG_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Common/Debug.h>
+#include <DataGen/ArrayConfig.h>
+#include <DataGen/Source.h>
+#include <string>
+#include <fstream.h>
+
+#define MAX_SOURCES 100
+
+
+class DataGenerator 
+{
+public:
+
+  DataGenerator (string config_file);
+
+  ArrayConfig *itsArray;
+  int itsNumberOfSources;
+  double itsLength;
+  Source *itsSources[MAX_SOURCES];
+};
+
+#endif
diff --git a/StationSim/src/FFTW.cc b/StationSim/src/FFTW.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f1b2f2d5db715dbf8a7fdb7b2976d1bf618f48ce
--- /dev/null
+++ b/StationSim/src/FFTW.cc
@@ -0,0 +1,71 @@
+//  FFTW.cc:
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//
+
+#include <DataGen/FFTW.h>
+
+using namespace blitz;
+
+namespace FFTW 
+{ 
+  void do_fft (LoVec_dcomplex& data, 
+			   int nfft, 
+			   int nbins, 
+			   Plan plan,
+			   Direction dir) 
+  {
+    // create local fftw plan if not supplied
+    bool created;
+    if (plan) {
+       created = false;
+	} else {
+	  plan = initPlan (nfft, dir, FFTW_IN_PLACE);
+	}
+
+    int stride = data.stride (0);
+
+	fftw (plan, 
+		  nbins, 
+		  reinterpret_cast < fftw_complex * >(data.data ()), 
+		  stride,
+		  nfft * stride, 
+		  NULL, 
+		  0, 
+		  0);
+
+    // destroy local fftw plan
+    if (created) {
+       deletePlan (plan);
+	}
+  }
+
+  // transform of all-real data
+  LoVec_dcomplex forward_fft (const LoVec_double& data, 
+							  int nfft,
+							  int nbins, 
+							  Plan plan) 
+  {
+    LoVec_dcomplex cdata (data.size ());
+    cdata = data + dcomplex (0, 0);
+    forward_fft (cdata, nfft, nbins, plan);
+    return cdata;
+  }
+};				// namespace FFTW
diff --git a/StationSim/src/FFTW.h b/StationSim/src/FFTW.h
new file mode 100644
index 0000000000000000000000000000000000000000..d93be826c37d88792c8e3d89a11f17083db86674
--- /dev/null
+++ b/StationSim/src/FFTW.h
@@ -0,0 +1,98 @@
+//  FFTW.h:
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//
+
+#ifndef DATAGEN_WFFT_H
+#define DATAGEN_WFFT_H 1
+
+#include <Common/Debug.h>
+#include <Common/Lorrays.h>
+#include <fftw.h>
+
+namespace FFTW 
+{
+  typedef fftw_plan Plan;
+  typedef fftw_direction Direction;
+
+  // Does in-place forward or inverse FFTs (nbins transforms of length 
+  // nfft each)
+  // data must be an nbins*nfft vector.
+  // If plan is =0, creates & destroys a local plan, otherwise uses the 
+  // supplied plan (must be a valid plan for an in-place complex transform).
+  // If plan=0, then a direction must be supplied.
+  void do_fft (LoVec_dcomplex& data, 
+			   int nfft, 
+			   int nbins, 
+			   Plan plan,
+			   Direction dir);
+
+  // simple aliases for do_fft
+  inline void forward_fft (LoVec_dcomplex& data, 
+						   int nfft, 
+						   int nbins,
+						   Plan plan = 0) 
+	{
+	  do_fft (data, nfft, nbins, plan, FFTW_FORWARD);
+	}
+ 
+  inline void inverse_fft (LoVec_dcomplex& data, 
+						   int nfft, 
+						   int nbins,
+						   Plan plan = 0) 
+	{
+	  do_fft (data, nfft, nbins, plan, FFTW_BACKWARD);
+	}
+
+  // Version of forward transform for all-real data
+  // (imaginary part is filled in as being all =0). 
+  // Plan must be either 0 or a valid forward, in-place plan
+  LoVec_dcomplex forward_fft (const LoVec_double& data, 
+							  int nfft,
+							  int nbins, 
+							  Plan plan = 0);
+
+
+  // Initializes a forward, in-place plan
+  inline Plan initPlan (int nfft, Direction dir, int flags = FFTW_IN_PLACE) 
+	{
+	  return fftw_create_plan (nfft, dir, flags);
+	}
+
+  // Initializes a forward, in-place plan
+  inline Plan initForwardPlan (int nfft) 
+	{
+	  return initPlan (nfft, FFTW_FORWARD);
+	}
+
+  // Initializes a backward, in-place plan
+  inline Plan initInversePlan (int nfft) 
+	{
+	  return initPlan (nfft, FFTW_BACKWARD);
+	}
+
+  // Destroys a plan
+  inline void deletePlan (Plan plan) 
+	{
+	  return fftw_destroy_plan (plan);
+	}
+};				// namespace FFTW
+
+#endif
diff --git a/StationSim/src/Makefile.am b/StationSim/src/Makefile.am
index dc251718e60c99bfb765cac004199c3e09dad4cd..4d3896d35133f1e2cf4f86b97dc367e2c2beeb98 100644
--- a/StationSim/src/Makefile.am
+++ b/StationSim/src/Makefile.am
@@ -1,9 +1,4 @@
 DOCHDRS		 	= 			\
-DH_RCU.h					\
-WH_RCU.h					\
-WH_RCUAdd.h					\
-WH_Merge.h					\
-WH_RCUAll.h					\
 DH_SampleR.h					\
 DH_SampleC.h					\
 WH_BandSep.h					\
@@ -11,26 +6,15 @@ DH_SubBandSel.h					\
 WH_SubBandSel.h					\
 WH_Selector.h					\
 DH_Weight.h					\
-DH_TargetTrack.h				\
-WH_TargetTrack.h				\
-DH_RFITrack.h					\
-WH_RFITrack.h					\
 WH_BeamFormer.h					\
 WH_AWE.h					\
-WH_Analysis.h					\
 WH_Detection.h					\
 WH_Calibration.h				\
-WH_Cancel.h					\
-WH_VerifyRFI.h
+WH_Cancel.h					
 
 lib_LTLIBRARIES 	= libstationsim.la
 
 libstationsim_la_SOURCES 	= $(DOCHDRS)	\
-DH_RCU.cc					\
-WH_RCU.cc					\
-WH_RCUAdd.cc					\
-WH_Merge.cc					\
-WH_RCUAll.cc					\
 DH_SampleR.cc					\
 DH_SampleC.cc					\
 WH_BandSep.cc					\
@@ -38,18 +22,12 @@ DH_SubBandSel.cc				\
 WH_SubBandSel.cc				\
 WH_Selector.cc					\
 DH_Weight.cc					\
-DH_TargetTrack.cc				\
-WH_TargetTrack.cc				\
-DH_RFITrack.cc					\
-WH_RFITrack.cc					\
 WH_BeamFormer.cc				\
 WH_AWE.cc					\
-WH_Analysis.cc					\
 StationSim.cc					\
 WH_Detection.cc					\
 WH_Calibration.cc				\
-WH_Cancel.cc					\
-WH_VerifyRFI.cc
+WH_Cancel.cc					
 
 bin_PROGRAMS		= Simulate
 Simulate_SOURCES 	= Simulate.cc Simulate.in
diff --git a/StationSim/src/Modulate.cc b/StationSim/src/Modulate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..47b817461efbff696d5a830e87e9af2543e33fbc
--- /dev/null
+++ b/StationSim/src/Modulate.cc
@@ -0,0 +1,178 @@
+//  Modulate.cc:
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//
+
+#include <Common/ArrayOperations.h>
+#include <DataGen/Modulate.h>
+#include <fftw.h>
+#include <rfftw.h>
+
+double theP;
+
+// implements the cumsum() function for blitz vectors:
+// (if y = cumsum(x), then y[tensor::i] = sum(x[0:tensor::i]))
+template < class T >
+    blitz::Array < T, 1 > cumsum (const blitz::Array < T, 1 > &x)
+{
+  using blitz::Array;
+
+  Array < T, 1 > y (x.size ());
+  T sum = 0;
+  typename Array < T, 1 >::iterator out = y.begin ();
+
+  for (typename Array < T, 1 >::const_iterator in = x.begin (); in != x.end (); ++in, ++out) {
+    *out = sum += *in;
+  }
+  return y;
+}
+
+template blitz::Array < double, 1 > cumsum (const blitz::Array < double, 1 > &x);
+
+namespace modulate 
+{
+  // copied from ArrayOperations.cc, since I can't be bothered to fix that right
+  // now
+  LoVec_dcomplex hilbert (const LoVec_double& input) 
+  {
+    int N = input.size ();
+	int	centre;
+    rfftwnd_plan fftplancomplex_forward = rfftwnd_create_plan (1, 
+															   &N, 
+															   FFTW_REAL_TO_COMPLEX,
+															   FFTW_ESTIMATE);
+    fftw_plan fftplancomplex_backward =	fftw_create_plan (N, FFTW_BACKWARD, FFTW_ESTIMATE);
+    LoVec_dcomplex output (N);
+
+    rfftwnd_one_real_to_complex (fftplancomplex_forward,
+								 (fftw_real *) input.data (),
+								 (fftw_complex *) output.data ());
+
+    if (N % 2 != 0) {
+      centre = N / 2;
+	} else {
+      centre = N / 2 - 1;
+	}
+
+    output (Range (1, centre)) *= 2;
+    fftw_one (fftplancomplex_backward, 
+			  (fftw_complex *) output.data (),
+			  (fftw_complex *) output.data ());
+    output /= N;
+
+
+    rfftwnd_destroy_plan (fftplancomplex_forward);
+    fftw_destroy_plan (fftplancomplex_backward);
+
+    return output;
+  }
+
+  // AM, double sideband, suppressd carrier   
+  // y = x*cos(2*pi*fc*t)  
+  LoVec_double amdsb (const LoVec_double &x,
+					  double fc, 
+					  double fs, 
+					  double phase) 
+  {
+    LoVec_double y (x.size ());
+
+    y = x * cos (2 * M_PI * fc * (tensor::i / fs + phase));
+    
+	return y;
+  }
+
+  // AM, double sideband, transmitted carrier   
+  // y = (x-opt)*cos(2*pi*fc*t)  
+  LoVec_double amdsb_tc (const LoVec_double& x,
+						 double fc, 
+						 double fs, 
+						 double phase, 
+						 double opt) 
+  {
+    LoVec_double y (x.size ());
+
+    if (opt == 0) {
+      opt = min (x);
+	}
+    
+	y = (x - opt) * cos (2 * M_PI * fc * (tensor::i / fs + phase));
+    
+	return y;
+  }
+
+  // AM, single sideband
+  // y = x*cos(2*pi*fc*t) + imag(hilbert(x))*sin(2*pi*fc*t)
+  LoVec_double amssb (const LoVec_double& x,
+					  double fc, 
+					  double fs, 
+					  double phase) 
+  {
+    LoVec_double y (x.size ());
+
+    y = x * cos (2 * M_PI * fc * (tensor::i / fs + phase)) +
+	  imag (hilbert (x)) * sin (2 * M_PI * fc * (tensor::i / fs + phase));
+
+    return y;
+  }
+
+  // FM
+  // y = cos(2*pi*fc*t + opt*cumsum(x))
+  LoVec_double fm (const LoVec_double& x,
+				   double fc,	
+				   double fs,	
+				   double opt,	
+				   double phase) 
+  {
+    LoVec_double y (x.size ());
+
+    if (opt == 0) {
+      opt = (fc / fs) * 2 * M_PI * max (x);
+	}
+
+    LoVec_double c = x;
+    c (0) += theP;
+    c = cumsum (c);
+    theP = c (x.size () - 1);
+    c *= opt;
+
+    y = cos (2 * M_PI * fc * (tensor::i / fs + phase) + c);
+
+    return y;
+  }
+
+  // PM
+  // y = cos(2*pi*fc*t + opt*x)
+  LoVec_double pm (const LoVec_double& x,
+				   double fc,	
+				   double fs,	
+				   double opt,	
+				   double phase) 
+  {
+    LoVec_double y (x.size ());
+
+    if (opt == 0) {
+      opt = M_PI / max (x);
+	}
+
+    y = cos (2 * M_PI * fc * (tensor::i / fs + phase) + opt * x);
+
+    return y;
+  }
+}				// namespace modulate
diff --git a/StationSim/src/Modulate.h b/StationSim/src/Modulate.h
new file mode 100644
index 0000000000000000000000000000000000000000..4c5b6a691c1b3abc21f0d930ca50f89dd8870ca1
--- /dev/null
+++ b/StationSim/src/Modulate.h
@@ -0,0 +1,80 @@
+//  Modulate.h:
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//
+
+#ifndef DATAGEN_MODULATE_H
+#define DATAGEN_MODULATE_H 1
+
+#include <Common/Debug.h>
+#include <Common/Lorrays.h>
+
+// implements the cumsum() function for blitz vectors:
+// (if y = cumsum(x), then y[i] = sum(x[0:i]))
+template < class T >
+    blitz::Array < T, 1 > cumsum (const blitz::Array < T, 1 > &x);
+
+using namespace blitz;
+
+namespace modulate 
+{
+  // AM, double sideband, suppreseed carrier
+  // y = x*cos(2*pi*fc*t)
+  LoVec_double amdsb (const LoVec_double & x,	// input time series
+					  double fc,	// carrier frequency
+					  double fs,	// sampling frequency
+					  double phase);	// phase offset for carrier frequency
+
+  // AM, double sideband, transmitted carrier
+  // y = (x-opt)*cos(2*pi*fc*t)
+  // if opt is not supplied, min(x) is used
+  LoVec_double amdsb_tc (const LoVec_double & x,	// input time series
+						 double fc,	// carrier frequency
+						 double fs,	// sampling frequency
+						 double phase,	// phase
+						 double opt = 0);	// base
+  
+  // AM, single sideband
+  // y = x*cos(2*pi*fc*t) + imag(hilbert(x))*sin(2*pi*fc*t)
+  // not yet implemented
+  LoVec_double amssb (const LoVec_double & x,	// input time series
+					  double fc,	// carrier frequency
+					  double fs,	// sampling frequency
+					  double phase);
+  
+  // FM
+  // y = cos(2*pi*fc*t + opt*cumsum(x))
+  LoVec_double fm (const LoVec_double & x,	// input time series
+				   double fc,	// carrier frequency
+				   double fs,	// sampling frequency 
+				   double opt,	// determines excursion in fq
+				   double phase);
+  
+  // PM
+  // y = cos(2*pi*fc*t + opt*x)
+  LoVec_double pm (const LoVec_double & x,	// input time series
+				   double fc,	// carrier frequency
+				   double fs,	// sampling frequency 
+				   double opt,	// determines excursion in phase
+				   double phase);
+  
+};				// namespace modulate
+
+#endif
diff --git a/StationSim/src/PhaseShift.cc b/StationSim/src/PhaseShift.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7bb1f7f78f2ffdfe60966e4b6f8441904284f335
--- /dev/null
+++ b/StationSim/src/PhaseShift.cc
@@ -0,0 +1,136 @@
+//  PhaseShift.cc:
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//
+
+#include <DataGen/PhaseShift.h>
+
+namespace PhaseShift 
+{
+  using namespace blitz;
+
+  // Applies antenna phase to a source & antenna pair.
+  // 
+  // input_signal is the source signal,
+  // doa is its direction-of-arrival at the antenna;
+  // freq_shift is a precomputed frequency shift vector:
+  //    (((i - nfft/2.0 + 1)*freq_resolution + center_freq)/center_freq);
+  // fft_plans are fftw forward/reverse transform plans (use {0,0} to have
+  // them created locally)
+  LoVec_dcomplex applyAntennaPhase (int nfft, 
+									int nbins, 
+									const LoVec_dcomplex& input_signal,
+									const LoVec_double& freq_shift,
+									double doa,
+									FFTW::Plan invplan) 
+  {
+    // compute the freq shift vector for this antenna
+    LoVec_dcomplex fs (nfft);
+	fs = exp (dcomplex (0, 1) * freq_shift * doa);
+    
+	// make copy of input signal
+    LoVec_dcomplex result = input_signal.copy ();
+    
+	// apply frequency shift repeatedly to each bin of signal
+    for (int i0 = 0; i0 < input_signal.size (); i0 += nfft) {
+       result (Range (i0, i0 + nfft - 1)) *= fs;
+	}
+
+	dprintf1 (2) ("inverse fft length %d bins %d\n", nfft, nbins);
+
+    // do inverse fft
+	FFTW::inverse_fft (result, nfft, nbins, invplan);
+	
+	return result;
+  }
+
+  // Phase-shifts a source for the given array configuration
+  // Returns [n_antennas,signal_length] matrix
+  // freq_shift is a precomputed frequency shift vector, determined via
+  // bandwidth and center freq.:
+  //    LoVec_double freq_shift(nfft);
+  //    firstIndex i;//    freq_shift = (((i - nfft/2.0 + 1)*freq_res + centerFreq)/centerFreq;
+  LoMat_dcomplex phaseShift (int nfft, 
+							 const LoVec_double& source, 
+							 const double theta, 
+							 const double phi, 
+							 const ArrayConfig& antennas, 
+							 const LoVec_double& freq_shift, 
+							 FFTW::Plan fwdplan,
+							 FFTW::Plan invplan) 
+  {
+    // truncate input signal data to a multiple of nfft (nbins*nfft)
+    int siglen = source.size ();
+    int nbins = siglen / nfft;	// number of fft bins
+
+    siglen = nbins * nfft;
+    LoVec_double datavec = source (Range (0, siglen - 1));
+
+    dprintf1 (1) ("phase shifting source, siglen=%d, nfft=%d, nbins=%d\n", siglen, nfft, nbins);
+
+    // do forward fft of source
+    LoVec_dcomplex cdata = FFTW::forward_fft (source (Range (0, siglen - 1)), nfft, nbins, fwdplan);
+
+    dprintf1 (1) ("foward fft done\n");
+
+    // compute vector of doas (per each antenna)
+    LoVec_double doa = DOA (antennas.getPointX (), antennas.getPointY (), theta, phi);
+
+    // this is the output matrix: one column of signal per each antenna
+    LoMat_dcomplex phased_signal (antennas.size (), siglen);
+
+    dprintf1 (1) ("applying phases for %d antennas\n", antennas.size ());
+
+    // loop over all antennas  
+    for (int iant = 0; iant < antennas.size (); iant++) {
+      phased_signal (iant, Range::all ()) = applyAntennaPhase (nfft, 
+															   nbins, 
+															   cdata, 
+															   freq_shift,
+															   doa (iant), 
+															   invplan);
+    }
+    dprintf1 (1) ("done\n");
+
+    return phased_signal;
+  }
+  
+  // Precomputes the freq_shift vector for phaseShift(), above
+  //    LoVec_double freq_shift(nfft);
+  //    firstIndex i;
+  //    freq_shift = (((i - nfft/2.0 + 1)*freq_res + centerFreq)/centerFreq;
+  LoVec_double getFreqShift (double bandwidth, double center_freq, int nfft) 
+  {
+    LoVec_double fs (nfft);
+
+    fs = ((tensor::i - nfft / 2.0 + 1) * (bandwidth / nfft) + center_freq) / center_freq;
+    return fs;
+  }
+
+  LoVec_double DOA (const LoVec_double& px, const LoVec_double& py, double theta, double phi) 
+  {
+    FailWhen1 (px.size () != py.size (), "vector size mismatch");
+    LoVec_double res (px.size ());
+
+    res = -2 * M_PI * (px * sin (theta) * cos (phi) + py * sin (theta) * sin (phi));
+	
+    return res;
+  }
+};				// namespace PhaseShift
diff --git a/StationSim/src/PhaseShift.h b/StationSim/src/PhaseShift.h
new file mode 100644
index 0000000000000000000000000000000000000000..e202dc91a5fd308d1cba24be62365edf9d3a5a67
--- /dev/null
+++ b/StationSim/src/PhaseShift.h
@@ -0,0 +1,80 @@
+//  PhaseShift.h:
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//
+
+#ifndef DATAGEN_PHASESHIFT_H
+#define DATAGEN_PHASESHIFT_H 1
+
+#include <Common/Debug.h>
+#include <Common/Lorrays.h>
+#include <DataGen/FFTW.h>
+#include <DataGen/DataGenConfig.h>
+
+
+namespace PhaseShift 
+{
+  // Phase-shifts a source for the given array configuration
+  // Returns [n_antennas,signal_length] matrix
+  // freq_shift can be obtained by getFreqShift, below
+  // fft_plans are fftw forward/reverse transform plans (use {0,0} to have
+  // them created locally)
+  LoMat_dcomplex phaseShift (int nfft, 
+							 const LoVec_double& source, 
+							 const double theta, 
+							 const double phi, 
+							 const ArrayConfig& antennas, 
+							 const LoVec_double& freq_shift, 
+							 FFTW::Plan fwdplan = 0,	     // forward transform plan, if available
+							 FFTW::Plan invplan = 0);        // reverse transform plan, if available
+
+  // Applies antenna phase to a source & antenna pair.
+  // input_signal is the source signal,
+  // doa is its direction-of-arrival at the antenna;
+  // freq_shift is a precomputed frequency shift vector:
+  //    (((i - nfft/2.0 + 1)*freq_resolution + center_freq)/center_freq);
+  // fft_plans are fftw forward/reverse transform plans (use {0,0} to have
+  // them created locally)
+  LoVec_dcomplex applyAntennaPhase (int nfft, 
+									int nbins, 
+									const LoVec_dcomplex& input_signal,	// nfft*nbins input signal f-domain)
+									const LoVec_double& freq_shift,	    // nfft precomputed frequency shifts
+									double doa,	                        // direction of arrival
+									FFTW::Plan invplan = 0);            // reverse transform plan
+
+  // freq_shift is a precomputed frequency shift vector, determined via
+  // bandwidth and center freq.:
+  //    LoVec_double freq_shift(nfft);
+  //    firstIndex i;
+  //    freq_shift = (((i - nfft/2.0 + 1)*freq_res + centerFreq)/centerFreq;
+  LoVec_double getFreqShift (double bandwidth, 
+							 double center_freq, 
+							 int nfft);
+
+  // computes the direction-of-arrival parameter for given
+  // antenna coordinates
+  LoVec_double DOA (const LoVec_double& px, 
+					const LoVec_double& py,
+					double theta, 
+					double phi);
+
+}; // namespace PhaseShift
+
+#endif
diff --git a/StationSim/src/Signal.cc b/StationSim/src/Signal.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b0b274c4cc36aca7ba9e35e270f8bf16c946e998
--- /dev/null
+++ b/StationSim/src/Signal.cc
@@ -0,0 +1,53 @@
+//  Signal.cc
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+
+#include <DataGen/Signal.h>
+
+
+Signal::Signal (string config_file, string mod, double cf, double amp, double opt)
+: itsCarrierFreq    (cf),
+  itsAmplitude      (amp),
+  itsOpt            (opt),
+  itsModulationType (mod),
+  itsInputFileName  (config_file)
+{
+  ifstream configfile (config_file.c_str (), ifstream::in);
+  string s;
+  int InfoRead = 0;
+
+  while (InfoRead < 2 && configfile.is_open ()) {
+    s = "";
+    configfile >> s;
+    if (s == "length") {
+      configfile >> s;
+      if (s == ":") {
+	configfile >> itsLength;
+	InfoRead++;
+      }
+    } else if (s == "fs_signal") {
+      configfile >> s;
+      if (s == ":") {
+	configfile >> itsSamplingFreq;
+	InfoRead++;
+      }
+    }
+  }
+}
diff --git a/StationSim/src/Signal.h b/StationSim/src/Signal.h
new file mode 100644
index 0000000000000000000000000000000000000000..5e14c85caab50605f6cebce53de3eb4306f7f955
--- /dev/null
+++ b/StationSim/src/Signal.h
@@ -0,0 +1,51 @@
+//  Signal.h
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//
+
+#ifndef DATAGEN_SIGNAL_H
+#define DATAGEN_SIGNAL_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Common/Lorrays.h>
+#include <Common/Debug.h>
+#include <string>
+#include <fstream.h>
+
+
+class Signal
+{
+public:
+
+  Signal (string config_file, string mod, double cf, double amp, double opt);
+
+  double itsCarrierFreq;
+  double itsAmplitude;
+  double itsOpt;
+  string itsModulationType;
+  string itsInputFileName;
+  double itsLength;
+  long   itsSamplingFreq;
+};
+
+#endif
diff --git a/StationSim/src/Source.cc b/StationSim/src/Source.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3d0710d2bd47fae1d9ab38e9a466bd7326a32c4e
--- /dev/null
+++ b/StationSim/src/Source.cc
@@ -0,0 +1,78 @@
+//  Source.cc
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+
+
+#include <DataGen/Source.h>
+
+Source::Source (string config_file)
+{
+  ifstream configfile (config_file.c_str (), ifstream::in);
+  string s;
+  string filename;
+  int i = 0;
+
+  while (!configfile.eof () && configfile.is_open ()) {
+    s = "";
+    configfile >> s;
+    if (s == "length") {
+      configfile >> s;
+      if (s == ":") {
+	configfile >> itsLength;
+      }
+    } else if (s == "fs") {
+      configfile >> s;
+      if (s == ":") {
+	configfile >> itsSamplingFreq;
+      }
+    } else if (s == "nsignals") {
+      configfile >> s;
+      if (s == ":") {
+	configfile >> itsNumberOfSignals;
+      }
+    } else if (s == "SignalFilename") {
+      configfile >> s;
+      if (s == ":") {
+	configfile >> filename;
+      }
+    } else if (s == "TrajectoryFilename") {
+      configfile >> s;
+      if (s == ":")
+	configfile >> s;
+      itsTraject = new Trajectory (s, itsSamplingFreq, itsLength);
+    } else if (s == "f_centre") {
+      configfile >> s;
+      if (s == ":") {
+	configfile >> itsCentreFrequency;
+      }
+    } else if (s.substr (0, 2) == "AM" || s == "FM" || s == "PM") {
+      double cf;
+      double amp;
+      double opt;
+      string mod = s;
+
+      configfile >> cf;
+      configfile >> amp;
+      configfile >> opt;
+
+      itsSignals[i++] = new Signal (filename, mod, cf, amp, opt);
+    }
+  }
+}
diff --git a/StationSim/src/Source.h b/StationSim/src/Source.h
new file mode 100644
index 0000000000000000000000000000000000000000..4178a1b0d2919401e3d25b5a79c9fb27867edf97
--- /dev/null
+++ b/StationSim/src/Source.h
@@ -0,0 +1,53 @@
+//  Source.h
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//
+
+#ifndef DATAGEN_SOURCE_H
+#define DATAGEN_SOURCE_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Common/Lorrays.h>
+#include <Common/Debug.h>
+#include <DataGen/Trajectory.h>
+#include <DataGen/Signal.h>
+#include <string>
+#include <fstream.h>
+
+#define MAX_SIGNALS 100
+
+class Source
+{
+public:
+
+  Source (string config_file);
+
+  Trajectory* itsTraject;
+  double      itsLength;
+  long        itsCentreFrequency;
+  long        itsSamplingFreq;
+  int         itsNumberOfSignals;
+  Signal*     itsSignals[MAX_SIGNALS];
+};
+
+#endif
\ No newline at end of file
diff --git a/StationSim/src/Trajectory.cc b/StationSim/src/Trajectory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e5a215dae2029fc40b41e949badf9d48d7226f94
--- /dev/null
+++ b/StationSim/src/Trajectory.cc
@@ -0,0 +1,84 @@
+// Trajectory.cc
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+
+#include <DataGen/Trajectory.h>
+
+
+Trajectory::Trajectory (string config_file, int fs, double length)
+: itsFs     (fs),
+  itsLength (length)
+{
+  ifstream configfile (config_file.c_str (), ifstream::in);
+  string s;
+  LoVec_double pointPhi;
+  LoVec_double pointTheta;
+  LoVec_double pointTime;
+
+  while (!configfile.eof () && configfile.is_open ()) {
+    s = "";
+    configfile >> s;
+    if (s == "type") {
+      configfile >> s;
+      if (s == ":")
+	configfile >> itsType;
+    } else if (s == "npoints") {
+      configfile >> s;
+      if (s == ":")
+	configfile >> itsNpoints;
+    } else if (s == "points") {
+      configfile >> s;    
+	  if (s == ":") {
+		pointPhi.resize (itsNpoints);
+		pointTheta.resize (itsNpoints);
+		pointTime.resize (itsNpoints);
+		for (int i = 0; i < itsNpoints; ++i) {
+		  configfile >> pointPhi (i);
+		  configfile >> pointTheta (i);
+		  configfile >> pointTime (i);
+		}
+      }
+    }
+  }
+
+  // File read in now create the phi and theta vectors
+  itsPhi.resize ((int)(itsFs / itsLength));
+  itsTheta.resize ((int)(itsFs / itsLength));
+  itsTime.resize ((int)(itsFs / itsLength));
+  
+  for (int i = 1; i < itsNpoints; ++i) {
+	for (int j = 0; j < (itsTime(i-1) - itsTime(i)) * itsFs * itsLength; ++j) {
+	  itsPhi(i) = (pointPhi(i-1) - pointPhi(i)) / (pointTheta(i-1) - pointTheta(i)) * j + pointPhi(i-1);
+	  itsTheta(i) = (pointPhi(i-1) - pointPhi(i)) / (pointTheta(i-1) - pointTheta(i)) * j + pointTheta(i-1);
+	}
+  }
+}
+
+double Trajectory::getPhi (int index)
+{
+  Assert (index < itsFs * itsLength);
+  return itsPhi(index);
+}
+
+double Trajectory::getTheta (int index)
+{
+  Assert (index < itsFs * itsLength);
+  return itsTheta(index);
+}
diff --git a/StationSim/src/Trajectory.h b/StationSim/src/Trajectory.h
new file mode 100644
index 0000000000000000000000000000000000000000..ccc575bf518bbbb66d8f74651c9f960b9deec12d
--- /dev/null
+++ b/StationSim/src/Trajectory.h
@@ -0,0 +1,57 @@
+//  Trajectory.h
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//
+
+#ifndef DATAGEN_TRAJECTORY_H
+#define DATAGEN_TRAJECTORY_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Common/Debug.h>
+#include <Common/Lorrays.h>
+#include <string>
+#include <fstream.h>
+
+
+class Trajectory
+{
+public:
+
+   Trajectory (string config_file, int fs, double length);
+
+  // returns source coordinates
+  double getPhi (int index);
+  double getTheta (int index);
+
+private:
+
+  int          itsFs;
+  double       itsLength;
+  int          itsNpoints;
+  string       itsType;
+  LoVec_double itsTheta;
+  LoVec_double itsPhi;
+  LoVec_double itsTime;
+};
+
+#endif
diff --git a/StationSim/src/WH_AddSignals.cc b/StationSim/src/WH_AddSignals.cc
new file mode 100644
index 0000000000000000000000000000000000000000..64e274c9efd1172d435ce4eedee070d3a7fe8ca6
--- /dev/null
+++ b/StationSim/src/WH_AddSignals.cc
@@ -0,0 +1,136 @@
+//  WH_AddSignals.cc:
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//
+
+#include <Common/Debug.h>
+#include <BaseSim/ParamBlock.h>
+#include <DataGen/WH_AddSignals.h>
+#include <stdio.h>		// for sprintf
+
+
+WH_AddSignals::WH_AddSignals (const string& name, 
+							  unsigned int nin,
+							  unsigned int nout,
+							  unsigned int nrcu)
+: WorkHolder    (nin, nout, name, "WH_AddSignals"),
+  itsInHolders  (0),
+  itsOutHolders (0),
+  itsNrcu       (nrcu)
+{
+  // Allocate blocks to hold pointers to input and output DH-s.
+  if (nin > 0) {
+    itsInHolders = new DH_SampleC *[nin];
+  }
+  if (nout > 0) {
+    itsOutHolders = new DH_SampleC *[nout];
+  }
+  // Create the input DH-s.
+  char str[8];
+
+  for (unsigned int i = 0; i < nin; i++) {
+    sprintf (str, "%d", i);
+    itsInHolders[i] = new DH_SampleC (string ("in_") + str, nrcu, 1);
+  }
+  // Create the output DH-s.
+  if (nin == 0) {
+    nin = 1;
+  }
+  for (unsigned int i = 0; i < nout; i++) {
+    sprintf (str, "%d", i);
+    itsOutHolders[i] = new DH_SampleC (string ("out_") + str, 1, 1);
+  }
+  // DEBUG
+  itsCount = 0;
+  itsFileOut.open ("/home/alex/gerdes/output.txt");
+}
+
+WH_AddSignals::~WH_AddSignals ()
+{
+  for (int i = 0; i < getInputs (); i++) {
+    delete itsInHolders[i];
+  }
+  delete[]itsInHolders;
+  for (int i = 0; i < getOutputs (); i++) {
+    delete itsOutHolders[i];
+  }
+  delete[]itsOutHolders;
+  itsFileOut.close ();
+}
+
+WorkHolder* WH_AddSignals::construct (const string& name, 
+									  int ninput,
+									  int noutput, 
+									  const ParamBlock&)
+{
+  return new WH_AddSignals (name, ninput, noutput, 1);
+}
+
+WH_AddSignals* WH_AddSignals::make (const string& name) const
+{
+  return new WH_AddSignals (name, getInputs (), getOutputs (), itsNrcu);
+}
+
+void WH_AddSignals::process ()
+{
+  if (getOutputs () > 0) {
+    for (int i = 0; i < itsNrcu; i++) {
+      itsOutHolders[i]->getBuffer ()[0] = 0;
+    }
+
+    for (int i = 0; i < getInputs (); i++) {
+      for (int j = 0; j < itsNrcu; j++) {
+	itsOutHolders[j]->getBuffer ()[0] += itsInHolders[i]->getBuffer ()[j];
+      }
+    }
+	
+	// DEBUG
+    for (int i = 0; i < itsNrcu; i++) {
+      itsFileOut << real (itsOutHolders[i]->getBuffer ()[0]) << " " 
+				 << imag (itsOutHolders[i]->getBuffer ()[0]) << " ";
+	}
+    itsFileOut << endl;
+  }
+}
+
+void WH_AddSignals::dump () const
+{
+  cout << "WH_AddSignals " << getName () << " Buffer:" << endl;
+  if (getOutputs () > 0) {
+    cout << itsOutHolders[0]->getBuffer ()[0];
+    if (getInputs () > 0) {
+      cout << ',' << itsOutHolders[0]->getBuffer ()[getInputs () - 1];
+    }
+    cout << endl;
+  }
+}
+
+
+DH_SampleC* WH_AddSignals::getInHolder (int channel)
+{
+  AssertStr (channel < getInputs (), "input channel too high");
+  return itsInHolders[channel];
+}
+
+DH_SampleC* WH_AddSignals::getOutHolder (int channel)
+{
+  AssertStr (channel < getOutputs (), "output channel too high");
+  return itsOutHolders[channel];
+}
diff --git a/StationSim/src/WH_AddSignals.h b/StationSim/src/WH_AddSignals.h
new file mode 100644
index 0000000000000000000000000000000000000000..21aa14537a4bb619e1cecdebb60b9b6ecaa49045
--- /dev/null
+++ b/StationSim/src/WH_AddSignals.h
@@ -0,0 +1,89 @@
+//  WH_AddSignals.h:
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//
+
+#ifndef DATAGEN_WH_ADD_SIGNALS_H
+#define DATAGEN_WH_ADD_SIGNALS_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <BaseSim/WorkHolder.h>
+#include <DataGen/DH_SampleC.h>
+
+
+class WH_AddSignals:public WorkHolder 
+{
+public:
+  /// Construct the work holder and give it a name.
+  /// It is possible to specify how many input and output data holders
+  /// are created and how many elements there are in the buffer.
+  /// The first WorkHolder should have nin=0.
+  WH_AddSignals (const string& name, 
+				 unsigned int nin, 
+				 unsigned int nout,
+				 unsigned int nrcu);
+
+  virtual ~WH_AddSignals ();
+
+  /// Static function to create an object.
+  static WorkHolder* construct (const string& name, 
+								int ninput,
+								int noutput, 
+								const ParamBlock&);
+
+  /// Make a fresh copy of the WH object.
+  virtual WH_AddSignals* make (const string& name) const;
+
+  /// Do a process step.
+  virtual void process ();
+
+  /// Show the work holder on stdout.
+  virtual void dump () const;
+
+  /// Get a pointer to the i-th input DataHolder.
+  virtual DH_SampleC* getInHolder (int channel);
+
+  /// Get a pointer to the i-th output DataHolder.
+  virtual DH_SampleC* getOutHolder (int channel);
+
+private:
+  /// Forbid copy constructor.
+   WH_AddSignals (const WH_AddSignals &);
+
+  /// Forbid assignment.
+   WH_AddSignals & operator = (const WH_AddSignals &);
+
+  /// Pointer to the array of input DataHolders.
+  DH_SampleC** itsInHolders;
+  /// Pointer to the array of output DataHolders.
+  DH_SampleC** itsOutHolders;
+
+  int itsNrcu;
+
+  // DEBUG
+  int itsCount;
+  ofstream itsFileOut;
+};
+
+
+#endif
diff --git a/StationSim/src/WH_CreateSource.cc b/StationSim/src/WH_CreateSource.cc
new file mode 100644
index 0000000000000000000000000000000000000000..be758b35a7aa1d9939416f06bb2605c45de1d4e3
--- /dev/null
+++ b/StationSim/src/WH_CreateSource.cc
@@ -0,0 +1,112 @@
+//  WH_CreateSource.cc:
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//
+
+#include <Common/Debug.h>
+#include <BaseSim/ParamBlock.h>
+#include <DataGen/WH_CreateSource.h>
+#include <stdio.h>		// for sprintf
+
+
+WH_CreateSource::WH_CreateSource (const string& name, 
+								  unsigned int nin, 
+								  unsigned int nout)
+: WorkHolder    (nin, nout, name, "WH_CreateSource"), 
+  itsInHolders  (0),
+  itsOutHolders (0)
+{
+  // Allocate blocks to hold pointers to input and output DH-s.
+  if (nin > 0) {
+    itsInHolders = new DH_SampleR* [nin];
+  }
+  if (nout > 0) {
+    itsOutHolders = new DH_SampleR* [nout];
+  }
+  // Create the input DH-s.
+  char str[8];
+
+  for (unsigned int i = 0; i < nin; i++) {
+    sprintf (str, "%d", i);
+    itsInHolders[i] = new DH_SampleR (string ("in_") + str, 1, 1);
+  }
+  // Create the output DH-s.
+  if (nin == 0) {
+    nin = 1;
+  }
+  for (unsigned int i = 0; i < nout; i++) {
+    sprintf (str, "%d", i);
+    itsOutHolders[i] = new DH_SampleR (string ("out_") + str, 1, 1);
+  }
+}
+
+WH_CreateSource::~WH_CreateSource ()
+{
+  for (int i = 0; i < getInputs (); i++) {
+    delete itsInHolders[i];
+  }
+  delete[]itsInHolders;
+  for (int i = 0; i < getOutputs (); i++) {
+    delete itsOutHolders[i];
+  }
+  delete[]itsOutHolders;
+}
+
+WorkHolder* WH_CreateSource::construct (const string& name, 
+										int ninput,
+										int noutput, 
+										const ParamBlock&)
+{
+  return new WH_CreateSource (name, ninput, noutput);
+}
+
+WH_CreateSource* WH_CreateSource::make (const string & name) const
+{
+  return new WH_CreateSource (name, getInputs (), getOutputs ());
+}
+
+void WH_CreateSource::process ()
+{
+  if (getOutputs () > 0) {
+    DH_SampleR::BufferType* buf = itsOutHolders[0]->getBuffer ();
+    buf[0] = 0;
+
+    for (int i = 0; i < getInputs (); i++) {
+      buf[0] += itsInHolders[i]->getBuffer ()[0];
+    }
+  }
+}
+
+void WH_CreateSource::dump () const
+{
+}
+
+
+DH_SampleR* WH_CreateSource::getInHolder (int channel)
+{
+  AssertStr (channel < getInputs (), "input channel too high");
+  return itsInHolders[channel];
+}
+
+DH_SampleR* WH_CreateSource::getOutHolder (int channel)
+{
+  AssertStr (channel < getOutputs (), "output channel too high");
+  return itsOutHolders[channel];
+}
diff --git a/StationSim/src/WH_CreateSource.h b/StationSim/src/WH_CreateSource.h
new file mode 100644
index 0000000000000000000000000000000000000000..615baebc08ead1c3eeccf63e87d193be5236a4d5
--- /dev/null
+++ b/StationSim/src/WH_CreateSource.h
@@ -0,0 +1,82 @@
+//  WH_CreateSources.h:
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//
+
+#ifndef DATAGEN_WH_CREATE_SOURCE_H
+#define DATAGEN_WH_CREATE_SOURCE_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <BaseSim/WorkHolder.h>
+#include <DataGen/DH_SampleR.h>
+
+
+class WH_CreateSource:public WorkHolder 
+{
+public:
+  /// Construct the work holder and give it a name.
+  /// It is possible to specify how many input and output data holders
+  /// are created and how many elements there are in the buffer.
+  /// The first WorkHolder should have nin=0.
+  WH_CreateSource (const string& name, 
+				   unsigned int nin, 
+				   unsigned int nout);
+
+  virtual ~WH_CreateSource ();
+
+  /// Static function to create an object.
+  static WorkHolder *construct (const string& name, 
+								int ninput,
+								int noutput, 
+								const ParamBlock&);
+
+  /// Make a fresh copy of the WH object.
+  virtual WH_CreateSource* make (const string& name) const;
+
+  /// Do a process step.
+  virtual void process ();
+
+  /// Show the work holder on stdout.
+  virtual void dump () const;
+
+  /// Get a pointer to the i-th input DataHolder.
+  virtual DH_SampleR* getInHolder (int channel);
+
+  /// Get a pointer to the i-th output DataHolder.
+  virtual DH_SampleR* getOutHolder (int channel);
+
+private:
+  /// Forbid copy constructor.
+   WH_CreateSource (const WH_CreateSource&);
+
+  /// Forbid assignment.
+   WH_CreateSource& operator = (const WH_CreateSource&);
+
+  /// Pointer to the array of input DataHolders.
+  DH_SampleR** itsInHolders;
+  /// Pointer to the array of output DataHolders.
+  DH_SampleR** itsOutHolders;
+};
+
+
+#endif
diff --git a/StationSim/src/WH_Modulate.cc b/StationSim/src/WH_Modulate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c1283737678d99d2a598eba92306473aab558a29
--- /dev/null
+++ b/StationSim/src/WH_Modulate.cc
@@ -0,0 +1,166 @@
+// WH_Modulate.cc: implementation of the WH_Modulate class.
+//
+//  Copyright (C) 2000,2001,2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+
+#include <DataGen/WH_Modulate.h>
+#include <Common/Debug.h>
+
+
+WH_Modulate::WH_Modulate (int nin, 
+						  int nout, 
+						  string mod_type, 
+						  double carrier_freq, 
+						  double samp_freq, 
+						  double opt, 
+						  double amp, 
+						  int window_size)
+: WorkHolder     (nin, nout, "aWorkHolder", "WH_Modulate"),
+  itsWindowSize  (window_size),
+  itsPos         (0),  
+  itsCarrierFreq (carrier_freq),
+  itsSampFreq    (samp_freq),
+  itsOpt         (opt),
+  itsAmp         (amp),
+  itsTc          (samp_freq / carrier_freq),
+  itsPhi         (0),
+  itsP           (0),
+  itsp           (0),
+  itsModType     (mod_type)
+{
+  // Allocate blocks to hold pointers to input and output DH-s.
+  if (nin > 0) {
+    itsInHolders = new DH_SampleR* [nin];
+  }
+  if (nout > 0) {
+    itsOutHolders = new DH_SampleR* [nout];
+  }
+  // Create the input DH-s.
+  char str[8];
+
+  for (int i = 0; i < nin; i++) {
+    sprintf (str, "%d", i);
+    itsInHolders[i] = new DH_SampleR (string ("in_") + str, 1, 1);
+  }
+  // Create the output DH-s.
+  if (nin == 0) {
+    nin = 1;
+  }
+  for (int i = 0; i < nout; i++) {
+    sprintf (str, "%d", i);
+    itsOutHolders[i] = new DH_SampleR (string ("out_") + str, 1, 1);
+  }
+  itsInputBuffer.resize (itsWindowSize);
+  itsOutputBuffer.resize (itsWindowSize);
+}
+
+
+WH_Modulate::~WH_Modulate ()
+{
+  for (int ch = 0; ch < getInputs (); ch++) {
+    delete itsInHolders[ch];
+  }
+  for (int ch = 0; ch < getOutputs (); ch++) {
+    delete itsOutHolders[ch];
+  }
+}
+
+
+WH_Modulate* WH_Modulate::make (const string &) const
+{
+  return new WH_Modulate (getInputs (), 
+						  getOutputs (), 
+						  itsModType,
+						  itsCarrierFreq, 
+						  itsSampFreq, 
+						  itsOpt, 
+						  itsAmp,
+						  itsWindowSize);
+}
+
+
+void WH_Modulate::process ()
+{
+  DH_SampleR::BufferType * bufin = itsInHolders[0]->getBuffer ();
+  itsInputBuffer (itsPos) = bufin[0];
+  itsPos = (itsPos + 1) % itsInputBuffer.size ();
+
+  if (itsPos == 0) {
+    // find out what modulationscheme has to be applied to the signal
+    // modulate the signal
+    if (itsModType == "AMDSB") {
+      itsOutputBuffer = modulate::amdsb (itsInputBuffer, 
+										 itsCarrierFreq,
+										 itsSampFreq, 
+										 itsPhi) * itsAmp;
+	} else if (itsModType == "AMDSB_TC") {
+      itsOutputBuffer = modulate::amdsb_tc (itsInputBuffer, 
+											itsCarrierFreq,
+											itsSampFreq, 
+											itsPhi, 
+											itsOpt) * itsAmp;
+    } else if (itsModType == "AMSSB") {
+      itsOutputBuffer = modulate::amssb (itsInputBuffer, 
+										 itsCarrierFreq,
+										 itsSampFreq, 
+										 itsPhi) * itsAmp;
+	} else if (itsModType == "FM") {
+      itsOutputBuffer = modulate::fm (itsInputBuffer, 
+									  itsCarrierFreq, 
+									  itsSampFreq,
+									  itsOpt, 
+									  itsPhi) * itsAmp;
+	} else if (itsModType == "PM") {
+      itsOutputBuffer = modulate::pm (itsInputBuffer, 
+									  itsCarrierFreq, 
+									  itsSampFreq,
+									  itsOpt, 
+									  itsPhi) * itsAmp;
+	}
+
+    // Calculate the proper phase for the carrier frequency
+    itsP = itsTc - itsp;
+    while (itsP < itsWindowSize) {
+      itsP += itsTc;
+	}
+    itsp = itsTc - (itsP - itsWindowSize);
+    itsPhi = itsp / itsSampFreq;
+  }
+
+  if (getOutputs () > 0) {
+    for (int i = 0; i < getOutputs (); i++) {
+      getOutHolder (i)->getBuffer ()[0] = itsOutputBuffer (itsPos);
+    }
+  }
+}
+
+void WH_Modulate::dump () const
+{
+}
+
+
+DH_SampleR* WH_Modulate::getInHolder (int channel)
+{
+  return itsInHolders[channel];
+}
+
+DH_SampleR* WH_Modulate::getOutHolder (int channel)
+{
+  return itsOutHolders[channel];
+}
diff --git a/StationSim/src/WH_Modulate.h b/StationSim/src/WH_Modulate.h
new file mode 100644
index 0000000000000000000000000000000000000000..eed38adf7b41a6ffcea02b736fe8cbfade1f6ded
--- /dev/null
+++ b/StationSim/src/WH_Modulate.h
@@ -0,0 +1,79 @@
+// WH_Modulate.h: interface for the WH_Modulate class.
+//
+//  Copyright (C) 2000,2001,2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+
+#ifndef DATAGEN_WH_MODULATE_H
+#define DATAGEN_WH_MODULATE_H
+
+#include <BaseSim/WorkHolder.h>
+#include <DataGen/DH_SampleR.h>
+#include <DataGen/Modulate.h>
+#include <DataGen/DataGenConfig.h>
+
+
+class WH_Modulate : public WorkHolder 
+{
+public:
+
+  WH_Modulate (int nin, 
+			   int nout, 
+			   string mod_type, 
+			   double carrier_freq,
+			   double samp_freq, 
+			   double opt, 
+			   double amp, 
+			   int window_size = 32);
+
+  virtual ~WH_Modulate ();
+
+  /// Make a fresh copy of the WH object.
+  virtual WH_Modulate* make (const string& name) const;
+
+  virtual void process ();
+  virtual void dump () const;
+
+  /// Retrieve a pointer to the input data holder for the given channel
+  virtual DH_SampleR* getInHolder (int channel);
+
+  /// Retrieve a pointer to the output data holder for the given channel
+  virtual DH_SampleR* getOutHolder (int channel);
+
+private:
+
+  DH_SampleR** itsInHolders;
+  DH_SampleR** itsOutHolders;
+
+  int           itsWindowSize;
+  int           itsPos;
+  double        itsCarrierFreq;
+  double        itsSampFreq;
+  double        itsOpt;
+  double        itsAmp;
+  double        itsTc;
+  double        itsPhi;
+  double        itsP;
+  double        itsp;
+  string        itsModType;
+  LoVec_double  itsInputBuffer;
+  LoVec_double  itsOutputBuffer;
+};
+
+
+#endif
diff --git a/StationSim/src/WH_PhaseShift.cc b/StationSim/src/WH_PhaseShift.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4edc7d27c910aedfafa3a89aa993435d70f08bef
--- /dev/null
+++ b/StationSim/src/WH_PhaseShift.cc
@@ -0,0 +1,151 @@
+// WH_PhaseShift.cc: implementation of the WH_PhaseShift class.
+//
+//  Copyright (C) 2000,2001,2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+
+#include <Common/Debug.h>
+#include <DataGen/WH_PhaseShift.h>
+
+using namespace blitz;
+
+
+WH_PhaseShift::WH_PhaseShift (int nin, 
+							  int nout, 
+							  int nrcu, 
+							  DataGenerator* dg_config, 
+							  int nfft, 
+							  int source, 
+							  int windowsize)
+  : WorkHolder        (nin, nout, "aWorkHolder", "WH_PhaseShift"),
+	itsNrcu           (nrcu),
+	itsPos            (0),
+	itsNfft           (nfft),
+	itsSource         (source),
+    itsPrevWindowSize (windowsize),
+    itsCount          (0),
+	itsConfig         (dg_config)
+{
+  // Allocate blocks to hold pointers to input and output DH-s.
+  if (nin > 0) {
+    itsInHolders = new DH_SampleR* [nin];
+  }
+  if (nout > 0) {
+    itsOutHolders = new DH_SampleC* [nout];
+  }
+  // Create the input DH-s.
+  char str[8];
+
+  for (int i = 0; i < nin; i++) {
+    sprintf (str, "%d", i);
+    itsInHolders[i] = new DH_SampleR (string ("in_") + str, 1, 1);
+  }
+  // Create the output DH-s.
+  if (nin == 0) {
+    nin = 1;
+  }
+  for (int i = 0; i < nout; i++) {
+    sprintf (str, "%d", i);
+    itsOutHolders[i] = new DH_SampleC (string ("out_") + str, nrcu, 1);
+  }
+
+  itsInputBuffer.resize (nfft);
+  itsForwardPlan = FFTW::initForwardPlan (nfft);
+  itsInversePlan = FFTW::initInversePlan (nfft);
+  itsFreqShift.resize (itsNfft);
+  itsOutputBuffer.resize (itsNrcu, 
+						  itsNfft);
+  itsFreqShift = 
+	PhaseShift::getFreqShift (itsConfig->itsSources[itsSource]->itsSamplingFreq,
+							  itsConfig->itsSources[itsSource]->itsCentreFrequency, 
+							  itsNfft);
+}
+
+WH_PhaseShift::~WH_PhaseShift ()
+{
+  for (int ch = 0; ch < getInputs (); ch++) {
+    delete itsInHolders[ch];
+  }
+  for (int ch = 0; ch < getOutputs (); ch++) {
+    delete itsOutHolders[ch];
+  }
+}
+
+
+WH_PhaseShift* WH_PhaseShift::make (const string&) const
+{
+  return new WH_PhaseShift (getInputs (), 
+							getOutputs (), 
+							itsNrcu, 
+							itsConfig,
+							itsNfft, 
+							itsSource, 
+							itsPrevWindowSize);
+}
+
+
+void WH_PhaseShift::process ()
+{
+  if (getOutputs () > 0) {
+    if (itsCount > itsPrevWindowSize - 2) {
+      DH_SampleR::BufferType* bufin = itsInHolders[0]->getBuffer ();
+      itsInputBuffer (itsPos) = bufin[0];
+      itsPos = (itsPos + 1) % itsInputBuffer.size ();
+
+      if (itsPos == 0) {
+		itsOutputBuffer = 
+		  PhaseShift::phaseShift (itsNfft,
+								  itsInputBuffer,
+								  itsConfig->itsSources[itsSource]->itsTraject->getTheta (itsCount),
+								  itsConfig->itsSources[itsSource]->itsTraject->getPhi (itsCount),
+								  *(itsConfig->itsArray),
+								  itsFreqShift,
+								  itsForwardPlan,
+								  itsInversePlan);
+		itsOutputBuffer /= itsNfft;
+      }
+
+      for (int i = 0; i < getOutputs (); i++) {
+		LoVec_dcomplex temp (itsNrcu);
+		for (int j = 0; j < itsNrcu; j++) {
+		  temp (j) = itsOutputBuffer (j, itsPos);
+		}
+		memcpy (getOutHolder (i)->getBuffer (), 
+				temp.data (),
+				itsNrcu * sizeof (dcomplex));
+      }
+    }
+    itsCount++;
+  }
+}
+
+
+void WH_PhaseShift::dump () const
+{
+
+}
+
+DH_SampleR* WH_PhaseShift::getInHolder (int channel)
+{
+  return itsInHolders[channel];
+}
+
+DH_SampleC* WH_PhaseShift::getOutHolder (int channel)
+{
+  return itsOutHolders[channel];
+}
diff --git a/StationSim/src/WH_PhaseShift.h b/StationSim/src/WH_PhaseShift.h
new file mode 100644
index 0000000000000000000000000000000000000000..8457aa01a826960f50a0d979d76e4528b3d2dc08
--- /dev/null
+++ b/StationSim/src/WH_PhaseShift.h
@@ -0,0 +1,79 @@
+// WH_PhaseShift.h: interface for the WH_PhaseShift class.
+//
+//  Copyright (C) 2000,2001,2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+
+#ifndef DATAGEN_WH_PHASESHIFT_H
+#define DATAGEN_WH_PHASESHIFT_H
+
+#include <Common/Lorrays.h>
+#include <BaseSim/WorkHolder.h>
+#include <DataGen/DH_SampleR.h>
+#include <DataGen/DH_SampleC.h>
+#include <DataGen/DataGenConfig.h>
+#include <DataGen/PhaseShift.h>
+#include <DataGen/FFTW.h>
+
+
+class WH_PhaseShift : public WorkHolder 
+{
+public:
+
+  WH_PhaseShift (int inputs, 
+				 int outputs, 
+				 int nrcu,
+				 DataGenerator * dg_config, 
+				 int nfft, 
+				 int source,
+				 int windowsize);
+
+  virtual ~WH_PhaseShift ();
+
+  // Make a fresh copy of the WH object.
+  virtual WH_PhaseShift* make (const string& name) const;
+
+  virtual void process ();
+  virtual void dump () const;
+
+  /// Retrieve a pointer to the input data holder for the given channel
+  virtual DH_SampleR* getInHolder (int channel);
+
+  /// Retrieve a pointer to the output data holder for the given channel
+  virtual DH_SampleC* getOutHolder (int channel);
+
+private:
+  DH_SampleR** itsInHolders;
+  DH_SampleC** itsOutHolders;
+
+  int                  itsNrcu;
+  int                  itsPos;
+  int                  itsNfft;
+  int                  itsSource;
+  int                  itsPrevWindowSize;
+  int                  itsCount;
+  DataGenerator*       itsConfig;
+  FFTW::Plan           itsForwardPlan;
+  FFTW::Plan           itsInversePlan;
+  LoVec_double         itsInputBuffer;
+  LoVec_double         itsFreqShift;
+  LoMat_dcomplex       itsOutputBuffer;
+};
+
+
+#endif
diff --git a/StationSim/src/WH_ReadSignal.cc b/StationSim/src/WH_ReadSignal.cc
new file mode 100644
index 0000000000000000000000000000000000000000..eadedeb58cb71e4629ebad405c7d80722f7a6e2a
--- /dev/null
+++ b/StationSim/src/WH_ReadSignal.cc
@@ -0,0 +1,113 @@
+//  WH_ReadSignal.cc:
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//  $Id$
+//
+
+#include <Common/Debug.h>
+#include <BaseSim/ParamBlock.h>
+#include <DataGen/WH_ReadSignal.h>
+#include <stdio.h>		// for sprintf
+
+
+WH_ReadSignal::WH_ReadSignal (const string & name, unsigned int nout, 
+							  const string & fileName)  
+: WorkHolder        (0, nout, name, "WH_ReadSignal"),
+  itsOutHolders     (0),
+  itsFileName       (fileName), 
+  itsFile           (fileName.c_str ())
+{
+  AssertStr (itsFile, "Failed to open file " << fileName);
+  // Set the file pointer to the begining of the data
+  char s[256];
+
+  while (strncmp (s, "Data :", 6) != 0)
+    itsFile.getline (s, 256);
+
+  if (nout > 0) {
+    itsOutHolders = new DH_SampleR*[nout];
+  }
+
+  char str[8];
+
+  for (unsigned int i = 0; i < nout; i++) {
+    sprintf (str, "%d", i);
+    itsOutHolders[i] = new DH_SampleR (string ("out_") + str, 1, 1);
+  }
+}
+
+WH_ReadSignal::~WH_ReadSignal ()
+{
+  for (int i = 0; i < getOutputs (); i++) {
+    delete itsOutHolders[i];
+  }
+  delete[]itsOutHolders;
+}
+
+WorkHolder* WH_ReadSignal::construct (const string& name,
+									  int ninput, 
+									  int noutput,
+									  const ParamBlock& params)
+{
+  Assert (ninput == 0);
+  return new WH_ReadSignal (name, 
+							noutput,
+							params.getString ("rcufilename", ""));
+}
+
+WH_ReadSignal* WH_ReadSignal::make (const string & name) const
+{
+  return new WH_ReadSignal (name, getOutputs (), itsFileName);
+}
+
+void WH_ReadSignal::process ()
+{
+  double sample;
+
+  if (!itsFile.eof ()) {
+    itsFile >> sample;
+  } else {
+    sample = 0;
+  }
+
+  for (int i = 0; i < getOutputs (); i++) {
+    itsOutHolders[i]->getBuffer ()[0] = sample;
+  }
+}
+
+void WH_ReadSignal::dump () const
+{
+  cout << "WH_ReadSignal " << getName () << " Buffers:" << endl;
+  cout << itsOutHolders[0]->getBuffer ()[0] << ','
+	   << itsOutHolders[getOutputs () - 1]->getBuffer ()[0] << endl;
+}
+
+
+DataHolder* WH_ReadSignal::getInHolder (int channel)
+{
+  AssertStr (channel < 0, "input channel too high");
+  return 0;
+}
+
+DH_SampleR* WH_ReadSignal::getOutHolder (int channel)
+{
+  AssertStr (channel < getOutputs (), "output channel too high");
+  return itsOutHolders[channel];
+}
diff --git a/StationSim/src/WH_ReadSignal.h b/StationSim/src/WH_ReadSignal.h
new file mode 100644
index 0000000000000000000000000000000000000000..f38ff7ab475eac8cfafc9ae68d5724b1788c0dbb
--- /dev/null
+++ b/StationSim/src/WH_ReadSignal.h
@@ -0,0 +1,83 @@
+//  WH_ReadSignals.h:
+//
+//  Copyright (C) 2002
+//  ASTRON (Netherlands Foundation for Research in Astronomy)
+//  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//
+//  This program is free software; you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation; either version 2 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//
+//  $Id$
+//
+
+#ifndef DATAGEN_WH_READSIGNAL_H
+#define DATAGEN_WH_READSIGNAL_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <BaseSim/WorkHolder.h>
+#include <DataGen/DH_SampleR.h>
+
+
+class WH_ReadSignal : public WorkHolder 
+{
+public:
+  /// Construct the work holder and give it a name.
+  /// It is possible to specify how many input and output data holders
+  /// are created and how many elements there are in the buffer.
+  /// The first WorkHolder should have nin=0.
+  WH_ReadSignal (const string & name, 
+				 unsigned int nout,
+				 const string & signalFileName);
+
+   virtual ~ WH_ReadSignal ();
+
+  /// Static function to create an object.
+  static WorkHolder* construct (const string& name, 
+								int ninput,
+								int noutput, 
+								const ParamBlock&);
+
+  /// Make a fresh copy of the WH object.
+  virtual WH_ReadSignal* make (const string & name) const;
+
+  /// Do a process step.
+  virtual void process ();
+
+  /// Show the work holder on stdout.
+  virtual void dump () const;
+
+  /// There are no input DataHolders.
+  virtual DataHolder* getInHolder (int channel);
+
+  /// Get a pointer to the i-th output DataHolder.
+  virtual DH_SampleR* getOutHolder (int channel);
+
+private:
+  /// Forbid copy constructor.
+   WH_ReadSignal (const WH_ReadSignal&);
+
+  /// Forbid assignment.
+   WH_ReadSignal& operator = (const WH_ReadSignal&);
+
+  /// Pointer to the array of output DataHolders.
+  DH_SampleR** itsOutHolders;
+  string       itsFileName;
+  ifstream     itsFile;
+};
+
+
+#endif