Jspice3
rawfile.c File Reference
#include "spice.h"
#include "ftedefs.h"
Include dependency graph for rawfile.c:

Go to the source code of this file.

Macros

#define DEFPREC   15
 
#define skip(s)   while (*(s) && !isspace(*(s)))(s)++; while (isspace(*(s)))(s)++
 
#define nonl(s)   r = (s); while (*r && (*r != '\n')) r++; *r = '\0'
 

Functions

static void fixdims ()
 
static char * dimstring ()
 
static int atodims ()
 
void raw_write (char *name, struct plot *pl, bool app, bool binary)
 
struct plotraw_read (char *name)
 
static void fixdims (struct dvec *v, char *s)
 
static char * dimstring (int *data, int length, char *buf)
 
static int atodims (char *p, int *data, int *outlength)
 

Variables

int raw_prec = -1
 

Macro Definition Documentation

#define DEFPREC   15

Definition at line 28 of file rawfile.c.

#define nonl (   s)    r = (s); while (*r && (*r != '\n')) r++; *r = '\0'

Definition at line 269 of file rawfile.c.

#define skip (   s)    while (*(s) && !isspace(*(s)))(s)++; while (isspace(*(s)))(s)++

Definition at line 268 of file rawfile.c.

Function Documentation

static int atodims ( )
static
static int atodims ( char *  p,
int *  data,
int *  outlength 
)
static

Definition at line 731 of file rawfile.c.

751 {
752  int length = 0;
753  int state = 0;
754  int err = 0;
755  int needbracket = 0;
756  char sep = '\0';
757 
758  if (!data || !outlength)
759  return (1);
760 
761  if (!p) {
762  *outlength = 0;
763  return (0);
764  }
765 
766  while (*p && isspace(*p))
767  p++;
768 
769  if (*p == '[') {
770  p++;
771  while (*p && isspace(*p))
772  p++;
773  needbracket = 1;
774  }
775 
776  while (*p && state != 3) {
777  switch (state) {
778  case 0: /* p just at or before a number */
779  if (length >= MAXDIMS) {
780  if (length == MAXDIMS)
781  printf("Error: maximum of %d dimensions allowed.\n",
782  MAXDIMS);
783  length += 1;
784  }
785  else if (!isdigit(*p)) {
786  data[length++] = 0; /* This position was empty. */
787  }
788  else {
789  data[length++] = atoi(p);
790  while (isdigit(*p))
791  p++;
792  }
793  state = 1;
794  break;
795 
796  case 1: /* p after a number, looking for ',' or ']' */
797  if (sep == '\0') {
798  sep = *p;
799  }
800  if (*p == ']' && *p == sep) {
801  p++;
802  state = 2;
803  }
804  else if (*p == ',' && *p == sep) {
805  p++;
806  state = 0;
807  }
808  else /* Funny character following a # */
809  break;
810  break;
811 
812  case 2: /* p after a ']', either at the end or looking for '[' */
813  if (*p == '[') {
814  p++;
815  state = 0;
816  }
817  else {
818  state = 3;
819  }
820  break;
821  }
822 
823  while (*p && isspace(*p))
824  p++;
825  }
826 
827  *outlength = length;
828  if (length > MAXDIMS) {
829  return (1);
830  }
831  if (state == 3) { /* We finished with a closing bracket */
832  err = !needbracket;
833  }
834  else if (*p) { /* We finished by hitting a bad character after a # */
835  err = 1;
836  }
837  else { /* We finished by exhausting the string */
838  err = needbracket;
839  }
840  if (err) {
841  *outlength = 0;
842  }
843  return (err);
844 }
FILE * p
Definition: proc2mod.c:48
Definition: cddefs.h:215
#define MAXDIMS
Definition: ftedata.h:22
Definition: mfb.h:383
static char* dimstring ( )
static
static char* dimstring ( int *  data,
int  length,
char *  buf 
)
static

Definition at line 706 of file rawfile.c.

