Project

General

Profile

Statistics
| Branch: | Revision:

root / src / scave / diffquot.cc @ a3be1d55

History | View | Annotate | Download (1.94 KB)

1 01873262 Georg Kunz
//=========================================================================
2
//  DIFFQUOT.CC - part of
3
//                  OMNeT++/OMNEST
4
//           Discrete System Simulation in C++
5
//
6
//  Author: Andras Varga
7
//
8
//=========================================================================
9
10
/*--------------------------------------------------------------*
11
  Copyright (C) 2005-2008 Andras Varga
12

13
  This file is distributed WITHOUT ANY WARRANTY. See the file
14
  `license' for details on this and other legal matters.
15
*--------------------------------------------------------------*/
16
17
#include "channel.h"
18
#include "diffquot.h"
19
20
USING_NAMESPACE
21
22
23
DifferenceQuotientNode::DifferenceQuotientNode()
24
{
25
    firstRead = false;
26
}
27
28
bool DifferenceQuotientNode::isReady() const
29
{
30
    return in()->length() > 0;
31
}
32
33
void DifferenceQuotientNode::process()
34
{
35
    Datum r, o;
36
37
    if (!firstRead)
38
    {
39
        in()->read(&l, 1);
40
        firstRead = true;
41
    }
42
43
    do {
44
        in()->read(&r, 1);
45
        // Make sure that the second values has a later time value
46
        if (r.x > l.x)
47
        {
48
            o.x = l.x;
49
            o.y = (r.y - l.y) / (r.x - l.x);
50
            out()->write(&o,1);
51
            l = r;
52
        }
53
    }
54
    while (in()->length() > 0);
55
}
56
57
//-----
58
59
const char *DifferenceQuotientNodeType::getDescription() const
60
{
61
    return "Calculates the difference quotient of every value and the subsequent one:\n"
62
           "yout[k] = (y[k+1]-y[k]) / (t[k+1]-t[k])";
63
}
64
65
void DifferenceQuotientNodeType::getAttributes(StringMap& attrs) const
66
{
67
}
68
69
void DifferenceQuotientNodeType::getAttrDefaults(StringMap& attrs) const
70
{
71
}
72
73
Node *DifferenceQuotientNodeType::create(DataflowManager *mgr, StringMap& attrs) const
74
{
75
    checkAttrNames(attrs);
76
77
    Node *node = new DifferenceQuotientNode();
78
    node->setNodeType(this);
79
    mgr->addNode(node);
80
    return node;
81
}
82
83
void DifferenceQuotientNodeType::mapVectorAttributes(/*inout*/StringMap &attrs) const
84
{
85
    attrs["type"] = "double";
86
}