yet another hspice file format variant
[gwave-svn.git] / spicefile / spicestream.h
blob465cc4d4cc3e50cd1aa504e05724528d3a97e7e2
1 /*
2 * spicefile.h - definitions for a file reader for the analog
3 * output files of various spice-like simulators.
5 * Copyright 1998,1999 Stephen G. Tell.
8 */
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
14 typedef struct _SpiceStream SpiceStream;
15 typedef struct _SpiceVar SpiceVar;
18 typedef enum {
19 UNKNOWN = 0,
20 TIME = 1,
21 VOLTAGE = 2,
22 CURRENT = 3,
23 FREQUENCY = 4,
24 } VarType;
26 typedef enum SSMsgLevel_tag {DBG = -1, INFO = 0, WARN = 1, ERR = 2} SSMsgLevel;
27 extern FILE *ss_error_file;
28 typedef void (*SSMsgHook) (char *s);
29 extern SSMsgHook ss_error_hook;
30 extern SSMsgLevel spicestream_msg_level;
32 /* header data on each variable mentioned in the file
33 * For sweep parameters, ncols will be 0.
35 struct _SpiceVar {
36 char *name;
37 VarType type;
38 int col; /* index of (first) column of data that goes with this variable */
39 int ncols; /* number of columns of data for this variable; complex numbers have two */
40 };
42 typedef int (*SSReadRow) (SpiceStream *sf, double *ivar, double *dvars);
43 typedef int (*SSReadSweep) (SpiceStream *sf, double *spar);
45 struct _SpiceStream {
46 char *filename;
47 int filetype;
48 int ndv; /* number of dependent variables */
49 int ncols; /* number of columns of data readrow will fill in */
50 SpiceVar *ivar; /* ptr to independent-variable info */
51 SpiceVar *dvar; /* ptr to array of dependent variable info */
52 SpiceVar *spar; /* ptr to array of sweep parameter info */
54 SSReadRow readrow; /* func to read one row of data points */
55 SSReadSweep readsweep; /* func to read one row of data points */
56 int ntables; /* number of data tables in the file; not
57 * reliable for all file formats */
58 int nsweepparam; /* number of implicit sweep parameter values at the start
59 * of each table; may be 0 even for a multi-variate
60 * sweep in some file formats */
62 /* the following stuff is for private use of reader routines */
63 FILE *fp;
64 int flags;
65 int lineno;
66 char *linebuf;
67 int line_length;
68 int lbufsize;
69 int expected_vals;
70 int read_vals;
71 int read_rows;
72 int read_tables;
73 int read_sweepparam;
74 char *linep;
75 double ivval;
77 /* following for nsout format */
78 double voltage_resolution;
79 double current_resolution;
80 double time_resolution;
81 int maxindex;
82 double *datrow; /* temporary data row indexed by ns indices */
83 int *nsindexes; /* indexed by dvar, contains ns index number */
86 /* values for flags field */
87 #define SSF_ESWAP 1
88 #define SSF_PUSHBACK 2
90 #define ss_readrow(sf, ivp, dvp) ((sf->readrow)(sf, ivp, dvp))
91 #define ss_readsweep(sf, swp) ((sf->readsweep)(sf, swp))
93 extern SpiceStream *ss_open(char *filename, char *type);
94 extern SpiceStream *ss_open_fp(FILE *fp, char *type);
95 extern SpiceStream *ss_open_internal(FILE *fp, char *name, char *type);
96 extern SpiceStream *ss_new(FILE *fp, char *name, int ndv, int nspar);
97 extern void ss_close(SpiceStream *sf);
98 extern void ss_delete(SpiceStream *ss);
99 extern char *ss_var_name(SpiceVar *sv, int col, char *buf, int n);
100 extern char *vartype_name_str(VarType type);
101 extern int fread_line(FILE *fp, char **bufp, int *bufsize);
102 extern void ss_msg(SSMsgLevel type, const char *id, const char *msg, ...);
103 extern char *ss_filetype_name(int n);
106 #ifdef __cplusplus
108 #endif