714 {
715  int i;
716 
717  buf[0] = '\0';
718 
719  if (!data || length < 1)
720  return (buf);
721 
722  for (i = 0; i < length; i++) {
723  sprintf(buf + strlen(buf), "%d%s", data[i],
724  (i < length - 1) ? "," : "");
725  }
726  return (buf);
727 }
static char buf[MAXPROMPT]
Definition: arg.c:18
static void fixdims ( )
static
static void fixdims ( struct dvec v,
char *  s 
)
static

Definition at line 691 of file rawfile.c.

696 {
697  if (atodims(s, v->v_dims, &(v->v_numdims)))
698  /* Something's wrong. */
699  fprintf(cp_err,
700  "Warning: syntax error in dimensions, ignored.\n");
701  return;
702 }
static int atodims()
Definition: cddefs.h:119
int v_dims[MAXDIMS]
Definition: ftedata.h:41
FILE * cp_err
Definition: help.c:101
int v_numdims
Definition: ftedata.h:40
struct plot* raw_read ( char *  name)

Definition at line 272 of file rawfile.c.

275 {
276  char *title = "default title";
277  char *date = 0;
278  struct plot *plots = NULL, *curpl = NULL;
279  char buf[BSIZE_SP], buf2[BSIZE_SP], *s, *t, *r;
280  int flags, nvars, npoints, i, j;
281  int numdims = 0, dims[MAXDIMS];
282  struct dvec *v, *nv;
283  struct variable *vv;
284  wordlist *wl, *nwl;
285  FILE *fp, *lastin, *lastout, *lasterr;
286  bool raw_padded = true;
287  double junk;
288  char *errbr = "Error: bad rawfile\n";
289 
290  if (!(fp = fopen(name, "r"))) {
291  perror(name);
292  return (NULL);
293  }
294 
295  /* Since we call cp_evloop() from here, we have to do this junk. */
296  lastin = cp_curin;
297  lastout = cp_curout;
298  lasterr = cp_curerr;
299  cp_curin = cp_in;
300  cp_curout = cp_out;
301  cp_curerr = cp_err;
302 
303  cp_pushcontrol();
304 
305  while (fgets(buf, BSIZE_SP, fp)) {
306  /* Figure out what this line is... */
307  if (ciprefix("title:", buf)) {
308  s = buf;
309  skip(s);
310  nonl(s);
311  title = copy(s);
312  }
313  else if (ciprefix("date:", buf)) {
314  s = buf;
315  skip(s);
316  nonl(s);
317  date = copy(s);
318  }
319  else if (ciprefix("plotname:", buf)) {
320  s = buf;
321  skip(s);
322  nonl(s);
323  if (curpl) { /* reverse commands list */
324  for (wl=curpl->pl_commands,
325  curpl->pl_commands=NULL; wl &&
326  wl->wl_next; wl=nwl) {
327  nwl = wl->wl_next;
328  wl->wl_next = curpl->pl_commands;
329  curpl->pl_commands = wl;
330  }
331  }
332  curpl = alloc(struct plot);
333  curpl->pl_next = plots;
334  plots = curpl;
335  curpl->pl_name = copy(s);
336  if (!date)
337  date = copy(datestring( ));
338  curpl->pl_date = date;
339  curpl->pl_title = title;
340  flags = 0;
341  nvars = npoints = 0;
342  }
343  else if (ciprefix("flags:", buf)) {
344  s = buf;
345  skip(s);
346  while (copytok(buf2,&s)) {
347  if (cieq(buf2, "real"))
348  flags |= VF_REAL;
349  else if (cieq(buf2, "complex"))
350  flags |= VF_COMPLEX;
351  else if (cieq(buf2, "unpadded"))
352  raw_padded = false;
353  else if (cieq(buf2, "padded"))
354  raw_padded = true;
355  else
356  fprintf(cp_err,
357  "Warning: unknown flag %s\n",buf2);
358  }
359  }
360  else if (ciprefix("no. variables:", buf)) {
361  s = buf;
362  skip(s);
363  skip(s);
364  nvars = scannum(s);
365  }
366  else if (ciprefix("no. points:", buf)) {
367  s = buf;
368  skip(s);
369  skip(s);
370  npoints = scannum(s);
371  }
372  else if (ciprefix("dimensions:", buf)) {
373  if (npoints == 0) {
374  fprintf(cp_err,
375  "Error: misplaced Dimensions: line\n");
376  continue;
377  }
378  s = buf;
379  skip(s);
380  if (atodims(s, dims, &numdims)) { /* Something's wrong. */
381  fprintf(cp_err,
382  "Warning: syntax error in dimensions, ignored.\n");
383  numdims = 0;
384  continue;
385  }
386  if (numdims > MAXDIMS) {
387  numdims = 0;
388  continue;
389  }
390  /* Let's just make sure that the no. of points
391  * and the dimensions are consistent.
392  */
393  for (j = 0, i = 1; j < numdims; j++) {
394  i *= dims[j];
395  }
396 
397  if (i != npoints) {
398  fprintf(cp_err,
399  "Warning: dimensions inconsistent with no. of points, ignored.\n");
400  numdims = 0;
401  }
402  }
403  else if (ciprefix("command:", buf)) {
404  /* Note that we reverse these commands eventually... */
405  s = buf;
406  skip(s);
407  nonl(s);
408  if (curpl) {
409  wl = alloc(struct wordlist);
410  wl->wl_word = copy(s);
411  wl->wl_next = curpl->pl_commands;
412  if (curpl->pl_commands)
413  curpl->pl_commands->wl_prev = wl;
414  curpl->pl_commands = wl;
415  }
416  else
417  fprintf(cp_err,
418  "Error: misplaced Command: line\n");
419  /* Now execute the command if we can. */
420  (void) cp_evloop(s);
421  }
422  else if (ciprefix("option:", buf)) {
423  s = buf;
424  skip(s);
425  nonl(s);
426  if (curpl) {
427  wl = cp_lexer(s);
428  for (vv = curpl->pl_env; vv && vv->va_next;
429  vv = vv->va_next)
430  ;
431  if (vv)
432  vv->va_next = cp_setparse(wl);
433  else
434  curpl->pl_env = cp_setparse(wl);
435  wl_free(wl);
436  }
437  else
438  fprintf(cp_err,
439  "Error: misplaced Command: line\n");
440  }
441  else if (ciprefix("variables:", buf)) {
442  /* We reverse the dvec list eventually... */
443  if (!curpl) {
444  fprintf(cp_err, "Error: no plot name given\n");
445  plots = NULL;
446  break;
447  }
448  s = buf;
449  skip(s);
450  if (!*s) {
451  (void) fgets(buf, BSIZE_SP, fp);
452  s = buf;
453  }
454  if (numdims == 0) {
455  numdims = 1;
456  dims[0] = npoints;
457  }
458  /* Now read all the variable lines in. */
459  for (i = 0; i < nvars; i++) {
460  v = alloc(struct dvec);
461  v->v_next = curpl->pl_dvecs;
462  curpl->pl_dvecs = v;
463  if (!curpl->pl_scale)
464  curpl->pl_scale = v;
465  v->v_flags = flags;
466  v->v_plot = curpl;
467 
468  v->v_length = npoints;
469  v->v_numdims = 0;
470  /* Length and dims might be changed by options. */
471 
472  if (!i)
473  curpl->pl_scale = v;
474  else {
475  (void) fgets(buf, BSIZE_SP, fp);
476  s = buf;
477  }
478  advtok(&s); /* The index field. */
479  if (t = gettok(&s))
480  v->v_name = t;
481  else
482  fprintf(cp_err,
483  "Error: bad var line %s\n", buf);
484  t = gettok(&s); /* The type name. */
485  if (t) {
486  v->v_type = ft_typnum(t);
487  txfree(t);
488  }
489  else
490  fprintf(cp_err,
491  "Error: bad var line %s\n", buf);
492 
493  /* Fix the name... */
494  if (isdigit(*v->v_name) &&
495  (r = ft_typabbrev(v->v_type))) {
496  (void) sprintf(buf2, "%s(%s)", r, v->v_name);
497  v->v_name = copy(buf2);
498  }
499  /* Now come the strange options... */
500  while (copytok(buf2,&s)) {
501  if (ciprefix("min=", buf2)) {
502  if (sscanf(buf2 + 4, "%lf",&v->v_minsignal) != 1)
503  fprintf(cp_err, "Error: bad arg %s\n", buf2);
504  v->v_flags |= VF_MINGIVEN;
505  }
506  else if (ciprefix("max=", buf2)) {
507  if (sscanf(buf2 + 4, "%lf",&v->v_maxsignal) != 1)
508  fprintf(cp_err, "Error: bad arg %s\n", buf2);
509  v->v_flags |= VF_MAXGIVEN;
510  }
511  else if (ciprefix("color=", buf2)) {
512  v->v_defcolor = copy(buf2 + 6);
513  }
514  else if (ciprefix("scale=", buf2)) {
515  /* This is bad, but... */
516  v->v_scale = (struct dvec *) copy(buf2 + 6);
517  }
518  else if (ciprefix("grid=", buf2)) {
519  v->v_gridtype = (GRIDTYPE) scannum(buf2 + 5);
520  }
521  else if (ciprefix("plot=", buf2)) {
522  v->v_plottype = (PLOTTYPE) scannum(buf2 + 5);
523  }
524  else if (ciprefix("dims=", buf2)) {
525  fixdims(v, buf2 + 5);
526  }
527  else {
528  fprintf(cp_err,"Warning: bad var param %s\n", buf2);
529  }
530  }
531 
532  /* Now we default any missing dimensions. */
533  if (!v->v_numdims) {
534  v->v_numdims = numdims;
535  for (j = 0; j < numdims; j++)
536  v->v_dims[j] = dims[j];
537  }
538  /* And allocate the data array. We would use
539  * the desired vector length, but this would
540  * be dangerous if the file is invalid.
541  */
542 
543  if (isreal(v))
544  v->v_realdata =
545  (double *) tmalloc(npoints * sizeof (double));
546  else
547  v->v_compdata =
548  (complex *) tmalloc(npoints * sizeof (complex));
549  }
550  }
551  else if (ciprefix("values:", buf) ||
552  ciprefix("binary:", buf)) {
553  if (!curpl) {
554  fprintf(cp_err, "Error: no plot name given\n");
555  plots = NULL;
556  break;
557  }
558  /* We'd better reverse the dvec list now... */
559  for (v = curpl->pl_dvecs, curpl->pl_dvecs = NULL; v;
560  v = nv) {
561  nv = v->v_next;
562  v->v_next = curpl->pl_dvecs;
563  curpl->pl_dvecs = v;
564  }
565  /* And fix the scale pointers. */
566  for (v = curpl->pl_dvecs; v; v = v->v_next) {
567  if (v->v_scale) {
568  for (nv = curpl->pl_dvecs; nv; nv = nv->v_next)
569  if (cieq((char *) v->v_scale, nv->v_name)) {
570  v->v_scale = nv;
571  break;
572  }
573  if (!nv) {
574  fprintf(cp_err,"Error: no such vector %s\n",
575  (char *) v->v_scale);
576  v->v_scale = NULL;
577  }
578  }
579  }
580  for (i = 0; i < npoints; i++) {
581  if ((*buf == 'v') || (*buf == 'V')) {
582  /* It's an ASCII file. */
583  (void) fscanf(fp, " %d", &j);
584  for (v = curpl->pl_dvecs; v; v = v->v_next) {
585  if (i < v->v_length) {
586  if (flags & VF_REAL) {
587  if (fscanf(fp, " %lf",
588  &v->v_realdata[i]) != 1)
589  fprintf(cp_err, errbr);
590  }
591  else {
592  if (fscanf(fp, " %lf, %lf",
593  &realpart(&v->v_compdata[i]),
594  &imagpart(&v->v_compdata[i])) != 2)
595  fprintf(cp_err, errbr);
596  }
597  }
598  else if (raw_padded) {
599  if (flags & VF_REAL) {
600  if (fscanf(fp, " %lf", &junk) != 1)
601  fprintf(cp_err, errbr);
602  }
603  else {
604  if (fscanf(fp, " %lf, %lf",
605  &junk, &junk) != 2)
606  fprintf(cp_err, errbr);
607  }
608  }
609  }
610  }
611  else {
612  /* It's a Binary file. */
613  for (v = curpl->pl_dvecs; v; v = v->v_next) {
614  if (i < v->v_length) {
615  if (flags & VF_REAL) {
616  if (fread((char *) &v->v_realdata[i],
617  sizeof (double), 1, fp) != 1)
618  fprintf(cp_err, errbr);
619  }
620  else {
621  if (fread((char *) &v->v_compdata[i].
622  cx_real, sizeof (double), 1, fp) != 1)
623  fprintf(cp_err, errbr);
624  if (fread((char *) &v->v_compdata[i].
625  cx_imag, sizeof (double), 1, fp) != 1)
626  fprintf(cp_err, errbr);
627  }
628  }
629  else if (raw_padded) {
630  if (flags & VF_REAL) {
631  if (fread((char *) &junk,
632  sizeof (double), 1, fp) != 1)
633  fprintf(cp_err, errbr);
634  }
635  else {
636  if (fread((char *) &junk,
637  sizeof (double), 1, fp) != 1)
638  fprintf(cp_err, errbr);
639  if (fread((char *) &junk,
640  sizeof (double), 1, fp) != 1)
641  fprintf(cp_err, errbr);
642  }
643  }
644  }
645  }
646  }
647  }
648  else {
649  s = buf;
650  skip(s);
651  if (*s) {
652  fprintf(cp_err,
653  "Error: strange line in rawfile -- load aborted\n");
654  return (NULL);
655  }
656  }
657  }
658 
659  if (curpl) { /* reverse commands list */
660  for (wl=curpl->pl_commands,
661  curpl->pl_commands=NULL; wl &&
662  wl->wl_next; wl=nwl) {
663  nwl = wl->wl_next;
664  wl->wl_next = curpl->pl_commands;
665  curpl->pl_commands = wl;
666  }
667  }
668 
669  /* Fix everything up nicely again. */
670  cp_popcontrol();
671  cp_curin = lastin;
672  cp_curout = lastout;
673  cp_curerr = lasterr;
674  (void) fclose(fp);
675 
676  /* make the vectors permanent */
677  for (curpl = plots; curpl; curpl = curpl->pl_next) {
678  curpl->pl_hashtab = htab_init();
679  for (v = curpl->pl_dvecs; v; v = nv) {
680  nv = v->v_next;
681  v->v_next = NULL;
682  htab_add(v->v_name,(void*)v,curpl->pl_hashtab);
683  }
684  curpl->pl_dvecs = NULL;
685  }
686  return (plots);
687 }
static char buf[MAXPROMPT]
Definition: arg.c:18
char * gettok()
#define BSIZE_SP
Definition: misc.h:19
double v_minsignal
Definition: ftedata.h:30
int ciprefix()
GRIDTYPE
Definition: fteconst.h:60
static int atodims()
#define VF_REAL
Definition: fteconst.h:39
int cieq()
char * pl_name
Definition: ftedata.h:64
Definition: cddefs.h:119
char * datestring()
Definition: time.c:37
int scannum()
Definition: cpstd.h:29
FILE * cp_curerr
Definition: cshpar.c:77
Definition: ftedata.h:61
Definition: library.c:18
int v_dims[MAXDIMS]
Definition: ftedata.h:41
PLOTTYPE
Definition: fteconst.h:73
struct dvec * v_next
Definition: ftedata.h:43
char * cx_real()
#define alloc(type)
Definition: cdmacs.h:21
complex * v_compdata
Definition: ftedata.h:29
struct variable * cp_setparse()
static void fixdims()
char * copy()
FILE * cp_curin
Definition: cshpar.c:75
void wl_free()
FILE * cp_err
Definition: help.c:101
char * tmalloc()
void * htab_init()
Definition: hash.c:27
#define skip(s)
Definition: rawfile.c:268
struct wordlist * wl_prev
Definition: cpstd.h:24
double v_maxsignal
Definition: ftedata.h:31
#define MAXDIMS
Definition: ftedata.h:22
void txfree()
#define NULL
Definition: spdefs.h:121
#define nonl(s)
Definition: rawfile.c:269
GRIDTYPE v_gridtype
Definition: ftedata.h:32
FILE * cp_out
Definition: help.c:101
struct plot * v_plot
Definition: ftedata.h:42
char * v_defcolor
Definition: ftedata.h:39
struct dvec * v_scale
Definition: ftedata.h:45
#define isreal(v)
Definition: ftedata.h:54
void perror()
int ft_typnum()
Definition: ftedata.h:24
void advtok()
wordlist * cp_lexer()
char * ft_typabbrev()
char * v_name
Definition: ftedata.h:25
#define imagpart(cval)
Definition: cpstd.h:36
Definition: cpstd.h:21
#define VF_MAXGIVEN
Definition: fteconst.h:45
struct plot * pl_next
Definition: ftedata.h:69
int v_type
Definition: ftedata.h:26
Definition: cddefs.h:162
void htab_add()
struct wordlist * wl_next
Definition: cpstd.h:23
int v_numdims
Definition: ftedata.h:40
PLOTTYPE v_plottype
Definition: ftedata.h:33
char * wl_word
Definition: cpstd.h:22
void cp_pushcontrol()
Definition: front.c:1066
void cp_popcontrol()
Definition: front.c:1051
int v_length
Definition: ftedata.h:34
int cp_evloop()
FILE * cp_curout
Definition: cshpar.c:76
FILE * cp_in
Definition: help.c:101
short v_flags
Definition: ftedata.h:27
double * v_realdata
Definition: ftedata.h:28
int copytok()
Definition: cddefs.h:192
struct variable * va_next
Definition: cpstd.h:51
#define VF_COMPLEX
Definition: fteconst.h:40
char * cx_imag()
Definition: cpstd.h:41
#define VF_MINGIVEN
Definition: fteconst.h:44
#define realpart(cval)
Definition: cpstd.h:35
void raw_write ( char *  name,
struct plot pl,
bool  app,
bool  binary 
)

