casa  $Rev:20696$
MsPlotHooks.h
Go to the documentation of this file.
00001 //# MsPlotHooks.h: The hookcs (callback) classes given to TablePlot to allow
00002 //                 MsPlot to control some of the plotting issues.
00003 //# Copyright (C) 2003-2008
00004 //# Associated Universities, Inc. Washington DC, USA.
00005 //#
00006 //# This library is free software; you can redistribute it and/or modify it
00007 //# under the terms of the GNU Library General Public License as published by
00008 //# the Free Software Foundation; either version 2 of the License, or (at your
00009 //# option) any later version.
00010 //#
00011 //# This library is distributed in the hope that it will be useful, but WITHOUT
00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 //# License for more details.
00015 //#
00016 //# You should have received a copy of the GNU Library General Public License
00017 //# along with this library; if not, write to the Free Software Foundation,
00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00019 //#
00020 //# Correspondence concerning AIPS++ should be addressed as follows:
00021 //#        Internet email: aips2-request@nrao.edu.
00022 //#        Postal address: AIPS++ Project Office
00023 //#                        National Radio Astronomy Observatory
00024 //#                        520 Edgemont Road
00025 //#                        Charlottesville, VA 22903-2475 USA
00026 //#
00027 //#
00028 //# $Id:$
00029 //#
00030 //# -------------------------------------------------------------------------
00031 //# Change Log
00032 //# Date   Name       Description
00033 //# 11/19/2007  S. Jaeger   Fixed up the message handling
00034 //#
00035 
00036 
00037 #if !defined CASA_MSPLOT_HOOKS_H
00038 #define CASA_MSPLOT_HOOKS_H
00039 
00040 //# System Includes
00041 #include <stdio.h>
00042 #include <iostream>
00043 #include <iomanip>
00044 
00045 //# General CASA includes
00046 #include <casa/BasicSL/String.h>
00047 #include <casa/Arrays/Slice.h>
00048 
00049 //# Table and TablePlot includes
00050 #include <tableplot/TablePlot/TablePlot.h>
00051 
00052 #include <tableplot/TablePlot/SLog.h>
00053 #include <flagging/Flagging/Flagger.h>
00054 #include <flagging/Flagging/ExtendFlagger.h>
00055 
00056 #define LOG0 0
00057 #define LOG2 1
00058 
00059 namespace casa { //# NAMESPACE CASA - BEGIN
00060 
00061 //#!//////////////////////////////////////////////////////////////////////////
00062 //#! All the wonderful docs, that will show up in the user reference
00063 //#! manual for this class.
00064     
00065 // <summary>
00066 // This class is provided to TablePlot to be called when someone
00067 // resets the TablePlot class.
00068 // </summary>
00069 //
00070 //#! <use visibility=local>   or   <use visibility=export>
00071 // <use visibility=local>
00072 //#!
00073 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00074 //#! for example:
00075 //#!  <reviewed reviewer="pshannon@nrao.edu" date="1994/10/10" tests="tMyClass, t1MyClass" demos="dMyClass, d1MyClass">
00076 //#!  </reviewed>
00077 // </reviewed>
00078 //
00079 //#! Classes or concepts you should understand before using this class.
00080 // <prerequisite>
00081 // <ul>    
00082 //   <li> <linkto class="TPResetCallback">TPResetCallback</linkto>class,
00083 //   <li> <linkto class="TablePlot">TablePlot</linkto>class, 
00084 //   <li> <linkto class="Table">MsPlot</linkto> class
00085 // </ul>    
00086 // </prerequisite>
00087 //    
00088 // <etymology>
00089 // Does the necessary cleanup, object destruction setting class variables
00090 // to intial values, and such when a reset occurs.
00091 // </etymology>
00092 //
00093 // <synopsis>
00094 // </synopsis>
00095 //
00096 // <example>
00097 // </example>
00098 //
00099 // <motivation>
00100 // To provide a way for the TablePlot object to inform the MsPlot object
00101 // that a reset has occured.    
00102 // </motivation>
00103 //
00104 // <thrown>
00105 //    <li> AIPSError
00106 // </thrown>
00107 //
00108 // <todo asof="2007/10/29">
00109 //   <li> Restructure MsPlot to subclass TablePlot and rewrite the
00110 //        MsPlot reset command to do what it needs to do then call
00111 //        the parents reset method.    
00112 //   <li> Figure out why the plot window isn't being destroyed after
00113 //        a reset
00114 // </todo>
00115 //#! End of documentation.    
00116 //#!///////////////////////////////////////////////////////////////////////////
00117     
00118 class MSPlotReset : public TPResetCallBack
00119 {
00120  public:
00121     MSPlotReset( MsPlot *inMsPlot )
00122     {
00123        String fnname = "MSPlotReset";
00124        log = SLog::slog();
00125    log->FnEnter(fnname, clname);
00126    
00127    itsMsPlot = inMsPlot;
00128 
00129    log->FnExit(fnname, clname);
00130     };
00131 
00132     ~MSPlotReset() {
00133      String fnname = "MSPlotReset";
00134    log->FnEnter(fnname, clname);
00135 
00136    log->FnExit(fnname, clname);
00137     };
00138 
00139     Bool reset() {
00140      String fnname = "reset";
00141    log->FnEnter(fnname, clname);
00142 
00143    log->FnExit(fnname, clname);
00144    return True;
00145     };
00146     
00147 
00148  private:
00149     MsPlot *itsMsPlot;
00150 
00151     // Message logger
00152     SLog *log;
00153     static const String clname;
00154 };
00155 
00156 const String MSPlotReset::clname = "MSPlotReset"; 
00157 //#!///////////////////////////////////////////////////////////////////////////
00158 //#! 
00159 //#!      HOOK CLASSES - All classes used with TablePlot, these classes are
00160 //#!                     hooks into TablePlot.  They are called when regions
00161 //#!                     have been "marked" and user has requested something 
00162 //#!                     be done with these regions.
00163 //#!
00164 //#!///////////////////////////////////////////////////////////////////////////
00165 
00166 
00167 //#!//////////////////////////////////////////////////////////////////////////
00168 //#! All the wonderful docs, that will show up in the user reference
00169 //#! manual for this class.
00170 // <summary>
00171 // This class is provided to TablePlot to allow MsPlot to do the proper thing
00172 // when button's are pressed on the plotting GUI. 
00173 // </summary>
00174 //
00175 //#! <use visibility=local>   or   <use visibility=export>
00176 // <use visibility=local>
00177 //#!
00178 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00179 //#! for example:
00180 //#!  <reviewed reviewer="pshannon@nrao.edu" date="1994/10/10" tests="tMyClass, t1MyClass" demos="dMyClass, d1MyClass">
00181 //#!  </reviewed>
00182 // </reviewed>
00183 //
00184 //#! Classes or concepts you should understand before using this class.
00185 // <prerequisite>
00186 // <ul>
00187 //   <li> <linkto class="TPGuiCallBackHooks">TPGuiCallBackHooks</linkto>class,
00188 //   <li> <linkto class="TablePlot">TablePlot</linkto>class, 
00189 //   <li> <linkto class="Table">MsPlot</linkto> class
00190 //   <li> <linkto class="Table">Measurement Set</linkto> class 
00191 // </ul>    
00192 // </prerequisite>
00193 //    
00194 // <etymology>
00195 // Callbacks from TablePlot to MsPlot that are executed when buttons are
00196 // pressed on the plotting GUI, and the data that has been plotted resides
00197 // in the main table of the Measurement Set. 
00198 // </etymology>
00199 //
00200 // <synopsis>
00201 // </synopsis>
00202 //
00203 // <example>
00204 // </example>
00205 //
00206 // <motivation>
00207 // To provide a way for the TablePlot object to inform the MsPlot object
00208 // that a particular button has been pressed on the plotting GUI and to
00209 // allow MS Plot to over ride the default TablePlot behaviour if necessary. 
00210 // </motivation>
00211 //
00212 // <thrown>
00213 //    <li> AIPSError
00214 // </thrown>
00215 //
00216 // <todo asof="2007/12/19">
00217 //   <li> Implement the relaseTable method.
00218 //   <li> Finish the documentation
00219 //   <li> Restructure TablePlot to send rows of data, rather then single
00220 //        data point.  This should improve the plotting speed as it will
00221 //        allow reuse of calculations more easily.
00222 //   <li> Build methods into MsPlot, or some other class that retrieves
00223 //        information from the tables.  Examples of methods are, getFieldNames,
00224 //        getAntNames, ...  This could help reduce the memory usage, reduce
00225 //        code duplication, and improve robustness. 
00226 //   <li> Restructure MsPlot to subclass TablePlot and rewrite the
00227 //        MsPlot reset command to do what it needs to do then call
00228 //        the parents reset method.    
00229 // </todo>
00230 //#! End of documentation.    
00231 //#!///////////////////////////////////////////////////////////////////////////
00232 class MSPlotMainMSCallBack : public TPGuiCallBackHooks
00233 {
00234     public: 
00235       MSPlotMainMSCallBack( MeasurementSet *inMS,
00236          Vector<String> antNames,
00237          //Matrix<Int> baselines,
00238          Vector<String> fieldNames,
00239          Vector<Vector<String> >corrNames,
00240          Vector<Double> refFrequencies,
00241          String msname,
00242          String extendChn,
00243          String extendCor,
00244          String extendSp,
00245          String extendAnts,
00246          String extendTm,
00247          Bool crossbl,
00248          Double avetime,
00249          MeasurementSet *aMS)
00250      {
00251          log = SLog::slog();
00252          String fnname = "MSPlotMainMSCallBack";
00253 #if LOG2 
00254          log->FnEnter(fnname + 
00255           "(inMS, antNames, fieldNames, corrNames, refFrequencies)", clname);
00256 #endif 
00257                  
00258          localMS = inMS;
00259          itsAntNames = antNames;
00260          //itsBaselines = baselines;
00261          itsFieldNames = fieldNames;
00262          itsCorrNames = corrNames;
00263          itsRefFrequencies = refFrequencies;
00264          flagms = msname;
00265          extendChan = extendChn;
00266          extendCorr = extendCor;
00267          extendSpw = extendSp;
00268          extendAnt = extendAnts;
00269          extendTime = extendTm;
00270          aveBl = crossbl;
00271          aveTime = avetime;
00272          aveMS = aMS;
00273          
00274          LocateColumns.resize(5);
00275          LocateColumns[0] = "ANTENNA1";
00276          LocateColumns[1] = "ANTENNA2";
00277          LocateColumns[2] = "FIELD_ID";
00278          LocateColumns[3] = "TIME";
00279          LocateColumns[4] = "DATA_DESC_ID";
00280          //cout << "itsBaseLines=" << itsBaselines << endl;
00281 
00282 #if LOG2 
00283          log->FnExit(fnname, clname);
00284 #endif 
00285      };
00286       
00287       ~MSPlotMainMSCallBack(){
00288           String fnname =  "~MSPlotMainMSCallback";
00289 #if LOG2 
00290           log->FnEnter(fnname, clname);
00291 
00292           log->FnExit(fnname, clname);
00293 #endif 
00294       };
00295       
00296       casa::Bool
00297       releasetable( Int /*nrows*/, Int /*ncols*/, Int /*panel*/, String /*tablename*/ )
00298       {
00299           String fnname = "releasetable";
00300 #if LOG2 
00301           log->FnEnter(fnname + "(nrows,ncols,panel,tablename)", clname);
00302 #endif 
00303           //# TODO free any data structures that were created
00304           //# with this class, maybe call the class destructor too.
00305 
00306 #if LOG2 
00307           log->FnExit(fnname, clname);
00308 #endif 
00309           return True;
00310       }
00311 
00312       casa::Bool
00313       createiterplotlabels(Vector<String> iteraxes,
00314                            Vector<Double> values, String &titleString) {
00315          String fnname = "createiterplotlabels";
00316 #if LOG2 
00317          log->FnEnter(fnname + "(iteraxes, values, titleString)", clname );
00318 #endif 
00319          //cout << " values=" << values << endl;
00320          //for (uInt i = 0; i < itsAntNames.nelements(); i++)
00321          //   cout << itsAntNames[i] << " " ;
00322          //cout << endl;
00323 
00324          titleString = "Iter: ";
00325          //cout << "main call back createiterplotlabels" << endl;  
00326          uInt iterNum = iteraxes.nelements();
00327          for (uint axesId = 0; axesId < iterNum; axesId++) {
00328             if (upcase(iteraxes[axesId]).matches("BASELINE") || 
00329                 upcase(iteraxes[axesId]).matches("ANTENNA") ||
00330                 upcase(iteraxes[axesId]).matches("ANTENNA1") || 
00331                 upcase(iteraxes[axesId]).matches("ANTENNA2")) {
00332                //cout << "iteraxes[axesId]=" << iteraxes[axesId] << endl;
00333                if (iterNum == 2 && 
00334                    upcase(iteraxes[0]).contains("ANTENNA") && 
00335                    upcase(iteraxes[1]).contains("ANTENNA")) {
00336                   if (axesId == 0)
00337                      titleString += "Baseline ";
00338                } 
00339                else {
00340                   titleString += String("Antenna") +
00341                         (iteraxes[axesId].contains("2") ? "2" : "1")
00342                         + String(" ");
00343                }
00344             
00345                if (values[axesId] < itsAntNames.nelements()) {
00346                   if (axesId > 0)
00347                      titleString += String(" : ");
00348                   titleString += itsAntNames[Int(values[axesId])];
00349                } 
00350                else {
00351 #if LOG2 
00352                    ostringstream os;
00353                    os << "Internal error! Antenna ID is "
00354                       << values[axesId]
00355                       << ", but there are only "
00356                       << itsAntNames.nelements()
00357                       << ".";
00358                    log->out(os, fnname, clname, LogMessage::DEBUG1); 
00359 #endif 
00360                }
00361                
00362             } 
00363             else if (upcase(iteraxes[axesId]).matches("FIELD") || 
00364                     upcase(iteraxes[axesId]).matches("FIELD_ID") ) {
00365                 titleString += "FIELD ";
00366                 if ( values[axesId] < itsFieldNames.nelements() ) {
00367                     if ( axesId > 0 )
00368                         titleString += String( " : " );
00369                     titleString += itsFieldNames[Int(values[axesId])];
00370                 } 
00371                 else {
00372 #if LOG2 
00373                   ostringstream os;
00374                   os << "Internal error! Field ID is "
00375                      << values[axesId]
00376                      << ", but there are only "
00377                      << itsFieldNames.nelements()
00378                      << ".";
00379                   log->out(os, fnname, clname, LogMessage::WARN); 
00380 #endif 
00381                }
00382             } else {
00383                 //# This includes SPW, SCAN, FEED, and ARRAY
00384                 //# since all of these don't have names.  This
00385                 //# may change in the future.
00386                 titleString += iteraxes[axesId] + String( " ");
00387     
00388                 if ( axesId > 0 )
00389                     titleString += String( " : " );
00390                 titleString += String::toString( Int(values[axesId]) );
00391             }
00392          }
00393          //cout << "titleString=" << titleString << endl;
00394          
00395          /*
00396          Bool selected = False;
00397          if (titleString.contains("Base")) {
00398             String selBase = titleString.after("Baseline ");
00399             for (Int k = 0; k < itsBaselines.shape()[0]; k++) {
00400                String inListBase = itsAntNames(itsBaselines(k, 0))
00401                                    + " : "
00402                                    + itsAntNames(itsBaselines(k,1));
00403                //cout << "inListBase=" << inListBase
00404                //     << " selBase=" << selBase << endl;
00405                if (inListBase == selBase)
00406                   selected = True;
00407             }
00408             //cout << "Baseline selected=" << selected << endl;
00409             return selected;
00410          }
00411          if (titleString.contains("Ante")) {
00412             String selAnt = titleString.after("Antenna");
00413             if (selAnt.length() < 2)
00414                selected = False;
00415             else if (selAnt.before(" ") == "2") {
00416                selAnt = selAnt.after(" ");
00417                for (Int k = 0; k < itsBaselines.shape()[0]; k++) {
00418                    String inListBase = itsAntNames(itsBaselines(k, 1));
00419                    //cout << "inListA2=" << inListBase
00420                    //     << " selAnt=" << selAnt << endl;
00421                    if (inListBase == selAnt)
00422                       selected = True;
00423                }
00424             }
00425             else {
00426                selAnt = selAnt.after(" ");
00427                for (Int k = 0; k < itsBaselines.shape()[0]; k++) {
00428                    String inListBase = itsAntNames(itsBaselines(k, 0));
00429                    //cout << "inListA1=" << inListBase
00430                    //     << " selAnt=" << selAnt << endl;
00431                    if (inListBase == selAnt)
00432                       selected = True;
00433                }
00434             }
00435             //cout << "selected=" << selected << endl;
00436             return selected;
00437          }
00438          */ 
00439 
00440          log->FnExit(fnname, clname);
00441          return True;
00442      };
00443          
00444      casa::Bool
00445      flagdata(String /*tablename*/) {
00446 #if LOG2 
00447          String fnname = "flagdata";
00448          log->FnEnter(fnname, clname);
00449          log->FnExit(fnname, clname);
00450 #endif 
00451          return True;
00452      }
00453 
00454       casa::Bool
00455       flagdisplay(Int direction, Vector<String> /*collist*/,
00456                 Matrix<Double> infomat, Vector<String> cpol) {
00457           String fnname = "flagdisplay";
00458           //cout << "MSPlotMainMSCallback::flagdisplay flag=" << direction << endl;
00459          
00460           IPosition mshape = infomat.shape();
00461           //cout << "infomat.shape=[" << mshape[0] << ", "
00462           //     << mshape[1] << "] cpol.size=" << cpol.size() << endl;
00463 
00464           //cout << "flag display now...." << endl;
00465           //cout << "aveMS=" << aveMS << endl;
00466           //cout << "aveMS=" << *aveMS << endl;
00467           //cout << "collist=" << collist << endl;
00468           //cout << "infomat=" << infomat << endl;
00469           //cout << "cpol=" << cpol << endl;
00470 //--------------------------------------------------------------
00471           ROMSDataDescColumns dataDescCol(aveMS->dataDescription());
00472           ROMSSpWindowColumns spwColumn(aveMS->spectralWindow());
00473 
00474           //Int maxrows = ms.nrow();
00475           Int maxrows = 0;
00476           for (Int i = 0; i < mshape[1]; i++) {
00477               maxrows += (Int)infomat(1, i);
00478           }
00479           //cout << "maxrows=" << maxrows << endl;
00480           Vector<FlagID> flagids(maxrows);
00481 
00482           Int idCount = 0;
00483           String warnings = String("Bad row:");
00484           for (Int i = 0; i < mshape[1]; i++) {
00485              if (mshape[0] != 7) {
00486                 warnings += String(" ") + String::toString(i);
00487                 break;
00488              }
00489 
00490              FlagID flagid;
00491              flagid.rowNum = (uInt)infomat(0, i);
00492              //flagid.npts = (uInt)infomat(1, i);
00493              if (infomat(2, i) < 0 || 
00494                  infomat(2, i) >= itsAntNames.nelements()) {
00495                 warnings += String(" ") + String::toString(i);
00496                 break;
00497              }
00498              flagid.ant1 = (uInt)infomat(2, i);
00499              if (infomat(3, i) < 0 || 
00500                 infomat(3, i) >= itsAntNames.nelements()) {
00501                 warnings += String(" ") + String::toString(i);
00502                 break;
00503              }
00504              flagid.ant2 = (uInt)infomat(3, i);
00505              if (infomat(4, i) < 0 || 
00506                 infomat(4, i) >= itsFieldNames.nelements()) { 
00507                 warnings += String(" ") + String::toString(i);
00508                 break;
00509              }
00510              flagid.field = (uInt)infomat(4, i);
00511              
00512              if (aveTime > 0.) {
00513                 //cout << "flag aved" << endl;
00514                 Double start = max(infomat(5, i) - aveTime / 2, 0.);
00515                 Double end = max(infomat(5, i) + aveTime / 2, start);
00516                 flagid.time = MVTime(start / C::day).string(MVTime::YMD, 7) +
00517                               String("~") +   
00518                               MVTime(end / C::day).string(MVTime::YMD, 7);
00519              }
00520              else {
00521                 String ltime = 
00522                      MVTime(infomat(5, i)/C::day).string(MVTime::YMD, 7); 
00523                 //cout << "ltime=" << ltime << endl;
00524                 String ntime = 
00525                      MVTime((infomat(5, i) + 0.1)/C::day).string(MVTime::YMD, 7); 
00526                 //cout << "ntime=" << ntime << endl;
00527                 flagid.time = ltime + String("~") + ntime; 
00528              }
00529 
00530              if (infomat(6, i) < 0 || 
00531                 infomat(6, i) >= dataDescCol.spectralWindowId().nrow()) { 
00532                 warnings += String(" ") + String::toString(i);
00533                 break;
00534              }
00535              flagid.spw = dataDescCol.spectralWindowId()((Int)infomat(6, i));
00536              if (infomat(6, i) < 0 || 
00537                  infomat(6, i) >= dataDescCol.polarizationId().nrow()) { 
00538                 warnings += String(" ") + String::toString(i);
00539                 break;
00540              }
00541              Int polId = dataDescCol.polarizationId()((Int)infomat(6, i));
00542              if (itsCorrNames[polId].nelements() <= 0) {
00543                 warnings += String(" ") + String::toString(i);
00544                 break;
00545              }
00546             
00547              //cout << "cpol=" << cpol(i) << endl;
00548              //cout << "cpol.size()=" << cpol(i).size() << endl;
00549              //cout << "cpol.length()=" << cpol(i).length() << endl;
00550              Int cCnt = cpol(i).freq(']');
00551              Int k = 0;
00552              Int l = 0;
00553              for (Int j = 0; j < cCnt; j++) {
00554                 l = cpol(i).index(']', k) + 1; 
00555                 String sect = cpol(i).substr(k, l);
00556                 sect = sect.after('[');
00557                 sect = sect.before(']');
00558                 //cout << "sect=" << j << " " << sect << endl;
00559                 String corr = sect.before(',');
00560                 String chan = sect.after(',');
00561                 //cout << "corr=" << corr << " chan=" << chan << endl; 
00562                 Int corrId = atoi(corr.chars());
00563                 flagid.corr = itsCorrNames[polId][corrId];
00564                 //cout << "corr=" << flagid.corr << endl; 
00565                 Int colCnt = chan.freq(':');
00566                 if (colCnt == 2) {
00567                    Int fst = chan.index(':');
00568                    fst = chan.index(':', fst + 1);
00569                    String s = chan.substr(0, fst);
00570                    //cout << "s=" << s << endl;
00571                    flagid.chan = s.before(':') + String('~') + s.after(':');
00572                 }
00573                 else if (colCnt == 1) {
00574                    flagid.chan = chan.before(':') + String('~') + chan.after(':');
00575                 }
00576                 else {
00577                    flagid.chan = chan;
00578                 }
00579                 //cout << "chan=" << flagid.chan << endl; 
00580                 //show flag base
00581                 //flagid.show();
00582                 flagids(idCount++) = flagid; 
00583                 k = l;
00584              }
00585           }
00586           flagids.resize(idCount, True);
00587           //cout << "flagids.size()=" << flagids.size() << endl;
00588          
00589           
00590           Vector<Int> spwNumChan = spwColumn.numChan().getColumn();
00591           //cout << "spwNumChan=" << spwNumChan << endl;
00592           //spwNumChan[0] = 4;
00593           //spwNumChan[1] = 1;
00594 
00595 //---------------------------------------------------------------
00596           if (aveBl) {
00597              extendAnt="ALL";
00598           }
00599 
00600           ExtendFlagger eflg;
00601           eflg.attach(*aveMS);
00602 
00603           Bool ret;
00604           ret = eflg.initdata();
00605           eflg.setdata();
00606           eflg.setExtend(extendChan, extendCorr, extendSpw,
00607                          extendAnt, extendTime, itsCorrNames, spwNumChan);
00608           eflg.setUnflag(!Bool(direction));
00609 
00610           //for (Int i = 0; i < flagids.nelements(); i++) {
00611           //   flagids[i].show();
00612           //}
00613           ret = eflg.extend(flagids);
00614           //cout << "flag display: " << ret << endl;
00615 
00616           return True;
00617 
00618       }
00619 
00620       casa::Bool
00621       flagdata(Int direction, Vector<String> /*collist*/,
00622                 Matrix<Double> infomat, Vector<String> cpol, Bool /*ave*/) {
00623           String fnname = "flagdata";
00624           //cout << "MSPlotMainMSCallback::flagdata flag=" << direction << endl;
00625          
00626           IPosition mshape = infomat.shape();
00627           //cout << "infomat.shape=[" << mshape[0] << ", "
00628           //     << mshape[1] << "] cpol.size=" << cpol.size() << endl;
00629 
00630           if (mshape[1] < 1 || cpol.size() < 1) 
00631              return True;
00632 
00633           //this can be commented out 
00634           //if (ave == True) {
00635           //   return flagdisplay(direction, collist, infomat, cpol);
00636           //}
00637 //--------------------------------------------------------------
00638           ROMSDataDescColumns dataDescCol(localMS->dataDescription());
00639 
00640 
00641           //cout << "flagms=" << flagms << endl; 
00642           MS ms(flagms, Table::Update);
00643 
00644           ROMSSpWindowColumns spwColumn(ms.spectralWindow());
00645 
00646           //Int maxrows = ms.nrow();
00647           Int maxrows = 0;
00648           for (Int i = 0; i < mshape[1]; i++) {
00649               maxrows += (Int)infomat(1, i);
00650           }
00651 
00652           //cout << "maxrows=" << maxrows << endl;
00653           Vector<FlagID> flagids(maxrows);
00654 
00655           Int idCount = 0;
00656           String warnings = String("Bad row:");
00657           for (Int i = 0; i < mshape[1]; i++) {
00658              if (mshape[0] != 7) {
00659                 warnings += String(" ") + String::toString(i);
00660                 break;
00661              }
00662 
00663              FlagID flagid;
00664              flagid.rowNum = (uInt)infomat(0, i);
00665              //flagid.npts = (uInt)infomat(1, i);
00666              if (infomat(2, i) < 0 || 
00667                  infomat(2, i) >= itsAntNames.nelements()) {
00668                 warnings += String(" ") + String::toString(i);
00669                 break;
00670              }
00671              flagid.ant1 = (uInt)infomat(2, i);
00672              if (infomat(3, i) < 0 || 
00673                 infomat(3, i) >= itsAntNames.nelements()) {
00674                 warnings += String(" ") + String::toString(i);
00675                 break;
00676              }
00677              flagid.ant2 = (uInt)infomat(3, i);
00678              if (infomat(4, i) < 0 || 
00679                 infomat(4, i) >= itsFieldNames.nelements()) { 
00680                 warnings += String(" ") + String::toString(i);
00681                 break;
00682              }
00683              flagid.field = (uInt)infomat(4, i);
00684              
00685              if (aveTime > 0.) {
00686                 //cout << "flag aved" << endl;
00687                 Double start = max(infomat(5, i) - aveTime / 2, 0.);
00688                 Double end = max(infomat(5, i) + aveTime / 2, start);
00689                 flagid.time = MVTime(start / C::day).string(MVTime::YMD, 7) +
00690                               String("~") +   
00691                               MVTime(end / C::day).string(MVTime::YMD, 7);
00692              }
00693              else {
00694                 String ltime = 
00695                      MVTime(infomat(5, i)/C::day).string(MVTime::YMD, 7); 
00696                 //cout << "ltime=" << ltime << endl;
00697                 //String ntime = 
00698                 //    MVTime((infomat(5, i) + 0.1)/C::day).string(MVTime::YMD, 7); 
00699                 //cout << "ntime=" << ntime << endl;
00700                 //flagid.time = ltime + String("~") + ntime; 
00701                 flagid.time = ltime; 
00702              }
00703 
00704              if (infomat(6, i) < 0 || 
00705                 infomat(6, i) >= dataDescCol.spectralWindowId().nrow()) { 
00706                 warnings += String(" ") + String::toString(i);
00707                 break;
00708              }
00709              flagid.spw = dataDescCol.spectralWindowId()((Int)infomat(6, i));
00710              if (infomat(6, i) < 0 || 
00711                  infomat(6, i) >= dataDescCol.polarizationId().nrow()) { 
00712                 warnings += String(" ") + String::toString(i);
00713                 break;
00714              }
00715              Int polId = dataDescCol.polarizationId()((Int)infomat(6, i));
00716              if (itsCorrNames[polId].nelements() <= 0) {
00717                 warnings += String(" ") + String::toString(i);
00718                 break;
00719              }
00720             
00721              //cout << "cpol=" << cpol(i) << endl;
00722              //cout << "cpol.size()=" << cpol(i).size() << endl;
00723              //cout << "cpol.length()=" << cpol(i).length() << endl;
00724              Int cCnt = cpol(i).freq(']');
00725              Vector<String> chans(4);
00726              for (Int s = 0; s < 4; s++)
00727                 chans(s) = "";
00728              Int k = 0;
00729              Int l = 0;
00730              String tmpChan = "";
00731              String tmpCorr = "";
00732              Int secCnt = 0;
00733              for (Int j = 0; j < cCnt; j++) {
00734                 l = cpol(i).index(']', k) + 1; 
00735                 String sect = cpol(i).substr(k, l);
00736                 sect = sect.after('[');
00737                 sect = sect.before(']');
00738                 //cout << "sect=" << j << " " << sect << endl;
00739                 String corr = sect.before(',');
00740                 String chan = sect.after(',');
00741                 //cout << "corr=" << corr << " chan=" << chan << endl; 
00742                 Int corrId = atoi(corr.chars());
00743                 tmpCorr = itsCorrNames[polId][corrId];
00744 
00745                 Int colCnt = chan.freq(':');
00746                 if (secCnt > 0) {
00747                    tmpChan += ";";
00748                 }
00749                 if (colCnt == 2) {
00750                    Int fst = chan.index(':');
00751                    fst = chan.index(':', fst + 1);
00752                    String s = chan.substr(0, fst);
00753                    //cout << "s=" << s << endl;
00754                    tmpChan += (s.before(':') + String('~') + s.after(':'));
00755                 }
00756                 else if (colCnt == 1) {
00757                    tmpChan += (chan.before(':') + String('~') + chan.after(':'));
00758                 }
00759                 else {
00760                    tmpChan += chan;
00761                 }
00762                 chans(corrId) = tmpChan;
00763                 secCnt++;
00764                 k = l;
00765              }
00766              for (Int s = 0; s < 4; s++) {
00767                 if (chans(s) != "") {
00768                    flagid.chan = chans(s);
00769                    flagid.corr = itsCorrNames[polId][s];
00770                    flagids(idCount++) = flagid; 
00771                    //show flag base
00772                    //flagid.show();
00773                 }
00774              }
00775           }
00776           if (idCount < 1)
00777               return True;
00778 
00779           flagids.resize(idCount, True);
00780           //cout << "flagids.size()=" << flagids.size() << endl;
00781           //for (uInt i = 0; i < flagids.size(); i++) {
00782           //    flagids(i).show();
00783           //}
00784 
00785           Vector<Int> spwNumChan = spwColumn.numChan().getColumn();
00786 
00787 //---------------------------------------------------------------
00788           if (aveBl) {
00789              extendAnt="ALL";
00790           }
00791 
00792           //cout << "sizeof(uint)=" << 8 * sizeof(uint) << endl;
00793           Int maxSel = 8 * sizeof(uint) - 5;
00794           Int nSel = maxSel; 
00795           Int start = 0;
00796           while (start < idCount) {
00797 
00798              nSel = min(idCount - start, maxSel);
00799 
00800              ExtendFlagger eflg;
00801              eflg.attach(ms);
00802              //cout << "ms=" << ms << endl;
00803 
00804              Bool ret;
00805              ret = eflg.initdata();
00806              eflg.setdata();
00807              eflg.setExtend(extendChan, extendCorr, extendSpw,
00808                          extendAnt, extendTime, itsCorrNames, spwNumChan);
00809              eflg.setUnflag(!Bool(direction));
00810 
00811              //cout << "start=" << start << " nSel=" << nSel 
00812              //     << " iCount=" << idCount
00813              //     << endl;
00814              ret = eflg.extend(flagids(Slice(start, nSel)));
00815 
00816              //eflg.detach();
00817              start += nSel;
00818           } 
00819           //cout << "Flagger return: " << ret << endl;
00820 
00821           //eflg.setSpw("0:3");
00822           //eflg.setCorrelation("lr");
00823           //eflg.selectdata();
00824           //eflg.setmanualflags(False);
00825           //eflg.run();
00826         
00827           //Flagger flagger;
00828           //
00829           //flagger.attach(ms);
00830           //
00831           //Bool useoriginalms=True;
00832           //
00833           //String field="";
00834           //String spw="";
00835           //String array="";
00836           //String feed="";
00837           //String scan="";
00838           //String baseline="";
00839           //String uvrange="";
00840           //String time="";
00841           //String correlation="";
00842           //
00843           //Bool ret = False;
00844           //ret = flagger.setdata(field, spw, array, 
00845           //       feed, scan, baseline, uvrange, time, correlation);
00846           //
00847           //cout << "------setdata=" << ret << endl;
00848           //
00849           //Bool autocorr = False;
00850           //String clipexpr = "";
00851           //Vector<Double> cliprange(0);
00852           //String clipcolumn = "DATA";
00853           //Bool outside = False;
00854           //Double quackinterval = 0.0;
00855           //String opmode = "flag";
00856           //
00857           //Bool unflag = False;
00858           //spw = "0:3";
00859           //correlation = "lr";
00860           //
00861           //cout << "useoriginalms=" << useoriginalms
00862           //     << " field=" << field << " spw=" << spw
00863           //     << " array=" << array << " feed=" << feed
00864           //     << " scan=" << scan << " baseline=" << baseline
00865           //     << " uvrange=" << uvrange << " time=" << time
00866           //<< " correlation=" << correlation << endl;
00867           // 
00868           //ret = flagger.selectdata(useoriginalms, field, spw, array, 
00869           //        feed, scan, baseline, uvrange, time, correlation);
00870           //cout << "------selectdata=" << ret << endl;
00871           //
00872           //cout << "autocorr=" << autocorr
00873           //   << " unflag=" << unflag
00874           //   << " clipexpr=" << clipexpr << " cliprange=" << cliprange
00875           //   << " clipcolumn=" << clipcolumn << " outside=" << outside
00876           //   << " quackinterval=" << quackinterval << " opmode=" << opmode
00877           //   << endl;
00878           //
00879           //ret = flagger.setmanualflags(autocorr, unflag, 
00880           //      clipexpr, cliprange, clipcolumn, outside, 
00881           //      quackinterval, opmode);
00882           //cout << "------setmanualflags=" << ret << endl;
00883           //
00884           //ret = flagger.selectdata(useoriginalms, field, spw, array, 
00885           //                feed, scan, baseline, uvrange, time, correlation);
00886           //cout << "------selectdata=" << ret << endl;
00887           //
00888           //ret = flagger.setmanualflags(False, unflag, 
00889           //      clipexpr, cliprange, clipcolumn, outside, 
00890           //      quackinterval, "SUMMARY");
00891           //cout << "------summary=" << ret << endl;
00892           //
00893           //flagger.run(False, False);
00894           //cout << "------run=" << ret << endl;
00895           return True;
00896 
00897       }
00898 
00899       casa::Bool
00900       printlocateinfo( Vector<String> /*collist*/,
00901                   Matrix<Double> infomat,Vector<String> cpol)
00902       {
00903           String fnname = "printlocateinfo";
00904 #if LOG2 
00905           log->FnEnter(fnname + "(collist, infomat, cpol)", clname);
00906 #endif 
00907           //collist never used!
00908 
00909           //cout << "cpol=" << cpol << endl;
00910 
00911           //# Define the column headings and other reptitive strings used.
00912           Vector<uInt> columnWidths(9);
00913           columnWidths[0]=8; columnWidths[1]=8; columnWidths[2]=9;
00914           columnWidths[3]=25; columnWidths[4]=22; columnWidths[5]=6;
00915           columnWidths[6]=10; columnWidths[7]=14; columnWidths[8]=30; 
00916          
00917           String colNames;
00918           ostringstream tmp;
00919      tmp << std::setw( columnWidths[0] ) <<  "ROW #   " << " | "
00920          << std::setw( columnWidths[1] ) <<  "# Points" << " |"
00921          << std::setw( columnWidths[2] ) <<  "Baseline" << "| "
00922          << std::setw( columnWidths[3] ) <<  "Field ID/Name      "  << " | "
00923          << std::setw( columnWidths[4] ) <<  "Time         "  << " | "
00924          << std::setw( columnWidths[5] ) <<  "SPW ID" << " | "
00925          << std::setw( columnWidths[6] ) <<  "Ref. Freq." << " | "
00926          << std::setw( columnWidths[7] ) <<  "Corr. Id/Name"  << " |"
00927          << std::setw( columnWidths[8] ) <<  "[pol /chan]" << " | "
00928          << endl;
00929           colNames += String( tmp );
00930           tmp.str( "" );
00931 
00932           //# get the DATA_DESC_ID column so we can extract polarization
00933           //# and spectral window information.
00934           ROMSDataDescColumns dataDescCol( localMS->dataDescription());
00935 
00936           IPosition mshape = infomat.shape();
00937           String warnings;
00938           String info;
00939           if (mshape[1] > 0)
00940              info += colNames;
00941           
00942           //cout << "infomat.shape=[" << mshape[0] << ", "
00943           //     << mshape[1] << "] cpol.size=" << cpol.size() << endl;
00944 //          for(Int i=0; i < mshape[1]; i++)
00945 //          {
00946 //         if ( mshape[0] != 7 )
00947 //         {
00948 //             warnings += String( "Skipping the " )
00949 //            + String::toString( i )
00950 //            + String( " set of data, its not a complete row. " );
00951 //             break;
00952 //         }
00953 //
00954 //         //# Put the Row number and the # of points in the row
00955 //         tmp << std::noshowpoint << std::setw( columnWidths[0] )
00956 //             << String::toString( infomat( 0, i ) ) << " | "
00957 //             << std::noshowpoint << std::setw( columnWidths[1] )
00958 //             << infomat( 1, i ) << " |  ";
00959 //
00960 //         //# Printout the Baseline, note that the information
00961 //         //# we are provided is the antenna IDs, but we want
00962 //         //# to display the antenna names.
00963 //         String baseline;
00964 //         if ( infomat(2,i) < 0
00965 //            || infomat(2,i) > itsAntNames.nelements() )
00966 //             baseline += String::toString( infomat(2,i) )
00967 //            + String( "(ID)" );
00968 //         else 
00969 //             baseline += itsAntNames( (uInt)infomat(2,i) );
00970 //         baseline += String( "/" );
00971 //         if ( infomat(3,i) < 0
00972 //            || infomat(3,i) > itsAntNames.nelements() )
00973 //             baseline += String::toString( infomat(3,i) )
00974 //            + String( "(ID)" );
00975 //         else 
00976 //             baseline += itsAntNames( (uInt)infomat(3,i) );
00977 //         baseline += "| ";
00978 //         tmp << std::setw( columnWidths[2] )
00979 //             << baseline;
00980 //         
00981 //
00982 //         //# Print out the Field ID, and Field Name
00983 //         String fieldStr = String::toString(infomat(4,i) )
00984 //             + String( "/" );
00985 //         if ( infomat(4,i) < itsFieldNames.nelements() ) 
00986 //             fieldStr += itsFieldNames[ Int( infomat(4,i) ) ];
00987 //         else {
00988 //             warnings += String( "Field ID, " )
00989 //            + String::toString( Int( infomat(4,i) ) )
00990 //            + String( ", is larger then the" )
00991 //            + String( " number of field names, " )
00992 //            + String::toString( itsFieldNames.nelements() )
00993 //            + String( ". \n" );
00994 //             fieldStr += "??";
00995 //         }
00996 //             tmp << std::noshowpoint << std::setw( columnWidths[3] )
00997 //            << fieldStr << " | ";
00998 //
00999 //         //Print out the time in YY/MM/DD/hh:mm:ss.s format
01000 //         tmp << std::setw( columnWidths[4] )
01001 //             << MVTime( infomat(5, i)/C::day).string( MVTime::DMY,7) 
01002 //             << " | ";
01003 //
01004 //         //# spectral window IDs and Ref Frequency
01005 //         Int spwId = dataDescCol.spectralWindowId()( (Int)infomat(6, i ) );
01006 //         tmp << std::noshowpoint << std::setw( columnWidths[5] )
01007 //             << spwId << " | ";
01008 //
01009 //         if ( spwId < (Int)itsRefFrequencies.nelements() ) 
01010 //             tmp << std::showpoint
01011 //            << std::setprecision( columnWidths[6]-7)
01012 //            << std::setw( columnWidths[6] )
01013 //            << itsRefFrequencies[ spwId ] << " | ";
01014 //         else {
01015 //             warnings += String( "SPW ID, " )
01016 //            + String::toString( spwId )
01017 //            + String( ", is larger then the" )
01018 //            + String( " number of reference frequencies, " )
01019 //            + String::toString( itsRefFrequencies.nelements() )
01020 //            + String( ". \n" );
01021 //             tmp << " ?? " << " | ";
01022 //         }
01023 //         
01024 //         
01025 //         //# Polarization ID and list of polls and chans selected
01026 //         //#  in this row.
01027 //         //# TODO add some check on spw ID here
01028 //         Int polId = dataDescCol.polarizationId()( (Int)infomat(6, i ) );
01029 //         String polStr = String::toString( polId ) + String( "/" );
01030 //         if ( itsCorrNames[polId].nelements() > 0 )
01031 //             for ( Int corrId=0;
01032 //              corrId < (Int)itsCorrNames[polId].nelements();
01033 //              corrId++ ) {
01034 //            if ( corrId > 0 )
01035 //                polStr += String( ", " );
01036 //            polStr += itsCorrNames[polId][corrId];
01037 //             }
01038 //         else {
01039 //             warnings += String( "Pol ID, " )
01040 //            + String::toString( polId )
01041 //            + String( ", is larger then the" )
01042 //            + String( " number of polarizations, " )
01043 //            + String::toString( itsCorrNames[polId].nelements() )
01044 //            + String( ", \n" );
01045 //             polStr += "??";
01046 //         }
01047 //         tmp << std::noshowpoint << std::setw( columnWidths[7] )
01048 //             << polStr << " | ";
01049 //
01050 //         tmp  << std::setw( columnWidths[8] )
01051 //              << cpol(i)  << "| " << endl;
01052 //         
01053 //         info += String( tmp );
01054 //         tmp.str( "" );         
01055 //          }
01056 
01057           for (Int i=0; i < mshape[1]; i++) {
01058              if ( mshape[0] != 7 ) {
01059                 warnings += String( "Skipping the " )
01060                          + String::toString( i )
01061                          + String( " set of data, its not a complete row. " );
01062                 break;
01063              }
01064 
01065              tmp.str("");         
01066 
01067              //# Put the Row number and the # of points in the row
01068              tmp << std::noshowpoint << std::setw( columnWidths[0] )
01069                     << String::toString(infomat(0, i) ) << " | "
01070                     << std::noshowpoint << std::setw( columnWidths[1] )
01071                     << infomat(1, i) << " |  ";
01072 
01073              //# Printout the Baseline, note that the information
01074              //# we are provided is the antenna IDs, but we want
01075              //# to display the antenna names.
01076              String baseline;
01077              if (infomat(2, i) < 0 || infomat(2, i) >= itsAntNames.nelements()) {
01078                  baseline += String::toString(infomat(2, i)) + String("(ID)");
01079                  continue;
01080              }
01081              else 
01082                  baseline += itsAntNames((uInt)infomat(2, i));
01083              baseline += String( "/" );
01084              if (infomat(3, i) < 0 || infomat(3, i) >= itsAntNames.nelements()) {
01085                  baseline += String::toString(infomat(3, i)) + String("(ID)");
01086                  continue;
01087              }
01088              else 
01089                  baseline += itsAntNames((uInt)infomat(3, i));
01090              baseline += "| ";
01091              tmp << std::setw( columnWidths[2]) << baseline;
01092          
01093              //# Print out the Field ID, and Field Name
01094              String fieldStr = String::toString(infomat(4, i)) + String("/");
01095              if (infomat(4, i) < 0 || infomat(4, i) >= itsFieldNames.nelements()) { 
01096                 warnings += String( "Field ID, " )
01097                          + String::toString(Int(infomat(4, i)))
01098                          + String(" does not exist" )
01099                          + String( ". \n" );
01100                 continue;
01101              }
01102              else {
01103                 fieldStr += itsFieldNames[Int(infomat(4, i))];
01104              }
01105 
01106              tmp << std::noshowpoint << std::setw(columnWidths[3])
01107                     << fieldStr << " | ";
01108 
01109              //Print out the time in YY/MM/DD/hh:mm:ss.s format
01110              tmp << std::setw(columnWidths[4])
01111                     << MVTime(infomat(5, i)/C::day).string(MVTime::DMY, 7) 
01112                     << " | ";
01113 
01114              //# spectral window IDs and Ref Frequency
01115              if (infomat(6, i) < 0 || 
01116                  infomat(6, i) >= dataDescCol.spectralWindowId().nrow()) { 
01117                 warnings += String("row ")
01118                          + String::toString(Int(infomat(6, i)))
01119                          + String(" does not exist in SpectralWindow")
01120                          + String(". \n");
01121                 continue;
01122              }
01123 
01124              Int spwId = dataDescCol.spectralWindowId()((Int)infomat(6, i));
01125              tmp << std::noshowpoint << std::setw(columnWidths[5])
01126                     << spwId << " | ";
01127 
01128              if (spwId < (Int)itsRefFrequencies.nelements()) { 
01129                 tmp << std::showpoint
01130                        << std::setprecision( columnWidths[6]-7)
01131                        << std::setw(columnWidths[6])
01132                        << itsRefFrequencies[spwId] << " | ";
01133              }
01134              else {
01135                  warnings += String("SPW ID, ")
01136                           + String::toString(spwId)
01137                           + String(" number of reference frequencies, ")
01138                           + String::toString(itsRefFrequencies.nelements())
01139                           + String(". \n" );
01140                  tmp << " ?? " << " | ";
01141              }
01142          
01143              //# Polarization ID and list of polls and chans selected
01144              //#  in this row.
01145              //# TODO add some check on spw ID here
01146              if (infomat(6, i) < 0 || 
01147                  infomat(6, i) >= dataDescCol.polarizationId().nrow()) { 
01148                 warnings += String("row ")
01149                          + String::toString(Int(infomat(6, i)))
01150                          + String(" does not exist in Polarization")
01151                          + String( ". \n" );
01152                 continue;
01153              }
01154 
01155              Int polId = dataDescCol.polarizationId()((Int)infomat(6, i));
01156              String polStr = String::toString(polId) + String( "/" );
01157              if (itsCorrNames[polId].nelements() > 0) {
01158                 for (Int corrId=0;
01159                      corrId < (Int)itsCorrNames[polId].nelements(); corrId++ ) {
01160                    if (corrId > 0)
01161                       polStr += String( ", " );
01162                    polStr += itsCorrNames[polId][corrId];
01163                 }
01164              }
01165              else {
01166                 warnings += String("Pol ID, ")
01167                          + String::toString( polId )
01168                          + String( ", is larger then the" )
01169                          + String( " number of polarizations, " )
01170                          + String::toString( itsCorrNames[polId].nelements() )
01171                          + String( ", \n" );
01172                 polStr += "??";
01173             }
01174             tmp << std::noshowpoint << std::setw( columnWidths[7] )
01175                    << polStr << " | ";
01176 
01177             tmp << std::setw( columnWidths[8] )
01178                    << cpol(i)  << "| " << endl;
01179          
01180             info += String(tmp);
01181           }
01182 
01183           //if (mshape[1] > 0)
01184           //info += colNames;
01185           //# Display the information in the list.
01186           if ( info.length() > colNames.length() )
01187              log->out(info, fnname, clname, LogMessage::NORMAL);
01188 
01189           //# Display any warnings encountered.
01190           if (warnings.length() > 0)
01191              //log->out(warnings, fnname, clname, LogMessage::WARN);
01192              log->out("Error occured while locating data points", 
01193                   fnname, clname, LogMessage::WARN);
01194 
01195 #if LOG2 
01196           log->FnExit(fnname, clname);
01197 #endif 
01198           return True;
01199       };
01200     private:
01201       MeasurementSet *localMS;             
01202       MeasurementSet *aveMS;             
01203       Vector<String> itsAntNames;
01204       //Matrix<Int> itsBaselines;
01205       Vector<String> itsFieldNames;
01206       Vector< Vector<String> > itsCorrNames;
01207       Vector<Double> itsRefFrequencies;
01208       String flagms;
01209       String extendChan;
01210       String extendCorr;
01211       String extendSpw;
01212       String extendAnt;
01213       String extendTime;
01214       Bool aveBl;
01215       Double aveTime;
01216 
01217       // Message logger
01218       SLog* log;         
01219       static const String clname;
01220 };
01221 
01222 const String MSPlotMainMSCallBack::clname = "MSPlotMainMSCallBack";
01223 //#!//////////////////////////////////////////////////////////////////////////
01224 //#! All the wonderful docs, that will show up in the user reference
01225 //#! manual for this class.
01226 // <summary>
01227 // This class is provided to TablePlot to allow MsPlot to do the proper thing
01228 // when button's are pressed on the plotting GUI. 
01229 // </summary>
01230 //
01231 //#! <use visibility=local>   or   <use visibility=export>
01232 // <use visibility=local>
01233 //#!
01234 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
01235 //#! for example:
01236 //#!  <reviewed reviewer="pshannon@nrao.edu" date="1994/10/10" tests="tMyClass, t1MyClass" demos="dMyClass, d1MyClass">
01237 //#!  </reviewed>
01238 // </reviewed>
01239 //
01240 //#! Classes or concepts you should understand before using this class.
01241 // <prerequisite>
01242 // <ul>
01243 //   <li> <linkto class="TPGuiCallBackHooks">TPGuiCallBackHooks</linkto>class,
01244 //   <li> <linkto class="TablePlot">TablePlot</linkto>class, 
01245 //   <li> <linkto class="Table">MsPlot</linkto> class
01246 //   <li> <linkto class="Table">Measurement Set</linkto> class 
01247 // </ul>    
01248 // </prerequisite>
01249 //    
01250 // <etymology>
01251 // Callbacks from TablePlot to MsPlot that are executed when buttons are
01252 // pressed on the plotting GUI, and the data that has been plotted resides
01253 // in the Antenna subtable of the Measurement Set. 
01254 // </etymology>
01255 //
01256 // <synopsis>
01257 // Note:  The full list of columns in the Antenna subtable (VLA) are:
01258 // <table border="2">
01259 // <tbody>
01260 //   <tr><th align="left">OFFSET</th>
01261 //       <th align="left">(x,y,z) offset value</th></tr>
01262 //   <tr><th align="left">POSITIION</th>
01263 //    <th align="left">(x,y,z) position value</th></tr>
01264 //   <tr><th align="left">TYPE</th>
01265 //    <th align="left">ground-base or not telescope</th></tr>
01266 //   <tr><th align="left">DISH_DIAMETER</th>
01267 //       <th align="left">&nbsp;</th></tr>    
01268 //   <tr><th align="left">FLAG_ROW</tr>
01269 //       <th align="left">&nbsp;</th></tr>    
01270 //   <tr><th align="left">MOUNT</th>
01271 //       <th align="left">type of mount</th></tr>
01272 //   <tr><th align="left">NAME</th>
01273 //       <th align="left">antenna name</th></tr>
01274 //   <tr><th align="left">STATION</th>
01275 //       <th align="left">antenna station name</th></tr>
01276 // </tbody>
01277 // </table>
01278 // </synopsis>
01279 //
01280 // <example>
01281 // </example>
01282 //
01283 // <motivation>
01284 // To provide a way for the TablePlot object to inform the MsPlot object
01285 // that a particular button has been pressed on the plotting GUI and to
01286 // allow MS Plot to over ride the default TablePlot behaviour if necessary. 
01287 // </motivation>
01288 //
01289 // <thrown>
01290 //    <li> AIPSError
01291 // </thrown>
01292 //
01293 // <todo asof="2007/12/19">
01294 //   <li> Implement the relaseTable method.</li>
01295 //   <li> Finish the documentation</li>
01296 //   <li>use enums in the MS code for the string values for the
01297 //      locate columns</li>
01298 //   <li> Restructure TablePlot to send rows of data, rather then single
01299 //        data point.  This should improve the plotting speed as it will
01300 //        allow reuse of calculations more easily.</li>
01301 //   <li> Build methods into MsPlot, or some other class that retrieves
01302 //        information from the tables.  Examples of methods are, getFieldNames,
01303 //        getAntNames, ...  This could help reduce the memory usage, reduce
01304 //        code duplication, and improve robustness.</li>
01305 //   <li> Restructure MsPlot to subclass TablePlot and rewrite the
01306 //        MsPlot reset command to do what it needs to do then call
01307 //        the parents reset method.</li>
01308 // </todo>
01309 //#! End of documentation.    
01310 //#!///////////////////////////////////////////////////////////////////////////
01311 class MSPlotAntennaCallBack : public TPGuiCallBackHooks
01312 {
01313     public: 
01314            MSPlotAntennaCallBack(Vector<String> inAntNames, Vector<String> inFieldNames )
01315       {
01316          log = SLog::slog();
01317          String fnname =  "MSPlotAntennaMSCallBack" ;
01318 #if LOG2 
01319          log->FnEnter(fnname + "(antNames, fieldNames)", clname );
01320 #endif 
01321                   
01322           itsAntNames = inAntNames;
01323           itsFieldNames = inFieldNames;
01324 
01325           LocateColumns.resize(3);
01326           //itsPlotOptions.LocateColumns[0] = "NAME";
01327           //itsPlotOptions.LocateColumns[1] = "STATION";
01328           LocateColumns[0] = "POSITION[1]";
01329           LocateColumns[1] = "POSITION[2]";
01330           LocateColumns[2] = "POSITION[3]";
01331 
01332 #if LOG2
01333           log->FnExit(fnname, clname);
01334 #endif 
01335            };
01336       
01337       ~MSPlotAntennaCallBack(){
01338 #if LOG2 
01339           String fnname = "~MSPlotAntennaCallback";
01340           log->FnEnter(fnname, clname);
01341           log->FnExit(fnname, clname);
01342 #endif 
01343       };
01344       
01345       casa::Bool
01346       releasetable( Int /*nrows*/,
01347          Int /*ncols*/,
01348          Int /*panel*/,
01349          String /*tablename */)
01350       {
01351           String fnname = "releasetable";
01352 #if LOG2
01353           log->FnEnter(fnname + "(nrows,ncols,panel,tablename)", clname );
01354 #endif 
01355              
01356           //# TODO free any data structures that were created
01357           //# with this class, maybe call the class destructor too.
01358 #if LOG2
01359           log->FnExit(fnname, clname);
01360 #endif 
01361           return True;
01362       }
01363 
01364       casa::Bool
01365       createiterplotlabels( Vector<String> iteraxes,
01366          Vector<Double> values,
01367          String &titleString )
01368      {
01369          String fnname = "createiterplotlabels";
01370 #if LOG2 
01371          log->FnEnter(fnname + "(iteraxes, values, titleString)", clname );
01372 #endif 
01373          
01374          titleString = "Iter: ";
01375          //# TODO add a check that the # of values = # of iteraxes.
01376          
01377          for ( uint axesId = 0; axesId < iteraxes.nelements(); axesId++ )
01378          {
01379         if ( upcase( iteraxes[axesId] ).matches( "BASELINE" )
01380            || upcase( iteraxes[axesId] ).matches( "ANTENNA" ) 
01381            || upcase( iteraxes[axesId] ).matches( "ANTENNA1" )
01382            || upcase( iteraxes[axesId] ).matches( "ANTENNA2" ) )
01383         {
01384             if  ( iteraxes.nelements() == 2 
01385                && upcase( iteraxes[0] ).contains( "ANTENNA" )
01386                && upcase( iteraxes[1] ).contains( "ANTENNA" ) )
01387             {
01388            if ( axesId == 0 )
01389                titleString += "Baseline ";
01390             } else
01391            titleString += "Antenna ";
01392 
01393             if ( values[axesId] < itsAntNames.nelements() )
01394             {
01395            if ( axesId > 0 )
01396                titleString += String( " : " );
01397            titleString += itsAntNames[Int(values[axesId])];
01398             } else {
01399                           ostringstream os;
01400               os       << "Internal error! Antenna ID is "
01401              << values[axesId]
01402              << ", but there are only "
01403              << itsAntNames.nelements()
01404              << ".";
01405                         log->out(os, fnname, clname, LogMessage::DEBUG1);
01406             }   
01407         } else if ( upcase(iteraxes[axesId]).matches("FIELD") 
01408            || upcase(iteraxes[axesId]).matches("FIELD_ID") )
01409         {
01410             titleString += "FIELD ";
01411             if ( values[axesId] < itsFieldNames.nelements() )
01412             {           
01413            if ( axesId > 0 )
01414                titleString += String( " : " );
01415            titleString += itsFieldNames[Int(values[axesId])];
01416             } else {
01417                         ostringstream os;
01418          os    << "Internal error! Antenna ID is "
01419              << values[axesId]
01420              << ", but there are only "
01421              << itsFieldNames.nelements()
01422              << ".";
01423                         log->out(os, fnname, clname, LogMessage::DEBUG1);
01424             }               
01425         } else {
01426             //# This includes SPW, SCAN, FEED, and ARRAY
01427             //# since all of these don't have names.  This
01428             //# may change in the future.
01429             titleString += iteraxes[axesId] + String( " ");
01430             
01431             if ( axesId > 0 )
01432            titleString += String( " : " );
01433             titleString += String::toString( Int(values[axesId]) );
01434         }
01435          }
01436 
01437 #if LOG2 
01438          log->FnExit(fnname, clname);
01439 #endif 
01440          return True;
01441      };
01442      
01443 
01444       casa::Bool
01445       flagdata(String /*tablename*/) {
01446 #if LOG2 
01447           String fnname = "flagdata";
01448           log->FnEnter(fnname, clname);
01449           log->FnExit(fnname, clname);
01450 #endif 
01451           return True;
01452       }
01453 
01454       casa::Bool
01455       flagdata(Int /*direction*/, Vector<String> /*collist*/,
01456                   Matrix<Double> /*infomat*/,Vector<String> /*cpol*/, Bool /*ave*/) {
01457           String fnname = "flagdata";
01458           //cout << "MSPlotAntennaCallBack::flagdata" << endl;
01459 
01460          
01461           return True;
01462 
01463       }
01464       
01465       casa::Bool
01466       printlocateinfo( Vector<String> /*collist*/,
01467                   Matrix<Double> infomat,Vector<String> /*cpol*/)
01468       {
01469           String fnname = "printlocateinfo";
01470 #if LOG2 
01471           log->FnEnter(fnname + "(collist, infomat, cpol)", clname);
01472 #endif 
01473 
01474           //# Note that TablePlot prepends the ROW (ant ID), and # of
01475           //# points to the front of the list.
01476 
01477           //# Define the column widths
01478           Vector<uInt> columnWidths(5);
01479           columnWidths[0]=10; columnWidths[1]=10; columnWidths[2]=10;
01480           columnWidths[3]=10; columnWidths[4]=10;
01481 
01482           //# Define the column headings
01483           String colNames;
01484           ostringstream tmp;
01485           tmp << std::setw( columnWidths[0] ) <<  "Ant ID  " << " | " 
01486          << std::setw( columnWidths[1] ) <<  "Ant. Names" << " | "
01487          << std::setw( columnWidths[2] ) <<  "X     "  << " | "
01488          << std::setw( columnWidths[3] ) <<  "Y     "  << " | "
01489          << std::setw( columnWidths[4] ) <<  "Z     "  << " |"
01490          << endl;
01491           colNames += String( tmp );
01492           tmp.str( "" );
01493                     
01494           //# Set up a string stream for warning msgs and for
01495           //# display the data.
01496           String warnings;
01497           String info;
01498           info += colNames;
01499           
01500           IPosition mshape = infomat.shape();
01501           Vector<Double> position(3);
01502 
01503           if ( mshape[1] < 1 )
01504          warnings += String( "No data to display" );
01505           
01506           for( Int i=0; i < mshape[1]; i++)
01507           {
01508          if ( mshape[0] != 5 )
01509          {
01510              warnings += String( "Skipping the " )
01511             +  String::toString( i )
01512             + String( " set of data, its not a complete row.\n" );
01513          } else {
01514              if ( infomat( 0, i ) < 0
01515                 || infomat( 0, i ) >= itsAntNames.nelements() )
01516              {
01517             warnings += String( "Unable to find antenna name ")
01518                 + String( "for antenna ID: " )
01519                 + String::toString( infomat( 0, i ) );
01520              }
01521              tmp << std::noshowpoint << std::setw( columnWidths[0] )
01522             << infomat( 0, i ) << " | "
01523             << std::noshowpoint << std::setw( columnWidths[1] )
01524             << itsAntNames[ Int(infomat( 0, i ) ) ] << " | "
01525             << std::showpoint
01526             << std::setprecision( columnWidths[2]-7)
01527             << std::setw( columnWidths[2] )
01528             << infomat( 2, i ) << " | "
01529             << std::showpoint
01530             << std::setprecision( columnWidths[3]-7)
01531             << std::setw( columnWidths[3] )
01532             << infomat( 3, i ) << " | "
01533             << std::showpoint
01534             << std::setprecision( columnWidths[4]-7)
01535             << std::setw( columnWidths[4] )
01536             << infomat( 4, i ) << " | " <<endl;;
01537              info += String( tmp );
01538              tmp.str( "" );
01539          }
01540           }
01541           info += colNames;
01542              
01543           //# Display the information in the list.
01544           if ( info.length() > 0 )
01545            log->out( info, fnname, clname, LogMessage::NORMAL);
01546 
01547           //# Display any warnings encountered.
01548           if ( warnings.length() > 0 )
01549            log->out(warnings, fnname, clname, LogMessage::NORMAL);
01550 
01551 #if LOG2 
01552           log->FnExit(fnname, clname);
01553 #endif 
01554           return True;
01555       };
01556                  
01557     private:
01558       Vector<String> itsAntNames;
01559       Vector<String> itsFieldNames;
01560 
01561       // Message logger
01562       SLog *log;         
01563       static const String clname;
01564 };
01565 
01566 const String MSPlotAntennaCallBack::clname = "MSPlotAntennaCallBack";
01567 
01568 
01569 
01570 
01571 //#!//////////////////////////////////////////////////////////////////////////
01572 //#! All the wonderful docs, that will show up in the user reference
01573 //#! manual for this class.
01574 // <summary>
01575 // This class is provided to TablePlot to allow MsPlot to do the proper thing
01576 // when button's are pressed on the plotting GUI. 
01577 // </summary>
01578 //
01579 //#! <use visibility=local>   or   <use visibility=export>
01580 // <use visibility=local>
01581 //#!
01582 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
01583 //#! for example:
01584 //#!  <reviewed reviewer="pshannon@nrao.edu" date="1994/10/10" tests="tMyClass, t1MyClass" demos="dMyClass, d1MyClass">
01585 //#!  </reviewed>
01586 // </reviewed>
01587 //
01588 //#! Classes or concepts you should understand before using this class.
01589 // <prerequisite>
01590 // <ul>
01591 //   <li> <linkto class="TPGuiCallBackHooks">TPGuiCallBackHooks</linkto>class,
01592 //   <li> <linkto class="TablePlot">TablePlot</linkto>class, 
01593 //   <li> <linkto class="Table">MsPlot</linkto> class
01594 //   <li> <linkto class="Table">Measurement Set</linkto> class 
01595 // </ul>    
01596 // </prerequisite>
01597 //    
01598 // <etymology>
01599 // Callbacks from TablePlot to MsPlot that are executed when buttons are
01600 // pressed on the plotting GUI, and the data that has been plotted resides
01601 // in the UVW column of the main table of the Measurement Set. 
01602 // </etymology>
01603 //
01604 // <synopsis>
01605 // </synopsis>
01606 //
01607 // <example>
01608 // </example>
01609 //
01610 // <motivation>
01611 // To provide a way for the TablePlot object to inform the MsPlot object
01612 // that a particular button has been pressed on the plotting GUI and to
01613 // allow MS Plot to over ride the default TablePlot behaviour if necessary. 
01614 // </motivation>
01615 //
01616 // <thrown>
01617 //    <li> AIPSError
01618 // </thrown>
01619 //
01620 // <todo asof="2007/12/19">
01621 //   <li> Implement the relaseTable method.
01622 //   <li> Finish the documentation
01623 //   <li> Restructure TablePlot to send rows of data, rather then single
01624 //        data point.  This should improve the plotting speed as it will
01625 //        allow reuse of calculations more easily.
01626 //   <li> Build methods into MsPlot, or some other class that retrieves
01627 //        information from the tables.  Examples of methods are, getFieldNames,
01628 //        getAntNames, ...  This could help reduce the memory usage, reduce
01629 //        code duplication, and improve robustness. 
01630 //   <li> Restructure MsPlot to subclass TablePlot and rewrite the
01631 //        MsPlot reset command to do what it needs to do then call
01632 //        the parents reset method.    
01633 // </todo>
01634 //#! End of documentation.    
01635 //#!///////////////////////////////////////////////////////////////////////////
01636 
01637 class MSPlotUVWCallBack : public TPGuiCallBackHooks
01638 {
01639     public: 
01640          MSPlotUVWCallBack( MeasurementSet *inMS,
01641          Vector<String> antNames,
01642          Vector<String> fieldNames,
01643          Vector<Vector<String> >corrNames,
01644          Vector<Double> refFrequencies )
01645      {
01646               
01647          log = SLog::slog();
01648          String fnname = "MSPlotUVWCallback";
01649 #if LOG2 
01650          log->FnEnter(fnname + 
01651                 "( inMS, antNames, fieldNames, corrNames, refFrequencies )",
01652                 clname);
01653 #endif 
01654          
01655          localMS = inMS;
01656          itsAntNames = antNames;
01657          itsFieldNames = fieldNames;
01658          itsCorrNames = corrNames;
01659          itsRefFrequencies = refFrequencies;
01660          
01661          LocateColumns.resize(8);
01662          LocateColumns[0] = "UVW[1]";
01663          LocateColumns[1] = "UVW[2]";
01664          LocateColumns[2] = "UVW[3]";
01665          LocateColumns[3] = "ANTENNA1";
01666          LocateColumns[4] = "ANTENNA2";
01667          LocateColumns[5] = "FIELD_ID";
01668          LocateColumns[6] = "TIME";
01669          LocateColumns[7] = "DATA_DESC_ID";
01670 
01671 #if LOG2 
01672          log->FnExit(fnname, clname);
01673 #endif 
01674       };
01675       
01676        ~MSPlotUVWCallBack(){
01677 #if LOG2 
01678           String fnname = "~MSPlotUVWCallback";
01679           log->FnEnter(fnname, clname);
01680           log->FnExit(fnname, clname);
01681 #endif 
01682       };
01683 
01684 
01685       casa::Bool
01686       releasetable( Int /*nrows*/, Int /*ncols*/, Int /*panel*/, String /*tablename */)
01687       {
01688           String fnname = "releasetable";
01689 #if LOG2 
01690           log->FnEnter(fnname + "(nrows,ncols,panel,tablename )", clname);
01691 #endif 
01692           //# TODO free any data structures that were created
01693           //# with this class, maybe call the class destructor too.
01694 
01695 #if LOG2 
01696           log->FnExit(fnname, clname);
01697 #endif 
01698           return True;
01699       }
01700 
01701             
01702       casa::Bool
01703       createiterplotlabels( Vector<String> iteraxes,
01704          Vector<Double> values,
01705          String &titleString )
01706      {
01707          String fnname = "createiterplotlabels";
01708 #if LOG2 
01709         log->FnEnter(fnname + "(iteraxes, values, titleString)", clname);   
01710 #endif 
01711          titleString = "Iter: ";
01712          
01713          for ( uint axesId = 0; axesId < iteraxes.nelements(); axesId++ )
01714          {
01715         if ( upcase( iteraxes[axesId] ).matches( "BASELINE" )
01716            || upcase( iteraxes[axesId] ).matches( "ANTENNA" ) 
01717            || upcase( iteraxes[axesId] ).matches( "ANTENNA1" )
01718            || upcase( iteraxes[axesId] ).matches( "ANTENNA2" ) )
01719         {
01720             if  ( iteraxes.nelements() == 2 
01721                && upcase( iteraxes[0] ).contains( "ANTENNA" )
01722                && upcase( iteraxes[1] ).contains( "ANTENNA" ) )
01723             {
01724            if ( axesId == 0 )
01725                titleString += "Baseline ";
01726             } else
01727            titleString += "Antenna ";
01728             
01729             
01730             if ( values[axesId] < itsAntNames.nelements() )
01731             {
01732            if ( axesId > 0 )
01733                titleString += String( " : " );
01734            titleString += itsAntNames[Int(values[axesId])];
01735             } else {
01736 #if LOG2 
01737          ostringstream os;
01738          os    << "Internal error! Antenna ID is "
01739              << values[axesId]
01740              << ", but there are only "
01741              << itsAntNames.nelements()
01742              << ".";
01743          log->out(os, fnname, clname, LogMessage::DEBUG1);
01744 #endif 
01745             }
01746         } else if ( upcase(iteraxes[axesId]).matches("FIELD") 
01747            || upcase(iteraxes[axesId]).matches("FIELD_ID") )
01748         {
01749             titleString += "FIELD ";
01750             if ( values[axesId] < itsFieldNames.nelements() )
01751             {
01752            if ( axesId > 0 )
01753                titleString += String( " : " );
01754            titleString += itsFieldNames[Int(values[axesId])];
01755             } else {
01756 #if LOG2 
01757             ostringstream os;
01758             os  << "Internal error! Antenna ID is "
01759              << values[axesId]
01760              << ", but there are only "
01761              << itsFieldNames.nelements()
01762              << ".";
01763              log->out(os, fnname, clname, LogMessage::DEBUG1);
01764 #endif 
01765             }
01766         } else {
01767             //# This includes SPW, SCAN, FEED, and ARRAY
01768             //# since all of these don't have names.  This
01769             //# may change in the future.
01770             titleString += iteraxes[axesId] + String( " ");
01771 
01772             if ( axesId > 0 )
01773            titleString += String( " : " );
01774             titleString += String::toString( Int(values[axesId]) );
01775         }
01776          }
01777          
01778 #if LOG2 
01779         log->FnExit(fnname, clname);
01780 #endif 
01781          return True;
01782      };
01783       
01784      casa::Bool
01785      flagdata(String /*tablename*/) {
01786 #if LOG2 
01787          String fnname = "flagdata";
01788          log->FnEnter(fnname, clname);
01789          log->FnExit(fnname, clname);
01790 #endif 
01791          return True;
01792      }
01793 
01794       casa::Bool
01795       flagdata(Int /*direction*/, Vector<String> /*collist*/,
01796                   Matrix<Double> /*infomat*/,Vector<String> /*cpol*/, Bool /*ave*/) {
01797           String fnname = "flagdata";
01798           //cout << "MSPlotUVWCallBack::flagdata" << endl;
01799          
01800           return True;
01801 
01802       }
01803      
01804      casa::Bool
01805      printlocateinfo( Vector<String> /*collist*/,
01806                   Matrix<Double> infomat,Vector<String> cpol)
01807      {
01808          String fnname = "printlocateinfo";
01809 #if LOG2 
01810          log->FnEnter(fnname + "(collist, infomat, cpol)", clname);
01811 #endif 
01812 
01813          //# Define the column headings and other reptitive strings used.
01814          Vector<uInt> columnWidths(12);
01815          columnWidths[0]=8; columnWidths[1]=8; columnWidths[2]=11;
01816          columnWidths[3]=11; columnWidths[4]=11; columnWidths[5]=8;
01817          columnWidths[6]=25; columnWidths[7]=22; columnWidths[8]=6;
01818          columnWidths[9]=10; columnWidths[10]=14; columnWidths[11]=30; 
01819          
01820          String colNames;
01821          ostringstream tmp;
01822          tmp << std::setw( columnWidths[0] ) <<  "ROW #" << " | "
01823         << std::setw( columnWidths[1] ) <<  "# Points"  << " | "
01824         << std::setw( columnWidths[2] ) <<  "U   " << " | "
01825         << std::setw( columnWidths[3] ) <<  "V   " << " | "
01826         << std::setw( columnWidths[4] ) <<  "W   " << " | "
01827         
01828         << std::setw( columnWidths[5] ) <<  "Baseline" << " | "
01829         << std::setw( columnWidths[6] ) <<  "Field ID/Name      "  << " | "
01830         << std::setw( columnWidths[7] ) <<  "Time         "  << " | "
01831         << std::setw( columnWidths[8] ) <<  "SPW ID" << " | "
01832         << std::setw( columnWidths[9] ) <<  "Ref. Freq." << " | "
01833         << std::setw( columnWidths[10] ) <<  "Corr. Id/Name"  << " |"
01834         << std::setw( columnWidths[11] ) <<  "[pol /chan]" << " | "
01835         << endl;
01836          colNames += String( tmp );
01837          tmp.str( "" );
01838 
01839          //# get the DATA_DESC_ID column so we can extract polarization
01840          //# and spectral window information.
01841          ROMSDataDescColumns dataDescCol( localMS->dataDescription() );
01842          
01843          IPosition mshape = infomat.shape();
01844          String warnings;
01845          String info;
01846          info += colNames;
01847          
01848          for(Int i=0; i < mshape[1]; i++)
01849          {
01850         if ( mshape[0] != 10 )
01851         {
01852             warnings += String( "Skipping the " )
01853            + String::toString( i )
01854            + String( " set of data, its not a complete row. " );
01855             break;
01856         }
01857 
01858          
01859         //# Put the Row number and the # of points in the row
01860         tmp << std::noshowpoint << std::setw( columnWidths[0] )
01861             << String::toString( infomat( 0, i ) ) << " | "
01862             << std::noshowpoint << std::setw( columnWidths[1] )
01863             << infomat( 1, i ) << " | ";
01864          
01865         //# Print the U, V and W values
01866         tmp << std::showpoint
01867             << std::setprecision( columnWidths[2]-7)
01868             << std::setw( columnWidths[2] )
01869             << infomat( 2, i ) << " | ";
01870         tmp << std::showpoint
01871             << std::setprecision( columnWidths[3]-7)
01872             << std::setw( columnWidths[3] )
01873             << infomat( 3, i ) << " | ";
01874         tmp << std::showpoint
01875             << std::setprecision( columnWidths[4]-7)
01876             << std::setw( columnWidths[4] )
01877             << infomat( 4, i ) << " | ";
01878          
01879         //# Printout the Baseline
01880          String baseline;
01881          if ( infomat(5,i) < 0
01882             || infomat(5,i) > itsAntNames.nelements() )
01883              baseline += String::toString( infomat(5,i) )
01884             + String( "(ID)" );
01885          else 
01886              baseline += itsAntNames( (uInt)infomat(5,i) );
01887          baseline += String( "/" );
01888          if ( infomat(6,i) < 0
01889             || infomat(6,i) > itsAntNames.nelements() )
01890              baseline += String::toString( infomat(6,i) )
01891             + String( "(ID)" );
01892          else 
01893              baseline += itsAntNames( (uInt)infomat(6,i) );
01894          baseline += " | ";
01895          tmp << std::setw( columnWidths[5] )
01896              << baseline;
01897          
01898         //# Print out the Field ID, and Field Name
01899         String fieldStr = String::toString(infomat(7,i) )
01900             + String( "/" );
01901         if ( infomat(7,i) < itsFieldNames.nelements() ) 
01902             fieldStr += itsFieldNames[ Int( infomat(7,i) ) ];
01903         else {
01904             warnings += String( "Field ID, " )
01905            + String::toString( Int( infomat(7,i) ) )
01906            + String( ", is larger then the" )
01907            + String( " number of field names, " )
01908            + String::toString( itsFieldNames.nelements() )
01909            + String( ". \n" );
01910             fieldStr += "??";
01911         }
01912         tmp << std::noshowpoint << std::setw( columnWidths[6] )
01913             << fieldStr << " | ";
01914         
01915         //Print out the time in YY/MM/DD/hh:mm:ss.s format
01916         tmp << std::setw( columnWidths[7] )
01917             << MVTime( infomat(8, i)/C::day).string( MVTime::DMY,7) 
01918             << " | ";
01919         
01920         //# spectral window IDs and Ref Frequency
01921         //# TODO add a check that infomat(9,i) isn't too big.
01922         Int spwId = dataDescCol.spectralWindowId()( (Int)infomat(9, i ) );
01923         tmp << std::noshowpoint << std::setw( columnWidths[8] )
01924             << spwId << " | ";
01925              
01926         if ( spwId < (Int)itsRefFrequencies.nelements() ) 
01927             tmp << std::showpoint
01928            << std::setprecision( columnWidths[9]-7)
01929            << std::setw( columnWidths[9] )
01930            << itsRefFrequencies[ spwId ] << " | ";
01931         else {
01932             warnings += String( "SPW ID, " )
01933            + String::toString( spwId )
01934            + String( ", is larger then the" )
01935            + String( " number of reference frequencies, " )
01936            + String::toString( itsRefFrequencies.nelements() )
01937            + String( ". \n" );
01938             tmp << " ?? " << " | ";
01939         }
01940              
01941         //# Polarization ID and list of polls and chans selected
01942         //#  in this row.
01943         //# TODO add a check that infomat(9,i) isn't too big.
01944         //#      add a check on SPWId    
01945         Int polId = dataDescCol.polarizationId()( (Int)infomat(9, i ) );
01946         String polStr = String::toString( polId ) + String( "/" );
01947         if ( itsCorrNames[polId].nelements() > 0 )
01948             for ( Int corrId=0;
01949              corrId < (Int)itsCorrNames[polId].nelements();
01950              corrId++ ) {
01951            if ( corrId > 0 )
01952                polStr += String( ", " );
01953            polStr += itsCorrNames[polId][corrId];
01954             }
01955         else {
01956             warnings += String( "Pol ID, " )
01957            + String::toString( polId )
01958            + String( ", is larger then the" )
01959            + String( " number of polarizations, " )
01960            + String::toString( itsCorrNames[spwId].nelements() )
01961            + String( ", \n" );
01962             polStr += "??";
01963         }
01964         tmp << std::noshowpoint << std::setw( columnWidths[10] )
01965             << polStr << " | ";
01966         
01967         tmp  << std::setw( columnWidths[11] )
01968              << cpol(i)  << " | " << endl;
01969          
01970         info += String( tmp );
01971         tmp.str( "" );         
01972           }   
01973           info += colNames;
01974              
01975           //# Display the information in the list.
01976           if ( info.length() > colNames.length() )
01977            log->out(info, fnname, clname, LogMessage::NORMAL);
01978 
01979           //# Display any warnings encountered.
01980           if ( warnings.length() > 0 )
01981            log->out( warnings, fnname, clname, LogMessage::WARN);
01982 
01983 #if LOG2 
01984           log->FnExit(fnname, clname);
01985 #endif 
01986           return True;
01987      }
01988                  
01989     private:
01990       MeasurementSet *localMS;
01991       Vector<String> itsAntNames;
01992       Vector<String> itsFieldNames;
01993       Vector< Vector<String> > itsCorrNames;
01994       Vector<Double> itsRefFrequencies;
01995 
01996       // Message logger
01997       SLog* log;         
01998       static const String clname;
01999 };
02000 
02001 const String MSPlotUVWCallBack::clname = "MSPlotUVWCallBack";
02002 
02003 };
02004 
02005 
02006 #endif //CASA_MSPLOT__HOOKS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines