LCOV - code coverage report
Current view: top level - synthesis/CalLibrary - CalLibraryTools.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 44 64 68.8 %
Date: 2024-10-28 15:53:10 Functions: 5 7 71.4 %

          Line data    Source code
       1             : //# CalLibraryTools.cc: access to cal library file parser
       2             : //# Copyright (C) 2015
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This library is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU Library General Public License as published by
       7             : //# the Free Software Foundation; either version 2 of the License, or (at your
       8             : //# option) any later version.
       9             : //#
      10             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      11             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      13             : //# License for more details.
      14             : //#
      15             : //# You should have received a copy of the GNU Library General Public License
      16             : //# along with this library; if not, write to the Free Software Foundation,
      17             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      18             : //#
      19             : //# Correspondence concerning AIPS++ should be addressed as follows:
      20             : //#        Internet email: casa-feedback@nrao.edu.
      21             : //#        Postal address: AIPS++ Project Office
      22             : //#                        National Radio Astronomy Observatory
      23             : //#                        520 Edgemont Road
      24             : //#                        Charlottesville, VA 22903-2475 USA
      25             : //#
      26             : 
      27             : #include <synthesis/CalLibrary/CalLibraryTools.h>
      28             : #include <fstream>
      29             : 
      30             : //# stdlib.h is needed for bison 1.28 and needs to be included here
      31             : //# (before the flex/bison files).
      32             : #include <casacore/casa/stdlib.h>
      33             : //# Define register as empty string to avoid warnings in C++11 compilers
      34             : //# because keyword register is not supported anymore.
      35             : #define register
      36             : #include "CalLibraryGram.ycc"                  // bison output
      37             : #include "CalLibraryGram.lcc"                  // flex output
      38             : 
      39             : // Define the yywrap function for flex.
      40           3 : int CalLibraryGramwrap()
      41             : {
      42           3 :   return 1;
      43             : }
      44             : 
      45             : 
      46             : using namespace casacore;
      47             : namespace casa {
      48             : 
      49             : static Int callib_linenum = 0;
      50             : static const Char* strpCalLibraryGram = 0;
      51             : 
      52           3 : Record callibSetParams(const String& calLibrary) {
      53           3 :     Record callibRec;
      54           3 :     CalLibraryParse* calParser = new CalLibraryParse();
      55             :     try {
      56           3 :         callibRec = calLibraryGramParseCommand(calParser, calLibrary);
      57           0 :     } catch(AipsError &x) {
      58           0 :         delete calParser;
      59           0 :         throw;
      60           0 :     }
      61           3 :     delete calParser;
      62           3 :     return callibRec; 
      63           0 : }
      64             : 
      65           3 : Record calLibraryGramParseCommand(CalLibraryParse* parser, const String& calLibrary) {
      66           3 :     ifstream myfile;
      67             :     try {
      68           3 :         if (calLibrary.contains("=")) {
      69             :             //calLibrary is a String
      70           2 :             CalLibraryGramrestart(CalLibraryGramin);
      71           2 :             yy_start = 1;
      72           2 :             String inputstr = calLibrary + "\n"; // caltable terminator
      73           2 :             strpCalLibraryGram = inputstr.chars();
      74           2 :             callib_linenum = 1;
      75           2 :             CalLibraryParse::thisCalLibParser = parser;
      76           2 :             CalLibraryGramparse();
      77           2 :             return *(parser->record());
      78           2 :         } else {
      79             :             // calLibrary is a File
      80           1 :             CalLibraryGramrestart(CalLibraryGramin);
      81           1 :             yy_start = 1;
      82           1 :             callib_linenum = 1;
      83           1 :             CalLibraryParse::thisCalLibParser = parser;
      84             : 
      85           1 :             myfile.open(calLibrary.chars());
      86           1 :             if (myfile.is_open()) {
      87           1 :                 string line;
      88           1 :                 string inputstr="";
      89           7 :                 while (getline(myfile, line)) {
      90           6 :                     inputstr += line + "\n"; // caltable terminator
      91             :                 }
      92           1 :                 strpCalLibraryGram = inputstr.c_str();
      93           1 :                 CalLibraryGramparse(); 
      94           1 :                 myfile.close();
      95           1 :                 return *(parser->record());
      96           1 :             } else {
      97           0 :                 throw (AipsError("Cal Library parser failed to open file"));
      98             :             }
      99             :         }
     100           0 :     } catch(AipsError &x) {
     101           0 :         myfile.close();
     102           0 :         throw;
     103           0 :     }
     104           3 : }
     105             : 
     106             : //# Get the next input characters for flex.
     107           6 : int calLibraryGramInput (char* buf, int max_size)
     108             : {
     109           6 :     int nr=0;
     110             :     //clearBuf(buf, max_size);
     111             : 
     112         489 :     while (*strpCalLibraryGram != 0) {
     113         483 :       if (nr >= max_size) {
     114           0 :         break;                         // get max. max_size char.
     115             :       }
     116         483 :       buf[nr++] = *strpCalLibraryGram++;
     117             :     }
     118           6 :     return nr;
     119             : }
     120             : 
     121           0 : void clearBuf(char* buf, int size) {
     122           0 :     for (int i=0; i<size; i++)
     123           0 :         buf[i] = 0;
     124           0 : }
     125             : 
     126           0 : void CalLibraryGramerror(const char* s) {
     127           0 :     stringstream ss;
     128           0 :     ss << "Cal Library file: Parse error on line " << callib_linenum <<  ": " << s;
     129           0 :     throw (AipsError(ss.str()));
     130           0 : }
     131             : 
     132           9 : Int& calLibLineNum() {
     133           9 :     return callib_linenum;
     134             : }
     135             : 
     136             : }
     137             : 

Generated by: LCOV version 1.16