Skip to content

Commit 109e9d5

Browse files
committed
sample family example
1 parent 172a795 commit 109e9d5

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

c/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ contents of the XDI file along with a few particularly important items
2727
| meta\_values | array of char* | array of values found among the metadata, indexed to nmetadata |
2828
| narrays | long | number of arrays in data table |
2929
| npts | long | number of rows in data table |
30-
| array | of array of double | the data table |
30+
| array | 2D array of double | the data table |
3131
| narray\_labels | long | number of array labels |
3232
| array\_labels | array of char* | array of labels for arrays in the data table |
3333
| array\_units | array of char* | array of units for arrays in the data table |
@@ -147,7 +147,7 @@ Validation tests do not exist for all items in the metadata dictionary
147147
}
148148
```
149149

150-
### Examine arrays from the data table
150+
### Extract named arrays from the data table
151151

152152
```C
153153
double *enarray, *muarray;
@@ -218,18 +218,18 @@ The return code from `XDI_required_metadata` can be interpreted
218218
bitwise. That is, a return code of 7 means that all three required
219219
metadata fields were missing.
220220
221-
| code | message |
222-
| ---: | ----------------------------------- |
223-
| 1 | Element.symbol missing or not valid |
224-
| 2 | Element.edge missing or not valid |
225-
| 4 | Mono.d\_spacing missing |
226-
| 8 | Mono.d\_spacing not valid |
221+
| code | message |
222+
| ---: | -------------------------------------- |
223+
| 1 | Element.symbol missing or not valid |
224+
| 2 | Element.edge missing or not valid |
225+
| 4 | Mono.d\_spacing missing |
226+
| 8 | Non-numeric value for Mono.d\_spacing |
227227
228228
### XDI_recommended_metadata return codes
229229
230230
The return code from `XDI_recommended_metadata` can be interpreted
231231
bitwise. That is, a return code of 7 means that the first three
232-
recommendation metadata fields were missing.
232+
recommended metadata fields were missing.
233233
234234
| code | message |
235235
| ---: | --------------------------------------------------- |

c/xdifile.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ XDI_required_metadata(XDIFile *xdifile) {
656656
if (ret & REQ_ELEM) { strcat(xdifile->error_message, "Element.symbol missing or not valid\n"); }
657657
if (ret & REQ_EDGE) { strcat(xdifile->error_message, "Element.edge missing or not valid\n"); }
658658
if (ret & REQ_NO_DSPACING) { strcat(xdifile->error_message, "Mono.d_spacing missing\n"); }
659-
if (ret & REQ_INVALID_DSPACING) { strcat(xdifile->error_message, "Mono.d_spacing not valid\n"); }
659+
if (ret & REQ_INVALID_DSPACING) { strcat(xdifile->error_message, "Non-numerical value fo Mono.d_spacing\n"); }
660660

661661
return ret;
662662
}
@@ -732,7 +732,7 @@ XDI_validate_item(XDIFile *xdifile, char *family, char *name, char *value) {
732732
err = 0;
733733

734734
} else if (strcasecmp(family, "sample") == 0) {
735-
err = 0;
735+
err = XDI_validate_sample(xdifile, name, value);
736736

737737
} else if (strcasecmp(family, "scan") == 0) {
738738
err = XDI_validate_scan(xdifile, name, value);
@@ -780,6 +780,26 @@ int XDI_validate_mono(XDIFile *xdifile, char *name, char *value) {
780780
return err;
781781
}
782782

783+
int XDI_validate_sample(XDIFile *xdifile, char *name, char *value) {
784+
int err;
785+
int regex_status;
786+
struct slre_cap caps[2];
787+
788+
err = 0;
789+
strcpy(xdifile->error_message, "");
790+
791+
if (strcasecmp(name, "temperature") == 0) {
792+
regex_status = slre_match("^\\d(\\.\\d)?\\s+[CcFfKk].*$", value, strlen(value), caps, 2, 0);
793+
if (regex_status < 0) {
794+
strcpy(xdifile->error_message, "Sample.temperature not interpretable as a temperature");
795+
err = WRN_BAD_SAMPLE;
796+
}
797+
}
798+
799+
return err;
800+
}
801+
802+
783803
int xdi_is_datestring(char *inp) {
784804
/* tests if input string is a valid datetime timestamp.
785805
This uses regular expression to check format and validates
@@ -824,6 +844,7 @@ int xdi_is_datestring(char *inp) {
824844
return 0;
825845
}
826846

847+
827848
int XDI_validate_scan(XDIFile *xdifile, char *name, char *value) {
828849
int err;
829850

c/xdifile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ static char *ValidElems[] =
144144
#define WRN_DATE_FORMAT 512
145145
#define WRN_DATE_RANGE 1024
146146
#define WRN_BAD_DSPACING 2048
147+
#define WRN_BAD_SAMPLE 4096
147148

148149
/* errors reading the XDI file */
149150
#define ERR_NOTXDI -1 /* used */

0 commit comments

Comments
 (0)