casa  $Rev:20696$
PlotCalHooks.h
Go to the documentation of this file.
00001 //# PlotCalHooks.cc: Callbacks for PlotCal
00002 //# Copyright (C) 1996,1997,1998,2001,2002,2003
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 //----------------------------------------------------------------------------
00028 
00029 #if !defined CASA_PLOTCAL_HOOKS_H
00030 #define CASA_PLOTCAL_HOOKS_H
00031 
00032 //# System Includes
00033 #include <stdio.h>
00034 #include <iostream>
00035 #include <iomanip>
00036 
00037 //# General CASA includes
00038 #include <casa/BasicSL/String.h>
00039 
00040 //# Table and TablePlot includes
00041 #include <tableplot/TablePlot/TablePlot.h>
00042 
00043 
00044 namespace casa { //# NAMESPACE CASA - BEGIN
00045 
00046 
00047 class PlotCalReset : public TPResetCallBack
00048 {
00049 public:
00050   PlotCalReset( PlotCal *inPlotCal )
00051   {
00052     itsPlotCal = inPlotCal;
00053   };
00054   
00055   ~PlotCalReset() {};
00056   
00057   Bool reset() {
00058     cout << "Resetting plotcal" << endl;
00059     itsPlotCal->close();
00060     return True;
00061   };
00062   
00063 private:
00064   PlotCal *itsPlotCal;
00065 };
00066 
00067 
00068 class PlotCalCallBacks : public TPGuiCallBackHooks
00069 {
00070 public:
00071   PlotCalCallBacks(Record metainfo,Bool isNCT):
00072     TPGuiCallBackHooks(),
00073     isNCT_p(isNCT)
00074  {
00075     LocateColumns.resize(4);
00076     LocateColumns[0] = "ANTENNA1";
00077     LocateColumns[1] = "FIELD_ID";
00078     LocateColumns[2] = "TIME";
00079     LocateColumns[3] = CDIcol();
00080 
00081     if (metainfo.isDefined("fieldNames"))
00082       fieldNames_p = metainfo.asArrayString("fieldNames");
00083     
00084     if (metainfo.isDefined("antNames")) 
00085       antNames_p = metainfo.asArrayString("antNames");
00086 
00087     if (metainfo.isDefined("spwIds")) 
00088       spwIds_p = metainfo.asArrayInt("spwIds");
00089 
00090     //    cout << "fieldNames_p = " << fieldNames_p << endl;
00091     //    cout << "antNames_p   = " << antNames_p << endl;
00092     //    cout << "spwIds_p     = " << spwIds_p << endl;
00093 
00094   };
00095 
00096   ~PlotCalCallBacks(){
00097     cout << "PlotCalCallBacks dtor" << endl;
00098   };
00099 
00100   casa::Bool flagdata(String tablename) {
00101     //    cout << "PlotCalCallBacks :: Completed flagging on : "
00102     //         << tablename << endl;
00103     return True;
00104   }
00105   casa::Bool releasetable(Int nrows, Int ncols, Int panel, String tablename) {
00106     //    cout << "PlotCalCallBacks :: releasing "
00107     //         << tablename << " from panel "
00108     //         << nrows << "," <<ncols << "," << panel << endl;
00109     return True;
00110   }
00111   casa::Bool createiterplotlabels( Vector<String> iteraxes,
00112                                    Vector<Double> values,
00113                                    String &titleString ) {
00114     //    cout << "iteraxes    = " << iteraxes << endl;
00115     //    cout << "values      = " << values << endl;
00116 
00117     titleString="    ";
00118     for (uInt i=0;i<iteraxes.nelements();++i) {
00119 
00120       if (iteraxes(i)=="ANTENNA1") {
00121         if (antNames_p.nelements()>0 && values(i)<antNames_p.nelements())
00122           titleString = titleString + "  Antenna=\\'" + antNames_p((Int)values(i)) + "\\'";
00123         else
00124           titleString = titleString + "  AntId=" + String::toString((Int)values(i));
00125       }
00126       if (iteraxes(i)=="FIELD_ID") {
00127         if (fieldNames_p.nelements()>0 && values(i)<fieldNames_p.nelements())
00128           titleString = titleString + "  Field=\\'" + fieldNames_p((Int)values(i)) + "\\'";
00129         else
00130           titleString = titleString + "  FldId=" + String::toString((Int)values(i));
00131       }
00132       if (iteraxes(i)==CDIcol()) {
00133         if (spwIds_p.nelements()>0 && values(i)<spwIds_p.nelements())
00134           titleString = titleString + "  Spw=\\'" + String::toString(spwIds_p((Int)values(i))) + "\\'";
00135         else
00136           titleString = titleString + "  CalId=" + String::toString((Int)values(i));
00137       }
00138       if (iteraxes(i)=="TIME") {
00139         titleString = titleString + "  Time=\\'" + MVTime(values(i)/C::day).string( MVTime::TIME,7) + "\\'";
00140       }
00141     }
00142 
00143     //    cout << "titleString = " << titleString << endl;
00144     
00145     return True;
00146 
00147   }
00148 
00149   casa::Bool printlocateinfo(Vector<String> collist,
00150                              Matrix<Double> infomat,
00151                              Vector<String> cpol) {
00152 
00153     LogIO log;
00154 
00155     if (infomat.shape()[1]>0) {
00156       //      cout << "collist = " << collist << endl;
00157       //      cout << "infomat = " << infomat << endl;
00158       //      cout << "cpol    = " << cpol << endl;
00159 
00160       //      log << "Found the following calibration samples in the region:" << LogIO::POST;
00161 
00162       for (Int j=0;j<infomat.shape()[1];++j) {
00163         log << MVTime( infomat(4, j)/C::day).string( MVTime::YMD,7) << " ";
00164 
00165         if (antNames_p.nelements()>0 && uInt(infomat(2,j))<antNames_p.nelements())
00166           log << " Antenna=" << "'" << antNames_p((Int)infomat(2,j)) << "'";
00167         else
00168           log << " AntId=" << infomat(2,j);
00169             
00170         if (spwIds_p.nelements()>0 && uInt(infomat(5,j))<spwIds_p.nelements())
00171           log << " SpwId=" << spwIds_p((Int)infomat(5,j));
00172         else
00173           log << " CalId=" << infomat(5,j);
00174           
00175         if (fieldNames_p.nelements()>0 && uInt(infomat(3,j))<fieldNames_p.nelements())
00176           log << " Field=" << "'" << fieldNames_p((Int)infomat(3,j)) << "'";
00177         else
00178           log << " FldId=" << infomat(3,j);
00179 
00180         log << " pol,chan=" << cpol(j);
00181            
00182         log << LogIO::POST;
00183 
00184       }
00185 
00186     }
00187     return True;
00188   }
00189 
00190 private:
00191 
00192   inline String CDIcol() { return (isNCT_p ? "SPECTRAL_WINDOW_ID" : "CAL_DESC_ID"); };
00193 
00194 
00195   Vector<String> fieldNames_p;
00196   Vector<String> antNames_p;
00197   Vector<Int> spwIds_p;
00198 
00199   Bool isNCT_p;
00200 
00201 };
00202 
00203 
00204 class PlotCalFreqAxes : public TPConvertChanToFreq
00205 {
00206 public :
00207   PlotCalFreqAxes(const Vector<Int>& cdlist,
00208                   const Vector<Double>& startFreq,
00209                   const Vector<Double>& stepFreq) {
00210     cdList = cdlist;
00211     offsetV = startFreq;
00212     intervalV = stepFreq;
00213     //    cout << cdList << " " << offsetV << " " << intervalV << endl;
00214 
00215   }
00216   ~PlotCalFreqAxes(){};
00217   Double offset,interval;
00218   inline Double Xconvert_col(Double x,Int row,Int tblNum){
00219     return x*intervalV(cdList(tblNum)) + offsetV(cdList(tblNum));
00220   }
00221 
00222 private:
00223   Vector<Int> cdList;
00224   Vector<Double> offsetV;
00225   Vector<Double> intervalV;
00226 
00227 };
00228 
00229 
00230 class PlotCalParang : public TPConvertBase
00231 {
00232 public:
00233   PlotCalParang(Vector<Vector<Int> >& fldlists) {
00234     // Set up MSDerivedValues to do calc
00235     fldLists = fldlists;
00236   };
00237   ~PlotCalParang(){};
00238   inline Double Xconvert(Double x,
00239                          Int row,
00240                          Int tblNum) {
00241     //    cout << "PCP::Xconvert: " << tblNum << " " << row << " " << x 
00242     //   << fldLists(tblNum)(row)
00243     //   << endl;
00244     return x;
00245   }
00246 private:
00247 
00248   Vector<Vector<Int> > fldLists;
00249 };
00250 
00251 
00252 } //# NAMESPACE CASA - END
00253 
00254 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines