Skip to content

Commit 077b6cd

Browse files
author
Giloo
committed
1 parent f2bdf27 commit 077b6cd

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

src/read.cpp

+15-14
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,22 @@ std::stringstream accept_comma_and_complex_default_format(std::stringstream & is
4040
if (parIn->Type() == GDL_STRING) return std::stringstream(is.str());
4141

4242
bool debug = false;
43-
if (debug) std::cout << "the raw full input :" << is.str() << std::endl;
43+
if (debug) std::cout << "the raw full input (1):" << is.str() << std::endl;
4444

45-
// for Complex, compting cases is complex since (12) eq (12,12) eq 12 ... count 1
45+
// for Complex, counting cases is complex since (12) eq (12,12) eq 12 ... count 1
4646
int flag_cplx = 0;
4747
if ((parIn->Type() == GDL_COMPLEX) || (parIn->Type() == GDL_COMPLEXDBL)) flag_cplx = 1;
48-
// int open_brace=0;
49-
//int loop=0;
50-
48+
SizeT NToTransfer=parIn->N_Elements();
49+
if (parIn->Type() == GDL_STRUCT) NToTransfer=parIn->ToTransfer();
5150
std::stringstream temp;
5251
char c;
5352
int loop = 0;
5453
int open_brace = 0;
5554
//repeat as many elements necessary, but no more!
5655
//for (SizeT ielem=0; ielem < (*par)->N_Elements(); ++ielem ) {
57-
if (debug) std::cout << "nb elems : " << parIn->N_Elements() << std::endl;
56+
if (debug) std::cout << "nb elems : " << NToTransfer << std::endl;
5857

59-
for (int ielem = 0; ielem < parIn->N_Elements(); ++ielem) {
58+
for (int ielem = 0; ielem < NToTransfer; ++ielem) {
6059

6160
loop++;
6261
while (is.get(c)) { //remove starting blanks, commas, tabs, newlines
@@ -88,7 +87,7 @@ std::stringstream accept_comma_and_complex_default_format(std::stringstream & is
8887
temp.put(' '); //put a spearator between values
8988

9089
// this is a security if the input is really badly formatted
91-
if (loop > 5 * parIn->N_Elements()) break;
90+
if (loop > 5 * NToTransfer) break;
9291

9392
} // for loop
9493

@@ -102,22 +101,24 @@ std::stringstream accept_comma_and_complex_default_format(std::istream *is, Base
102101
assert (parIn->Type() != GDL_STRING);
103102

104103
bool debug = false;
104+
if (debug) std::cout << "the raw full input (2):" << is << std::endl;
105105

106-
// for Complex, compting cases is complex since (12) eq (12,12) eq 12 ... count 1
106+
// for Complex, counting cases is complex since (12) eq (12,12) eq 12 ... count 1
107107
int flag_cplx = 0;
108108
if ((parIn->Type() == GDL_COMPLEX) || (parIn->Type() == GDL_COMPLEXDBL)) flag_cplx = 1;
109-
// int open_brace=0;
110-
//int loop=0;
109+
SizeT NToTransfer=parIn->N_Elements();
110+
if (parIn->Type() == GDL_STRUCT) NToTransfer=parIn->ToTransfer();
111+
111112

112113
std::stringstream temp;
113114
char c;
114115
int loop = 0;
115116
int open_brace = 0;
116117
//repeat as many elements necessary, but no more!
117118
//for (SizeT ielem=0; ielem < (*par)->N_Elements(); ++ielem ) {
118-
if (debug) std::cout << "nb elems : " << parIn->N_Elements() << std::endl;
119+
if (debug) std::cout << "nb elems : " << NToTransfer << std::endl;
119120

120-
for (int ielem = 0; ielem < parIn->N_Elements(); ++ielem) {
121+
for (int ielem = 0; ielem < NToTransfer; ++ielem) {
121122

122123
loop++;
123124
while (is->get(c)) { //remove starting blanks, commas, tabs, newlines
@@ -149,7 +150,7 @@ std::stringstream accept_comma_and_complex_default_format(std::istream *is, Base
149150
temp.put(' '); //put a spearator between values
150151

151152
// this is a security if the input is really badly formatted
152-
if (loop > 5 * parIn->N_Elements()) break;
153+
if (loop > 5 * NToTransfer) break;
153154

154155
} // for loop
155156

testsuite/test_reads.pro

+28
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,33 @@ if ~ICI_ARRAY_EQUAL(expected_f, f, debug=debug) then ERRORS_ADD, errors, 'case m
454454

455455

456456

457+
; ----- final ----
458+
;
459+
BANNER_FOR_TESTSUITE, 'TEST_READS_MIXING_TYPES', errors, /status
460+
ERRORS_CUMUL, cumul_errors, errors
461+
;
462+
if KEYWORD_SET(test) then STOP
463+
;
464+
end
465+
;
466+
; -------------------------------------
467+
;
468+
pro TEST_READSTRUCT, cumul_errors, help=help, verbose=verbose, no_exit=no_exit, test=test
469+
errors=0
470+
;
471+
rcd = {index: 0l, $
472+
catalogue: 0l, $
473+
date: 0.d}
474+
475+
expected={index: 9l, $
476+
catalogue: 145l, $
477+
date: 97843.973284d}
478+
479+
;
480+
data='9 145 97843.973284'
481+
READS,data, rcd
482+
; problem #1970 was that even the first structure read was not filled correctly.
483+
if ~ICI_ARRAY_EQUAL(expected.date, rcd.date, debug=debug) then ERRORS_ADD, errors, 'case read structure'
457484
; ----- final ----
458485
;
459486
BANNER_FOR_TESTSUITE, 'TEST_READS_MIXING_TYPES', errors, /status
@@ -488,6 +515,7 @@ TEST_READS_STRING, errors, verbose=verbose, test=test
488515
TEST_READS_MIXED, errors, verbose=verbose, test=test
489516
;
490517
TEST_READS_MIXING_TYPES, errors, verbose=verbose, test=test
518+
TEST_READSTRUCT, errors, verbose=verbose, test=test
491519
;
492520
; ----------------- final message ----------
493521
;

0 commit comments

Comments
 (0)