Definition at line 34 of file rawfile.c.

39 {
40  FILE *fp;
41  bool realflag = true;
42  bool raw_padding;
43  int length, numdims, dims[MAXDIMS];
44  int nvars, i, j, prec;
45  char buf[BSIZE_SP];
46  struct dvec *v;
47  struct variable *vv;
48  struct dvlist *dl0, *dl, *tl;
49  wordlist *wl;
50  double dd;
51 
52  if (!cp_getvar("nopadding", VT_BOOL, (char *) &raw_padding))
53  raw_padding = false;
54  /* Invert since we want to know if we should pad. */
55  raw_padding = !raw_padding;
56 
57  /* Why bother printing out an empty plot? */
58  if (htab_empty(pl->pl_hashtab)) {
59  fprintf(cp_err, "Error: plot is empty, nothing written.\n");
60  return;
61  }
62 
63  if (raw_prec != -1)
64  prec = raw_prec;
65  else
66  prec = DEFPREC;
67 
68  if (!(fp = fopen(name, app ? "a" : "w"))) {
69  perror(name);
70  return;
71  }
72 
73  numdims = nvars = length = 0;
74 
75  v = vec_fromplot("all",pl);
76  vec_sort(v);
77  dl0 = v->v_link2;
78 
79  for (nvars = 0, dl = dl0; dl; dl = dl->dl_next) {
80  v = dl->dl_dvec;
81  if (iscomplex(v))
82  realflag = false;
83  nvars++;
84  /* Find the length and dimensions of the longest vector
85  * in the plot.
86  * Be paranoid and assume somewhere we may have
87  * forgotten to set the dimensions of 1-D vectors.
88  */
89  if (v->v_numdims <= 1) {
90  v->v_numdims = 1;
91  v->v_dims[0] = v->v_length;
92  }
93  if (v->v_length > length) {
94  length = v->v_length;
95  numdims = v->v_numdims;
96  for (j = 0; j < numdims; j++) {
97  dims[j] = v->v_dims[j];
98  }
99  }
100  }
101 
102  fprintf(fp, "Title: %s\n", pl->pl_title);
103  fprintf(fp, "Date: %s\n", pl->pl_date);
104  fprintf(fp, "Plotname: %s\n", pl->pl_name);
105  fprintf(fp, "Flags: %s%s\n",
106  realflag ? "real" : "complex", raw_padding ? "" : " unpadded" );
107  fprintf(fp, "No. Variables: %d\n", nvars);
108  fprintf(fp, "No. Points: %d\n", length);
109  if (numdims > 1) {
110  fprintf(fp, "Dimensions: %s\n", dimstring(dims, numdims, buf));
111  }
112 
113  for (wl = pl->pl_commands; wl; wl = wl->wl_next)
114  fprintf(fp, "Command: %s\n", wl->wl_word);
115 
116  for (vv = pl->pl_env; vv; vv = vv->va_next) {
117  wl = cp_varwl(vv);
118  if (vv->va_type == VT_BOOL) {
119  fprintf(fp, "Option: %s\n", vv->va_name);
120  }
121  else {
122  fprintf(fp, "Option: %s = ", vv->va_name);
123  if (vv->va_type == VT_LIST)
124  fprintf(fp, "( ");
125  wl_print(wl, fp);
126  if (vv->va_type == VT_LIST)
127  fprintf(fp, " )");
128  (void) putc('\n', fp);
129  }
130  }
131 
132  /* Before we write the stuff out, make sure that the scale is the first
133  * in the list.
134  */
135 
136  for (tl = NULL,dl = dl0; dl; tl = dl, dl = dl->dl_next) {
137  if (dl->dl_dvec == pl->pl_scale) {
138  if (tl) {
139  tl->dl_next = dl->dl_next;
140  dl->dl_next = dl0;
141  dl0 = dl;
142  }
143  break;
144  }
145  }
146 
147  fprintf(fp, "Variables:");
148  for (i = 0, dl = dl0; dl; dl = dl->dl_next) {
149  v = dl->dl_dvec;
150  fprintf(fp, " %d %s %s", i++, v->v_name,
151  ft_typenames(v->v_type));
152  if (v->v_flags & VF_MINGIVEN)
153  fprintf(fp, " min=%e", v->v_minsignal);
154  if (v->v_flags & VF_MAXGIVEN)
155  fprintf(fp, " max=%e", v->v_maxsignal);
156  if (v->v_defcolor)
157  fprintf(fp, " color=%s", v->v_defcolor);
158  if (v->v_gridtype)
159  fprintf(fp, " grid=%d", v->v_gridtype);
160  if (v->v_plottype)
161  fprintf(fp, " plot=%d", v->v_gridtype);
162 
163  /* Only write dims if they are different from default. */
164  j = 0;
165  if (v->v_numdims == numdims) {
166  for ( ; j < numdims; j++)
167  if (dims[j] != v->v_dims[j])
168  break;
169  }
170  if (j < numdims) {
171  fprintf(fp, " dims=%s", dimstring(v->v_dims, v->v_numdims, buf));
172  }
173  (void) putc('\n', fp);
174  }
175 
176  if (binary) {
177  fprintf(fp, "Binary:\n");
178  for (i = 0; i < length; i++) {
179  for (dl = dl0; dl; dl = dl->dl_next) {
180  v = dl->dl_dvec;
181  /* Don't run off the end of this vector's data. */
182  if (i < v->v_length) {
183  if (realflag) {
184  dd = (isreal(v) ? v->v_realdata[i] :
185  realpart(&v->v_compdata[i]));
186  (void) fwrite((char *) &dd, sizeof
187  (double), 1, fp);
188  }
189  else if (isreal(v)) {
190  dd = v->v_realdata[i];
191  (void) fwrite((char *) &dd, sizeof
192  (double), 1, fp);
193  dd = 0.0;
194  (void) fwrite((char *) &dd, sizeof
195  (double), 1, fp);
196  }
197  else {
198  dd = realpart(&v->v_compdata[i]);
199  (void) fwrite((char *) &dd, sizeof
200  (double), 1, fp);
201  dd = imagpart(&v->v_compdata[i]);
202  (void) fwrite((char *) &dd, sizeof
203  (double), 1, fp);
204  }
205  }
206  else if (raw_padding) {
207  dd = 0.0;
208  if (realflag) {
209  (void) fwrite((char *) &dd, sizeof
210  (double), 1, fp);
211  }
212  else {
213  (void) fwrite((char *) &dd, sizeof
214  (double), 1, fp);
215  (void) fwrite((char *) &dd, sizeof
216  (double), 1, fp);
217  }
218  }
219  }
220  }
221  }
222  else {
223  fprintf(fp, "Values:\n");
224  for (i = 0; i < length; i++) {
225  fprintf(fp, " %d", i);
226  for (dl = dl0; dl; dl = dl->dl_next) {
227  v = dl->dl_dvec;
228  if (i < v->v_length) {
229  if (realflag) {
230  fprintf(fp, "\t%.*e\n", prec,
231  isreal(v) ? v->v_realdata[i] :
232  realpart(&v->v_compdata[i]));
233  }
234  else if (isreal(v)) {
235  fprintf(fp, "\t%.*e,0.0\n", prec,
236  v->v_realdata[i]);
237  }
238  else {
239  fprintf(fp, "\t%.*e,%.*e\n", prec,
240  realpart(&v->v_compdata[i]),
241  prec,
242  imagpart(&v->v_compdata[i]));
243  }
244  }
245  else if (raw_padding) {
246  if (realflag) {
247  fprintf(fp, "\t%.*e\n", prec, 0.0);
248  }
249  else {
250  fprintf(fp, "\t%.*e,%.*e\n",
251  prec, 0.0, prec, 0.0);
252  }
253  }
254  }
255  }
256  }
257  (void) fclose(fp);
258  return;
259 }
#define DEFPREC
Definition: rawfile.c:28
static char * dimstring()
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
void wl_print()
double v_minsignal
Definition: ftedata.h:30
bool cp_getvar(char *n, int t, char *r)
Definition: help.c:184
void vec_sort()
char * pl_date
Definition: ftedata.h:63
struct dvlist * v_link2
Definition: ftedata.h:44
char * pl_title
Definition: ftedata.h:62
char * pl_name
Definition: ftedata.h:64
struct variable * pl_env
Definition: ftedata.h:71
Definition: ftedata.h:49
#define VT_LIST
Definition: cpstd.h:64
Definition: library.c:18
int v_dims[MAXDIMS]
Definition: ftedata.h:41
int raw_prec
Definition: rawfile.c:26
void * pl_hashtab
Definition: ftedata.h:66
complex * v_compdata
Definition: ftedata.h:29
char va_type
Definition: cpstd.h:42
struct dvlist * dl_next
Definition: ftedata.h:51
FILE * cp_err
Definition: help.c:101
char * va_name
Definition: cpstd.h:43
int htab_empty()
double v_maxsignal
Definition: ftedata.h:31
#define MAXDIMS
Definition: ftedata.h:22
struct dvec * pl_scale
Definition: ftedata.h:68
#define NULL
Definition: spdefs.h:121
GRIDTYPE v_gridtype
Definition: ftedata.h:32
char * v_defcolor
Definition: ftedata.h:39
struct dvec * vec_fromplot()
#define isreal(v)
Definition: ftedata.h:54
void perror()
Definition: ftedata.h:24
struct dvec * dl_dvec
Definition: ftedata.h:50
char * v_name
Definition: ftedata.h:25
#define imagpart(cval)
Definition: cpstd.h:36
#define VT_BOOL
Definition: cpstd.h:60
char * ft_typenames()
Definition: cpstd.h:21
#define VF_MAXGIVEN
Definition: fteconst.h:45
#define iscomplex(v)
Definition: ftedata.h:55
int v_type
Definition: ftedata.h:26
struct wordlist * wl_next
Definition: cpstd.h:23
int v_numdims
Definition: ftedata.h:40
PLOTTYPE v_plottype
Definition: ftedata.h:33
char * wl_word
Definition: cpstd.h:22
wordlist * cp_varwl()
int v_length
Definition: ftedata.h:34
short v_flags
Definition: ftedata.h:27
wordlist * pl_commands
Definition: ftedata.h:70
double * v_realdata
Definition: ftedata.h:28
struct variable * va_next
Definition: cpstd.h:51
Definition: cpstd.h:41
#define VF_MINGIVEN
Definition: fteconst.h:44
#define realpart(cval)
Definition: cpstd.h:35

Variable Documentation

int raw_prec = -1

Definition at line 26 of file rawfile.c.