Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vfile.cpp
Go to the documentation of this file.
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 vfile::vfile () : circuit (2) {
41  type = CIR_VFILE;
42  setVSource (true);
44  interpolType = dataType = 0;
45  data = NULL;
46  inter = NULL;
47 }
48 
49 // Destructor deletes vfile object from memory.
51  if (data) delete data;
52  if (inter) delete inter;
53 }
54 
55 void vfile::prepare (void) {
56 
57  // check type of interpolator
58  char * type = getPropertyString ("Interpolator");
59  if (!strcmp (type, "linear")) {
61  } else if (!strcmp (type, "cubic")) {
63  } else if (!strcmp (type, "hold")) {
65  }
66 
67  // check type of repetition
68  type = getPropertyString ("Repeat");
69  if (!strcmp (type, "no")) {
70  // rectangular data
72  } else if (!strcmp (type, "yes")) {
73  // polar data
75  }
76 
77  // load file with samples
78  char * file = getPropertyString ("File");
79  if (data == NULL) {
80  if (strlen (file) > 4 && !strcasecmp (&file[strlen (file) - 4], ".dat"))
81  data = dataset::load (file);
82  else
83  data = dataset::load_csv (file);
84  if (data != NULL) {
85  // check number of variables / dependencies defined by that file
86  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  file);
90  return;
91  }
92  qucs::vector * vs = data->getVariables(); // voltage
93  qucs::vector * ts = data->getDependencies(); // time
94  inter = new interpolator ();
95  inter->rvectors (vs, ts);
97  }
98  }
99 }
100 
101 void vfile::initSP (void) {
102  allocMatrixS ();
103  setS (NODE_1, NODE_1, 0.0);
104  setS (NODE_1, NODE_2, 1.0);
105  setS (NODE_2, NODE_1, 1.0);
106  setS (NODE_2, NODE_2, 0.0);
107 }
108 
109 void vfile::initDC (void) {
110  allocMatrixMNA ();
112  prepare ();
113  setE (VSRC_1, 0);
114 }
115 
116 void vfile::initAC (void) {
117  initDC ();
118  setE (VSRC_1, 0);
119 }
120 
121 void vfile::initTR (void) {
122  initDC ();
123 }
124 
125 void vfile::calcTR (nr_double_t t) {
126  nr_double_t G = getPropertyDouble ("G");
127  nr_double_t T = getPropertyDouble ("T");
128  nr_double_t u = inter->rinterpolate (t - T);
129  setE (VSRC_1, G * u);
130 }
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 =
#define PROP_POS_RANGE
Definition: netdefs.h:129
#define REPEAT_NO
Definition: interpolator.h:33
void prepare(int, int, int domain=DATA_RECTANGULAR)
#define NODE_2
Definition: circuit.h:35
qucs::vector * getVariables(void)
Definition: dataset.h:63
#define PROP_DEF
Definition: netdefs.h:189
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
#define PROP_REAL
Definition: netdefs.h:174
nr_double_t rinterpolate(nr_double_t)
t
Definition: parse_vcd.y:290
void initAC(void)
Definition: vfile.cpp:116
void calcTR(nr_double_t)
Definition: vfile.cpp:125
#define PROP_NO_PROP
Definition: netdefs.h:122
void setVoltageSources(int)
Definition: circuit.cpp:607
#define PROP_NO_RANGE
Definition: netdefs.h:126
int countVariables(void)
Definition: dataset.cpp:301
#define PROP_NO_STR
Definition: netdefs.h:125
#define REPEAT_YES
Definition: interpolator.h:34
void allocMatrixS(void)
Definition: circuit.cpp:251
qucs::dataset * data
Definition: vfile.h:47
#define PROP_LINEAR
Definition: netdefs.h:120
int dataType
Definition: vfile.h:48
void prepare(void)
Definition: vfile.cpp:55
#define VSRC_1
Definition: circuit.h:40
#define INTERPOL_HOLD
Definition: interpolator.h:31
#define INTERPOL_LINEAR
Definition: interpolator.h:29
#define INTERPOL_CUBIC
Definition: interpolator.h:30
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: vfile.cpp:101
#define PROP_COMPONENT
Definition: netdefs.h:116
void setE(int, nr_complex_t)
Definition: circuit.cpp:385
void setVSource(bool v)
Definition: circuit.h:192
qucs::interpolator * inter
Definition: vfile.h:50
PROP_REQ[]
Definition: vfile.cpp:133
void allocMatrixMNA(void)
Definition: circuit.cpp:267
PROP_OPT[]
Definition: vfile.cpp:136
Definition: vfile.cpp:143
#define PROP_STR
Definition: netdefs.h:175
#define NODE_1
Definition: circuit.h:34
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
~vfile()
Definition: vfile.cpp:50
#define LOG_ERROR
Definition: logging.h:28
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
void initTR(void)
Definition: vfile.cpp:121
#define PROP_NO_VAL
Definition: netdefs.h:124
#define PROP_RNG_STR3(s1, s2, s3)
Definition: netdefs.h:147
qucs::vector * getDependencies(void)
Definition: dataset.h:62
#define PROP_RNG_YESNO
Definition: netdefs.h:158
char * getPropertyString(const char *)
Definition: object.cpp:159
void logprint(int level, const char *format,...)
Definition: logging.c:37
void initDC(void)
Definition: vfile.cpp:109
int countDependencies(void)
Definition: dataset.cpp:309
void rvectors(qucs::vector *, qucs::vector *)
int interpolType
Definition: vfile.h:49
#define PROP_NO_SUBSTRATE
Definition: netdefs.h:118
data
Definition: parse_citi.y:117