Skip to content

Commit 9ea2c5e

Browse files
committed
Merge pull request #52 from XraySpectroscopy/warning_codes
Warning codes
2 parents d85a419 + b5a0a86 commit 9ea2c5e

File tree

6 files changed

+84
-33
lines changed

6 files changed

+84
-33
lines changed

c/README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -289,24 +289,31 @@ translation of a table of error messages into another language.
289289
290290
Here `<word>` will be the text that triggered the error.
291291
292-
### XDI_readfile and XDI_validate_item warning codes
292+
### XDI_readfile warning codes
293293
294294
| code | message |
295295
| ----: | ------------------------------------------------------------ |
296296
| 1 | no mono.d_spacing given with angle array |
297297
| 2 | no line of minus signs '#-----' separating header from data |
298298
| 4 | contains unrecognized header lines |
299-
| 8 | element.symbol missing or not valid |
300-
| 16 | element.edge missing or not valid |
301-
| 32 | element.reference not valid |
302-
| 64 | element.ref\_edge not valid |
303-
| 128 | extension field used without versioning information |
304-
| 256 | Column.1 is not "energy" or "angle" |
305-
| 512 | invalid timestamp: format should be ISO 8601 (YYYY-MM-DD HH:MM:SS) |
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 |
299+
300+
301+
### XDI_validate_item warning codes
302+
303+
304+
| code | message |
305+
| ----: | ------------------------------------------------------------ |
306+
| 100 | element.symbol missing or not valid |
307+
| 101 | element.edge missing or not valid |
308+
| 102 | element.reference not valid |
309+
| 103 | element.ref\_edge not valid |
310+
| 104 | extension field used without versioning information |
311+
| 105 | Column.1 is not "energy" or "angle" |
312+
| 106 | invalid timestamp: format should be ISO 8601 (YYYY-MM-DD HH:MM:SS) |
313+
| 107 | invalid timestamp: date out of valid range |
314+
| 108 | <not used> |
315+
| 109 | bad value in Sample namespace |
316+
| 110 | bad value in Facility namespace |
310317
311318
312319
### XDI_required_metadata return codes

