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