LCOV - code coverage report
Current view: top level - air_casawvr/src - dispersion.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 30 0.0 %
Date: 2024-10-28 15:53:10 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /**
       2             :    Bojan Nikolic <b.nikolic@mrao.cam.ac.uk>, <bojan@bnikolic.co.uk>
       3             :    Initial version August 2010.
       4             :    Maintained by ESO since 2013.
       5             : 
       6             :    This file is part of LibAIR and is licensed under GNU Public
       7             :    License Version 2
       8             : 
       9             :    \file dispersion.cpp
      10             :    Renamed dispersion.cc 2023
      11             : 
      12             : */
      13             : #include <iostream>
      14             : #include <fstream>
      15             : #include <sstream>
      16             : 
      17             : #include <stdio.h> 
      18             : #include <stdlib.h>
      19             : #include <string>
      20             : 
      21             : #include "dispersion.h"
      22             : 
      23             : namespace LibAIR2 {
      24             : 
      25           0 :   double DispersionTab::operator() (double fnu)
      26             :   {
      27           0 :     std::pair<double, double> b= *lower_bound(fnu);
      28           0 :     if (b.first==fnu)
      29           0 :       return b.second;
      30             : 
      31           0 :     std::pair<double, double> l= *(--lower_bound(fnu));
      32           0 :     std::pair<double, double> u= *upper_bound(fnu);
      33             :     
      34           0 :     const double f=(fnu-l.first)/(u.first-l.first);
      35           0 :     return l.second+ f*(u.second-l.second);
      36             :     
      37             :   }
      38             : 
      39           0 :   void loadCSV(const char *fname,
      40             :                DispersionTab &dt)
      41             :   {
      42           0 :     std::ifstream ifs(fname);
      43           0 :     if (not ifs.good()){
      44           0 :       throw std::runtime_error(std::string("Could not open dispersion table ")+fname);
      45             :     }
      46           0 :     std::string scratch;
      47             : 
      48           0 :     while(ifs.good()){
      49           0 :       std::getline(ifs, scratch);
      50             :       //std::cerr << scratch << " - interpreted as:"; 
      51           0 :       if (scratch.size() < 5){
      52             :         //std::cerr << "(nothing)" << std:: endl;
      53           0 :         continue;
      54             :       }
      55             : 
      56           0 :       std::stringstream ss(scratch);
      57             :       double first, second;
      58           0 :       std::string sep;
      59           0 :       if(ss >> first){
      60           0 :         if(ss >> sep){
      61           0 :           if(ss >> second){
      62           0 :             dt.insert(dt.end(),
      63           0 :                       std::pair<double, double>(first, second));
      64             :             //std::cerr << "(double)  " << first << " ,  " << second << " " << std::endl;
      65             :           }
      66             :           else{
      67           0 :             std::cerr<<" Reading " << fname << ": could not interpret third part of " << scratch <<std::endl;
      68             :           }
      69             :         }
      70             :         else{
      71           0 :           std::cerr<<" Reading " << fname << ": could not interpret separator in " << scratch <<std::endl;
      72             :         }
      73             :       }
      74             :       else{
      75           0 :         std::cerr<<" Reading " << fname << ": could not interpret first part of " << scratch <<std::endl;
      76             :       } 
      77           0 :     }
      78             : 
      79           0 :     return;
      80           0 :   }
      81             : 
      82             : }

Generated by: LCOV version 1.16