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.
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 */
44 sf_rdhdr_s2raw(char *name
, FILE *fp
)
46 SpiceStream
*sf
= NULL
;
51 spice_var_name_t s2vname
;
52 spice_var_type_t s2vtype
;
53 spice_var_loc_t s2vloc
;
54 spice_plot_title_t s2title
;
57 if(fread (&s2var
,sizeof(s2var
),1,fp
) != 1)
59 if (memcmp(&s2var
,SPICE_MAGIC
,8)) {
60 ss_msg(DBG
, msgid
, "%s: not a spice2 rawfile (bad magic number)", name
);
63 if(fread (&s2hdr
,sizeof(s2hdr
),1,fp
) != 1)
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)
72 if(cp
= strchr(s2vname
.name
, ' '))
75 ndv
= s2hdr
.nvars
- 1;
76 sf
= ss_new(fp
, name
, ndv
, 0);
78 sf
->ivar
->name
= g_strdup(s2vname
.name
);
79 sf
->ivar
->type
= TIME
;
83 for (i
= 0; i
< ndv
; i
++) {
84 if(fread (&s2vname
, sizeof(s2vname
), 1, fp
) != 1)
87 if(cp
= strchr(s2vname
.name
, ' '))
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)
98 for (i
= 0; i
< ndv
; i
++) {
99 if(fread (&s2vtype
, sizeof(s2vtype
), 1, fp
) != 1)
103 if(fread (&s2vloc
, sizeof(s2vloc
), 1, fp
) != 1)
105 for (i
= 0; i
< ndv
; i
++) {
106 if(fread (&s2vloc
, sizeof(s2vloc
), 1, fp
) != 1)
109 if(fread (&s2title
, sizeof(s2title
), 1, fp
) != 1)
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
;
126 * Read row of values from a spice2 rawfile
129 sf_readrow_s2raw(SpiceStream
*sf
, double *ivar
, double *dvars
)
134 /* independent var */
135 if ((rc
= fread (&val
,sizeof(val
),1, sf
->fp
)) != 1) {
141 if (memcmp(&val
,SPICE_MAGIC
,8) == 0) /* another analysis */
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
);