LCOV - code coverage report
Current view: top level - synthesis/CalLibrary - CalLibraryTools.cc (source / functions) Hit Total Coverage
Test: ctest_coverage.info Lines: 33 57 57.9 %
Date: 2023-11-06 10:06:49 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: aips2-request@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          11 : int CalLibraryGramwrap()
      41             : {
      42          11 :   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          11 : Record callibSetParams(const String& calLibrary) {
      53          11 :     Record callibRec;
      54          11 :     CalLibraryParse* calParser = new CalLibraryParse();
      55             :     try {
      56          11 :         callibRec = calLibraryGramParseCommand(calParser, calLibrary);
      57           0 :     } catch(AipsError &x) {
      58           0 :         delete calParser;
      59           0 :         throw;
      60             :     }
      61          11 :     delete calParser;
      62          11 :     return callibRec; 
      63             : }
      64             : 
      65          11 : Record calLibraryGramParseCommand(CalLibraryParse* parser, const String& calLibrary) {
      66          22 :     ifstream myfile;
      67             :     try {
      68          11 :         if (calLibrary.contains("=")) {
      69             :             //calLibrary is a String
      70           0 :             CalLibraryGramrestart(CalLibraryGramin);
      71           0 :             yy_start = 1;
      72           0 :             String inputstr = calLibrary + "\n"; // caltable terminator
      73           0 :             strpCalLibraryGram = inputstr.chars();
      74           0 :             callib_linenum = 1;
      75           0 :             CalLibraryParse::thisCalLibParser = parser;
      76           0 :             CalLibraryGramparse();
      77           0 :             return *(parser->record());
      78             :         } else {
      79             :             // calLibrary is a File
      80          11 :             CalLibraryGramrestart(CalLibraryGramin);
      81          11 :             yy_start = 1;
      82          11 :             callib_linenum = 1;
      83          11 :             CalLibraryParse::thisCalLibParser = parser;
      84             : 
      85          11 :             myfile.open(calLibrary.chars());
      86          11 :             if (myfile.is_open()) {
      87          22 :                 string line;
      88          33 :                 string inputstr="";
      89          27 :                 while (getline(myfile, line)) {
      90          16 :                     inputstr += line + "\n"; // caltable terminator
      91             :                 }
      92          11 :                 strpCalLibraryGram = inputstr.c_str();
      93          11 :                 CalLibraryGramparse(); 
      94          11 :                 myfile.close();
      95          11 :                 return *(parser->record());
      96             :             } 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             :     }
     104             : }
     105             : 
     106             : //# Get the next input characters for flex.
     107          22 : int calLibraryGramInput (char* buf, int max_size)
     108             : {
     109          22 :     int nr=0;
     110             :     //clearBuf(buf, max_size);
     111             : 
     112        1001 :     while (*strpCalLibraryGram != 0) {
     113         979 :       if (nr >= max_size) {
     114           0 :         break;                         // get max. max_size char.
     115             :       }
     116         979 :       buf[nr++] = *strpCalLibraryGram++;
     117             :     }
     118          22 :     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             : }
     131             : 
     132          16 : Int& calLibLineNum() {
     133          16 :     return callib_linenum;
     134             : }
     135             : 
     136             : }
     137             : 

Generated by: LCOV version 1.16