13 # define _XOPEN_SOURCE_EXTENDED 1
17 # define DONT_DECLARE_MALLOC
18 # include "multinet_root:[multinet.include.rpc]rpc.h"
20 # include <ucx$rpcxdr.h>
24 #include "grconvert.h"
28 #define BADMAGIC 999999
29 #define BADVERSION 999998
34 int read_char(char *d
, int n
, FILE * fout
);
35 int read_int(int *d
, int n
, FILE * fout
);
36 int read_double(double *d
, int n
, FILE * fin
);
38 int read_charstr(char *d
, FILE * fout
);
39 int read_float(float *d
, int n
, FILE * fout
);
40 int read_short(short *d
, int n
, FILE * fout
);
41 static int read_velocityp(velocityp
* d
, FILE * fin
);
42 static int read_world(world
* d
, FILE * fin
);
43 static int read_view(view
* d
, FILE * fin
);
44 static int read_world_stack(world_stack
* d
, FILE * fin
);
45 static int read_labels(labels
* d
, FILE * fin
);
46 static int read_plotarr(plotarr
* d
, FILE * fin
);
47 static int read_tickmarks(tickmarks
* d
, FILE * fin
);
48 static int read_legend(legend
* d
, FILE * fin
);
49 static int read_framep(framep
* d
, FILE * fin
);
50 static int read_BoxPlot(BoxPlot
* d
, FILE * fin
);
52 int replace_xdr_short( short *i
);
58 int read_boxtype(boxtype
* d
, FILE * fin
)
61 short magic
, version
, testmagic
= 20, testversion
= 0;
62 if ((err
= read_short(&magic
, 1, fin
)))
64 if (magic
!= testmagic
)
66 if ((err
= read_short(&version
, 1, fin
)))
68 if (version
!= testversion
)
70 if ((err
= read_int(&(d
->active
), 1, fin
)))
72 if ((err
= read_int(&(d
->loctype
), 1, fin
)))
74 if ((err
= read_int(&(d
->gno
), 1, fin
)))
76 if ((err
= read_double(&(d
->x1
), 1, fin
)))
78 if ((err
= read_double(&(d
->y1
), 1, fin
)))
80 if ((err
= read_double(&(d
->x2
), 1, fin
)))
82 if ((err
= read_double(&(d
->y2
), 1, fin
)))
84 if ((err
= read_int(&(d
->lines
), 1, fin
)))
86 if ((err
= read_int(&(d
->linew
), 1, fin
)))
88 if ((err
= read_int(&(d
->color
), 1, fin
)))
90 if ((err
= read_int(&(d
->fill
), 1, fin
)))
92 if ((err
= read_int(&(d
->fillcolor
), 1, fin
)))
94 if ((err
= read_int(&(d
->fillpattern
), 1, fin
)))
100 * Read type ellipsetype
102 int read_ellipsetype(ellipsetype
* d
, FILE * fin
)
105 short magic
, version
, testmagic
= 41, testversion
= 0;
106 if ((err
= read_short(&magic
, 1, fin
)))
108 if (magic
!= testmagic
) {
109 /* try to recover so that older saves will be compatible */
110 replace_xdr_short( &magic
);
113 if ((err
= read_short(&version
, 1, fin
)))
115 if (version
!= testversion
)
117 if ((err
= read_int(&(d
->active
), 1, fin
)))
119 if ((err
= read_int(&(d
->loctype
), 1, fin
)))
121 if ((err
= read_int(&(d
->gno
), 1, fin
)))
123 if ((err
= read_double(&(d
->x1
), 1, fin
)))
125 if ((err
= read_double(&(d
->y1
), 1, fin
)))
127 if ((err
= read_double(&(d
->x2
), 1, fin
)))
129 if ((err
= read_double(&(d
->y2
), 1, fin
)))
131 if ((err
= read_int(&(d
->lines
), 1, fin
)))
133 if ((err
= read_int(&(d
->linew
), 1, fin
)))
135 if ((err
= read_int(&(d
->color
), 1, fin
)))
137 if ((err
= read_int(&(d
->fill
), 1, fin
)))
139 if ((err
= read_int(&(d
->fillcolor
), 1, fin
)))
141 if ((err
= read_int(&(d
->fillpattern
), 1, fin
)))
149 int read_linetype(linetype
* d
, FILE * fin
)
152 short magic
, version
, testmagic
= 21, testversion
= 0;
153 if ((err
= read_short(&magic
, 1, fin
)))
155 if (magic
!= testmagic
)
157 if ((err
= read_short(&version
, 1, fin
)))
159 if (version
!= testversion
)
161 if ((err
= read_int(&(d
->active
), 1, fin
)))
163 if ((err
= read_int(&(d
->loctype
), 1, fin
)))
165 if ((err
= read_int(&(d
->gno
), 1, fin
)))
167 if ((err
= read_double(&(d
->x1
), 1, fin
)))
169 if ((err
= read_double(&(d
->y1
), 1, fin
)))
171 if ((err
= read_double(&(d
->x2
), 1, fin
)))
173 if ((err
= read_double(&(d
->y2
), 1, fin
)))
175 if ((err
= read_int(&(d
->lines
), 1, fin
)))
177 if ((err
= read_int(&(d
->linew
), 1, fin
)))
179 if ((err
= read_int(&(d
->color
), 1, fin
)))
181 if ((err
= read_int(&(d
->arrow
), 1, fin
)))
183 if ((err
= read_int(&(d
->atype
), 1, fin
)))
185 if ((err
= read_double(&(d
->asize
), 1, fin
)))
193 int read_plotstr(plotstr
* d
, FILE * fin
)
196 short magic
, version
, testmagic
= 22, testversion
= 0;
197 if ((err
= read_short(&magic
, 1, fin
)))
199 if (magic
!= testmagic
)
201 if ((err
= read_short(&version
, 1, fin
)))
203 if (version
!= testversion
)
205 if ((err
= read_int(&(d
->active
), 1, fin
)))
207 if ((err
= read_int(&(d
->loctype
), 1, fin
)))
209 if ((err
= read_int(&(d
->gno
), 1, fin
)))
211 if ((err
= read_double(&(d
->x
), 1, fin
)))
213 if ((err
= read_double(&(d
->y
), 1, fin
)))
215 if ((err
= read_int(&(d
->lines
), 1, fin
)))
217 if ((err
= read_int(&(d
->linew
), 1, fin
)))
219 if ((err
= read_int(&(d
->color
), 1, fin
)))
221 if ((err
= read_int(&(d
->rot
), 1, fin
)))
223 if ((err
= read_int(&(d
->font
), 1, fin
)))
225 if ((err
= read_int(&(d
->just
), 1, fin
)))
227 if ((err
= read_double(&(d
->charsize
), 1, fin
)))
229 if ((err
= read_int(&i
, 1, fin
)))
239 d->s = (char *) malloc(i * sizeof(char));
242 d
->s
= (char *) malloc(i
* sizeof(char));
243 if ((err
= read_char(d
->s
, i
, fin
)))
249 * Read type velocityp
251 static int read_velocityp(velocityp
* d
, FILE * fin
)
254 short magic
, version
, testmagic
= 25, testversion
= 0;
255 if ((err
= read_short(&magic
, 1, fin
)))
257 if (magic
!= testmagic
)
259 if ((err
= read_short(&version
, 1, fin
)))
261 if (version
!= testversion
)
263 if ((err
= read_int(&(d
->active
), 1, fin
)))
265 if ((err
= read_int(&(d
->type
), 1, fin
)))
267 if ((err
= read_int(&(d
->color
), 1, fin
)))
269 if ((err
= read_int(&(d
->lines
), 1, fin
)))
271 if ((err
= read_int(&(d
->linew
), 1, fin
)))
273 if ((err
= read_int(&(d
->arrowtype
), 1, fin
)))
275 if ((err
= read_int(&(d
->loctype
), 1, fin
)))
277 if ((err
= read_double(&(d
->velx
), 1, fin
)))
279 if ((err
= read_double(&(d
->vely
), 1, fin
)))
281 if ((err
= read_double(&(d
->vscale
), 1, fin
)))
283 if ((err
= read_int(&(d
->units
), 1, fin
)))
285 if ((err
= read_double(&(d
->userlength
), 1, fin
)))
287 if ((err
= read_plotstr(&(d
->vstr
), fin
)))
295 static int read_world(world
* d
, FILE * fin
)
298 short magic
, version
, testmagic
= 26, testversion
= 0;
299 if ((err
= read_short(&magic
, 1, fin
)))
301 if (magic
!= testmagic
)
303 if ((err
= read_short(&version
, 1, fin
)))
305 if (version
!= testversion
)
307 if ((err
= read_double(&(d
->xg1
), 1, fin
)))
309 if ((err
= read_double(&(d
->xg2
), 1, fin
)))
311 if ((err
= read_double(&(d
->yg1
), 1, fin
)))
313 if ((err
= read_double(&(d
->yg2
), 1, fin
)))
321 static int read_view(view
* d
, FILE * fin
)
324 short magic
, version
, testmagic
= 27, testversion
= 0;
325 if ((err
= read_short(&magic
, 1, fin
)))
327 if (magic
!= testmagic
)
329 if ((err
= read_short(&version
, 1, fin
)))
331 if (version
!= testversion
)
333 if ((err
= read_double(&(d
->xv1
), 1, fin
)))
335 if ((err
= read_double(&(d
->xv2
), 1, fin
)))
337 if ((err
= read_double(&(d
->yv1
), 1, fin
)))
339 if ((err
= read_double(&(d
->yv2
), 1, fin
)))
345 * Read type world_stack
347 static int read_world_stack(world_stack
* d
, FILE * fin
)
350 short magic
, version
, testmagic
= 28, testversion
= 0;
351 if ((err
= read_short(&magic
, 1, fin
)))
353 if (magic
!= testmagic
)
355 if ((err
= read_short(&version
, 1, fin
)))
357 if (version
!= testversion
)
359 if ((err
= read_world(&(d
->w
), fin
)))
361 for (i
= 0; i
< 3; i
++) {
362 if ((err
= read_world(&(d
->t
[i
]), fin
)))
371 static int read_labels(labels
* d
, FILE * fin
)
374 short magic
, version
, testmagic
= 29, testversion
= 0;
375 if ((err
= read_short(&magic
, 1, fin
)))
377 if (magic
!= testmagic
)
379 if ((err
= read_short(&version
, 1, fin
)))
381 if (version
!= testversion
)
383 if ((err
= read_plotstr(&(d
->title
), fin
)))
385 if ((err
= read_plotstr(&(d
->stitle
), fin
)))
393 static int read_plotarr(plotarr
* d
, FILE * fin
)
396 int i
, cnt
, ind
, err
= 0;
397 short magic
, version
, testmagic
= 33, testversion
= 0;
398 if ((err
= read_short(&magic
, 1, fin
)))
400 if (magic
!= testmagic
)
402 if ((err
= read_short(&version
, 1, fin
)))
404 if (version
!= testversion
)
406 if ((err
= read_int(&(d
->active
), 1, fin
)))
408 if ((err
= read_int(&(d
->type
), 1, fin
)))
410 if ((err
= read_int(&(d
->deact
), 1, fin
)))
412 if ((err
= read_int(&(d
->len
), 1, fin
)))
414 if ((err
= read_double(&(d
->missing
), 1, fin
)))
416 if ((err
= read_int(&cnt
, 1, fin
)))
418 for (i
= 0; i
< cnt
; i
++) {
419 if ((err
= read_int(&ind
, 1, fin
)))
421 d
->ex
[ind
] = (double *) malloc(d
->len
* sizeof(double));
422 if ((err
= read_double(d
->ex
[ind
], d
->len
, fin
)))
425 if (d
->type
== XYSTRING
) {
426 d
->s
= (char **) malloc(d
->len
* sizeof(char *));
430 for (i
=0;i
<d
->len
;i
++) {
431 if ((err
= read_charstr(buf
, fin
)))
433 d
->s
[i
] = (char *) malloc((strlen(buf
) + 1) * sizeof(char));
434 if (d
->s
[i
] == NULL
) {
437 strcpy(d
->s
[i
], buf
);
440 if ((err
= read_double(&(d
->xmin
), 1, fin
)))
442 if ((err
= read_double(&(d
->xmax
), 1, fin
)))
444 if ((err
= read_double(&(d
->ymin
), 1, fin
)))
446 if ((err
= read_double(&(d
->ymax
), 1, fin
)))
448 if ((err
= read_int(&(d
->sym
), 1, fin
)))
450 if ((err
= read_char(&(d
->symchar
), 1, fin
)))
452 if ((err
= read_int(&(d
->symskip
), 1, fin
)))
454 if ((err
= read_int(&(d
->symfill
), 1, fin
)))
456 if ((err
= read_int(&(d
->symdot
), 1, fin
)))
458 if ((err
= read_int(&(d
->symlines
), 1, fin
)))
460 if ((err
= read_int(&(d
->symlinew
), 1, fin
)))
462 if ((err
= read_int(&(d
->symcolor
), 1, fin
)))
464 if ((err
= read_double(&(d
->symsize
), 1, fin
)))
466 if ((err
= read_int(&(d
->avgflag
), 1, fin
)))
468 if ((err
= read_int(&(d
->avgstdflag
), 1, fin
)))
470 if ((err
= read_int(&(d
->avg2stdflag
), 1, fin
)))
472 if ((err
= read_int(&(d
->avg3stdflag
), 1, fin
)))
474 if ((err
= read_int(&(d
->avgallflag
), 1, fin
)))
476 if ((err
= read_int(&(d
->avgvalflag
), 1, fin
)))
478 if ((err
= read_int(&(d
->harmonicflag
), 1, fin
)))
480 if ((err
= read_int(&(d
->geometricflag
), 1, fin
)))
482 if ((err
= read_int(&(d
->font
), 1, fin
)))
484 if ((err
= read_int(&(d
->format
), 1, fin
)))
486 if ((err
= read_int(&(d
->prec
), 1, fin
)))
488 if ((err
= read_int(&(d
->just
), 1, fin
)))
490 if ((err
= read_int(&(d
->where
), 1, fin
)))
492 if ((err
= read_double(&(d
->valsize
), 1, fin
)))
494 if ((err
= read_int(&(d
->lines
), 1, fin
)))
496 if ((err
= read_int(&(d
->linew
), 1, fin
)))
498 if ((err
= read_int(&(d
->color
), 1, fin
)))
500 if ((err
= read_int(&(d
->lineskip
), 1, fin
)))
502 if ((err
= read_int(&(d
->fill
), 1, fin
)))
504 if ((err
= read_int(&(d
->fillusing
), 1, fin
)))
506 if ((err
= read_int(&(d
->fillcolor
), 1, fin
)))
508 if ((err
= read_int(&(d
->fillpattern
), 1, fin
)))
510 if ((err
= read_int(&(d
->errbar
), 1, fin
)))
512 if ((err
= read_int(&(d
->errbarxy
), 1, fin
)))
514 if ((err
= read_int(&(d
->errbar_linew
), 1, fin
)))
516 if ((err
= read_int(&(d
->errbar_lines
), 1, fin
)))
518 if ((err
= read_int(&(d
->errbar_riser
), 1, fin
)))
520 if ((err
= read_int(&(d
->errbar_riser_linew
), 1, fin
)))
522 if ((err
= read_int(&(d
->errbar_riser_lines
), 1, fin
)))
524 if ((err
= read_double(&(d
->errbarper
), 1, fin
)))
526 if ((err
= read_double(&(d
->hilowper
), 1, fin
)))
528 if ((err
= read_int(&(d
->density_plot
), 1, fin
)))
530 if ((err
= read_double(&(d
->zmin
), 1, fin
)))
532 if ((err
= read_double(&(d
->zmax
), 1, fin
)))
534 if ((err
= read_charstr(d
->comments
, fin
)))
536 if ((err
= read_charstr(d
->lstr
, fin
)))
538 if ((err
= read_int(&(d
->hotlink
), 1, fin
)))
540 if ((err
= read_int(&(d
->hotsrc
), 1, fin
)))
542 if ((err
= read_charstr(d
->hotfile
, fin
)))
544 if ((err
= read_double(d
->emin
, 6, fin
)))
546 if ((err
= read_double(d
->emax
, 6, fin
)))
548 if ((err
= read_int(d
->imin
, 6, fin
)))
550 if ((err
= read_int(d
->imax
, 6, fin
)))
552 /* TODO for (i = 0; i < 0; i++) {
553 if ((err = read_Regression(d->r, fin))) return err;
555 TODO for (i = 0; i < 0; i++) {
556 if ((err = read_Spline(d->spl, fin))) return err;
562 * Read type tickmarks
564 static int read_tickmarks(tickmarks
* d
, FILE * fin
)
567 short magic
, version
, testmagic
= 34, testversion
= 0;
568 if ((err
= read_short(&magic
, 1, fin
)))
570 if (magic
!= testmagic
)
572 if ((err
= read_short(&version
, 1, fin
)))
574 if (version
!= testversion
)
576 if ((err
= read_int(&(d
->axis
), 1, fin
)))
578 if ((err
= read_int(&(d
->active
), 1, fin
)))
580 if ((err
= read_int(&(d
->alt
), 1, fin
)))
582 if ((err
= read_double(&(d
->tmin
), 1, fin
)))
584 if ((err
= read_double(&(d
->tmax
), 1, fin
)))
586 if ((err
= read_double(&(d
->tmajor
), 1, fin
)))
588 if ((err
= read_double(&(d
->tminor
), 1, fin
)))
590 if ((err
= read_double(&(d
->offsx
), 1, fin
)))
592 if ((err
= read_double(&(d
->offsy
), 1, fin
)))
594 if ((err
= read_plotstr(&(d
->label
), fin
)))
596 if ((err
= read_int(&(d
->label_layout
), 1, fin
)))
598 if ((err
= read_int(&(d
->label_place
), 1, fin
)))
600 if ((err
= read_int(&(d
->tl_flag
), 1, fin
)))
602 if ((err
= read_int(&(d
->tl_type
), 1, fin
)))
604 if ((err
= read_int(&(d
->tl_layout
), 1, fin
)))
606 if ((err
= read_int(&(d
->tl_angle
), 1, fin
)))
608 if ((err
= read_int(&(d
->tl_sign
), 1, fin
)))
610 if ((err
= read_int(&(d
->tl_just
), 1, fin
)))
612 if ((err
= read_int(&(d
->tl_prec
), 1, fin
)))
614 if ((err
= read_int(&(d
->tl_format
), 1, fin
)))
616 if ((err
= read_int(&(d
->tl_skip
), 1, fin
)))
618 if ((err
= read_int(&(d
->tl_staggered
), 1, fin
)))
620 if ((err
= read_int(&(d
->tl_starttype
), 1, fin
)))
622 if ((err
= read_int(&(d
->tl_stoptype
), 1, fin
)))
624 if ((err
= read_double(&(d
->tl_start
), 1, fin
)))
626 if ((err
= read_double(&(d
->tl_stop
), 1, fin
)))
628 if ((err
= read_int(&(d
->tl_op
), 1, fin
)))
630 if ((err
= read_double(&(d
->tl_vgap
), 1, fin
)))
632 if ((err
= read_double(&(d
->tl_hgap
), 1, fin
)))
634 if ((err
= read_int(&(d
->tl_font
), 1, fin
)))
636 if ((err
= read_double(&(d
->tl_charsize
), 1, fin
)))
638 if ((err
= read_int(&(d
->tl_color
), 1, fin
)))
640 if ((err
= read_int(&(d
->tl_linew
), 1, fin
)))
642 if ((err
= read_charstr(d
->tl_appstr
, fin
)))
644 if ((err
= read_charstr(d
->tl_prestr
, fin
)))
646 if ((err
= read_int(&(d
->t_type
), 1, fin
)))
648 if ((err
= read_int(&(d
->t_flag
), 1, fin
)))
650 if ((err
= read_int(&(d
->t_mflag
), 1, fin
)))
652 if ((err
= read_int(&(d
->t_integer
), 1, fin
)))
654 if ((err
= read_int(&(d
->t_num
), 1, fin
)))
656 if ((err
= read_int(&(d
->t_inout
), 1, fin
)))
658 if ((err
= read_int(&(d
->t_log
), 1, fin
)))
660 if ((err
= read_int(&(d
->t_op
), 1, fin
)))
662 if ((err
= read_int(&(d
->t_color
), 1, fin
)))
664 if ((err
= read_int(&(d
->t_lines
), 1, fin
)))
666 if ((err
= read_int(&(d
->t_linew
), 1, fin
)))
668 if ((err
= read_int(&(d
->t_mcolor
), 1, fin
)))
670 if ((err
= read_int(&(d
->t_mlines
), 1, fin
)))
672 if ((err
= read_int(&(d
->t_mlinew
), 1, fin
)))
674 if ((err
= read_double(&(d
->t_size
), 1, fin
)))
676 if ((err
= read_double(&(d
->t_msize
), 1, fin
)))
678 if ((err
= read_int(&(d
->t_drawbar
), 1, fin
)))
680 if ((err
= read_int(&(d
->t_drawbarcolor
), 1, fin
)))
682 if ((err
= read_int(&(d
->t_drawbarlines
), 1, fin
)))
684 if ((err
= read_int(&(d
->t_drawbarlinew
), 1, fin
)))
686 if ((err
= read_int(&(d
->t_gridflag
), 1, fin
)))
688 if ((err
= read_int(&(d
->t_mgridflag
), 1, fin
)))
690 if ((err
= read_int(&(d
->t_spec
), 1, fin
)))
692 if ((err
= read_int(&cnt
, 1, fin
)))
694 if ((err
= read_double(d
->t_specloc
, cnt
, fin
)))
696 for (i
= 0; i
< cnt
; i
++) {
697 if ((err
= read_plotstr(&(d
->t_speclab
[i
]), fin
)))
700 if ((err
= read_int(&(d
->spec_font
), 1, fin
)))
702 if ((err
= read_double(&(d
->spec_charsize
), 1, fin
)))
704 if ((err
= read_int(&(d
->spec_color
), 1, fin
)))
706 if ((err
= read_int(&(d
->spec_linew
), 1, fin
)))
714 static int read_legend(legend
* d
, FILE * fin
)
717 short magic
, version
, testmagic
= 36, testversion
= 0;
718 if ((err
= read_short(&magic
, 1, fin
)))
720 if (magic
!= testmagic
)
722 if ((err
= read_short(&version
, 1, fin
)))
724 if (version
!= testversion
)
726 if ((err
= read_int(&(d
->active
), 1, fin
)))
728 if ((err
= read_int(&(d
->loctype
), 1, fin
)))
730 if ((err
= read_int(&(d
->layout
), 1, fin
)))
732 if ((err
= read_int(&(d
->vgap
), 1, fin
)))
734 if ((err
= read_int(&(d
->hgap
), 1, fin
)))
736 if ((err
= read_int(&(d
->len
), 1, fin
)))
738 if ((err
= read_int(&(d
->box
), 1, fin
)))
740 if ((err
= read_double(&(d
->legx
), 1, fin
)))
742 if ((err
= read_double(&(d
->legy
), 1, fin
)))
744 if ((err
= read_int(&(d
->font
), 1, fin
)))
746 if ((err
= read_double(&(d
->charsize
), 1, fin
)))
748 if ((err
= read_int(&(d
->color
), 1, fin
)))
750 if ((err
= read_int(&(d
->linew
), 1, fin
)))
752 if ((err
= read_int(&(d
->lines
), 1, fin
)))
754 if ((err
= read_int(&(d
->boxfill
), 1, fin
)))
756 if ((err
= read_int(&(d
->boxfillusing
), 1, fin
)))
758 if ((err
= read_int(&(d
->boxfillcolor
), 1, fin
)))
760 if ((err
= read_int(&(d
->boxfillpat
), 1, fin
)))
762 if ((err
= read_int(&(d
->boxlcolor
), 1, fin
)))
764 if ((err
= read_int(&(d
->boxlinew
), 1, fin
)))
766 if ((err
= read_int(&(d
->boxlines
), 1, fin
)))
774 static int read_framep(framep
* d
, FILE * fin
)
777 short magic
, version
, testmagic
= 38, testversion
= 0;
778 if ((err
= read_short(&magic
, 1, fin
)))
780 if (magic
!= testmagic
)
782 if ((err
= read_short(&version
, 1, fin
)))
784 if (version
!= testversion
)
786 if ((err
= read_int(&(d
->active
), 1, fin
)))
788 if ((err
= read_int(&(d
->type
), 1, fin
)))
790 if ((err
= read_int(&(d
->color
), 1, fin
)))
792 if ((err
= read_int(&(d
->lines
), 1, fin
)))
794 if ((err
= read_int(&(d
->linew
), 1, fin
)))
796 if ((err
= read_int(&(d
->fillbg
), 1, fin
)))
798 if ((err
= read_int(&(d
->bgcolor
), 1, fin
)))
806 static int read_BoxPlot(BoxPlot
* d
, FILE * fin
)
809 short magic
, version
, testmagic
= 39, testversion
= 0;
810 if ((err
= read_short(&magic
, 1, fin
)))
812 if (magic
!= testmagic
)
814 if ((err
= read_short(&version
, 1, fin
)))
816 if (version
!= testversion
)
818 if ((err
= read_double(&(d
->il
), 1, fin
)))
820 if ((err
= read_double(&(d
->iu
), 1, fin
)))
822 if ((err
= read_double(&(d
->ol
), 1, fin
)))
824 if ((err
= read_double(&(d
->ou
), 1, fin
)))
826 if ((err
= read_int(&(d
->nthresh
), 1, fin
)))
828 if ((err
= read_int(&(d
->outliers
), 1, fin
)))
830 if ((err
= read_int(&(d
->wtype
), 1, fin
)))
832 if ((err
= read_double(&(d
->boxwid
), 1, fin
)))
840 int read_graph(graph
* d
, FILE * fin
)
842 int i
, cnt
, ind
, err
= 0;
843 short magic
, version
, testmagic
= 40, testversion
= 0;
844 if ((err
= read_short(&magic
, 1, fin
)))
846 if (magic
!= testmagic
)
848 if ((err
= read_short(&version
, 1, fin
)))
850 if (version
!= testversion
)
852 if ((err
= read_int(&(d
->active
), 1, fin
)))
854 if ((err
= read_int(&(d
->hidden
), 1, fin
)))
856 if ((err
= read_int(&(d
->label
), 1, fin
)))
858 if ((err
= read_int(&(d
->type
), 1, fin
)))
860 if ((err
= read_int(&(d
->noauto_world
), 1, fin
)))
862 if ((err
= read_int(&(d
->noauto_tics
), 1, fin
)))
864 if ((err
= read_int(&(d
->auto_type
), 1, fin
)))
866 if ((err
= read_int(&(d
->parmsread
), 1, fin
)))
869 /* parmsread must be assumed to be true when read from a binary file */
870 /* (we don't erase the above 2 lines for the sake of compatibility) */
873 if ((err
= read_int(&(d
->revx
), 1, fin
)))
875 if ((err
= read_int(&(d
->revy
), 1, fin
)))
877 if ((err
= read_int(&(d
->maxplot
), 1, fin
)))
880 if ((err
= read_int(&cnt
, 1, fin
)))
882 for (i
= 0; i
< cnt
; i
++) {
883 if ((err
= read_int(&ind
, 1, fin
)))
885 if ((err
= read_plotarr(&(d
->p
[ind
]), fin
))) {
890 if ((err
= read_legend(&(d
->l
), fin
))) {
893 if ((err
= read_world(&(d
->w
), fin
)))
895 if ((err
= read_view(&(d
->v
), fin
)))
897 if ((err
= read_world(&(d
->rt
), fin
)))
899 if ((err
= read_labels(&(d
->labs
), fin
)))
901 for (i
= 0; i
< 4; i
++) {
902 if ((err
= read_tickmarks(&(d
->t
[i
]), fin
)))
905 if ((err
= read_framep(&(d
->f
), fin
)))
907 if ((err
= read_int(&(d
->pointset
), 1, fin
)))
909 if ((err
= read_int(&(d
->pt_type
), 1, fin
)))
911 if ((err
= read_double(&(d
->dsx
), 1, fin
)))
913 if ((err
= read_double(&(d
->dsy
), 1, fin
)))
915 if ((err
= read_int(&(d
->fx
), 1, fin
)))
917 if ((err
= read_int(&(d
->fy
), 1, fin
)))
919 if ((err
= read_int(&(d
->px
), 1, fin
)))
921 if ((err
= read_int(&(d
->py
), 1, fin
)))
923 if ((err
= read_int(&(d
->ws_top
), 1, fin
)))
925 for (i
= 0; i
< d
->ws_top
; i
++) {
926 if ((err
= read_world_stack(&(d
->ws
[i
]), fin
)))
930 /* add this for compatability issues */
934 if ((err
= read_int(&(d
->curw
), 1, fin
)))
936 if ((err
= read_velocityp(&(d
->vp
), fin
)))
938 if ((err
= read_BoxPlot(&(d
->bp
), fin
)))
943 void open_xdr(FILE *fp
, int rw
) /* rw write = 0, read = 1 */
946 xdrstdio_create(&xdrs
, fp
, XDR_ENCODE
);
948 xdrstdio_create(&xdrs
, fp
, XDR_DECODE
);
959 int read_double(double *d
, int n
, FILE * fp
)
962 if (n
<= 0) return 0;
963 err
= xdr_vector(&xdrs
, (char *) d
, n
, sizeof(double), (xdrproc_t
) xdr_double
);
964 return err
? 0 : err
;
968 int read_int(int *d
, int n
, FILE * fp
)
971 if (n
<= 0) return 0;
972 err
= xdr_vector(&xdrs
, (char *) d
, n
, sizeof(int), (xdrproc_t
) xdr_int
);
973 return err
? 0 : err
;
976 int read_charstr(char *d
, FILE * fp
)
981 err
= xdr_vector(&xdrs
, (char *) d
, n
, sizeof(char), (xdrproc_t
) xdr_char
);
982 return err
? 0 : err
;
985 int read_char(char *d
, int n
, FILE * fp
)
988 if (n
<= 0) return 0;
989 err
= xdr_vector(&xdrs
, (char *) d
, n
, sizeof(char), (xdrproc_t
) xdr_char
);
990 return err
? 0 : err
;
993 int read_short(short *d
, int n
, FILE * fp
)
996 if (n
<= 0) return 0;
997 err
= xdr_vector(&xdrs
, (char *) d
, n
, sizeof(short), (xdrproc_t
) xdr_short
);
998 return err
? 0 : err
;
1001 int read_float(float *d
, int n
, FILE * fp
)
1004 if (n
<= 0) return 0;
1005 err
= xdr_vector(&xdrs
, (char *) d
, n
, sizeof(float), (xdrproc_t
) xdr_float
);
1006 return err
? 0 : err
;
1009 int replace_xdr_int( int *i
)
1012 xdr_setpos( &xdrs
, xdr_getpos( &xdrs
)-4 );
1013 err
= xdr_vector(&xdrs
, (char *) i
, 1, sizeof(int), (xdrproc_t
) xdr_int
);
1014 xdr_setpos( &xdrs
, xdr_getpos( &xdrs
)-4 );
1015 return err
? 0: err
;
1018 int replace_xdr_short( short *i
)
1021 xdr_setpos( &xdrs
, xdr_getpos( &xdrs
)-4 );
1022 err
= xdr_vector(&xdrs
, (char *) i
, 1, sizeof(short), (xdrproc_t
) xdr_short
);
1023 xdr_setpos( &xdrs
, xdr_getpos( &xdrs
)-4 );
1024 return err
? 0: err
;
1030 * write state information
1032 #define PARMS_MAGIC 1002003
1033 #define HEADERLENGTH 64
1036 int is_state_save(char *fname
)
1038 int magic
, clen
, slen
, ilen
, flen
, dlen
;
1040 char ver
[64], ord
[64], math
[64], name
[64];
1042 if ((fp
= fopen(fname
, "r")) == NULL
) {
1045 open_xdr(fp
, 1); /* open XDR stream */
1046 read_char(buf
, HEADERLENGTH
, fp
);
1047 buf
[HEADERLENGTH
- 1] = 0;
1048 sscanf(buf
, "%d %s %s %s %s %d %d %d %d %d",
1049 &magic
, ver
, ord
, math
, name
, &clen
, &slen
, &ilen
, &flen
, &dlen
);
1052 return (magic
== PARMS_MAGIC
) ? 1 : 0;
1056 * getbinary - read in binary project file
1059 * 1 - nothing read in
1062 int getbinary(int gno
, char *fname
, int imbed
)
1064 int ind
, i
, k
, cnt
, ng
, magic
;
1065 int clen
, slen
, ilen
, flen
, dlen
, nblocks
;
1067 char ver
[64], ord
[64], math
[64], name
[64];
1069 if ((pp
= fopen(fname
, "rb")) == NULL
) {
1070 sprintf(buf
, "Can't open project file %s", fname
);
1074 strcpy( docname
, fname
);
1075 open_xdr(pp
, 1); /* open XDR stream */
1076 read_char(buf
, HEADERLENGTH
, pp
);
1077 buf
[HEADERLENGTH
- 1] = 0;
1078 sscanf(buf
, "%d %s %s %s %s %d %d %d %d %d",
1079 &magic
, ver
, ord
, math
, name
, &clen
, &slen
, &ilen
, &flen
, &dlen
);
1080 if (magic
!= PARMS_MAGIC
) {
1081 errmsg("Bad magic in project file");
1085 read_int(&cnt
, 1, pp
);
1086 for (k
= 0; k
< cnt
; k
++) {
1087 read_int(&ng
, 1, pp
);
1088 if (read_graph(&g
[ng
], pp
)) {
1089 errmsg("Error reading project file (graphs), cancelled");
1094 read_int(&cnt
, 1, pp
);
1095 for (k
= 0; k
< cnt
; k
++) {
1096 read_int(&ind
, 1, pp
);
1097 if (read_linetype(&lines
[ind
], pp
)) {
1098 errmsg("Error reading project file (lines), cancelled");
1102 lines
[ind
].active
= ON
;
1104 read_int(&cnt
, 1, pp
);
1105 for (k
= 0; k
< cnt
; k
++) {
1106 read_int(&ind
, 1, pp
);
1107 if (read_boxtype(&boxes
[ind
], pp
)) {
1108 errmsg("Error reading project file (boxes), cancelled");
1112 boxes
[ind
].active
= ON
;
1114 read_int(&cnt
, 1, pp
);
1115 for (k
= 0; k
< cnt
; k
++) {
1116 read_int(&ind
, 1, pp
);
1117 switch(read_ellipsetype(&ellip
[ind
], pp
)) {
1119 ellip
[ind
].active
= ON
;
1122 /* assume error from reading pre-ellipse file so put things
1124 if( replace_xdr_int( &ind
) || replace_xdr_int( &cnt
) ) {
1125 errmsg("Error reading project file (ellipses), cancelled");
1129 k
= cnt
; /* end loop */
1132 errmsg("Error reading project file (plotstr), cancelled");
1137 read_int(&cnt
, 1, pp
);
1138 for (k
= 0; k
< cnt
; k
++) {
1139 read_int(&ind
, 1, pp
);
1140 if (read_plotstr(&pstr
[ind
], pp
)) {
1141 errmsg("Error reading project file (plotstr), cancelled");
1146 /* read block data */
1147 read_int(&nblocks
, 1, pp
);
1149 read_int(&blocklen
, 1, pp
);
1150 read_int(&blockncols
, 1, pp
);
1151 for (i
= 0; i
< blockncols
; i
++) {
1152 read_int(&ind
, 1, pp
); /* TODO need to fix this malloc business */
1153 blockdata
[ind
] = (double *) malloc(sizeof(double) * blocklen
);
1154 read_double(blockdata
[ind
], blocklen
, pp
);
1157 /* read description */
1158 if( read_charstr( description
, pp
) )
1159 strcpy( description
, "Just a typical project I assume" );
1160 if( read_int(&page_layout
, 1, pp
))