Skip to content

Commit 69374f1

Browse files
committed
minor fixes for writing strings 249 - 255 chars
1 parent 0fb7032 commit 69374f1

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

src/writesav.cpp

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ void writesav(const char * filePath, Rcpp::DataFrame dat, uint8_t compress)
139139
tmp1[2] = 1;
140140
tmp1[3] = 0;
141141
} else if (subtyp == -1) {
142-
tmp1[0] = 0;
143-
tmp1[1] = 0;
144-
tmp1[2] = 0;
142+
tmp1[0] = 1;
143+
tmp1[1] = 29;
144+
tmp1[2] = 1;
145145
tmp1[3] = 0;
146146
}
147147

@@ -166,9 +166,9 @@ void writesav(const char * filePath, Rcpp::DataFrame dat, uint8_t compress)
166166
tmp2[2] = 1;
167167
tmp2[3] = 0;
168168
} else if (subtyp == -1) {
169-
tmp2[0] = 0;
170-
tmp2[1] = 0;
171-
tmp2[2] = 0;
169+
tmp2[0] = 1;
170+
tmp2[1] = 29;
171+
tmp2[2] = 1;
172172
tmp2[3] = 0;
173173
}
174174

@@ -306,7 +306,6 @@ void writesav(const char * filePath, Rcpp::DataFrame dat, uint8_t compress)
306306
// double val_d = 0.0;
307307

308308

309-
Rcpp::List buf;
310309
std::vector<double> buf_d;
311310
std::vector<std::string> buf_s;
312311
std::vector<int> flush_type(8);
@@ -365,11 +364,15 @@ void writesav(const char * filePath, Rcpp::DataFrame dat, uint8_t compress)
365364

366365
string val_s = as<string>(as<CharacterVector>(dat[j])[i]);
367366

368-
val_s.resize(type, ' ');
367+
int strlen = type;
368+
if (strlen == 255) strlen = 256;
369+
370+
371+
val_s.resize(strlen, ' ');
369372

370373
// begin writing of the string
371374

372-
int8_t fills = type/8;
375+
int8_t fills = strlen/8;
373376

374377
// Rprintf("type: %d\n", type);
375378
// Rprintf("fills: %d\n", fills);
@@ -388,13 +391,6 @@ void writesav(const char * filePath, Rcpp::DataFrame dat, uint8_t compress)
388391

389392
int strt = 253, strl = 8;
390393

391-
if (pos == 248)
392-
strl = 7;
393-
394-
// if (pos == 256)
395-
// strt = 254;
396-
397-
398394
buf_s.push_back(val_s.substr(pos, strl));
399395
flush_type[iter] = 2;
400396

@@ -490,10 +486,24 @@ void writesav(const char * filePath, Rcpp::DataFrame dat, uint8_t compress)
490486
if ((i == n-1) & (j == kk -1)) {
491487

492488
// Rcout << "--- EOF ---" << std::endl;
489+
// Rprintf("buf_s.size() = %d\n", buf_s.size());
490+
// Rprintf("buf_d.size() = %d\n", buf_d.size());
493491

494-
std::memcpy(&chunk, chnk, sizeof(double));
495-
writebin(chunk, sav, swapit);
496-
iter = 0;
492+
493+
// Rprintf("iter: %d\n", iter);
494+
495+
// chunk is not yet completely written.
496+
if (iter > 0) {
497+
498+
for (int8_t itr = iter; itr < 8; ++itr) {
499+
chnk[itr] = 0;
500+
}
501+
502+
std::memcpy(&chunk, chnk, sizeof(double));
503+
writebin(chunk, sav, swapit);
504+
505+
iter = 0;
506+
}
497507

498508

499509
int di = 0, ds = 0;

0 commit comments

Comments
 (0)