From f692c295bc4a071f1315db09517b6e6fcdd20b5c Mon Sep 17 00:00:00 2001 From: Jan Marvin Garbuszus Date: Tue, 17 Sep 2024 17:22:29 +0200 Subject: [PATCH] Revert "research case 8" This reverts commit 28a017800d45e9189b34df7f255badf0bb5e9234. --- src/readsas.cpp | 76 +++++++++++++++++------------------------------- src/writesas.cpp | 52 +++++++++++++-------------------- 2 files changed, 47 insertions(+), 81 deletions(-) diff --git a/src/readsas.cpp b/src/readsas.cpp index c4f9a97..0d7ebc5 100644 --- a/src/readsas.cpp +++ b/src/readsas.cpp @@ -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); @@ -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) { @@ -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; @@ -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); @@ -1403,7 +1400,7 @@ Rcpp::List readsas(const char * filePath, if (debug) Rcpp::Rcout << comprlen << ", " - << (uint32_t)tmp << ", " + << tmp << ", " << proclen << ", " << swlen << "; " << varname_pos[0] @@ -1523,9 +1520,6 @@ Rcpp::List readsas(const char * filePath, } - - if (debug) - Rcpp::Rcout << "SH_LEN " << potabs[sc].SH_LEN << std::endl; break; } @@ -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; diff --git a/src/writesas.cpp b/src/writesas.cpp index 7e71e75..bde4966 100644 --- a/src/writesas.cpp +++ b/src/writesas.cpp @@ -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; @@ -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(); @@ -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); @@ -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(); @@ -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); @@ -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);