Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ifile.cpp
Go to the documentation of this file.
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 ifile::ifile () : circuit (2) {
40  type = CIR_IFILE;
41  setISource (true);
42  interpolType = dataType = 0;
43  data = NULL;
44  inter = NULL;
45 }
46 
47 // Destructor deletes ifile object from memory.
49  if (data) delete data;
50  if (inter) delete inter;
51 }
52 
53 void ifile::prepare (void) {
54 
55  // check type of interpolator
56  char * type = getPropertyString ("Interpolator");
57  if (!strcmp (type, "linear")) {
59  } else if (!strcmp (type, "cubic")) {
61  } else if (!strcmp (type, "hold")) {
63  }
64 
65  // check type of repetition
66  type = getPropertyString ("Repeat");
67  if (!strcmp (type, "no")) {
68  // rectangular data
70  } else if (!strcmp (type, "yes")) {
71  // polar data
73  }
74 
75  // load file with samples
76  char * file = getPropertyString ("File");
77  if (data == NULL) {
78  if (strlen (file) > 4 && !strcasecmp (&file[strlen (file) - 4], ".dat"))
79  data = dataset::load (file);
80  else
81  data = dataset::load_csv (file);
82  if (data != NULL) {
83  // check number of variables / dependencies defined by that file
84  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  file);
88  return;
89  }
90  qucs::vector * is = data->getVariables(); // current
91  qucs::vector * ts = data->getDependencies(); // time
92  inter = new interpolator ();
93  inter->rvectors (is, ts);
95  }
96  }
97 }
98 
99 void ifile::initSP (void) {
100  allocMatrixS ();
101  setS (NODE_1, NODE_1, 1.0);
102  setS (NODE_1, NODE_2, 0.0);
103  setS (NODE_2, NODE_1, 0.0);
104  setS (NODE_2, NODE_2, 1.0);
105 }
106 
107 void ifile::initDC (void) {
108  allocMatrixMNA ();
109  prepare ();
110 }
111 
112 void ifile::initAC (void) {
113  initDC ();
114 }
115 
116 void ifile::initTR (void) {
117  initDC ();
118 }
119 
120 void ifile::calcTR (nr_double_t t) {
121  nr_double_t G = getPropertyDouble ("G");
122  nr_double_t T = getPropertyDouble ("T");
123  nr_double_t i = inter->rinterpolate (t - T);
124  setI (NODE_1, +G * i); setI (NODE_2, -G * i);
125 }
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 =
#define PROP_POS_RANGE
Definition: netdefs.h:129
#define REPEAT_NO
Definition: interpolator.h:33
~ifile()
Definition: ifile.cpp:48
void prepare(int, int, int domain=DATA_RECTANGULAR)
#define NODE_2
Definition: circuit.h:35
qucs::vector * getVariables(void)
Definition: dataset.h:63
void setISource(bool i)
Definition: circuit.h:194
#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
#define PROP_NO_PROP
Definition: netdefs.h:122
#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
#define PROP_LINEAR
Definition: netdefs.h:120
i
Definition: parse_mdl.y:516
PROP_OPT[]
Definition: ifile.cpp:131
#define INTERPOL_HOLD
Definition: interpolator.h:31
#define INTERPOL_LINEAR
Definition: interpolator.h:29
#define INTERPOL_CUBIC
Definition: interpolator.h:30
PROP_REQ[]
Definition: ifile.cpp:128
#define PROP_COMPONENT
Definition: netdefs.h:116
void prepare(void)
Definition: ifile.cpp:53
int interpolType
Definition: ifile.h:48
Definition: ifile.cpp:138
void setI(int, nr_complex_t)
Definition: circuit.cpp:397
void initTR(void)
Definition: ifile.cpp:116
PROP_NO_SUBSTRATE
Definition: ifile.cpp:139
void initAC(void)
Definition: ifile.cpp:112
void allocMatrixMNA(void)
Definition: circuit.cpp:267
qucs::dataset * data
Definition: ifile.h:46
#define PROP_STR
Definition: netdefs.h:175
void initDC(void)
Definition: ifile.cpp:107
int dataType
Definition: ifile.h:47
#define NODE_1
Definition: circuit.h:34
#define LOG_ERROR
Definition: logging.h:28
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
#define PROP_NO_VAL
Definition: netdefs.h:124
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: ifile.cpp:99
#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 calcTR(nr_double_t)
Definition: ifile.cpp:120
void logprint(int level, const char *format,...)
Definition: logging.c:37
qucs::interpolator * inter
Definition: ifile.h:49
int countDependencies(void)
Definition: dataset.cpp:309
void rvectors(qucs::vector *, qucs::vector *)
data
Definition: parse_citi.y:117