1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
// Copyright (C) 2009, 2010, 2011, 2013 D. V. Wiebe
//
///////////////////////////////////////////////////////////////////////////
//
// This file is part of the GetData project.
//
// GetData is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the
// Free Software Foundation; either version 2.1 of the License, or (at your
// option) any later version.
//
// GetData is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
// License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with GetData; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
#include "internal.h"
using namespace GetData;
PolynomEntry::PolynomEntry(const char* field_code, int poly_ord,
const char* in_field, double* a, int fragment_index) : Entry()
{
int i;
E.field = strdup(field_code);
E.field_type = GD_POLYNOM_ENTRY;
E.u.polynom.poly_ord = poly_ord;
E.fragment_index = fragment_index;
E.flags = 0;
E.in_fields[0] = strdup(in_field);
for (i = 0; i <= poly_ord; ++i)
E.u.polynom.a[i] = a[i];
}
PolynomEntry::PolynomEntry(const char* field_code, int poly_ord,
const char* in_field, std::complex<double>* ca, int fragment_index) :
Entry()
{
int i;
E.field = strdup(field_code);
E.field_type = GD_POLYNOM_ENTRY;
E.u.polynom.poly_ord = poly_ord;
E.fragment_index = fragment_index;
E.flags = GD_EN_COMPSCAL;
E.in_fields[0] = strdup(in_field);
for (i = 0; i <= poly_ord; ++i) {
E.u.polynom.ca[i][0] = ca[i].real();
E.u.polynom.ca[i][1] = ca[i].imag();
}
}
int PolynomEntry::SetInput(const char* field)
{
char* ptr = strdup(field);
if (ptr == NULL)
return -1;
free(E.in_fields[0]);
E.in_fields[0] = ptr;
if (D != NULL)
return gd_alter_entry(D->D, E.field, &E, 0);
return 0;
}
int PolynomEntry::SetCoefficient(double coeff, int index)
{
if (index < 0 || index > GD_MAX_POLYORD)
return -1;
E.u.polynom.ca[index][0] = E.u.polynom.a[index] = coeff;
E.u.polynom.ca[index][1] = 0;
if (D != NULL)
return gd_alter_entry(D->D, E.field, &E, 0);
return 0;
}
int PolynomEntry::SetCoefficient(const char *scale, int index)
{
int r = 0;
if (index < 0 || index > GD_MAX_POLYORD)
return -1;
SetScalar(index, scale);
if (D != NULL) {
r = gd_alter_entry(D->D, E.field, &E, 0);
if (!r) {
r = gd_get_constant(D->D, scale, GD_COMPLEX128, E.u.polynom.ca + index);
E.u.polynom.a[index] = E.u.polynom.ca[index][0];
}
}
return r;
}
int PolynomEntry::SetCoefficient(std::complex<double> coeff, int index)
{
if (index < 0 || index > GD_MAX_POLYORD)
return -1;
E.u.polynom.a[index] = E.u.polynom.ca[index][0] = coeff.real();
E.u.polynom.ca[index][1] = coeff.imag();
E.flags = GD_EN_COMPSCAL;
if (D != NULL)
return gd_alter_entry(D->D, E.field, &E, 0);
return 0;
}
int PolynomEntry::SetPolyOrd(int poly_ord)
{
int old_n = E.u.polynom.poly_ord;
if (poly_ord < 2 || poly_ord > GD_MAX_POLYORD)
return -1;
if (poly_ord > old_n) {
int i;
for (i = old_n + 1; i <= poly_ord; ++i)
E.u.polynom.a[i] = 0;
}
E.u.polynom.poly_ord = poly_ord;
if (D != NULL)
return gd_alter_entry(D->D, E.field, &E, 0);
return 0;
}
const char *PolynomEntry::Scalar(int index) const
{
if (index < 0 || index > E.u.polynom.poly_ord)
return NULL;
return E.scalar[index];
}
int PolynomEntry::ScalarIndex(int index) const
{
if (index < 0 || index > E.u.polynom.poly_ord)
return 0;
return E.scalar_ind[index];
}
|