Skip to content

Commit 3200f06

Browse files
committed
Merge pull request #27 from bruceravel/master
fixed several bugs in libxdifile + completed perl wrapper
2 parents 551f332 + f0dbb6a commit 3200f06

27 files changed

+424
-114
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ perl/XDIFile.inl
3939
perl/pm_to_blib
4040
_Inline/*
4141
perl/t/baddata/coverage.txt
42+
perl/*.inl
4243

4344
*.aux
4445
*.dvi
4546
*.nav
4647
*.out
4748
*.snm
4849
*.toc
50+
latex/xdi.log
51+
latex/xdi.pdf
4952
doc/Poster_XAFS15/XDI_Poster.log

c/xdi_reader.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ int main(int argc, char **argv) {
3434
xdifile = malloc(sizeof(XDIFile));
3535
ret = XDI_readfile(argv[1], xdifile);
3636
if (ret < 0) {
37-
printf("Error reading XDI file '%s':\n %s\n",
38-
argv[1], XDI_errorstring(ret));
37+
printf("Error reading XDI file '%s':\n %s\t(error code = %ld)\n",
38+
argv[1], XDI_errorstring(ret), ret);
3939
return 1;
4040
}
4141

42+
if (ret > 0) {
43+
printf("Warning reading XDI file '%s':\n %s\t(error code = %ld)\n\n",
44+
argv[1], XDI_errorstring(ret), ret);
45+
}
46+
4247
printf("#------\n# XDI FILE Read %s VERSIONS: |%s|%s|\n" ,
4348
xdifile->filename, xdifile->xdi_version, xdifile->extra_version);
4449

@@ -59,11 +64,10 @@ int main(int argc, char **argv) {
5964
tdat = (double *)calloc(xdifile->npts, sizeof(double));
6065
for (j = 0; j < xdifile->narrays; j++ ) {
6166
ret = XDI_get_array_name(xdifile,xdifile->array_labels[j], tdat);
62-
printf(" %ld %9s: ", j, xdifile->array_labels[j], ret);
67+
printf(" %ld %9s: ", j, xdifile->array_labels[j]);
6368
for (k=0; k < nout; k++) { printf("%.8g, ", tdat[k]); }
64-
printf("\n");
65-
/* printf("..., %.8g, %.8g\n", tdat[xdifile->npts-2], tdat[xdifile->npts-1]);
66-
*/
69+
/* printf("\n"); */
70+
printf("..., %.8g, %.8g\n", tdat[xdifile->npts-2], tdat[xdifile->npts-1]);
6771
}
6872

6973
if ((strlen(xdifile->outer_label) > 0)&& xdifile->nouter > 1) {

c/xdifile.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ _EXPORT(char*) XDI_errorstring(int errcode) {
4343
} else if (errcode == ERR_NCOLS_CHANGE) {
4444
return "number of columns changes in file";
4545
} else if (errcode == ERR_NONNUMERIC) {
46-
return "non-numeric value in data table";
46+
return "non-numeric value in data table or for d-spacing";
4747
} else if (errcode == ERR_IGNOREDMETA) {
4848
return "contains unrecognized header lines";
4949
}
@@ -95,7 +95,7 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
9595
char *header[MAX_LINES];
9696
char *words[MAX_WORDS], *cwords[2];
9797
char *col_labels[MAX_COLUMNS], *col_units[MAX_COLUMNS];
98-
char *c, *line, *mkey, *mval, *version_xdi, *version_extra;
98+
char *c, *line, *fullline, *mkey, *mval, *version_xdi, *version_extra;
9999
char *reword;
100100
char tlabel[32];
101101
char comments[1024] = "";
@@ -119,7 +119,7 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
119119
COPY_STRING(xdifile->xdi_version, "");
120120
COPY_STRING(xdifile->extra_version, "");
121121
COPY_STRING(xdifile->element, "__");
122-
COPY_STRING(xdifile->edge, "K");
122+
COPY_STRING(xdifile->edge, "_");
123123
COPY_STRING(xdifile->comments, "");
124124
COPY_STRING(xdifile->error_line, "");
125125
COPY_STRING(xdifile->outer_label, "");
@@ -170,8 +170,9 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
170170
nheader= index of first line that does not start with '#'
171171
*/
172172
for (i = 1; i < ilen ; i++) {
173-
if ((strlen(textlines[i]) > 3) &&
174-
(strncmp(textlines[i], TOK_COMM, 1) != 0)) {
173+
regex_status = slre_match(1, DATALINE, textlines[i], strlen(textlines[i]));
174+
if ((strlen(textlines[i]) > 3) && (regex_status == NULL)) {
175+
/* (strncmp(textlines[i], TOK_COMM, 1) != 0)) { */
175176
break;
176177
}
177178
}
@@ -188,7 +189,9 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
188189

189190
if (strncmp(textlines[i], TOK_COMM, 1) == 0) {
190191
COPY_STRING(line, textlines[i]);
192+
COPY_STRING(fullline, textlines[i]);
191193
line++;
194+
fullline++;
192195
nwords = split_on(line, TOK_DELIM, words);
193196
if (nwords < 1) { continue; }
194197
COPY_STRING(mkey, words[0]);
@@ -269,10 +272,10 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
269272
if ((strlen(comments) > 0) && strlen(comments) < sizeof(comments)) {
270273
strncat(comments, "\n", sizeof(comments)-strlen(comments) - 1);
271274
}
272-
if (strlen(line) + 1 > sizeof(comments) - strlen(comments)) {
275+
if (strlen(fullline) + 1 > sizeof(comments) - strlen(comments)) {
273276
printf("Warning.... user comment may be truncated!\n");
274277
}
275-
strncat(comments, line, sizeof(comments) - strlen(comments) - 1);
278+
strncat(comments, fullline, sizeof(comments) - strlen(comments) - 1);
276279
} else if (mode == 0) {
277280
return ERR_META_FORMAT;
278281
}
@@ -282,8 +285,8 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
282285
}
283286
}
284287
}
285-
if (has_minusline == 0) { iret = ERR_NOMINUSLINE; }
286288
if (ignored_headerline > 0) { iret = ERR_IGNOREDMETA; }
289+
if (has_minusline == 0) { iret = ERR_NOMINUSLINE; }
287290

