Clean up a slew of warnings from gcc -Wall - mostly unused variables.
[gwave-svn.git] / spicefile / ss_spice2.c
blob4ba235747b55148e32f6848d7a964305522674f3
1 /*
2 * ss_spice2.c: routines for SpiceStream that handle the output
3 * format from Berkeley Spice2G6
5 * Copyright 1998,1999 Stephen G. Tell
6 * Copyright 1998 D. Jeff Dionne
8 * Based on rd_spice2.c that Jeff Dione contributed to gwave-0.0.4,
9 * this was largely rewritten by Steve Tell for the spicestream library.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the Free
23 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include "ssintern.h"
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include <float.h>
34 #include <config.h>
35 #include <glib.h>
36 #include "spice2.h"
37 #include "spicestream.h"
39 static int sf_readrow_s2raw(SpiceStream *sf, double *ivar, double *dvars);
40 static char *msgid = "s2raw";
42 /* Read spice-type file header - Berkeley Spice2G6 "raw" format */
43 SpiceStream *
44 sf_rdhdr_s2raw(char *name, FILE *fp)
46 SpiceStream *sf = NULL;
47 int ndv;
48 int i;
49 char *cp;
50 spice_hdr_t s2hdr;
51 spice_var_name_t s2vname;
52 spice_var_type_t s2vtype;
53 spice_var_loc_t s2vloc;
54 spice_plot_title_t s2title;
55 spice_var_t s2var;
57 if(fread (&s2var,sizeof(s2var),1,fp) != 1)
58 return NULL;
59 if (memcmp(&s2var,SPICE_MAGIC,8)) {
60 ss_msg(DBG, msgid, "%s: not a spice2 rawfile (bad magic number)", name);
61 return NULL;
63 if(fread (&s2hdr,sizeof(s2hdr),1,fp) != 1)
64 return NULL;
65 ss_msg(DBG, msgid, "%s: nvars=%d const=%d analysis mode %d",
66 name, s2hdr.nvars, s2hdr.const4, s2hdr.mode);
68 /* independent variable name */
69 if(fread (&s2vname,sizeof(s2vname),1,fp) != 1)
70 return NULL;
71 s2vname.name[7] = 0;
72 if(cp = strchr(s2vname.name, ' '))
73 *cp = 0;
75 ndv = s2hdr.nvars - 1;
76 sf = ss_new(fp, name, ndv, 0);
77 sf->ncols = ndv;
78 sf->ivar->name = g_strdup(s2vname.name);
79 sf->ivar->type = TIME;
80 sf->ivar->col = 0;
81 sf->ivar->ncols = 1;
83 for (i = 0; i < ndv; i++) {
84 if(fread (&s2vname, sizeof(s2vname), 1, fp) != 1)
85 goto err;
86 s2vname.name[7] = 0;
87 if(cp = strchr(s2vname.name, ' '))
88 *cp = 0;
90 sf->dvar[i].name = g_strdup(s2vname.name);
91 sf->dvar[i].type = VOLTAGE; /* FIXME:sgt: get correct type */
92 sf->dvar[i].col = i; /* FIXME:sgt: handle complex */
93 sf->dvar[i].ncols = 1;
96 if(fread (&s2vtype, sizeof(s2vtype), 1, fp) != 1)
97 goto err;
98 for (i = 0; i < ndv; i++) {
99 if(fread (&s2vtype, sizeof(s2vtype), 1, fp) != 1)
100 goto err;
103 if(fread (&s2vloc, sizeof(s2vloc), 1, fp) != 1)
104 goto err;
105 for (i = 0; i < ndv; i++) {
106 if(fread (&s2vloc, sizeof(s2vloc), 1, fp) != 1)
107 goto err;
109 if(fread (&s2title, sizeof(s2title), 1, fp) != 1)
110 goto err;
111 s2title.title[23] = 0;
112 ss_msg(DBG, msgid, "title=\"%s\"", s2title.title);
113 ss_msg(DBG, msgid, "done with header at offset=0x%lx", (long) ftello64(fp));
115 sf->readrow = sf_readrow_s2raw;
116 return sf;
117 err:
118 if(sf) {
119 ss_delete(sf);
121 return NULL;
126 * Read row of values from a spice2 rawfile
128 static int
129 sf_readrow_s2raw(SpiceStream *sf, double *ivar, double *dvars)
131 int i, rc;
132 spice_var_t val;
134 /* independent var */
135 if ((rc = fread (&val,sizeof(val),1, sf->fp)) != 1) {
136 if(rc == 0)
137 return 0;
138 else
139 return -1;
141 if (memcmp(&val,SPICE_MAGIC,8) == 0) /* another analysis */
142 return 0;
143 *ivar = val.val;
145 /* dependent vars */
146 for(i = 0; i < sf->ndv; i++) {
147 if(fread(&val, sizeof(val), 1, sf->fp) != 1) {
148 ss_msg(ERR, msgid, "unexpected EOF at dvar %d", i);
149 return -1;
151 dvars[i] = val.val;
153 return 1;