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
++) {
85 if(fread (&s2vname
, sizeof(s2vname
), 1, fp
) != 1)
88 if(cp
= strchr(s2vname
.name
, ' '))
91 /* FIXME:sgt: get correct type */
92 /* FIXME:sgt: handle complex */
93 dvar
= ss_spicevar_new(s2vname
.name
, VOLTAGE
, i
, 1);
94 g_ptr_array_add(sf
->dvarp
, dvar
);
97 if(fread (&s2vtype
, sizeof(s2vtype
), 1, fp
) != 1)
99 for (i
= 0; i
< ndv
; i
++) {
100 if(fread (&s2vtype
, sizeof(s2vtype
), 1, fp
) != 1)
104 if(fread (&s2vloc
, sizeof(s2vloc
), 1, fp
) != 1)
106 for (i
= 0; i
< ndv
; i
++) {
107 if(fread (&s2vloc
, sizeof(s2vloc
), 1, fp
) != 1)
110 if(fread (&s2title
, sizeof(s2title
), 1, fp
) != 1)
112 s2title
.title
[23] = 0;
113 ss_msg(DBG
, msgid
, "title=\"%s\"", s2title
.title
);
114 ss_msg(DBG
, msgid
, "done with header at offset=0x%lx", (long) ftello64(fp
));
116 sf
->readrow
= sf_readrow_s2raw
;
127 * Read row of values from a spice2 rawfile
130 sf_readrow_s2raw(SpiceStream
*sf
, double *ivar
, double *dvars
)
135 /* independent var */
136 if ((rc
= fread (&val
,sizeof(val
),1, sf
->fp
)) != 1) {
142 if (memcmp(&val
,SPICE_MAGIC
,8) == 0) /* another analysis */
147 for(i
= 0; i
< sf
->ndv
; i
++) {
148 if(fread(&val
, sizeof(val
), 1, sf
->fp
) != 1) {
149 ss_msg(ERR
, msgid
, "unexpected EOF at dvar %d", i
);