288291
/* check edge, element, return error code if invalid */
289292
valid = 0;
@@ -350,7 +353,7 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
350353
/* loop through data table, inserting data into xdifile->array */
351354
ipt = 0;
352355
iouter = 1;
353-
for (i = nheader-2; i < ilen; i++) {
356+
for (i = nheader-2; i <= ilen; i++) {
354357
/* may find a header line interspersed in array data */
355358
COPY_STRING(line, textlines[i]);
356359
xdifile->error_lineno = i;

c/xdifile.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ _EXPORT(int) XDI_get_array_name(XDIFile *xdifile, char *name, double *out);
6262
#define FAMILYNAME "^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_][ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789]+$"
6363
#define KEYNAME "^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789]+$"
6464

65+
#define DATALINE "^[ \t]*[0123456789.]"
6566

6667
/* Notes:
6768
1. The absorption edge must be one of those listed in ValidEdges below
@@ -94,7 +95,7 @@ static char *ValidElems[] =
9495

9596

9697
/* error codes
97-
< 1 data file is not valid
98+
< 0 data file is not valid
9899
= 0 all OK.
99100
> 0 data file is valid but may be incomplete as XAFS data
100101
*/

filemagic/install_magic

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/sh
2+
##################################################
3+
## install magic for recognizing XDI files into
4+
## system magic file
5+
##################################################
6+
## this must be run as root/sudo
7+
##################################################
8+
9+
10+
showhelp () {
11+
echo "
12+
install_magic: append file magic for XDI file to system magic file
13+
14+
install_magic [filename] [-h]
15+
filename specify location of system magic file (default=/etc/magic)
16+
-h show this help
17+
"
18+
}
19+
20+
## ======== identify system file =========================
21+
system_file=/etc/magic
22+
if [ $1 ]; then
23+
system_file=$1
24+
fi
25+
if [ "$system_file" = '-h' ]; then
26+
showhelp
27+
exit 0
28+
fi
29+
tempfile=./system.magic
30+
31+
## ======== sanity checking ==============================
32+
if [ `whoami` != 'root' ]; then
33+
echo "install_magic: this script must be run as root"
34+
exit 0
35+
fi
36+
37+
if [ ! -e $system_file ]; then
38+
echo "install_magic: magic file not found at '$system_file'"
39+
exit 0
40+
fi
41+
42+
## ======== append XDi magic to system file ==============
43+
cp $system_file $tempfile # make a copy of the system magic file
44+
sed -i "/# ----- XDI/,/# ----- XDI/ d" $tempfile # remove any previous definition of an XDI file
45+
cat $tempfile magic > $system_file # concatinate system file with XDI definition
46+
rm $tempfile # remove copy of old system file

filemagic/magic

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# ----- XDI files: file(1) magic for XAS Data Interchange (XDI) files
2+
#
3+
0 string #\ XDI/ XAS Data Interchange file
4+
>&0 regex [0-9.]+ -- XDI specification %s
5+
# ----- XDI files

filemagic/xdi.ico

11.9 KB
Binary file not shown.

filemagic/xdi.reg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Windows Registry Editor Version 5.00
2+
3+
[HKEY_CLASSES_ROOT\.xdi]
4+
5+
[HKEY_CLASSES_ROOT\.tj\DefaultIcon]
6+
@="C:\\path\\to\\xdi.ico"

magic

Lines changed: 0 additions & 11 deletions
This file was deleted.

perl/Makefile.PL

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11

2-
use Inline::MakeMaker;
2+
BEGIN {
3+
eval {
4+
require Inline::MakeMaker;
5+
};
6+
if ($@) {
7+
print "You need to install the 'Inline' perl module before building the XDI perl wrapper.
8+
See https://metacpan.org/release/Inline
9+
or install from a package for your system:
10+
debian/ubuntu: libinline-perl
11+
redhat/mandriva: perl-Inline
12+
suse: perl-Inline
13+
gentoo: dev-perl/Inline
14+
";
15+
exit;
16+
}
17+
}
18+
19+
import Inline::MakeMaker;
320

421
WriteMakefile(
522
NAME => 'Xray::XDI',
623
VERSION_FROM => 'lib/Xray/XDI.pm', # finds $VERSION
724
PREREQ_PM => {
825
Inline => 0.5,
26+
Inline::C => 0.62,
927
Moose => 2.06,
1028
'MooseX::NonMoose' => 0.22,
1129
'MooseX::Aliases' => 0.10,
@@ -31,4 +49,4 @@ WriteMakefile(
3149
# This work is published from: United States.
3250
#
3351
# Author: Bruce Ravel (bravel AT bnl DOT gov).
34-
# Last update: 8 September, 2012
52+
# Last update: 22 July, 2014

0 commit comments

Comments
 (0)