Skip to content

Commit ab18530

Browse files
committed
abstract out the list of recommended metadata items to xdifile.h
1 parent 9c341fc commit ab18530

File tree

2 files changed

+38
-29
lines changed

2 files changed

+38
-29
lines changed

c/xdifile.c

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -678,40 +678,38 @@ XDI_required_metadata(XDIFile *xdifile) {
678678

679679
_EXPORT(int)
680680
XDI_recommended_metadata(XDIFile *xdifile) {
681-
int ret, i;
682-
683-
ret = pow(2,5)-1;
681+
int ret, i, n, errcode, found;
682+
int n_rec = sizeof(RecommendedMetadata)/sizeof(char*);
683+
char *words[2];
684+
char thisword[100] = {'\0'};
685+
int nwords;
686+
687+
/* ret = pow(2,n_rec+1)-1; */
688+
ret = (1<<(n_rec)) - 1;
684689
strcpy(xdifile->error_message, "");
685690

686-
for (i=0; i < xdifile->nmetadata; i++) {
687-
if ((strcasecmp(xdifile->meta_families[i], "facility") == 0) && (strcasecmp(xdifile->meta_keywords[i], "name") == 0)) {
688-
ret = ret-1; /* 2^0 */
689-
continue;
690-
}
691-
if ((strcasecmp(xdifile->meta_families[i], "facility") == 0) && (strcasecmp(xdifile->meta_keywords[i], "xray_source") == 0)) {
692-
ret = ret-2; /* 2^1 */
693-
continue;
694-
}
695-
if ((strcasecmp(xdifile->meta_families[i], "beamline") == 0) && (strcasecmp(xdifile->meta_keywords[i], "name") == 0)) {
696-
ret = ret-4; /* 2^2 */
697-
continue;
698-
}
699-
if ((strcasecmp(xdifile->meta_families[i], "scan") == 0) && (strcasecmp(xdifile->meta_keywords[i], "start_time") == 0)) {
700-
ret = ret-8; /* 2^3 */
701-
continue;
691+
692+
for (n=0; n<n_rec; n++) {
693+
found = 0;
694+
/* errcode = pow(2,n); */
695+
errcode = 1<<n;
696+
/* printf("%d %d %s\n", ret, errcode, RecommendedMetadata[n]); */
697+
strcpy(thisword, RecommendedMetadata[n]);
698+
nwords = split_on(thisword, TOK_DOT, words);
699+
700+
for (i=0; i < xdifile->nmetadata; i++) {
701+
if ((strcasecmp(xdifile->meta_families[i], words[0]) == 0) && (strcasecmp(xdifile->meta_keywords[i], words[1]) == 0)) {
702+
ret = ret-errcode;
703+
found = 1;
704+
break;
705+
}
702706
}
703-
if ((strcasecmp(xdifile->meta_families[i], "column") == 0) && (strcasecmp(xdifile->meta_keywords[i], "1") == 0)) {
704-
ret = ret-16; /* 2^4 */
705-
continue;
707+
if (found == 0) {
708+
strcat(xdifile->error_message, "Missing recommended metadata field: ");
709+
strcat(xdifile->error_message, RecommendedMetadata[n]);
710+
strcat(xdifile->error_message, "\n");
706711
}
707712
}
708-
/* printf("%d\n", ret); */
709-
710-
if (ret & 1) { strcat(xdifile->error_message, "Missing recommended metadata field: Facility.name\n"); }
711-
if (ret & 2) { strcat(xdifile->error_message, "Missing recommended metadata field: Facility.source\n"); }
712-
if (ret & 4) { strcat(xdifile->error_message, "Missing recommended metadata field: Beamline.name\n"); }
713-
if (ret & 8) { strcat(xdifile->error_message, "Missing recommended metadata field: Scan.start_time\n"); }
714-
if (ret & 16) { strcat(xdifile->error_message, "Missing recommended metadata field: Column.1\n"); }
715713

716714
return ret;
717715
}

c/xdifile.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,14 @@ static char *ValidElems[] =
156156
#define ERR_MEMERROR -64 /* NOT used */
157157

158158
/* _EXPORT(char*) XDI_errorstring(int errcode); */
159+
160+
161+
/* List of recommended metadata items */
162+
static char *RecommendedMetadata[] =
163+
{ /* these are the bits of the errorcode returned by XDI_recommended_metadata */
164+
"Facility.name", /* 2^0 */
165+
"Facility.xray_source", /* 2^1 */
166+
"Beamline.name", /* 2^2 */
167+
"Scan.start_time", /* 2^3 */
168+
"Column.1", /* 2^4 */
169+
};

0 commit comments

Comments
 (0)