@@ -9,45 +9,48 @@ least very similar).
9
9
10
10
See ` xdi_reader.c ` for an example of a C program using ` libxdifile ` to
11
11
import and interpret XDI-formatted data. See the python and perl
12
- wrappers for examples of language specific implementations which use
13
- ` libxdifile ` .
12
+ wrappers for examples of language specific implementations which link
13
+ directly to the ` libxdifile ` library .
14
14
15
15
` libxdifile ` was written by Matt Newville and Bruce Ravel.
16
16
17
17
## XDIFile struct
18
18
19
19
This is the content of the XDIFile struct. It will contain the entire
20
- contents of the XDI file along with a few particularly important items
21
- (d-spacing, element, and edge).
22
-
23
- | attribute | type | explanation |
24
- | --------------- | ------------------ | ----------- |
25
- | filename | char* | the name of the XDI file |
26
- | nmetadata | long | number of metadata fields |
27
- | meta\_ families | array of char* | array of family names found among the metadata, indexed to nmetadata |
20
+ contents of the XDI file along with a few particularly important
21
+ metadata items (d-spacing, element, and edge).
22
+
23
+ | attribute | type | explanation |
24
+ | --------------- | ------------------ | --------------------------------------------------------------------- |
25
+ | filename | char* | the name of the XDI file |
26
+ | nmetadata | long | number of metadata fields |
27
+ | meta\_ families | array of char* | array of family names found among the metadata, indexed to nmetadata |
28
28
| meta\_ keywords | array of char* | array of keyword names found among the metadata, indexed to nmetadata |
29
- | meta\_ values | array of char* | array of values found among the metadata, indexed to nmetadata |
30
- | narrays | long | number of arrays in data table |
31
- | npts | long | number of rows in data table |
32
- | array | 2D array of double | the data table |
33
- | narray\_ labels | long | number of array labels |
34
- | array\_ labels | array of char* | array of labels for arrays in the data table |
35
- | array\_ units | array of char* | array of units for arrays in the data table |
36
- | comments | char* | the user supplied comments from the XDI file |
37
- | xdi\_ libversion | char* | the ` libxdifile ` version number |
38
- | xdi\_ version | char* | the XDI file specification version number from the file |
39
- | extra\_ version | char* | versioning information for extension fields |
40
- | dspacing | double | the Mono.d-spacing value |
29
+ | meta\_ values | array of char* | array of values found among the metadata, indexed to nmetadata |
30
+ | narrays | long | number of arrays in data table |
31
+ | npts | long | number of rows in data table |
32
+ | array | 2D array of double | the data table |
33
+ | narray\_ labels | long | number of array labels |
34
+ | array\_ labels | array of char* | array of labels for arrays in the data table |
35
+ | array\_ units | array of char* | array of units for arrays in the data table |
36
+ | comments | char* | the user supplied comments from the XDI file |
37
+ | xdi\_ libversion | char* | the ` libxdifile ` version number |
38
+ | xdi\_ version | char* | the XDI file specification version number from the file |
39
+ | extra\_ version | char* | versioning information for extension fields |
40
+ | dspacing | double | the Mono.d-spacing value |
41
41
| element | char* | the Element.symbol value, the 1, 2, or 3 letter symbol of the element |
42
- | edge | char* | the Element.edge value, the the 1 or 2 letter symbol of the edge |
43
- | error\_ lineno | long | the line number of a line returning an error |
44
- | error\_ line | char* | the line returning an error |
45
- | error\_ message | char* | the error message |
46
- | nouter | long | |
47
- | outer\_ label | array char* | |
48
- | outer\_ array | array of double | |
49
- | outer\_ breakpts | array of long | |
50
-
42
+ | edge | char* | the Element.edge value, the 1 or 2 letter symbol of the edge |
43
+ | error\_ lineno | long | the line number of a line returning an error |
44
+ | error\_ line | char* | the line returning an error |
45
+ | error\_ message | char* | the error message |
46
+ | nouter | long | (\* ) |
47
+ | outer\_ label | array char* | (\* ) |
48
+ | outer\_ array | array of double | (\* ) |
49
+ | outer\_ breakpts | array of long | (\* ) |
50
+
51
+ (\* ) Currently undocumented struct elements intended for support of
52
+ two-dimensional data. This may be supported in a future version of
53
+ ` libxdifile ` .
51
54
52
55
## API
53
56
@@ -57,7 +60,7 @@ parsing the file and validating its content.
57
60
The main point of entry is the function ` XDI_readfile ` which creates
58
61
an ` XDIFile ` struct, then opens and parses a file for XDI content.
59
62
This function will signal an error and issue a useful error message in
60
- the even that some content of the file precludes its being understood
63
+ the event that some content of the file precludes its being understood
61
64
as XDI data. These situations include such things as
62
65
63
66
* Missing XDI versioning information in the first line of the file
@@ -67,10 +70,22 @@ as XDI data. These situations include such things as
67
70
68
71
Certain conditions that are non-conforming with the XDI specification
69
72
but which do not preclude partial interpretation of the XDI file
70
- result in warning messages at this time.
73
+ result in warning messages issued by ` XDI_readfile ` .
74
+
75
+ Validating the content of the XDI metadata is treated in three
76
+ separate steps. The philosophy of use of the XDI library is:
71
77
72
- Validating the content of the XDI metadata is treated as a separate
73
- step. There are three main functions for this purpose:
78
+ 1 . Read the XDI file, stopping only in the case of an unrecoverable error, then
79
+ 2 . Check that the metadata identified in the specification as ** required** are present, then
80
+ 3 . Check that the metadata identified in the specification as ** recommended** are present, then
81
+ 4 . Validate each individual metadata item against its dictionary definition
82
+
83
+ This allows an application to take a fine-grained approach to how
84
+ strictly it will follow the details of the XDI specification. Thus, a
85
+ file can be read and used with any level of validation -- including
86
+ _ no validation_ -- being performed.
87
+
88
+ The three validation functions are:
74
89
75
90
* ` XDI_required_metadata ` : This function tests that the pieces of
76
91
metadata which are ** required** by the specification are present in
@@ -105,10 +120,6 @@ condition of the most recently performed action. The relation between
105
120
the returned error/warning codes and the error messages are tabulated
106
121
below.
107
122
108
- The value of separating most validation chores from the parsing of the
109
- file is that it allows an application to choose to accept structurally
110
- compliant data then to perform the level of validation appropriate to
111
- the task at hand.
112
123
113
124
114
125
### Read an XDI file
@@ -117,6 +128,8 @@ Read an XDI file, store it's content in an XDIFile struct, and return
117
128
an integer return code.
118
129
119
130
``` C
131
+ #include " xdifile.h"
132
+
120
133
XDIFile *xdifile;
121
134
int ret;
122
135
@@ -126,11 +139,11 @@ an integer return code.
126
139
127
140
### Interpret the XDI_readfile error code
128
141
129
- Interpret the return code by printing the corresponding error message
130
- to the screen:
142
+ Interpret the ` XDI_readfile ` return code by printing the corresponding
143
+ error or warning message to the screen:
131
144
132
145
``` C
133
- /* react to a terminal error */
146
+ /* react to an error reading the file */
134
147
if (ret < 0 ) {
135
148
printf ("Error reading XDI file '%s':\n %s\t(error code = %ld)\n",
136
149
argv[ 1] , xdifile->error_message, ret);
@@ -149,7 +162,9 @@ to the screen:
149
162
The `xdifile->error_message` attribute will always contain the error
150
163
or warning message from the most recent action. If an error code
151
164
returns as non-zero, the content of `xdifile->error_message` will
152
- explain the meaning of the error code in English.
165
+ explain the meaning of the error code in English. Note that cleanup
166
+ and deallocation must be performed in the event of an error precluding
167
+ the reading of the file.
153
168
154
169
### Test for required metadata
155
170
@@ -193,7 +208,8 @@ This `for` loop iterates through each set of metadata family, keyword,
193
208
and value found in the XDI file. `XDI_validate_item` tests the value
194
209
to see if it meets the recommendation of the specification.
195
210
Validation tests do not exist for all items in the metadata dictionary
196
- -- `XDI_validate_item` will return 0 for
211
+ -- `XDI_validate_item` will return 0 for any free-format dictionary
212
+ item.
197
213
198
214
```C
199
215
for (i=0; i < xdifile->nmetadata; i++) {
@@ -271,9 +287,9 @@ translation of a table of error messages into another language.
271
287
| -16 | number of columns changes in data table |
272
288
| -32 | non-numeric value in data table: `<word>` |
273
289
274
- Here `<word>` will be the the text that triggered the error.
290
+ Here `<word>` will be the text that triggered the error.
275
291
276
- ### XDI_readfile warning codes
292
+ ### XDI_readfile and XDI_validate_item warning codes
277
293
278
294
| code | message |
279
295
| ----: | ------------------------------------------------------------ |
@@ -288,13 +304,16 @@ Here `<word>` will be the the text that triggered the error.
288
304
| 256 | Column.1 is not "energy" or "angle" |
289
305
| 512 | invalid timestamp: format should be ISO 8601 (YYYY-MM-DD HH:MM:SS) |
290
306
| 1024 | invalid timestamp: date out of valid range |
307
+ | 2048 | <not used> |
308
+ | 4096 | bad value in Sample namespace |
309
+ | 8192 | bad value in Facility namespace |
291
310
292
311
293
312
### XDI_required_metadata return codes
294
313
295
- The return code from `XDI_required_metadata` can be interpreted
296
- bitwise. That is, a return code of 7 means that all three required
297
- metadata fields were missing.
314
+ The return code from `XDI_required_metadata` is interpreted bitwise.
315
+ That is, a return code of 7 means that all three required metadata
316
+ fields were missing or invalid .
298
317
299
318
| code | message |
300
319
| ---: | -------------------------------------- |
@@ -305,15 +324,15 @@ metadata fields were missing.
305
324
306
325
### XDI_recommended_metadata return codes
307
326
308
- The return code from `XDI_recommended_metadata` can be interpreted
327
+ The return code from `XDI_recommended_metadata` is interpreted
309
328
bitwise. That is, a return code of 7 means that the first three
310
329
recommended metadata fields were missing.
311
330
312
- | code | message |
313
- | ---: | --------------------------------------------------- |
314
- | 1 | Missing recommended metadata field: Facility.name |
315
- | 2 | Missing recommended metadata field: Facility.source |
316
- | 4 | Missing recommended metadata field: Beamline.name |
317
- | 8 | Missing recommended metadata field: Scan.start_time |
318
- | 16 | Missing recommended metadata field: Column.1 |
331
+ | code | message |
332
+ | ---: | --------------------------------------------------------- |
333
+ | 1 | Missing recommended metadata field: Facility.name |
334
+ | 2 | Missing recommended metadata field: Facility.xray\_source |
335
+ | 4 | Missing recommended metadata field: Beamline.name |
336
+ | 8 | Missing recommended metadata field: Scan.start_time |
337
+ | 16 | Missing recommended metadata field: Column.1 |
319
338
0 commit comments