Ignore all generated/compiled files
[gwave-svn.git] / spicefile / wavefile.h
blob04b5293a9a547d5cf03e06aa0d106477c83b3d08
2 /*
3 * wavefile.h - definitions for WaveFile, routines and data structures
4 * for reading and working with entire datasets of waveform data.
6 * Copyright 1999,2005 Stephen G. Tell.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the Free
20 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #ifndef WAVEFILE_H
25 #define WAVEFILE_H
27 #include <spicestream.h>
28 #include <glib.h>
30 typedef struct _WaveFile WaveFile;
31 typedef struct _WaveVar WaveVar;
32 typedef struct _WDataSet WDataSet;
33 typedef struct _WvTable WvTable;
35 /* Wave Data Set -
36 * an array of double-precision floating-point values, used to store a
37 * column of values. Organized as a block structure because we don't know
38 * how many entries there will be without reading the file, and we don't
39 * want to read the whole thing twice.
41 * Depending on what the memory allocator does, this might even
42 * end up being relatively cache-friendly. TODO: think more about this.
43 */
45 #define DS_DBLKSIZE 8192
46 #define DS_INBLKS 1024
47 #define ds_blockno(n) ((n) / DS_DBLKSIZE)
48 #define ds_offset(n) ((n) % DS_DBLKSIZE)
50 struct _WDataSet {
51 double min;
52 double max;
54 /* remaining stuff is an array storage structure
55 * that could be abstracted out and/or replaced with somthing else */
56 /* pointer to array of pointers to blocks of doubles */
57 double **bptr;
58 int bpsize; /* size of array of pointers */
59 int bpused; /* number of blocks actually allocated */
60 int nreallocs;
63 /* Wave Variable - used for independent or dependent variable.
65 struct _WaveVar {
66 SpiceVar *sv;
67 WvTable *wtable; /* backpointer to file */
68 WDataSet *wds; /* data for one or more columns */
69 void *udata;
72 #define wv_name sv->name
73 #define wv_type sv->type
74 #define wv_ncols sv->ncols
75 #define wv_nvalues wtable->nvalues
76 #define wv_iv wtable->iv
77 #define wv_file wtable->wf
79 #define wv_is_multisweep(WV) ((WV)->wtable->wf->wf_ntables>1)
82 * Wave Table - association of one or more dependent variables with
83 * a contiguous, nondecreasing independent variable.
85 struct _WvTable {
86 WaveFile *wf;
87 int swindex; /* index of the sweep, 0-based */
88 char *name; /* name of the sweep, if any, else NULL */
89 double swval; /* value at which the sweep was taken */
90 int nvalues; /* number of rows */
91 WaveVar *iv; /* pointer to single independent variable */
92 GPtrArray *dvp; /* array of WaveVar* */
95 #define wt_dv(WT, I) (WaveVar *)g_ptr_array_index((WT)->dvp, (I))
97 //#define wt_ndv wf->ss->ndv
98 #define wt_ndv dvp->len
101 * WaveFile - data struture containing all of the data from a file.
103 struct _WaveFile {
104 SpiceStream *ss;
105 GPtrArray *tables; /* array of WvTable* */
106 void *udata;
109 #define wf_filename ss->filename
110 #define wf_ndv ss->ndv
111 #define wf_ncols ss->ncols
112 #define wf_ntables tables->len
113 #define wf_wtable(WF,I) (WvTable*)g_ptr_array_index((WF)->tables, (I))
116 /* defined in wavefile.c */
117 extern WaveFile *wf_read(char *name, char *format);
118 extern double wv_interp_value(WaveVar *dv, double ival);
119 extern int wf_find_point(WaveVar *iv, double ival);
120 extern double wds_get_point(WDataSet *ds, int n);
121 extern void wf_free(WaveFile *df);
122 extern WaveVar *wf_find_variable(WaveFile *wf, char *varname, int swpno);
123 extern void wf_foreach_wavevar(WaveFile *wf, GFunc func, gpointer *p);
125 extern int wf_add_var(WaveFile *wf, char *varname, int ncols, VarType type,
126 void *udata);
128 extern void wf_set_point(WDataSet *ds, int n, double val);
130 #endif /* WAVEFILE_H */