00001
00002
00003
00004 #ifndef FITYK__API__H__
00005 #define FITYK__API__H__
00006
00007 #ifndef __cplusplus
00008 #error "This library does not have C API."
00009 #endif
00010
00011
00012 #ifdef _MSC_VER
00013
00014 #pragma warning( disable : 4290 )
00015 #endif
00016
00017 #include <string>
00018 #include <vector>
00019 #include <cstdio>
00020 #include <stdexcept>
00021 class Ftk;
00022
00023
00024 #define USE_LONG_DOUBLE 0
00025 #if USE_LONG_DOUBLE
00026 typedef long double realt;
00027 #define REALT_LENGTH_MOD "L"
00028 #else
00029 typedef double realt;
00030 #define REALT_LENGTH_MOD ""
00031 #endif
00032
00033
00034
00035
00036
00037
00038 namespace fityk
00039 {
00040
00041
00042 struct ExecuteError : public std::runtime_error
00043 {
00044 ExecuteError(const std::string& msg) : runtime_error(msg) {}
00045 };
00046
00047
00048 struct SyntaxError : public std::invalid_argument
00049 {
00050 SyntaxError(const std::string& msg="") : invalid_argument(msg) {}
00051 };
00052
00053
00054
00055 struct ExitRequestedException : std::exception
00056 {
00057 };
00058
00059
00060 struct Point
00061 {
00062 realt x, y, sigma;
00063 bool is_active;
00064
00065 Point();
00066 Point(realt x_, realt y_);
00067 Point(realt x_, realt y_, realt sigma_);
00068 std::string str() const;
00069 };
00070 inline bool operator< (Point const& p, Point const& q) { return p.x < q.x; }
00071
00072
00073 typedef void t_show_message(std::string const& s);
00074
00075
00076 const int all_datasets=-1;
00077
00078
00079
00080 class Fityk
00081 {
00082 public:
00083
00084 Fityk();
00085 Fityk(Ftk* F);
00086 ~Fityk();
00087
00088
00089
00090
00091
00092 void execute(std::string const& s) throw(SyntaxError, ExecuteError,
00093 ExitRequestedException);
00094
00095
00096 void load_data(int dataset,
00097 std::vector<realt> const& x,
00098 std::vector<realt> const& y,
00099 std::vector<realt> const& sigma,
00100 std::string const& title="") throw(ExecuteError);
00101
00102
00103 void add_point(realt x, realt y, realt sigma, int dataset=0)
00104 throw(ExecuteError);
00105
00106
00107
00108
00109
00110
00111
00112 void set_throws(bool state) { throws_ = state; }
00113
00114
00115 bool get_throws() const { return throws_; }
00116
00117
00118
00119 std::string const& last_error() const { return last_error_; }
00120
00121
00122 void clear_last_error() { last_error_.clear(); }
00123
00124
00125
00126
00127
00128
00129
00130 void set_show_message(t_show_message *func);
00131
00132
00133 void redir_messages(std::FILE *stream);
00134
00135
00136 void out(std::string const& s) const;
00137
00138
00139
00140
00141
00142
00143
00144
00145 std::string get_info(std::string const& s, int dataset=0)
00146 throw(SyntaxError, ExecuteError);
00147
00148
00149 realt calculate_expr(std::string const& s, int dataset=0)
00150 throw(SyntaxError, ExecuteError);
00151
00152
00153 int get_dataset_count();
00154
00155
00156 std::vector<Point> const& get_data(int dataset=0) throw(ExecuteError);
00157
00158
00159 realt get_model_value(realt x, int dataset=0) throw(ExecuteError);
00160
00161
00162 std::vector<realt>
00163 get_model_vector(std::vector<realt> const& x, int dataset=0)
00164 throw(ExecuteError);
00165
00166
00167
00168
00169 int get_variable_nr(std::string const& name) throw(ExecuteError);
00170
00171
00172
00173
00174
00175
00176
00177 realt get_wssr(int dataset=all_datasets) throw(ExecuteError);
00178
00179
00180 realt get_ssr(int dataset=all_datasets) throw(ExecuteError);
00181
00182
00183 realt get_rsquared(int dataset=all_datasets) throw(ExecuteError);
00184
00185
00186 int get_dof(int dataset=all_datasets) throw(ExecuteError);
00187
00188
00189
00190
00191 std::vector<std::vector<realt> >
00192 get_covariance_matrix(int dataset=all_datasets) throw(ExecuteError);
00193
00194
00195 private:
00196 Ftk *ftk_;
00197 bool throws_, owns_;
00198 std::string last_error_;
00199 };
00200
00201 }
00202
00203 #endif
00204