1 /* FILE IDENTIFICATION
\r
3 * Name: sdf.h Header file for Standard Data FIle system
\r
4 * Programmer: Kevin Rosenberg
\r
5 * Date Started: 9-18-84
\r
6 * Last Change: 12-24-84
\r
15 /*----------------*/
\r
16 /* SYSTEM ALIASES */
\r
17 /*----------------*/
\r
19 #define SDF_VERSION 2
\r
20 #define SDF_ID_STR "SDF"
\r
22 /*------------------*/
\r
23 /* DEFINITION BLOCK */
\r
24 /*------------------*/
\r
26 /* fixed system constants */
\r
28 #define BLK_SIZE 256 /* Size of a header block */
\r
29 #define NUM_DIRBLK 1 /* number of directory blocks */
\r
33 #define BT_EMPTY 0 /* Not being used */
\r
34 #define BT_DIRECTORY 1 /* First blocks in file */
\r
35 #define BT_LABEL 2 /* Label block */
\r
39 #define LT_EMPTY 0 /* label record is available for use */
\r
40 #define LT_TITLE 1 /* descriptive label given by user */
\r
41 #define LT_HISTORY 2 /* history label generated by application */
\r
43 #define LT_NOTE 3 /* A note created with a label editor */
\r
45 /* codes for open_sdf and create_sdf */
\r
47 #define SDF_RDONLY 0
\r
48 #define SDF_WRONLY 1
\r
51 /* function return codes */
\r
53 #define SDF_ERROR ERROR
\r
54 #define SDF_2D_ERROR SDF_ERROR
\r
57 /* types of sdf file, this area is EXPANDABLE */
\r
59 #define SDF_FTYPE_2D 10 /* Two-dimensional data file */
\r
62 /* BLOCK IDENTIFICATION
\r
64 * Name: Directory Header Block
\r
65 * Size: Multiple of BLK_SIZE
\r
68 * This is the first block of a sdf file. It contains information on the
\r
69 * size of the users' data plus the number and type of header blocks.
\r
73 int block_type; /* required at the beginning of every block */
\r
74 /* to identify type of block */
\r
76 char id_str[4]; /* identification string == SDF_ID_STR */
\r
77 int sdf_version; /* which version of sdf system == SDF_VERSION */
\r
79 int blk_size; /* size of a header block in bytes */
\r
81 int df_type; /* type of data file, used as identification */
\r
82 /* by application programs */
\r
84 unsigned int num_dirblk; /* number of directory header blocks */
\r
85 /* currently, only 1 block long */
\r
87 /* label directory */
\r
89 unsigned int start_label; /* starting position of label header blocks */
\r
90 unsigned int num_label; /* number of label header blocks */
\r
92 /* data header info */
\r
94 unsigned int start_dhead; /* block number of the start of the users' */
\r
95 /* data header blocks */
\r
96 unsigned int num_dhead; /* number of data header blocks */
\r
97 unsigned int dhead_len; /* length of data header in bytes */
\r
99 /* data record info */
\r
101 unsigned int start_drec; /* block number of start of data records */
\r
102 unsigned int num_drec; /* number of of user data records */
\r
103 unsigned int drec_size; /* size of users' record */
\r
104 int num_dval; /* number of values in each data record */
\r
105 int dval_size; /* size of data value in bytes */
\r
106 /* NOTE: drec_size = dval_size * num_dval */
\r
110 /* BLOCK IDENTIFICATION
\r
112 * Name: Label block
\r
116 * This block contains both user and history labels. Labels are alpha-
\r
117 * numeric. History labels include time & date stamp plus calculation time.
\r
120 #define LABEL_LEN 159 /* size of alphanumeric label */
\r
121 #define LABELS_PER_BLOCK 1
\r
122 /* number of labels in each block */
\r
124 struct label_blk_st {
\r
125 int block_type; /* required at the beginning of every block */
\r
126 int label_type; /* type of label */
\r
127 char label_str[LABEL_LEN+1];/* alpha numeric label */
\r
129 /* history label time stamping */
\r
131 TIMEDATE timedate; /* time and date of operation */
\r
132 float calc_time; /* calculation time in seconds */
\r
136 /* BLOCK IDENTIFICATION
\r
138 * Name: Data Header Block
\r
139 * Size: Variable, but always integer multiple of BLK_SIZE
\r
142 * This block hold information entirely specific to the data in the sdf
\r
143 * file, such as the user coordinates of the extent of an image, or the
\r
144 * the rotation increment of raysum data. When an application program
\r
145 * reads or writes the data header, it passes the size in bytes of the
\r
146 * data header to be read or written. If the length of a data header
\r
147 * being read doesn't match the length of the data header in the file,
\r
148 * the header is still read, but a WARNING message is given.
\r
153 /* STRUCTURE IDENTIFICATION
\r
155 * Name: Data File Structure Contains all information on open files
\r
158 * This structure is generated by open_file() and create_file(), it is
\r
159 * passed to all subroutines of the sdf system.
\r
163 bool open; /* if file is open or not */
\r
164 int mode; /* read-write mode */
\r
165 int fd; /* file descriptor gotten from C library */
\r
166 bool error; /* TRUE if error occurred, all further */
\r
167 /* procesing is stopped */
\r
168 bool error_report; /* Error reporting flag */
\r
170 unsigned int blk_size; /* size of a header block */
\r
171 unsigned int num_dirblk; /* number of directory header blocks */
\r
172 char fname[MAXFULLNAME+1]; /* operating system filename */
\r
174 int df_type; /* identification type of data file */
\r
176 /* variables that are used when writing to a file, they define what parts
\r
177 * of the file have been written
\r
181 unsigned dir : 1; /* 1 if directory header has been written */
\r
182 unsigned label : 1; /* 1 if labels have been written */
\r
183 unsigned dhead : 1; /* 1 if data header has been written */
\r
184 unsigned drec : 1; /* 1 when data records have been written */
\r
187 /* Directory information to have about the file */
\r
189 unsigned int start_label; /* starting position of labels */
\r
190 unsigned int num_label; /* number of labels in file */
\r
192 unsigned int dhead_len; /* length of data header in bytes */
\r
194 unsigned int num_drec; /* number of data records */
\r
195 unsigned int drec_size; /* size of data records in bytes */
\r
196 int num_dval; /* number of values in each data record */
\r
197 int dval_size; /* size of data value in bytes */
\r
198 /* NOTE: drec_size = dval_size * num_dval */
\r
200 /* ffset pointers into sdf file */
\r
202 long int pos_dhead; /* starting position of data header */
\r
203 long int pos_drec; /* starting position of users' data */
\r
208 char buf[BLK_SIZE];
\r
209 struct dir_blk_st dir;
\r
210 struct label_blk_st lab;
\r
213 typedef struct dir_blk_st DIR_BLK;
\r
214 typedef struct label_blk_st LABEL_BLK;
\r
215 typedef struct sdfile_st SDFILE;
\r
216 typedef union sdf_blk_un SDF_BLK;
\r
219 /*----------------------------------------------------------------------*/
\r
220 /* 2-Dimensional Standard Data File Header */
\r
221 /*----------------------------------------------------------------------*/
\r
224 /* STRUCTURE IDENTIFICATION
\r
226 * Name: sdf_2d_dhead_st Data header for 2d data files
\r
230 * This structure holds the data that is stored in an image sdf file's
\r
231 * data header. It contains all data needed to use 2d data records
\r
234 struct sdf_2d_dhead_st {
\r
235 int file_type; /* type of data making up this file */
\r
236 /* currenty, DFT_2D_IMAGE or DFT_2D_RAYSUM */
\r
237 int nx; /* number of rows */
\r
238 int ny; /* number of columns in row */
\r
239 int val_type; /* type of pixel value, eg, DT_FLOAT */
\r
240 int val_size; /* size of pixel value in bytes */
\r
242 bool axis_ext_kwn; /* TRUE if picture extent is known */
\r
243 /* stored in xmin,xmax,ymin,ymax */
\r
244 double xmin, ymin; /* position of lower left corner of picture */
\r
245 double xmax, ymax; /* position of upper right corner of picture */
\r
247 bool axis_incr_kwn; /* TRUE if increments are known */
\r
250 bool val_ext_kwn; /* TRUE if pixel extent is known */
\r
251 double dvalmin, dvalmax;/* min & max data value for FLOAT & DOUBLE */
\r
252 long lvalmin, lvalmax; /* data extent for INT & LONG */
\r
256 /* STRUCTURE IDENTIFICATION
\r
258 * Name: sdf_2d_st Information about an sdf image
\r
262 * This structure holds all the information need to access an sdf
\r
267 struct sdf_2d_dhead_st dhead; /* image information that is stored in data header */
\r
268 SDFILE *dfp; /* pointer to image's standard data file */
\r
269 MTX *mtx; /* data values */
\r
270 int memory_only; /* TRUE if sdf_2d file is stored in memory only */
\r
273 typedef struct sdf_2d_dhead_st SDF_2D_DHEAD;
\r
274 typedef struct sdf_2d_st SDF_2D;
\r
276 /* types of 2d data files */
\r
278 #define SDF_2D_IMAGE 100 /* data file type is an image */
\r
279 #define SDF_2D_RAYSUM 101 /* raysum data file type */
\r
283 SDFILE *sdf_open(const char *filename, const int mode);
\r
284 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);
\r
285 int sdf_read_label(LABEL_BLK *lrec, const int nlab, SDFILE *dfp);
\r
286 int sdf_write_label(LABEL_BLK *lrec, const int nlab, SDFILE *dfp);
\r
287 int sdf_add_label(const int ltype, const char *lstr, const double calc_time, SDFILE *dfp);
\r
288 int sdf_add_empty_label(SDFILE *dfp);
\r
289 int sdf_copy_labels(SDFILE *dfp_to, SDFILE *dfp_from);
\r
290 int sdf_read_dhead(void *dh_buf, const unsigned int dhead_len, SDFILE *dfp);
\r
291 int sdf_write_dhead(const void *dh_buf, const unsigned int dhead_len, SDFILE *dfp);
\r
292 int sdf_read_drec(void *drec, const int start_rec, const int num_rec, SDFILE *dfp);
\r
293 int sdf_write_drec(const void *drec, const int start_rec, const int num_rec, SDFILE *dfp);
\r
294 int sdf_read_dval(void *dval, const int rec, const int start_val, const int num_val, SDFILE *dfp);
\r
295 int sdf_write_dval(const void *dval, const int rec, const int start_val, const int num_val, SDFILE *dfp);
\r
296 int sdf_close(SDFILE *dfp);
\r
297 void sdf_error_report(SDFILE *dfp, const int flag);
\r
298 void sdf_error(const SDFILE *dfp, const char *str, ...);
\r
299 bool sdf_check_dfp(const SDFILE *dfp, const int mode, const char *name);
\r
300 void *sdf_alloc_blk(const int n, SDFILE *dfp, const char *name);
\r
301 int sdf_free_blk(void *hb, SDFILE *dfp, const char *name);
\r
303 SDF_2D *sdf_2d_open(const char *fname, const int mode);
\r
304 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);
\r
305 int sdf_2d_save(SDF_2D *imp);
\r
306 int sdf_2d_restore(SDF_2D *imp);
\r
307 int sdf_2d_alloc_mtx(SDF_2D *imp);
\r
308 int sdf_2d_free_mtx(SDF_2D *sdf_2d);
\r
309 int sdf_2d_read_row(char *row_buf, const unsigned int row, SDF_2D *imp);
\r
310 int sdf_2d_write_row(const char *row_buf, const unsigned int row, SDF_2D *imp);
\r
311 int sdf_2d_read_col(char *col_buf, const unsigned int col, SDF_2D *imp);
\r
312 int sdf_2d_write_col(const char *col_buf, const unsigned int col, SDF_2D *imp);
\r
313 int sdf_2d_close(SDF_2D *imp);
\r
314 char *sdf_2d_alloc_row(const int nrow, SDF_2D *imp);
\r
315 char *sdf_2d_alloc_col(const int ncol, SDF_2D *imp);
\r
316 void sdf_2d_error(const SDF_2D *imp, const char *str, ...);
\r