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-11-06 17:42:47 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          14 : int CalLibraryGramwrap()
      41             : {
      42          14 :   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          14 : Record callibSetParams(const String& calLibrary) {
      53          14 :     Record callibRec;
      54          14 :     CalLibraryParse* calParser = new CalLibraryParse();
      55             :     try {
      56          14 :         callibRec = calLibraryGramParseCommand(calParser, calLibrary);
      57           0 :     } catch(AipsError &x) {
      58           0 :         delete calParser;
      59           0 :         throw;
      60           0 :     }
      61          14 :     delete calParser;
      62          14 :     return callibRec; 
      63           0 : }
      64             : 
      65          14 : Record calLibraryGramParseCommand(CalLibraryParse* parser, const String& calLibrary) {
      66          14 :     ifstream myfile;
      67             :     try {
      68          14 :         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          12 :             CalLibraryGramrestart(CalLibraryGramin);
      81          12 :             yy_start = 1;
      82          12 :             callib_linenum = 1;
      83          12 :             CalLibraryParse::thisCalLibParser = parser;
      84             : 
      85          12 :             myfile.open(calLibrary.chars());
      86          12 :             if (myfile.is_open()) {
      87          12 :                 string line;
      88          12 :                 string inputstr="";
      89          34 :                 while (getline(myfile, line)) {
      90          22 :                     inputstr += line + "\n"; // caltable terminator
      91             :                 }
      92          12 :                 strpCalLibraryGram = inputstr.c_str();
      93          12 :                 CalLibraryGramparse(); 
      94          12 :                 myfile.close();
      95          12 :                 return *(parser->record());
      96          12 :             } 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          14 : }
     105             : 
     106             : //# Get the next input characters for flex.
     107          28 : int calLibraryGramInput (char* buf, int max_size)
     108             : {
     109          28 :     int nr=0;
     110             :     //clearBuf(buf, max_size);
     111             : 
     112        1490 :     while (*strpCalLibraryGram != 0) {
     113        1462 :       if (nr >= max_size) {
     114           0 :         break;                         // get max. max_size char.
     115             :       }
     116        1462 :       buf[nr++] = *strpCalLibraryGram++;
     117             :     }
     118          28 :     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          25 : Int& calLibLineNum() {
     133          25 :     return callib_linenum;
     134             : }
     135             : 
     136             : }
     137             : 

Generated by: LCOV version 1.16