1 /*----------------------------------------------------------------------------
2                              data.cc (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 #include <stdio.h>
25 #include <stdlib.h>
26 #include <math.h>
27 #include <string.h>
28 #include <string>
29 #include "data.h"
30 #include "gdi.h"
31 #include "vectdefs.h"
32 #include "pointdefs.h"
33 #include "filepoint.h"
34 #include "graph.h"
35 #include "frame.h"
36 #include "topazvalues.h"
37 #include "convtxt.h"
38 #include "paths.h"
39 
40 extern void message(const char *msg);
41 extern void StyleLinePath(bool flag, doublepointarray *array, int no_of_point, int style, int width,
42 			  bool Clip, intrect *AxisRect, intrect *boundrect);
43 extern char *toshortfilename(char *in);
44 extern char confpath[1000];
45 extern char tmppath[1000];
46 extern char pid[100];
47 extern FileHandleArray *fhvuff;
48 extern bool genxdata(double start, double end, int div, int scaling, earray* outx, earray* outy);
49 extern int CalcFormulastring(char *s, double *n, int InitFormula, data* dat, int cellno, int seriesno, int Isminmax);
50 
data()51 data::data():plobj()
52 {
53   /* plot style */
54   version             = 2;
55   id                  = 0;
56   label               = new std::string("");
57   virgin              = true;
58   selected            = false;
59   display             = true;
60   trans_x             = false;
61   format_x            = new std::string("");
62   trans_y             = false;
63   format_y            = new std::string("");
64   linecolor.setblack();
65   markeredgecolor.setblack();
66   markerbodycolor.setwhite();
67   linestyle.init();
68   markeredgestyle.init();
69   markerbodyfillstyle.init();
70   interpolate         = INTER_POLYLINE;
71   interpolatediv      = 50;
72   markerstyle         = MARKER_SQUARE;
73   markercenterdot     = false;
74   markersize          = 100;
75   clipping            = true;
76   refaxis_x           = 0;
77   refaxis_y           = 1;
78   basevalue           = 0.0;
79   m_start              = 0.0;
80   m_end                = 10.0;
81   m_div                = 10;
82   m_scaling            = MSCALING_LINEAR;
83 
84   /* read data */
85   col_x               = 1;
86   col_y               = 2;
87   col_xmin            = 1;
88   col_xmax            = 1;
89   col_ymin            = 1;
90   col_ymax            = 1;
91   readstart           = 1;
92   readend             = -1;
93   skip                = 1;
94   commentlineaction   = COMMENT_ABORT;
95   bar_x               = false;
96   bar_y               = false;
97   datasearchpath      = PATH_RELATIVE;
98   for (int i = 0; i < 99; i++)
99     extradatadispflag[i] = false;
100   extradata           = new std::string("");
101 
102   /* data */
103   x                   = new earray;
104   y                   = new earray;
105   xmax                = new earray;
106   xmin                = new earray;
107   ymax                = new earray;
108   ymin                = new earray;;
109   for (int i = 0; i < 99; i++)
110     extra[i]          = new earray;
111   bound_xmin          = MAXDOUBLE;
112   bound_xmax          = -MAXDOUBLE;
113   bound_ymin          = MAXDOUBLE;
114   bound_ymax          = -MAXDOUBLE;
115   strcpy(filename, "");
116   isfiledata          = true;
117   info                = new std::string("");
118 }
119 
~data()120 data::~data()
121 {
122   delete label;
123 
124   /* plot style */
125   delete format_x;
126   delete format_y;
127 
128   /* read data */
129   delete extradata;
130 
131   /* data */
132   delete x;
133   delete y;
134   delete xmax;
135   delete xmin;
136   delete ymax;
137   delete ymin;
138   for (int i = 0; i < 99; i++)
139     delete extra[i];
140   delete info;
141 
142 }
143 
operator =(const data & da)144 data& data::operator = (const data&  da)
145 {
146 //  parent              = da.parent;
147 
148   /* plot style */
149 //  id                  = da.id;
150   version             = da.version;
151   virgin              = da.virgin;
152   selected            = da.selected;
153   display             = da.display;
154   trans_x             = da.trans_x;
155   *format_x           = *da.format_x;
156   trans_y             = da.trans_y;
157   *format_y           = *da.format_y;
158   linecolor           = da.linecolor;
159   markeredgecolor     = da.markeredgecolor;
160   markerbodycolor     = da.markerbodycolor;
161   linestyle           = da.linestyle;
162   markeredgestyle     = da.markeredgestyle;
163   markerbodyfillstyle = da.markerbodyfillstyle;
164   interpolate         = da.interpolate;
165   interpolatediv      = da.interpolatediv;
166   markerstyle         = da.markerstyle;
167   markercenterdot     = da.markercenterdot;
168   markersize          = da.markersize;
169   clipping            = da.clipping;
170   refaxis_x           = da.refaxis_x;
171   refaxis_y           = da.refaxis_y;
172   basevalue           = da.basevalue;
173   m_start              = da.m_start;
174   m_end                = da.m_end;
175   m_div                = da.m_div;
176   m_scaling            = da.m_scaling;
177 
178   // read data
179   col_x               = da.col_x;
180   col_y               = da.col_y;
181   col_xmin            = da.col_xmin;
182   col_xmax            = da.col_xmax;
183   col_ymin            = da.col_ymin;
184   col_ymax            = da.col_ymax;
185   readstart           = da.readstart;
186   readend             = da.readend;
187   skip                = da.skip;
188   commentlineaction   = da.commentlineaction;
189   bar_x               = da.bar_x;
190   bar_y               = da.bar_y;
191   datasearchpath      = da.datasearchpath;
192   for (int i = 0; i < 99; i++)
193     extradatadispflag[i] = da.extradatadispflag[i];
194   *extradata          = *da.extradata;
195 
196   x->setbuff(0);
197   for(int i = 0; i < da.x->getarraylength(); i++)
198     {
199       x->add(new dataelement);
200       (*x)[i] = (*da.x)[i];
201     }
202   y->setbuff(0);
203   for(int i = 0; i < da.y->getarraylength(); i++)
204     {
205       y->add(new dataelement);
206       (*y)[i] = (*da.y)[i];
207     }
208   xmin->setbuff(0);
209   for(int i = 0; i < da.xmin->getarraylength(); i++)
210     {
211       xmin->add(new dataelement);
212       (*xmin)[i] = (*da.xmin)[i];
213     }
214   xmax->setbuff(0);
215   for(int i = 0; i < da.xmax->getarraylength(); i++)
216     {
217       xmax->add(new dataelement);
218       (*xmax)[i] = (*da.xmax)[i];
219     }
220   ymin->setbuff(0);
221   for(int i = 0; i < da.ymin->getarraylength(); i++)
222     {
223       ymin->add(new dataelement);
224       (*ymin)[i] = (*da.ymin)[i];
225     }
226   ymax->setbuff(0);
227   for(int i = 0; i < da.ymax->getarraylength(); i++)
228     {
229       ymax->add(new dataelement);
230       (*ymax)[i] = (*da.ymax)[i];
231     }
232 
233   for (int i = 0; i < 99; i++)
234     {
235       extra[i]->setbuff(0);
236       for (int j = 0; j < da.extra[i]->getarraylength(); j++)
237 	{
238 	  extra[i]->add(new dataelement);
239 	  (*(extra[i]))[j] = (*(da.extra[i]))[j];
240 	}
241     }
242 
243   bound_xmin          = da.bound_xmin;
244   bound_xmax          = da.bound_xmax;
245   bound_ymin          = da.bound_ymin;
246   bound_ymax          = da.bound_ymax;
247   strcpy(filename, da.filename);
248 
249   isfiledata          = da.isfiledata;
250   *info               = *da.info;
251 
252   return *this;
253 }
254 
ispatternequal(data * dat1,data * dat2)255 bool data::ispatternequal(data* dat1, data* dat2)
256 {
257   return (
258 	  dat1->linecolor           == dat2->linecolor             &&
259 	  dat1->markeredgecolor     == dat2->markeredgecolor       &&
260 	  dat1->markerbodycolor     == dat2->markerbodycolor       &&
261 	  dat1->linestyle           == dat2->linestyle             &&
262 	  dat1->markeredgestyle     == dat2->markeredgestyle       &&
263 	  dat1->markerbodyfillstyle == dat2->markerbodyfillstyle   &&
264 	  dat1->markerstyle         == dat2->markerstyle           &&
265 	  dat1->markercenterdot     == dat2->markercenterdot       &&
266 	  dat1->markersize          == dat2->markersize
267 	  );
268 }
269 
270 
get(std::string * member,tokenbuff * outvalue)271 bool data::get(std::string* member, tokenbuff* outvalue)
272 {
273   std::string out, shrunk;
274   int iid;
275   char stemp[1000];
276   int itemp;
277   std::string temp_pre_formula;
278   double ftemp;
279   frame* fr = (frame *)parent;
280 
281   if (topobject(member, &out, &iid) == true)
282     {
283       if (out == std::string("id") && iid == -1)
284 	{
285 	  sprintf(stemp, "%d", id);
286 	  outvalue->value->add(stemp);
287 	  return true;
288 	}
289       else if (out == std::string("label") && iid == -1)
290 	{
291 	  outvalue->value->add(label->c_str());
292 	  return true;
293 	}
294       else if (out == std::string("selected") && iid == -1)
295 	{
296 	  sprintf(stemp, "%d", selected);
297 	  outvalue->value->add(stemp);
298 	  return true;
299 	}
300       else if (out == std::string("show") && iid == -1)
301 	{
302 	  sprintf(stemp, "%d", display);
303 	  outvalue->value->add(stemp);
304 	  return true;
305 	}
306       else if (out == std::string("virgin") && iid == -1)
307 	{
308 	  sprintf(stemp, "%d", virgin);
309 	  outvalue->value->add(stemp);
310 	  return true;
311 	}
312       else if (out == std::string("trans_x") && iid == -1)
313 	{
314 	  sprintf(stemp, "%d", trans_x);
315 	  outvalue->value->add(stemp);
316 	  return true;
317 	}
318       else if (out == std::string("format_x") && iid == -1)
319 	{
320 	  outvalue->value->add(format_x->c_str());
321 	  return true;
322 	}
323       else if (out == std::string("trans_y") && iid == -1)
324 	{
325 	  sprintf(stemp, "%d", trans_y);
326 	  outvalue->value->add(stemp);
327 	  return true;
328 	}
329       else if (out == std::string("format_y") && iid == -1)
330 	{
331 	  outvalue->value->add(format_y->c_str());
332 	  return true;
333 	}
334       else if (out == std::string("linecolor_red") && iid == -1)
335 	{
336 	  sprintf(stemp, "%u", linecolor.red);
337 	  outvalue->value->add(stemp);
338 	  return true;
339 	}
340       else if (out == std::string("linecolor_green") && iid == -1)
341 	{
342 	  sprintf(stemp, "%u", linecolor.green);
343 	  outvalue->value->add(stemp);
344 	  return true;
345 	}
346       else if (out == std::string("linecolor_blue") && iid == -1)
347 	{
348 	  sprintf(stemp, "%u", linecolor.blue);
349 	  outvalue->value->add(stemp);
350 	  return true;
351 	}
352       else if (out == std::string("markeredgecolor_red") && iid == -1)
353 	{
354 	  sprintf(stemp, "%u", markeredgecolor.red);
355 	  outvalue->value->add(stemp);
356 	  return true;
357 	}
358       else if (out == std::string("markeredgecolor_green") && iid == -1)
359 	{
360 	  sprintf(stemp, "%u", markeredgecolor.green);
361 	  outvalue->value->add(stemp);
362 	  return true;
363 	}
364       else if (out == std::string("markeredgecolor_blue") && iid == -1)
365 	{
366 	  sprintf(stemp, "%u", markeredgecolor.blue);
367 	  outvalue->value->add(stemp);
368 	  return true;
369 	}
370       else if (out == std::string("markerbodycolor_red") && iid == -1)
371 	{
372 	  sprintf(stemp, "%u", markerbodycolor.red);
373 	  outvalue->value->add(stemp);
374 	  return true;
375 	}
376       else if (out == std::string("markerbodycolor_green") && iid == -1)
377 	{
378 	  sprintf(stemp, "%u", markerbodycolor.green);
379 	  outvalue->value->add(stemp);
380 	  return true;
381 	}
382       else if (out == std::string("markerbodycolor_blue") && iid == -1)
383 	{
384 	  sprintf(stemp, "%u", markerbodycolor.blue);
385 	  outvalue->value->add(stemp);
386 	  return true;
387 	}
388       else if (out == std::string("linewidth") && iid == -1)
389 	{
390 	  sprintf(stemp, "%d", linestyle.width);
391 	  outvalue->value->add(stemp);
392 	  return true;
393 	}
394       else if (out == std::string("linecap") && iid == -1)
395 	{
396 	  sprintf(stemp, "%d", linestyle.cap);
397 	  outvalue->value->add(stemp);
398 	  return true;
399 	}
400       else if (out == std::string("linejoin") && iid == -1)
401 	{
402 	  sprintf(stemp, "%d", linestyle.join);
403 	  outvalue->value->add(stemp);
404 	  return true;
405 	}
406       else if (out == std::string("linestyle") && iid == -1)
407 	{
408 	  sprintf(stemp, "%d", linestyle.style);
409 	  outvalue->value->add(stemp);
410 	  return true;
411 	}
412       else if (out == std::string("markeredgewidth") && iid == -1)
413 	{
414 	  sprintf(stemp, "%d", markeredgestyle.width);
415 	  outvalue->value->add(stemp);
416 	  return true;
417 	}
418       else if (out == std::string("markeredgecap") && iid == -1)
419 	{
420 	  sprintf(stemp, "%d", markeredgestyle.cap);
421 	  outvalue->value->add(stemp);
422 	  return true;
423 	}
424       else if (out == std::string("markeredgejoin") && iid == -1)
425 	{
426 	  sprintf(stemp, "%d", markeredgestyle.join);
427 	  outvalue->value->add(stemp);
428 	  return true;
429 	}
430       else if (out == std::string("markeredgestyle") && iid == -1)
431 	{
432 	  sprintf(stemp, "%d", markeredgestyle.style);
433 	  outvalue->value->add(stemp);
434 	  return true;
435 	}
436       else if (out == std::string("markerfillstyle") && iid == -1)
437 	{
438 	  sprintf(stemp, "%d", markerbodyfillstyle.style);
439 	  outvalue->value->add(stemp);
440 	  return true;
441 	}
442       else if (out == std::string("markerfillrule") && iid == -1)
443 	{
444 	  sprintf(stemp, "%d", markerbodyfillstyle.fillrule);
445 	  outvalue->value->add(stemp);
446 	  return true;
447 	}
448       else if (out == std::string("interpolate") && iid == -1)
449 	{
450 	  sprintf(stemp, "%d", interpolate);
451 	  outvalue->value->add(stemp);
452 	  return true;
453 	}
454       else if (out == std::string("interpolatediv") && iid == -1)
455 	{
456 	  sprintf(stemp, "%d", interpolatediv);
457 	  outvalue->value->add(stemp);
458 	  return true;
459 	}
460       else if (out == std::string("markerstyle") && iid == -1)
461 	{
462 	  sprintf(stemp, "%d", markerstyle);
463 	  outvalue->value->add(stemp);
464 	  return true;
465 	}
466       else if (out == std::string("markercenterdot") && iid == -1)
467 	{
468 	  sprintf(stemp, "%d", markercenterdot);
469 	  outvalue->value->add(stemp);
470 	  return true;
471 	}
472       else if (out == std::string("markersize") && iid == -1)
473 	{
474 	  sprintf(stemp, "%d", markersize);
475 	  outvalue->value->add(stemp);
476 	  return true;
477 	}
478       else if (out == std::string("clipping") && iid == -1)
479 	{
480 	  sprintf(stemp, "%d", clipping);
481 	  outvalue->value->add(stemp);
482 	  return true;
483 	}
484       else if (out == std::string("refaxis_x") && iid == -1)
485 	{
486 	  sprintf(stemp, "%d", refaxis_x);
487 	  outvalue->value->add(stemp);
488 	  return true;
489 	}
490       else if (out == std::string("refaxis_y") && iid == -1)
491 	{
492 	  sprintf(stemp, "%d", refaxis_y);
493 	  outvalue->value->add(stemp);
494 	  return true;
495 	}
496       else if (out == std::string("basevalue") && iid == -1)
497 	{
498 	  sprintf(stemp, "%.15g", basevalue);
499 	  outvalue->value->add(stemp);
500 	  return true;
501 	}
502       else if (out == std::string("m_start") && iid == -1)
503 	{
504 	  sprintf(stemp, "%.15g", m_start);
505 	  outvalue->value->add(stemp);
506 	  return true;
507 	}
508       else if (out == std::string("m_end") && iid == -1)
509 	{
510 	  sprintf(stemp, "%.15g", m_end);
511 	  outvalue->value->add(stemp);
512 	  return true;
513 	}
514       else if (out == std::string("m_div") && iid == -1)
515 	{
516 	  sprintf(stemp, "%d", m_div);
517 	  outvalue->value->add(stemp);
518 	  return true;
519 	}
520       else if (out == std::string("m_scaling") && iid == -1)
521 	{
522 	  sprintf(stemp, "%d", m_scaling);
523 	  outvalue->value->add(stemp);
524 	  return true;
525 	}
526       else if (out == std::string("col_x") && iid == -1)
527 	{
528 	  sprintf(stemp, "%d", col_x);
529 	  outvalue->value->add(stemp);
530 	  return true;
531 	}
532       else if (out == std::string("col_xmin") && iid == -1)
533 	{
534 	  sprintf(stemp, "%d", col_xmin);
535 	  outvalue->value->add(stemp);
536 	  return true;
537 	}
538       else if (out == std::string("col_xmax") && iid == -1)
539 	{
540 	  sprintf(stemp, "%d", col_xmax);
541 	  outvalue->value->add(stemp);
542 	  return true;
543 	}
544       else if (out == std::string("col_y") && iid == -1)
545 	{
546 	  sprintf(stemp, "%d", col_y);
547 	  outvalue->value->add(stemp);
548 	  return true;
549 	}
550       else if (out == std::string("col_ymin") && iid == -1)
551 	{
552 	  sprintf(stemp, "%d", col_ymin);
553 	  outvalue->value->add(stemp);
554 	  return true;
555 	}
556       else if (out == std::string("col_ymax") && iid == -1)
557 	{
558 	  sprintf(stemp, "%d", col_ymax);
559 	  outvalue->value->add(stemp);
560 	  return true;
561 	}
562       else if (out == std::string("readstart") && iid == -1)
563 	{
564 	  sprintf(stemp, "%d", readstart);
565 	  outvalue->value->add(stemp);
566 	  return true;
567 	}
568       else if (out == std::string("readend") && iid == -1)
569 	{
570 	  sprintf(stemp, "%d", readend);
571 	  outvalue->value->add(stemp);
572 	  return true;
573 	}
574       else if (out == std::string("skip") && iid == -1)
575 	{
576 	  sprintf(stemp, "%d", skip);
577 	  outvalue->value->add(stemp);
578 	  return true;
579 	}
580       else if (out == std::string("commentlineaction") && iid == -1)
581 	{
582 	  sprintf(stemp, "%d", commentlineaction);
583 	  outvalue->value->add(stemp);
584 	  return true;
585 	}
586       else if (out == std::string("bar_x") && iid == -1)
587 	{
588 	  sprintf(stemp, "%d", bar_x);
589 	  outvalue->value->add(stemp);
590 	  return true;
591 	}
592       else if (out == std::string("bar_y") && iid == -1)
593 	{
594 	  sprintf(stemp, "%d", bar_y);
595 	  outvalue->value->add(stemp);
596 	  return true;
597 	}
598       else if (out == std::string("datasearchpath") && iid == -1)
599 	{
600 	  sprintf(stemp, "%d", datasearchpath);
601 	  outvalue->value->add(stemp);
602 	  return true;
603 	}
604       else if (out == std::string("extradatadispflag") && 1 <= iid && iid <= 99)
605 	{
606 	  sprintf(stemp, "%d", extradatadispflag[iid - 1]);
607 	  outvalue->value->add(stemp);
608 	  return true;
609 	}
610       else if (out == std::string("extradata") && iid == -1)
611 	{
612 	  sprintf(stemp, "%s", extradata->c_str());
613 	  outvalue->value->add(stemp);
614 	  return true;
615 	}
616       else if (out == std::string("X") && 0 <= iid)
617 	{
618 	  if (iid < x->getarraylength())
619 	    {
620 	      if (trans_x)
621 		temp_pre_formula = *format_x;
622 	      else
623 		temp_pre_formula = std::string("x");
624 
625 	      CalcFormulastring((char *)temp_pre_formula.c_str(), &ftemp, true ,this, 0, fr->getdataindex(id), 0);
626 	      CalcFormulastring((char *)temp_pre_formula.c_str(), &ftemp, false ,this, iid, fr->getdataindex(id), 0);
627 
628 	      sprintf(stemp, "%.15g", ftemp);
629 	      outvalue->value->add(stemp);
630 	      return true;
631 	    }
632 	  else
633 	    return false;
634 	}
635       else if (out == std::string("XMIN") && 0 <= iid)
636 	{
637 	  if (iid < xmin->getarraylength())
638 	    {
639 	      if (trans_x)
640 		temp_pre_formula = *format_x;
641 	      else
642 		temp_pre_formula = std::string("x");
643 
644 	      CalcFormulastring((char *)temp_pre_formula.c_str(), &ftemp, true ,this, 0, fr->getdataindex(id), 1);
645 	      CalcFormulastring((char *)temp_pre_formula.c_str(), &ftemp, false ,this, iid, fr->getdataindex(id), 1);
646 
647 	      sprintf(stemp, "%.15g", ftemp);
648 	      outvalue->value->add(stemp);
649 	      return true;
650 	    }
651 	  else
652 	    return false;
653 	}
654       else if (out == std::string("XMAX") && 0 <= iid)
655 	{
656 	  if (iid < xmax->getarraylength())
657 	    {
658 	      if (trans_x)
659 		temp_pre_formula = *format_x;
660 	      else
661 		temp_pre_formula = std::string("x");
662 
663 	      CalcFormulastring((char *)temp_pre_formula.c_str(), &ftemp, true ,this, 0, fr->getdataindex(id), 2);
664 	      CalcFormulastring((char *)temp_pre_formula.c_str(), &ftemp, false ,this, iid, fr->getdataindex(id), 2);
665 
666 	      sprintf(stemp, "%.15g", ftemp);
667 	      outvalue->value->add(stemp);
668 	      return true;
669 	    }
670 	  else
671 	    return false;
672 	}
673       else if (out == std::string("Y") && 0 <= iid)
674 	{
675 	  if (iid < y->getarraylength())
676 	    {
677 	      if (trans_y)
678 		temp_pre_formula = *format_y;
679 	      else
680 		temp_pre_formula = std::string("y");
681 
682 	      CalcFormulastring((char *)temp_pre_formula.c_str(), &ftemp, true ,this, 0, fr->getdataindex(id), 0);
683 	      CalcFormulastring((char *)temp_pre_formula.c_str(), &ftemp, false ,this, iid, fr->getdataindex(id), 0);
684 
685 	      sprintf(stemp, "%.15g", ftemp);
686 	      outvalue->value->add(stemp);
687 	      return true;
688 	    }
689 	  else
690 	    return false;
691 	}
692       else if (out == std::string("YMIN") && 0 <= iid)
693 	{
694 	  if (iid < ymin->getarraylength())
695 	    {
696 	      if (trans_y)
697 		temp_pre_formula = *format_y;
698 	      else
699 		temp_pre_formula = std::string("y");
700 
701 	      CalcFormulastring((char *)temp_pre_formula.c_str(), &ftemp, true ,this, 0, fr->getdataindex(id), 1);
702 	      CalcFormulastring((char *)temp_pre_formula.c_str(), &ftemp, false ,this, iid, fr->getdataindex(id), 1);
703 
704 	      sprintf(stemp, "%.15g", ftemp);
705 	      outvalue->value->add(stemp);
706 	      return true;
707 	    }
708 	  else
709 	    return false;
710 	}
711       else if (out == std::string("YMAX") && 0 <= iid)
712 	{
713 	  if (iid < ymax->getarraylength())
714 	    {
715 	      if (trans_y)
716 		temp_pre_formula = *format_y;
717 	      else
718 		temp_pre_formula = std::string("y");
719 
720 	      CalcFormulastring((char *)temp_pre_formula.c_str(), &ftemp, true ,this, 0, fr->getdataindex(id), 2);
721 	      CalcFormulastring((char *)temp_pre_formula.c_str(), &ftemp, false ,this, iid, fr->getdataindex(id), 2);
722 
723 	      sprintf(stemp, "%.15g", ftemp);
724 	      outvalue->value->add(stemp);
725 	      return true;
726 	    }
727 	  else
728 	    return false;
729 	}
730       else if (out == std::string("x") && 0 <= iid)
731 	{
732 	  if (iid < x->getarraylength())
733 	    {
734 	      sprintf(stemp, "%.15g", (*x)[iid].data);
735 	      outvalue->value->add(stemp);
736 	      return true;
737 	    }
738 	  else
739 	    return false;
740 	}
741       else if (out == std::string("xmin") && 0 <= iid)
742 	{
743 	  if (iid < xmin->getarraylength())
744 	    {
745 	      sprintf(stemp, "%.15g", (*xmin)[iid].data);
746 	      outvalue->value->add(stemp);
747 	      return true;
748 	    }
749 	  else
750 	    return false;
751 	}
752       else if (out == std::string("xmax") && 0 <= iid)
753 	{
754 	  if (iid < xmax->getarraylength())
755 	    {
756 	      sprintf(stemp, "%.15g", (*xmax)[iid].data);
757 	      outvalue->value->add(stemp);
758 	      return true;
759 	    }
760 	  else
761 	    return false;
762 	}
763       else if (out == std::string("y") && 0 <= iid)
764 	{
765 	  if (iid < y->getarraylength())
766 	    {
767 	      sprintf(stemp, "%.15g", (*y)[iid].data);
768 	      outvalue->value->add(stemp);
769 	      return true;
770 	    }
771 	  else
772 	    return false;
773 	}
774       else if (out == std::string("ymin") && 0 <= iid)
775 	{
776 	  if (iid < ymin->getarraylength())
777 	    {
778 	      sprintf(stemp, "%.15g", (*ymin)[iid].data);
779 	      outvalue->value->add(stemp);
780 	      return true;
781 	    }
782 	  else
783 	    return false;
784 	}
785       else if (out == std::string("ymax") && 0 <= iid)
786 	{
787 	  if (iid < ymax->getarraylength())
788 	    {
789 	      sprintf(stemp, "%.15g", (*ymax)[iid].data);
790 	      outvalue->value->add(stemp);
791 	      return true;
792 	    }
793 	  else
794 	    return false;
795 	}
796       else if (
797 	       (out.c_str())[0] == 'd'
798 	       && ('0' <= (out.c_str())[1] && (out.c_str())[1] <= 9)
799 	       && ('0' <= (out.c_str())[2] && (out.c_str())[2] <= 9)
800 	       && (out.c_str())[3] == 0
801 	       && 0 <= iid)
802 	{
803 	  itemp = 10 * ((out.c_str())[1] + out.c_str())[2] - 1;
804 	  if (itemp >= 0 && itemp < 99)
805 	    {
806 	      if (0 <= iid && iid < extra[itemp]->getarraylength())
807 		{
808 		  sprintf(stemp, "%.15g", (*extra[itemp])[iid].data);
809 		  outvalue->value->add(stemp);
810 		  return true;
811 		}
812 	      else
813 		return false;
814 	    }
815 	  else
816 	    return false;
817 	}
818       else if (out == std::string("x_attr") && 0 <= iid)
819 	{
820 	  if (iid < x->getarraylength())
821 	    {
822 	      sprintf(stemp, "%d", (*x)[iid].status);
823 	      outvalue->value->add(stemp);
824 	      return true;
825 	    }
826 	  else
827 	    return false;
828 	}
829       else if (out == std::string("xmin_attr") && 0 <= iid)
830 	{
831 	  if (iid < xmin->getarraylength())
832 	    {
833 	      sprintf(stemp, "%d", (*xmin)[iid].status);
834 	      outvalue->value->add(stemp);
835 	      return true;
836 	    }
837 	  else
838 	    return false;
839 	}
840       else if (out == std::string("xmax_attr") && 0 <= iid)
841 	{
842 	  if (iid < xmax->getarraylength())
843 	    {
844 	      sprintf(stemp, "%d", (*xmax)[iid].status);
845 	      outvalue->value->add(stemp);
846 	      return true;
847 	    }
848 	  else
849 	    return false;
850 	}
851       else if (out == std::string("y_attr") && 0 <= iid)
852 	{
853 	  if (iid < y->getarraylength())
854 	    {
855 	      sprintf(stemp, "%d", (*y)[iid].status);
856 	      outvalue->value->add(stemp);
857 	      return true;
858 	    }
859 	  else
860 	    return false;
861 	}
862       else if (out == std::string("ymin_attr") && 0 <= iid)
863 	{
864 	  if (iid < ymin->getarraylength())
865 	    {
866 	      sprintf(stemp, "%d", (*ymin)[iid].status);
867 	      outvalue->value->add(stemp);
868 	      return true;
869 	    }
870 	  else
871 	    return false;
872 	}
873       else if (out == std::string("ymax_attr") && 0 <= iid)
874 	{
875 	  if (iid < ymax->getarraylength())
876 	    {
877 	      sprintf(stemp, "%d", (*ymax)[iid].status);
878 	      outvalue->value->add(stemp);
879 	      return true;
880 	    }
881 	  else
882 	    return false;
883 	}
884       else if (
885 	       (out.c_str())[0] == 'a'
886 	       && ('0' <= (out.c_str())[1] && (out.c_str())[1] <= 9)
887 	       && ('0' <= (out.c_str())[2] && (out.c_str())[2] <= 9)
888 	       && (out.c_str())[3] == 0
889 	       && 0 <= iid)
890 	{
891 	  itemp = 10 * ((out.c_str())[1] + out.c_str())[2] - 1;
892 	  if (itemp >= 0 && itemp < 99)
893 	    {
894 	      if (0 <= iid && iid < extra[itemp]->getarraylength())
895 		{
896 		  sprintf(stemp, "%d", (*extra[itemp])[iid].status);
897 		  outvalue->value->add(stemp);
898 		  return true;
899 		}
900 	      else
901 		return false;
902 	    }
903 	  else
904 	    return false;
905 	}
906       else if (out == std::string("bound_xmin") && iid == -1)
907 	{
908 	  sprintf(stemp, "%.15g", bound_xmin);
909 	  outvalue->value->add(stemp);
910 	  return true;
911 	}
912       else if (out == std::string("bound_xmax") && iid == -1)
913 	{
914 	  sprintf(stemp, "%.15g", bound_xmax);
915 	  outvalue->value->add(stemp);
916 	  return true;
917 	}
918       else if (out == std::string("bound_ymin") && iid == -1)
919 	{
920 	  sprintf(stemp, "%.15g", bound_ymin);
921 	  outvalue->value->add(stemp);
922 	  return true;
923 	}
924       else if (out == std::string("bound_ymax") && iid == -1)
925 	{
926 	  sprintf(stemp, "%.15g", bound_ymax);
927 	  outvalue->value->add(stemp);
928 	  return true;
929 	}
930       else if (out == std::string("filename") && iid == -1)
931 	{
932 	  sprintf(stemp, "%s", filename);
933 	  outvalue->value->add(stemp);
934 	  return true;
935 	}
936       else if (out == std::string("isfiledata") && iid == -1)
937 	{
938 	  sprintf(stemp, "%d", isfiledata);
939 	  outvalue->value->add(stemp);
940 	  return true;
941 	}
942       else if (out == std::string("info") && iid == -1)
943 	{
944 	  outvalue->value->add(info->c_str());
945 	  return true;
946 	}
947       else
948 	return false;
949     }
950   else
951     return false;
952 
953   return true;
954 
955 }
956 
set(std::string * member,std::string * setvalue)957 bool data::set(std::string* member, std::string* setvalue)
958 {
959   std::string out, shrunk;
960   int iid;
961   int itemp;
962 
963   if (topobject(member, &out, &iid) == true)
964     {
965       if (out == std::string("id") && iid == -1)
966 	{
967 	  id = atoi(setvalue->c_str());
968 	  return true;
969 	}
970       else if (out == std::string("label") && iid == -1)
971 	{
972 	  *label = *setvalue;
973 	  return true;
974 	}
975       else if (out == std::string("selected") && iid == -1)
976 	{
977 	  selected = atoi(setvalue->c_str());
978 	  return true;
979 	}
980       else if (out == std::string("show") && iid == -1)
981 	{
982 	  display = atoi(setvalue->c_str());
983 	  return true;
984 	}
985       else if (out == std::string("virgin") && iid == -1)
986 	{
987 	  virgin = atoi(setvalue->c_str());
988 	  return true;
989 	}
990       else if (out == std::string("trans_x") && iid == -1)
991 	{
992 	  trans_x = atoi(setvalue->c_str());
993 	  return true;
994 	}
995       else if (out == std::string("format_x") && iid == -1)
996 	{
997 	  *format_x = *setvalue;
998 	  return true;
999 	}
1000       else if (out == std::string("trans_y") && iid == -1)
1001 	{
1002 	  trans_y = atoi(setvalue->c_str());
1003 	  return true;
1004 	}
1005       else if (out == std::string("format_y") && iid == -1)
1006 	{
1007 	  *format_y = *setvalue;
1008 	  return true;
1009 	}
1010       else if (out == std::string("linecolor_red") && iid == -1)
1011 	{
1012 	  linecolor.red = atoi(setvalue->c_str());
1013 	  return true;
1014 	}
1015       else if (out == std::string("linecolor_green") && iid == -1)
1016 	{
1017 	  linecolor.green = atoi(setvalue->c_str());
1018 	  return true;
1019 	}
1020       else if (out == std::string("linecolor_blue") && iid == -1)
1021 	{
1022 	  linecolor.blue = atoi(setvalue->c_str());
1023 	  return true;
1024 	}
1025       else if (out == std::string("markeredgecolor_red") && iid == -1)
1026 	{
1027 	  markeredgecolor.red = atoi(setvalue->c_str());
1028 	  return true;
1029 	}
1030       else if (out == std::string("markeredgecolor_green") && iid == -1)
1031 	{
1032 	  markeredgecolor.green = atoi(setvalue->c_str());
1033 	  return true;
1034 	}
1035       else if (out == std::string("markeredgecolor_blue") && iid == -1)
1036 	{
1037 	  markeredgecolor.blue = atoi(setvalue->c_str());
1038 	  return true;
1039 	}
1040       else if (out == std::string("markerbodycolor_red") && iid == -1)
1041 	{
1042 	  markerbodycolor.red = atoi(setvalue->c_str());
1043 	  return true;
1044 	}
1045       else if (out == std::string("markerbodycolor_green") && iid == -1)
1046 	{
1047 	  markerbodycolor.green = atoi(setvalue->c_str());
1048 	  return true;
1049 	}
1050       else if (out == std::string("markerbodycolor_blue") && iid == -1)
1051 	{
1052 	  markerbodycolor.blue = atoi(setvalue->c_str());
1053 	  return true;
1054 	}
1055       else if (out == std::string("linewidth") && iid == -1)
1056 	{
1057 	  linestyle.width = atoi(setvalue->c_str());
1058 	  return true;
1059 	}
1060       else if (out == std::string("linecap") && iid == -1)
1061 	{
1062 	  linestyle.cap = atoi(setvalue->c_str());
1063 	  return true;
1064 	}
1065       else if (out == std::string("linejoin") && iid == -1)
1066 	{
1067 	  linestyle.join = atoi(setvalue->c_str());
1068 	  return true;
1069 	}
1070       else if (out == std::string("linestyle") && iid == -1)
1071 	{
1072 	  linestyle.style = atoi(setvalue->c_str());
1073 	  return true;
1074 	}
1075       else if (out == std::string("markeredgewidth") && iid == -1)
1076 	{
1077 	  markeredgestyle.width = atoi(setvalue->c_str());
1078 	  return true;
1079 	}
1080       else if (out == std::string("markeredgecap") && iid == -1)
1081 	{
1082 	  markeredgestyle.cap = atoi(setvalue->c_str());
1083 	  return true;
1084 	}
1085       else if (out == std::string("markeredgejoin") && iid == -1)
1086 	{
1087 	  markeredgestyle.join = atoi(setvalue->c_str());
1088 	  return true;
1089 	}
1090       else if (out == std::string("markeredgestyle") && iid == -1)
1091 	{
1092 	  markeredgestyle.style = atoi(setvalue->c_str());
1093 	  return true;
1094 	}
1095       else if (out == std::string("markerfillstyle") && iid == -1)
1096 	{
1097 	  markerbodyfillstyle.style = atoi(setvalue->c_str());
1098 	  return true;
1099 	}
1100       else if (out == std::string("markerfillrule") && iid == -1)
1101 	{
1102 	  markerbodyfillstyle.fillrule = atoi(setvalue->c_str());
1103 	  return true;
1104 	}
1105       else if (out == std::string("interpolate") && iid == -1)
1106 	{
1107 	  interpolate = atoi(setvalue->c_str());
1108 	  return true;
1109 	}
1110       else if (out == std::string("interpolatediv") && iid == -1)
1111 	{
1112 	  interpolatediv = atoi(setvalue->c_str());
1113 	  return true;
1114 	}
1115       else if (out == std::string("markerstyle") && iid == -1)
1116 	{
1117 	  markerstyle = atoi(setvalue->c_str());
1118 	  return true;
1119 	}
1120       else if (out == std::string("markercenterdot") && iid == -1)
1121 	{
1122 	  markercenterdot = atoi(setvalue->c_str());
1123 	  return true;
1124 	}
1125       else if (out == std::string("markersize") && iid == -1)
1126 	{
1127 	  markersize = atoi(setvalue->c_str());
1128 	  return true;
1129 	}
1130       else if (out == std::string("clipping") && iid == -1)
1131 	{
1132 	  clipping = atoi(setvalue->c_str());
1133 	  return true;
1134 	}
1135       else if (out == std::string("refaxis_x") && iid == -1)
1136 	{
1137 	  refaxis_x = atoi(setvalue->c_str());
1138 	  return true;
1139 	}
1140       else if (out == std::string("refaxis_y") && iid == -1)
1141 	{
1142 	  refaxis_y = atoi(setvalue->c_str());
1143 	  return true;
1144 	}
1145       else if (out == std::string("basevalue") && iid == -1)
1146 	{
1147 	  basevalue = atof(setvalue->c_str());
1148 	  return true;
1149 	}
1150       else if (out == std::string("m_start") && iid == -1)
1151 	{
1152 	  m_start = atof(setvalue->c_str());
1153 	  return true;
1154 	}
1155       else if (out == std::string("m_end") && iid == -1)
1156 	{
1157 	  m_end = atof(setvalue->c_str());
1158 	  return true;
1159 	}
1160       else if (out == std::string("m_div") && iid == -1)
1161 	{
1162 	  m_div = atoi(setvalue->c_str());
1163 	  return true;
1164 	}
1165       else if (out == std::string("m_scaling") && iid == -1)
1166 	{
1167 	  m_scaling = atoi(setvalue->c_str());
1168 	  return true;
1169 	}
1170       else if (out == std::string("col_x") && iid == -1)
1171 	{
1172 	  col_x = atoi(setvalue->c_str());
1173 	  return true;
1174 	}
1175       else if (out == std::string("col_xmin") && iid == -1)
1176 	{
1177 	  col_xmin = atoi(setvalue->c_str());
1178 	  return true;
1179 	}
1180       else if (out == std::string("col_xmax") && iid == -1)
1181 	{
1182 	  col_xmax = atoi(setvalue->c_str());
1183 	  return true;
1184 	}
1185       else if (out == std::string("col_y") && iid == -1)
1186 	{
1187 	  col_y = atoi(setvalue->c_str());
1188 	  return true;
1189 	}
1190       else if (out == std::string("col_ymin") && iid == -1)
1191 	{
1192 	  col_ymin = atoi(setvalue->c_str());
1193 	  return true;
1194 	}
1195       else if (out == std::string("col_ymax") && iid == -1)
1196 	{
1197 	  col_ymax = atoi(setvalue->c_str());
1198 	  return true;
1199 	}
1200       else if (out == std::string("readstart") && iid == -1)
1201 	{
1202 	  readstart = atoi(setvalue->c_str());
1203 	  return true;
1204 	}
1205       else if (out == std::string("readend") && iid == -1)
1206 	{
1207 	  readend = atoi(setvalue->c_str());
1208 	  return true;
1209 	}
1210       else if (out == std::string("skip") && iid == -1)
1211 	{
1212 	  skip = atoi(setvalue->c_str());
1213 	  return true;
1214 	}
1215       else if (out == std::string("commentlineaction") && iid == -1)
1216 	{
1217 	  commentlineaction = atoi(setvalue->c_str());
1218 	  return true;
1219 	}
1220       else if (out == std::string("bar_x") && iid == -1)
1221 	{
1222 	  bar_x = atoi(setvalue->c_str());
1223 	  return true;
1224 	}
1225       else if (out == std::string("bar_y") && iid == -1)
1226 	{
1227 	  bar_y = atoi(setvalue->c_str());
1228 	  return true;
1229 	}
1230       else if (out == std::string("datasearchpath") && iid == -1)
1231 	{
1232 	  datasearchpath = atoi(setvalue->c_str());
1233 	  return true;
1234 	}
1235       else if (out == std::string("extradatadispflag") && 1 <= iid && iid <= 99)
1236 	{
1237 	  extradatadispflag[iid - 1] = atoi(setvalue->c_str());
1238 	  return true;
1239 	}
1240       else if (out == std::string("extradata") && iid == -1)
1241 	{
1242 	  *extradata = *setvalue;
1243 	  return true;
1244 	}
1245       else if (out == std::string("x") && 0 <= iid)
1246 	{
1247 	  if (iid < x->getarraylength())
1248 	    {
1249 	      (*x)[iid].data = atof(setvalue->c_str());
1250 	      return true;
1251 	    }
1252 	  else
1253 	    return false;
1254 	}
1255       else if (out == std::string("xmin") && 0 <= iid)
1256 	{
1257 	  if (iid < xmin->getarraylength())
1258 	    {
1259 	      (*xmin)[iid].data = atof(setvalue->c_str());
1260 	      return true;
1261 	    }
1262 	  else
1263 	    return false;
1264 	}
1265       else if (out == std::string("xmax") && 0 <= iid)
1266 	{
1267 	  if (iid < xmax->getarraylength())
1268 	    {
1269 	      (*xmax)[iid].data = atof(setvalue->c_str());
1270 	      return true;
1271 	    }
1272 	  else
1273 	    return false;
1274 	}
1275       else if (out == std::string("y") && 0 <= iid)
1276 	{
1277 	  if (iid < y->getarraylength())
1278 	    {
1279 	      (*y)[iid].data = atof(setvalue->c_str());
1280 	      return true;
1281 	    }
1282 	  else
1283 	    return false;
1284 	}
1285       else if (out == std::string("ymin") && 0 <= iid)
1286 	{
1287 	  if (iid < ymin->getarraylength())
1288 	    {
1289 	      (*ymin)[iid].data = atof(setvalue->c_str());
1290 	      return true;
1291 	    }
1292 	  else
1293 	    return false;
1294 	}
1295       else if (out == std::string("ymax") && 0 <= iid)
1296 	{
1297 	  if (iid < ymax->getarraylength())
1298 	    {
1299 	      (*ymax)[iid].data = atof(setvalue->c_str());
1300 	      return true;
1301 	    }
1302 	  else
1303 	    return false;
1304 	}
1305       else if (
1306 	       (out.c_str())[0] == 'd'
1307 	       && ('0' <= (out.c_str())[1] && (out.c_str())[1] <= 9)
1308 	       && ('0' <= (out.c_str())[2] && (out.c_str())[2] <= 9)
1309 	       && (out.c_str())[3] == 0
1310 	       && 0 <= iid)
1311 	{
1312 	  itemp = 10 * ((out.c_str())[1] + out.c_str())[2] - 1;
1313 	  if (itemp >= 0 && itemp < 99)
1314 	    {
1315 	      if (0 <= iid && iid < extra[itemp]->getarraylength())
1316 		{
1317 		  (*extra[itemp])[iid].data = atof(setvalue->c_str());
1318 		  return true;
1319 		}
1320 	      else
1321 		return false;
1322 	    }
1323 	  else
1324 	    return false;
1325 	}
1326       else if (out == std::string("x_attr") && 0 <= iid)
1327 	{
1328 	  if (iid < x->getarraylength())
1329 	    {
1330 	      (*x)[iid].status = atoi(setvalue->c_str());
1331 	      return true;
1332 	    }
1333 	  else
1334 	    return false;
1335 	}
1336       else if (out == std::string("xmin_attr") && 0 <= iid)
1337 	{
1338 	  if (iid < xmin->getarraylength())
1339 	    {
1340 	      (*xmin)[iid].status = atoi(setvalue->c_str());
1341 	      return true;
1342 	    }
1343 	  else
1344 	    return false;
1345 	}
1346       else if (out == std::string("xmax_attr") && 0 <= iid)
1347 	{
1348 	  if (iid < xmax->getarraylength())
1349 	    {
1350 	      (*xmax)[iid].status = atoi(setvalue->c_str());
1351 	      return true;
1352 	    }
1353 	  else
1354 	    return false;
1355 	}
1356       else if (out == std::string("y_attr") && 0 <= iid)
1357 	{
1358 	  if (iid < y->getarraylength())
1359 	    {
1360 	      (*y)[iid].status = atoi(setvalue->c_str());
1361 	      return true;
1362 	    }
1363 	  else
1364 	    return false;
1365 	}
1366       else if (out == std::string("ymin_attr") && 0 <= iid)
1367 	{
1368 	  if (iid < ymin->getarraylength())
1369 	    {
1370 	      (*ymin)[iid].status = atoi(setvalue->c_str());
1371 	      return true;
1372 	    }
1373 	  else
1374 	    return false;
1375 	}
1376       else if (out == std::string("ymax_attr") && 0 <= iid)
1377 	{
1378 	  if (iid < ymax->getarraylength())
1379 	    {
1380 	      (*ymax)[iid].status = atoi(setvalue->c_str());
1381 	      return true;
1382 	    }
1383 	  else
1384 	    return false;
1385 	}
1386       else if (
1387 	       (out.c_str())[0] == 'a'
1388 	       && ('0' <= (out.c_str())[1] && (out.c_str())[1] <= 9)
1389 	       && ('0' <= (out.c_str())[2] && (out.c_str())[2] <= 9)
1390 	       && (out.c_str())[3] == 0
1391 	       && 0 <= iid)
1392 	{
1393 	  itemp = 10 * ((out.c_str())[1] + out.c_str())[2] - 1;
1394 	  if (itemp >= 0 && itemp < 99)
1395 	    {
1396 	      if (0 <= iid && iid < extra[itemp]->getarraylength())
1397 		{
1398 		  (*extra[itemp])[iid].status = atoi(setvalue->c_str());
1399 		  return true;
1400 		}
1401 	      else
1402 		return false;
1403 	    }
1404 	  else
1405 	    return false;
1406 	}
1407       else if (out == std::string("bound_xmin") && iid == -1)
1408 	{
1409 	  bound_xmin = atof(setvalue->c_str());
1410 	  return true;
1411 	}
1412       else if (out == std::string("bound_xmax") && iid == -1)
1413 	{
1414 	  bound_xmax = atof(setvalue->c_str());
1415 	  return true;
1416 	}
1417       else if (out == std::string("bound_ymin") && iid == -1)
1418 	{
1419 	  bound_ymin = atof(setvalue->c_str());
1420 	  return true;
1421 	}
1422       else if (out == std::string("bound_ymax") && iid == -1)
1423 	{
1424 	  bound_ymax = atof(setvalue->c_str());
1425 	  return true;
1426 	}
1427       else if (out == std::string("filename") && iid == -1)
1428 	{
1429 	  if (strlen(setvalue->c_str()) < 1000)
1430             {
1431               strcpy(filename, setvalue->c_str());
1432               return true;
1433             }
1434           else
1435             return false;
1436 	}
1437       else if (out == std::string("isfiledata") && iid == -1)
1438 	{
1439 	  isfiledata = atoi(setvalue->c_str());
1440 	  return true;
1441 	}
1442       else if (out == std::string("info") && iid == -1)
1443 	{
1444 	  *info = *setvalue;
1445 	  return true;
1446 	}
1447       else
1448 	return false;
1449     }
1450   else
1451     return false;
1452 
1453   return true;
1454 
1455 }
1456 
exec(std::string * function,buffarray * argument,tokenbuff * outvalue)1457 bool data::exec(std::string* function, buffarray *argument, tokenbuff* outvalue)
1458 {
1459   std::string out, shrunk, str1, str2;
1460   int iid, arglength;
1461   char stemp[100];
1462   FILE* fp;
1463   int itemp;
1464   buffarray ini, fun;
1465   graph* gra = (graph *)(((frame *)parent)->parent);
1466 
1467   outvalue->value->setbuff(0);
1468   if (topobject(function, &out, &iid) == true)
1469     {
1470       arglength = argument->getarraylength();
1471 
1472       // paint
1473       if (out == std::string("paint") && iid == -1)
1474 	{
1475 	  if (arglength == 1)
1476 	    {
1477 	      if (fhvuff->get(&(*argument)[0], &fp, &itemp, &str1))
1478 		{
1479 		  paint(true, fp);
1480 		  return true;
1481 		}
1482 	      else
1483 		return false;
1484 	    }
1485 	  else
1486 	    return false;
1487 	}
1488       // remakebuffer
1489       else if (out == std::string("remakebuffer") && iid == -1)
1490 	{
1491 	  if (arglength == 1 && (*argument)[0] == std::string("null"))
1492 	    {
1493 	      if (!isfiledata)
1494 		if (!genxdata(m_start, m_end, m_div, m_scaling, x, y))
1495 		  return false;
1496 	      return true;
1497 	    }
1498 	  else
1499 	    return false;
1500 	}
1501       // setbbox
1502       else if (out == std::string("setbbox") && iid == -1)
1503 	{
1504 	  if (arglength == 1 && (*argument)[0] == std::string("null"))
1505 	    {
1506 	      paint(false, fp);
1507 	      return true;
1508 	    }
1509 	  else
1510 	    return false;
1511 	}
1512       // datalength
1513       else if (out == std::string("datalength") && iid == -1)
1514 	{
1515 	  if (arglength == 1 && (*argument)[0] == std::string("null"))
1516 	    {
1517 	      sprintf(stemp, "%d", x->getarraylength());
1518 	      outvalue->value->add(stemp);
1519 	      return true;
1520 	    }
1521 	  else
1522 	    return false;
1523 	}
1524       // linearfit
1525       else if (out == std::string("linearfit") && iid == -1)
1526 	{
1527 	  if (arglength == 6)
1528 	    {
1529 	      gra->updated = true;
1530 	      if (ExecLinearSQ(atoi((*argument)[0].c_str()),
1531 			   atoi((*argument)[1].c_str()),
1532 			   atof((*argument)[2].c_str()),
1533 			   atof((*argument)[3].c_str()),
1534 			   atoi((*argument)[4].c_str()),
1535 			   atoi((*argument)[5].c_str()),
1536 			   &str1,
1537 			   &str2))
1538 		{
1539 		  outvalue->value->add(str1.c_str());
1540 		  outvalue->value->add(str2.c_str());
1541 		}
1542 	      else
1543 		{
1544 		  outvalue->value->add("");
1545 		  outvalue->value->add("");
1546 		}
1547 	      return true;
1548 	    }
1549 	  else
1550 	    return false;
1551 	}
1552       // nonlinearfit
1553       else if (out == std::string("nonlinearfit") && iid == -1)
1554 	{
1555 	  if (arglength == 22)
1556 	    {
1557 	      ini.setbuff(0);
1558 	      ini.add("");
1559 	      for (int i = 3; i <= 11; i++)
1560 		ini.add((*argument)[i].c_str());
1561 
1562 	      fun.setbuff(0);
1563 	      fun.add("");
1564 	      for (int i = 12; i <= 20; i++)
1565 		fun.add((*argument)[i].c_str());
1566 
1567 	      gra->updated = true;
1568 	      if (OutMar(atoi((*argument)[0].c_str())
1569 			 ,atoi((*argument)[1].c_str())
1570 			 ,&(*argument)[2]
1571 			 ,&ini
1572 			 ,&fun
1573 			 ,atof((*argument)[21].c_str())
1574 			 , &str1
1575 			 , &str2
1576 			 ))
1577 		{
1578 		  outvalue->value->add(str1.c_str());
1579 		  outvalue->value->add(str2.c_str());
1580 		}
1581 	      else
1582 		{
1583 		  outvalue->value->add("");
1584 		  outvalue->value->add("");
1585 		}
1586 	      return true;
1587 	    }
1588 	  else
1589 	    return false;
1590 	}
1591       // loaddata
1592       else if (out == std::string("loaddata") && iid == -1)
1593 	{
1594 	  if (arglength == 1 && (*argument)[0] == std::string("null"))
1595 	    {
1596 	      gra->updated = true;
1597 	      if (loaddata())
1598 		sprintf(stemp, "1");
1599 	      else
1600 		sprintf(stemp, "0");
1601 
1602 	      outvalue->value->add(stemp);
1603 	      return true;
1604 	    }
1605 	  else
1606 	    return false;
1607 	}
1608       else
1609 	return false;
1610     }
1611   else
1612     return false;
1613 
1614   return true;
1615 }
1616 
1617 
paint(bool flag,FILE * f)1618 bool data::paint(bool flag, FILE* f)
1619 {
1620   drawplot(flag, f);
1621   return true;
1622 }
1623 
1624 
readdata(FILE * fp)1625 bool data::readdata(FILE *fp)
1626 {
1627   char stemp[10000];
1628   std::string str;
1629   char *p;
1630   int readversion;
1631 
1632 //  virgin = false;
1633 
1634   // version
1635   if (getnextline(stemp, sizeof(stemp), fp))
1636   {
1637     if (nextitem(stemp, &str) != 0)
1638       readversion = atoi(str.c_str());
1639     else
1640       return false;
1641   }
1642   else
1643     return false;
1644 
1645   // id
1646   if (getnextline(stemp, sizeof(stemp), fp))
1647   {
1648     if (nextitem(stemp, &str) != 0)
1649       id = atoi(str.c_str());
1650     else
1651       return false;
1652   }
1653   else
1654     return false;
1655 
1656   // virgin
1657   if (getnextline(stemp, sizeof(stemp), fp))
1658   {
1659     if (nextitem(stemp, &str) != 0)
1660       virgin = atoi(str.c_str());
1661     else
1662       return false;
1663   }
1664   else
1665     return false;
1666 
1667   if (readversion >= 2)
1668     {
1669       // display
1670       if (getnextline(stemp, sizeof(stemp), fp))
1671 	{
1672 	  if (nextitem(stemp, &str) != 0)
1673 	    display = atoi(str.c_str());
1674 	  else
1675 	    return false;
1676 	}
1677       else
1678 	return false;
1679     }
1680 
1681   // trans_x, trans_y
1682   if (getnextline(stemp, sizeof(stemp), fp))
1683   {
1684     p = stemp;
1685     // trans_x
1686     p = nextitem(p, &str);
1687     if (p != 0)
1688       trans_x = atoi(str.c_str());
1689     else
1690       return false;
1691     // trans_y
1692     p = nextitem(p, &str);
1693     if (p != 0)
1694       trans_y = atoi(str.c_str());
1695     else
1696       return false;
1697   }
1698   else
1699     return false;
1700 
1701   // format_x
1702   if (getnextline(stemp, sizeof(stemp), fp))
1703   {
1704     if (gettxt(stemp, &str))
1705       *format_x = str;
1706     else
1707       return false;
1708   }
1709 
1710   // format_y
1711   if (getnextline(stemp, sizeof(stemp), fp))
1712   {
1713     if (gettxt(stemp, &str))
1714       *format_y = str;
1715     else
1716       return false;
1717   }
1718 
1719   // linecolor
1720   if (getnextline(stemp, sizeof(stemp), fp))
1721   {
1722     p = stemp;
1723     // red
1724     p = nextitem(p, &str);
1725     if (p != 0)
1726       linecolor.red = atoi(str.c_str());
1727     else
1728       return false;
1729     // green
1730     p = nextitem(p, &str);
1731     if (p != 0)
1732       linecolor.green = atoi(str.c_str());
1733     else
1734       return false;
1735     // blue
1736     p = nextitem(p, &str);
1737     if (p != 0)
1738       linecolor.blue = atoi(str.c_str());
1739     else
1740       return false;
1741   }
1742   else
1743     return false;
1744 
1745   // markeredgecolor
1746   if (getnextline(stemp, sizeof(stemp), fp))
1747   {
1748     p = stemp;
1749     // red
1750     p = nextitem(p, &str);
1751     if (p != 0)
1752       markeredgecolor.red = atoi(str.c_str());
1753     else
1754       return false;
1755     // green
1756     p = nextitem(p, &str);
1757     if (p != 0)
1758       markeredgecolor.green = atoi(str.c_str());
1759     else
1760       return false;
1761     // blue
1762     p = nextitem(p, &str);
1763     if (p != 0)
1764       markeredgecolor.blue = atoi(str.c_str());
1765     else
1766       return false;
1767   }
1768   else
1769     return false;
1770 
1771   // markerbodycolor
1772   if (getnextline(stemp, sizeof(stemp), fp))
1773   {
1774     p = stemp;
1775     // red
1776     p = nextitem(p, &str);
1777     if (p != 0)
1778       markerbodycolor.red = atoi(str.c_str());
1779     else
1780       return false;
1781     // green
1782     p = nextitem(p, &str);
1783     if (p != 0)
1784       markerbodycolor.green = atoi(str.c_str());
1785     else
1786       return false;
1787     // blue
1788     p = nextitem(p, &str);
1789     if (p != 0)
1790       markerbodycolor.blue = atoi(str.c_str());
1791     else
1792       return false;
1793   }
1794   else
1795     return false;
1796 
1797   // linestyle
1798   if (getnextline(stemp, sizeof(stemp), fp))
1799   {
1800     p = stemp;
1801     // width
1802     p = nextitem(p, &str);
1803     if (p != 0)
1804       linestyle.width = atoi(str.c_str());
1805     else
1806       return false;
1807     // cap
1808     p = nextitem(p, &str);
1809     if (p != 0)
1810       linestyle.cap = atoi(str.c_str());
1811     else
1812       return false;
1813     // join
1814     p = nextitem(p, &str);
1815     if (p != 0)
1816       linestyle.join = atoi(str.c_str());
1817     else
1818       return false;
1819     // style
1820     p = nextitem(p, &str);
1821     if (p != 0)
1822       linestyle.style = atoi(str.c_str());
1823     else
1824       return false;
1825   }
1826   else
1827     return false;
1828 
1829   // markeredgestyle
1830   if (getnextline(stemp, sizeof(stemp), fp))
1831   {
1832     p = stemp;
1833     // width
1834     p = nextitem(p, &str);
1835     if (p != 0)
1836       markeredgestyle.width = atoi(str.c_str());
1837     else
1838       return false;
1839     // cap
1840     p = nextitem(p, &str);
1841     if (p != 0)
1842       markeredgestyle.cap = atoi(str.c_str());
1843     else
1844       return false;
1845     // join
1846     p = nextitem(p, &str);
1847     if (p != 0)
1848       markeredgestyle.join = atoi(str.c_str());
1849     else
1850       return false;
1851     // style
1852     p = nextitem(p, &str);
1853     if (p != 0)
1854       markeredgestyle.style = atoi(str.c_str());
1855     else
1856       return false;
1857   }
1858   else
1859     return false;
1860 
1861   // markerbodyfillstyle
1862   if (getnextline(stemp, sizeof(stemp), fp))
1863   {
1864     p = stemp;
1865     // fillrule
1866     p = nextitem(p, &str);
1867     if (p != 0)
1868       markerbodyfillstyle.fillrule = atoi(str.c_str());
1869     else
1870       return false;
1871     // style
1872     p = nextitem(p, &str);
1873     if (p != 0)
1874       markerbodyfillstyle.style = atoi(str.c_str());
1875     else
1876       return false;
1877   }
1878   else
1879     return false;
1880 
1881   if (getnextline(stemp, sizeof(stemp), fp))
1882   {
1883     p = stemp;
1884     // interpolate
1885     p = nextitem(p, &str);
1886     if (p != 0)
1887       interpolate = atoi(str.c_str());
1888     else
1889       return false;
1890     // interpolatediv
1891     p = nextitem(p, &str);
1892     if (p != 0)
1893       interpolatediv = atoi(str.c_str());
1894     else
1895       return false;
1896     // markerstyle
1897     p = nextitem(p, &str);
1898     if (p != 0)
1899       markerstyle = atoi(str.c_str());
1900     else
1901       return false;
1902     // markercenterdot
1903     p = nextitem(p, &str);
1904     if (p != 0)
1905       markercenterdot = atoi(str.c_str());
1906     else
1907       return false;
1908     // markersize
1909     p = nextitem(p, &str);
1910     if (p != 0)
1911       markersize = atoi(str.c_str());
1912     else
1913       return false;
1914     // clipping
1915     p = nextitem(p, &str);
1916     if (p != 0)
1917       clipping = atoi(str.c_str());
1918     else
1919       return false;
1920     // refaxis_x
1921     p = nextitem(p, &str);
1922     if (p != 0)
1923       refaxis_x = atoi(str.c_str());
1924     else
1925       return false;
1926     // refaxis_y
1927     p = nextitem(p, &str);
1928     if (p != 0)
1929       refaxis_y = atoi(str.c_str());
1930     else
1931       return false;
1932     // basevalue
1933     p = nextitem(p, &str);
1934     if (p != 0)
1935       basevalue = atof(str.c_str());
1936     else
1937       return false;
1938   }
1939   else
1940     return false;
1941 
1942   // memory data
1943   if (getnextline(stemp, sizeof(stemp), fp))
1944   {
1945     p = stemp;
1946     // m_start
1947     p = nextitem(p, &str);
1948     if (p != 0)
1949       m_start = atof(str.c_str());
1950     else
1951       return false;
1952     // m_end
1953     p = nextitem(p, &str);
1954     if (p != 0)
1955       m_end = atof(str.c_str());
1956     else
1957       return false;
1958     // m_div
1959     p = nextitem(p, &str);
1960     if (p != 0)
1961       m_div = atoi(str.c_str());
1962     else
1963       return false;
1964     // m_scaling
1965     p = nextitem(p, &str);
1966     if (p != 0)
1967       m_scaling = atoi(str.c_str());
1968     else
1969       return false;
1970   }
1971   else
1972     return false;
1973 
1974 
1975 
1976 
1977   // col_x
1978   if (getnextline(stemp, sizeof(stemp), fp))
1979   {
1980     p = stemp;
1981     // col_x
1982     p = nextitem(p, &str);
1983     if (p != 0)
1984       col_x = atoi(str.c_str());
1985     else
1986       return false;
1987     // col_xmin
1988     p = nextitem(p, &str);
1989     if (p != 0)
1990       col_xmin = atoi(str.c_str());
1991     else
1992       return false;
1993     // col_xmax
1994     p = nextitem(p, &str);
1995     if (p != 0)
1996       col_xmax = atoi(str.c_str());
1997     else
1998       return false;
1999   }
2000   else
2001     return false;
2002 
2003   // col_y
2004   if (getnextline(stemp, sizeof(stemp), fp))
2005   {
2006     p = stemp;
2007     // col_y
2008     p = nextitem(p, &str);
2009     if (p != 0)
2010       col_y = atoi(str.c_str());
2011     else
2012       return false;
2013     // col_ymin
2014     p = nextitem(p, &str);
2015     if (p != 0)
2016       col_ymin = atoi(str.c_str());
2017     else
2018       return false;
2019     // col_ymax
2020     p = nextitem(p, &str);
2021     if (p != 0)
2022       col_ymax = atoi(str.c_str());
2023     else
2024       return false;
2025   }
2026   else
2027     return false;
2028 
2029   // readposition
2030   if (getnextline(stemp, sizeof(stemp), fp))
2031   {
2032     p = stemp;
2033     // readstart
2034     p = nextitem(p, &str);
2035     if (p != 0)
2036       readstart = atoi(str.c_str());
2037     else
2038       return false;
2039     // readend
2040     p = nextitem(p, &str);
2041     if (p != 0)
2042       readend = atoi(str.c_str());
2043     else
2044       return false;
2045     // skip
2046     p = nextitem(p, &str);
2047     if (p != 0)
2048       skip = atoi(str.c_str());
2049     else
2050       return false;
2051     // commentlineaction
2052     p = nextitem(p, &str);
2053     if (p != 0)
2054       commentlineaction = atoi(str.c_str());
2055     else
2056       return false;
2057   }
2058   else
2059     return false;
2060 
2061   // bar
2062   if (getnextline(stemp, sizeof(stemp), fp))
2063   {
2064     p = stemp;
2065     // bar_x
2066     p = nextitem(p, &str);
2067     if (p != 0)
2068       bar_x = atoi(str.c_str());
2069     else
2070       return false;
2071     // bar_y
2072     p = nextitem(p, &str);
2073     if (p != 0)
2074       bar_y = atoi(str.c_str());
2075     else
2076       return false;
2077   }
2078   else
2079     return false;
2080 
2081   if (getnextline(stemp, sizeof(stemp), fp))
2082   {
2083     p = stemp;
2084     // datasearchpath
2085     p = nextitem(p, &str);
2086     if (p != 0)
2087       datasearchpath = atoi(str.c_str());
2088     else
2089       return false;
2090     // isfiledata
2091     p = nextitem(p, &str);
2092     if (p != 0)
2093       isfiledata = atoi(str.c_str());
2094     else
2095       return false;
2096   }
2097   else
2098     return false;
2099 
2100   // extradata
2101   if (getnextline(stemp, sizeof(stemp), fp))
2102   {
2103     if (gettxt(stemp, &str))
2104       *extradata = str;
2105     else
2106       return false;
2107   }
2108 
2109   // filename
2110   if (getnextline(stemp, sizeof(stemp), fp))
2111   {
2112     if (gettxt(stemp, &str))
2113       strcpy(filename, str.c_str());
2114     else
2115       return false;
2116   }
2117 
2118   // info
2119   if (getnextline(stemp, sizeof(stemp), fp))
2120   {
2121     if (gettxt(stemp, &str))
2122       *info = str;
2123     else
2124       return false;
2125   }
2126 
2127   return true;
2128 }
2129 
writedata(FILE * fp)2130 bool data::writedata(FILE *fp)
2131 {
2132   std::string str;
2133   fprintf(fp, "[data]\n");
2134 
2135   // style
2136   fprintf(fp, "%d\n", version);
2137   fprintf(fp, "%d\n", id);
2138   fprintf(fp, "%d\n", virgin);
2139   fprintf(fp, "%d\n", display);
2140   fprintf(fp, "%d %d\n", trans_x, trans_y);
2141   fprintf(fp, "\"%s\"\n", format_x->c_str());
2142   fprintf(fp, "\"%s\"\n", format_y->c_str());
2143   fprintf(fp, "%u %u %u\n", linecolor.red, linecolor.green, linecolor.blue);
2144   fprintf(fp, "%u %u %u\n", markeredgecolor.red, markeredgecolor.green, markeredgecolor.blue);
2145   fprintf(fp, "%u %u %u\n", markerbodycolor.red, markerbodycolor.green, markerbodycolor.blue);
2146   fprintf(fp, "%d %d %d %d\n", linestyle.width, linestyle.cap, linestyle.join, linestyle.style);
2147   fprintf(fp, "%d %d %d %d\n", markeredgestyle.width, markeredgestyle.cap, markeredgestyle.join, markeredgestyle.style);
2148   fprintf(fp, "%d %d\n", markerbodyfillstyle.fillrule, markerbodyfillstyle.style);
2149   fprintf(fp, "%d %d %d %d %d %d %d %d %.15g\n", interpolate, interpolatediv, markerstyle, markercenterdot, markersize,
2150 	  clipping, refaxis_x, refaxis_y, basevalue);
2151   fprintf(fp, "%.15g %.15g %d %d\n", m_start, m_end, m_div, m_scaling);
2152 
2153   // read data
2154   fprintf(fp, "%d %d %d\n", col_x, col_xmin, col_xmax);
2155   fprintf(fp, "%d %d %d\n", col_y, col_ymin, col_ymax);
2156   fprintf(fp, "%d %d %d %d\n", readstart, readend, skip, commentlineaction);
2157   fprintf(fp, "%d %d\n", bar_x, bar_y);
2158   fprintf(fp, "%d %d\n", datasearchpath, isfiledata);
2159   fprintf(fp, "\"%s\"\n", extradata->c_str());
2160   fprintf(fp, "\"%s\"\n", filename);
2161   fprintf(fp, "\"%s\"\n", info->c_str());
2162 
2163   return true;
2164 }
2165 
appendoriginaldata(FILE * fp,int dataid)2166 bool data::appendoriginaldata(FILE *fp, int dataid)
2167 {
2168   FILE *dest;
2169   char openfilename[1000];
2170   char stemp[10000];
2171   char header[1000];
2172   frame* fr = (frame *)parent;
2173 
2174   sprintf(header, "sod[%s]\n", filename);
2175 
2176   // load from tmpdir
2177   if (!virgin)
2178     {
2179       strcpy(openfilename, tmppath);
2180       strcat(openfilename, "/");
2181       strcat(openfilename, pid);
2182       sprintf(stemp, "%d_", fr->id);
2183       strcat(openfilename, stemp);
2184       sprintf(stemp, "%d_", dataid);
2185       strcat(openfilename, stemp);
2186       strcat(openfilename, filename);
2187 
2188       if ((dest = fopen(openfilename, "r")) != NULL)
2189 	{
2190 	  fputs(header, fp);
2191 	  while (topazfgets(stemp, sizeof(stemp), dest) != NULL)
2192 	    fputs(stemp, fp);
2193 	  fputs("eod\n", fp);
2194 	  fclose(dest);
2195 	}
2196       else
2197 	return false;
2198     }
2199   return true;
2200 }
2201 
gettmpdataname(std::string * file)2202 void data::gettmpdataname(std::string* file)
2203 {
2204   frame* fr = (frame *)parent;
2205   char stemp[10000];
2206 
2207   *file = std::string(pid);
2208   sprintf(stemp, "%d_", fr->id);
2209   *file += std::string(stemp);
2210   sprintf(stemp, "%d_", id);
2211   *file += std::string(stemp);
2212   *file += std::string(toshortfilename(filename));
2213 }
2214 
2215 
setrefpath(char * refpath)2216 bool data::setrefpath(char *refpath)
2217 {
2218   frame* fr = (frame *)parent;
2219 
2220   if ((!fr->withdata) && isfiledata && datasearchpath == 1)
2221     strcpy(filename, relpath((const char *)refpath, (const char *)filename));
2222   return true;
2223 }
2224 
2225 
restoreabspath(char * refpath)2226 bool data::restoreabspath(char *refpath)
2227 {
2228   frame* fr = (frame *)parent;
2229 
2230   if ((!fr->withdata) && isfiledata && datasearchpath == 1)
2231     return abspath((const char *)filename, (const char *)refpath, filename);
2232 
2233   return true;
2234 }
2235 
2236 
2237 
2238