Skip to content

Commit

Permalink
solves and closes #1970 (#1975)
Browse files Browse the repository at this point in the history
Co-authored-by: Giloo <gildas@localhost>
  • Loading branch information
GillesDuvert and Giloo authored Jan 31, 2025
1 parent e7d09ee commit e7ccf8c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,22 @@ std::stringstream accept_comma_and_complex_default_format(std::stringstream & is
if (parIn->Type() == GDL_STRING) return std::stringstream(is.str());

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

// for Complex, compting cases is complex since (12) eq (12,12) eq 12 ... count 1
// for Complex, counting cases is complex since (12) eq (12,12) eq 12 ... count 1
int flag_cplx = 0;
if ((parIn->Type() == GDL_COMPLEX) || (parIn->Type() == GDL_COMPLEXDBL)) flag_cplx = 1;
// int open_brace=0;
//int loop=0;

SizeT NToTransfer=parIn->N_Elements();
if (parIn->Type() == GDL_STRUCT) NToTransfer=parIn->ToTransfer();
std::stringstream temp;
char c;
int loop = 0;
int open_brace = 0;
//repeat as many elements necessary, but no more!
//for (SizeT ielem=0; ielem < (*par)->N_Elements(); ++ielem ) {
if (debug) std::cout << "nb elems : " << parIn->N_Elements() << std::endl;
if (debug) std::cout << "nb elems : " << NToTransfer << std::endl;

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

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

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

} // for loop

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

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

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


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

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

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

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

} // for loop

Expand Down
28 changes: 28 additions & 0 deletions testsuite/test_reads.pro
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,33 @@ if ~ICI_ARRAY_EQUAL(expected_f, f, debug=debug) then ERRORS_ADD, errors, 'case m



; ----- final ----
;
BANNER_FOR_TESTSUITE, 'TEST_READS_MIXING_TYPES', errors, /status
ERRORS_CUMUL, cumul_errors, errors
;
if KEYWORD_SET(test) then STOP
;
end
;
; -------------------------------------
;
pro TEST_READSTRUCT, cumul_errors, help=help, verbose=verbose, no_exit=no_exit, test=test
errors=0
;
rcd = {index: 0l, $
catalogue: 0l, $
date: 0.d}

expected={index: 9l, $
catalogue: 145l, $
date: 97843.973284d}

;
data='9 145 97843.973284'
READS,data, rcd
; problem #1970 was that even the first structure read was not filled correctly.
if ~ICI_ARRAY_EQUAL(expected.date, rcd.date, debug=debug) then ERRORS_ADD, errors, 'case read structure'
; ----- final ----
;
BANNER_FOR_TESTSUITE, 'TEST_READS_MIXING_TYPES', errors, /status
Expand Down Expand Up @@ -488,6 +515,7 @@ TEST_READS_STRING, errors, verbose=verbose, test=test
TEST_READS_MIXED, errors, verbose=verbose, test=test
;
TEST_READS_MIXING_TYPES, errors, verbose=verbose, test=test
TEST_READSTRUCT, errors, verbose=verbose, test=test
;
; ----------------- final message ----------
;
Expand Down

0 comments on commit e7ccf8c

Please sign in to comment.