@@ -12,8 +12,152 @@ import and interpret XDI-formatted data.
12
12
13
13
## API
14
14
15
+ ### read an XDI file
16
+
17
+ Read an XDI file, store it's content in an XDIFile struct, and return
18
+ an integer return code.
19
+
15
20
``` C
21
+ XDIFile *xdifile;
16
22
int ret;
23
+
17
24
xdifile = malloc(sizeof (XDIFile));
18
- ret = XDI_readfile(argv[1 ], xdifile);
25
+ ret = XDI_readfile(" mydata.xdi" , xdifile);
26
+ ```
27
+
28
+ ### interpret the XDI_readfile error code
29
+
30
+ Interpret the return code by printing teh corresponding error massage
31
+ to the screen:
32
+
33
+ ``` C
34
+ /* react to a terminal error */
35
+ if (ret < 0 ) {
36
+ printf ("Error reading XDI file '%s':\n %s\t(error code = %ld)\n",
37
+ argv[ 1] , xdifile->error_message, ret);
38
+ XDI_cleanup(xdifile, ret);
39
+ return 1;
40
+ }
41
+
42
+ /* react to a warning */
43
+ if (ret > 0) {
44
+ printf ("Warning reading XDI file '%s':\n %s\t(warning code = %ld)\n\n",
45
+ argv[ 1] , xdifile->error_message, ret);
46
+ }
47
+ ```
48
+
49
+ The `xdifile->error_message` attribute will always contain the error
50
+ or warning message from the most recent action. If an error code
51
+ returns as non-zero, the content of `xdifile->error_message` will
52
+ explain the meaning of the error code in English.
53
+
54
+ ### test for required metadata
55
+
56
+ Test whether the **required** metadata was present in the XDI file.
57
+ If `XDI_required_metadata` returns a non-zero value, the file is
58
+ **not compliant** with the XDI specification.
59
+
60
+ ```C
61
+ j = XDI_required_metadata(xdifile);
62
+ if (j != 0) {
63
+ printf("\n# check for required metadata -- (requirement code %ld):\n%s\n", j, xdifile->error_message);
64
+ }
65
+ ```
66
+
67
+ Run ` xdi_reader ` agains ` baddata/bad_30.xdi ` for an example of a
68
+ file which is non-compliant because of missing ** required** metadata.
69
+
70
+ ### test for recommended metadata
71
+
72
+ Test whether the ** recommended** metadata was present in the XDI file.
73
+ If ` XDI_required_metadata ` returns a non-zero value, the file is
74
+ compliant with the XDI specification, but lacks information considered
75
+ highly useful to the interchange of the data contained in the file.
76
+
77
+ ``` C
78
+ j = XDI_recommended_metadata(xdifile);
79
+ if (j != ) {
80
+ printf ("\n# check for recommended metadata -- (recommendation code %ld):\n%s\n", j, xdifile->error_message);
81
+ }
19
82
```
83
+
84
+ Run `xdi_reader` agains `baddata/bad_32.xdi` for an example of a
85
+ file which is missing **recommended** metadata.
86
+
87
+
88
+ ### Examine and validate metadata
89
+
90
+ This `for` loop iterates through each set of metadata family, keyword,
91
+ and value found in the XDI file. `XDI_validate_item` tests the value
92
+ to see if it meets the recommendation of the specification.
93
+ Validation tests do not exist for all items in the metadata dictionary
94
+ -- `XDI_validate_item` will return 0 for
95
+
96
+ ```C
97
+ for (i=0; i < xdifile->nmetadata; i++) {
98
+ printf(" %s / %s => %s\n",
99
+ xdifile->meta_families[i],
100
+ xdifile->meta_keywords[i],
101
+ xdifile->meta_values[i]);
102
+
103
+ j = XDI_validate_item(xdifile, xdifile->meta_families[i], xdifile->meta_keywords[i], xdifile->meta_values[i]);
104
+ if (j!=0) {
105
+ printf("-- Warning for %s.%s: %s\t(warning code = %ld)\n\t%s\n",
106
+ xdifile->meta_families[i], xdifile->meta_keywords[i], xdifile->meta_values[i], j, xdifile->error_message);
107
+ }
108
+ }
109
+ ```
110
+
111
+ ### Examine arrays from the data table
112
+
113
+ ``` C
114
+ double *enarray, *muarray;
115
+ enarray = (double *)calloc(xdifile->npts, sizeof (double ));
116
+ muarray = (double *)calloc(xdifile->npts, sizeof (double ));
117
+ ret = XDI_get_array_name(xdifile, " energy" , enarray);
118
+ ret = XDI_get_array_name(xdifile, " mutrans" , muarray);
119
+ ```
120
+
121
+ The return value is 0 if an array by that name was found in the data
122
+ table. The return value is -1 if the array cannot be retrieved.
123
+
124
+ The array names are held in the ` Column.N ` metadata fields.
125
+
126
+ ## Error codes
127
+
128
+ Here is a list of all error codes and their English explanation. An
129
+ application using ` libxdifile ` can use these lists as the basis for
130
+ translation of a table of error messages into another language.
131
+
132
+ ### XDI_readfile error codes
133
+
134
+ | code | message |
135
+ | -1 | |
136
+ | -2 | |
137
+
138
+ ### XDI_readfile warning codes
139
+
140
+ | 1 | |
141
+ | 2 | |
142
+
143
+ ### XDI_required_metadata return codes
144
+
145
+ The return code from ` XDI_required_metadata ` can be interpreted
146
+ bitwise. That is, a return code of 7 means that all three required
147
+ metadata fields were missing.
148
+
149
+ | 1 | |
150
+ | 2 | |
151
+ | 4 | |
152
+
153
+ ### XDI_recommended_metadata return codes
154
+
155
+ The return code from ` XDI_recommended_metadata ` can be interpreted
156
+ bitwise. That is, a return code of 7 means that the first three
157
+ recommendation metadata fields were missing.
158
+
159
+ | 1 | |
160
+ | 2 | |
161
+ | 4 | |
162
+ | 8 | |
163
+ | 16 | |
0 commit comments