1 /*----------------------------------------------------------------------------
2                        data.h (definitions of data object)
3                        This file is a part of topaz systems
4                   Copyright: Hisao Kawaura, All rights reserved
5                                    1997 - 98
6 
7 
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12 
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17 
18     You should have received a copy of the GNU General Public License
19     along with this program; if not, write to the Free Software
20     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 
22 ----------------------------------------------------------------------------*/
23 
24 #if !defined(__data_h)
25 #define __data_h
26 
27 #include <stdio.h>
28 
29 #include "plobj.h"
30 #include <string>
31 #include "col.h"
32 #include "vect.h"
33 #include "vectdefs.h"
34 
35 /* marker style */
36 #define MARKER_NULL          0
37 #define MARKER_SQUARE        1
38 #define MARKER_TRIANGLE      2
39 #define MARKER_REVTRIANGLE   3
40 #define MARKER_DIAMOND       4
41 #define MARKER_CIRCLE        5
42 #define MARKER_CROSS         6
43 #define MARKER_DCROSS        7
44 #define MARKER_VAREA         8
45 #define MARKER_HAREA         9
46 #define MARKER_VBAR          10
47 #define MARKER_HBAR          11
48 #define MARKER_VSTEP         12
49 #define MARKER_HSTEP         13
50 #define MARKER_VBAR2         14
51 #define MARKER_HBAR2         15
52 
53 /* action of reading comment line */
54 #define COMMENT_ABORT        0
55 #define COMMENT_IGNORE       1
56 #define COMMENT_SEPARTION    2
57 
58 /* data search path */
59 #define PATH_ABSOLUTE        0
60 #define PATH_RELATIVE        1
61 
62 /* data interpolation */
63 #define INTER_POLYLINE           0
64 #define INTER_CLOSEDPOLYLINE     1
65 #define INTER_SPLINE             2
66 #define INTER_PSPLINE            3
67 #define INTER_CLOSEDPSPLINE      4
68 #define INTER_BSPLINE            5
69 #define INTER_CLOSEDBSPLINE      6
70 
71 /* dataelement status*/
72 #define DATA_NORMAL               0
73 #define DATA_INVALID              2
74 #define DATA_IGNORE               4
75 
76 /* maxreadline */
77 #define MAXREADLINE             2000;
78 
79 /* mscaling */
80 #define MSCALING_LINEAR          0
81 #define MSCALING_LOG             1
82 #define MSCALING_INV             2
83 
84 
85 class dataelement
86 {
87  public:
dataelement()88   dataelement(){data = 0; status = DATA_NORMAL;}
dataelement(double d,int s)89   dataelement(double d, int s){data = d; status = s;}
~dataelement()90   ~dataelement(){;}
91 
92   double data;
93   int    status;
94 
95   int operator == (const dataelement& de ) const;
96   dataelement& operator =(const dataelement& de);
97 };
98 
99 inline int dataelement::operator == ( const dataelement& de ) const
100 {
101         return this == &de;
102 }
103 
104 inline dataelement& dataelement::operator =(const dataelement& de)
105 {
106         data                    = de.data;
107         status                  = de.status;
108 
109         return *this;
110 }
111 
112 typedef vect<dataelement> earray;
113 /* typedef vect<earray> eearray; */
114 
115 class data: public plobj
116 {
117  public:
118   data();
119   ~data();
120   data& operator = (const data& dat);
121   bool ispatternequal(data* dat1, data* dat2);
122 
123   bool get(std::string* member,  tokenbuff* outvalue);
124   bool set(std::string* member,  std::string* setvalue);
125   bool exec(std::string* function, buffarray *argument, tokenbuff* outvalue);
126   bool paint(bool flag, FILE *f);
127 
128   /* plot style */
129   int id;
130   std::string *label;
131   int selected;
132   bool virgin;
133   bool display;
134   bool trans_x;
135   std::string *format_x;
136   bool trans_y;
137   std::string *format_y;
138   Capcolor linecolor, markeredgecolor, markerbodycolor;
139   Caplinestyle linestyle, markeredgestyle;
140   Capfillstyle markerbodyfillstyle;
141   int interpolate;
142   int interpolatediv;
143   int markerstyle;
144   bool markercenterdot;
145   int markersize;
146   bool clipping;
147   int refaxis_x;
148   int refaxis_y;
149   double basevalue;
150 
151   /* memory data */
152   double m_start;
153   double m_end;
154   int    m_div;
155   int    m_scaling;
156 
157   /* data read / write  */
158   bool readdata(FILE *fp);
159   bool writedata(FILE *fp);
160   bool appendoriginaldata(FILE *fp, int dataid);
161   void gettmpdataname(std::string* file);
162 
163   /* read data */
164   int col_x, col_y, col_xmin, col_xmax, col_ymin, col_ymax;
165   int readstart, readend, skip;
166   int commentlineaction;
167   bool bar_x, bar_y;
168   int datasearchpath;
169   bool extradatadispflag[99];
170   std::string *extradata;
171 
172   /* data */
173   earray *x, *y, *xmax, *xmin, *ymax, *ymin;
174   earray *extra[99];
175   double bound_xmin, bound_xmax, bound_ymin, bound_ymax;
176   char filename[1000];
177   bool isfiledata;
178   std::string *info;
179 
180 
181   bool loaddata();
182   bool loaddataproc(FILE *fp);
183   bool setrefpath(char *refpath);
184   bool restoreabspath(char *refpath);
185   bool extradataformat(const char *s, bool CheckMode);
186   void drawplot(int flag, FILE* f);
187   void drawmark(int flag, FILE* f, int x,int y, intpointarray *ia);
188   bool ExecLinearSQ(int fittingCurve, bool Fixed, double fixed_x, double fixed_y, int startline, int endline
189 		    , std::string* outfnstr, std::string *infostr);
190   bool UserFuncs(data *dat, int Ndata, double *a, int na, int Npara);
191   bool MarqSetPara(data *dat, int Ndata, double *a, int Na, int *list,
192 		   int Npara, double **alpha, double *beta, double *X2);
193   bool ExecMarquadt(data *dat, int Ndata, double *a, int *list,
194 		    int Npara, double init_chisq, double *out_chisq);
195   bool OutMar(int StartLine, int EndLine, std::string* func, buffarray* ini, buffarray* dydA, double seido,
196 	      std::string* outfn, std::string* info);
197   void createfunction(std::string *in, std::string *out);
198 
199 };
200 
201 #endif
202 
203 
204 
205 
206 
207 
208 
209 
210