1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: sdf.h,v 1.3 2000/05/07 12:46:19 kevin Exp $
7 ** Revision 1.3 2000/05/07 12:46:19 kevin
10 ** Revision 1.2 2000/04/28 14:14:16 kevin
11 ** *** empty log message ***
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
27 /* FILE IDENTIFICATION
29 * Name: sdf.h Header file for Standard Data FIle system
30 * Programmer: Kevin Rosenberg
31 * Date Started: 9-18-84
32 * Last Change: 12-24-84
42 #endif /* __cplusplus */
49 #define SDF_ID_STR "SDF"
51 /*------------------*/
52 /* DEFINITION BLOCK */
53 /*------------------*/
55 /* fixed system constants */
57 #define BLK_SIZE 256 /* Size of a header block */
58 #define NUM_DIRBLK 1 /* number of directory blocks */
62 #define BT_EMPTY 0 /* Not being used */
63 #define BT_DIRECTORY 1 /* First blocks in file */
64 #define BT_LABEL 2 /* Label block */
68 #define LT_EMPTY 0 /* label record is available for use */
69 #define LT_TITLE 1 /* descriptive label given by user */
70 #define LT_HISTORY 2 /* history label generated by application */
72 #define LT_NOTE 3 /* A note created with a label editor */
74 /* codes for open_sdf and create_sdf */
80 /* function return codes */
82 #define SDF_ERROR ERROR
83 #define SDF_2D_ERROR SDF_ERROR
86 /* types of sdf file, this area is EXPANDABLE */
88 #define SDF_FTYPE_2D 10 /* Two-dimensional data file */
91 /* BLOCK IDENTIFICATION
93 * Name: Directory Header Block
94 * Size: Multiple of BLK_SIZE
97 * This is the first block of a sdf file. It contains information on the
98 * size of the users' data plus the number and type of header blocks.
102 int block_type; /* required at the beginning of every block */
103 /* to identify type of block */
105 char id_str[4]; /* identification string == SDF_ID_STR */
106 int sdf_version; /* which version of sdf system == SDF_VERSION */
108 int blk_size; /* size of a header block in bytes */
110 int df_type; /* type of data file, used as identification */
111 /* by application programs */
113 unsigned int num_dirblk; /* number of directory header blocks */
114 /* currently, only 1 block long */
116 /* label directory */
118 unsigned int start_label; /* starting position of label header blocks */
119 unsigned int num_label; /* number of label header blocks */
121 /* data header info */
123 unsigned int start_dhead; /* block number of the start of the users' */
124 /* data header blocks */
125 unsigned int num_dhead; /* number of data header blocks */
126 unsigned int dhead_len; /* length of data header in bytes */
128 /* data record info */
130 unsigned int start_drec; /* block number of start of data records */
131 unsigned int num_drec; /* number of of user data records */
132 unsigned int drec_size; /* size of users' record */
133 int num_dval; /* number of values in each data record */
134 int dval_size; /* size of data value in bytes */
135 /* NOTE: drec_size = dval_size * num_dval */
139 /* BLOCK IDENTIFICATION
145 * This block contains both user and history labels. Labels are alpha-
146 * numeric. History labels include time & date stamp plus calculation time.
149 #define LABEL_LEN 159 /* size of alphanumeric label */
150 #define LABELS_PER_BLOCK 1
151 /* number of labels in each block */
153 struct label_blk_st {
154 int block_type; /* required at the beginning of every block */
155 int label_type; /* type of label */
156 char label_str[LABEL_LEN+1];/* alpha numeric label */
158 /* history label time stamping */
160 TIMEDATE timedate; /* time and date of operation */
161 float calc_time; /* calculation time in seconds */
165 /* BLOCK IDENTIFICATION
167 * Name: Data Header Block
168 * Size: Variable, but always integer multiple of BLK_SIZE
171 * This block hold information entirely specific to the data in the sdf
172 * file, such as the user coordinates of the extent of an image, or the
173 * the rotation increment of raysum data. When an application program
174 * reads or writes the data header, it passes the size in bytes of the
175 * data header to be read or written. If the length of a data header
176 * being read doesn't match the length of the data header in the file,
177 * the header is still read, but a WARNING message is given.
182 /* STRUCTURE IDENTIFICATION
184 * Name: Data File Structure Contains all information on open files
187 * This structure is generated by open_file() and create_file(), it is
188 * passed to all subroutines of the sdf system.
192 bool open; /* if file is open or not */
193 int mode; /* read-write mode */
194 int fd; /* file descriptor gotten from C library */
195 bool error; /* TRUE if error occurred, all further */
196 /* procesing is stopped */
197 bool error_report; /* Error reporting flag */
199 unsigned int blk_size; /* size of a header block */
200 unsigned int num_dirblk; /* number of directory header blocks */
201 char fname[MAXFULLNAME+1]; /* operating system filename */
203 int df_type; /* identification type of data file */
205 /* variables that are used when writing to a file, they define what parts
206 * of the file have been written
210 unsigned dir : 1; /* 1 if directory header has been written */
211 unsigned label : 1; /* 1 if labels have been written */
212 unsigned dhead : 1; /* 1 if data header has been written */
213 unsigned drec : 1; /* 1 when data records have been written */
216 /* Directory information to have about the file */
218 unsigned int start_label; /* starting position of labels */
219 unsigned int num_label; /* number of labels in file */
221 unsigned int dhead_len; /* length of data header in bytes */
223 unsigned int num_drec; /* number of data records */
224 unsigned int drec_size; /* size of data records in bytes */
225 int num_dval; /* number of values in each data record */
226 int dval_size; /* size of data value in bytes */
227 /* NOTE: drec_size = dval_size * num_dval */
229 /* ffset pointers into sdf file */
231 long int pos_dhead; /* starting position of data header */
232 long int pos_drec; /* starting position of users' data */
238 struct dir_blk_st dir;
239 struct label_blk_st lab;
242 typedef struct dir_blk_st DIR_BLK;
243 typedef struct label_blk_st LABEL_BLK;
244 typedef struct sdfile_st SDFILE;
245 typedef union sdf_blk_un SDF_BLK;
248 /*----------------------------------------------------------------------*/
249 /* 2-Dimensional Standard Data File Header */
250 /*----------------------------------------------------------------------*/
253 /* STRUCTURE IDENTIFICATION
255 * Name: sdf_2d_dhead_st Data header for 2d data files
259 * This structure holds the data that is stored in an image sdf file's
260 * data header. It contains all data needed to use 2d data records
263 struct sdf_2d_dhead_st {
264 int file_type; /* type of data making up this file */
265 /* currenty, DFT_2D_IMAGE or DFT_2D_RAYSUM */
266 int nx; /* number of rows */
267 int ny; /* number of columns in row */
268 int val_type; /* type of pixel value, eg, DT_FLOAT */
269 int val_size; /* size of pixel value in bytes */
271 bool axis_ext_kwn; /* TRUE if picture extent is known */
272 /* stored in xmin,xmax,ymin,ymax */
273 double xmin, ymin; /* position of lower left corner of picture */
274 double xmax, ymax; /* position of upper right corner of picture */
276 bool axis_incr_kwn; /* TRUE if increments are known */
279 bool val_ext_kwn; /* TRUE if pixel extent is known */
280 double dvalmin, dvalmax;/* min & max data value for FLOAT & DOUBLE */
281 long lvalmin, lvalmax; /* data extent for INT & LONG */
285 /* STRUCTURE IDENTIFICATION
287 * Name: sdf_2d_st Information about an sdf image
291 * This structure holds all the information need to access an sdf
296 struct sdf_2d_dhead_st dhead; /* image information that is stored in data header */
297 SDFILE *dfp; /* pointer to image's standard data file */
298 MTX *mtx; /* data values */
299 int memory_only; /* TRUE if sdf_2d file is stored in memory only */
302 typedef struct sdf_2d_dhead_st SDF_2D_DHEAD;
303 typedef struct sdf_2d_st SDF_2D;
305 /* types of 2d data files */
307 #define SDF_2D_IMAGE 100 /* data file type is an image */
308 #define SDF_2D_RAYSUM 101 /* raysum data file type */
312 SDFILE *sdf_open(const char *filename, const int mode);
313 SDFILE *sdf_create(const char *filename, const int mode, const unsigned int num_drec, const unsigned int num_dval, const int dval_size, const int df_type);
314 int sdf_read_label(LABEL_BLK *lrec, const int nlab, SDFILE *dfp);
315 int sdf_write_label(LABEL_BLK *lrec, const int nlab, SDFILE *dfp);
316 int sdf_add_label(const int ltype, const char *lstr, const double calc_time, SDFILE *dfp);
317 int sdf_add_empty_label(SDFILE *dfp);
318 int sdf_copy_labels(SDFILE *dfp_to, SDFILE *dfp_from);
319 int sdf_read_dhead(void *dh_buf, const unsigned int dhead_len, SDFILE *dfp);
320 int sdf_write_dhead(const void *dh_buf, const unsigned int dhead_len, SDFILE *dfp);
321 int sdf_read_drec(void *drec, const int start_rec, const int num_rec, SDFILE *dfp);
322 int sdf_write_drec(const void *drec, const int start_rec, const int num_rec, SDFILE *dfp);
323 int sdf_read_dval(void *dval, const int rec, const int start_val, const int num_val, SDFILE *dfp);
324 int sdf_write_dval(const void *dval, const int rec, const int start_val, const int num_val, SDFILE *dfp);
325 int sdf_close(SDFILE *dfp);
326 void sdf_error_report(SDFILE *dfp, const int flag);
327 void sdf_error(const SDFILE *dfp, const char *str, ...);
328 bool sdf_check_dfp(const SDFILE *dfp, const int mode, const char *name);
329 void *sdf_alloc_blk(const int n, SDFILE *dfp, const char *name);
330 int sdf_free_blk(void *hb, SDFILE *dfp, const char *name);
332 SDF_2D *sdf_2d_open(const char *fname, const int mode);
333 SDF_2D *sdf_2d_create(const char *fname, const int mode, const int nx, const int ny, const int val_type, const int df_type);
334 int sdf_2d_save(SDF_2D *imp);
335 int sdf_2d_restore(SDF_2D *imp);
336 int sdf_2d_alloc_mtx(SDF_2D *imp);
337 int sdf_2d_free_mtx(SDF_2D *sdf_2d);
338 int sdf_2d_read_row(char *row_buf, const unsigned int row, SDF_2D *imp);
339 int sdf_2d_write_row(const char *row_buf, const unsigned int row, SDF_2D *imp);
340 int sdf_2d_read_col(char *col_buf, const unsigned int col, SDF_2D *imp);
341 int sdf_2d_write_col(const char *col_buf, const unsigned int col, SDF_2D *imp);
342 int sdf_2d_close(SDF_2D *imp);
343 char *sdf_2d_alloc_row(const int nrow, SDF_2D *imp);
344 char *sdf_2d_alloc_col(const int ncol, SDF_2D *imp);
345 void sdf_2d_error(const SDF_2D *imp, const char *str, ...);
349 #endif /* __cplusplus */