Skip to content

Commit f0dbb6a

Browse files
committed
fix bug in xdifile.c where last point was dropped from data table
have xdireader report bottom of data table perl wrapper now passes all tests
1 parent 3ec0385 commit f0dbb6a

File tree

8 files changed

+45
-39
lines changed

8 files changed

+45
-39
lines changed

c/xdi_reader.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ int main(int argc, char **argv) {
6666
ret = XDI_get_array_name(xdifile,xdifile->array_labels[j], tdat);
6767
printf(" %ld %9s: ", j, xdifile->array_labels[j]);
6868
for (k=0; k < nout; k++) { printf("%.8g, ", tdat[k]); }
69-
printf("\n");
70-
/* printf("..., %.8g, %.8g\n", tdat[xdifile->npts-2], tdat[xdifile->npts-1]);
71-
*/
69+
/* printf("\n"); */
70+
printf("..., %.8g, %.8g\n", tdat[xdifile->npts-2], tdat[xdifile->npts-1]);
7271
}
7372

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

c/xdifile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
353353
/* loop through data table, inserting data into xdifile->array */
354354
ipt = 0;
355355
iouter = 1;
356-
for (i = nheader-2; i < ilen; i++) {
356+
for (i = nheader-2; i <= ilen; i++) {
357357
/* may find a header line interspersed in array data */
358358
COPY_STRING(line, textlines[i]);
359359
xdifile->error_lineno = i;

perl/README.org

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ For documentation, once installed:
2626

2727
: perldoc Xray::XDI
2828

29+
*Note:* The compilation of Xray::XDIFile currently generates a large
30+
number of warings about casting pointers to/from integers of different
31+
sizes. This does not affect the preformance of the wrapper, but does
32+
need to be cleaned up eventually.
33+
2934
** DEPENDENCIES
3035

3136
This module requires these modules, all available from cpan and as

perl/lib/Xray/XDI.pm

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -154,31 +154,33 @@ sub _build_object {
154154
my %data = ();
155155
foreach my $i (0 .. $self->narray_labels-1) {
156156
my @x = $obj->_data_array($i);
157+
#print $array_labels[$i], $/;
158+
#print join("|", @x), $/, $/;
157159
$data{$array_labels[$i]} = \@x;
158160
};
159161
$self->data(\%data);
160162

161163
return $obj;
162164
};
163165

164-
use Term::ANSIColor qw(:constants);
165-
sub trace {
166-
my ($self) = @_;
167-
my $max_depth = 30;
168-
my $i = 0;
169-
my ($green, $red, $yellow, $end) = (BOLD.GREEN, BOLD.RED, BOLD.YELLOW, RESET);
170-
local $|=1;
171-
print($/.BOLD."--- Begin stack trace ---$end\n");
172-
while ( (my @call_details = (caller($i++))) && ($i<$max_depth) ) {
173-
my $from = $call_details[1];
174-
my $line = $call_details[2];
175-
my $color = RESET.YELLOW;
176-
(my $func = $call_details[3]) =~ s{(?<=::)(\w+)\z}{$color$1};
177-
print("$green$from$end line $red$line$end in function $yellow$func$end\n");
178-
}
179-
print(BOLD."--- End stack trace ---$end\n");
180-
return $self;
181-
};
166+
# use Term::ANSIColor qw(:constants);
167+
# sub trace {
168+
# my ($self) = @_;
169+
# my $max_depth = 30;
170+
# my $i = 0;
171+
# my ($green, $red, $yellow, $end) = (BOLD.GREEN, BOLD.RED, BOLD.YELLOW, RESET);
172+
# local $|=1;
173+
# print($/.BOLD."--- Begin stack trace ---$end\n");
174+
# while ( (my @call_details = (caller($i++))) && ($i<$max_depth) ) {
175+
# my $from = $call_details[1];
176+
# my $line = $call_details[2];
177+
# my $color = RESET.YELLOW;
178+
# (my $func = $call_details[3]) =~ s{(?<=::)(\w+)\z}{$color$1};
179+
# print("$green$from$end line $red$line$end in function $yellow$func$end\n");
180+
# }
181+
# print(BOLD."--- End stack trace ---$end\n");
182+
# return $self;
183+
# };
182184

183185

184186

perl/lib/Xray/XDIFile.pm

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,25 @@ __C__
109109
#include "xdifile.h"
110110
111111
SV* new(char* class, char* file, SV* errcode) {
112-
XDIFile* xdifile;
113-
long ret;
112+
XDIFile* xdifile;
113+
long ret;
114114
115-
SV* obj_ref = newSViv(0);
116-
SV* obj = newSVrv(obj_ref, class);
115+
SV* obj_ref = newSViv(0);
116+
SV* obj = newSVrv(obj_ref, class);
117117
118-
New(42, xdifile, 1, XDIFile);
119-
xdifile = malloc(sizeof(XDIFile));
118+
Newx(xdifile, 1, XDIFile);
119+
xdifile = malloc(sizeof(XDIFile));
120120
121-
ret = XDI_readfile(file, xdifile);
122-
sv_setiv(errcode, ret);
121+
ret = XDI_readfile(file, xdifile);
122+
sv_setiv(errcode, ret);
123123
124-
sv_setiv(obj, (IV)xdifile);
125-
SvREADONLY_on(obj);
126-
return obj_ref;
124+
sv_setiv(obj, (IV)xdifile);
125+
SvREADONLY_on(obj);
126+
return obj_ref;
127127
}
128128
129129
char* _errorstring(SV* obj, int code) {
130-
return XDI_errorstring(code);
130+
return XDI_errorstring(code);
131131
}
132132
133133
void _valid_edges(SV* obj) {

perl/t/00_base.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ ok($families[6] eq 'Mono', 'specific family');
6363
ok($keywords[6] eq 'name', 'specific keyword');
6464
ok($values[6] eq 'Si 111', 'specific value');
6565

66-
ok($xdifile->_npts == 417, 'npts');
66+
ok($xdifile->_npts == 418, 'npts');
6767
ok($xdifile->_narrays == 3, 'narrays');
6868
ok($xdifile->_narrays == $xdifile->_narray_labels, 'narray_labels');
6969

perl/t/01_moose_nonmoose.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ ok($count == $xdi->nmetadata, 'correct numbe
6767
ok($xdi->metadata->{Mono}->{name} eq 'Si 111', 'fetching Mono.name');
6868
ok($xdi->metadata->{Facility}->{xray_source} eq 'APS undulator A', 'fetching Facility.xray_source');
6969

70-
ok($xdi->npts == 417, 'npts');
70+
ok($xdi->npts == 418, 'npts');
7171
ok($xdi->narrays == 3, 'narrays');
7272
ok($xdi->narrays == $xdi->narray_labels, 'narray_labels');
7373

perl/t/writer/01_pp.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ $xdi->freeze('freeze.xdi');
5757
ok(-s 'foo.xdi' == -s 'write.xdi', 'write alias' );
5858
ok(-s 'foo.xdi' == -s 'freeze.xdi', 'freeze alias');
5959

60-
#unlink 'foo.xdi';
61-
#unlink 'write.xdi';
62-
#unlink 'freeze.xdi';
60+
unlink 'foo.xdi';
61+
unlink 'write.xdi';
62+
unlink 'freeze.xdi';

0 commit comments

Comments
 (0)