c/xdifile.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ XDI_validate_item(XDIFile *xdifile, char *family, char *name, char *value) {
767767

768768

769769
/***************************************************************************/
770-
/* all tests in the Facility familty should return WRN_BAD_FACILITY if the */
770+
/* all tests in the Facility family should return WRN_BAD_FACILITY if the */
771771
/* value does not match the definition. error_message should explain */
772772
/* the problem in a way that is appropruiate to the metadata item */
773773
/***************************************************************************/
@@ -821,7 +821,7 @@ int XDI_validate_mono(XDIFile *xdifile, char *name, char *value) {
821821
}
822822

823823
/***********************************************************************/
824-
/* all tests in the Sample familty should return WRN_BAD_SAMPLE if the */
824+
/* all tests in the Sample family should return WRN_BAD_SAMPLE if the */
825825
/* value does not match the definition. error_message should explain */
826826
/* the problem in a way that is appropruiate to the metadata item */
827827
/***********************************************************************/
@@ -849,11 +849,12 @@ int XDI_validate_sample(XDIFile *xdifile, char *name, char *value) {
849849
}
850850

851851

852+
/**************************************************************/
853+
/* tests if input string is a valid datetime timestamp. */
854+
/* This uses regular expression to check format and validates */
855+
/* range of values, though not exhaustively. */
856+
/**************************************************************/
852857
int xdi_is_datestring(char *inp) {
853-
/* tests if input string is a valid datetime timestamp.
854-
This uses regular expression to check format and validates
855-
range of values, though not exhaustively.
856-
*/
857858
int regex_status;
858859
struct slre_cap caps[6];
859860
int year, month, day, hour, minute, sec;

c/xdifile.h

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,18 @@ static char *ValidElems[] =
142142
#define WRN_NODSPACE 1
143143
#define WRN_NOMINUSLINE 2
144144
#define WRN_IGNOREDMETA 4
145-
/* warnings from metadata value validation */
146-
#define WRN_NOELEM 8
147-
#define WRN_NOEDGE 16
148-
#define WRN_REFELEM 32
149-
#define WRN_REFEDGE 64
150-
#define WRN_NOEXTRA 128
151-
#define WRN_BAD_COL1 256
152-
#define WRN_DATE_FORMAT 512
153-
#define WRN_DATE_RANGE 1024
154-
#define WRN_BAD_DSPACING 2048
155-
#define WRN_BAD_SAMPLE 4096
156-
#define WRN_BAD_FACILITY 8192
145+
/* warnings from metadata value validation, these are not use bitwise */
146+
#define WRN_NOELEM 100
147+
#define WRN_NOEDGE 101
148+
#define WRN_REFELEM 102
149+
#define WRN_REFEDGE 103
150+
#define WRN_NOEXTRA 104
151+
#define WRN_BAD_COL1 105
152+
#define WRN_DATE_FORMAT 106
153+
#define WRN_DATE_RANGE 107
154+
#define WRN_BAD_DSPACING 108
155+
#define WRN_BAD_SAMPLE 109
156+
#define WRN_BAD_FACILITY 110
157157

158158
/* errors reading the XDI file */
159159
#define ERR_NOTXDI -1 /* used */
@@ -167,6 +167,13 @@ static char *ValidElems[] =
167167
/* _EXPORT(char*) XDI_errorstring(int errcode); */
168168

169169

170+
/* List of required metadata items */
171+
static char *RequiredMetadata[] =
172+
{ /* these are the bits of the errorcode returned by XDI_recommended_metadata */
173+
"Element.symbol", /* 2^0 */
174+
"Element.edge", /* 2^1 */
175+
"Mono.d_spacing", /* 2^2 */
176+
};
170177
/* List of recommended metadata items */
171178
static char *RecommendedMetadata[] =
172179
{ /* these are the bits of the errorcode returned by XDI_recommended_metadata */

languages/perl/example/xdi_reader.pl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,17 @@
1111
use Xray::XDI;
1212

1313
my $xdi = Xray::XDI->new(file=>$ARGV[0]||"");
14-
print "Syntax: xdi_reader.pl filename\n", exit if not defined($xdi->xdifile);
15-
printf "Error reading XDI file '%s':\n\t%s\t(error code = %d)\n", $ARGV[0], $xdi->errormessage, $xdi->errorcode, exit if $xdi->errorcode < 0;
16-
printf "Warning reading XDI file '%s':\n\t%s\t(warning code = %d)\n\n", $ARGV[0], $xdi->errormessage, $xdi->errorcode if $xdi->errorcode > 0;
14+
if (not defined($xdi->xdifile)) {
15+
print "Syntax: xdi_reader.pl filename\n";
16+
exit;
17+
};
18+
if ($xdi->errorcode < 0) {
19+
printf "Error reading XDI file '%s':\n\t%s\t(error code = %d)\n", $ARGV[0], $xdi->errormessage, $xdi->errorcode;
20+
exit;
21+
};
22+
if ($xdi->errorcode > 0) {
23+
printf "Warning reading XDI file '%s':\n\t%s\t(warning code = %d)\n\n", $ARGV[0], $xdi->errormessage, $xdi->errorcode;
24+
};
1725

1826

1927
print "#------\n";

languages/perl/lib/Xray/XDI.pm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,21 @@ sub required {
274274
$self->errormessage($self->xdifile->_error_message);
275275
return $i;
276276
};
277+
sub required_list {
278+
my ($self) = @_;
279+
return Xray::XDIFile->_required_list;
280+
};
277281
sub recommended {
278282
my ($self) = @_;
279283
my $i = $self->xdifile->_recommended_metadata;
280284
$self->errorcode($i);
281285
$self->errormessage($self->xdifile->_error_message);
282286
return $i;
283287
};
288+
sub recommended_list {
289+
my ($self) = @_;
290+
return Xray::XDIFile->_recommended_list;
291+
};
284292

285293
sub validate {
286294
my ($self, $family, $name, $value) = @_;

languages/perl/lib/Xray/XDIFile.pm

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,32 @@ int _required_metadata(SV* obj) {
160160
return ret;
161161
}
162162
163+
void _required_list(SV* obj) {
164+
long i;
165+
Inline_Stack_Vars;
166+
Inline_Stack_Reset;
167+
for (i=0; i < sizeof(RequiredMetadata)/sizeof(RequiredMetadata[0]); i++) {
168+
Inline_Stack_Push(sv_2mortal(newSVpv( RequiredMetadata[i], 0 )));
169+
}
170+
Inline_Stack_Done;
171+
}
172+
163173
int _recommended_metadata(SV* obj) {
164174
int ret;
165175
ret = XDI_recommended_metadata((INT2PTR(XDIFile*, SvIV(SvRV(obj)))));
166176
return ret;
167177
}
168178
179+
void _recommended_list(SV* obj) {
180+
long i;
181+
Inline_Stack_Vars;
182+
Inline_Stack_Reset;
183+
for (i=0; i < sizeof(RecommendedMetadata)/sizeof(RecommendedMetadata[0]); i++) {
184+
Inline_Stack_Push(sv_2mortal(newSVpv( RecommendedMetadata[i], 0 )));
185+
}
186+
Inline_Stack_Done;
187+
}
188+
169189
void _cleanup(SV* obj, long err) {
170190
XDI_cleanup((INT2PTR(XDIFile*, SvIV(SvRV(obj)))), err);
171191
}

0 commit comments

Comments
 (0)