File: umfile.h

package info (click to toggle)
cf-python 1.3.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,996 kB
  • sloc: python: 51,733; ansic: 2,736; makefile: 78; sh: 2
file content (204 lines) | stat: -rw-r--r-- 5,336 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
 * ==============================================================
 * Header file only for stuff intended to be called directly from
 * python.  Everything else should be in umfileint.h.
 * ==============================================================
 */

#include <stddef.h>

typedef enum 
{
  plain_pp,
  fields_file
} 
  File_format;

typedef enum 
{
  little_endian,
  big_endian
} 
  Byte_ordering;

typedef enum 
{
  int_type,
  real_type
} 
  Data_type;


/* ---------------- 
 * Placeholders for internal structures to be defined in umfileint.h
 * Here just need to predeclare them so that we can have pointers to them.
 */
struct _File;
struct _Var;
struct _Rec;
/* ---------------- */

typedef struct 
{
  File_format format;
  Byte_ordering byte_ordering;
  int word_size;
}
  File_type ;

typedef struct 
{
  void *int_hdr;
  void *real_hdr;
  size_t header_offset;  /* in bytes */
  size_t data_offset;  /* in bytes */
  size_t disk_length;  /* in bytes */
  struct _Rec *internp;
}
  Rec;

typedef struct 
{
  Rec **recs;
  int nz;
  int nt;
  int supervar_index;
  struct _Var *internp;
}
  Var;

typedef struct 
{
  int fd;
  File_type file_type;
  int nvars;
  Var **vars;
  struct _File *internp;
}
  File;

/* ------------------------------------------------------------------- */

int detect_file_type(int fd, File_type *file_type_rtn);
/* 
   Given an open file, detect type of file (caller provides storage for info
   returned).  if detection was successful, returns 0 and populates the
   File_type structure provided by the caller, otherwise returns 1.
*/

File *file_parse(int fd,
		 File_type file_type);
/* 
   Given an open file handle, parse a file into a File structure, with
   embedded Var and Rec structures, relating the PP records to variables
   within the file.

   Caller should pass a File_type structure as either returned from
   detect_file_type() or populated by the caller.
*/

/* commented out - to handle in Python */
/* void close_fd(File *file); */
/* int reopen_fd(File *file); */

void file_free(File *file);
/*
 * Free memory associated with a File structure (including anything hung off
 * the internal pointer) and all variables and records underneath it
 */

/* ------------------------------------------------------------------- */
/* functions for reading the actual data, not dependent on the above objects 
 * (although may call common code in the implementation)
 */

int read_header(int fd,
		size_t header_offset,
		Byte_ordering byte_ordering, 
		int word_size, 
		void *int_hdr_rtn,
		void *real_hdr_rtn);
/*
  reads a PP header at specified offset; function will do byte-swapping
  as necessary, but returned header data will match word size, and 
  caller must provide storage of appropriate length to contain these
  (45 and 19 words respectively)
*/


int get_type_and_length(int word_size,
			const void *int_hdr,
			Data_type *type_rtn,
			size_t *num_words_rtn);
/*
  Parses integer PP header, works out number of words and data type.

  Caller provides integer header as array of 4 or 8 byte ints 
  as appropriate to passed word_size, and provides storage for 
  returned info.

  Return value is 0 for success, otherwise 1.
 */

int read_record_data(int fd, 
		     size_t data_offset, 
		     size_t disk_length, 
		     Byte_ordering byte_ordering, 
		     int word_size, 
		     const void *int_hdr,
		     const void *real_hdr,
		     size_t nwords, 
		     void *data_return);
/* 
   Reads record data at specified offset; function will do byte-swapping and
   unpacking as necessary.  Caller provides PP headers as arrays of 4 or 8
   byte ints and floats/doubles as appropriate to passed word_size (real
   header needed for missing data value).  This must match actual file word
   size, and there will be no casting of data except as appropriate when
   unpacking packed fields.

   Returns in data_return an array of int or float at this word size; caller 
   must provide storage of size nwords words, and nwords must have been
   obtained by calling get_nwords().

   Return value is 0 for success, 1 for failure.
*/
/* ------------------------------------------------------------------- */


int get_extra_data_offset_and_length(int word_size, 
				     const void *int_hdr,
				     size_t data_offset,
				     size_t disk_length,
				     size_t *extra_data_offset_rtn,
				     size_t *extra_data_length_rtn);
/*
  Parses integer PP header in conjunction with data offset and length
  (where the length includes the extra data), to works out the offset
  and length of extra data

  Caller provides integer header as array of 4 or 8 byte ints 
  as appropriate to passed word_size, and provides storage for 
  returned info.

  Return value is length, or -1 on failure
 */

int read_extra_data(int fd,
		    size_t extra_data_offset,
		    size_t extra_data_length,
		    Byte_ordering byte_ordering,
		    int word_size,
		    void *extra_data_return);

/* 
   Reads extra data at specified offset; function will do byte-swapping 
   as necessary.

   Returns raw data (aside from the byte swapping) in extra_data_return;
   caller must provide storage of size extra_data_length * word_size bytes,
   and extra_data_length must have been obtained by calling 
   get_extra_data_length().

   Return value is 0 for success, 1 for failure.
*/