My Project
0.0.16
QUCS Mapping
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
DownLoad
QUCS-src
qucs-0.0.16
qucs-core
src
components
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: ifile.cpp 1825 2011-03-11 20:42:14Z ela $
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
// Constructor creates ifile object in memory.
37
ifile::ifile () :
circuit
(2) {
38
type =
CIR_IFILE
;
39
setISource (
true
);
40
interpolType = dataType = 0;
41
data
= NULL;
42
inter = NULL;
43
}
44
45
// Destructor deletes ifile object from memory.
46
ifile::~ifile
() {
47
if
(data)
delete
data;
48
if
(inter)
delete
inter;
49
}
50
51
void
ifile::prepare
(
void
) {
52
53
// check type of interpolator
54
char
*
type
=
getPropertyString
(
"Interpolator"
);
55
if
(!strcmp (type,
"linear"
)) {
56
interpolType =
INTERPOL_LINEAR
;
57
}
else
if
(!strcmp (type,
"cubic"
)) {
58
interpolType =
INTERPOL_CUBIC
;
59
}
else
if
(!strcmp (type,
"hold"
)) {
60
interpolType =
INTERPOL_HOLD
;
61
}
62
63
// check type of repetition
64
type =
getPropertyString
(
"Repeat"
);
65
if
(!strcmp (type,
"no"
)) {
66
// rectangular data
67
dataType =
REPEAT_NO
;
68
}
else
if
(!strcmp (type,
"yes"
)) {
69
// polar data
70
dataType =
REPEAT_YES
;
71
}
72
73
// load file with samples
74
char
* file =
getPropertyString
(
"File"
);
75
if
(data == NULL) {
76
if
(strlen (file) > 4 && !strcasecmp (&file[strlen (file) - 4],
".dat"
))
77
data =
dataset::load
(file);
78
else
79
data =
dataset::load_csv
(file);
80
if
(data != NULL) {
81
// check number of variables / dependencies defined by that file
82
if
(data->
countVariables
() != 1 || data->
countDependencies
() != 1) {
83
logprint
(
LOG_ERROR
,
"ERROR: file `%s' must have time as an "
84
"independent and the current source samples as dependents\n"
,
85
file);
86
return
;
87
}
88
vector
* is = data->
getVariables
();
// current
89
vector
* ts = data->
getDependencies
();
// time
90
inter =
new
interpolator
();
91
inter->
rvectors
(is, ts);
92
inter->
prepare
(interpolType, dataType);
93
}
94
}
95
}
96
97
void
ifile::initSP
(
void
) {
98
allocMatrixS
();
99
setS
(
NODE_1
,
NODE_1
, 1.0);
100
setS
(
NODE_1
,
NODE_2
, 0.0);
101
setS
(
NODE_2
,
NODE_1
, 0.0);
102
setS
(
NODE_2
,
NODE_2
, 1.0);
103
}
104
105
void
ifile::initDC
(
void
) {
106
allocMatrixMNA
();
107
prepare
();
108
}
109
110
void
ifile::initAC
(
void
) {
111
initDC
();
112
}
113
114
void
ifile::initTR
(
void
) {
115
initDC
();
116
}
117
118
void
ifile::calcTR
(nr_double_t
t
) {
119
nr_double_t
G
=
getPropertyDouble
(
"G"
);
120
nr_double_t
T
=
getPropertyDouble
(
"T"
);
121
nr_double_t
i
= inter->
rinterpolate
(t - T);
122
setI
(
NODE_1
, +G * i);
setI
(
NODE_2
, -G * i);
123
}
124
125
// properties
126
PROP_REQ
[] = {
127
{
"File"
,
PROP_STR
, {
PROP_NO_VAL
,
"ifile.dat"
},
PROP_NO_RANGE
},
128
PROP_NO_PROP
};
129
PROP_OPT
[] = {
130
{
"Interpolator"
,
PROP_STR
, {
PROP_NO_VAL
,
"linear"
},
131
PROP_RNG_STR3
(
"hold"
,
"linear"
,
"cubic"
) },
132
{
"Repeat"
,
PROP_STR
, {
PROP_NO_VAL
,
"no"
},
PROP_RNG_YESNO
},
133
{
"G"
,
PROP_REAL
, { 1,
PROP_NO_STR
},
PROP_NO_RANGE
},
134
{
"T"
,
PROP_REAL
, { 0,
PROP_NO_STR
},
PROP_POS_RANGE
},
135
PROP_NO_PROP
};
136
struct
define_t
ifile
::cirdef =
137
{
"Ifile"
, 2,
PROP_COMPONENT
,
PROP_NO_SUBSTRATE
,
PROP_LINEAR
,
PROP_DEF
};
Generated on Tue Dec 25 2012 14:30:39 for My Project by
1.8.2