OSDN Git Service

abbf51ce10f5e03bd161a2b776d59d825357fb62
[cueplot/cueplot.git] / src / command / Fit.cpp
1 /*
2  * Cueplot: a GUI front-end to gnuplot
3  * Copyright (C) 2007, 2008 Muneyuki Noguchi
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation, 
17  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19 #include "Fit.h"
20
21 const double Fit::DEFAULT_FIT_LIMIT = 1e-5;
22
23 Fit::Fit() : functionName_("f(x)"),
24         fitLimit_(DEFAULT_FIT_LIMIT), fitMaxIter_(DEFAULT_FIT_MAX_ITER)
25 {
26 }
27
28 void Fit::setRange(const FitRange &range)
29 {
30         range_ = range;
31 }
32
33 const FitRange &Fit::range() const
34 {
35         return range_;
36 }
37
38 void Fit::setFunctionName(const QString &name)
39 {
40         functionName_ = name;
41 }
42
43 const QString &Fit::functionName() const
44 {
45         return functionName_;
46 }
47
48 void Fit::setFunction(const QString &function)
49 {
50         function_ = function;
51 }
52
53 const QString &Fit::function() const
54 {
55         return function_;
56 }
57
58 void Fit::setDataFile(const QString &file)
59 {
60         dataFile_ = file;
61 }
62
63 const QString &Fit::dataFile() const
64 {
65         return dataFile_;
66 }
67
68 void Fit::setDataFileModifier(const FitModifier &mod)
69 {
70         dataFileModifier_ = mod;
71 }
72
73 const FitModifier &Fit::dataFileModifier() const
74 {
75         return dataFileModifier_;
76 }
77
78 void Fit::setParameterFile(bool isFile)
79 {
80         isParameterFile_ = isFile;
81 }
82
83 bool Fit::isParameterFile() const
84 {
85         return isParameterFile_;
86 }
87
88 void Fit::setParameterFile(const QString &file)
89 {
90         parameterFile_ = file;
91 }
92
93 const QString &Fit::parameterFile() const
94 {
95         return parameterFile_;
96 }
97
98 void Fit::setVariable(const QStringList &var)
99 {
100         variable_ = var;
101 }
102
103 const QStringList &Fit::variable() const
104 {
105         return variable_;
106 }
107
108 void Fit::setFitLimit(double limit)
109 {
110         fitLimit_ = limit;
111 }
112
113 double Fit::fitLimit() const
114 {
115         return fitLimit_;
116 }
117
118 void Fit::setFitMaxIter(int iter)
119 {
120         fitMaxIter_ = iter;
121 }
122
123 int Fit::fitMaxIter() const
124 {
125         return fitMaxIter_;
126 }
127
128 QString Fit::command() const
129 {
130         QStringList commandList;
131         if (fitLimit_ != DEFAULT_FIT_LIMIT) {
132                 commandList << "FIT_LIMIT = " + QString::number(fitLimit_);
133         }
134         if (fitMaxIter_ != DEFAULT_FIT_MAX_ITER) {
135                 commandList << "FIT_MAXITER = " + QString::number(fitMaxIter_);
136         }
137         commandList << functionName_ + '=' + function_;
138         QString str = "fit " + range_.option() + ' ' + functionName_ + " '" 
139                 + dataFile_ + "' " + dataFileModifier_.option() + " via ";
140         if (isParameterFile_) {
141                 str += '\'' + parameterFile_ + '\'';
142         } else {
143                 str += variable_.join(",");
144         }
145         commandList << str;
146         return commandList.join("\n");
147 }