LCOV - code coverage report
Current view: top level - atmosphere/ATM - ATMSpectralGrid.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 286 460 62.2 %
Date: 2024-12-11 20:54:31 Functions: 38 52 73.1 %

          Line data    Source code
       1             : /*******************************************************************************
       2             :  * ALMA - Atacama Large Millimiter Array
       3             :  * (c) Instituto de Estructura de la Materia, 2009
       4             :  *
       5             :  * This library is free software; you can redistribute it and/or
       6             :  * modify it under the terms of the GNU Lesser General Public
       7             :  * License as published by the Free Software Foundation; either
       8             :  * version 2.1 of the License, or (at your option) any later version.
       9             :  *
      10             :  * This library is distributed in the hope that it will be useful,
      11             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13             :  * Lesser General Public License for more details.
      14             :  *
      15             :  * You should have received a copy of the GNU Lesser General Public
      16             :  * License along with this library; if not, write to the Free Software
      17             :  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
      18             :  *
      19             :  * "@(#) $Id: ATMSpectralGrid.cpp Exp $"
      20             :  *
      21             :  * who       when      what
      22             :  * --------  --------  ----------------------------------------------
      23             :  * pardo     24/03/09  created
      24             :  */
      25             : 
      26             : #include "ATMSpectralGrid.h"
      27             : 
      28             : #include <iostream>
      29             : #include <limits>
      30             : #include <math.h>
      31             : #include <vector>
      32             : #include <string>
      33             : 
      34             : 
      35             : 
      36             : ATM_NAMESPACE_BEGIN
      37             : 
      38             : // public methods:
      39             : // constructors
      40           2 : SpectralGrid::SpectralGrid(const Frequency &oneFreq)
      41             : {
      42           2 :   v_chanFreq_.reserve(1);
      43           2 :   freqUnits_ = Frequency::UnitHertz;
      44           2 :   v_transfertId_.resize(0); // not sure this is necessary!
      45           2 :   unsigned int numChan = 1;
      46           2 :   unsigned int refChan = 0;
      47           2 :   Frequency chanSep(0.0);
      48           2 :   add(numChan, refChan, oneFreq, chanSep);
      49           2 :   std::vector<unsigned int> v_dummyInt;
      50           2 :   vv_assocSpwId_.push_back(v_dummyInt); // put an empty std::vector
      51           2 :   std::vector<std::string> v_dummyString;
      52           2 :   vv_assocNature_.push_back(v_dummyString); // put an empty std::vector
      53           2 : }
      54             : 
      55         871 : SpectralGrid::SpectralGrid(unsigned int numChan,
      56             :                            unsigned int refChan,
      57             :                            const Frequency &refFreq,
      58         871 :                            const Frequency &chanSep)
      59             : {
      60             :   //  cout << " SpectralGrid constructor" << endl;
      61         871 :   v_chanFreq_.reserve(numChan);
      62         871 :   freqUnits_ = Frequency::UnitHertz;
      63         871 :   v_transfertId_.resize(0); // not sure this is necessary!
      64         871 :   add(numChan, refChan, refFreq, chanSep);
      65         871 :   std::vector<unsigned int> v_dummyInt;
      66         871 :   vv_assocSpwId_.push_back(v_dummyInt); // put an empty std::vector
      67         871 :   std::vector<std::string> v_dummyString;
      68         871 :   vv_assocNature_.push_back(v_dummyString); // put an empty std::vector
      69         871 : }
      70             : 
      71           2 : SpectralGrid::SpectralGrid(unsigned int numChan,
      72             :                            unsigned int refChan,
      73             :                            const Frequency &refFreq,
      74             :                            const Frequency &chanSep,
      75             :                            const Frequency &intermediateFreq,
      76             :                            const SidebandSide &sbSide,
      77           2 :                            const SidebandType &sbType)
      78             : {
      79           2 :   freqUnits_ = Frequency::UnitHertz;
      80           2 :   v_transfertId_.resize(0); // not sure this is necessary!
      81           2 :   v_chanFreq_.reserve(numChan);
      82             :   /* cout << " la" << endl; */
      83           2 :   add(numChan, refChan, refFreq, chanSep, intermediateFreq, sbSide, sbType);
      84           2 : }
      85             : 
      86           1 : SpectralGrid::SpectralGrid(unsigned int numChan,
      87             :                            unsigned int refChan,
      88             :                            double* chanFreq,
      89           1 :                            Frequency::Units freqUnits)
      90             : {
      91           1 :   v_chanFreq_.reserve(numChan);
      92           1 :   freqUnits_ = Frequency::UnitHertz;
      93           1 :   v_transfertId_.resize(0); // not sure this is necessary!
      94           1 :   add(numChan, refChan, chanFreq, freqUnits);
      95           1 : }
      96             : 
      97           2 : void SpectralGrid::add(unsigned int numChan,
      98             :                        unsigned int refChan,
      99             :                        const Frequency &refFreq,
     100             :                        const Frequency &chanSep,
     101             :                        const Frequency &intermediateFreq,
     102             :                        const SidebandSide &sbSide,
     103             :                        const SidebandType &sbType)
     104             : {
     105             : 
     106             : 
     107             :   double chSep;
     108           2 :   std::vector<std::string> v_assocNature;
     109           2 :   std::vector<unsigned int> v_assocSpwId;
     110             : 
     111           2 :   unsigned int spwId = v_transfertId_.size();
     112             : 
     113           2 :   if(sbSide == LSB) { // LSB tuning
     114             :     // the LSB:
     115           2 :     add(numChan, refChan, refFreq, chanSep); // LSB
     116           2 :     v_sidebandSide_[spwId] = LSB;
     117           2 :     v_sidebandType_[spwId] = sbType;
     118           2 :     double loFreq    = refFreq.get() + intermediateFreq.get(); // store loFreq for USB
     119           2 :     v_loFreq_[spwId] = loFreq;
     120           2 :     v_assocSpwId.push_back(v_numChan_.size());
     121           2 :     vv_assocSpwId_[vv_assocSpwId_.size() - 1] = v_assocSpwId;
     122           2 :     v_assocNature.push_back("USB");
     123           2 :     vv_assocNature_[vv_assocNature_.size() - 1] = v_assocNature;
     124             : 
     125             :     // the USB:
     126           2 :     spwId = v_transfertId_.size();
     127           2 :     double refFreqUSB = refFreq.get() + 2.*intermediateFreq.get();  // fix refFreq in the image band (refChan is unchanged)
     128           2 :     chSep = -chanSep.get();
     129           2 :     add(numChan, refChan, Frequency(refFreqUSB), Frequency(chSep));
     130             : 
     131           2 :     v_sidebandSide_[spwId] = USB;
     132           2 :     v_sidebandType_[spwId] = sbType;
     133           2 :     v_loFreq_[spwId] = loFreq;
     134             : 
     135           2 :     v_assocSpwId[0] = v_numChan_.size() - 2;
     136           2 :     vv_assocSpwId_[vv_assocSpwId_.size() - 1] = v_assocSpwId;
     137           2 :     v_assocNature[0] = "LSB";
     138           2 :     vv_assocNature_[vv_assocNature_.size() - 1] = v_assocNature;
     139             : 
     140             :   } else { // USB tuning
     141             :     // the USB:
     142           0 :     add(numChan, refChan, refFreq, chanSep);
     143             : 
     144           0 :     v_sidebandSide_[spwId] = USB;
     145           0 :     v_sidebandType_[spwId] = sbType;
     146           0 :     double loFreq    = refFreq.get() - intermediateFreq.get();
     147           0 :     v_loFreq_[spwId] = loFreq;
     148             : 
     149           0 :     v_assocSpwId.push_back(v_numChan_.size());
     150           0 :     vv_assocSpwId_[vv_assocSpwId_.size() - 1] = v_assocSpwId;
     151           0 :     v_assocNature.push_back("LSB");
     152           0 :     vv_assocNature_[vv_assocNature_.size() - 1] = v_assocNature;
     153             : 
     154             :     // the LSB:
     155           0 :     spwId = v_transfertId_.size();
     156           0 :     double refFreqLSB = refFreq.get() - 2.*intermediateFreq.get();  // fix refFreq in the image band (refChan is unchanged)
     157           0 :     chSep = -chanSep.get();
     158           0 :     add(numChan, refChan, Frequency(refFreqLSB), Frequency(chSep));
     159             : 
     160           0 :     v_sidebandSide_[spwId] = LSB;
     161           0 :     v_sidebandType_[spwId] = sbType;
     162           0 :     v_loFreq_[spwId] = loFreq;
     163             : 
     164           0 :     v_assocSpwId[0] = v_numChan_.size() - 2;
     165           0 :     vv_assocSpwId_[vv_assocSpwId_.size() - 1] = v_assocSpwId;
     166           0 :     v_assocNature[0] = "USB";
     167           0 :     vv_assocNature_[vv_assocNature_.size() - 1] = v_assocNature;
     168             :   }
     169           2 : }
     170             : 
     171         878 : unsigned int SpectralGrid::add(unsigned int numChan,
     172             :                                unsigned int refChan,
     173             :                                const Frequency &refFreq,
     174             :                                const Frequency &chanSep)
     175             : {
     176         878 :   freqUnits_ = Frequency::UnitHertz;
     177             : 
     178         878 :   unsigned int spwId = v_transfertId_.size();
     179         878 :   v_loFreq_.push_back(refFreq.get());
     180             : 
     181         878 :   if(spwId == 0) {
     182         875 :     v_transfertId_.push_back(0);
     183             :   } else {
     184           3 :     v_transfertId_.push_back(v_transfertId_[spwId - 1] + v_numChan_[spwId - 1]);
     185             :   }
     186             : 
     187         878 :   v_numChan_.push_back(numChan);
     188         878 :   v_refChan_.push_back(refChan);
     189             : 
     190         878 :   v_refFreq_.push_back(refFreq.get(freqUnits_));
     191         878 :   v_chanSep_.push_back(chanSep.get(freqUnits_));
     192             : 
     193         878 :   double* chanFreq = new double[numChan];
     194             :   {
     195             :         // CAS-9762 refChan should not be 1-base
     196             :         // ICT-9490     Change refChan convention so that it is 0-based
     197             :     // double freqOffset = v_refFreq_[spwId] - v_chanSep_[spwId]
     198             :     //     * (double) (v_refChan_[spwId] - 1.);
     199         878 :     double freqOffset = v_refFreq_[spwId] - v_chanSep_[spwId]
     200         878 :         * (double) (v_refChan_[spwId]);
     201             : 
     202      373292 :     for(unsigned int i = 0; i < numChan; i++) {
     203      372414 :       chanFreq[i] = freqOffset + (double) i * v_chanSep_[spwId];
     204             :     }
     205         878 :     appendChanFreq(numChan, chanFreq);
     206             : 
     207         878 :     if(numChan > 1) {
     208         876 :       if(chanFreq[0] > chanFreq[1]) {
     209         360 :         v_minFreq_.push_back(chanFreq[numChan - 1]);
     210         360 :         v_maxFreq_.push_back(chanFreq[0]);
     211             :       } else {
     212         516 :         v_minFreq_.push_back(chanFreq[0]);
     213         516 :         v_maxFreq_.push_back(chanFreq[numChan - 1]);
     214             :       }
     215             :     } else {
     216           2 :       v_minFreq_.push_back(chanFreq[0]);
     217           2 :       v_maxFreq_.push_back(chanFreq[0]);
     218             :     }
     219             : 
     220         878 :     v_sidebandSide_ .push_back(NOSB);
     221         878 :     v_sidebandType_ .push_back(NOTYPE);
     222         878 :     v_intermediateFrequency_.push_back(0.0);
     223             :   }
     224         878 :   std::vector<unsigned int> v_dummyAssoc;
     225         878 :   vv_assocSpwId_.push_back(v_dummyAssoc);
     226         878 :   std::vector<std::string> v_dummyNature;
     227         878 :   vv_assocNature_.push_back(v_dummyNature);
     228             : 
     229         878 :   delete [] chanFreq;
     230         878 :   return spwId;
     231         878 : }
     232             : 
     233         881 : void SpectralGrid::appendChanFreq(unsigned int numChan, double* chanFreq)
     234             : {
     235             : 
     236             :   //    unsigned int k=v_chanFreq_.size();
     237      373487 :   for(unsigned int i = 0; i < numChan; i++) {
     238      372606 :     v_chanFreq_.push_back(chanFreq[i]); // cout << i << "v_chanFreq_="<<v_chanFreq_[k+i]<<endl;
     239             :   }
     240         881 : }
     241             : 
     242           0 : void SpectralGrid::appendChanFreq(unsigned int numChan, const std::vector<double> &chanFreq)
     243             : {
     244             : 
     245             :   //    unsigned int k=v_chanFreq_.size();
     246           0 :   for(unsigned int i = 0; i < numChan; i++) {
     247           0 :     v_chanFreq_.push_back(chanFreq[i]); // cout << i << "v_chanFreq_="<<v_chanFreq_[k+i]<<endl;
     248             :   }
     249           0 : }
     250             : 
     251           2 : unsigned int SpectralGrid::add(unsigned int numChan,
     252             :                                unsigned int refChan,
     253             :                                double* chanFreq,
     254             :                                Frequency::Units freqUnits)
     255             : {
     256           2 :   double fact = 1.0;
     257           2 :   if(freqUnits == Frequency::UnitGigaHertz) fact = 1.0E9;
     258           2 :   if(freqUnits == Frequency::UnitMegaHertz) fact = 1.0E6;
     259           2 :   if(freqUnits == Frequency::UnitKiloHertz) fact = 1.0E3;
     260             : 
     261           2 :   unsigned int spwId = v_transfertId_.size();
     262           2 :   if(spwId == 0) {
     263           1 :     v_transfertId_.push_back(0);
     264             :   } else {
     265           1 :     v_transfertId_.push_back(v_transfertId_[spwId - 1] + v_numChan_[spwId - 1]);
     266             :   }
     267             : 
     268           2 :   v_numChan_.push_back(numChan);
     269           2 :   v_refChan_.push_back(refChan);
     270             : 
     271           2 :   bool regular = true;
     272           2 :   double minFreq = 1.E30;
     273           2 :   double maxFreq = 0;
     274           2 :   double chanSep = 0;
     275           2 :   if(numChan > 1) chanSep = fact * (chanFreq[1] - chanFreq[0]);
     276             : 
     277           2 :   chanFreq[0] = fact * chanFreq[0];
     278         128 :   for(unsigned int i = 1; i < numChan; i++) {
     279         126 :     chanFreq[i] = fact * chanFreq[i];
     280         126 :     if(fabs(chanFreq[i] - chanFreq[i - 1] - chanSep) > 1.0E-12) regular = false;
     281         126 :     if(chanFreq[i] < minFreq) minFreq = chanFreq[i];
     282         126 :     if(chanFreq[i] > maxFreq) maxFreq = chanFreq[i];
     283             :   }
     284           2 :   appendChanFreq(numChan, chanFreq);
     285             : 
     286           2 :   v_refFreq_.push_back(chanFreq[refChan - 1]);
     287           2 :   if(regular) {
     288           1 :     v_chanSep_.push_back(chanSep);
     289             :   } else {
     290           1 :     v_chanSep_.push_back(0);
     291             :   }
     292           2 :   v_sidebandSide_ .push_back(NOSB);
     293           2 :   v_sidebandType_ .push_back(NOTYPE);
     294           2 :   v_intermediateFrequency_.push_back(0.0);
     295             : 
     296           2 :   return spwId;
     297             : }
     298             : 
     299           1 : SpectralGrid::SpectralGrid(unsigned int numChan,
     300             :                            double refFreq,
     301             :                            double* chanFreq,
     302           1 :                            Frequency::Units freqUnits)
     303             : {
     304           1 :   v_chanFreq_.reserve(numChan);
     305           1 :   freqUnits_ = Frequency::UnitHertz;
     306           1 :   v_transfertId_.resize(0); // not sure this is necessary!
     307           1 :   add(numChan, refFreq, chanFreq, freqUnits);
     308           1 :   std::vector<unsigned int> v_dummyInt;
     309           1 :   vv_assocSpwId_.push_back(v_dummyInt); // put an empty std::vector
     310           1 :   std::vector<std::string> v_dummyString;
     311           1 :   vv_assocNature_.push_back(v_dummyString); // put an empty std::vector
     312           1 : }
     313             : 
     314           0 : SpectralGrid::SpectralGrid(double refFreq,
     315             :                            const std::vector<double> &chanFreq,
     316           0 :                            Frequency::Units freqUnits)
     317             : {
     318           0 :   v_chanFreq_.reserve(chanFreq.size());
     319           0 :   freqUnits_ = Frequency::UnitHertz;
     320           0 :   v_transfertId_.resize(0); // not sure this is necessary!
     321           0 :   add(chanFreq.size(), refFreq, chanFreq, freqUnits);
     322           0 :   std::vector<unsigned int> v_dummyInt;
     323           0 :   vv_assocSpwId_.push_back(v_dummyInt); // put an empty std::vector
     324           0 :   std::vector<std::string> v_dummyString;
     325           0 :   vv_assocNature_.push_back(v_dummyString); // put an empty std::vector
     326           0 : }
     327             : 
     328           0 : SpectralGrid::SpectralGrid(const std::vector<double> &chanFreq, Frequency::Units freqUnits)
     329             : {
     330           0 :   v_chanFreq_.reserve(chanFreq.size());
     331           0 :   freqUnits_ = Frequency::UnitHertz;
     332           0 :   v_transfertId_.resize(0); // not sure this is necessary!
     333           0 :   double refFreq = (Frequency(chanFreq[0], freqUnits)).get(Frequency::UnitHertz); // We take the frequency of the first channel as
     334             :   // reference frequency because it has not been specified
     335           0 :   add(chanFreq.size(), refFreq, chanFreq, freqUnits);
     336           0 :   std::vector<unsigned int> v_dummyInt;
     337           0 :   vv_assocSpwId_.push_back(v_dummyInt); // put an empty std::vector
     338           0 :   std::vector<std::string> v_dummyString;
     339           0 :   vv_assocNature_.push_back(v_dummyString); // put an empty std::vector
     340           0 : }
     341             : 
     342           0 : SpectralGrid::SpectralGrid(const std::vector<Frequency> &chanFreq)
     343             : {
     344           0 :   v_chanFreq_.reserve(chanFreq.size());
     345           0 :   freqUnits_ = Frequency::UnitHertz;
     346           0 :   v_transfertId_.resize(0); // not sure this is necessary!
     347           0 :   double refFreq = chanFreq[0].get(Frequency::UnitHertz); // We take the frequency of the first channel as
     348             :   // reference frequency because it has not been specified
     349           0 :   std::vector<double> chanFreq_double;
     350           0 :   for(unsigned int i = 0; i < chanFreq.size(); i++) {
     351           0 :     chanFreq_double.push_back(chanFreq[i].get(Frequency::UnitGigaHertz));
     352             :   }
     353             : 
     354           0 :   add(chanFreq.size(), refFreq, chanFreq_double, Frequency::UnitGigaHertz);
     355           0 :   std::vector<unsigned int> v_dummyInt;
     356           0 :   vv_assocSpwId_.push_back(v_dummyInt); // put an empty std::vector
     357           0 :   std::vector<std::string> v_dummyString;
     358           0 :   vv_assocNature_.push_back(v_dummyString); // put an empty std::vector
     359           0 : }
     360             : 
     361           1 : unsigned int SpectralGrid::add(unsigned int numChan,
     362             :                                double refFreq,
     363             :                                double* chanFreq,
     364             :                                Frequency::Units freqUnits)
     365             : {
     366             : 
     367           1 :   bool regular = true;
     368           1 :   double fact = 1.0;
     369           1 :   if(freqUnits == Frequency::UnitGigaHertz) fact = 1.0E9;
     370           1 :   if(freqUnits == Frequency::UnitMegaHertz) fact = 1.0E6;
     371           1 :   if(freqUnits == Frequency::UnitKiloHertz) fact = 1.0E3;
     372             : 
     373           1 :   freqUnits_ = Frequency::UnitHertz;
     374             : 
     375           1 :   unsigned int spwId = v_transfertId_.size();
     376           1 :   if(spwId == 0) {
     377           1 :     v_transfertId_.push_back(0);
     378             :   } else {
     379           0 :     v_transfertId_.push_back(v_transfertId_[spwId - 1] + v_numChan_[spwId - 1]);
     380             :   }
     381             : 
     382           1 :   v_numChan_.push_back(numChan);
     383           1 :   v_refFreq_.push_back(fact * refFreq);
     384             : 
     385           1 :   double chanSep = fact * (chanFreq[1] - chanFreq[0]);
     386           1 :   double minFreq = 1.E30;
     387           1 :   double maxFreq = 0;
     388             : 
     389           1 :   chanFreq[0] = fact * chanFreq[0];
     390          64 :   for(unsigned int i = 1; i < numChan; i++) {
     391          63 :     chanFreq[i] = fact * chanFreq[i];
     392          63 :     if(fabs(chanFreq[i] - chanFreq[i - 1] - chanSep) > 1.0E-12) regular = false;
     393          63 :     if(chanFreq[i] < minFreq) minFreq = chanFreq[i];
     394          63 :     if(chanFreq[i] > maxFreq) maxFreq = chanFreq[i];
     395             :   }
     396           1 :   appendChanFreq(numChan, chanFreq);
     397           1 :   v_minFreq_.push_back(minFreq);
     398           1 :   v_maxFreq_.push_back(maxFreq);
     399             : 
     400           1 :   if(numChan > 1) {
     401           1 :     if(regular) {
     402           0 :       v_refChan_.push_back((unsigned int) (1. + (refFreq - v_chanFreq_[0]
     403           0 :           + 1.E-12) / chanSep));
     404           0 :       v_chanSep_.push_back(chanSep);
     405             :     } else {
     406           1 :       v_refChan_.push_back(0);
     407           1 :       v_chanSep_.push_back(0.0);
     408             :     }
     409             :   } else {
     410           0 :     v_refChan_.push_back(0);
     411           0 :     v_chanSep_.push_back(0.0);
     412             :   }
     413           1 :   v_sidebandSide_ .push_back(NOSB);
     414           1 :   v_sidebandType_ .push_back(NOTYPE);
     415           1 :   v_intermediateFrequency_.push_back(0.0);
     416             : 
     417           1 :   return spwId;
     418             : }
     419             : 
     420           0 :   unsigned int SpectralGrid::add(unsigned int numChan,
     421             :                                  double refFreq,
     422             :                                  const std::vector<double> &chanFreq,
     423             :                                  Frequency::Units freqUnits)
     424             : {
     425             : 
     426           0 :   bool regular = true;
     427           0 :   double fact = 1.0;
     428           0 :   if(freqUnits == Frequency::UnitGigaHertz) fact = 1.0E9;
     429           0 :   if(freqUnits == Frequency::UnitMegaHertz) fact = 1.0E6;
     430           0 :   if(freqUnits == Frequency::UnitKiloHertz) fact = 1.0E3;
     431             : 
     432           0 :   freqUnits_ =Frequency::UnitHertz;
     433             : 
     434           0 :   unsigned int spwId = v_transfertId_.size();
     435           0 :   if(spwId == 0) {
     436           0 :     v_transfertId_.push_back(0);
     437             :   } else {
     438           0 :     v_transfertId_.push_back(v_transfertId_[spwId - 1] + v_numChan_[spwId - 1]);
     439             :   }
     440             : 
     441           0 :   v_numChan_.push_back(numChan);
     442           0 :   v_refFreq_.push_back(fact * refFreq);
     443             : 
     444           0 :   double chanSep = fact * (chanFreq[1] - chanFreq[0]);
     445             : 
     446           0 :   std::vector<double> chanFreqHz(numChan);
     447           0 :   chanFreqHz[0] = fact * chanFreq[0];
     448           0 :   double minFreq = chanFreqHz[0];
     449           0 :   double maxFreq = chanFreqHz[0];
     450             : 
     451           0 :   for(unsigned int i = 1; i < numChan; i++) {
     452           0 :     chanFreqHz[i] = fact * chanFreq[i];
     453           0 :     if(fabs(chanFreqHz[i] - chanFreqHz[i - 1] - chanSep) > 1.0E-12) regular = false;
     454           0 :     if(chanFreqHz[i] < minFreq) minFreq = chanFreqHz[i];
     455           0 :     if(chanFreqHz[i] > maxFreq) maxFreq = chanFreqHz[i];
     456             :   }
     457           0 :   appendChanFreq(numChan, chanFreqHz);
     458           0 :   v_minFreq_.push_back(minFreq);
     459           0 :   v_maxFreq_.push_back(maxFreq);
     460             : 
     461           0 :   if(numChan > 1) {
     462           0 :     if(regular) {
     463           0 :       v_refChan_.push_back((unsigned int) (1. + (refFreq - v_chanFreq_[0]
     464           0 :           + 1.E-12) / chanSep));
     465           0 :       v_chanSep_.push_back(chanSep);
     466             :     } else {
     467           0 :       v_refChan_.push_back(0);
     468           0 :       v_chanSep_.push_back(0.0);
     469             :     }
     470             :   } else {
     471           0 :     v_refChan_.push_back(0);
     472           0 :     v_chanSep_.push_back(0.0);
     473             :   }
     474           0 :   v_sidebandSide_ .push_back(NOSB);
     475           0 :   v_sidebandType_ .push_back(NOTYPE);
     476           0 :   v_intermediateFrequency_.push_back(0.0);
     477             : 
     478           0 :   return spwId;
     479           0 : }
     480             : 
     481        2598 : SpectralGrid::SpectralGrid(const SpectralGrid & a)
     482             : {
     483             :   // cout <<  " SpectralGrid copy constructor" << endl;
     484        2598 :   freqUnits_ = a.freqUnits_;
     485        2598 :   v_chanFreq_ = a.v_chanFreq_;
     486             : 
     487        2598 :   v_numChan_ = a.v_numChan_; // cout << numChan_ << endl;
     488        2598 :   v_refChan_ = a.v_refChan_; // cout << refChan_ << endl;
     489        2598 :   v_refFreq_ = a.v_refFreq_; // cout << refChan_ << endl;
     490        2598 :   v_chanSep_ = a.v_chanSep_; // cout << chanSep_ << endl;
     491        2598 :   v_maxFreq_ = a.v_maxFreq_; // cout << maxFreq_ << endl;
     492        2598 :   v_minFreq_ = a.v_minFreq_; // cout << minFreq_ << endl;
     493        2598 :   v_intermediateFrequency_ = a.v_intermediateFrequency_;
     494        2598 :   v_loFreq_ = a.v_loFreq_;
     495        2598 :   v_sidebandSide_ = a.v_sidebandSide_;
     496        2598 :   v_sidebandType_ = a.v_sidebandType_;
     497        2598 :   vv_assocSpwId_ = a.vv_assocSpwId_;
     498        2598 :   vv_assocNature_ = a.vv_assocNature_;
     499        2598 :   v_transfertId_ = a.v_transfertId_;
     500             : 
     501             :   // cout << "v_chanFreq_.size()=" << v_chanFreq_.size() << endl;
     502        2598 : }
     503             : 
     504           0 : SpectralGrid::SpectralGrid()
     505             : {
     506           0 : }
     507             : 
     508             : // destructor
     509        3473 : SpectralGrid::~SpectralGrid()
     510             : {
     511        3473 : }
     512             : 
     513    32261243 : bool SpectralGrid::wrongSpwId(unsigned int spwId) const
     514             : {
     515    32261243 :   if(spwId > (v_transfertId_.size() - 1)) {
     516           2 :     std::cout << " SpectralGrid: ERROR: " << spwId
     517           2 :         << " is a wrong spectral window identifier" << std::endl;
     518           2 :     return (bool) true;
     519             :   }
     520    32261241 :   return (bool) false;
     521             : }
     522             : 
     523             : // accessors and utilities:
     524    16451928 : unsigned int SpectralGrid::getNumSpectralWindow() const
     525             : {
     526    16451928 :   return v_transfertId_.size();
     527             : }
     528       13352 : unsigned int SpectralGrid::getNumChan() const
     529             : {
     530       13352 :   return v_numChan_[0];
     531             : }
     532    16499602 : unsigned int SpectralGrid::getNumChan(unsigned int spwId) const
     533             : {
     534    16499602 :   if(wrongSpwId(spwId)) return 0;
     535    16499601 :   return v_numChan_[spwId];
     536             : }
     537             : 
     538           5 : unsigned int SpectralGrid::getRefChan() const
     539             : {
     540           5 :   return v_refChan_[0];
     541             : }
     542          15 : unsigned int SpectralGrid::getRefChan(unsigned int spwId) const
     543             : {
     544          15 :   if(wrongSpwId(spwId)) return 32767;
     545          15 :   return v_refChan_[spwId];
     546             : }
     547             : 
     548           6 : Frequency SpectralGrid::getRefFreq() const
     549             : {
     550           6 :   return Frequency(v_refFreq_[0], Frequency::UnitHertz);
     551             : }
     552           6 : Frequency SpectralGrid::getRefFreq(unsigned int spwId) const
     553             : {
     554           6 :   if(wrongSpwId(spwId)) return 32767.;
     555           6 :   return Frequency(v_refFreq_[spwId], Frequency::UnitHertz);
     556             : }
     557             : 
     558           7 : Frequency SpectralGrid::getChanSep() const
     559             : {
     560           7 :   return Frequency(v_chanSep_[0], Frequency::UnitHertz);
     561             : }
     562           7 : Frequency SpectralGrid::getChanSep(unsigned int spwId) const
     563             : {
     564           7 :   if(wrongSpwId(spwId)) return 32767.;
     565           7 :   return Frequency(v_chanSep_[spwId], Frequency::UnitHertz);
     566             : }
     567             : 
     568          87 : Frequency SpectralGrid::getChanFreq(unsigned int i) const
     569             : {
     570          87 :   return Frequency(v_chanFreq_[i], Frequency::UnitHertz);
     571             : }
     572             : 
     573           0 : Frequency SpectralGrid::getChanWidth(unsigned int i) const
     574             : {
     575           0 :  if(i == 0){
     576           0 :    return getChanFreq(i+1)-getChanFreq(i);
     577             :  }else{
     578           0 :    return getChanFreq(i)-getChanFreq(i-1);
     579             :  }
     580             : }
     581             : 
     582    15760961 : Frequency SpectralGrid::getChanFreq(unsigned int spwId, unsigned int chanIdx) const
     583             : {
     584    15760961 :   if(wrongSpwId(spwId)) return 32767.;
     585    15760961 :   return Frequency(v_chanFreq_[v_transfertId_[spwId] + chanIdx], Frequency::UnitHertz);
     586             : }
     587             : 
     588           0 : Frequency SpectralGrid::getChanWidth(unsigned int spwId, unsigned int chanIdx) const
     589             : {
     590           0 :   if(wrongSpwId(spwId)) return 32767.;
     591             : 
     592           0 :   unsigned int banda=spwId;
     593           0 :   unsigned int canalmasuno=chanIdx+1;
     594           0 :   unsigned int canal=chanIdx;
     595           0 :   unsigned int canalmenosuno=chanIdx-1;
     596             :   //  cout << "banda,canal-1,canal,canal+1= " << banda << " " << canalmenosuno << " " << canal << " " << canalmasuno << endl;
     597             : 
     598           0 :   if(chanIdx == 0){
     599           0 :     return getChanFreq(spwId,canalmasuno)-getChanFreq(spwId,canal);
     600             :   }else{
     601             :     //  cout << "ChanFreq(" << banda << "," << canal << ")=" << getChanFreq(banda,canal).get(Frequency::UnitGigaHertz) << endl;
     602             :     //  cout << "ChanFreq(" << banda << "," << canalmenosuno << ")=" << getChanFreq(banda,canalmenosuno).get(Frequency::UnitGigaHertz) << endl;
     603           0 :     return getChanFreq(banda,canal)-getChanFreq(banda,canalmenosuno);
     604             :   }
     605             : }
     606             : 
     607           0 : std::vector<double> SpectralGrid::getSbChanFreq(unsigned int spwId,
     608             :                                            unsigned int chanIdx,
     609             :                                            const std::string &units) const
     610             : {
     611           0 :   std::vector<double> v_dummyVector;
     612           0 :   if(wrongSpwId(spwId)) return v_dummyVector;
     613           0 :   v_dummyVector.push_back(getChanFreq(spwId, chanIdx).get(units));
     614           0 :   for(unsigned int n = 0; n < vv_assocNature_[spwId].size(); n++) {
     615           0 :     if(vv_assocNature_[spwId][n] == "USB" || vv_assocNature_[spwId][n] == "LSB") {
     616           0 :       unsigned int assocSpwId = vv_assocSpwId_[spwId][n];
     617           0 :       v_dummyVector.push_back(getChanFreq(assocSpwId, chanIdx).get(units));
     618             :     }
     619             :   }
     620           0 :   return v_dummyVector;
     621           0 : }
     622             : 
     623         105 : std::vector<double> SpectralGrid::getSpectralWindow(unsigned int spwId) const
     624             : {
     625         105 :   std::vector<double> v_chanFreq;
     626         105 :   if(wrongSpwId(spwId)) return v_chanFreq;
     627         105 :   v_chanFreq.reserve(v_numChan_[spwId]);
     628      210105 :   for(unsigned int n = 0; n < v_numChan_[spwId]; n++)
     629      210000 :     v_chanFreq.push_back(v_chanFreq_[v_transfertId_[spwId] + n]);
     630         105 :   return v_chanFreq;
     631           0 : }
     632             : 
     633           2 : Frequency SpectralGrid::getMinFreq() const
     634             : {
     635           2 :   return Frequency(v_minFreq_[0], Frequency::UnitHertz);
     636             : }
     637           4 : Frequency SpectralGrid::getMinFreq(unsigned int spwId) const
     638             : {
     639           4 :   if(wrongSpwId(spwId)) return 32767.;
     640           4 :   return Frequency(v_minFreq_[spwId], Frequency::UnitHertz);
     641             : }
     642             : 
     643           2 : Frequency SpectralGrid::getMaxFreq() const
     644             : {
     645           2 :   return Frequency(v_maxFreq_[0], Frequency::UnitHertz);
     646             : }
     647           4 : Frequency SpectralGrid::getMaxFreq(unsigned int spwId) const
     648             : {
     649           4 :   if(wrongSpwId(spwId)) return 32767.;
     650           4 :   return Frequency(v_maxFreq_[spwId], Frequency::UnitHertz);
     651             : }
     652             : 
     653           1 : double SpectralGrid::getChanNum(double freq) const
     654             : {
     655           1 :   if(v_numChan_[0] == 1) return 1;
     656           1 :   if(v_chanSep_[0] == 0.0) { // irregular grid, look for the nearest channel
     657           1 :     double sep = 1.E30;
     658           1 :     int k = -1;
     659          65 :     for(unsigned int i = 0; i < v_numChan_[0]; i++) {
     660          64 :       if(sep > fabs(v_chanFreq_[v_transfertId_[0] + i] - freq)) {
     661          33 :         sep = fabs(v_chanFreq_[v_transfertId_[0] + i] - freq);
     662          33 :         k = i;
     663             :       }
     664             :     }
     665           1 :     return (double) 1 - v_refChan_[0] + k; // channel the nearest
     666             :   } else { // regular spectral grid
     667           0 :     return (freq - v_refFreq_[0]) / v_chanSep_[0];
     668             :   }
     669             : }
     670           4 : double SpectralGrid::getChanNum(unsigned int spwId, double freq) const
     671             : {
     672           4 :   if(wrongSpwId(spwId)) return 32767.;
     673           4 :   if(v_numChan_[spwId] == 1) return 1;
     674           4 :   if(v_chanSep_[spwId] == 0.0) { // irregular grid, look for the nearest channel
     675           0 :     double sep = 1.E30;
     676           0 :     int k = -1;
     677           0 :     for(unsigned int i = 0; i < v_numChan_[spwId]; i++) {
     678           0 :       if(sep > fabs(v_chanFreq_[v_transfertId_[spwId] + i] - freq)) {
     679           0 :         sep = fabs(v_chanFreq_[v_transfertId_[spwId] + i] - freq);
     680           0 :         k = i;
     681             :       }
     682             :     }
     683           0 :     return (double) 1 - v_refChan_[spwId] + k; // channel the nearest
     684             :   } else { // regular spectral grid
     685           4 :     return (freq - v_refFreq_[spwId]) / v_chanSep_[spwId];
     686             :   }
     687             : }
     688             : 
     689           1 : Frequency SpectralGrid::getBandwidth() const
     690             : {
     691           1 :   return Frequency(v_maxFreq_[0] - v_minFreq_[0], Frequency::UnitHertz);
     692             : }
     693             : 
     694           0 : Frequency SpectralGrid::getBandwidth(unsigned int spwId) const
     695             : {
     696           0 :   if(wrongSpwId(spwId)) return 32767.;
     697           0 :   return Frequency(v_maxFreq_[spwId] - v_minFreq_[spwId], Frequency::UnitHertz);
     698             : }
     699             : 
     700           2 : bool SpectralGrid::isRegular() const
     701             : {
     702           2 :   if(v_chanSep_[0] == 0.0) return false;
     703           2 :   return true;
     704             : }
     705             : 
     706           5 : bool SpectralGrid::isRegular(unsigned int spwId) const
     707             : {
     708           5 :   if(wrongSpwId(spwId)) return false;
     709           5 :   if(v_chanSep_[spwId] == 0.0) return false;
     710           4 :   return true;
     711             : }
     712             : 
     713           0 : std::string SpectralGrid::getSidebandSide(unsigned int spwId) const
     714             : {
     715           0 :   if(!wrongSpwId(spwId)) {
     716           0 :     if(vv_assocSpwId_[spwId].size() == 0) {
     717             :       /* cout << "WARNING: the spectral window with the identifier "<< spwId
     718             :        << " has no associated spectral window "<< endl; */
     719           0 :       return "";
     720             :     }
     721           0 :     if(v_sidebandSide_[spwId] == NOSB) return "NoSB";
     722           0 :     if(v_sidebandSide_[spwId] == LSB) return "LSB";
     723           0 :     if(v_sidebandSide_[spwId] == USB) return "USB";
     724             :   }
     725           0 :   return "";
     726             : }
     727             : 
     728           0 : std::string SpectralGrid::getSidebandType(unsigned int spwId) const
     729             : {
     730           0 :   if(!wrongSpwId(spwId)) {
     731           0 :     if(vv_assocSpwId_[spwId].size() == 0) {
     732             :       /* cout << "WARNING: the spectral window with the identifier "<< spwId
     733             :        << " has no associated spectral window "<< endl; */
     734             :     }
     735           0 :     return "";
     736             :     if(v_sidebandType_[spwId] == DSB) return " DSB";
     737             :     if(v_sidebandType_[spwId] == SSB) return " SSB";
     738             :     if(v_sidebandType_[spwId] == TWOSB) return " 2SB";
     739             :   }
     740           0 :   return "";
     741             : }
     742             : 
     743         260 : std::string SpectralGrid::getSideband(unsigned int spwId) const
     744             : {
     745         260 :   if(!wrongSpwId(spwId)) {
     746         259 :     if(vv_assocSpwId_[spwId].size() == 0) {
     747             :       /* cout << "WARNING: the spectral window with the identifier "<< spwId
     748             :        << " has no associated spectral window "<< endl; */
     749             :     }
     750         259 :     return "";
     751             :     if(getSidebandSide(spwId) == "NoSB") {
     752             :       return getSidebandSide(spwId);
     753             :     } else {
     754             :       std::string sbTypeSide = getSidebandSide(spwId) + " with type ";
     755             :       return (sbTypeSide + getSidebandType(spwId));
     756             :     }
     757             :   }
     758           1 :   return "";
     759             : }
     760             : 
     761         258 : std::vector<std::string> SpectralGrid::getAssocNature(unsigned int spwId) const
     762             : {
     763         258 :   if(!wrongSpwId(spwId)) {
     764         258 :     if(vv_assocNature_[spwId].size() == 0) {
     765             :       /* cout << "WARNING: the spectral window with the identifier "<< spwId
     766             :        << " has no associated spectral window "<< endl; */
     767             :     }
     768         258 :     return vv_assocNature_[spwId];
     769             :   }
     770           0 :   std::vector<std::string> v_dummyVector;
     771           0 :   return v_dummyVector;
     772           0 : }
     773             : 
     774           9 : std::vector<unsigned int> SpectralGrid::getAssocSpwId(unsigned int spwId) const
     775             : {
     776           9 :   if(!wrongSpwId(spwId)) {
     777           9 :     if(vv_assocSpwId_[spwId].size() == 0) {
     778             :       /* cout << "WARNING: the spectral window with the identifier "<< spwId
     779             :        << " has no associated spectral window "<< endl; */
     780             :       /* cout << "vv_assocSpwId_[" <<spwId<<"]=" <<  vv_assocSpwId_[spwId][0] << endl; */
     781             :     }
     782           9 :     return vv_assocSpwId_[spwId];
     783             : 
     784             :   }
     785           0 :   std::vector<unsigned int> v_dummyVector;
     786           0 :   return v_dummyVector;
     787           0 : }
     788             : 
     789           0 : std::vector<unsigned int> SpectralGrid::getAssocSpwIds(const std::vector<unsigned int> &spwIds) const
     790             : {
     791             : 
     792             :   unsigned int spwId;
     793           0 :   std::vector<unsigned int> assoc_spwIds;
     794             : 
     795           0 :   for(unsigned int n = 0; n < spwIds.size(); n++) {
     796             : 
     797           0 :     spwId = spwIds[n];
     798             : 
     799           0 :     if(!wrongSpwId(spwId)) {
     800           0 :       if(vv_assocSpwId_[spwId].size() == 0) {
     801             :         /* cout << "WARNING: the spectral window with the identifier "<< spwId
     802             :          << " has no associated spectral window "<< endl; */
     803             :         /* cout << "vv_assocSpwId_[" <<spwId<<"]=" <<  vv_assocSpwId_[spwId][0] << endl; */
     804             :       }
     805             : 
     806           0 :       assoc_spwIds.push_back((vv_assocSpwId_[spwId])[0]);
     807             : 
     808             :     } else {
     809           0 :       assoc_spwIds.push_back(spwId);
     810             :     }
     811             : 
     812             :   }
     813             : 
     814           0 :   return assoc_spwIds;
     815             : 
     816           0 : }
     817             : 
     818           0 : double SpectralGrid::getLoFrequency() const
     819             : {
     820           0 :   return v_loFreq_[0];
     821             : }
     822             : 
     823           3 : double SpectralGrid::getLoFrequency(unsigned int spwId) const
     824             : {
     825           3 :   if(wrongSpwId(spwId)) return 32767.;
     826           3 :   return v_loFreq_[spwId];
     827             : }
     828             : 
     829             : ATM_NAMESPACE_END
     830             : 

Generated by: LCOV version 1.16