LCOV - code coverage report
Current view: top level - src/components - ifile.cpp (source / functions) Hit Total Coverage
Test: qucs-core-0.0.19 Code Coverage Lines: 0 61 0.0 %
Date: 2015-01-05 16:01:02 Functions: 0 11 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 66 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * ifile.cpp - file based current source class implementation
       3                 :            :  *
       4                 :            :  * Copyright (C) 2007, 2008, 2009 Stefan Jahn <stefan@lkcc.org>
       5                 :            :  *
       6                 :            :  * This is free software; you can redistribute it and/or modify
       7                 :            :  * it under the terms of the GNU General Public License as published by
       8                 :            :  * the Free Software Foundation; either version 2, or (at your option)
       9                 :            :  * any later version.
      10                 :            :  *
      11                 :            :  * This software is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this package; see the file COPYING.  If not, write to
      18                 :            :  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
      19                 :            :  * Boston, MA 02110-1301, USA.
      20                 :            :  *
      21                 :            :  * $Id$
      22                 :            :  *
      23                 :            :  */
      24                 :            : 
      25                 :            : #if HAVE_CONFIG_H
      26                 :            : # include <config.h>
      27                 :            : #endif
      28                 :            : 
      29                 :            : #include "component.h"
      30                 :            : #include "dataset.h"
      31                 :            : #include "poly.h"
      32                 :            : #include "spline.h"
      33                 :            : #include "interpolator.h"
      34                 :            : #include "ifile.h"
      35                 :            : 
      36                 :            : using namespace qucs;
      37                 :            : 
      38                 :            : // Constructor creates ifile object in memory.
      39                 :          0 : ifile::ifile () : circuit (2) {
      40                 :          0 :   type = CIR_IFILE;
      41                 :          0 :   setISource (true);
      42                 :          0 :   interpolType = dataType = 0;
      43                 :          0 :   data = NULL;
      44                 :          0 :   inter = NULL;
      45                 :          0 : }
      46                 :            : 
      47                 :            : // Destructor deletes ifile object from memory.
      48                 :          0 : ifile::~ifile () {
      49 [ #  # ][ #  # ]:          0 :   if (data) delete data;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      50 [ #  # ][ #  # ]:          0 :   if (inter) delete inter;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      51 [ #  # ][ #  # ]:          0 : }
      52                 :            : 
      53                 :          0 : void ifile::prepare (void) {
      54                 :            : 
      55                 :            :   // check type of interpolator
      56                 :          0 :   const char * itype = getPropertyString ("Interpolator");
      57         [ #  # ]:          0 :   if (!strcmp (itype, "linear")) {
      58                 :          0 :     interpolType = INTERPOL_LINEAR;
      59         [ #  # ]:          0 :   } else if (!strcmp (itype, "cubic")) {
      60                 :          0 :     interpolType = INTERPOL_CUBIC;
      61         [ #  # ]:          0 :   } else if (!strcmp (itype, "hold")) {
      62                 :          0 :     interpolType = INTERPOL_HOLD;
      63                 :            :   }
      64                 :            : 
      65                 :            :   // check type of repetition
      66                 :          0 :   const char * rtype = getPropertyString ("Repeat");
      67         [ #  # ]:          0 :   if (!strcmp (rtype, "no")) {
      68                 :            :     // rectangular data
      69                 :          0 :     dataType = REPEAT_NO;
      70         [ #  # ]:          0 :   } else if (!strcmp (rtype, "yes")) {
      71                 :            :     // polar data
      72                 :          0 :     dataType = REPEAT_YES;
      73                 :            :   }
      74                 :            : 
      75                 :            :   // load file with samples
      76                 :          0 :   const char * file = getPropertyString ("File");
      77         [ #  # ]:          0 :   if (data == NULL) {
      78 [ #  # ][ #  # ]:          0 :     if (strlen (file) > 4 && !strcasecmp (&file[strlen (file) - 4], ".dat"))
      79                 :          0 :       data = dataset::load (file);
      80                 :            :     else
      81                 :          0 :       data = dataset::load_csv (file);
      82         [ #  # ]:          0 :     if (data != NULL) {
      83                 :            :       // check number of variables / dependencies defined by that file
      84 [ #  # ][ #  # ]:          0 :       if (data->countVariables () != 1 || data->countDependencies () != 1) {
                 [ #  # ]
      85                 :            :         logprint (LOG_ERROR, "ERROR: file `%s' must have time as an "
      86                 :            :                   "independent and the current source samples as dependents\n",
      87                 :          0 :                   file);
      88                 :          0 :         return;
      89                 :            :       }
      90                 :          0 :       qucs::vector * is = data->getVariables();    // current
      91                 :          0 :       qucs::vector * ts = data->getDependencies(); // time
      92         [ #  # ]:          0 :       inter = new interpolator ();
      93                 :          0 :       inter->rvectors (is, ts);
      94                 :          0 :       inter->prepare (interpolType, dataType);
      95                 :            :     }
      96                 :            :   }
      97                 :            : }
      98                 :            : 
      99                 :          0 : void ifile::initSP (void) {
     100                 :          0 :   allocMatrixS ();
     101         [ #  # ]:          0 :   setS (NODE_1, NODE_1, 1.0);
     102         [ #  # ]:          0 :   setS (NODE_1, NODE_2, 0.0);
     103         [ #  # ]:          0 :   setS (NODE_2, NODE_1, 0.0);
     104         [ #  # ]:          0 :   setS (NODE_2, NODE_2, 1.0);
     105                 :          0 : }
     106                 :            : 
     107                 :          0 : void ifile::initDC (void) {
     108                 :          0 :   allocMatrixMNA ();
     109                 :          0 :   prepare ();
     110                 :          0 : }
     111                 :            : 
     112                 :          0 : void ifile::initAC (void) {
     113                 :          0 :   initDC ();
     114                 :          0 : }
     115                 :            : 
     116                 :          0 : void ifile::initTR (void) {
     117                 :          0 :   initDC ();
     118                 :          0 : }
     119                 :            : 
     120                 :          0 : void ifile::calcTR (nr_double_t t) {
     121                 :          0 :   nr_double_t G = getPropertyDouble ("G");
     122                 :          0 :   nr_double_t T = getPropertyDouble ("T");
     123                 :          0 :   nr_double_t i = inter->rinterpolate (t - T);
     124 [ #  # ][ #  # ]:          0 :   setI (NODE_1, +G * i); setI (NODE_2, -G * i);
     125                 :          0 : }
     126                 :            : 
     127                 :            : // properties
     128                 :            : PROP_REQ [] = {
     129                 :            :   { "File", PROP_STR, { PROP_NO_VAL, "ifile.dat" }, PROP_NO_RANGE },
     130                 :            :   PROP_NO_PROP };
     131                 :            : PROP_OPT [] = {
     132                 :            :   { "Interpolator", PROP_STR, { PROP_NO_VAL, "linear" },
     133                 :            :     PROP_RNG_STR3 ("hold", "linear", "cubic") },
     134                 :            :   { "Repeat", PROP_STR, { PROP_NO_VAL, "no" }, PROP_RNG_YESNO },
     135                 :            :   { "G", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE },
     136                 :            :   { "T", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
     137                 :            :   PROP_NO_PROP };
     138                 :            : struct define_t ifile::cirdef =
     139                 :            :   { "Ifile", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };

Generated by: LCOV version 1.11