Ignore all generated/compiled files
[gwave-svn.git] / spicefile / spicestream.h
bloba6fab09ae953ba2b07bff42471670224a8d25c56
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 #ifndef SPICESTREAM_H
11 #define SPICESTREAM_H
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
17 #include <glib.h>
19 typedef struct _SpiceStream SpiceStream;
20 typedef struct _SpiceVar SpiceVar;
23 typedef enum {
24 UNKNOWN = 0,
25 TIME = 1,
26 VOLTAGE = 2,
27 CURRENT = 3,
28 FREQUENCY = 4,
29 MATH = 5,
30 } VarType;
32 typedef enum SSMsgLevel_tag {DBG = -1, INFO = 0, WARN = 1, ERR = 2} SSMsgLevel;
33 extern FILE *ss_error_file;
34 typedef void (*SSMsgHook) (char *s);
35 extern SSMsgHook ss_error_hook;
36 extern SSMsgLevel spicestream_msg_level;
38 /* header data on each variable mentioned in the file
39 * For sweep parameters, ncols will be 0.
41 struct _SpiceVar {
42 char *name;
43 VarType type;
44 int col; /* index of (first) column of data that goes with this variable */
45 int ncols; /* number of columns of data for this variable; complex numbers have two */
46 };
48 typedef int (*SSReadRow) (SpiceStream *sf, double *ivar, double *dvars);
49 typedef int (*SSReadSweep) (SpiceStream *sf, double *spar);
51 struct _SpiceStream {
52 char *filename;
53 int filetype;
54 int ndv; /* number of dependent variables */
55 int ncols; /* number of columns of data readrow will fill in */
56 SpiceVar *ivar; /* ptr to independent-variable info */
57 GPtrArray *dvarp; /* array of SpiceVar* */
58 SpiceVar *spar; /* ptr to array of sweep parameter info */
60 SSReadRow readrow; /* func to read one row of data points */
61 SSReadSweep readsweep; /* func to read one row of data points */
62 int ntables; /* number of data tables in the file; not
63 * reliable for all file formats */
64 int nsweepparam; /* number of implicit sweep parameter values at the start
65 * of each table; may be 0 even for a multi-variate
66 * sweep in some file formats */
68 /* the following stuff is for private use of reader routines */
69 FILE *fp;
70 int flags;
71 int lineno;
72 char *linebuf;
73 int line_length;
74 int lbufsize;
75 int expected_vals;
76 int read_vals;
77 int read_rows;
78 int read_tables;
79 int read_sweepparam;
80 char *linep;
81 double ivval;
83 /* following for nsout format */
84 double voltage_resolution;
85 double current_resolution;
86 double time_resolution;
87 int maxindex;
88 double *datrow; /* temporary data row indexed by ns indices */
89 int *nsindexes; /* indexed by dvar, contains ns index number */
92 /* values for flags field */
93 #define SSF_ESWAP 1
94 #define SSF_PUSHBACK 2
96 #define ss_readrow(sf, ivp, dvp) ((sf->readrow)(sf, ivp, dvp))
97 #define ss_readsweep(sf, swp) ((sf->readsweep)(sf, swp))
98 #define ss_dvar(SF, I) (SpiceVar*)(g_ptr_array_index((SF)->dvarp, (I)))
101 extern SpiceStream *ss_open(char *filename, char *type);
102 extern SpiceStream *ss_open_fp(FILE *fp, char *type);
103 extern SpiceStream *ss_open_internal(FILE *fp, char *name, char *type);
104 extern SpiceStream *ss_new(FILE *fp, char *name, int ndv, int nspar);
105 extern SpiceVar *ss_spicevar_new(char *name, VarType type, int col, int ncols);
106 extern void ss_spicevar_free(SpiceVar *sv);
107 extern void ss_close(SpiceStream *sf);
108 extern void ss_delete(SpiceStream *ss);
109 extern char *ss_var_name(SpiceVar *sv, int col, char *buf, int n);
110 extern char *vartype_name_str(VarType type);
111 extern int fread_line(FILE *fp, char **bufp, int *bufsize);
112 extern void ss_msg(SSMsgLevel type, const char *id, const char *msg, ...);
113 extern char *ss_filetype_name(int n);
116 #ifdef __cplusplus
118 #endif
120 #endif /* SPICESTREAM_H */