LCOV - code coverage report
Current view: top level - src/components - vfile.cpp (source / functions) Hit Total Coverage
Test: qucs-core-0.0.19 Code Coverage Lines: 0 65 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 72 0.0 %

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

Generated by: LCOV version 1.11