Skip to content

Commit 892a3bc

Browse files
committed
Merge pull request #48 from XraySpectroscopy/allow_neg_data
Allow negative data
2 parents ed6836e + 77410e3 commit 892a3bc

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

c/xdifile.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
241241
}
242242
}
243243
nheader = i+1;
244+
if (nheader < 1) {nheader = 1;}
244245
xdifile->meta_families = calloc(nheader, sizeof(char *));
245246
xdifile->meta_keywords = calloc(nheader, sizeof(char *));
246247
xdifile->meta_values = calloc(nheader, sizeof(char *));
@@ -410,6 +411,7 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
410411
npts_ = ilen - nheader + 1;
411412

412413
nouter = npts_ - 1;
414+
if (nouter < 1) {nouter = 1;}
413415
outer_arr = calloc(nouter, sizeof(double));
414416
outer_pts = calloc(nouter, sizeof(long));
415417
outer_arr[0] = outer_arr0;
@@ -422,7 +424,7 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
422424
COPY_STRING(xdifile->filename, filename);
423425

424426
maxcol++;
425-
427+
if (ncols < 1) {ncols = 1;}
426428
xdifile->array_labels = calloc(ncols, sizeof(char *));
427429
xdifile->array_units = calloc(ncols, sizeof(char *));
428430
has_energy = 0;
@@ -446,6 +448,7 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
446448

447449
/* set size of data arrays */
448450
xdifile->array = calloc(ncols, sizeof(double *));
451+
if (npts_ < 0) {npts_ = 0;}
449452
for (j = 0; j < ncols; j++) {
450453
xdifile->array[j] = calloc(npts_+1, sizeof(double));
451454
if (0 != xdi_strtod(words[j], &dval)) {
@@ -546,6 +549,7 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
546549
xdifile->narrays = ncols;
547550
xdifile->narray_labels = min(ncols, maxcol);
548551
xdifile->nmetadata = ndict+1;
552+
if (iouter < 1) {iouter = 1;}
549553
xdifile->outer_array = calloc(iouter, sizeof(double));
550554
xdifile->outer_breakpts = calloc(iouter, sizeof(long));
551555
for (j= 0; j < iouter; j++) {

c/xdifile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ _EXPORT(void) XDI_cleanup(XDIFile *xdifile, long err);
9999
/* #define FAMILYNAME "(?i)^[a-z_][a-z0-9_]+$" */
100100
/* #define KEYNAME "(?i)^[a-z0-9_]+$" */
101101

102-
#define DATALINE "^([ \\t]*[0-9\\.])"
102+
#define DATALINE "^([ \\t]*[-+]*?[0-9\\.])"
103103

104104
/* Notes:
105105
1. The absorption edge must be one of those listed in ValidEdges below

data/nonxafs_negvalues.xdi

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# XDI/1.1
2+
# Scan.start_time: 2015-04-13 10:36:55
3+
# Column.1: X
4+
# Column.2: Y
5+
# Column.3: Z
6+
# Mono.d_spacing: 3.13477
7+
# Facility.Ring_Lifetime: 9.2 || S:SRlifeTimeHrsCC.VAL
8+
# Facility.Ring_Current: 102.1 || S:SRcurrentAI.VAL
9+
# Facility.xray_source: undultaor, 3.6 cm period, 2.1 m length
10+
# Facility.name: Advanced Photon Source
11+
# Beamline.name: GSECARS, 13-ID-E
12+
#--------------
13+
# X Y Z
14+
-0.500 0.150 1.000
15+
-0.400 0.250 1.000
16+
-0.300 0.350 2.000
17+
-0.200 0.470 3.500
18+
-0.100 0.520 3.800
19+
0.000 0.550 4.100
20+
0.200 0.590 4.400
21+
0.300 0.660 4.300
22+
0.400 0.710 3.900
23+
0.500 0.720 3.600

0 commit comments

Comments
 (0)