Index: /branches/atnf/doc/README
===================================================================
--- /branches/atnf/doc/README	(revision 3)
+++ /branches/atnf/doc/README	(revision 3)
@@ -0,0 +1,4 @@
+Nothin here yet.
+This is not a release yet.
+
+Malte Marquarding.
Index: /branches/atnf/src/Makefile
===================================================================
--- /branches/atnf/src/Makefile	(revision 3)
+++ /branches/atnf/src/Makefile	(revision 3)
@@ -0,0 +1,77 @@
+TARGET    = atnf_sd.so
+
+CXX	  = g++-3.2.3
+CXXFLAGS  = -fPIC -w -g -fpermissive -O2
+
+AIPSROOT = $(word 1, $(AIPSPATH))
+
+AIPSINC = -I$(AIPSROOT)/code/include \
+          -I$(AIPSROOT)/code/atnf \
+          -I$(AIPSROOT)/code/trial \
+          -I$(AIPSROOT)/code/aips
+
+AIPSLIB  = $(AIPSROOT)/linux_gnu/lib
+AIPSPPLIB = -L$(AIPSLIB) \
+	$(AIPSLIB)/version.o \
+        $(AIPSLIB)/libatnf.a \
+        $(AIPSLIB)/libtrial.a \
+        $(AIPSLIB)/libaips_f.a \
+        $(AIPSLIB)/libaips.a \
+        -llapack -lblas -lg2c -lcfitsio -lrpfits \
+        -lglish -ledit -lsos -lnpd
+
+LINK      = g++-3.2.3
+LFLAGS    = -shared -Wl,-soname,$(TARGET)
+#-rpath,/home/mar637/lib
+#LFLAGS    += -Xlinker -rpath -Xlinker -L$(AIPSLIB)
+
+BOOSTLIB  = -lboost_python-mt
+BOOSTINC  = 
+
+PYTHONINC = -I/usr/include/python2.2
+PYTHONLIB = -lpython2.2
+
+INCDIRS   = -I. $(AIPSINC) $(BOOSTINC) $(PYTHONINC)
+LIBDIRS   = $(BOOSTLIB) $(PYTHONLIB) $(AIPSPPLIB)
+
+OBJECTS   = SDContainer.o \
+	    SDMemTable.o \
+	    SDReader.o \
+            SDMath.o \
+	    SDTemplates.o \
+	    python_SDMemTable.o \
+	    python_SDReader.o \
+	    python_SDMath.o \
+	    python_SD.o
+
+HEADERS   = SDContainer.h \
+	    SDMemTable.h \
+	    SDReader.h \
+	    SDMath.h \
+	    SDMemTableWrapper.h \
+	    python_SD.h
+
+.SUFFIXES: .c .o .cpp .cc .cxx .C
+
+.cpp.o:
+	$(CXX) -c $(CXXFLAGS) $(INCDIRS) -o $@ $<
+
+.cc.o:
+	$(CXX) -c $(CXXFLAGS) $(INCDIRS) -o $@ $<
+
+.cxx.o:	
+	$(CXX) -c $(CXXFLAGS) $(INCDIRS) -o $@ $<
+
+.C.o:
+	$(CXX) -c $(CXXFLAGS) $(INCDIRS) -o $@ $<
+
+$(TARGET):  $(OBJECTS)
+	$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS)  $(LIBDIRS)
+
+$(OBJECTS): $(HEADERS)
+
+clean:
+	-rm -f $(OBJECTS)
+
+realclean: clean
+	-rm -f $(TARGET)
Index: /branches/atnf/src/SDContainer.cc
===================================================================
--- /branches/atnf/src/SDContainer.cc	(revision 3)
+++ /branches/atnf/src/SDContainer.cc	(revision 3)
@@ -0,0 +1,134 @@
+//#---------------------------------------------------------------------------
+//# SDContainer.cc: A container class for single dish integrations
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#include <aips/Tables/Table.h>
+#include <aips/Arrays/IPosition.h>
+#include <aips/Arrays/ArrayAccessor.h>
+#include <aips/Arrays/Matrix.h>
+
+#include "SDContainer.h"
+
+using namespace atnf_sd;
+
+SDContainer::SDContainer(uInt nBeam, uInt nIF, uInt nChan, uInt nPol) 
+  : nBeam_(nBeam),
+  nIF_(nIF),
+  nChan_(nChan),
+  nPol_(nPol),
+  spectrum_(IPosition(4,nBeam,nIF,nChan,nPol)),
+  flags_(IPosition(4,nBeam,nIF,nChan,nPol)),
+  tsys_(IPosition(3,nBeam,nIF,nPol)) {
+  uChar x = 0;
+  flags_ = ~x;
+}
+
+SDContainer::~SDContainer() {
+}
+
+Bool SDContainer::putSpectrum(const Array<Float>& spec) {
+  spectrum_ = spec;
+}
+Bool SDContainer::putFlags(const Array<uChar>& spec) {
+  flags_ = spec;
+}
+Bool SDContainer::putTsys(const Array<Float>& spec) {
+  tsys_ = spec;
+}
+
+Bool SDContainer::setSpectrum(const Matrix<Float>& spec,
+			      uInt whichBeam, uInt whichIF) {
+
+  ArrayAccessor<Float, Axis<0> > aa0(spectrum_);
+  aa0.reset(aa0.begin(whichBeam));
+  ArrayAccessor<Float, Axis<1> > aa1(aa0);
+  aa1.reset(aa1.begin(whichIF));
+  
+  uInt nChan = spec.nrow();
+  uInt nPol  = spec.ncolumn();
+  Vector<Float> pols(nPol);
+  uInt chani = 0;
+  uInt poli = 0;
+  // assert dimensions are the same....
+  for (ArrayAccessor<Float, Axis<2> > i(aa1);i != i.end(); ++i) {
+    pols = spec.row(chani);
+    for (ArrayAccessor<Float, Axis<3> > ii(i);ii != ii.end(); ++ii) {
+      (*ii) = pols[poli];
+      poli++;
+    }
+    poli = 0;
+    chani++;
+  }
+  // unset flags for this spectrum, they might be set again by the
+  // setFlags method
+  IPosition shp = flags_.shape();
+  IPosition start(4,whichBeam,whichIF,0,0);
+  IPosition end(4,whichBeam,whichIF,shp(2)-1,shp(3)-1);
+  Array<uChar> arr(flags_(start,end));
+  arr = uChar(0);
+}
+
+Bool SDContainer::setFlags(const Matrix<uChar>& flag,
+			   uInt whichBeam, uInt whichIF) {
+
+  ArrayAccessor<uChar, Axis<0> > aa0(flags_);
+  aa0.reset(aa0.begin(whichBeam));
+  ArrayAccessor<uChar, Axis<1> > aa1(aa0);
+  aa1.reset(aa1.begin(whichIF));
+  
+  uInt nChan = flag.nrow();
+  uInt nPol  = flag.ncolumn();
+  Vector<uChar> pols(nPol);
+  uInt chani = 0;
+  uInt poli = 0;
+  // assert dimensions are the same....
+  for (ArrayAccessor<uChar, Axis<2> > i(aa1);i != i.end(); ++i) {
+    pols = flag.row(chani);
+    for (ArrayAccessor<uChar, Axis<3> > ii(i);ii != ii.end(); ++ii) {
+      (*ii) = uChar(pols[poli]);
+      poli++;
+    }
+    poli = 0;
+    chani++;
+  }
+}
+
+Bool SDContainer::setTsys(const Vector<Float>& tsys,
+			  uInt whichBeam, uInt whichIF) {
+  ArrayAccessor<Float, Axis<0> > aa0(tsys_);
+  aa0.reset(aa0.begin(whichBeam));
+  ArrayAccessor<Float, Axis<1> > aa1(aa0);
+  aa1.reset(aa1.begin(whichIF));
+  // assert dimensions are the same....
+  uInt idx = 0;
+  for (ArrayAccessor<Float, Axis<2> > i(aa1);i != i.end(); ++i) {
+    (*i) = tsys[idx];
+    idx++;
+  }  
+}
Index: /branches/atnf/src/SDContainer.h
===================================================================
--- /branches/atnf/src/SDContainer.h	(revision 3)
+++ /branches/atnf/src/SDContainer.h	(revision 3)
@@ -0,0 +1,113 @@
+//#---------------------------------------------------------------------------
+//# SDContainer.h: A container class for single dish integrations
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#ifndef _SDCONTAINER_H_
+#define _SDCONTAINER_H_
+
+#include <aips/aips.h>
+#include <aips/Utilities/String.h>
+#include <aips/Arrays/Array.h>
+#include <aips/Arrays/Vector.h>
+
+template<class T> class Matrix;
+
+namespace atnf_sd {
+
+class SDFrequencyTable {
+
+public:
+
+  SDFrequencyTable(Double refPix, Double refVal, Double inc) {;}
+  // returns the index into the table
+  // this creates a new one or returns an existing one
+  Int addFrequency(Double refPix, Double refVal, Double inc) {;}
+  
+  Int length() const { return nFreq_;};// # of stored Frequencies
+  // returns a Table with nRows == nFreq, and three cols
+
+private:
+  Int nFreq_;
+  Vector<Double> refPix_;
+  Vector<Double> revVal_;
+  Vector<Double> increment_;
+};
+
+
+class SDContainer {
+
+public:
+  SDContainer(uInt nBeam, uInt nIF, uInt nChan, uInt nPol);
+
+  virtual ~SDContainer();
+
+  Bool setSpectrum(const Matrix<Float>& spec,
+		   uInt whichBeam, uInt whichIF);
+  Bool putSpectrum(const Array<Float>& spec);
+
+  Bool setFlags(const Matrix<uChar>& flgs,
+		uInt whichBeam, uInt whichIF);
+  Bool putFlags(const Array<uChar>& spec);
+
+  Bool setTsys(const Vector<Float>& ts, 
+	       uInt whichBeam, uInt whichIF);
+  Bool putTsys(const Array<Float>& spec);
+
+  Bool setPointing(const Vector<Double>& point, uInt whichBeam) {;}
+
+  Bool setFrequencyMap(uInt freqslot, uInt whichIF) {;}
+  
+  const Array<Float>& getSpectrum() const { return spectrum_; }
+  const Array<uChar>& getFlags() const { return flags_; }
+  const Array<Float>& getTsys() const { return tsys_; }
+
+  Double timestamp;
+  String sourcename;
+  Double interval;
+  uInt scanid;
+  
+private:
+  uInt nBeam_,nIF_,nChan_,nPol_;
+
+  // (nBeam,nIF,nChannel,nPol)
+  Array<Float>    spectrum_;  
+  Array<uChar>    flags_;
+  // (nBeam,nIF,nPol)
+  Array<Float>    tsys_;
+  Array<Float>    tcal_;
+
+  //(nBeam) maybe use Measures here...
+  //*** Vector<Vector<Double>>  pointing_;
+  //(nIF) indx into "global" frequency table
+  Vector<uInt>            freqidx_;
+
+};
+
+} // namespace
+#endif
Index: /branches/atnf/src/SDMath.cc
===================================================================
--- /branches/atnf/src/SDMath.cc	(revision 3)
+++ /branches/atnf/src/SDMath.cc	(revision 3)
@@ -0,0 +1,96 @@
+//#---------------------------------------------------------------------------
+//# SDMath.cc: A collection of single dish mathematical operations
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#include <aips/aips.h>
+#include <aips/Utilities/String.h>
+#include <aips/Arrays/IPosition.h>
+#include <aips/Arrays/Array.h>
+#include <aips/Arrays/ArrayMath.h>
+#include <aips/Arrays/ArrayLogical.h>
+#include <aips/Arrays/MaskedArray.h>
+#include <aips/Arrays/MaskArrMath.h>
+#include <aips/Arrays/MaskArrLogi.h>
+
+#include <aips/Tables/Table.h>
+#include <aips/Tables/ScalarColumn.h>
+#include <aips/Tables/ArrayColumn.h>
+
+#include "SDContainer.h"
+#include "SDMemTable.h"
+
+#include "SDMath.h"
+
+using namespace atnf_sd;
+
+static CountedPtr<SDMemTable> SDMath::average(const CountedPtr<SDMemTable>& in) {
+  Table t = in->table();
+  ROArrayColumn<Float> tsys(t, "TSYS");  
+  ROScalarColumn<Double> mjd(t, "TIME");
+  ROScalarColumn<String> srcn(t, "SRCNAME");
+  IPosition ip = in->rowAsMaskedArray(0).shape();
+  Array<Float> outarr(ip); outarr =0.0;
+  Array<Float> narr(ip);narr = 0.0;
+  Array<Float> narrinc(ip);narrinc = 1.0;
+
+  Array<Float> tsarr(tsys.shape(0));
+  Array<Float> outtsarr(tsys.shape(0));
+  Double tme = 0.0;
+
+  for (uInt i=0; i < t.nrow(); i++) {
+    // data stuff
+    MaskedArray<Float> marr(in->rowAsMaskedArray(i));
+    outarr += marr;
+    MaskedArray<Float> n(narrinc,marr.getMask());
+    narr += n;
+    // get 
+    tsys.get(i, tsarr);// this is probably unneccessary as tsys should
+    outtsarr += tsarr; // be constant
+    Double tmp;
+    mjd.get(i,tmp);
+    tme += tmp;// average time
+  }
+  // averaging using mask
+  MaskedArray<Float> nma (narr,(narr > Float(0)));
+  outarr /= nma;
+
+  SDContainer sc(ip(0),ip(1),ip(2),ip(3));
+
+  Int n = t.nrow();
+  outtsarr /= Float(n/2);
+  sc.timestamp = tme/Double(n/2);
+
+  String tstr; srcn.getScalar(n,tstr);// get sourcename of "mid" point
+  sc.sourcename = tstr;
+  sc.putSpectrum(outarr);
+  //sc.putFlags(outflags);  
+  SDMemTable* sdmt = new SDMemTable(*in);
+  sdmt->putSDContainer(sc);
+  return CountedPtr<SDMemTable>(sdmt);
+}
Index: /branches/atnf/src/SDMath.h
===================================================================
--- /branches/atnf/src/SDMath.h	(revision 3)
+++ /branches/atnf/src/SDMath.h	(revision 3)
@@ -0,0 +1,50 @@
+//#---------------------------------------------------------------------------
+//# SDMath.h: A collection of single dish mathematical operations
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#ifndef _SDMATH_H_
+#define _SDMATH_H_
+
+#include <aips/Utilities/CountedPtr.h>
+
+namespace atnf_sd {
+
+class SDMemTable;
+
+class SDMath {
+public:
+  static CountedPtr<SDMemTable> average(const CountedPtr<SDMemTable>& in);
+  //SDMemTable quotient(const SDMemTable& on, const SDMemTable& off);
+  //SDMemTable multiply(SDMemTable& in, Float factor);
+  
+};
+
+} // namespace
+
+#endif
Index: /branches/atnf/src/SDMemTable.cc
===================================================================
--- /branches/atnf/src/SDMemTable.cc	(revision 3)
+++ /branches/atnf/src/SDMemTable.cc	(revision 3)
@@ -0,0 +1,248 @@
+//#---------------------------------------------------------------------------
+//# SDMemTable.cc: A MemoryTable container for single dish integrations
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+
+#include <aips/iostream.h>
+#include <aips/Arrays/Array.h>
+#include <aips/Arrays/ArrayMath.h>
+#include <aips/Arrays/MaskArrMath.h>
+#include <aips/Arrays/ArrayLogical.h>
+#include <aips/Arrays/ArrayAccessor.h>
+
+#include <aips/Tables/TableParse.h>
+#include <aips/Tables/TableDesc.h>
+#include <aips/Tables/SetupNewTab.h>
+#include <aips/Tables/ScaColDesc.h>
+#include <aips/Tables/ArrColDesc.h>
+
+#include <aips/Tables/ExprNode.h>
+#include <aips/Tables/ScalarColumn.h>
+#include <aips/Tables/ArrayColumn.h>
+
+#include "SDMemTable.h"
+#include "SDContainer.h"
+
+using namespace atnf_sd;
+
+SDMemTable::SDMemTable(const std::string& name) :
+  IFSel_(0),
+  beamSel_(0),
+  polSel_(0) {
+  name_ = String(name);
+  setup();
+}
+
+SDMemTable::SDMemTable(const SDMemTable& other) {
+  this->IFSel_= other.IFSel_;
+  this->beamSel_= other.beamSel_;
+  this->polSel_= other.polSel_;
+  this->chanMask_ = other.chanMask_;
+  this->name_ = String("dummy");
+  this->table_ = other.table_.copyToMemoryTable(String("dummy"));
+  // clear all rows()
+  this->table_.removeRow(this->table_.rowNumbers());
+}
+
+SDMemTable::SDMemTable(const Table& tab, Int scanID) :
+  IFSel_(0),
+  beamSel_(0),
+  polSel_(0) {
+  name_ = String("SDMemTable");
+  String exprs = String("select * from $1 where SCANID == ")
+    +String::toString(scanID);
+  cerr << exprs << endl;
+  Table t = tableCommand(exprs,tab);
+  table_ = t.copyToMemoryTable(name_);
+}
+
+SDMemTable::~SDMemTable(){
+  cerr << "goodbye from SDMemTable @ " << this << endl;
+}
+
+SDMemTable SDMemTable::getScan(Int scanID) {
+  return SDMemTable(table_, scanID);
+}
+
+void SDMemTable::setup() {
+  TableDesc td("", "1", TableDesc::Scratch);
+  td.comment() = "A SDMemTable";
+  //td.rwKeywordSet().define("VERSION",Float(0.1));
+  td.addColumn(ScalarColumnDesc<Double>("TIME"));
+  td.addColumn(ScalarColumnDesc<String>("SRCNAME"));
+  td.addColumn(ArrayColumnDesc<Float>("SPECTRA"));
+  td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA"));
+  td.addColumn(ArrayColumnDesc<Float>("TSYS"));  
+  td.addColumn(ScalarColumnDesc<Int>("SCANID"));  
+  // Now create a new table from the description.
+  SetupNewTable aNewTab(name_, td, Table::New);
+  table_ = Table(aNewTab, Table::Memory, 0);  
+}
+
+std::string SDMemTable::name() const {
+  return name_;
+}
+
+std::string SDMemTable::getSourceName(Int whichRow) const {
+  ROScalarColumn<String> src(table_, "SRCNAME");
+  String name;
+  src.get(whichRow, name);
+  return name;
+}
+
+Double SDMemTable::getTime(Int whichRow) const {
+  ROScalarColumn<Double> src(table_, "TIME");
+  Double tm;
+  src.get(whichRow, tm);
+  return tm;
+}
+
+bool SDMemTable::setIF(Int whichIF) {
+  //if ( whichIF >= 0 && whichIF < nIF_) {
+    IFSel_ = whichIF;
+    return true;
+    //}
+    //return false;
+}
+bool SDMemTable::setBeam(Int whichBeam) {
+  //if ( whichBeam >= 0 && whichBeam < nBeam_) {
+    beamSel_ = whichBeam;
+    return true;
+    //}
+    //return false;
+
+}
+bool SDMemTable::setPol(Int whichPol) {
+  //if ( whichPol >= 0 && whichPol < nPol_) {
+    polSel_ = whichPol;
+    return true;
+    //}
+    //return false;
+}
+
+bool SDMemTable::setChannels(const std::vector<int>& whichChans) {
+  //std::vector<bool>::iterator it;
+  //std::fill(chanMask_.begin(), chanMask_.end(), false);
+  //for (it = whichChans.begin(); it != whichChans.end(); it++) {
+  //chanMask_[*it] = true;
+  //}
+  cout << "SDMemTable::setChannels() disabled" << endl;
+  return true;
+}
+
+std::vector<bool> SDMemTable::getMask() const {
+  return chanMask_;
+}
+std::vector<float> SDMemTable::getSpectrum(Int whichRow) const {
+
+  std::vector<float> spectrum;
+  ROArrayColumn<Float> spec(table_, "SPECTRA");
+  Array<Float> arr;
+  spec.get(whichRow, arr);
+  ArrayAccessor<Float, Axis<0> > aa0(arr);
+  aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
+  ArrayAccessor<Float, Axis<1> > aa1(aa0);
+  aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
+  for (ArrayAccessor<Float, Axis<2> > i(aa1); i != i.end(); ++i) {
+    ArrayAccessor<Float, Axis<3> > aa2(i);
+    aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
+    spectrum.push_back(*aa2);
+  }
+  return spectrum;
+}
+
+MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow) {
+  ROArrayColumn<Float> spec(table_, "SPECTRA");
+  Array<Float> arr;
+  ROArrayColumn<uChar> flag(table_, "FLAGTRA");
+  Array<uChar> farr;
+  spec.get(whichRow, arr);
+  flag.get(whichRow, farr);
+  Array<Bool> barr(farr.shape());convertArray(barr, farr);
+  MaskedArray<Float> marr;
+  marr.setData(arr,!barr);
+  return marr;
+}
+
+
+Float SDMemTable::getTsys(Int whichRow) const {
+  ROArrayColumn<Float> ts(table_, "TSYS");
+  Array<Float> arr;
+  ts.get(whichRow, arr);
+  Float out;
+  IPosition ip(arr.shape());
+  ip(0) = beamSel_;ip(1) = IFSel_;ip(2) = polSel_;
+  out = arr(ip);
+  return out;
+}
+
+bool SDMemTable::putSDContainer(const SDContainer& sdc) {
+  ScalarColumn<Double> mjd(table_, "TIME");
+  ScalarColumn<String> srcn(table_, "SRCNAME");
+  ArrayColumn<Float> spec(table_, "SPECTRA");
+  ArrayColumn<uChar> flags(table_, "FLAGTRA");
+  ArrayColumn<Float> ts(table_, "TSYS");
+  ScalarColumn<Int> scan(table_, "SCANID");
+
+  uInt rno = table_.nrow();
+  table_.addRow();
+  
+  mjd.put(rno, sdc.timestamp);
+  srcn.put(rno, sdc.sourcename);
+  spec.put(rno, sdc.getSpectrum());
+  flags.put(rno, sdc.getFlags());
+  ts.put(rno, sdc.getTsys());
+  scan.put(rno, sdc.scanid);
+  return true;
+}
+void SDMemTable::makePersistent(const std::string& filename) {
+  table_.deepCopy(filename,Table::New);
+}
+
+void SDMemTable::summary() const {
+  cerr << "SDMemTable::summary()" << endl;
+  ROScalarColumn<Int> scans(table_, "SCANID");
+  ROScalarColumn<String> srcs(table_, "SRCNAME");
+  uInt count = 0;
+  String name;
+  Int previous = -1;Int current=0;
+  cout << "Scan\tSource" << endl;
+  for (uInt i=0; i< scans.nrow();i++) {
+    scans.getScalar(i,current);
+    if (previous != current) {
+      srcs.getScalar(i,name);
+      previous = current;     
+      count++;
+      cout << count << "\t" << name << endl;
+    }
+  }
+  cout << "Table contains " << table_.nrow() << "integrations." << endl;
+  cout << "in " << count << "scans." << endl;
+}
+
Index: /branches/atnf/src/SDMemTable.h
===================================================================
--- /branches/atnf/src/SDMemTable.h	(revision 3)
+++ /branches/atnf/src/SDMemTable.h	(revision 3)
@@ -0,0 +1,98 @@
+//#---------------------------------------------------------------------------
+//# SDMemTable.h: A MemoryTable container for single dish integrations
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#ifndef _SDMEMTABLE_H_
+#define _SDMEMTABLE_H_
+
+// STL
+#include <string>
+#include <vector>
+// AIPS++
+#include <aips/aips.h>
+#include <aips/Utilities/String.h>
+#include <aips/Tables/Table.h>
+#include <aips/Arrays/MaskedArray.h>
+
+namespace atnf_sd {
+
+class SDContainer;
+class SDHeader;
+class SDFrequencyTable;
+
+
+class SDMemTable {
+public:
+  SDMemTable(const std::string& name= "SDInputTable.tbl");
+  SDMemTable(const SDMemTable& other);
+
+  SDMemTable(const Table& tab, Int scanID);
+  virtual ~SDMemTable();
+  virtual bool putSDContainer(const SDContainer& sdc);
+  virtual bool putSDHeader(const SDHeader& sdh) {;}
+  virtual bool putSDFreqTable(const SDFrequencyTable& sdft) {;}
+  
+  virtual std::vector<float> getSpectrum(Int whichRow) const;
+  virtual std::vector<bool> getMask() const;
+  
+  MaskedArray<Float> rowAsMaskedArray(uInt whichRow);
+
+  virtual Float getTsys(Int whichRow) const;
+  virtual Double getTime(Int whichRow) const ;
+  virtual std::string getSourceName(Int whichRow) const ;
+  
+  virtual bool setIF(Int whichIF=0);
+  virtual bool setBeam(Int whichBeam=0);
+  virtual bool setPol(Int whichPol=0);    
+
+  virtual Int getIF() { return IFSel_; }
+  virtual Int getBeam() { return beamSel_; }
+  virtual Int getPol() { return polSel_; }   
+
+  //sets the mask
+  virtual bool setChannels(const std::vector<int>& whichChans);
+  
+  virtual void summary() const;
+  
+  std::string name() const;
+  void makePersistent(const std::string& filename);
+  SDMemTable getScan(Int scanID);
+  const Table& table() { return table_; }
+
+private:
+  void setup();
+  //Int nBeam_,nIF_,nChan_,nPol_;
+  Int IFSel_,beamSel_,polSel_;
+  std::vector<bool> chanMask_;
+  String name_;
+  Table table_;
+};
+
+}// namespace
+#endif
Index: /branches/atnf/src/SDMemTableWrapper.h
===================================================================
--- /branches/atnf/src/SDMemTableWrapper.h	(revision 3)
+++ /branches/atnf/src/SDMemTableWrapper.h	(revision 3)
@@ -0,0 +1,113 @@
+//#---------------------------------------------------------------------------
+//# SDMemTableWrapper.h: Wrapper classes to use CountedPtr
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#ifndef _SDMEMTABLEWRAPPER_H_
+#define _SDMEMTABLEWRAPPER_H_
+
+#include <vector>
+#include <string>
+
+#include "SDMemTable.h"
+#include "SDReader.h"
+#include "SDMath.h"
+
+namespace atnf_sd {
+
+class SDMemTableWrapper {
+
+public:
+  SDMemTableWrapper(const std::string& name = "SDinput.tbl") : 
+    table_(new SDMemTable(name)) {;}
+  SDMemTableWrapper(CountedPtr<SDMemTable> cp) : table_(cp) {;}
+  SDMemTableWrapper(SDMemTable* sdmt) : table_(sdmt) {;}
+  
+  SDMemTableWrapper(const SDMemTableWrapper& mt, int scan) :
+    table_(new SDMemTable(mt.getCP()->table(), scan)) {;}
+  
+  SDMemTableWrapper getScan(int scan) {
+    return SDMemTableWrapper(*this, scan);
+  }
+  std::vector<float> getSpectrum(int whichRow) const {
+    return table_->getSpectrum(whichRow);
+  }
+  float getTsys(int whichRow) {return table_->getTsys(whichRow);}
+  double getTime(int whichRow) {return table_->getTime(whichRow);}
+
+  std::vector<bool> getMask() const { return table_->getMask(); }
+
+  std::string getSourceName(int whichRow) {
+    return table_->getSourceName(whichRow);
+  }
+
+  bool setIF(int whichIF=0) {return table_->setIF(whichIF);}
+  bool setBeam(int whichBeam=0) {return table_->setBeam(whichBeam);}
+  bool setPol(int whichPol=0) {return table_->setPol(whichPol);} 
+
+  int getIF() {return table_->getIF();}
+  int getBeam() {return table_->getBeam();}
+  int getPol() {return table_->getPol();} 
+
+
+  //sets the mask
+  bool setChannels(const std::vector<int>& whichChans) {
+    return setChannels(whichChans); 
+  }
+  void makePersistent(const std::string& fname) {
+    table_->makePersistent(fname);
+  }
+  CountedPtr<SDMemTable> getCP() const {return table_;}
+  void summary() { table_->summary(); }
+  std::string name() { return table_->name(); }
+  
+private:
+  CountedPtr<SDMemTable> table_;
+};
+
+class SDReaderWrapper : public SDReader {
+public:
+  SDReaderWrapper() {;}
+  SDReaderWrapper(SDMemTableWrapper tbl) :
+    SDReader(tbl.getCP()){;}
+  SDMemTableWrapper getSDMemTable() const {
+    return SDMemTableWrapper(getTable());
+  }
+};
+
+class SDMathWrapper {
+public:
+  SDMemTableWrapper average(const SDMemTableWrapper& sdt) {
+    return SDMemTableWrapper(SDMath::average(sdt.getCP()));
+  }
+};
+
+} // namespace
+
+#endif
+
Index: /branches/atnf/src/SDReader.cc
===================================================================
--- /branches/atnf/src/SDReader.cc	(revision 3)
+++ /branches/atnf/src/SDReader.cc	(revision 3)
@@ -0,0 +1,233 @@
+//#---------------------------------------------------------------------------
+//# SDReader.cc: A class to read single dish spectra from SDFITS, RPFITS
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#include <atnf/PKSIO/PKSreader.h>
+
+#include "SDContainer.h"
+#include "SDReader.h"
+
+using namespace atnf_sd;
+
+SDReader::SDReader() :
+  reader_(0),
+  table_(new SDMemTable()) {
+  cursor_ = 0;
+  timestamp_ = 0;
+}
+
+SDReader::SDReader(CountedPtr<SDMemTable> tbl) :
+  reader_(0),
+  table_(tbl) {
+  cursor_ = 0;
+  timestamp_ = 0;
+}
+
+SDReader::~SDReader() {
+  delete reader_;reader_ =0;
+}
+
+void SDReader::reset() {
+  cursor_ = 0; 
+  timestamp_ = 0;
+  open(filename_);
+}
+
+void SDReader::open(const std::string& filename) {
+  if (reader_) delete reader_; reader_ = 0;
+  Bool   haveBase, haveSpectra, haveXPol;
+  //Int    nChan, nIF, nPol;
+  String inName(filename);
+  String format;
+  Vector<Bool> beams;
+  if ((reader_ = getPKSreader(inName, 0, False, format, beams, nIF_,
+                              nChan_, nPol_, haveBase, haveSpectra,
+                              haveXPol)) == 0)  {
+    cerr << "PKSreader failed" << endl;
+  }
+  if (!haveSpectra) {
+    delete reader_;
+    reader_ = 0;
+    cerr << "Spectral data absent." << endl;
+    return;
+  }
+  nBeam_ = beams.nelements();
+  cout << "Reading " + format + " format from " + inName << endl;
+  cout << "nChannels = " << nChan_ << ", " << "nPol = " << nPol_ << endl
+       << "nIF = " << nIF_ << endl 
+       << "nBeams = " << nBeam_ << endl;
+  
+  // Get basic parameters.
+  Double bandwidth, refFreq;
+  header_ = SDHeader();
+  header_.nchan = nChan_;
+  header_.npol = nPol_;
+  header_.nbeam = nBeam_;
+
+  //cerr << " getting header ..." << endl;
+  Int status = reader_->getHeader(header_.observer, header_.project, 
+				  header_.antennaname, header_.antennaposition,
+                                  header_.obstype,header_.equinox, 
+				  header_.freqref,
+				  header_.utc, header_.reffreq,
+                                  header_.bandwidth);
+  if (status) {
+    delete reader_;
+    reader_ = 0;
+    cerr << "Failed to get data description." << endl;
+    return;
+  }
+  header_.print();  
+  if ((header_.obstype).matches("*SW*")) {
+    // need robust way here - probably read ahead of next timestamp
+    cout << "Header indicates frequency switched observation.\n"
+      "setting # of IFs = 1 " << endl;
+    nIF_ = 1;
+  }
+  header_.nif = nIF_;
+  // Apply selection criteria.
+  cerr << "applying selection criteria..." << endl; 
+  Vector<Int> start(nIF_, 1);
+  Vector<Int> end(nIF_, 0);
+  Vector<Int> ref;
+  Vector<Bool> beamSel(nBeam_,True);
+  Vector<Bool> IFsel(nIF_,True);
+  reader_->select(beamSel, IFsel, start, end, ref, True, haveXPol);
+  cerr << "open finished" << endl;
+}
+
+int SDReader::read(const std::vector<int>& seq) {
+  cerr << "SDReader::read" << endl;
+  int status = 0;  
+  
+  Int    beamNo, IFno, refBeam, scanNo;
+  Float  azimuth, elevation, focusAxi, focusRot, focusTan, 
+    humidity, parAngle, pressure, temperature, windAz, windSpeed;
+  Double bandwidth, freqInc, interval, mjd, refFreq, srcVel;
+  String          fieldName, srcName, tcalTime;
+  Vector<Float>   calFctr, sigma, tcal, tsys;
+  Matrix<Float>   baseLin, baseSub;
+  Vector<Double>  direction(2), scanRate(2), srcDir(2), srcPM(2);
+  Matrix<Float>   spectra;
+  Matrix<uChar>   flagtra;
+  Complex         xCalFctr;
+  Vector<Complex> xPol;
+  mjd = 0;
+  uInt n = seq.size();
+  cerr <<  header_.nif << ", " << header_.nbeam << endl;
+  uInt stepsize = header_.nif*header_.nbeam;
+  cerr << "SDReader stepsize = " << stepsize << endl;
+  uInt scanid = 0;
+  String prevName = "_noname_";// temporary until scanid is present
+  uInt seqi = 0;
+  //SDFrequencyTable sdft();
+  Bool getAll = False;
+  if (seq[n-1] == -1) getAll = True;
+  while ( (cursor_ <= seq[n-1]) || getAll) {
+    // only needs to be create if in seq
+    SDContainer sc(header_.nbeam,header_.nif,header_.nchan,header_.npol);
+
+    // iterate over one correlator integration cycle = nBeam*nIF
+    for (uInt row=0; row < stepsize; row++) {
+
+      //cerr << "SDReader starting reading process row = " << row << endl;
+
+      // add scanid from GROUP field -- this will remove the need for
+      // stepsize as well
+      // spectra(nChan,nPol)!!!
+      status = reader_->read(scanNo, mjd, interval, fieldName, srcName,
+			     srcDir, srcPM, srcVel, IFno, refFreq,
+			     bandwidth, freqInc, tcal, tcalTime, 
+			     azimuth, elevation, parAngle, focusAxi, 
+			     focusTan, focusRot, temperature, pressure, 
+			     humidity, windSpeed, windAz, refBeam, 
+			     beamNo, direction, scanRate,
+			     tsys, sigma, calFctr, baseLin, baseSub, 
+			     spectra, flagtra, xCalFctr, xPol);          
+
+      // cerr << "SDReader row  read"<< endl;
+
+      if (status) {
+	if (status == -1) {
+	  // EOF.
+	  if (row < stepsize-1) cerr << "incomplete integration data." << endl;
+	  cerr << "EOF" << endl;
+	  return status;
+	}
+      }      
+      // if in the given list
+      if ( cursor_ == seq[seqi]) {
+
+	//cerr << "SDReader cursor == seq[i]" << endl;
+	
+	// add integration cycle
+	if (row==0) {
+	  //add invariant info: scanNo, mjd, interval, fieldName,
+	  //srcName, azimuth, elevation, parAngle, focusAxi, focusTan,
+	  //focusRot, temperature, pressure, humidity, windSpeed,
+	  //windAz  srcDir, srcPM, srcVel
+	}
+
+	// cerr << "SDReader::read -  before SDContainer" << endl;
+
+	// add specific info
+	// IFno beamNo are 1-relative
+	// refPix = nChan/2+1 in  Integer arith.!
+	uInt refPix = header_.nchan/2+1; 
+	//uInt frqslot = sdft.addFrequency(refPix, refFreq, freqInc);
+
+	if ( srcName != prevName ) {//temp
+	  scanid++;//temp
+	  prevName = srcName;//temp
+	}//temp
+
+	sc.sourcename = srcName;
+	sc.timestamp = mjd;
+	sc.interval = interval;
+	sc.scanid = scanid;
+	//sc.setFrequencyMap(frqslot,IFno-1);
+	sc.setSpectrum(spectra, beamNo-1, IFno-1);
+	sc.setFlags(flagtra,  beamNo-1, IFno-1);
+	sc.setTsys(tsys, beamNo-1, IFno-1);
+	//sc.addPointing(direction, beamNo-1);
+
+	// cerr << "SDReader::read -  after SDContainer" << endl;
+
+      }
+    }
+    if (cursor_ == seq[seqi]) {
+      // insert container into table/list
+      table_->putSDContainer(sc);
+      cout << "Reading integration " << seqi << endl;
+      seqi++;// next in list
+    }
+    cursor_++;
+  }
+  return status;
+}
Index: /branches/atnf/src/SDReader.h
===================================================================
--- /branches/atnf/src/SDReader.h	(revision 3)
+++ /branches/atnf/src/SDReader.h	(revision 3)
@@ -0,0 +1,114 @@
+//#---------------------------------------------------------------------------
+//# SDReader.h: A class to read single dish spectra from SDFITS, RPFITS
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#ifndef _SDREADER_H_
+#define _SDREADER_H_
+
+#include <vector>
+#include <string>
+
+#include <aips/aips.h>
+#include <aips/iostream.h>
+#include <aips/iomanip.h>
+#include <aips/Utilities/CountedPtr.h>
+#include <aips/Utilities/String.h>
+#include <aips/Arrays/Vector.h>
+
+#include "SDMemTable.h"
+
+class PKSreader;
+
+namespace atnf_sd {
+
+struct SDHeader {
+  Int nchan;
+  Int npol;
+  Int nif;
+  Int nbeam;
+  String observer;
+  String project;
+  String obstype;
+  String antennaname;
+  Vector<Double> antennaposition;
+  Float equinox;
+  String freqref;
+  Double reffreq;
+  Double bandwidth;
+  Double utc;
+  void print() {
+    cout << "Observer: " << this->observer << endl 
+	 << "Project: " << this->project << endl
+	 << "Obstype: " << this->obstype << endl
+	 << "Antenna: " << this->antennaname << endl
+	 << "Ant. Position: " << this->antennaposition << endl
+	 << "Equinox: " << this->equinox << endl
+	 << "Freq. ref.: " << this->freqref << endl
+	 << "Ref. frequency: " << this->reffreq << endl
+	 << "Bandwidth: "  << this->bandwidth << endl
+	 << "Time (utc): " << setprecision(10) << this->utc << endl;
+  };
+};
+
+class SDReader {
+public:
+  SDReader();
+  SDReader(CountedPtr<SDMemTable> tbl);
+  virtual ~SDReader();
+
+  void open(const std::string& filename);
+  int read(const std::vector<int>& seq);
+
+  CountedPtr<SDMemTable> getTable() const { return table_;}
+
+  void reset();
+
+  std::vector<int> pseudoHeader() const {
+    std::vector<int> v;
+    v.push_back(nBeam_);v.push_back(nIF_);
+    v.push_back(nChan_);v.push_back(nPol_);
+    return v;
+  }
+
+protected:
+
+private:
+  Int nBeam_,nIF_,nChan_,nPol_;
+  Bool getHeader();
+  PKSreader* reader_;  
+  SDHeader header_;
+  CountedPtr<SDMemTable> table_;
+  String filename_;
+  uInt cursor_;
+  Double timestamp_;
+};
+
+}// namespace
+#endif
+
Index: /branches/atnf/src/SDTemplates.cc
===================================================================
--- /branches/atnf/src/SDTemplates.cc	(revision 3)
+++ /branches/atnf/src/SDTemplates.cc	(revision 3)
@@ -0,0 +1,56 @@
+//#---------------------------------------------------------------------------
+//# SDTemplates.cc: explicit templates for aips++
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#include <aips/Exceptions/Error.cc>
+#include <aips/Exceptions/Error2.cc>
+#include <aips/Utilities/CountedPtr.cc>
+#include <aips/Utilities/CountedPtr2.cc>
+#include "SDMemTable.h"
+
+namespace atnf_sd {
+  template class CountedConstPtr<SDMemTable>;
+  template class CountedPtr<SDMemTable>;
+  template class PtrRep<SDMemTable>;
+  template class SimpleCountedConstPtr<SDMemTable>;
+  template class SimpleCountedPtr<SDMemTable>;
+}
+
+#include <aips/Arrays/ArrayLogical.cc>
+#include <aips/Arrays/ArrayMath.cc>
+#include <aips/Arrays/MaskArrMath.cc>
+#include <aips/Arrays/Array.h>
+
+template void convertArray(Array<Bool> &, Array<uChar> const &);
+//template void convertArray(Array<uChar> &, Array<Bool> const &);
+template LogicalArray operator!=(Array<Float> const &, Float const &);
+template LogicalArray operator==(Array<Float> const &, Float const &);
+template LogicalArray operator>(Array<Float> const &, Float const &);
+template LogicalArray operator>=(Array<Float> const &, Float const &);
+template Array<Float>& operator/=(Array<Float>&, MaskedArray<Float> const&);
Index: /branches/atnf/src/python_SD.cc
===================================================================
--- /branches/atnf/src/python_SD.cc	(revision 3)
+++ /branches/atnf/src/python_SD.cc	(revision 3)
@@ -0,0 +1,57 @@
+//#---------------------------------------------------------------------------
+//# python_SD.cc: python module for single dish package
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#include <string>
+#include <vector>
+#include <boost/python.hpp>
+#include <boost/python/pyconversions.h>
+
+#include "python_SD.h"
+
+using namespace boost::python;
+
+BOOST_PYTHON_MODULE(atnf_sd) {
+  atnf_sd::python::python_SDMemTable();
+  atnf_sd::python::python_SDReader();
+  atnf_sd::python::python_SDMath();
+
+  std_vector_to_tuple < int > ();
+  from_python_sequence < std::vector < int >,  
+    variable_capacity_policy > ();
+  std_vector_to_tuple < float > ();
+  from_python_sequence < std::vector < float >,  
+    variable_capacity_policy > ();
+  std_vector_to_tuple < std::string > ();
+  from_python_sequence < std::vector < std::string >,  
+    variable_capacity_policy > ();
+  std_vector_to_tuple < bool> ();
+  from_python_sequence < std::vector < bool >,  
+    variable_capacity_policy > ();
+}
Index: /branches/atnf/src/python_SD.h
===================================================================
--- /branches/atnf/src/python_SD.h	(revision 3)
+++ /branches/atnf/src/python_SD.h	(revision 3)
@@ -0,0 +1,44 @@
+//#---------------------------------------------------------------------------
+//# python_SD.h: python module for single dish package
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#ifndef _PYTHON_SD_H_
+#define _PYTHON_SD_H_
+
+namespace atnf_sd {
+  namespace python {
+
+void python_SDMemTable();
+void python_SDReader();
+void python_SDMath();
+
+  } // python
+} //atnf_sd
+
+#endif
Index: /branches/atnf/src/python_SDMath.cc
===================================================================
--- /branches/atnf/src/python_SDMath.cc	(revision 3)
+++ /branches/atnf/src/python_SDMath.cc	(revision 3)
@@ -0,0 +1,47 @@
+//#---------------------------------------------------------------------------
+//# python_SDMath.cc: python exposure of c++ SDMath class
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#include <boost/python.hpp>
+
+#include "SDMemTableWrapper.h"
+
+using namespace boost::python;
+
+namespace atnf_sd {
+  namespace python {
+
+void python_SDMath() {
+  class_<SDMathWrapper>("sdmath")
+    .def("average", &SDMathWrapper::average)
+    ;
+};
+
+  } // python
+}
Index: /branches/atnf/src/python_SDMemTable.cc
===================================================================
--- /branches/atnf/src/python_SDMemTable.cc	(revision 3)
+++ /branches/atnf/src/python_SDMemTable.cc	(revision 3)
@@ -0,0 +1,65 @@
+//#---------------------------------------------------------------------------
+//# python_SDMemTable.cc: python exposure of c++ SDMemTable class
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#include <vector>
+
+#include <boost/python.hpp>
+
+#include "SDMemTableWrapper.h"
+
+using namespace boost::python;
+
+namespace atnf_sd {
+  namespace python {
+
+void python_SDMemTable() {
+  class_<SDMemTableWrapper>("sdtable")
+    .def( init < std::string > () )
+    .def( init < SDMemTableWrapper, int > () )
+    .def("getscan", &SDMemTableWrapper::getScan)
+    .def("getspectrum", &SDMemTableWrapper::getSpectrum)
+    //.def("getmask", &SDMemTableWrapper::getMask)
+    .def("gettsys", &SDMemTableWrapper::getTsys)
+    .def("getsourcename", &SDMemTableWrapper::getSourceName)
+    .def("gettime", &SDMemTableWrapper::getTime)
+    .def("getif", &SDMemTableWrapper::getIF)
+    .def("getbeam", &SDMemTableWrapper::getBeam)
+    .def("getpol", &SDMemTableWrapper::getPol)
+    .def("setif", &SDMemTableWrapper::setIF)
+    .def("setbeam", &SDMemTableWrapper::setBeam)
+    .def("setpol", &SDMemTableWrapper::setPol)
+    .def("makepersistent",  &SDMemTableWrapper::makePersistent)
+    .def("summary",  &SDMemTableWrapper::summary)
+    .def("name",  &SDMemTableWrapper::name)
+  ;
+};
+
+  } // python
+} // atnf_sd
Index: /branches/atnf/src/python_SDReader.cc
===================================================================
--- /branches/atnf/src/python_SDReader.cc	(revision 3)
+++ /branches/atnf/src/python_SDReader.cc	(revision 3)
@@ -0,0 +1,51 @@
+//#---------------------------------------------------------------------------
+//# python_SDReader.cc: python exposure of c++ SDReader class
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#include <boost/python.hpp>
+
+#include "SDMemTableWrapper.h"
+
+using namespace boost::python;
+
+namespace atnf_sd {
+  namespace python {
+
+void python_SDReader() {
+  class_<SDReaderWrapper>("sdreader")
+    //.def( init < SDMemTableWrapper > () )
+    .def("open", &SDReaderWrapper::open)
+    .def("read", &SDReaderWrapper::read)
+    .def("gettable", &SDReaderWrapper::getSDMemTable)
+    .def("header",  &SDReaderWrapper::pseudoHeader);
+  ;
+};
+
+  }
+}
Index: /trunk/doc/README
===================================================================
--- /trunk/doc/README	(revision 3)
+++ /trunk/doc/README	(revision 3)
@@ -0,0 +1,4 @@
+Nothin here yet.
+This is not a release yet.
+
+Malte Marquarding.
Index: /trunk/src/Makefile
===================================================================
--- /trunk/src/Makefile	(revision 3)
+++ /trunk/src/Makefile	(revision 3)
@@ -0,0 +1,77 @@
+TARGET    = atnf_sd.so
+
+CXX	  = g++-3.2.3
+CXXFLAGS  = -fPIC -w -g -fpermissive -O2
+
+AIPSROOT = $(word 1, $(AIPSPATH))
+
+AIPSINC = -I$(AIPSROOT)/code/include \
+          -I$(AIPSROOT)/code/atnf \
+          -I$(AIPSROOT)/code/trial \
+          -I$(AIPSROOT)/code/aips
+
+AIPSLIB  = $(AIPSROOT)/linux_gnu/lib
+AIPSPPLIB = -L$(AIPSLIB) \
+	$(AIPSLIB)/version.o \
+        $(AIPSLIB)/libatnf.a \
+        $(AIPSLIB)/libtrial.a \
+        $(AIPSLIB)/libaips_f.a \
+        $(AIPSLIB)/libaips.a \
+        -llapack -lblas -lg2c -lcfitsio -lrpfits \
+        -lglish -ledit -lsos -lnpd
+
+LINK      = g++-3.2.3
+LFLAGS    = -shared -Wl,-soname,$(TARGET)
+#-rpath,/home/mar637/lib
+#LFLAGS    += -Xlinker -rpath -Xlinker -L$(AIPSLIB)
+
+BOOSTLIB  = -lboost_python-mt
+BOOSTINC  = 
+
+PYTHONINC = -I/usr/include/python2.2
+PYTHONLIB = -lpython2.2
+
+INCDIRS   = -I. $(AIPSINC) $(BOOSTINC) $(PYTHONINC)
+LIBDIRS   = $(BOOSTLIB) $(PYTHONLIB) $(AIPSPPLIB)
+
+OBJECTS   = SDContainer.o \
+	    SDMemTable.o \
+	    SDReader.o \
+            SDMath.o \
+	    SDTemplates.o \
+	    python_SDMemTable.o \
+	    python_SDReader.o \
+	    python_SDMath.o \
+	    python_SD.o
+
+HEADERS   = SDContainer.h \
+	    SDMemTable.h \
+	    SDReader.h \
+	    SDMath.h \
+	    SDMemTableWrapper.h \
+	    python_SD.h
+
+.SUFFIXES: .c .o .cpp .cc .cxx .C
+
+.cpp.o:
+	$(CXX) -c $(CXXFLAGS) $(INCDIRS) -o $@ $<
+
+.cc.o:
+	$(CXX) -c $(CXXFLAGS) $(INCDIRS) -o $@ $<
+
+.cxx.o:	
+	$(CXX) -c $(CXXFLAGS) $(INCDIRS) -o $@ $<
+
+.C.o:
+	$(CXX) -c $(CXXFLAGS) $(INCDIRS) -o $@ $<
+
+$(TARGET):  $(OBJECTS)
+	$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS)  $(LIBDIRS)
+
+$(OBJECTS): $(HEADERS)
+
+clean:
+	-rm -f $(OBJECTS)
+
+realclean: clean
+	-rm -f $(TARGET)
Index: /trunk/src/SDContainer.cc
===================================================================
--- /trunk/src/SDContainer.cc	(revision 3)
+++ /trunk/src/SDContainer.cc	(revision 3)
@@ -0,0 +1,134 @@
+//#---------------------------------------------------------------------------
+//# SDContainer.cc: A container class for single dish integrations
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#include <aips/Tables/Table.h>
+#include <aips/Arrays/IPosition.h>
+#include <aips/Arrays/ArrayAccessor.h>
+#include <aips/Arrays/Matrix.h>
+
+#include "SDContainer.h"
+
+using namespace atnf_sd;
+
+SDContainer::SDContainer(uInt nBeam, uInt nIF, uInt nChan, uInt nPol) 
+  : nBeam_(nBeam),
+  nIF_(nIF),
+  nChan_(nChan),
+  nPol_(nPol),
+  spectrum_(IPosition(4,nBeam,nIF,nChan,nPol)),
+  flags_(IPosition(4,nBeam,nIF,nChan,nPol)),
+  tsys_(IPosition(3,nBeam,nIF,nPol)) {
+  uChar x = 0;
+  flags_ = ~x;
+}
+
+SDContainer::~SDContainer() {
+}
+
+Bool SDContainer::putSpectrum(const Array<Float>& spec) {
+  spectrum_ = spec;
+}
+Bool SDContainer::putFlags(const Array<uChar>& spec) {
+  flags_ = spec;
+}
+Bool SDContainer::putTsys(const Array<Float>& spec) {
+  tsys_ = spec;
+}
+
+Bool SDContainer::setSpectrum(const Matrix<Float>& spec,
+			      uInt whichBeam, uInt whichIF) {
+
+  ArrayAccessor<Float, Axis<0> > aa0(spectrum_);
+  aa0.reset(aa0.begin(whichBeam));
+  ArrayAccessor<Float, Axis<1> > aa1(aa0);
+  aa1.reset(aa1.begin(whichIF));
+  
+  uInt nChan = spec.nrow();
+  uInt nPol  = spec.ncolumn();
+  Vector<Float> pols(nPol);
+  uInt chani = 0;
+  uInt poli = 0;
+  // assert dimensions are the same....
+  for (ArrayAccessor<Float, Axis<2> > i(aa1);i != i.end(); ++i) {
+    pols = spec.row(chani);
+    for (ArrayAccessor<Float, Axis<3> > ii(i);ii != ii.end(); ++ii) {
+      (*ii) = pols[poli];
+      poli++;
+    }
+    poli = 0;
+    chani++;
+  }
+  // unset flags for this spectrum, they might be set again by the
+  // setFlags method
+  IPosition shp = flags_.shape();
+  IPosition start(4,whichBeam,whichIF,0,0);
+  IPosition end(4,whichBeam,whichIF,shp(2)-1,shp(3)-1);
+  Array<uChar> arr(flags_(start,end));
+  arr = uChar(0);
+}
+
+Bool SDContainer::setFlags(const Matrix<uChar>& flag,
+			   uInt whichBeam, uInt whichIF) {
+
+  ArrayAccessor<uChar, Axis<0> > aa0(flags_);
+  aa0.reset(aa0.begin(whichBeam));
+  ArrayAccessor<uChar, Axis<1> > aa1(aa0);
+  aa1.reset(aa1.begin(whichIF));
+  
+  uInt nChan = flag.nrow();
+  uInt nPol  = flag.ncolumn();
+  Vector<uChar> pols(nPol);
+  uInt chani = 0;
+  uInt poli = 0;
+  // assert dimensions are the same....
+  for (ArrayAccessor<uChar, Axis<2> > i(aa1);i != i.end(); ++i) {
+    pols = flag.row(chani);
+    for (ArrayAccessor<uChar, Axis<3> > ii(i);ii != ii.end(); ++ii) {
+      (*ii) = uChar(pols[poli]);
+      poli++;
+    }
+    poli = 0;
+    chani++;
+  }
+}
+
+Bool SDContainer::setTsys(const Vector<Float>& tsys,
+			  uInt whichBeam, uInt whichIF) {
+  ArrayAccessor<Float, Axis<0> > aa0(tsys_);
+  aa0.reset(aa0.begin(whichBeam));
+  ArrayAccessor<Float, Axis<1> > aa1(aa0);
+  aa1.reset(aa1.begin(whichIF));
+  // assert dimensions are the same....
+  uInt idx = 0;
+  for (ArrayAccessor<Float, Axis<2> > i(aa1);i != i.end(); ++i) {
+    (*i) = tsys[idx];
+    idx++;
+  }  
+}
Index: /trunk/src/SDContainer.h
===================================================================
--- /trunk/src/SDContainer.h	(revision 3)
+++ /trunk/src/SDContainer.h	(revision 3)
@@ -0,0 +1,113 @@
+//#---------------------------------------------------------------------------
+//# SDContainer.h: A container class for single dish integrations
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#ifndef _SDCONTAINER_H_
+#define _SDCONTAINER_H_
+
+#include <aips/aips.h>
+#include <aips/Utilities/String.h>
+#include <aips/Arrays/Array.h>
+#include <aips/Arrays/Vector.h>
+
+template<class T> class Matrix;
+
+namespace atnf_sd {
+
+class SDFrequencyTable {
+
+public:
+
+  SDFrequencyTable(Double refPix, Double refVal, Double inc) {;}
+  // returns the index into the table
+  // this creates a new one or returns an existing one
+  Int addFrequency(Double refPix, Double refVal, Double inc) {;}
+  
+  Int length() const { return nFreq_;};// # of stored Frequencies
+  // returns a Table with nRows == nFreq, and three cols
+
+private:
+  Int nFreq_;
+  Vector<Double> refPix_;
+  Vector<Double> revVal_;
+  Vector<Double> increment_;
+};
+
+
+class SDContainer {
+
+public:
+  SDContainer(uInt nBeam, uInt nIF, uInt nChan, uInt nPol);
+
+  virtual ~SDContainer();
+
+  Bool setSpectrum(const Matrix<Float>& spec,
+		   uInt whichBeam, uInt whichIF);
+  Bool putSpectrum(const Array<Float>& spec);
+
+  Bool setFlags(const Matrix<uChar>& flgs,
+		uInt whichBeam, uInt whichIF);
+  Bool putFlags(const Array<uChar>& spec);
+
+  Bool setTsys(const Vector<Float>& ts, 
+	       uInt whichBeam, uInt whichIF);
+  Bool putTsys(const Array<Float>& spec);
+
+  Bool setPointing(const Vector<Double>& point, uInt whichBeam) {;}
+
+  Bool setFrequencyMap(uInt freqslot, uInt whichIF) {;}
+  
+  const Array<Float>& getSpectrum() const { return spectrum_; }
+  const Array<uChar>& getFlags() const { return flags_; }
+  const Array<Float>& getTsys() const { return tsys_; }
+
+  Double timestamp;
+  String sourcename;
+  Double interval;
+  uInt scanid;
+  
+private:
+  uInt nBeam_,nIF_,nChan_,nPol_;
+
+  // (nBeam,nIF,nChannel,nPol)
+  Array<Float>    spectrum_;  
+  Array<uChar>    flags_;
+  // (nBeam,nIF,nPol)
+  Array<Float>    tsys_;
+  Array<Float>    tcal_;
+
+  //(nBeam) maybe use Measures here...
+  //*** Vector<Vector<Double>>  pointing_;
+  //(nIF) indx into "global" frequency table
+  Vector<uInt>            freqidx_;
+
+};
+
+} // namespace
+#endif
Index: /trunk/src/SDMath.cc
===================================================================
--- /trunk/src/SDMath.cc	(revision 3)
+++ /trunk/src/SDMath.cc	(revision 3)
@@ -0,0 +1,96 @@
+//#---------------------------------------------------------------------------
+//# SDMath.cc: A collection of single dish mathematical operations
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#include <aips/aips.h>
+#include <aips/Utilities/String.h>
+#include <aips/Arrays/IPosition.h>
+#include <aips/Arrays/Array.h>
+#include <aips/Arrays/ArrayMath.h>
+#include <aips/Arrays/ArrayLogical.h>
+#include <aips/Arrays/MaskedArray.h>
+#include <aips/Arrays/MaskArrMath.h>
+#include <aips/Arrays/MaskArrLogi.h>
+
+#include <aips/Tables/Table.h>
+#include <aips/Tables/ScalarColumn.h>
+#include <aips/Tables/ArrayColumn.h>
+
+#include "SDContainer.h"
+#include "SDMemTable.h"
+
+#include "SDMath.h"
+
+using namespace atnf_sd;
+
+static CountedPtr<SDMemTable> SDMath::average(const CountedPtr<SDMemTable>& in) {
+  Table t = in->table();
+  ROArrayColumn<Float> tsys(t, "TSYS");  
+  ROScalarColumn<Double> mjd(t, "TIME");
+  ROScalarColumn<String> srcn(t, "SRCNAME");
+  IPosition ip = in->rowAsMaskedArray(0).shape();
+  Array<Float> outarr(ip); outarr =0.0;
+  Array<Float> narr(ip);narr = 0.0;
+  Array<Float> narrinc(ip);narrinc = 1.0;
+
+  Array<Float> tsarr(tsys.shape(0));
+  Array<Float> outtsarr(tsys.shape(0));
+  Double tme = 0.0;
+
+  for (uInt i=0; i < t.nrow(); i++) {
+    // data stuff
+    MaskedArray<Float> marr(in->rowAsMaskedArray(i));
+    outarr += marr;
+    MaskedArray<Float> n(narrinc,marr.getMask());
+    narr += n;
+    // get 
+    tsys.get(i, tsarr);// this is probably unneccessary as tsys should
+    outtsarr += tsarr; // be constant
+    Double tmp;
+    mjd.get(i,tmp);
+    tme += tmp;// average time
+  }
+  // averaging using mask
+  MaskedArray<Float> nma (narr,(narr > Float(0)));
+  outarr /= nma;
+
+  SDContainer sc(ip(0),ip(1),ip(2),ip(3));
+
+  Int n = t.nrow();
+  outtsarr /= Float(n/2);
+  sc.timestamp = tme/Double(n/2);
+
+  String tstr; srcn.getScalar(n,tstr);// get sourcename of "mid" point
+  sc.sourcename = tstr;
+  sc.putSpectrum(outarr);
+  //sc.putFlags(outflags);  
+  SDMemTable* sdmt = new SDMemTable(*in);
+  sdmt->putSDContainer(sc);
+  return CountedPtr<SDMemTable>(sdmt);
+}
Index: /trunk/src/SDMath.h
===================================================================
--- /trunk/src/SDMath.h	(revision 3)
+++ /trunk/src/SDMath.h	(revision 3)
@@ -0,0 +1,50 @@
+//#---------------------------------------------------------------------------
+//# SDMath.h: A collection of single dish mathematical operations
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#ifndef _SDMATH_H_
+#define _SDMATH_H_
+
+#include <aips/Utilities/CountedPtr.h>
+
+namespace atnf_sd {
+
+class SDMemTable;
+
+class SDMath {
+public:
+  static CountedPtr<SDMemTable> average(const CountedPtr<SDMemTable>& in);
+  //SDMemTable quotient(const SDMemTable& on, const SDMemTable& off);
+  //SDMemTable multiply(SDMemTable& in, Float factor);
+  
+};
+
+} // namespace
+
+#endif
Index: /trunk/src/SDMemTable.cc
===================================================================
--- /trunk/src/SDMemTable.cc	(revision 3)
+++ /trunk/src/SDMemTable.cc	(revision 3)
@@ -0,0 +1,248 @@
+//#---------------------------------------------------------------------------
+//# SDMemTable.cc: A MemoryTable container for single dish integrations
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+
+#include <aips/iostream.h>
+#include <aips/Arrays/Array.h>
+#include <aips/Arrays/ArrayMath.h>
+#include <aips/Arrays/MaskArrMath.h>
+#include <aips/Arrays/ArrayLogical.h>
+#include <aips/Arrays/ArrayAccessor.h>
+
+#include <aips/Tables/TableParse.h>
+#include <aips/Tables/TableDesc.h>
+#include <aips/Tables/SetupNewTab.h>
+#include <aips/Tables/ScaColDesc.h>
+#include <aips/Tables/ArrColDesc.h>
+
+#include <aips/Tables/ExprNode.h>
+#include <aips/Tables/ScalarColumn.h>
+#include <aips/Tables/ArrayColumn.h>
+
+#include "SDMemTable.h"
+#include "SDContainer.h"
+
+using namespace atnf_sd;
+
+SDMemTable::SDMemTable(const std::string& name) :
+  IFSel_(0),
+  beamSel_(0),
+  polSel_(0) {
+  name_ = String(name);
+  setup();
+}
+
+SDMemTable::SDMemTable(const SDMemTable& other) {
+  this->IFSel_= other.IFSel_;
+  this->beamSel_= other.beamSel_;
+  this->polSel_= other.polSel_;
+  this->chanMask_ = other.chanMask_;
+  this->name_ = String("dummy");
+  this->table_ = other.table_.copyToMemoryTable(String("dummy"));
+  // clear all rows()
+  this->table_.removeRow(this->table_.rowNumbers());
+}
+
+SDMemTable::SDMemTable(const Table& tab, Int scanID) :
+  IFSel_(0),
+  beamSel_(0),
+  polSel_(0) {
+  name_ = String("SDMemTable");
+  String exprs = String("select * from $1 where SCANID == ")
+    +String::toString(scanID);
+  cerr << exprs << endl;
+  Table t = tableCommand(exprs,tab);
+  table_ = t.copyToMemoryTable(name_);
+}
+
+SDMemTable::~SDMemTable(){
+  cerr << "goodbye from SDMemTable @ " << this << endl;
+}
+
+SDMemTable SDMemTable::getScan(Int scanID) {
+  return SDMemTable(table_, scanID);
+}
+
+void SDMemTable::setup() {
+  TableDesc td("", "1", TableDesc::Scratch);
+  td.comment() = "A SDMemTable";
+  //td.rwKeywordSet().define("VERSION",Float(0.1));
+  td.addColumn(ScalarColumnDesc<Double>("TIME"));
+  td.addColumn(ScalarColumnDesc<String>("SRCNAME"));
+  td.addColumn(ArrayColumnDesc<Float>("SPECTRA"));
+  td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA"));
+  td.addColumn(ArrayColumnDesc<Float>("TSYS"));  
+  td.addColumn(ScalarColumnDesc<Int>("SCANID"));  
+  // Now create a new table from the description.
+  SetupNewTable aNewTab(name_, td, Table::New);
+  table_ = Table(aNewTab, Table::Memory, 0);  
+}
+
+std::string SDMemTable::name() const {
+  return name_;
+}
+
+std::string SDMemTable::getSourceName(Int whichRow) const {
+  ROScalarColumn<String> src(table_, "SRCNAME");
+  String name;
+  src.get(whichRow, name);
+  return name;
+}
+
+Double SDMemTable::getTime(Int whichRow) const {
+  ROScalarColumn<Double> src(table_, "TIME");
+  Double tm;
+  src.get(whichRow, tm);
+  return tm;
+}
+
+bool SDMemTable::setIF(Int whichIF) {
+  //if ( whichIF >= 0 && whichIF < nIF_) {
+    IFSel_ = whichIF;
+    return true;
+    //}
+    //return false;
+}
+bool SDMemTable::setBeam(Int whichBeam) {
+  //if ( whichBeam >= 0 && whichBeam < nBeam_) {
+    beamSel_ = whichBeam;
+    return true;
+    //}
+    //return false;
+
+}
+bool SDMemTable::setPol(Int whichPol) {
+  //if ( whichPol >= 0 && whichPol < nPol_) {
+    polSel_ = whichPol;
+    return true;
+    //}
+    //return false;
+}
+
+bool SDMemTable::setChannels(const std::vector<int>& whichChans) {
+  //std::vector<bool>::iterator it;
+  //std::fill(chanMask_.begin(), chanMask_.end(), false);
+  //for (it = whichChans.begin(); it != whichChans.end(); it++) {
+  //chanMask_[*it] = true;
+  //}
+  cout << "SDMemTable::setChannels() disabled" << endl;
+  return true;
+}
+
+std::vector<bool> SDMemTable::getMask() const {
+  return chanMask_;
+}
+std::vector<float> SDMemTable::getSpectrum(Int whichRow) const {
+
+  std::vector<float> spectrum;
+  ROArrayColumn<Float> spec(table_, "SPECTRA");
+  Array<Float> arr;
+  spec.get(whichRow, arr);
+  ArrayAccessor<Float, Axis<0> > aa0(arr);
+  aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
+  ArrayAccessor<Float, Axis<1> > aa1(aa0);
+  aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
+  for (ArrayAccessor<Float, Axis<2> > i(aa1); i != i.end(); ++i) {
+    ArrayAccessor<Float, Axis<3> > aa2(i);
+    aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
+    spectrum.push_back(*aa2);
+  }
+  return spectrum;
+}
+
+MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow) {
+  ROArrayColumn<Float> spec(table_, "SPECTRA");
+  Array<Float> arr;
+  ROArrayColumn<uChar> flag(table_, "FLAGTRA");
+  Array<uChar> farr;
+  spec.get(whichRow, arr);
+  flag.get(whichRow, farr);
+  Array<Bool> barr(farr.shape());convertArray(barr, farr);
+  MaskedArray<Float> marr;
+  marr.setData(arr,!barr);
+  return marr;
+}
+
+
+Float SDMemTable::getTsys(Int whichRow) const {
+  ROArrayColumn<Float> ts(table_, "TSYS");
+  Array<Float> arr;
+  ts.get(whichRow, arr);
+  Float out;
+  IPosition ip(arr.shape());
+  ip(0) = beamSel_;ip(1) = IFSel_;ip(2) = polSel_;
+  out = arr(ip);
+  return out;
+}
+
+bool SDMemTable::putSDContainer(const SDContainer& sdc) {
+  ScalarColumn<Double> mjd(table_, "TIME");
+  ScalarColumn<String> srcn(table_, "SRCNAME");
+  ArrayColumn<Float> spec(table_, "SPECTRA");
+  ArrayColumn<uChar> flags(table_, "FLAGTRA");
+  ArrayColumn<Float> ts(table_, "TSYS");
+  ScalarColumn<Int> scan(table_, "SCANID");
+
+  uInt rno = table_.nrow();
+  table_.addRow();
+  
+  mjd.put(rno, sdc.timestamp);
+  srcn.put(rno, sdc.sourcename);
+  spec.put(rno, sdc.getSpectrum());
+  flags.put(rno, sdc.getFlags());
+  ts.put(rno, sdc.getTsys());
+  scan.put(rno, sdc.scanid);
+  return true;
+}
+void SDMemTable::makePersistent(const std::string& filename) {
+  table_.deepCopy(filename,Table::New);
+}
+
+void SDMemTable::summary() const {
+  cerr << "SDMemTable::summary()" << endl;
+  ROScalarColumn<Int> scans(table_, "SCANID");
+  ROScalarColumn<String> srcs(table_, "SRCNAME");
+  uInt count = 0;
+  String name;
+  Int previous = -1;Int current=0;
+  cout << "Scan\tSource" << endl;
+  for (uInt i=0; i< scans.nrow();i++) {
+    scans.getScalar(i,current);
+    if (previous != current) {
+      srcs.getScalar(i,name);
+      previous = current;     
+      count++;
+      cout << count << "\t" << name << endl;
+    }
+  }
+  cout << "Table contains " << table_.nrow() << "integrations." << endl;
+  cout << "in " << count << "scans." << endl;
+}
+
Index: /trunk/src/SDMemTable.h
===================================================================
--- /trunk/src/SDMemTable.h	(revision 3)
+++ /trunk/src/SDMemTable.h	(revision 3)
@@ -0,0 +1,98 @@
+//#---------------------------------------------------------------------------
+//# SDMemTable.h: A MemoryTable container for single dish integrations
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#ifndef _SDMEMTABLE_H_
+#define _SDMEMTABLE_H_
+
+// STL
+#include <string>
+#include <vector>
+// AIPS++
+#include <aips/aips.h>
+#include <aips/Utilities/String.h>
+#include <aips/Tables/Table.h>
+#include <aips/Arrays/MaskedArray.h>
+
+namespace atnf_sd {
+
+class SDContainer;
+class SDHeader;
+class SDFrequencyTable;
+
+
+class SDMemTable {
+public:
+  SDMemTable(const std::string& name= "SDInputTable.tbl");
+  SDMemTable(const SDMemTable& other);
+
+  SDMemTable(const Table& tab, Int scanID);
+  virtual ~SDMemTable();
+  virtual bool putSDContainer(const SDContainer& sdc);
+  virtual bool putSDHeader(const SDHeader& sdh) {;}
+  virtual bool putSDFreqTable(const SDFrequencyTable& sdft) {;}
+  
+  virtual std::vector<float> getSpectrum(Int whichRow) const;
+  virtual std::vector<bool> getMask() const;
+  
+  MaskedArray<Float> rowAsMaskedArray(uInt whichRow);
+
+  virtual Float getTsys(Int whichRow) const;
+  virtual Double getTime(Int whichRow) const ;
+  virtual std::string getSourceName(Int whichRow) const ;
+  
+  virtual bool setIF(Int whichIF=0);
+  virtual bool setBeam(Int whichBeam=0);
+  virtual bool setPol(Int whichPol=0);    
+
+  virtual Int getIF() { return IFSel_; }
+  virtual Int getBeam() { return beamSel_; }
+  virtual Int getPol() { return polSel_; }   
+
+  //sets the mask
+  virtual bool setChannels(const std::vector<int>& whichChans);
+  
+  virtual void summary() const;
+  
+  std::string name() const;
+  void makePersistent(const std::string& filename);
+  SDMemTable getScan(Int scanID);
+  const Table& table() { return table_; }
+
+private:
+  void setup();
+  //Int nBeam_,nIF_,nChan_,nPol_;
+  Int IFSel_,beamSel_,polSel_;
+  std::vector<bool> chanMask_;
+  String name_;
+  Table table_;
+};
+
+}// namespace
+#endif
Index: /trunk/src/SDMemTableWrapper.h
===================================================================
--- /trunk/src/SDMemTableWrapper.h	(revision 3)
+++ /trunk/src/SDMemTableWrapper.h	(revision 3)
@@ -0,0 +1,113 @@
+//#---------------------------------------------------------------------------
+//# SDMemTableWrapper.h: Wrapper classes to use CountedPtr
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#ifndef _SDMEMTABLEWRAPPER_H_
+#define _SDMEMTABLEWRAPPER_H_
+
+#include <vector>
+#include <string>
+
+#include "SDMemTable.h"
+#include "SDReader.h"
+#include "SDMath.h"
+
+namespace atnf_sd {
+
+class SDMemTableWrapper {
+
+public:
+  SDMemTableWrapper(const std::string& name = "SDinput.tbl") : 
+    table_(new SDMemTable(name)) {;}
+  SDMemTableWrapper(CountedPtr<SDMemTable> cp) : table_(cp) {;}
+  SDMemTableWrapper(SDMemTable* sdmt) : table_(sdmt) {;}
+  
+  SDMemTableWrapper(const SDMemTableWrapper& mt, int scan) :
+    table_(new SDMemTable(mt.getCP()->table(), scan)) {;}
+  
+  SDMemTableWrapper getScan(int scan) {
+    return SDMemTableWrapper(*this, scan);
+  }
+  std::vector<float> getSpectrum(int whichRow) const {
+    return table_->getSpectrum(whichRow);
+  }
+  float getTsys(int whichRow) {return table_->getTsys(whichRow);}
+  double getTime(int whichRow) {return table_->getTime(whichRow);}
+
+  std::vector<bool> getMask() const { return table_->getMask(); }
+
+  std::string getSourceName(int whichRow) {
+    return table_->getSourceName(whichRow);
+  }
+
+  bool setIF(int whichIF=0) {return table_->setIF(whichIF);}
+  bool setBeam(int whichBeam=0) {return table_->setBeam(whichBeam);}
+  bool setPol(int whichPol=0) {return table_->setPol(whichPol);} 
+
+  int getIF() {return table_->getIF();}
+  int getBeam() {return table_->getBeam();}
+  int getPol() {return table_->getPol();} 
+
+
+  //sets the mask
+  bool setChannels(const std::vector<int>& whichChans) {
+    return setChannels(whichChans); 
+  }
+  void makePersistent(const std::string& fname) {
+    table_->makePersistent(fname);
+  }
+  CountedPtr<SDMemTable> getCP() const {return table_;}
+  void summary() { table_->summary(); }
+  std::string name() { return table_->name(); }
+  
+private:
+  CountedPtr<SDMemTable> table_;
+};
+
+class SDReaderWrapper : public SDReader {
+public:
+  SDReaderWrapper() {;}
+  SDReaderWrapper(SDMemTableWrapper tbl) :
+    SDReader(tbl.getCP()){;}
+  SDMemTableWrapper getSDMemTable() const {
+    return SDMemTableWrapper(getTable());
+  }
+};
+
+class SDMathWrapper {
+public:
+  SDMemTableWrapper average(const SDMemTableWrapper& sdt) {
+    return SDMemTableWrapper(SDMath::average(sdt.getCP()));
+  }
+};
+
+} // namespace
+
+#endif
+
Index: /trunk/src/SDReader.cc
===================================================================
--- /trunk/src/SDReader.cc	(revision 3)
+++ /trunk/src/SDReader.cc	(revision 3)
@@ -0,0 +1,233 @@
+//#---------------------------------------------------------------------------
+//# SDReader.cc: A class to read single dish spectra from SDFITS, RPFITS
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#include <atnf/PKSIO/PKSreader.h>
+
+#include "SDContainer.h"
+#include "SDReader.h"
+
+using namespace atnf_sd;
+
+SDReader::SDReader() :
+  reader_(0),
+  table_(new SDMemTable()) {
+  cursor_ = 0;
+  timestamp_ = 0;
+}
+
+SDReader::SDReader(CountedPtr<SDMemTable> tbl) :
+  reader_(0),
+  table_(tbl) {
+  cursor_ = 0;
+  timestamp_ = 0;
+}
+
+SDReader::~SDReader() {
+  delete reader_;reader_ =0;
+}
+
+void SDReader::reset() {
+  cursor_ = 0; 
+  timestamp_ = 0;
+  open(filename_);
+}
+
+void SDReader::open(const std::string& filename) {
+  if (reader_) delete reader_; reader_ = 0;
+  Bool   haveBase, haveSpectra, haveXPol;
+  //Int    nChan, nIF, nPol;
+  String inName(filename);
+  String format;
+  Vector<Bool> beams;
+  if ((reader_ = getPKSreader(inName, 0, False, format, beams, nIF_,
+                              nChan_, nPol_, haveBase, haveSpectra,
+                              haveXPol)) == 0)  {
+    cerr << "PKSreader failed" << endl;
+  }
+  if (!haveSpectra) {
+    delete reader_;
+    reader_ = 0;
+    cerr << "Spectral data absent." << endl;
+    return;
+  }
+  nBeam_ = beams.nelements();
+  cout << "Reading " + format + " format from " + inName << endl;
+  cout << "nChannels = " << nChan_ << ", " << "nPol = " << nPol_ << endl
+       << "nIF = " << nIF_ << endl 
+       << "nBeams = " << nBeam_ << endl;
+  
+  // Get basic parameters.
+  Double bandwidth, refFreq;
+  header_ = SDHeader();
+  header_.nchan = nChan_;
+  header_.npol = nPol_;
+  header_.nbeam = nBeam_;
+
+  //cerr << " getting header ..." << endl;
+  Int status = reader_->getHeader(header_.observer, header_.project, 
+				  header_.antennaname, header_.antennaposition,
+                                  header_.obstype,header_.equinox, 
+				  header_.freqref,
+				  header_.utc, header_.reffreq,
+                                  header_.bandwidth);
+  if (status) {
+    delete reader_;
+    reader_ = 0;
+    cerr << "Failed to get data description." << endl;
+    return;
+  }
+  header_.print();  
+  if ((header_.obstype).matches("*SW*")) {
+    // need robust way here - probably read ahead of next timestamp
+    cout << "Header indicates frequency switched observation.\n"
+      "setting # of IFs = 1 " << endl;
+    nIF_ = 1;
+  }
+  header_.nif = nIF_;
+  // Apply selection criteria.
+  cerr << "applying selection criteria..." << endl; 
+  Vector<Int> start(nIF_, 1);
+  Vector<Int> end(nIF_, 0);
+  Vector<Int> ref;
+  Vector<Bool> beamSel(nBeam_,True);
+  Vector<Bool> IFsel(nIF_,True);
+  reader_->select(beamSel, IFsel, start, end, ref, True, haveXPol);
+  cerr << "open finished" << endl;
+}
+
+int SDReader::read(const std::vector<int>& seq) {
+  cerr << "SDReader::read" << endl;
+  int status = 0;  
+  
+  Int    beamNo, IFno, refBeam, scanNo;
+  Float  azimuth, elevation, focusAxi, focusRot, focusTan, 
+    humidity, parAngle, pressure, temperature, windAz, windSpeed;
+  Double bandwidth, freqInc, interval, mjd, refFreq, srcVel;
+  String          fieldName, srcName, tcalTime;
+  Vector<Float>   calFctr, sigma, tcal, tsys;
+  Matrix<Float>   baseLin, baseSub;
+  Vector<Double>  direction(2), scanRate(2), srcDir(2), srcPM(2);
+  Matrix<Float>   spectra;
+  Matrix<uChar>   flagtra;
+  Complex         xCalFctr;
+  Vector<Complex> xPol;
+  mjd = 0;
+  uInt n = seq.size();
+  cerr <<  header_.nif << ", " << header_.nbeam << endl;
+  uInt stepsize = header_.nif*header_.nbeam;
+  cerr << "SDReader stepsize = " << stepsize << endl;
+  uInt scanid = 0;
+  String prevName = "_noname_";// temporary until scanid is present
+  uInt seqi = 0;
+  //SDFrequencyTable sdft();
+  Bool getAll = False;
+  if (seq[n-1] == -1) getAll = True;
+  while ( (cursor_ <= seq[n-1]) || getAll) {
+    // only needs to be create if in seq
+    SDContainer sc(header_.nbeam,header_.nif,header_.nchan,header_.npol);
+
+    // iterate over one correlator integration cycle = nBeam*nIF
+    for (uInt row=0; row < stepsize; row++) {
+
+      //cerr << "SDReader starting reading process row = " << row << endl;
+
+      // add scanid from GROUP field -- this will remove the need for
+      // stepsize as well
+      // spectra(nChan,nPol)!!!
+      status = reader_->read(scanNo, mjd, interval, fieldName, srcName,
+			     srcDir, srcPM, srcVel, IFno, refFreq,
+			     bandwidth, freqInc, tcal, tcalTime, 
+			     azimuth, elevation, parAngle, focusAxi, 
+			     focusTan, focusRot, temperature, pressure, 
+			     humidity, windSpeed, windAz, refBeam, 
+			     beamNo, direction, scanRate,
+			     tsys, sigma, calFctr, baseLin, baseSub, 
+			     spectra, flagtra, xCalFctr, xPol);          
+
+      // cerr << "SDReader row  read"<< endl;
+
+      if (status) {
+	if (status == -1) {
+	  // EOF.
+	  if (row < stepsize-1) cerr << "incomplete integration data." << endl;
+	  cerr << "EOF" << endl;
+	  return status;
+	}
+      }      
+      // if in the given list
+      if ( cursor_ == seq[seqi]) {
+
+	//cerr << "SDReader cursor == seq[i]" << endl;
+	
+	// add integration cycle
+	if (row==0) {
+	  //add invariant info: scanNo, mjd, interval, fieldName,
+	  //srcName, azimuth, elevation, parAngle, focusAxi, focusTan,
+	  //focusRot, temperature, pressure, humidity, windSpeed,
+	  //windAz  srcDir, srcPM, srcVel
+	}
+
+	// cerr << "SDReader::read -  before SDContainer" << endl;
+
+	// add specific info
+	// IFno beamNo are 1-relative
+	// refPix = nChan/2+1 in  Integer arith.!
+	uInt refPix = header_.nchan/2+1; 
+	//uInt frqslot = sdft.addFrequency(refPix, refFreq, freqInc);
+
+	if ( srcName != prevName ) {//temp
+	  scanid++;//temp
+	  prevName = srcName;//temp
+	}//temp
+
+	sc.sourcename = srcName;
+	sc.timestamp = mjd;
+	sc.interval = interval;
+	sc.scanid = scanid;
+	//sc.setFrequencyMap(frqslot,IFno-1);
+	sc.setSpectrum(spectra, beamNo-1, IFno-1);
+	sc.setFlags(flagtra,  beamNo-1, IFno-1);
+	sc.setTsys(tsys, beamNo-1, IFno-1);
+	//sc.addPointing(direction, beamNo-1);
+
+	// cerr << "SDReader::read -  after SDContainer" << endl;
+
+      }
+    }
+    if (cursor_ == seq[seqi]) {
+      // insert container into table/list
+      table_->putSDContainer(sc);
+      cout << "Reading integration " << seqi << endl;
+      seqi++;// next in list
+    }
+    cursor_++;
+  }
+  return status;
+}
Index: /trunk/src/SDReader.h
===================================================================
--- /trunk/src/SDReader.h	(revision 3)
+++ /trunk/src/SDReader.h	(revision 3)
@@ -0,0 +1,114 @@
+//#---------------------------------------------------------------------------
+//# SDReader.h: A class to read single dish spectra from SDFITS, RPFITS
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#ifndef _SDREADER_H_
+#define _SDREADER_H_
+
+#include <vector>
+#include <string>
+
+#include <aips/aips.h>
+#include <aips/iostream.h>
+#include <aips/iomanip.h>
+#include <aips/Utilities/CountedPtr.h>
+#include <aips/Utilities/String.h>
+#include <aips/Arrays/Vector.h>
+
+#include "SDMemTable.h"
+
+class PKSreader;
+
+namespace atnf_sd {
+
+struct SDHeader {
+  Int nchan;
+  Int npol;
+  Int nif;
+  Int nbeam;
+  String observer;
+  String project;
+  String obstype;
+  String antennaname;
+  Vector<Double> antennaposition;
+  Float equinox;
+  String freqref;
+  Double reffreq;
+  Double bandwidth;
+  Double utc;
+  void print() {
+    cout << "Observer: " << this->observer << endl 
+	 << "Project: " << this->project << endl
+	 << "Obstype: " << this->obstype << endl
+	 << "Antenna: " << this->antennaname << endl
+	 << "Ant. Position: " << this->antennaposition << endl
+	 << "Equinox: " << this->equinox << endl
+	 << "Freq. ref.: " << this->freqref << endl
+	 << "Ref. frequency: " << this->reffreq << endl
+	 << "Bandwidth: "  << this->bandwidth << endl
+	 << "Time (utc): " << setprecision(10) << this->utc << endl;
+  };
+};
+
+class SDReader {
+public:
+  SDReader();
+  SDReader(CountedPtr<SDMemTable> tbl);
+  virtual ~SDReader();
+
+  void open(const std::string& filename);
+  int read(const std::vector<int>& seq);
+
+  CountedPtr<SDMemTable> getTable() const { return table_;}
+
+  void reset();
+
+  std::vector<int> pseudoHeader() const {
+    std::vector<int> v;
+    v.push_back(nBeam_);v.push_back(nIF_);
+    v.push_back(nChan_);v.push_back(nPol_);
+    return v;
+  }
+
+protected:
+
+private:
+  Int nBeam_,nIF_,nChan_,nPol_;
+  Bool getHeader();
+  PKSreader* reader_;  
+  SDHeader header_;
+  CountedPtr<SDMemTable> table_;
+  String filename_;
+  uInt cursor_;
+  Double timestamp_;
+};
+
+}// namespace
+#endif
+
Index: /trunk/src/SDTemplates.cc
===================================================================
--- /trunk/src/SDTemplates.cc	(revision 3)
+++ /trunk/src/SDTemplates.cc	(revision 3)
@@ -0,0 +1,56 @@
+//#---------------------------------------------------------------------------
+//# SDTemplates.cc: explicit templates for aips++
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#include <aips/Exceptions/Error.cc>
+#include <aips/Exceptions/Error2.cc>
+#include <aips/Utilities/CountedPtr.cc>
+#include <aips/Utilities/CountedPtr2.cc>
+#include "SDMemTable.h"
+
+namespace atnf_sd {
+  template class CountedConstPtr<SDMemTable>;
+  template class CountedPtr<SDMemTable>;
+  template class PtrRep<SDMemTable>;
+  template class SimpleCountedConstPtr<SDMemTable>;
+  template class SimpleCountedPtr<SDMemTable>;
+}
+
+#include <aips/Arrays/ArrayLogical.cc>
+#include <aips/Arrays/ArrayMath.cc>
+#include <aips/Arrays/MaskArrMath.cc>
+#include <aips/Arrays/Array.h>
+
+template void convertArray(Array<Bool> &, Array<uChar> const &);
+//template void convertArray(Array<uChar> &, Array<Bool> const &);
+template LogicalArray operator!=(Array<Float> const &, Float const &);
+template LogicalArray operator==(Array<Float> const &, Float const &);
+template LogicalArray operator>(Array<Float> const &, Float const &);
+template LogicalArray operator>=(Array<Float> const &, Float const &);
+template Array<Float>& operator/=(Array<Float>&, MaskedArray<Float> const&);
Index: /trunk/src/python_SD.cc
===================================================================
--- /trunk/src/python_SD.cc	(revision 3)
+++ /trunk/src/python_SD.cc	(revision 3)
@@ -0,0 +1,57 @@
+//#---------------------------------------------------------------------------
+//# python_SD.cc: python module for single dish package
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#include <string>
+#include <vector>
+#include <boost/python.hpp>
+#include <boost/python/pyconversions.h>
+
+#include "python_SD.h"
+
+using namespace boost::python;
+
+BOOST_PYTHON_MODULE(atnf_sd) {
+  atnf_sd::python::python_SDMemTable();
+  atnf_sd::python::python_SDReader();
+  atnf_sd::python::python_SDMath();
+
+  std_vector_to_tuple < int > ();
+  from_python_sequence < std::vector < int >,  
+    variable_capacity_policy > ();
+  std_vector_to_tuple < float > ();
+  from_python_sequence < std::vector < float >,  
+    variable_capacity_policy > ();
+  std_vector_to_tuple < std::string > ();
+  from_python_sequence < std::vector < std::string >,  
+    variable_capacity_policy > ();
+  std_vector_to_tuple < bool> ();
+  from_python_sequence < std::vector < bool >,  
+    variable_capacity_policy > ();
+}
Index: /trunk/src/python_SD.h
===================================================================
--- /trunk/src/python_SD.h	(revision 3)
+++ /trunk/src/python_SD.h	(revision 3)
@@ -0,0 +1,44 @@
+//#---------------------------------------------------------------------------
+//# python_SD.h: python module for single dish package
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#ifndef _PYTHON_SD_H_
+#define _PYTHON_SD_H_
+
+namespace atnf_sd {
+  namespace python {
+
+void python_SDMemTable();
+void python_SDReader();
+void python_SDMath();
+
+  } // python
+} //atnf_sd
+
+#endif
Index: /trunk/src/python_SDMath.cc
===================================================================
--- /trunk/src/python_SDMath.cc	(revision 3)
+++ /trunk/src/python_SDMath.cc	(revision 3)
@@ -0,0 +1,47 @@
+//#---------------------------------------------------------------------------
+//# python_SDMath.cc: python exposure of c++ SDMath class
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#include <boost/python.hpp>
+
+#include "SDMemTableWrapper.h"
+
+using namespace boost::python;
+
+namespace atnf_sd {
+  namespace python {
+
+void python_SDMath() {
+  class_<SDMathWrapper>("sdmath")
+    .def("average", &SDMathWrapper::average)
+    ;
+};
+
+  } // python
+}
Index: /trunk/src/python_SDMemTable.cc
===================================================================
--- /trunk/src/python_SDMemTable.cc	(revision 3)
+++ /trunk/src/python_SDMemTable.cc	(revision 3)
@@ -0,0 +1,65 @@
+//#---------------------------------------------------------------------------
+//# python_SDMemTable.cc: python exposure of c++ SDMemTable class
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#include <vector>
+
+#include <boost/python.hpp>
+
+#include "SDMemTableWrapper.h"
+
+using namespace boost::python;
+
+namespace atnf_sd {
+  namespace python {
+
+void python_SDMemTable() {
+  class_<SDMemTableWrapper>("sdtable")
+    .def( init < std::string > () )
+    .def( init < SDMemTableWrapper, int > () )
+    .def("getscan", &SDMemTableWrapper::getScan)
+    .def("getspectrum", &SDMemTableWrapper::getSpectrum)
+    //.def("getmask", &SDMemTableWrapper::getMask)
+    .def("gettsys", &SDMemTableWrapper::getTsys)
+    .def("getsourcename", &SDMemTableWrapper::getSourceName)
+    .def("gettime", &SDMemTableWrapper::getTime)
+    .def("getif", &SDMemTableWrapper::getIF)
+    .def("getbeam", &SDMemTableWrapper::getBeam)
+    .def("getpol", &SDMemTableWrapper::getPol)
+    .def("setif", &SDMemTableWrapper::setIF)
+    .def("setbeam", &SDMemTableWrapper::setBeam)
+    .def("setpol", &SDMemTableWrapper::setPol)
+    .def("makepersistent",  &SDMemTableWrapper::makePersistent)
+    .def("summary",  &SDMemTableWrapper::summary)
+    .def("name",  &SDMemTableWrapper::name)
+  ;
+};
+
+  } // python
+} // atnf_sd
Index: /trunk/src/python_SDReader.cc
===================================================================
--- /trunk/src/python_SDReader.cc	(revision 3)
+++ /trunk/src/python_SDReader.cc	(revision 3)
@@ -0,0 +1,51 @@
+//#---------------------------------------------------------------------------
+//# python_SDReader.cc: python exposure of c++ SDReader class
+//#---------------------------------------------------------------------------
+//# Copyright (C) 2004
+//# Malte Marquarding, ATNF
+//#
+//# 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.,
+//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
+//#
+//# Correspondence concerning this software should be addressed as follows:
+//#        Internet email: Malte.Marquarding@csiro.au
+//#        Postal address: Malte Marquarding,
+//#                        Australia Telescope National Facility,
+//#                        P.O. Box 76,
+//#                        Epping, NSW, 2121,
+//#                        AUSTRALIA
+//#
+//# $Id:
+//#---------------------------------------------------------------------------
+#include <boost/python.hpp>
+
+#include "SDMemTableWrapper.h"
+
+using namespace boost::python;
+
+namespace atnf_sd {
+  namespace python {
+
+void python_SDReader() {
+  class_<SDReaderWrapper>("sdreader")
+    //.def( init < SDMemTableWrapper > () )
+    .def("open", &SDReaderWrapper::open)
+    .def("read", &SDReaderWrapper::read)
+    .def("gettable", &SDReaderWrapper::getSDMemTable)
+    .def("header",  &SDReaderWrapper::pseudoHeader);
+  ;
+};
+
+  }
+}
