LCOV - code coverage report
Current view: top level - singledishfiller/Filler - SpectralWindowRecord.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 49 52 94.2 %
Date: 2024-12-11 20:54:31 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :  * SpectralWindowRecord.h
       3             :  *
       4             :  *  Created on: Jan 27, 2016
       5             :  *      Author: nakazato
       6             :  */
       7             : 
       8             : #ifndef SINGLEDISH_FILLER_SPECTRALWINDOWRECORD_H_
       9             : #define SINGLEDISH_FILLER_SPECTRALWINDOWRECORD_H_
      10             : 
      11             : #include <casacore/casa/Arrays/Matrix.h>
      12             : #include <casacore/casa/BasicSL/String.h>
      13             : #include <casacore/measures/Measures/MDirection.h>
      14             : #include <casacore/ms/MeasurementSets/MSSpectralWindow.h>
      15             : #include <casacore/ms/MeasurementSets/MSSpWindowColumns.h>
      16             : 
      17             : namespace casa { //# NAMESPACE CASA - BEGIN
      18             : namespace sdfiller { //# NAMESPACE SDFILLER - BEGIN
      19             : 
      20             : struct SpectralWindowRecord {
      21             :   typedef casacore::MSSpectralWindow AssociatingTable;
      22             :   typedef casacore::MSSpWindowColumns AssociatingColumns;
      23             : 
      24             :   // meta
      25             :   casacore::Int spw_id;
      26             : 
      27             :   // mandatory
      28             :   casacore::Int num_chan;
      29             :   casacore::Int meas_freq_ref;
      30             :   casacore::Double refpix;
      31             :   casacore::Double refval;
      32             :   casacore::Double increment;
      33             : 
      34             :   // optional
      35             :   casacore::String name;
      36             : 
      37             :   // for dummy entry
      38             :   casacore::Int const d_num_chan = 1;
      39             :   casacore::Vector<casacore::Double> const d_array = casacore::Vector<casacore::Double>(1, 0.0);
      40             :   casacore::Int const d_freq = 0.0;
      41             : 
      42             :   // method
      43          36 :   void clear() {
      44          36 :     spw_id = -1;
      45          36 :     name = "";
      46          36 :     meas_freq_ref = -1;
      47          36 :     num_chan = 0;
      48          36 :     refpix = 0.0;
      49          36 :     refval = 0.0;
      50          36 :     increment = 0.0;
      51          36 :   }
      52             : 
      53             :   SpectralWindowRecord &operator=(SpectralWindowRecord const &other) {
      54             :     spw_id = other.spw_id;
      55             :     name = other.name;
      56             :     meas_freq_ref = other.meas_freq_ref;
      57             :     num_chan = other.num_chan;
      58             :     refpix = other.refpix;
      59             :     refval = other.refval;
      60             :     increment = other.increment;
      61             :     return *this;
      62             :   }
      63             : 
      64          29 :   void add(AssociatingTable &table, AssociatingColumns &columns) {
      65          29 :     casacore::uInt uspw_id = (casacore::uInt) spw_id;
      66          29 :     casacore::uInt nrow = table.nrow();
      67          29 :     if (nrow <= uspw_id) {
      68          29 :       table.addRow(uspw_id - nrow + 1);
      69          29 :       casacore::uInt new_nrow = table.nrow();
      70          99 :       for (casacore::uInt i = nrow; i < new_nrow - 1; ++i) {
      71          70 :         columns.numChan().put(i, d_num_chan);
      72          70 :         columns.refFrequency().put(i, d_freq);
      73          70 :         columns.totalBandwidth().put(i, d_freq);
      74          70 :         columns.chanFreq().put(i, d_array);
      75          70 :         columns.chanWidth().put(i, d_array);
      76          70 :         columns.effectiveBW().put(i, d_array);
      77          70 :         columns.resolution().put(i, d_array);
      78             :       }
      79             :     }
      80          29 :   }
      81             : 
      82          29 :   casacore::Bool fill(casacore::uInt /*irow*/, AssociatingColumns &columns) {
      83          29 :     if (spw_id < 0) {
      84           0 :       return false;
      85             :     }
      86             : 
      87          29 :     casacore::uInt nrow = columns.nrow();
      88             : 
      89          29 :     if (nrow <= (casacore::uInt) spw_id) {
      90           0 :       return false;
      91             :     }
      92             : 
      93          29 :     columns.numChan().put(spw_id, num_chan);
      94          29 :     columns.measFreqRef().put(spw_id, meas_freq_ref);
      95          29 :     casacore::Double tot_bw = num_chan * fabs(increment);
      96          29 :     columns.totalBandwidth().put(spw_id, tot_bw);
      97          29 :     casacore::Double ref_frequency = refval - refpix * increment;
      98          29 :     columns.refFrequency().put(spw_id, ref_frequency);
      99          29 :     casacore::Vector<casacore::Double> freq(num_chan);
     100          29 :     indgen(freq, ref_frequency, increment);
     101          29 :     columns.chanFreq().put(spw_id, freq);
     102          29 :     freq = increment;
     103          29 :     columns.chanWidth().put(spw_id, freq);
     104          29 :     freq = abs(freq);
     105          29 :     columns.effectiveBW().put(spw_id, freq);
     106          29 :     columns.resolution().put(spw_id, freq);
     107          29 :     casacore::Int net_sideband = 0; // USB
     108          29 :     if (increment < 0.0) {
     109          22 :       net_sideband = 1; // LSB
     110             :     }
     111          29 :     columns.netSideband().put(spw_id, net_sideband);
     112          29 :     if (name.size() > 0) {
     113           0 :       columns.name().put(spw_id, name);
     114             :     }
     115             : 
     116          29 :     return true;
     117          29 :   }
     118             : };
     119             : 
     120             : } //# NAMESPACE SDFILLER - END
     121             : } //# NAMESPACE CASA - END
     122             : 
     123             : #endif /* SINGLEDISH_FILLER_SPECTRALWINDOWRECORD_H_ */

Generated by: LCOV version 1.16