Skip to content

Commit

Permalink
Revert "research case 8"
Browse files Browse the repository at this point in the history
This reverts commit 28a0178.
  • Loading branch information
JanMarvin committed Sep 17, 2024
1 parent a941e35 commit f692c29
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 81 deletions.
76 changes: 27 additions & 49 deletions src/readsas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,9 @@ Rcpp::List readsas(const char * filePath,

if (debug)
Rcpp::Rcout << "SH_OFF: " << potabs[i].SH_OFF
<< " SH_LEN: " << potabs[i].SH_LEN
<< " COMPR.: " << (int32_t)potabs[i].COMPRESSION
<< " SH_TYPE: " << (int32_t)potabs[i].SH_TYPE << std::endl;
<< "SH_LEN: " << potabs[i].SH_LEN
<< "COMPR.: " << potabs[i].COMPRESSION
<< "SH_TYPE: " << potabs[i].SH_TYPE << std::endl;

dataoff = potabs[i].SH_OFF - ((double)rowsperpage[pg] * rowlength);

Expand Down Expand Up @@ -670,7 +670,6 @@ Rcpp::List readsas(const char * filePath,
if (page0not)
sas_offset_table = 10;

// Rcpp::Rcout << sas_offset_table << std::endl;

switch(sas_offset_table)
{
Expand Down Expand Up @@ -713,16 +712,15 @@ Rcpp::List readsas(const char * filePath,
delobs = readbin(delobs, sas, swapit);
if (debug) Rcout << "delobs " << delobs << std::endl;
unk64 = readbin(unk64, sas, swapit);
if (debug) Rcout << unk64 << std::endl; // 0
if (debug) Rcout << unk64 << std::endl;

colf_p1 = readbin(colf_p1, sas, swapit);
if (debug) Rcout << colf_p1 << std::endl; // number of variables on page1
if (debug) Rcout << colf_p1 << std::endl;
colf_p2 = readbin(colf_p2, sas, swapit);
if (debug) Rcout << colf_p2 << std::endl; // number of variables on page2
unk64 = readbin(unk64, sas, swapit); // lenremain of case 8
// if (debug)
Rcout << "lenremain case8: "<< unk64 << std::endl;
unk64 = readbin(unk64, sas, swapit); //
if (debug) Rcout << colf_p2 << std::endl;
unk64 = readbin(unk64, sas, swapit); // p3 and p4?
if (debug) Rcout << unk64 << std::endl;
unk64 = readbin(unk64, sas, swapit);
if (debug) Rcout << unk64 << std::endl;
pgsize = readbin(pgsize, sas, swapit);
if (debug) Rcout << "pgsize " << pgsize << std::endl;
Expand Down Expand Up @@ -938,10 +936,9 @@ Rcpp::List readsas(const char * filePath,
colf_p2 = readbin((int32_t)colf_p2, sas, swapit);
if (debug) Rcout << "colfp2 " << colf_p2 << std::endl;
unk32 = readbin(unk32, sas, swapit);
Rcout << "lenremain case8: "<< unk32 << std::endl;
if (debug) Rcout << unk32 << std::endl;
unk32 = readbin(unk32, sas, swapit);
// if (debug)
Rcout << unk32 << std::endl;
if (debug) Rcout << unk32 << std::endl;
pgsize = readbin((int32_t)pgsize, sas, swapit);
if (debug) Rcout << "pgsize " << pgsize << std::endl;
unk32 = readbin(unk32, sas, swapit);
Expand Down Expand Up @@ -1403,7 +1400,7 @@ Rcpp::List readsas(const char * filePath,

if (debug)
Rcpp::Rcout << comprlen << ", "
<< (uint32_t)tmp << ", "
<< tmp << ", "
<< proclen << ", "
<< swlen << "; "
<< varname_pos[0]
Expand Down Expand Up @@ -1523,9 +1520,6 @@ Rcpp::List readsas(const char * filePath,


}

if (debug)
Rcpp::Rcout << "SH_LEN " << potabs[sc].SH_LEN << std::endl;

break;
}
Expand Down Expand Up @@ -1618,64 +1612,48 @@ Rcpp::List readsas(const char * filePath,
lenremain = readbin((int32_t)lenremain, sas, swapit);
}

// if (debug)
if (debug)
Rcout << "lenremain "<< lenremain << std::endl; // 92

unk16 = readbin(unk16, sas, swapit);
if (debug) Rcout << unk16 << std::endl; // number of varnames?
// Rcout << unk16 << std::endl; // number of varnames?
cls = readbin(cls, sas, swapit);
if (debug) Rcout << "cls: " << cls << std::endl; // counter for unk loop below
// Rcout << cls << std::endl; // counter for unk loop below
unk16 = readbin(unk16, sas, swapit);
if (debug) Rcout << unk16 << std::endl; // 1
// Rcout << unk16 << std::endl; // 1
unk16 = readbin(unk16, sas, swapit);
if (debug) Rcout << "varnames: " << unk16 << std::endl; // number of varnames?
// Rcout << unk16 << std::endl; // number of varnames?
unk16 = readbin(unk16, sas, swapit); // 3233
if (debug) Rcout << unk16 << std::endl; // 0
// Rcout << unk16 << std::endl; // 0
unk16 = readbin(unk16, sas, swapit); // 3233
if (debug) Rcout << unk16 << std::endl; // 0
// Rcout << unk16 << std::endl; // 0
unk16 = readbin(unk16, sas, swapit); // 3233
if (debug) Rcout << unk16 << std::endl; // 0
// Rcout << unk16 << std::endl; // 0

lenremain -= 14;


// Rcout << lenremain << " " << cls << std::endl;

for (auto cl = 0; cl < cls; ++cl) {
int16_t res = 0;
res = readbin(res, sas, swapit);
Rcpp::Rcout << res << std::endl;
c8vec.push_back(res);
}

lenremain -= (cls * 2);


// Rcout << "---------------------------" << std::endl;

// 8
unk16 = readbin((int8_t)unk16, sas, swapit); // 0
if (debug) Rcout << unk16 << std::endl;
// Rcout << unk16 << std::endl;
unk16 = readbin((int8_t)unk16, sas, swapit); // 0
if (debug) Rcout << unk16 << std::endl;
// Rcout << unk16 << std::endl;
unk16 = readbin((int8_t)unk16, sas, swapit); // 0
if (debug) Rcout << unk16 << std::endl;
// Rcout << unk16 << std::endl;
unk16 = readbin((int8_t)unk16, sas, swapit); // 0
if (debug) Rcout << unk16 << std::endl;
// Rcout << unk16 << std::endl;

// Rcout << "---------------------------" << std::endl;

lenremain -= 4;

// if (debug)
Rcout << "lenremain "<< lenremain << std::endl;

// while (lenremain > 0) {
// unk8 = readbin((uint8_t)unk16, sas, swapit); // lenremain != 0, is there more?
// Rcpp::Rcout << unk8 << std::endl;
// --lenremain;
// }


if (debug)
Rcpp::Rcout << "SH_LEN " << potabs[sc].SH_LEN << std::endl;

break;

Expand Down
52 changes: 20 additions & 32 deletions src/writesas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,16 +809,16 @@ void writesas(const char * filePath, Rcpp::DataFrame dat, uint8_t compress,
potabs[shc].SH_OFF = pre_shlen - headersize - pg*pagesize;

if (debug)
Rcout << "-------- case 8 " << sas.tellg() << std::endl;
Rcout << "-------- case 8 "<< sas.tellg() << std::endl;

uint32_t case81 = 4294967294;
uint32_t case82 = 4294967295;

write_case_i(case81, case82, ENDIANNESS, bit32, swapit, sas);

int16_t cls = k; // something else? subheader count -2?
int16_t cls = k;
int64_t lenremain = 14 +
k * 2 + 8 +
cls * 2 + 8 +
12; // 14 below, (k+2) * 2 and double?

int32_t ptk32 = 2143813666;
Expand Down Expand Up @@ -849,36 +849,24 @@ void writesas(const char * filePath, Rcpp::DataFrame dat, uint8_t compress,
// Rcout << lenremain << " " << cls << std::endl;

int16_t res = 0;
for (auto cl = 0; cl < cls; ++cl) {
ptk16 = cl + 1;
// this is something like an index
// sas writes a vector of nrow + x. missings are filled with 0,
// row numbers are integers with a sign.
// mtcars is: 7, 6, 11, 9, 1, -10, 5, -2, 8, -3, 4
writebin(ptk16, sas, swapit);
}

lenremain -= (cls * 2);
// for (auto cl = 0; cl < cls; ++cl) {
ptk16 = -1;
writebin(ptk16, sas, swapit);
writebin((int16_t)k, sas, swapit);
writebin(unk16, sas, swapit);
writebin(unk16, sas, swapit);
// }

// to be on par with lenremain
// writebin(unkdub, sas, swapit);
writebin(unkdub, sas, swapit);

// // padding? Not in lenremain
writebin(unk16, sas, swapit); // 0
// writebin(unk16, sas, swapit); // 0
writebin(unk8, sas, swapit); // 0
writebin(unk8, sas, swapit); // 0
writebin(unk8, sas, swapit); // 0
writebin(unk8, sas, swapit); // 0

lenremain -= 4;

if (debug) Rcpp::Rcout << lenremain << std::endl;

while (lenremain > 0) {
// required to have lenremain = 0
writebin((uint8_t)unk16, sas, swapit);
--lenremain;
}
// writebin(unk16, sas, swapit); // 0
// writebin(unk16, sas, swapit); // 0
// writebin(unk16, sas, swapit); // 0


// break;
post_shlen = sas.tellg();
Expand Down Expand Up @@ -1275,7 +1263,7 @@ void writesas(const char * filePath, Rcpp::DataFrame dat, uint8_t compress,
}

if (debug)
Rprintf("SIG %ld; FIRST %ld; F_POS %d; LAST %ld; L_POS %d\n",
Rprintf("SIG %d; FIRST %d; F_POS %d; LAST %d; L_POS %d\n",
scv[i].SIG, scv[i].FIRST, scv[i].F_POS,
scv[i].LAST, scv[i].L_POS);

Expand Down Expand Up @@ -1316,7 +1304,7 @@ void writesas(const char * filePath, Rcpp::DataFrame dat, uint8_t compress,
writebin((int32_t)uunk64, sas, swapit);
}
if (debug)
Rprintf("colnum %ld; uunk64 %ld\n",
Rprintf("colnum %d; uunk64 %d\n",
colnum, uunk64);

post_shlen = sas.tellg();
Expand Down Expand Up @@ -1394,7 +1382,7 @@ void writesas(const char * filePath, Rcpp::DataFrame dat, uint8_t compress,
writebin(colf_p1, sas, swapit); // k related
writebin(colf_p2, sas, swapit);
int64_t ptk64 = 0; // changing this makes SAS complain about missing tables
writebin((int64_t)ptk64, sas, swapit); // p3 and p4?
writebin(ptk64, sas, swapit); // p3 and p4?
ptk64 = 34; // was 8 for k = 1
writebin(ptk64, sas, swapit);
writebin(pgsize, sas, swapit);
Expand Down Expand Up @@ -1553,7 +1541,7 @@ void writesas(const char * filePath, Rcpp::DataFrame dat, uint8_t compress,
writebin(unk32, sas, swapit);
writebin((int32_t)colf_p1, sas, swapit);
writebin((int32_t)colf_p2, sas, swapit);
writebin((uint32_t)k, sas, swapit);
writebin(unk32, sas, swapit);
writebin(unk32, sas, swapit);
writebin((int32_t)pgsize, sas, swapit);
writebin(unk32, sas, swapit);
Expand Down

0 comments on commit f692c29

Please sign in to comment.