30# define sleep(sec) Sleep(sec * 1000)
39# error "SDDS_VERSION does not match the version number of this file"
44static int32_t defaultIOBufferSize = SDDS_FILEBUFFER_SIZE;
49int32_t SDDS_SetBufferedRead(int32_t dummy) {
69 return defaultIOBufferSize;
72 previous = defaultIOBufferSize;
73 defaultIOBufferSize = newValue;
97 int float80tofloat64 = 0;
99 if (getenv(
"SDDS_LONGDOUBLE_64BITS") == NULL) {
101 float80tofloat64 = 1;
104 if (!fBuffer->bufferSize) {
107 return !fseek(fp, (
long)targetSize, SEEK_CUR);
109 if (float80tofloat64) {
113 while (shift < targetSize) {
114 if (fread(&x, (
size_t)1, 16, fp) != 16)
117 memcpy((
char *)target + shift, &d, 8);
122 return fread(target, (
size_t)1, (
size_t)targetSize, fp) == targetSize;
126 if ((fBuffer->bytesLeft -= targetSize) >= 0) {
129 if (float80tofloat64) {
133 while (shift < targetSize) {
134 memcpy(x, (
char *)fBuffer->data + shift, 16);
136 memcpy((
char *)target + shift, &d, 8);
140 memcpy((
char *)target, (
char *)fBuffer->data, targetSize);
143 fBuffer->data += targetSize;
147 int64_t bytesNeeded, offset;
148 fBuffer->bytesLeft += targetSize;
151 if ((offset = fBuffer->bytesLeft)) {
154 if (float80tofloat64) {
158 while (shift < offset) {
159 memcpy(x, (
char *)fBuffer->data + shift, 16);
161 memcpy((
char *)target + shift, &d, 8);
165 memcpy((
char *)target, (
char *)fBuffer->data, offset);
168 bytesNeeded = targetSize - offset;
169 fBuffer->bytesLeft = 0;
171 bytesNeeded = targetSize;
173 fBuffer->data = fBuffer->buffer;
175 if (fBuffer->bufferSize < bytesNeeded) {
178 return !fseek(fp, (
long)bytesNeeded, SEEK_CUR);
180 if (float80tofloat64) {
184 while (shift < bytesNeeded) {
185 if (fread(&x, (
size_t)1, 16, fp) != 16)
188 memcpy((
char *)target + offset + shift, &d, 8);
193 return fread((
char *)target + offset, (
size_t)1, (
size_t)bytesNeeded, fp) == bytesNeeded;
199 if ((fBuffer->bytesLeft = fread(fBuffer->data, (
size_t)1, (
size_t)fBuffer->bufferSize, fp)) < bytesNeeded)
202 if (float80tofloat64) {
206 while (shift < bytesNeeded) {
207 memcpy(x, (
char *)fBuffer->data + shift, 16);
209 memcpy((
char *)target + offset + shift, &d, 8);
213 memcpy((
char *)target + offset, (
char *)fBuffer->data, bytesNeeded);
216 fBuffer->data += bytesNeeded;
217 fBuffer->bytesLeft -= bytesNeeded;
244 int float80tofloat64 = 0;
245 if (!fBuffer->bufferSize) {
246 SDDS_SetError(
"You must presently have a nonzero file buffer to use LZMA (reading/writing .lzma or .xz files)");
250 if (getenv(
"SDDS_LONGDOUBLE_64BITS") == NULL) {
252 float80tofloat64 = 1;
255 if ((fBuffer->bytesLeft -= targetSize) >= 0) {
257 if (float80tofloat64) {
261 while (shift < targetSize) {
262 memcpy(x, (
char *)fBuffer->data + shift, 16);
264 memcpy((
char *)target + shift, &d, 8);
268 memcpy((
char *)target, (
char *)fBuffer->data, targetSize);
271 fBuffer->data += targetSize;
274 int64_t bytesNeeded, offset;
275 fBuffer->bytesLeft += targetSize;
276 if ((offset = fBuffer->bytesLeft)) {
278 if (float80tofloat64) {
282 while (shift < offset) {
283 memcpy(x, (
char *)fBuffer->data + shift, 16);
285 memcpy((
char *)target + shift, &d, 8);
289 memcpy((
char *)target, (
char *)fBuffer->data, offset);
292 bytesNeeded = targetSize - offset;
293 fBuffer->bytesLeft = 0;
295 bytesNeeded = targetSize;
297 fBuffer->data = fBuffer->buffer;
299 if (fBuffer->bufferSize < bytesNeeded) {
302 return !lzma_seek(lzmafp, (
long)bytesNeeded, SEEK_CUR);
304 if (float80tofloat64) {
308 while (shift < bytesNeeded) {
309 if (lzma_read(lzmafp, &x, 16) != 16)
312 memcpy((
char *)target + offset + shift, &d, 8);
317 return lzma_read(lzmafp, (
char *)target + offset, (
size_t)bytesNeeded) == bytesNeeded;
322 if ((fBuffer->bytesLeft = lzma_read(lzmafp, fBuffer->data, (
size_t)fBuffer->bufferSize)) < bytesNeeded)
325 if (float80tofloat64) {
329 while (shift < bytesNeeded) {
330 memcpy(x, (
char *)fBuffer->data + shift, 16);
332 memcpy((
char *)target + offset + shift, &d, 8);
336 memcpy((
char *)target + offset, (
char *)fBuffer->data, bytesNeeded);
339 fBuffer->data += bytesNeeded;
340 fBuffer->bytesLeft -= bytesNeeded;
367int32_t SDDS_GZipBufferedRead(
void *target, int64_t targetSize, gzFile gzfp,
SDDS_FILEBUFFER *fBuffer, int32_t type, int32_t byteOrder) {
368 int float80tofloat64 = 0;
369 if (!fBuffer->bufferSize) {
370 SDDS_SetError(
"You must presently have a nonzero file buffer to use zLib (reading/writing .gz files)");
374 if (getenv(
"SDDS_LONGDOUBLE_64BITS") == NULL) {
376 float80tofloat64 = 1;
379 if ((fBuffer->bytesLeft -= targetSize) >= 0) {
381 if (float80tofloat64) {
385 while (shift < targetSize) {
386 memcpy(x, (
char *)fBuffer->data + shift, 16);
388 memcpy((
char *)target + shift, &d, 8);
392 memcpy((
char *)target, (
char *)fBuffer->data, targetSize);
395 fBuffer->data += targetSize;
398 int64_t bytesNeeded, offset;
399 fBuffer->bytesLeft += targetSize;
400 if ((offset = fBuffer->bytesLeft)) {
402 if (float80tofloat64) {
406 while (shift < offset) {
407 memcpy(x, (
char *)fBuffer->data + shift, 16);
409 memcpy((
char *)target + shift, &d, 8);
413 memcpy((
char *)target, (
char *)fBuffer->data, offset);
416 bytesNeeded = targetSize - offset;
417 fBuffer->bytesLeft = 0;
419 bytesNeeded = targetSize;
421 fBuffer->data = fBuffer->buffer;
423 if (fBuffer->bufferSize < bytesNeeded) {
426 return !gzseek(gzfp, bytesNeeded, SEEK_CUR);
428 if (float80tofloat64) {
432 while (shift < bytesNeeded) {
433 if (gzread(gzfp, &x, 16) != 16)
436 memcpy((
char *)target + offset + shift, &d, 8);
441 return gzread(gzfp, (
char *)target + offset, bytesNeeded) == bytesNeeded;
446 if ((fBuffer->bytesLeft = gzread(gzfp, fBuffer->data, fBuffer->bufferSize)) < bytesNeeded)
449 if (float80tofloat64) {
453 while (shift < bytesNeeded) {
454 memcpy(x, (
char *)fBuffer->data + shift, 16);
456 memcpy((
char *)target + offset + shift, &d, 8);
460 memcpy((
char *)target + offset, (
char *)fBuffer->data, bytesNeeded);
463 fBuffer->data += bytesNeeded;
464 fBuffer->bytesLeft -= bytesNeeded;
485 if (!fBuffer->bufferSize) {
486 return fwrite(target, (
size_t)1, (
size_t)targetSize, fp) == targetSize;
488 if ((fBuffer->bytesLeft -= targetSize) >= 0) {
489 memcpy((
char *)fBuffer->data, (
char *)target, targetSize);
490 fBuffer->data += targetSize;
492 fprintf(stderr,
"SDDS_BufferedWrite of %" PRId64
" bytes done in-memory, %" PRId64
" bytes left\n", targetSize, fBuffer->bytesLeft);
501 lastLeft = (fBuffer->bytesLeft += targetSize);
503 memcpy((
char *)fBuffer->data, (
char *)target, (
size_t)fBuffer->bytesLeft);
504 if (fwrite(fBuffer->buffer, (
size_t)1, (
size_t)fBuffer->bufferSize, fp) != fBuffer->bufferSize)
515 fBuffer->data = fBuffer->buffer;
516 if ((targetSize -= lastLeft) > (fBuffer->bytesLeft = fBuffer->bufferSize)) {
517 return fwrite((
char *)target + lastLeft, (
size_t)1, (
size_t)targetSize, fp) == targetSize;
522 memcpy((
char *)fBuffer->data, (
char *)target + lastLeft, targetSize);
523 fBuffer->data += targetSize;
524 fBuffer->bytesLeft -= targetSize;
551 if (!fBuffer->bufferSize) {
552 SDDS_SetError(
"You must presently have a nonzero file buffer to use lzma (reading/writing .xz files)");
555 if ((fBuffer->bytesLeft -= targetSize) >= 0) {
556 memcpy((
char *)fBuffer->data, (
char *)target, targetSize);
557 fBuffer->data += targetSize;
561 lastLeft = (fBuffer->bytesLeft += targetSize);
562 memcpy((
char *)fBuffer->data, (
char *)target, (
size_t)fBuffer->bytesLeft);
563 if (lzma_write(lzmafp, fBuffer->buffer, (
size_t)fBuffer->bufferSize) != fBuffer->bufferSize)
565 fBuffer->bytesLeft = fBuffer->bufferSize;
566 fBuffer->data = fBuffer->buffer;
593int32_t SDDS_GZipBufferedWrite(
void *target, int64_t targetSize, gzFile gzfp,
SDDS_FILEBUFFER *fBuffer) {
594 if (!fBuffer->bufferSize) {
595 SDDS_SetError(
"You must presently have a nonzero file buffer to use zLib (reading/writing .gz files}");
598 if ((fBuffer->bytesLeft -= targetSize) >= 0) {
599 memcpy((
char *)fBuffer->data, (
char *)target, targetSize);
600 fBuffer->data += targetSize;
604 lastLeft = (fBuffer->bytesLeft + targetSize);
605 memcpy((
char *)fBuffer->data, (
char *)target, lastLeft);
606 if (gzwrite(gzfp, fBuffer->buffer, fBuffer->bufferSize) != fBuffer->bufferSize)
609 fBuffer->bytesLeft = fBuffer->bufferSize;
610 fBuffer->data = fBuffer->buffer;
611 return SDDS_GZipBufferedWrite((
char *)target + lastLeft, targetSize - lastLeft, gzfp, fBuffer);
635 SDDS_SetError(
"Unable to flush buffer: file pointer is NULL. (SDDS_FlushBuffer)");
638 if (!fBuffer->bufferSize) {
647 SDDS_SetError(
"Unable to flush buffer: buffer pointer is NULL. (SDDS_FlushBuffer)");
650 if ((writeBytes = fBuffer->bufferSize - fBuffer->bytesLeft)) {
651 if (writeBytes < 0) {
652 SDDS_SetError(
"Unable to flush buffer: negative byte count (SDDS_FlushBuffer).");
656 fprintf(stderr,
"Writing %" PRId64
" bytes to disk\n", writeBytes);
658 if (fwrite(fBuffer->buffer, 1, writeBytes, fp) != writeBytes) {
659 SDDS_SetError(
"Unable to flush buffer: write operation failed (SDDS_FlushBuffer).");
662 fBuffer->bytesLeft = fBuffer->bufferSize;
663 fBuffer->data = fBuffer->buffer;
689 if ((writeBytes = fBuffer->bufferSize - fBuffer->bytesLeft)) {
690 if (lzma_write(lzmafp, fBuffer->buffer, writeBytes) != writeBytes)
692 fBuffer->bytesLeft = fBuffer->bufferSize;
693 fBuffer->data = fBuffer->buffer;
715 if ((writeBytes = fBuffer->bufferSize - fBuffer->bytesLeft)) {
716 if (gzwrite(gzfp, fBuffer->buffer, writeBytes) != writeBytes)
718 fBuffer->bytesLeft = fBuffer->bufferSize;
719 fBuffer->data = fBuffer->buffer;
755 int64_t i, rows, fixed_rows;
756 int32_t min32 = INT32_MIN, rows32;
759 char *outputEndianess = NULL;
761 if ((outputEndianess = getenv(
"SDDS_OUTPUT_ENDIANESS"))) {
770 if (SDDS_dataset->layout.gzipFile) {
771 if (!(gzfp = SDDS_dataset->layout.gzfp)) {
772 SDDS_SetError(
"Unable to write page--file pointer is NULL (SDDS_WriteBinaryPage)");
775 fBuffer = &SDDS_dataset->fBuffer;
777 if (!fBuffer->buffer) {
778 if (!(fBuffer->buffer = fBuffer->data =
SDDS_Malloc(
sizeof(
char) * (defaultIOBufferSize + 1)))) {
779 SDDS_SetError(
"Unable to do buffered read--allocation failure (SDDS_WriteBinaryPage)");
782 fBuffer->bufferSize = defaultIOBufferSize;
783 fBuffer->bytesLeft = defaultIOBufferSize;
787 SDDS_dataset->rowcount_offset = gztell(gzfp);
788 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
789 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
790 if (fixed_rows > INT32_MAX) {
791 if (!SDDS_GZipBufferedWrite(&min32,
sizeof(min32), gzfp, fBuffer)) {
792 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
795 if (!SDDS_GZipBufferedWrite(&fixed_rows,
sizeof(fixed_rows), gzfp, fBuffer)) {
796 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
800 rows32 = (int32_t)fixed_rows;
801 if (!SDDS_GZipBufferedWrite(&rows32,
sizeof(rows32), gzfp, fBuffer)) {
802 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
807 if (rows > INT32_MAX) {
808 if (!SDDS_GZipBufferedWrite(&min32,
sizeof(min32), gzfp, fBuffer)) {
809 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
812 if (!SDDS_GZipBufferedWrite(&rows,
sizeof(rows), gzfp, fBuffer)) {
813 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
817 rows32 = (int32_t)rows;
818 if (!SDDS_GZipBufferedWrite(&rows32,
sizeof(rows32), gzfp, fBuffer)) {
819 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
825 SDDS_SetError(
"Unable to write page--parameter writing problem (SDDS_WriteBinaryPage)");
829 SDDS_SetError(
"Unable to write page--array writing problem (SDDS_WriteBinaryPage)");
832 if (SDDS_dataset->layout.n_columns) {
833 if (SDDS_dataset->layout.data_mode.column_major) {
835 SDDS_SetError(
"Unable to write page--column writing problem (SDDS_WriteBinaryPage)");
839 for (i = 0; i < SDDS_dataset->n_rows; i++) {
841 SDDS_SetError(
"Unable to write page--row writing problem (SDDS_WriteBinaryPage)");
847 if (!SDDS_GZipFlushBuffer(gzfp, fBuffer)) {
848 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_WriteBinaryPage)");
851 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
852 SDDS_dataset->n_rows_written = rows;
853 SDDS_dataset->writing_page = 1;
856 if (SDDS_dataset->layout.lzmaFile) {
857 if (!(lzmafp = SDDS_dataset->layout.lzmafp)) {
858 SDDS_SetError(
"Unable to write page--file pointer is NULL (SDDS_WriteBinaryPage)");
861 fBuffer = &SDDS_dataset->fBuffer;
863 if (!fBuffer->buffer) {
864 if (!(fBuffer->buffer = fBuffer->data =
SDDS_Malloc(
sizeof(
char) * (defaultIOBufferSize + 1)))) {
865 SDDS_SetError(
"Unable to do buffered read--allocation failure (SDDS_WriteBinaryPage)");
868 fBuffer->bufferSize = defaultIOBufferSize;
869 fBuffer->bytesLeft = defaultIOBufferSize;
872 SDDS_dataset->rowcount_offset = lzma_tell(lzmafp);
873 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
874 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
875 if (fixed_rows > INT32_MAX) {
877 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
881 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
885 rows32 = (int32_t)fixed_rows;
887 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
892 if (rows > INT32_MAX) {
894 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
898 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
902 rows32 = (int32_t)rows;
904 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
910 SDDS_SetError(
"Unable to write page--parameter writing problem (SDDS_WriteBinaryPage)");
914 SDDS_SetError(
"Unable to write page--array writing problem (SDDS_WriteBinaryPage)");
917 if (SDDS_dataset->layout.n_columns) {
918 if (SDDS_dataset->layout.data_mode.column_major) {
920 SDDS_SetError(
"Unable to write page--column writing problem (SDDS_WriteBinaryPage)");
924 for (i = 0; i < SDDS_dataset->n_rows; i++) {
926 SDDS_SetError(
"Unable to write page--row writing problem (SDDS_WriteBinaryPage)");
933 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_WriteBinaryPage)");
936 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
937 SDDS_dataset->n_rows_written = rows;
938 SDDS_dataset->writing_page = 1;
940 if (!(fp = SDDS_dataset->layout.fp)) {
941 SDDS_SetError(
"Unable to write page--file pointer is NULL (SDDS_WriteBinaryPage)");
944 fBuffer = &SDDS_dataset->fBuffer;
946 if (!fBuffer->buffer) {
947 if (!(fBuffer->buffer = fBuffer->data =
SDDS_Malloc(
sizeof(
char) * (defaultIOBufferSize + 1)))) {
948 SDDS_SetError(
"Unable to do buffered read--allocation failure (SDDS_WriteBinaryPage)");
951 fBuffer->bufferSize = defaultIOBufferSize;
952 fBuffer->bytesLeft = defaultIOBufferSize;
959 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_WriteBinaryPage)");
965 SDDS_dataset->rowcount_offset = ftell(fp);
966 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
967 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
969 fprintf(stderr,
"setting %" PRId64
" fixed rows\n", fixed_rows);
971 if (fixed_rows > INT32_MAX) {
973 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
977 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
981 rows32 = (int32_t)fixed_rows;
983 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
989 fprintf(stderr,
"setting %" PRId64
" rows\n", rows);
991 if (rows > INT32_MAX) {
993 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
997 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
1001 rows32 = (int32_t)rows;
1003 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteBinaryPage)");
1011 SDDS_SetError(
"Unable to write page--parameter writing problem (SDDS_WriteBinaryPage)");
1015 SDDS_SetError(
"Unable to write page--array writing problem (SDDS_WriteBinaryPage)");
1018 if (SDDS_dataset->layout.n_columns) {
1019 if (SDDS_dataset->layout.data_mode.column_major) {
1021 SDDS_SetError(
"Unable to write page--column writing problem (SDDS_WriteBinaryPage)");
1025 for (i = 0; i < SDDS_dataset->n_rows; i++) {
1027 SDDS_SetError(
"Unable to write page--row writing problem (SDDS_WriteBinaryPage)");
1035 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_WriteBinaryPage)");
1038 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
1039 SDDS_dataset->n_rows_written = rows;
1040 SDDS_dataset->writing_page = 1;
1079 int64_t i, rows, offset, code, fixed_rows;
1080 int32_t min32 = INT32_MIN, rows32;
1082 char *outputEndianess = NULL;
1084 if ((outputEndianess = getenv(
"SDDS_OUTPUT_ENDIANESS"))) {
1090 fprintf(stderr,
"%" PRId64
" virtual rows present, first=%" PRId64
"\n",
SDDS_CountRowsOfInterest(SDDS_dataset), SDDS_dataset->first_row_in_mem);
1095 if (SDDS_dataset->layout.gzipFile) {
1096 SDDS_SetError(
"Unable to perform page updates on a gzip file (SDDS_UpdateBinaryPage)");
1100 if (SDDS_dataset->layout.lzmaFile) {
1101 SDDS_SetError(
"Unable to perform page updates on an .lzma or .xz file (SDDS_UpdateBinaryPage)");
1104 if (SDDS_dataset->layout.data_mode.column_major) {
1105 SDDS_SetError(
"Unable to perform page updates on column major order file. (SDDS_UpdateBinaryPage)");
1108 if (!SDDS_dataset->writing_page) {
1110 fprintf(stderr,
"Page not being written---calling SDDS_UpdateBinaryPage\n");
1114 if (mode & FLUSH_TABLE) {
1117 SDDS_dataset->last_row_written = -1;
1118 SDDS_dataset->n_rows = 0;
1123 if (!(fp = SDDS_dataset->layout.fp)) {
1124 SDDS_SetError(
"Unable to update page--file pointer is NULL (SDDS_UpdateBinaryPage)");
1127 fBuffer = &SDDS_dataset->fBuffer;
1129 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_UpdateBinaryPage)");
1136 fprintf(stderr,
"%" PRId64
" rows stored in table, %" PRId64
" already written\n", rows, SDDS_dataset->n_rows_written);
1138 if (rows == SDDS_dataset->n_rows_written)
1140 if (rows < SDDS_dataset->n_rows_written) {
1141 SDDS_SetError(
"Unable to update page--new number of rows less than previous number (SDDS_UpdateBinaryPage)");
1144 if ((!SDDS_dataset->layout.data_mode.fixed_row_count) || (((rows + rows - SDDS_dataset->n_rows_written) / SDDS_dataset->layout.data_mode.fixed_row_increment) != (rows / SDDS_dataset->layout.data_mode.fixed_row_increment))) {
1145 if (
SDDS_fseek(fp, SDDS_dataset->rowcount_offset, 0) == -1) {
1146 SDDS_SetError(
"Unable to update page--failure doing fseek (SDDS_UpdateBinaryPage)");
1149 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
1150 if ((rows - SDDS_dataset->n_rows_written) + 1 > SDDS_dataset->layout.data_mode.fixed_row_increment) {
1151 SDDS_dataset->layout.data_mode.fixed_row_increment = (rows - SDDS_dataset->n_rows_written) + 1;
1153 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
1155 fprintf(stderr,
"Setting %" PRId64
" fixed rows\n", fixed_rows);
1157 if ((fixed_rows > INT32_MAX) && (SDDS_dataset->n_rows_written <= INT32_MAX)) {
1158 SDDS_SetError(
"Unable to update page--crossed the INT32_MAX row boundary (SDDS_UpdateBinaryPage)");
1161 if (fixed_rows > INT32_MAX) {
1162 if (fwrite(&min32,
sizeof(min32), 1, fp) != 1) {
1163 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
1166 if (fwrite(&fixed_rows,
sizeof(fixed_rows), 1, fp) != 1) {
1167 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
1171 rows32 = (int32_t)fixed_rows;
1172 if (fwrite(&fixed_rows,
sizeof(rows32), 1, fp) != 1) {
1173 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
1179 fprintf(stderr,
"Setting %" PRId64
" rows\n", rows);
1181 if ((rows > INT32_MAX) && (SDDS_dataset->n_rows_written <= INT32_MAX)) {
1182 SDDS_SetError(
"Unable to update page--crossed the INT32_MAX row boundary (SDDS_UpdateBinaryPage)");
1185 if (rows > INT32_MAX) {
1186 if (fwrite(&min32,
sizeof(min32), 1, fp) != 1) {
1187 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
1190 if (fwrite(&rows,
sizeof(rows), 1, fp) != 1) {
1191 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
1195 rows32 = (int32_t)rows;
1196 if (fwrite(&rows32,
sizeof(rows32), 1, fp) != 1) {
1197 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
1203 SDDS_SetError(
"Unable to update page--failure doing fseek to end of page (SDDS_UpdateBinaryPage)");
1207 for (i = SDDS_dataset->last_row_written + 1; i < SDDS_dataset->n_rows; i++)
1209 SDDS_SetError(
"Unable to update page--failure writing row (SDDS_UpdateBinaryPage)");
1213 fprintf(stderr,
"Flushing buffer\n");
1216 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_UpdateBinaryPage)");
1219 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
1220 SDDS_dataset->n_rows_written = rows;
1221 if (mode & FLUSH_TABLE) {
1223 SDDS_dataset->first_row_in_mem = rows;
1224 SDDS_dataset->last_row_written = -1;
1225 SDDS_dataset->n_rows = 0;
1230#define FSEEK_TRIES 10
1261 struct timespec rqtp;
1265 for (
try = 0;
try < FSEEK_TRIES;
try++) {
1266 if (fseek(fp, offset, dir) == -1) {
1268 nanosleep(&rqtp, NULL);
1277 if (
try == FSEEK_TRIES) {
1278 fputs(
"warning: fseek problems--unable to recover\n", stderr);
1281 fputs(
"warning: fseek problems--recovered\n", stderr);
1315 struct timespec rqtp;
1319 for (
try = 0;
try < FSEEK_TRIES;
try++) {
1320 if (lzma_seek(lzmafp, offset, dir) == -1) {
1322 nanosleep(&rqtp, NULL);
1331 if (
try == FSEEK_TRIES) {
1332 fputs(
"warning: lzma_seek problems--unable to recover\n", stderr);
1335 fputs(
"warning: lzma_seek problems--recovered\n", stderr);
1367int32_t SDDS_gzseek(gzFile gzfp, int64_t offset, int32_t dir) {
1369# if defined(vxWorks)
1370 struct timespec rqtp;
1374 for (
try = 0;
try < FSEEK_TRIES;
try++) {
1375 if (gzseek(gzfp, offset, dir) == -1) {
1376# if defined(vxWorks)
1377 nanosleep(&rqtp, NULL);
1386 if (
try == FSEEK_TRIES) {
1387 fputs(
"warning: gzseek problems--unable to recover\n", stderr);
1390 fputs(
"warning: gzseek problems--recovered\n", stderr);
1440 layout = &SDDS_dataset->layout;
1442 if (SDDS_dataset->layout.gzipFile) {
1443 gzfp = layout->gzfp;
1444 fBuffer = &SDDS_dataset->fBuffer;
1445 for (i = 0; i < layout->n_parameters; i++) {
1446 if (layout->parameter_definition[i].fixed_value)
1448 if (layout->parameter_definition[i].type ==
SDDS_STRING) {
1449 if (!SDDS_GZipWriteBinaryString(*((
char **)SDDS_dataset->parameter[i]), gzfp, fBuffer)) {
1450 SDDS_SetError(
"Unable to write parameters--failure writing string (SDDS_WriteBinaryParameters)");
1453 }
else if (!SDDS_GZipBufferedWrite(SDDS_dataset->parameter[i],
SDDS_type_size[layout->parameter_definition[i].type - 1], gzfp, fBuffer)) {
1454 SDDS_SetError(
"Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
1460 if (SDDS_dataset->layout.lzmaFile) {
1461 lzmafp = layout->lzmafp;
1462 fBuffer = &SDDS_dataset->fBuffer;
1463 for (i = 0; i < layout->n_parameters; i++) {
1464 if (layout->parameter_definition[i].fixed_value)
1466 if (layout->parameter_definition[i].type ==
SDDS_STRING) {
1468 SDDS_SetError(
"Unable to write parameters--failure writing string (SDDS_WriteBinaryParameters)");
1472 SDDS_SetError(
"Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
1478 fBuffer = &SDDS_dataset->fBuffer;
1479 for (i = 0; i < layout->n_parameters; i++) {
1480 if (layout->parameter_definition[i].fixed_value)
1482 if (layout->parameter_definition[i].type ==
SDDS_STRING) {
1484 SDDS_SetError(
"Unable to write parameters--failure writing string (SDDS_WriteBinaryParameters)");
1488 SDDS_SetError(
"Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
1534 int32_t i, j, zero = 0;
1545 layout = &SDDS_dataset->layout;
1547 if (SDDS_dataset->layout.gzipFile) {
1548 gzfp = layout->gzfp;
1549 fBuffer = &SDDS_dataset->fBuffer;
1550 for (i = 0; i < layout->n_arrays; i++) {
1551 if (!SDDS_dataset->array[i].dimension) {
1552 for (j = 0; j < layout->array_definition[i].dimensions; j++)
1553 if (!SDDS_GZipBufferedWrite(&zero,
sizeof(zero), gzfp, fBuffer)) {
1554 SDDS_SetError(
"Unable to write null array--failure writing dimensions (SDDS_WriteBinaryArrays)");
1559 if (!SDDS_GZipBufferedWrite(SDDS_dataset->array[i].dimension,
sizeof(*(SDDS_dataset->array)[i].dimension) * layout->array_definition[i].dimensions, gzfp, fBuffer)) {
1560 SDDS_SetError(
"Unable to write arrays--failure writing dimensions (SDDS_WriteBinaryArrays)");
1563 if (layout->array_definition[i].type ==
SDDS_STRING) {
1564 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
1565 if (!SDDS_GZipWriteBinaryString(((
char **)SDDS_dataset->array[i].data)[j], gzfp, fBuffer)) {
1566 SDDS_SetError(
"Unable to write arrays--failure writing string (SDDS_WriteBinaryArrays)");
1570 }
else if (!SDDS_GZipBufferedWrite(SDDS_dataset->array[i].data,
SDDS_type_size[layout->array_definition[i].type - 1] * SDDS_dataset->array[i].elements, gzfp, fBuffer)) {
1571 SDDS_SetError(
"Unable to write arrays--failure writing values (SDDS_WriteBinaryArrays)");
1577 if (SDDS_dataset->layout.gzipFile) {
1578 lzmafp = layout->lzmafp;
1579 fBuffer = &SDDS_dataset->fBuffer;
1580 for (i = 0; i < layout->n_arrays; i++) {
1581 if (!SDDS_dataset->array[i].dimension) {
1582 for (j = 0; j < layout->array_definition[i].dimensions; j++)
1584 SDDS_SetError(
"Unable to write null array--failure writing dimensions (SDDS_WriteBinaryArrays)");
1589 if (!
SDDS_LZMABufferedWrite(SDDS_dataset->array[i].dimension,
sizeof(*(SDDS_dataset->array)[i].dimension) * layout->array_definition[i].dimensions, lzmafp, fBuffer)) {
1590 SDDS_SetError(
"Unable to write arrays--failure writing dimensions (SDDS_WriteBinaryArrays)");
1593 if (layout->array_definition[i].type ==
SDDS_STRING) {
1594 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
1596 SDDS_SetError(
"Unable to write arrays--failure writing string (SDDS_WriteBinaryArrays)");
1601 SDDS_SetError(
"Unable to write arrays--failure writing values (SDDS_WriteBinaryArrays)");
1607 fBuffer = &SDDS_dataset->fBuffer;
1608 for (i = 0; i < layout->n_arrays; i++) {
1609 if (!SDDS_dataset->array[i].dimension) {
1610 for (j = 0; j < layout->array_definition[i].dimensions; j++)
1612 SDDS_SetError(
"Unable to write null array--failure writing dimensions (SDDS_WriteBinaryArrays)");
1617 if (!
SDDS_BufferedWrite(SDDS_dataset->array[i].dimension,
sizeof(*(SDDS_dataset->array)[i].dimension) * layout->array_definition[i].dimensions, fp, fBuffer)) {
1618 SDDS_SetError(
"Unable to write arrays--failure writing dimensions (SDDS_WriteBinaryArrays)");
1621 if (layout->array_definition[i].type ==
SDDS_STRING) {
1622 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
1624 SDDS_SetError(
"Unable to write arrays--failure writing string (SDDS_WriteBinaryArrays)");
1628 }
else if (!
SDDS_BufferedWrite(SDDS_dataset->array[i].data,
SDDS_type_size[layout->array_definition[i].type - 1] * SDDS_dataset->array[i].elements, fp, fBuffer)) {
1629 SDDS_SetError(
"Unable to write arrays--failure writing values (SDDS_WriteBinaryArrays)");
1674 int64_t i, row, rows, type, size;
1685 layout = &SDDS_dataset->layout;
1686 fBuffer = &SDDS_dataset->fBuffer;
1689 if (SDDS_dataset->layout.gzipFile) {
1690 gzfp = layout->gzfp;
1691 for (i = 0; i < layout->n_columns; i++) {
1692 type = layout->column_definition[i].type;
1695 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1696 if (SDDS_dataset->row_flag[row] && !SDDS_GZipWriteBinaryString(*((
char **)SDDS_dataset->data[i] + row), gzfp, fBuffer)) {
1697 SDDS_SetError(
"Unable to write arrays--failure writing string (SDDS_WriteBinaryColumns)");
1702 if (rows == SDDS_dataset->n_rows) {
1703 if (!SDDS_GZipBufferedWrite(SDDS_dataset->data[i], size * rows, gzfp, fBuffer)) {
1704 SDDS_SetError(
"Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1708 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1709 if (SDDS_dataset->row_flag[row] && !SDDS_GZipBufferedWrite((
char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer)) {
1710 SDDS_SetError(
"Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1719 if (SDDS_dataset->layout.lzmaFile) {
1720 lzmafp = layout->lzmafp;
1721 for (i = 0; i < layout->n_columns; i++) {
1722 type = layout->column_definition[i].type;
1724 if (layout->column_definition[i].type ==
SDDS_STRING) {
1725 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1727 SDDS_SetError(
"Unable to write arrays--failure writing string (SDDS_WriteBinaryColumns)");
1732 if (rows == SDDS_dataset->n_rows) {
1734 SDDS_SetError(
"Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1738 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1739 if (SDDS_dataset->row_flag[row] && !
SDDS_LZMABufferedWrite((
char *)SDDS_dataset->data[i] + row * size, size, lzmafp, fBuffer)) {
1740 SDDS_SetError(
"Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1749 for (i = 0; i < layout->n_columns; i++) {
1750 type = layout->column_definition[i].type;
1752 if (layout->column_definition[i].type ==
SDDS_STRING) {
1753 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1754 if (SDDS_dataset->row_flag[row] && !
SDDS_WriteBinaryString(*((
char **)SDDS_dataset->data[i] + row), fp, fBuffer)) {
1755 SDDS_SetError(
"Unable to write arrays--failure writing string (SDDS_WriteBinaryColumns)");
1760 if (rows == SDDS_dataset->n_rows) {
1762 SDDS_SetError(
"Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1766 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1767 if (SDDS_dataset->row_flag[row] && !
SDDS_BufferedWrite((
char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer)) {
1768 SDDS_SetError(
"Unable to write columns--failure writing values (SDDS_WriteBinaryColumns)");
1817 int64_t i, row, rows, size, type;
1828 layout = &SDDS_dataset->layout;
1830 fBuffer = &SDDS_dataset->fBuffer;
1832 if (SDDS_dataset->layout.gzipFile) {
1833 gzfp = layout->gzfp;
1834 for (i = 0; i < layout->n_columns; i++) {
1835 type = layout->column_definition[i].type;
1838 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1839 if (SDDS_dataset->row_flag[row] && !SDDS_GZipWriteNonNativeBinaryString(*((
char **)SDDS_dataset->data[i] + row), gzfp, fBuffer)) {
1840 SDDS_SetError(
"Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryColumns)");
1845 if (rows == SDDS_dataset->n_rows) {
1846 if (!SDDS_GZipBufferedWrite((
char *)SDDS_dataset->data[i], size * rows, gzfp, fBuffer)) {
1847 SDDS_SetError(
"Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1851 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1852 if (SDDS_dataset->row_flag[row] && !SDDS_GZipBufferedWrite((
char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer)) {
1853 SDDS_SetError(
"Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1862 if (SDDS_dataset->layout.lzmaFile) {
1863 lzmafp = layout->lzmafp;
1864 for (i = 0; i < layout->n_columns; i++) {
1865 type = layout->column_definition[i].type;
1868 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1870 SDDS_SetError(
"Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryColumns)");
1875 if (rows == SDDS_dataset->n_rows) {
1877 SDDS_SetError(
"Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1881 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1882 if (SDDS_dataset->row_flag[row] && !
SDDS_LZMABufferedWrite((
char *)SDDS_dataset->data[i] + row * size, size, lzmafp, fBuffer)) {
1883 SDDS_SetError(
"Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1892 for (i = 0; i < layout->n_columns; i++) {
1893 type = layout->column_definition[i].type;
1896 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1898 SDDS_SetError(
"Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryColumns)");
1903 if (rows == SDDS_dataset->n_rows) {
1905 SDDS_SetError(
"Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1909 for (row = 0; row < SDDS_dataset->n_rows; row++) {
1910 if (SDDS_dataset->row_flag[row] && !
SDDS_BufferedWrite((
char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer)) {
1911 SDDS_SetError(
"Unable to write columns--failure writing values (SDDS_WriteNonNativeBinaryColumns)");
1958 int64_t i, type, size;
1969 layout = &SDDS_dataset->layout;
1971 if (SDDS_dataset->layout.gzipFile) {
1972 gzfp = layout->gzfp;
1973 fBuffer = &SDDS_dataset->fBuffer;
1974 for (i = 0; i < layout->n_columns; i++) {
1975 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
1976 if (!SDDS_GZipWriteBinaryString(*((
char **)SDDS_dataset->data[i] + row), gzfp, fBuffer)) {
1977 SDDS_SetError(
"Unable to write rows--failure writing string (SDDS_WriteBinaryRows)");
1982 if (!SDDS_GZipBufferedWrite((
char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer)) {
1983 SDDS_SetError(
"Unable to write row--failure writing value (SDDS_WriteBinaryRow)");
1990 if (SDDS_dataset->layout.lzmaFile) {
1991 lzmafp = layout->lzmafp;
1992 fBuffer = &SDDS_dataset->fBuffer;
1993 for (i = 0; i < layout->n_columns; i++) {
1994 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
1996 SDDS_SetError(
"Unable to write rows--failure writing string (SDDS_WriteBinaryRows)");
2002 SDDS_SetError(
"Unable to write row--failure writing value (SDDS_WriteBinaryRow)");
2009 fBuffer = &SDDS_dataset->fBuffer;
2010 for (i = 0; i < layout->n_columns; i++) {
2011 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
2013 SDDS_SetError(
"Unable to write rows--failure writing string (SDDS_WriteBinaryRows)");
2018 if (!
SDDS_BufferedWrite((
char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer)) {
2019 SDDS_SetError(
"Unable to write row--failure writing value (SDDS_WriteBinaryRow)");
2055 int32_t returnValue;
2057 returnValue = SDDS_dataset->readRecoveryPossible;
2058 SDDS_dataset->readRecoveryPossible = 0;
2083 SDDS_dataset->readRecoveryPossible = mode;
2204 int64_t n_rows, i, j, k, alloc_rows, rows_to_store, mod;
2213 void **statData=NULL;
2216 if (SDDS_dataset->autoRecovered)
2218 if (SDDS_dataset->swapByteOrder) {
2226 if (SDDS_dataset->layout.gzipFile) {
2227 gzfp = SDDS_dataset->layout.gzfp;
2230 if (SDDS_dataset->layout.lzmaFile) {
2231 lzmafp = SDDS_dataset->layout.lzmafp;
2233 fp = SDDS_dataset->layout.fp;
2238 fBuffer = &SDDS_dataset->fBuffer;
2239 if (!fBuffer->buffer) {
2240 if (defaultIOBufferSize == 0 && (SDDS_dataset->layout.popenUsed || !SDDS_dataset->layout.filename) && (sparse_interval > 1 || sparse_offset > 0 || last_rows > 0)) {
2241 SDDS_SetError(
"The IO buffer size is 0 for data being read from a pipe with sparsing. This is not supported.");
2244 if (!(fBuffer->buffer = fBuffer->data =
SDDS_Malloc(
sizeof(
char) * (defaultIOBufferSize + 1)))) {
2245 SDDS_SetError(
"Unable to do buffered read--allocation failure");
2248 fBuffer->bufferSize = defaultIOBufferSize;
2249 fBuffer->bytesLeft = 0;
2251 SDDS_dataset->rowcount_offset = -1;
2253 if (SDDS_dataset->layout.gzipFile) {
2254 if (!SDDS_GZipBufferedRead(&n_rows32,
sizeof(n_rows32), gzfp, &SDDS_dataset->fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
2256 return (SDDS_dataset->page_number = -1);
2257 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2260 if (n_rows32 == INT32_MIN) {
2261 if (!SDDS_GZipBufferedRead(&n_rows,
sizeof(n_rows), gzfp, &SDDS_dataset->fBuffer,
SDDS_LONG64, SDDS_dataset->layout.byteOrderDeclared)) {
2263 return (SDDS_dataset->page_number = -1);
2264 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2276 if (SDDS_dataset->layout.lzmaFile) {
2278 if (lzma_eof(lzmafp))
2279 return (SDDS_dataset->page_number = -1);
2280 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2283 if (n_rows32 == INT32_MIN) {
2285 if (lzma_eof(lzmafp))
2286 return (SDDS_dataset->page_number = -1);
2287 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2294 SDDS_dataset->rowcount_offset = ftell(fp);
2295 if (!
SDDS_BufferedRead(&n_rows32,
sizeof(n_rows32), fp, &SDDS_dataset->fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
2297 return (SDDS_dataset->page_number = -1);
2298 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2301 if (n_rows32 == INT32_MIN) {
2304 return (SDDS_dataset->page_number = -1);
2305 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadBinaryPageDetailed)");
2317 fprintf(stderr,
"Expect %" PRId64
" rows of data\n", n_rows);
2320 SDDS_SetError(
"Unable to read page--negative number of rows (SDDS_ReadBinaryPageDetailed)");
2323 if (SDDS_dataset->layout.byteOrderDeclared == 0) {
2324 if (n_rows > 10000000) {
2325 SDDS_SetError(
"Unable to read page--endian byte order not declared and suspected to be non-native. (SDDS_ReadBinaryPageDetailed)");
2331 return (SDDS_dataset->page_number = -1);
2336 if (SDDS_dataset->layout.data_mode.column_major) {
2337 if ((sparse_interval != 1) || (sparse_offset != 0) || (last_rows != 0)) {
2338 SDDS_SetError(
"Sparsing column data not yet supported for column-major layout. Use sddsconvert -majorOrder=row to convert first.\n");
2341 sparse_interval = 1;
2346 sparse_interval = 1;
2347 sparse_offset = n_rows - last_rows;
2349 if (sparse_interval <= 0)
2350 sparse_interval = 1;
2351 if (sparse_offset < 0)
2354 rows_to_store = (n_rows - sparse_offset) / sparse_interval + 2;
2355 alloc_rows = rows_to_store - SDDS_dataset->n_rows_allocated;
2358 SDDS_SetError(
"Unable to read page--couldn't start page (SDDS_ReadBinaryPageDetailed)");
2364 SDDS_SetError(
"Unable to read page--parameter reading error (SDDS_ReadBinaryPageDetailed)");
2370 SDDS_SetError(
"Unable to read page--array reading error (SDDS_ReadBinaryPageDetailed)");
2373 if (SDDS_dataset->layout.data_mode.column_major) {
2374 SDDS_dataset->n_rows = n_rows;
2376 SDDS_SetError(
"Unable to read page--column reading error (SDDS_ReadBinaryPageDetailed)");
2379 return (SDDS_dataset->page_number);
2381 if ((sparse_interval <= 1) && (sparse_offset == 0)) {
2382 for (j = 0; j < n_rows; j++) {
2384 SDDS_dataset->n_rows = j;
2385 if (SDDS_dataset->autoRecover) {
2387 fprintf(stderr,
"Doing auto-read recovery\n");
2389 SDDS_dataset->autoRecovered = 1;
2391 return (SDDS_dataset->page_number);
2393 SDDS_SetError(
"Unable to read page--error reading data row (SDDS_ReadBinaryPageDetailed)");
2398 SDDS_dataset->n_rows = j;
2399 return (SDDS_dataset->page_number);
2401 for (j = 0; j < sparse_offset; j++) {
2403 SDDS_dataset->n_rows = 0;
2404 if (SDDS_dataset->autoRecover) {
2405 SDDS_dataset->autoRecovered = 1;
2407 return (SDDS_dataset->page_number);
2409 SDDS_SetError(
"Unable to read page--error reading data row (SDDS_ReadBinaryPageDetailed)");
2414 n_rows -= sparse_offset;
2415 if (sparse_statistics != 0) {
2417 statData = (
void**)malloc(SDDS_dataset->layout.n_columns *
sizeof(
void*));
2418 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2421 statData[i] = (
double*)calloc(sparse_interval,
sizeof(
double));
2424 for (j = k = 0; j < n_rows; j++) {
2426 SDDS_dataset->n_rows = k;
2427 if (SDDS_dataset->autoRecover) {
2428 SDDS_dataset->autoRecovered = 1;
2430 return (SDDS_dataset->page_number);
2432 SDDS_SetError(
"Unable to read page--error reading data row (SDDS_ReadBinaryPageDetailed)");
2436 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2437 switch (SDDS_dataset->layout.column_definition[i].type) {
2439 ((
double*)statData[i])[j % sparse_interval] = (double)(((
float*)SDDS_dataset->data[i])[k]);
2442 ((
double*)statData[i])[j % sparse_interval] = ((
double*)SDDS_dataset->data[i])[k];
2445 ((
double*)statData[i])[j % sparse_interval] = (double)(((
long double*)SDDS_dataset->data[i])[k]);
2449 if (sparse_statistics == 1) {
2451 compute_average(&statResult, (
double*)statData[i], (j % sparse_interval) + 1);
2452 }
else if (sparse_statistics == 2) {
2454 compute_median(&statResult, (
double*)statData[i], (j % sparse_interval) + 1);
2455 }
else if (sparse_statistics == 3) {
2457 statResult = min_in_array((
double*)statData[i], (j % sparse_interval) + 1);
2458 }
else if (sparse_statistics == 4) {
2460 statResult = max_in_array((
double*)statData[i], (j % sparse_interval) + 1);
2463 switch (SDDS_dataset->layout.column_definition[i].type) {
2465 ((
float*)SDDS_dataset->data[i])[k] = statResult;
2468 ((
double*)SDDS_dataset->data[i])[k] = statResult;
2471 ((
long double*)SDDS_dataset->data[i])[k] = statResult;
2475 if (j % sparse_interval == sparse_interval - 1) {
2479 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2486 for (j = k = 0; j < n_rows; j++) {
2488 SDDS_dataset->n_rows = k;
2489 if (SDDS_dataset->autoRecover) {
2490 SDDS_dataset->autoRecovered = 1;
2492 return (SDDS_dataset->page_number);
2494 SDDS_SetError(
"Unable to read page--error reading data row (SDDS_ReadBinaryPageDetailed)");
2501 SDDS_dataset->n_rows = k;
2502 return (SDDS_dataset->page_number);
2523 static char *dummy_string =
"";
2525 string = dummy_string;
2526 length = strlen(
string);
2528 SDDS_SetError(
"Unable to write string--error writing length");
2532 SDDS_SetError(
"Unable to write string--error writing contents");
2555 static char *dummy_string =
"";
2557 string = dummy_string;
2558 length = strlen(
string);
2560 SDDS_SetError(
"Unable to write string--error writing length");
2564 SDDS_SetError(
"Unable to write string--error writing contents");
2586int32_t SDDS_GZipWriteBinaryString(
char *
string, gzFile gzfp,
SDDS_FILEBUFFER *fBuffer) {
2588 static char *dummy_string =
"";
2590 string = dummy_string;
2591 length = strlen(
string);
2592 if (!SDDS_GZipBufferedWrite(&length,
sizeof(length), gzfp, fBuffer)) {
2593 SDDS_SetError(
"Unable to write string--error writing length");
2596 if (length && !SDDS_GZipBufferedWrite(
string,
sizeof(*
string) * length, gzfp, fBuffer)) {
2597 SDDS_SetError(
"Unable to write string--error writing contents");
2626 if (!(
string =
SDDS_Malloc(
sizeof(*
string) * (length + 1))))
2656 if (!(
string =
SDDS_Malloc(
sizeof(*
string) * (length + 1))))
2681char *SDDS_ReadGZipBinaryString(gzFile gzfp,
SDDS_FILEBUFFER *fBuffer, int32_t skip) {
2685 if (!SDDS_GZipBufferedRead(&length,
sizeof(length), gzfp, fBuffer,
SDDS_LONG, 0) || length < 0)
2687 if (!(
string =
SDDS_Malloc(
sizeof(*
string) * (length + 1))))
2689 if (length && !SDDS_GZipBufferedRead(skip ? NULL :
string,
sizeof(*
string) * length, gzfp, fBuffer,
SDDS_STRING, 0))
2716 int64_t i, type, size;
2727 layout = &SDDS_dataset->layout;
2728 fBuffer = &SDDS_dataset->fBuffer;
2731 if (SDDS_dataset->layout.gzipFile) {
2732 gzfp = layout->gzfp;
2733 for (i = 0; i < layout->n_columns; i++) {
2734 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
2736 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
2738 if (((
char ***)SDDS_dataset->data)[i][row])
2739 free((((
char ***)SDDS_dataset->data)[i][row]));
2740 if (!(((
char ***)SDDS_dataset->data)[i][row] = SDDS_ReadGZipBinaryString(gzfp, fBuffer, 0))) {
2741 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2745 if (!SDDS_ReadGZipBinaryString(gzfp, fBuffer, 1)) {
2746 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2752 if (!SDDS_GZipBufferedRead(skip ? NULL : (
char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
2753 SDDS_SetError(
"Unable to read row--failure reading value (SDDS_ReadBinaryRow)");
2760 if (SDDS_dataset->layout.lzmaFile) {
2761 lzmafp = layout->lzmafp;
2762 for (i = 0; i < layout->n_columns; i++) {
2763 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
2765 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
2767 if (((
char ***)SDDS_dataset->data)[i][row])
2768 free((((
char ***)SDDS_dataset->data)[i][row]));
2770 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2775 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2781 if (!
SDDS_LZMABufferedRead(skip ? NULL : (
char *)SDDS_dataset->data[i] + row * size, size, lzmafp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
2782 SDDS_SetError(
"Unable to read row--failure reading value (SDDS_ReadBinaryRow)");
2789 for (i = 0; i < layout->n_columns; i++) {
2790 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
2792 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
2794 if (((
char ***)SDDS_dataset->data)[i][row])
2795 free((((
char ***)SDDS_dataset->data)[i][row]));
2797 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2802 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2808 if (!
SDDS_BufferedRead(skip ? NULL : (
char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
2809 SDDS_SetError(
"Unable to read row--failure reading value (SDDS_ReadBinaryRow)");
2842 int64_t row, offset, newRows = 0;
2843 int32_t rowsPresent32;
2844 int64_t rowsPresent;
2847 if (SDDS_dataset->parallel_io) {
2848 SDDS_SetError(
"Error: MPI mode not supported yet in SDDS_ReadNewBinaryRows");
2852 if (SDDS_dataset->original_layout.data_mode.mode == SDDS_ASCII) {
2853 SDDS_SetError(
"Error: ASCII files not supported in SDDS_ReadNewBinaryRows");
2856 if (SDDS_dataset->layout.data_mode.column_major) {
2857 SDDS_SetError(
"Error: column-major order binary files not supported in SDDS_ReadNewBinaryRows");
2860 if (SDDS_dataset->swapByteOrder) {
2861 SDDS_SetError(
"Error: Non-native endian not supported yet in SDDS_ReadNewBinaryRows");
2865 if (SDDS_dataset->layout.gzipFile) {
2866 SDDS_SetError(
"Error: gzip compressed files not supported yet in SDDS_ReadNewBinaryRows");
2870 if (SDDS_dataset->layout.lzmaFile) {
2871 SDDS_SetError(
"Error: lzma compressed files not supported yet in SDDS_ReadNewBinaryRows");
2879 offset = ftell(SDDS_dataset->layout.fp);
2880 fseek(SDDS_dataset->layout.fp, SDDS_dataset->rowcount_offset, 0);
2881 if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY) {
2882 fread(&rowsPresent32,
sizeof(rowsPresent32), 1, SDDS_dataset->layout.fp);
2883 if (SDDS_dataset->swapByteOrder) {
2886 if (rowsPresent32 == INT32_MIN) {
2887 fread(&rowsPresent,
sizeof(rowsPresent), 1, SDDS_dataset->layout.fp);
2888 if (SDDS_dataset->swapByteOrder) {
2892 rowsPresent = rowsPresent32;
2896 if (!fgets(buffer, 30, SDDS_dataset->layout.fp) || strlen(buffer) != 21 || sscanf(buffer,
"%" SCNd64, &rowsPresent) != 1) {
2897 SDDS_SetError(
"Error: row count not present or not correct length");
2901 fseek(SDDS_dataset->layout.fp, offset, 0);
2904 if (rowsPresent > SDDS_dataset->n_rows_allocated) {
2910 for (row = SDDS_dataset->n_rows; row < rowsPresent; row++) {
2912 if (SDDS_dataset->autoRecover) {
2914 SDDS_dataset->autoRecovered = 1;
2918 SDDS_SetError(
"Unable to read page--error reading data row");
2922 newRows = row + 1 - SDDS_dataset->n_rows;
2923 SDDS_dataset->n_rows = row + 1;
2949 char buffer[SDDS_MAXLINE];
2959 layout = &SDDS_dataset->layout;
2960 if (!layout->n_parameters)
2963 if (SDDS_dataset->layout.gzipFile) {
2964 gzfp = layout->gzfp;
2967 if (SDDS_dataset->layout.lzmaFile) {
2968 lzmafp = layout->lzmafp;
2975 fBuffer = &SDDS_dataset->fBuffer;
2976 for (i = 0; i < layout->n_parameters; i++) {
2977 if (layout->parameter_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
2979 if (layout->parameter_definition[i].fixed_value) {
2980 strcpy(buffer, layout->parameter_definition[i].fixed_value);
2981 if (!
SDDS_ScanData(buffer, layout->parameter_definition[i].type, 0, SDDS_dataset->parameter[i], 0, 1)) {
2982 SDDS_SetError(
"Unable to read page--parameter scanning error (SDDS_ReadBinaryParameters)");
2985 }
else if (layout->parameter_definition[i].type ==
SDDS_STRING) {
2986 if (*(
char **)SDDS_dataset->parameter[i])
2987 free(*(
char **)SDDS_dataset->parameter[i]);
2989 if (SDDS_dataset->layout.gzipFile) {
2990 if (!(*((
char **)SDDS_dataset->parameter[i]) = SDDS_ReadGZipBinaryString(gzfp, fBuffer, 0))) {
2991 SDDS_SetError(
"Unable to read parameters--failure reading string (SDDS_ReadBinaryParameters)");
2996 if (SDDS_dataset->layout.lzmaFile) {
2998 SDDS_SetError(
"Unable to read parameters--failure reading string (SDDS_ReadBinaryParameters)");
3003 SDDS_SetError(
"Unable to read parameters--failure reading string (SDDS_ReadBinaryParameters)");
3012 if (SDDS_dataset->layout.gzipFile) {
3013 if (!SDDS_GZipBufferedRead(SDDS_dataset->parameter[i],
SDDS_type_size[layout->parameter_definition[i].type - 1], gzfp, fBuffer, layout->parameter_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3014 SDDS_SetError(
"Unable to read parameters--failure reading value (SDDS_ReadBinaryParameters)");
3019 if (SDDS_dataset->layout.lzmaFile) {
3020 if (!
SDDS_LZMABufferedRead(SDDS_dataset->parameter[i],
SDDS_type_size[layout->parameter_definition[i].type - 1], lzmafp, fBuffer, layout->parameter_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3021 SDDS_SetError(
"Unable to read parameters--failure reading value (SDDS_ReadBinaryParameters)");
3025 if (!
SDDS_BufferedRead(SDDS_dataset->parameter[i],
SDDS_type_size[layout->parameter_definition[i].type - 1], fp, fBuffer, layout->parameter_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3026 SDDS_SetError(
"Unable to read parameters--failure reading value (SDDS_ReadBinaryParameters)");
3072 layout = &SDDS_dataset->layout;
3073 if (!layout->n_arrays)
3076 if (SDDS_dataset->layout.gzipFile) {
3077 gzfp = layout->gzfp;
3080 if (SDDS_dataset->layout.lzmaFile) {
3081 lzmafp = layout->lzmafp;
3088 fBuffer = &SDDS_dataset->fBuffer;
3089 if (!SDDS_dataset->array) {
3090 SDDS_SetError(
"Unable to read array--pointer to structure storage area is NULL (SDDS_ReadBinaryArrays)");
3093 for (i = 0; i < layout->n_arrays; i++) {
3094 array = SDDS_dataset->array + i;
3096 SDDS_SetError(
"Unable to get array--array definition corrupted (SDDS_ReadBinaryArrays)");
3100 SDDS_SetError(
"Unable to read array--definition copy failed (SDDS_ReadBinaryArrays)");
3104 if (!(array->dimension =
SDDS_Realloc(array->dimension,
sizeof(*array->dimension) * array->definition->dimensions))) {
3105 SDDS_SetError(
"Unable to read array--allocation failure (SDDS_ReadBinaryArrays)");
3109 if (SDDS_dataset->layout.gzipFile) {
3110 if (!SDDS_GZipBufferedRead(array->dimension,
sizeof(*array->dimension) * array->definition->dimensions, gzfp, fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
3111 SDDS_SetError(
"Unable to read arrays--failure reading dimensions (SDDS_ReadBinaryArrays)");
3116 if (SDDS_dataset->layout.lzmaFile) {
3117 if (!
SDDS_LZMABufferedRead(array->dimension,
sizeof(*array->dimension) * array->definition->dimensions, lzmafp, fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
3118 SDDS_SetError(
"Unable to read arrays--failure reading dimensions (SDDS_ReadBinaryArrays)");
3122 if (!
SDDS_BufferedRead(array->dimension,
sizeof(*array->dimension) * array->definition->dimensions, fp, fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
3123 SDDS_SetError(
"Unable to read arrays--failure reading dimensions (SDDS_ReadBinaryArrays)");
3130 array->elements = 1;
3131 for (j = 0; j < array->definition->dimensions; j++)
3132 array->elements *= array->dimension[j];
3135 array->data = array->pointer = NULL;
3136 if (array->elements == 0)
3138 if (array->elements < 0) {
3139 SDDS_SetError(
"Unable to read array--number of elements is negative (SDDS_ReadBinaryArrays)");
3143 SDDS_SetError(
"Unable to read array--allocation failure (SDDS_ReadBinaryArrays)");
3148 if (SDDS_dataset->layout.gzipFile) {
3149 for (j = 0; j < array->elements; j++) {
3150 if (!(((
char **)(array->data))[j] = SDDS_ReadGZipBinaryString(gzfp, fBuffer, 0))) {
3151 SDDS_SetError(
"Unable to read arrays--failure reading string (SDDS_ReadBinaryArrays)");
3157 if (SDDS_dataset->layout.lzmaFile) {
3158 for (j = 0; j < array->elements; j++) {
3160 SDDS_SetError(
"Unable to read arrays--failure reading string (SDDS_ReadBinaryArrays)");
3165 for (j = 0; j < array->elements; j++) {
3167 SDDS_SetError(
"Unable to read arrays--failure reading string (SDDS_ReadBinaryArrays)");
3177 if (SDDS_dataset->layout.gzipFile) {
3178 if (!SDDS_GZipBufferedRead(array->data,
SDDS_type_size[array->definition->type - 1] * array->elements, gzfp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
3179 SDDS_SetError(
"Unable to read arrays--failure reading values (SDDS_ReadBinaryArrays)");
3184 if (SDDS_dataset->layout.lzmaFile) {
3185 if (!
SDDS_LZMABufferedRead(array->data,
SDDS_type_size[array->definition->type - 1] * array->elements, lzmafp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
3186 SDDS_SetError(
"Unable to read arrays--failure reading values (SDDS_ReadBinaryArrays)");
3190 if (!
SDDS_BufferedRead(array->data,
SDDS_type_size[array->definition->type - 1] * array->elements, fp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
3191 SDDS_SetError(
"Unable to read arrays--failure reading values (SDDS_ReadBinaryArrays)");
3236 layout = &SDDS_dataset->layout;
3237 if (!layout->n_columns || !SDDS_dataset->n_rows)
3240 if (SDDS_dataset->layout.gzipFile) {
3241 gzfp = layout->gzfp;
3244 if (SDDS_dataset->layout.lzmaFile) {
3245 lzmafp = layout->lzmafp;
3252 fBuffer = &SDDS_dataset->fBuffer;
3254 for (i = 0; i < layout->n_columns; i++) {
3255 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
3257 if (layout->column_definition[i].type ==
SDDS_STRING) {
3259 if (SDDS_dataset->layout.gzipFile) {
3260 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3261 if (((
char ***)SDDS_dataset->data)[i][row])
3262 free((((
char ***)SDDS_dataset->data)[i][row]));
3263 if (!(((
char ***)SDDS_dataset->data)[i][row] = SDDS_ReadGZipBinaryString(gzfp, fBuffer, 0))) {
3264 SDDS_SetError(
"Unable to read columns--failure reading string (SDDS_ReadBinaryColumns)");
3270 if (SDDS_dataset->layout.lzmaFile) {
3271 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3272 if (((
char ***)SDDS_dataset->data)[i][row])
3273 free((((
char ***)SDDS_dataset->data)[i][row]));
3275 SDDS_SetError(
"Unable to read columns--failure reading string (SDDS_ReadBinaryColumms)");
3280 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3281 if (((
char ***)SDDS_dataset->data)[i][row])
3282 free((((
char ***)SDDS_dataset->data)[i][row]));
3284 SDDS_SetError(
"Unable to read columns--failure reading string (SDDS_ReadBinaryColumms)");
3294 if (SDDS_dataset->layout.gzipFile) {
3295 if (!SDDS_GZipBufferedRead(SDDS_dataset->data[i],
SDDS_type_size[layout->column_definition[i].type - 1] * SDDS_dataset->n_rows, gzfp, fBuffer, layout->column_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3296 SDDS_SetError(
"Unable to read columns--failure reading values (SDDS_ReadBinaryColumns)");
3301 if (SDDS_dataset->layout.lzmaFile) {
3302 if (!
SDDS_LZMABufferedRead(SDDS_dataset->data[i],
SDDS_type_size[layout->column_definition[i].type - 1] * SDDS_dataset->n_rows, lzmafp, fBuffer, layout->column_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3303 SDDS_SetError(
"Unable to read columns--failure reading values (SDDS_ReadBinaryColumns)");
3307 if (!
SDDS_BufferedRead(SDDS_dataset->data[i],
SDDS_type_size[layout->column_definition[i].type - 1] * SDDS_dataset->n_rows, fp, fBuffer, layout->column_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3308 SDDS_SetError(
"Unable to read columns--failure reading values (SDDS_ReadBinaryColumns)");
3355 layout = &SDDS_dataset->layout;
3356 if (!layout->n_columns || !SDDS_dataset->n_rows)
3359 if (SDDS_dataset->layout.gzipFile) {
3360 gzfp = layout->gzfp;
3363 if (SDDS_dataset->layout.lzmaFile) {
3364 lzmafp = layout->lzmafp;
3371 fBuffer = &SDDS_dataset->fBuffer;
3373 for (i = 0; i < layout->n_columns; i++) {
3374 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
3376 if (layout->column_definition[i].type ==
SDDS_STRING) {
3378 if (SDDS_dataset->layout.gzipFile) {
3379 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3380 if (((
char ***)SDDS_dataset->data)[i][row])
3381 free((((
char ***)SDDS_dataset->data)[i][row]));
3382 if (!(((
char ***)SDDS_dataset->data)[i][row] = SDDS_ReadNonNativeGZipBinaryString(gzfp, fBuffer, 0))) {
3383 SDDS_SetError(
"Unable to read columns--failure reading string (SDDS_ReadNonNativeBinaryColumns)");
3389 if (SDDS_dataset->layout.lzmaFile) {
3390 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3391 if (((
char ***)SDDS_dataset->data)[i][row])
3392 free((((
char ***)SDDS_dataset->data)[i][row]));
3394 SDDS_SetError(
"Unable to read columns--failure reading string (SDDS_ReadNonNativeBinaryColumms)");
3399 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3400 if (((
char ***)SDDS_dataset->data)[i][row])
3401 free((((
char ***)SDDS_dataset->data)[i][row]));
3403 SDDS_SetError(
"Unable to read columns--failure reading string (SDDS_ReadNonNativeBinaryColumms)");
3413 if (SDDS_dataset->layout.gzipFile) {
3414 if (!SDDS_GZipBufferedRead(SDDS_dataset->data[i],
SDDS_type_size[layout->column_definition[i].type - 1] * SDDS_dataset->n_rows, gzfp, fBuffer, layout->column_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3415 SDDS_SetError(
"Unable to read columns--failure reading values (SDDS_ReadNonNativeBinaryColumns)");
3420 if (SDDS_dataset->layout.lzmaFile) {
3421 if (!
SDDS_LZMABufferedRead(SDDS_dataset->data[i],
SDDS_type_size[layout->column_definition[i].type - 1] * SDDS_dataset->n_rows, lzmafp, fBuffer, layout->column_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3422 SDDS_SetError(
"Unable to read columns--failure reading values (SDDS_ReadNonNativeBinaryColumns)");
3426 if (!
SDDS_BufferedRead(SDDS_dataset->data[i],
SDDS_type_size[layout->column_definition[i].type - 1] * SDDS_dataset->n_rows, fp, fBuffer, layout->column_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
3427 SDDS_SetError(
"Unable to read columns--failure reading values (SDDS_ReadNonNativeBinaryColumns)");
3462 unsigned short *suData;
3469 long double *ldData;
3471 layout = &SDDSin->layout;
3472 for (i = 0; i < layout->n_columns; i++) {
3473 switch (layout->column_definition[i].type) {
3475 sData = SDDSin->data[i];
3476 for (row = 0; row < SDDSin->n_rows; row++)
3480 suData = SDDSin->data[i];
3481 for (row = 0; row < SDDSin->n_rows; row++)
3485 lData = SDDSin->data[i];
3486 for (row = 0; row < SDDSin->n_rows; row++)
3490 luData = SDDSin->data[i];
3491 for (row = 0; row < SDDSin->n_rows; row++)
3495 lData64 = SDDSin->data[i];
3496 for (row = 0; row < SDDSin->n_rows; row++)
3500 luData64 = SDDSin->data[i];
3501 for (row = 0; row < SDDSin->n_rows; row++)
3505 ldData = SDDSin->data[i];
3506 for (row = 0; row < SDDSin->n_rows; row++)
3510 dData = SDDSin->data[i];
3511 for (row = 0; row < SDDSin->n_rows; row++)
3515 fData = SDDSin->data[i];
3516 for (row = 0; row < SDDSin->n_rows; row++)
3548 unsigned short *suData;
3555 long double *ldData;
3557 layout = &SDDSin->layout;
3558 for (i = 0; i < layout->n_parameters; i++) {
3559 if (layout->parameter_definition[i].fixed_value) {
3562 switch (layout->parameter_definition[i].type) {
3564 sData = SDDSin->parameter[i];
3568 suData = SDDSin->parameter[i];
3572 lData = SDDSin->parameter[i];
3576 luData = SDDSin->parameter[i];
3580 lData64 = SDDSin->parameter[i];
3584 luData64 = SDDSin->parameter[i];
3588 ldData = SDDSin->parameter[i];
3592 dData = SDDSin->parameter[i];
3596 fData = SDDSin->parameter[i];
3627 unsigned short *suData;
3634 long double *ldData;
3636 layout = &SDDSin->layout;
3638 for (i = 0; i < layout->n_arrays; i++) {
3639 switch (layout->array_definition[i].type) {
3641 sData = SDDSin->array[i].data;
3642 for (j = 0; j < SDDSin->array[i].elements; j++)
3646 suData = SDDSin->array[i].data;
3647 for (j = 0; j < SDDSin->array[i].elements; j++)
3651 lData = SDDSin->array[i].data;
3652 for (j = 0; j < SDDSin->array[i].elements; j++)
3656 luData = SDDSin->array[i].data;
3657 for (j = 0; j < SDDSin->array[i].elements; j++)
3661 lData64 = SDDSin->array[i].data;
3662 for (j = 0; j < SDDSin->array[i].elements; j++)
3666 luData64 = SDDSin->array[i].data;
3667 for (j = 0; j < SDDSin->array[i].elements; j++)
3671 ldData = SDDSin->array[i].data;
3672 for (j = 0; j < SDDSin->array[i].elements; j++)
3676 dData = SDDSin->array[i].data;
3677 for (j = 0; j < SDDSin->array[i].elements; j++)
3681 fData = SDDSin->array[i].data;
3682 for (j = 0; j < SDDSin->array[i].elements; j++)
3705 c1 = *((
char *)data);
3706 *((
char *)data) = *(((
char *)data) + 1);
3707 *(((
char *)data) + 1) = c1;
3723 c1 = *((
char *)data);
3724 *((
char *)data) = *(((
char *)data) + 1);
3725 *(((
char *)data) + 1) = c1;
3743 for (i = 0, j = 3; i < 4; i++, j--)
3744 *(((
char *)data) + i) = *(((
char *)©) + j);
3762 for (i = 0, j = 3; i < 4; i++, j--)
3763 *(((
char *)data) + i) = *(((
char *)©) + j);
3781 for (i = 0, j = 7; i < 8; i++, j--)
3782 *(((
char *)data) + i) = *(((
char *)©) + j);
3800 for (i = 0, j = 7; i < 8; i++, j--)
3801 *(((
char *)data) + i) = *(((
char *)©) + j);
3819 for (i = 0, j = 3; i < 4; i++, j--)
3820 *(((
char *)data) + i) = *(((
char *)©) + j);
3838 for (i = 0, j = 7; i < 8; i++, j--)
3839 *(((
char *)data) + i) = *(((
char *)©) + j);
3858 if (LDBL_DIG == 18) {
3859 for (i = 0, j = 11; i < 12; i++, j--)
3860 *(((
char *)data) + i) = *(((
char *)©) + j);
3862 for (i = 0, j = 7; i < 8; i++, j--)
3863 *(((
char *)data) + i) = *(((
char *)©) + j);
3941 if (SDDS_dataset->layout.disconnected) {
3942 SDDS_SetError(
"Can't read page--file is disconnected (SDDS_ReadNonNativePageDetailed)");
3946 if (SDDS_dataset->layout.gzipFile) {
3947 if (!SDDS_dataset->layout.gzfp) {
3948 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadNonNativePageDetailed)");
3953 if (SDDS_dataset->layout.lzmaFile) {
3954 if (!SDDS_dataset->layout.lzmafp) {
3955 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadNonNativePageDetailed)");
3959 if (!SDDS_dataset->layout.fp) {
3960 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadNonNativePageDetailed)");
3967 if (SDDS_dataset->original_layout.data_mode.mode == SDDS_ASCII) {
3968 if ((retval =
SDDS_ReadAsciiPage(SDDS_dataset, sparse_interval, sparse_offset, 0)) < 1) {
3971 }
else if (SDDS_dataset->original_layout.data_mode.mode == SDDS_BINARY) {
3976 SDDS_SetError(
"Unable to read page--unrecognized data mode (SDDS_ReadNonNativePageDetailed)");
4004 if (SDDS_dataset->layout.disconnected) {
4005 SDDS_SetError(
"Can't read page--file is disconnected (SDDS_ReadNonNativePageLastRows)");
4009 if (SDDS_dataset->layout.gzipFile) {
4010 if (!SDDS_dataset->layout.gzfp) {
4011 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadNonNativePageLastRows)");
4016 if (SDDS_dataset->layout.lzmaFile) {
4017 if (!SDDS_dataset->layout.lzmafp) {
4018 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadNonNativePageLastRows)");
4022 if (!SDDS_dataset->layout.fp) {
4023 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadNonNativePageLastRows)");
4030 if (SDDS_dataset->original_layout.data_mode.mode == SDDS_ASCII) {
4034 }
else if (SDDS_dataset->original_layout.data_mode.mode == SDDS_BINARY) {
4039 SDDS_SetError(
"Unable to read page--unrecognized data mode (SDDS_ReadNonNativePageLastRows)");
4113 int32_t n_rows32 = 0;
4114 int64_t n_rows, j, k, alloc_rows, rows_to_store, mod;
4127 if (SDDS_dataset->layout.gzipFile) {
4128 gzfp = SDDS_dataset->layout.gzfp;
4131 if (SDDS_dataset->layout.lzmaFile) {
4132 lzmafp = SDDS_dataset->layout.lzmafp;
4134 fp = SDDS_dataset->layout.fp;
4139 fBuffer = &SDDS_dataset->fBuffer;
4140 if (!fBuffer->buffer) {
4141 if (!(fBuffer->buffer = fBuffer->data =
SDDS_Malloc(
sizeof(
char) * defaultIOBufferSize))) {
4142 SDDS_SetError(
"Unable to do buffered read--allocation failure");
4145 fBuffer->bufferSize = defaultIOBufferSize;
4146 fBuffer->bytesLeft = 0;
4148 SDDS_dataset->rowcount_offset = -1;
4150 if (SDDS_dataset->layout.gzipFile) {
4151 if (!SDDS_GZipBufferedRead(&n_rows32,
sizeof(n_rows32), gzfp, &SDDS_dataset->fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4153 return (SDDS_dataset->page_number = -1);
4154 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4158 if (n_rows32 == INT32_MIN) {
4159 if (!SDDS_GZipBufferedRead(&n_rows,
sizeof(n_rows), gzfp, &SDDS_dataset->fBuffer,
SDDS_LONG64, SDDS_dataset->layout.byteOrderDeclared)) {
4161 return (SDDS_dataset->page_number = -1);
4162 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4175 if (SDDS_dataset->layout.lzmaFile) {
4177 if (lzma_eof(lzmafp))
4178 return (SDDS_dataset->page_number = -1);
4179 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4183 if (n_rows32 == INT32_MIN) {
4185 if (lzma_eof(lzmafp))
4186 return (SDDS_dataset->page_number = -1);
4187 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4195 SDDS_dataset->rowcount_offset = ftell(fp);
4196 if (!
SDDS_BufferedRead(&n_rows32,
sizeof(n_rows32), fp, &SDDS_dataset->fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4198 return (SDDS_dataset->page_number = -1);
4199 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4203 if (n_rows32 == INT32_MIN) {
4206 return (SDDS_dataset->page_number = -1);
4207 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4219 SDDS_SetError(
"Unable to read page--negative number of rows (SDDS_ReadNonNativeBinaryPage)");
4225 if (SDDS_dataset->layout.data_mode.column_major) {
4226 sparse_interval = 1;
4231 sparse_interval = 1;
4232 sparse_offset = n_rows - last_rows;
4233 rows_to_store = last_rows + 2;
4234 alloc_rows = rows_to_store - SDDS_dataset->n_rows_allocated;
4236 if (sparse_interval <= 0)
4237 sparse_interval = 1;
4238 if (sparse_offset < 0)
4241 rows_to_store = (n_rows - sparse_offset) / sparse_interval + 2;
4242 alloc_rows = rows_to_store - SDDS_dataset->n_rows_allocated;
4244 SDDS_SetError(
"Unable to read page--couldn't start page (SDDS_ReadNonNativeBinaryPage)");
4250 SDDS_SetError(
"Unable to read page--parameter reading error (SDDS_ReadNonNativeBinaryPage)");
4256 SDDS_SetError(
"Unable to read page--array reading error (SDDS_ReadNonNativeBinaryPage)");
4259 if (SDDS_dataset->layout.data_mode.column_major) {
4260 SDDS_dataset->n_rows = n_rows;
4262 SDDS_SetError(
"Unable to read page--column reading error (SDDS_ReadNonNativeBinaryPage)");
4266 return (SDDS_dataset->page_number);
4268 if ((sparse_interval <= 1) && (sparse_offset == 0)) {
4269 for (j = 0; j < n_rows; j++) {
4271 SDDS_dataset->n_rows = j - 1;
4272 if (SDDS_dataset->autoRecover) {
4275 return (SDDS_dataset->page_number);
4277 SDDS_SetError(
"Unable to read page--error reading data row (SDDS_ReadNonNativeBinaryPage)");
4282 SDDS_dataset->n_rows = j;
4284 return (SDDS_dataset->page_number);
4286 for (j = 0; j < sparse_offset; j++) {
4288 SDDS_dataset->n_rows = 0;
4289 if (SDDS_dataset->autoRecover) {
4292 return (SDDS_dataset->page_number);
4294 SDDS_SetError(
"Unable to read page--error reading data row (SDDS_ReadNonNativeBinaryPage)");
4299 n_rows -= sparse_offset;
4300 for (j = k = 0; j < n_rows; j++) {
4302 SDDS_dataset->n_rows = k - 1;
4303 if (SDDS_dataset->autoRecover) {
4306 return (SDDS_dataset->page_number);
4308 SDDS_SetError(
"Unable to read page--error reading data row (SDDS_ReadNonNativeBinaryPage)");
4314 SDDS_dataset->n_rows = k;
4316 return (SDDS_dataset->page_number);
4346 char buffer[SDDS_MAXLINE];
4356 layout = &SDDS_dataset->layout;
4357 if (!layout->n_parameters)
4360 if (SDDS_dataset->layout.gzipFile) {
4361 gzfp = layout->gzfp;
4364 if (SDDS_dataset->layout.lzmaFile) {
4365 lzmafp = layout->lzmafp;
4372 fBuffer = &SDDS_dataset->fBuffer;
4373 for (i = 0; i < layout->n_parameters; i++) {
4374 if (layout->parameter_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
4376 if (layout->parameter_definition[i].fixed_value) {
4377 strcpy(buffer, layout->parameter_definition[i].fixed_value);
4378 if (!
SDDS_ScanData(buffer, layout->parameter_definition[i].type, 0, SDDS_dataset->parameter[i], 0, 1)) {
4379 SDDS_SetError(
"Unable to read page--parameter scanning error (SDDS_ReadNonNativeBinaryParameters)");
4382 }
else if (layout->parameter_definition[i].type ==
SDDS_STRING) {
4383 if (*(
char **)SDDS_dataset->parameter[i])
4384 free(*(
char **)SDDS_dataset->parameter[i]);
4386 if (SDDS_dataset->layout.gzipFile) {
4387 if (!(*((
char **)SDDS_dataset->parameter[i]) = SDDS_ReadNonNativeGZipBinaryString(gzfp, fBuffer, 0))) {
4388 SDDS_SetError(
"Unable to read parameters--failure reading string (SDDS_ReadNonNativeBinaryParameters)");
4393 if (SDDS_dataset->layout.lzmaFile) {
4395 SDDS_SetError(
"Unable to read parameters--failure reading string (SDDS_ReadNonNativeBinaryParameters)");
4400 SDDS_SetError(
"Unable to read parameters--failure reading string (SDDS_ReadNonNativeBinaryParameters)");
4409 if (SDDS_dataset->layout.gzipFile) {
4410 if (!SDDS_GZipBufferedRead(SDDS_dataset->parameter[i],
SDDS_type_size[layout->parameter_definition[i].type - 1], gzfp, fBuffer, layout->parameter_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
4411 SDDS_SetError(
"Unable to read parameters--failure reading value (SDDS_ReadNonNativeBinaryParameters)");
4416 if (SDDS_dataset->layout.lzmaFile) {
4417 if (!
SDDS_LZMABufferedRead(SDDS_dataset->parameter[i],
SDDS_type_size[layout->parameter_definition[i].type - 1], lzmafp, fBuffer, layout->parameter_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
4418 SDDS_SetError(
"Unable to read parameters--failure reading value (SDDS_ReadNonNativeBinaryParameters)");
4422 if (!
SDDS_BufferedRead(SDDS_dataset->parameter[i],
SDDS_type_size[layout->parameter_definition[i].type - 1], fp, fBuffer, layout->parameter_definition[i].type, SDDS_dataset->layout.byteOrderDeclared)) {
4423 SDDS_SetError(
"Unable to read parameters--failure reading value (SDDS_ReadNonNativeBinaryParameters)");
4473 layout = &SDDS_dataset->layout;
4474 if (!layout->n_arrays)
4477 if (SDDS_dataset->layout.gzipFile) {
4478 gzfp = layout->gzfp;
4481 if (SDDS_dataset->layout.lzmaFile) {
4482 lzmafp = layout->lzmafp;
4489 fBuffer = &SDDS_dataset->fBuffer;
4490 if (!SDDS_dataset->array) {
4491 SDDS_SetError(
"Unable to read array--pointer to structure storage area is NULL (SDDS_ReadNonNativeBinaryArrays)");
4494 for (i = 0; i < layout->n_arrays; i++) {
4495 array = SDDS_dataset->array + i;
4497 SDDS_SetError(
"Unable to get array--array definition corrupted (SDDS_ReadNonNativeBinaryArrays)");
4501 SDDS_SetError(
"Unable to read array--definition copy failed (SDDS_ReadNonNativeBinaryArrays)");
4505 if (!(array->dimension =
SDDS_Realloc(array->dimension,
sizeof(*array->dimension) * array->definition->dimensions))) {
4506 SDDS_SetError(
"Unable to read array--allocation failure (SDDS_ReadNonNativeBinaryArrays)");
4510 if (SDDS_dataset->layout.gzipFile) {
4511 if (!SDDS_GZipBufferedRead(array->dimension,
sizeof(*array->dimension) * array->definition->dimensions, gzfp, fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4512 SDDS_SetError(
"Unable to read arrays--failure reading dimensions (SDDS_ReadNonNativeBinaryArrays)");
4517 if (SDDS_dataset->layout.lzmaFile) {
4518 if (!
SDDS_LZMABufferedRead(array->dimension,
sizeof(*array->dimension) * array->definition->dimensions, lzmafp, fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4519 SDDS_SetError(
"Unable to read arrays--failure reading dimensions (SDDS_ReadNonNativeBinaryArrays)");
4523 if (!
SDDS_BufferedRead(array->dimension,
sizeof(*array->dimension) * array->definition->dimensions, fp, fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4524 SDDS_SetError(
"Unable to read arrays--failure reading dimensions (SDDS_ReadNonNativeBinaryArrays)");
4531 array->elements = 1;
4532 for (j = 0; j < array->definition->dimensions; j++) {
4534 array->elements *= array->dimension[j];
4538 array->data = array->pointer = NULL;
4539 if (array->elements == 0)
4541 if (array->elements < 0) {
4542 SDDS_SetError(
"Unable to read array--number of elements is negative (SDDS_ReadNonNativeBinaryArrays)");
4546 SDDS_SetError(
"Unable to read array--allocation failure (SDDS_ReadNonNativeBinaryArrays)");
4551 if (SDDS_dataset->layout.gzipFile) {
4552 for (j = 0; j < array->elements; j++) {
4553 if (!(((
char **)(array->data))[j] = SDDS_ReadNonNativeGZipBinaryString(gzfp, fBuffer, 0))) {
4554 SDDS_SetError(
"Unable to read arrays--failure reading string (SDDS_ReadNonNativeBinaryArrays)");
4560 if (SDDS_dataset->layout.lzmaFile) {
4561 for (j = 0; j < array->elements; j++) {
4563 SDDS_SetError(
"Unable to read arrays--failure reading string (SDDS_ReadNonNativeBinaryArrays)");
4568 for (j = 0; j < array->elements; j++) {
4570 SDDS_SetError(
"Unable to read arrays--failure reading string (SDDS_ReadNonNativeBinaryArrays)");
4580 if (SDDS_dataset->layout.gzipFile) {
4581 if (!SDDS_GZipBufferedRead(array->data,
SDDS_type_size[array->definition->type - 1] * array->elements, gzfp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
4582 SDDS_SetError(
"Unable to read arrays--failure reading values (SDDS_ReadNonNativeBinaryArrays)");
4587 if (SDDS_dataset->layout.lzmaFile) {
4588 if (!
SDDS_LZMABufferedRead(array->data,
SDDS_type_size[array->definition->type - 1] * array->elements, lzmafp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
4589 SDDS_SetError(
"Unable to read arrays--failure reading values (SDDS_ReadNonNativeBinaryArrays)");
4593 if (!
SDDS_BufferedRead(array->data,
SDDS_type_size[array->definition->type - 1] * array->elements, fp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
4594 SDDS_SetError(
"Unable to read arrays--failure reading values (SDDS_ReadNonNativeBinaryArrays)");
4629 int64_t i, type, size;
4640 layout = &SDDS_dataset->layout;
4641 fBuffer = &SDDS_dataset->fBuffer;
4644 if (SDDS_dataset->layout.gzipFile) {
4645 gzfp = layout->gzfp;
4646 for (i = 0; i < layout->n_columns; i++) {
4647 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
4649 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
4651 if (((
char ***)SDDS_dataset->data)[i][row])
4652 free((((
char ***)SDDS_dataset->data)[i][row]));
4653 if (!(((
char ***)SDDS_dataset->data)[i][row] = SDDS_ReadNonNativeGZipBinaryString(gzfp, fBuffer, 0))) {
4654 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4658 if (!SDDS_ReadNonNativeGZipBinaryString(gzfp, fBuffer, 1)) {
4659 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4665 if (!SDDS_GZipBufferedRead(skip ? NULL : (
char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
4666 SDDS_SetError(
"Unable to read row--failure reading value (SDDS_ReadNonNativeBinaryRow)");
4673 if (SDDS_dataset->layout.lzmaFile) {
4674 lzmafp = layout->lzmafp;
4675 for (i = 0; i < layout->n_columns; i++) {
4676 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
4678 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
4680 if (((
char ***)SDDS_dataset->data)[i][row])
4681 free((((
char ***)SDDS_dataset->data)[i][row]));
4683 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4688 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4694 if (!
SDDS_LZMABufferedRead(skip ? NULL : (
char *)SDDS_dataset->data[i] + row * size, size, lzmafp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
4695 SDDS_SetError(
"Unable to read row--failure reading value (SDDS_ReadNonNativeBinaryRow)");
4702 for (i = 0; i < layout->n_columns; i++) {
4703 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
4705 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
4707 if (((
char ***)SDDS_dataset->data)[i][row])
4708 free((((
char ***)SDDS_dataset->data)[i][row]));
4710 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4715 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4721 if (!
SDDS_BufferedRead(skip ? NULL : (
char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
4722 SDDS_SetError(
"Unable to read row--failure reading value (SDDS_ReadNonNativeBinaryRow)");
4760 if (!(
string =
SDDS_Malloc(
sizeof(*
string) * (length + 1))))
4794 if (!(
string =
SDDS_Malloc(
sizeof(*
string) * (length + 1))))
4820char *SDDS_ReadNonNativeGZipBinaryString(gzFile gzfp,
SDDS_FILEBUFFER *fBuffer, int32_t skip) {
4824 if (!SDDS_GZipBufferedRead(&length,
sizeof(length), gzfp, fBuffer,
SDDS_LONG, 0))
4829 if (!(
string =
SDDS_Malloc(
sizeof(*
string) * (length + 1))))
4831 if (length && !SDDS_GZipBufferedRead(skip ? NULL :
string,
sizeof(*
string) * length, gzfp, fBuffer,
SDDS_STRING, 0))
4869 int64_t i, rows, fixed_rows;
4870 int32_t min32 = INT32_MIN, rows32;
4878 if (!(fp = SDDS_dataset->layout.fp)) {
4879 SDDS_SetError(
"Unable to write page--file pointer is NULL (SDDS_WriteNonNativeBinaryPage)");
4882 fBuffer = &SDDS_dataset->fBuffer;
4884 if (!fBuffer->buffer) {
4885 if (!(fBuffer->buffer = fBuffer->data =
SDDS_Malloc(
sizeof(
char) * defaultIOBufferSize))) {
4886 SDDS_SetError(
"Unable to do buffered read--allocation failure (SDDS_WriteNonNativeBinaryPage)");
4889 fBuffer->bufferSize = defaultIOBufferSize;
4890 fBuffer->bytesLeft = defaultIOBufferSize;
4896 if (SDDS_dataset->layout.gzipFile) {
4897 if (!(gzfp = SDDS_dataset->layout.gzfp)) {
4898 SDDS_SetError(
"Unable to write page--file pointer is NULL (SDDS_WriteNonNativeBinaryPage)");
4901 SDDS_dataset->rowcount_offset = gztell(gzfp);
4902 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
4903 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
4904 if (fixed_rows > INT32_MAX) {
4905 if (!SDDS_GZipBufferedWrite(&min32,
sizeof(min32), gzfp, fBuffer)) {
4906 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
4910 if (!SDDS_GZipBufferedWrite(&fixed_rows,
sizeof(fixed_rows), gzfp, fBuffer)) {
4911 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
4916 rows32 = (int32_t)fixed_rows;
4918 if (!SDDS_GZipBufferedWrite(&rows32,
sizeof(rows32), gzfp, fBuffer)) {
4919 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
4924 if (rows > INT32_MAX) {
4925 if (!SDDS_GZipBufferedWrite(&min32,
sizeof(min32), gzfp, fBuffer)) {
4926 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
4930 if (!SDDS_GZipBufferedWrite(&rows,
sizeof(rows), gzfp, fBuffer)) {
4931 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
4936 rows32 = (int32_t)rows;
4938 if (!SDDS_GZipBufferedWrite(&rows32,
sizeof(rows32), gzfp, fBuffer)) {
4939 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
4946 if (SDDS_dataset->layout.lzmaFile) {
4947 if (!(lzmafp = SDDS_dataset->layout.lzmafp)) {
4948 SDDS_SetError(
"Unable to write page--file pointer is NULL (SDDS_WriteNonNativeBinaryPage)");
4951 SDDS_dataset->rowcount_offset = lzma_tell(lzmafp);
4952 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
4953 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
4954 if (fixed_rows > INT32_MAX) {
4956 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
4961 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
4966 rows32 = (int32_t)fixed_rows;
4969 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
4974 if (rows > INT32_MAX) {
4976 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
4981 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
4986 rows32 = (int32_t)rows;
4989 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
4995 SDDS_dataset->rowcount_offset = ftell(fp);
4996 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
4997 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
4998 if (fixed_rows > INT32_MAX) {
5000 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5005 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5010 rows32 = (int32_t)fixed_rows;
5013 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5018 if (rows > INT32_MAX) {
5020 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5025 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5030 rows32 = (int32_t)rows;
5033 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5043 SDDS_SetError(
"Unable to write page--parameter writing problem (SDDS_WriteNonNativeBinaryPage)");
5047 SDDS_SetError(
"Unable to write page--array writing problem (SDDS_WriteNonNativeBinaryPage)");
5051 if (SDDS_dataset->layout.n_columns) {
5052 if (SDDS_dataset->layout.data_mode.column_major) {
5054 SDDS_SetError(
"Unable to write page--column writing problem (SDDS_WriteNonNativeBinaryPage)");
5058 for (i = 0; i < SDDS_dataset->n_rows; i++) {
5059 if (SDDS_dataset->row_flag[i]) {
5061 SDDS_SetError(
"Unable to write page--row writing problem (SDDS_WriteNonNativeBinaryPage)");
5070 if (SDDS_dataset->layout.gzipFile) {
5071 if (!SDDS_GZipFlushBuffer(gzfp, fBuffer)) {
5072 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_WriteNonNativeBinaryPage)");
5077 if (SDDS_dataset->layout.lzmaFile) {
5079 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_WriteNonNativeBinaryPage)");
5084 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_WriteNonNativeBinaryPage)");
5091 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
5092 SDDS_dataset->n_rows_written = rows;
5093 SDDS_dataset->writing_page = 1;
5133 layout = &SDDS_dataset->layout;
5134 fBuffer = &SDDS_dataset->fBuffer;
5136 if (SDDS_dataset->layout.gzipFile) {
5137 if (!(gzfp = layout->gzfp)) {
5138 SDDS_SetError(
"Unable to write parameters--file pointer is NULL (SDDS_WriteNonNativeBinaryParameters)");
5141 for (i = 0; i < layout->n_parameters; i++) {
5142 if (layout->parameter_definition[i].fixed_value)
5144 if (layout->parameter_definition[i].type ==
SDDS_STRING) {
5145 if (!SDDS_GZipWriteNonNativeBinaryString(*((
char **)SDDS_dataset->parameter[i]), gzfp, fBuffer)) {
5146 SDDS_SetError(
"Unable to write parameters--failure writing string (SDDS_WriteNonNativeBinaryParameters)");
5150 }
else if (!SDDS_GZipBufferedWrite(SDDS_dataset->parameter[i],
SDDS_type_size[layout->parameter_definition[i].type - 1], gzfp, fBuffer)) {
5151 SDDS_SetError(
"Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
5158 if (SDDS_dataset->layout.lzmaFile) {
5159 if (!(lzmafp = layout->lzmafp)) {
5160 SDDS_SetError(
"Unable to write parameters--file pointer is NULL (SDDS_WriteNonNativeBinaryParameters)");
5163 for (i = 0; i < layout->n_parameters; i++) {
5164 if (layout->parameter_definition[i].fixed_value)
5166 if (layout->parameter_definition[i].type ==
SDDS_STRING) {
5168 SDDS_SetError(
"Unable to write parameters--failure writing string (SDDS_WriteNonNativeBinaryParameters)");
5173 SDDS_SetError(
"Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
5180 for (i = 0; i < layout->n_parameters; i++) {
5181 if (layout->parameter_definition[i].fixed_value)
5183 if (layout->parameter_definition[i].type ==
SDDS_STRING) {
5185 SDDS_SetError(
"Unable to write parameters--failure writing string (SDDS_WriteNonNativeBinaryParameters)");
5190 SDDS_SetError(
"Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
5227 int32_t i, j, dimension, zero = 0;
5239 layout = &SDDS_dataset->layout;
5240 fBuffer = &SDDS_dataset->fBuffer;
5242 if (SDDS_dataset->layout.gzipFile) {
5243 gzfp = layout->gzfp;
5244 for (i = 0; i < layout->n_arrays; i++) {
5245 if (!SDDS_dataset->array[i].dimension) {
5246 for (j = 0; j < layout->array_definition[i].dimensions; j++)
5247 if (!SDDS_GZipBufferedWrite(&zero,
sizeof(zero), gzfp, fBuffer)) {
5248 SDDS_SetError(
"Unable to write null array--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5255 for (j = 0; j < layout->array_definition[i].dimensions; j++) {
5256 dimension = SDDS_dataset->array[i].dimension[j];
5258 if (!SDDS_GZipBufferedWrite(&dimension,
sizeof(dimension), gzfp, fBuffer)) {
5259 SDDS_SetError(
"Unable to write arrays--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5264 if (layout->array_definition[i].type ==
SDDS_STRING) {
5265 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
5266 if (!SDDS_GZipWriteNonNativeBinaryString(((
char **)SDDS_dataset->array[i].data)[j], gzfp, fBuffer)) {
5267 SDDS_SetError(
"Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryArrays)");
5272 }
else if (!SDDS_GZipBufferedWrite(SDDS_dataset->array[i].data,
SDDS_type_size[layout->array_definition[i].type - 1] * SDDS_dataset->array[i].elements, gzfp, fBuffer)) {
5273 SDDS_SetError(
"Unable to write arrays--failure writing values (SDDS_WriteNonNativeBinaryArrays)");
5280 if (SDDS_dataset->layout.lzmaFile) {
5281 lzmafp = layout->lzmafp;
5282 for (i = 0; i < layout->n_arrays; i++) {
5283 if (!SDDS_dataset->array[i].dimension) {
5284 for (j = 0; j < layout->array_definition[i].dimensions; j++)
5286 SDDS_SetError(
"Unable to write null array--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5293 for (j = 0; j < layout->array_definition[i].dimensions; j++) {
5294 dimension = SDDS_dataset->array[i].dimension[j];
5297 SDDS_SetError(
"Unable to write arrays--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5302 if (layout->array_definition[i].type ==
SDDS_STRING) {
5303 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
5305 SDDS_SetError(
"Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryArrays)");
5311 SDDS_SetError(
"Unable to write arrays--failure writing values (SDDS_WriteNonNativeBinaryArrays)");
5318 for (i = 0; i < layout->n_arrays; i++) {
5319 if (!SDDS_dataset->array[i].dimension) {
5320 for (j = 0; j < layout->array_definition[i].dimensions; j++)
5322 SDDS_SetError(
"Unable to write null array--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5329 for (j = 0; j < layout->array_definition[i].dimensions; j++) {
5330 dimension = SDDS_dataset->array[i].dimension[j];
5333 SDDS_SetError(
"Unable to write arrays--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5338 if (layout->array_definition[i].type ==
SDDS_STRING) {
5339 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
5341 SDDS_SetError(
"Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryArrays)");
5346 }
else if (!
SDDS_BufferedWrite(SDDS_dataset->array[i].data,
SDDS_type_size[layout->array_definition[i].type - 1] * SDDS_dataset->array[i].elements, fp, fBuffer)) {
5347 SDDS_SetError(
"Unable to write arrays--failure writing values (SDDS_WriteNonNativeBinaryArrays)");
5382 int64_t i, type, size;
5393 layout = &SDDS_dataset->layout;
5394 fBuffer = &SDDS_dataset->fBuffer;
5396 if (SDDS_dataset->layout.gzipFile) {
5397 gzfp = layout->gzfp;
5398 for (i = 0; i < layout->n_columns; i++) {
5399 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
5400 if (!SDDS_GZipWriteNonNativeBinaryString(*((
char **)SDDS_dataset->data[i] + row), gzfp, fBuffer)) {
5401 SDDS_SetError(
"Unable to write rows--failure writing string (SDDS_WriteNonNativeBinaryRows)");
5406 if (!SDDS_GZipBufferedWrite((
char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer)) {
5407 SDDS_SetError(
"Unable to write row--failure writing value (SDDS_WriteNonNativeBinaryRow)");
5414 if (SDDS_dataset->layout.lzmaFile) {
5415 lzmafp = layout->lzmafp;
5416 for (i = 0; i < layout->n_columns; i++) {
5417 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
5419 SDDS_SetError(
"Unable to write rows--failure writing string (SDDS_WriteNonNativeBinaryRows)");
5425 SDDS_SetError(
"Unable to write row--failure writing value (SDDS_WriteNonNativeBinaryRow)");
5432 for (i = 0; i < layout->n_columns; i++) {
5433 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
5435 SDDS_SetError(
"Unable to write rows--failure writing string (SDDS_WriteNonNativeBinaryRows)");
5440 if (!
SDDS_BufferedWrite((
char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer)) {
5441 SDDS_SetError(
"Unable to write row--failure writing value (SDDS_WriteNonNativeBinaryRow)");
5475 static char *dummy_string =
"";
5477 string = dummy_string;
5478 length = strlen(
string);
5481 SDDS_SetError(
"Unable to write string--error writing length");
5486 SDDS_SetError(
"Unable to write string--error writing contents");
5514 static char *dummy_string =
"";
5516 string = dummy_string;
5517 length = strlen(
string);
5520 SDDS_SetError(
"Unable to write string--error writing length");
5525 SDDS_SetError(
"Unable to write string--error writing contents");
5552int32_t SDDS_GZipWriteNonNativeBinaryString(
char *
string, gzFile gzfp,
SDDS_FILEBUFFER *fBuffer) {
5554 static char *dummy_string =
"";
5556 string = dummy_string;
5557 length = strlen(
string);
5559 if (!SDDS_GZipBufferedWrite(&length,
sizeof(length), gzfp, fBuffer)) {
5560 SDDS_SetError(
"Unable to write string--error writing length");
5564 if (length && !SDDS_GZipBufferedWrite(
string,
sizeof(*
string) * length, gzfp, fBuffer)) {
5565 SDDS_SetError(
"Unable to write string--error writing contents");
5595 int32_t code, min32 = INT32_MIN, rows32;
5596 int64_t i, rows, offset, fixed_rows;
5602 if (SDDS_dataset->layout.gzipFile) {
5603 SDDS_SetError(
"Unable to perform page updates on a gzip file (SDDS_UpdateNonNativeBinaryPage)");
5607 if (SDDS_dataset->layout.lzmaFile) {
5608 SDDS_SetError(
"Unable to perform page updates on .lzma or .xz files (SDDS_UpdateNonNativeBinaryPage)");
5611 if (SDDS_dataset->layout.data_mode.column_major) {
5612 SDDS_SetError(
"Unable to perform page updates on a column major order file (SDDS_UpdateNonNativeBinaryPage)");
5615 if (!SDDS_dataset->writing_page) {
5617 fprintf(stderr,
"Page not being written---calling SDDS_UpdateNonNativeBinaryPage\n");
5622 if (mode & FLUSH_TABLE) {
5625 SDDS_dataset->last_row_written = -1;
5626 SDDS_dataset->n_rows = 0;
5631 if (!(fp = SDDS_dataset->layout.fp)) {
5632 SDDS_SetError(
"Unable to update page--file pointer is NULL (SDDS_UpdateNonNativeBinaryPage)");
5635 fBuffer = &SDDS_dataset->fBuffer;
5637 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_UpdateNonNativeBinaryPage)");
5644 fprintf(stderr,
"%" PRId64
" rows stored in table, %" PRId32
" already written\n", rows, SDDS_dataset->n_rows_written);
5646 if (rows == SDDS_dataset->n_rows_written) {
5649 if (rows < SDDS_dataset->n_rows_written) {
5650 SDDS_SetError(
"Unable to update page--new number of rows less than previous number (SDDS_UpdateNonNativeBinaryPage)");
5654 if ((!SDDS_dataset->layout.data_mode.fixed_row_count) || (((rows + rows - SDDS_dataset->n_rows_written / SDDS_dataset->layout.data_mode.fixed_row_increment)) != (rows / SDDS_dataset->layout.data_mode.fixed_row_increment))) {
5655 if (
SDDS_fseek(fp, SDDS_dataset->rowcount_offset, 0) == -1) {
5656 SDDS_SetError(
"Unable to update page--failure doing fseek (SDDS_UpdateNonNativeBinaryPage)");
5659 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
5660 if ((rows - SDDS_dataset->n_rows_written) + 1 > SDDS_dataset->layout.data_mode.fixed_row_increment) {
5661 SDDS_dataset->layout.data_mode.fixed_row_increment = (rows - SDDS_dataset->n_rows_written) + 1;
5663 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
5665 fprintf(stderr,
"Setting %" PRId64
" fixed rows\n", fixed_rows);
5667 if ((fixed_rows > INT32_MAX) && (SDDS_dataset->n_rows_written <= INT32_MAX)) {
5668 SDDS_SetError(
"Unable to update page--crossed the INT32_MAX row boundary (SDDS_UpdateNonNativeBinaryPage)");
5671 if (fixed_rows > INT32_MAX) {
5672 if (fwrite(&min32,
sizeof(min32), 1, fp) != 1) {
5673 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
5677 if (fwrite(&fixed_rows,
sizeof(fixed_rows), 1, fp) != 1) {
5678 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateNonNativeBinaryPage)");
5683 rows32 = (int32_t)fixed_rows;
5685 if (fwrite(&rows32,
sizeof(rows32), 1, fp) != 1) {
5686 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateNonNativeBinaryPage)");
5692 fprintf(stderr,
"Setting %" PRId64
" rows\n", rows);
5694 if ((rows > INT32_MAX) && (SDDS_dataset->n_rows_written <= INT32_MAX)) {
5695 SDDS_SetError(
"Unable to update page--crossed the INT32_MAX row boundary (SDDS_UpdateNonNativeBinaryPage)");
5698 if (rows > INT32_MAX) {
5699 if (fwrite(&min32,
sizeof(min32), 1, fp) != 1) {
5700 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
5704 if (fwrite(&rows,
sizeof(rows), 1, fp) != 1) {
5705 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateNonNativeBinaryPage)");
5710 rows32 = (int32_t)rows;
5712 if (fwrite(&rows32,
sizeof(rows32), 1, fp) != 1) {
5713 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateNonNativeBinaryPage)");
5719 SDDS_SetError(
"Unable to update page--failure doing fseek to end of page (SDDS_UpdateNonNativeBinaryPage)");
5724 for (i = SDDS_dataset->last_row_written + 1; i < SDDS_dataset->n_rows; i++) {
5726 SDDS_SetError(
"Unable to update page--failure writing row (SDDS_UpdateNonNativeBinaryPage)");
5732 fprintf(stderr,
"Flushing buffer\n");
5735 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_UpdateNonNativeBinaryPage)");
5738 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
5739 SDDS_dataset->n_rows_written = rows;
5740 if (mode & FLUSH_TABLE) {
5742 SDDS_dataset->first_row_in_mem = rows;
5743 SDDS_dataset->last_row_written = -1;
5744 SDDS_dataset->n_rows = 0;
5771 unsigned char d[8] = {0};
5774 if (byteOrder == SDDS_BIGENDIAN_SEEN) {
5778 for (i = 0; i < 6; i++) {
5780 x[0 + i] = x[11 - i];
5785 exponent = (((x[9] << 8) | x[8]) & 0x7FFF);
5787 ((uint64_t)x[7] << 56) | ((uint64_t)x[6] << 48) | ((uint64_t)x[5] << 40) | ((uint64_t)x[4] << 32) |
5788 ((uint64_t)x[3] << 24) | ((uint64_t)x[2] << 16) | ((uint64_t)x[1] << 8) | (uint64_t)x[0];
5792 if ((exponent == 0x7FFF) || (exponent == 0)) {
5794 if (exponent == 0x7FFF) {
5800 memcpy(&result, d, 8);
5805 exponent = exponent - 0x3FFF + 0x03FF;
5807 if (exponent <= -52)
5809 memcpy(&result, d, 8);
5811 }
else if (exponent < 0) {
5813 }
else if (exponent >= 0x7FF)
5818 memcpy(&result, d, 8);
5822 d[7] |= (exponent & 0x7F0) >> 4;
5823 d[6] |= (exponent & 0xF) << 4;
5832 mantissa >>= (-exponent + 1);
5835 d[0] = mantissa & 0xFF;
5836 d[1] = (mantissa >> 8) & 0xFF;
5837 d[2] = (mantissa >> 16) & 0xFF;
5838 d[3] = (mantissa >> 24) & 0xFF;
5839 d[4] = (mantissa >> 32) & 0xFF;
5840 d[5] = (mantissa >> 40) & 0xFF;
5841 d[6] |= (mantissa >> 48) & 0x0F;
5843 memcpy(&result, d, 8);
5845 if (byteOrder == SDDS_BIGENDIAN_SEEN) {
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_ReadAsciiPageLastRows(SDDS_DATASET *SDDS_dataset, int64_t last_rows)
Reads the last specified number of rows from an ASCII page of an SDDS dataset.
int32_t SDDS_ScanData(char *string, int32_t type, int32_t field_length, void *data, int64_t index, int32_t is_parameter)
Scans a string and saves the parsed value into a data pointer according to the specified data type.
int32_t SDDS_ReadAsciiPage(SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset, int32_t sparse_statistics)
Reads the next SDDS ASCII page into memory with optional data sparsity and statistics.
void SDDS_SwapLongDouble(long double *data)
Swaps the endianness of a long double.
int32_t SDDS_SwapEndsColumnData(SDDS_DATASET *SDDSin)
Swaps the endianness of the column data in an SDDS dataset.
int32_t SDDS_ReadNewBinaryRows(SDDS_DATASET *SDDS_dataset)
Reads new binary rows from the SDDS dataset.
int32_t SDDS_ReadNonNativeBinaryPage(SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset)
Reads a non-native endian binary page from an SDDS dataset.
char * SDDS_ReadNonNativeLZMABinaryString(struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer, int32_t skip)
Reads a non-native endian binary string from an LZMA-compressed file.
int32_t SDDS_SetDefaultIOBufferSize(int32_t newValue)
int32_t SDDS_WriteNonNativeBinaryPage(SDDS_DATASET *SDDS_dataset)
Writes a non-native endian binary page to an SDDS dataset.
int32_t SDDS_WriteNonNativeBinaryRow(SDDS_DATASET *SDDS_dataset, int64_t row)
Writes a non-native endian binary row to an SDDS dataset.
int32_t SDDS_ReadNonNativeBinaryPageDetailed(SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset, int64_t last_rows)
Reads a detailed non-native endian binary page from an SDDS dataset.
void SDDS_SwapLong64(int64_t *data)
Swaps the endianness of a 64-bit integer.
int32_t SDDS_ReadNonNativePage(SDDS_DATASET *SDDS_dataset)
Reads a non-native endian page from an SDDS dataset.
int32_t SDDS_UpdateNonNativeBinaryPage(SDDS_DATASET *SDDS_dataset, uint32_t mode)
Updates a non-native endian binary page in an SDDS dataset.
int32_t SDDS_WriteBinaryColumns(SDDS_DATASET *SDDS_dataset)
Writes the binary columns of an SDDS dataset to the associated file.
int32_t SDDS_LZMABufferedRead(void *target, int64_t targetSize, struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer, int32_t type, int32_t byteOrder)
int32_t SDDS_WriteBinaryRow(SDDS_DATASET *SDDS_dataset, int64_t row)
Writes a single binary row of an SDDS dataset to the associated file.
int32_t SDDS_WriteBinaryArrays(SDDS_DATASET *SDDS_dataset)
Writes the binary arrays of the SDDS dataset to a file.
int32_t SDDS_ReadBinaryRow(SDDS_DATASET *SDDS_dataset, int64_t row, int32_t skip)
Reads a binary row from the specified SDDS dataset.
int32_t SDDS_WriteNonNativeBinaryString(char *string, FILE *fp, SDDS_FILEBUFFER *fBuffer)
Writes a non-native endian binary string to a file.
int32_t SDDS_WriteNonNativeBinaryArrays(SDDS_DATASET *SDDS_dataset)
Writes non-native endian binary arrays to an SDDS dataset.
void SDDS_SwapULong64(uint64_t *data)
Swaps the endianness of a 64-bit unsigned integer.
int32_t SDDS_ReadNonNativeBinaryPageLastRows(SDDS_DATASET *SDDS_dataset, int64_t last_rows)
Reads the last few rows from a non-native endian binary page in an SDDS dataset.
char * SDDS_ReadBinaryString(FILE *fp, SDDS_FILEBUFFER *fBuffer, int32_t skip)
Reads a binary string from a file with buffering.
int32_t SDDS_BufferedWrite(void *target, int64_t targetSize, FILE *fp, SDDS_FILEBUFFER *fBuffer)
void SDDS_SwapULong(uint32_t *data)
Swaps the endianness of a 32-bit unsigned integer.
int32_t SDDS_LZMAWriteBinaryString(char *string, struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer)
Writes a binary string to a file with LZMA compression.
int32_t SDDS_WriteBinaryString(char *string, FILE *fp, SDDS_FILEBUFFER *fBuffer)
Writes a binary string to a file with buffering.
void SDDS_SwapUShort(unsigned short *data)
Swaps the endianness of an unsigned short integer.
int32_t SDDS_ReadNonNativePageSparse(SDDS_DATASET *SDDS_dataset, uint32_t mode, int64_t sparse_interval, int64_t sparse_offset)
Reads a sparse non-native endian page from an SDDS dataset.
int32_t SDDS_ReadBinaryPageDetailed(SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset, int64_t last_rows, int32_t sparse_statistics)
Reads a binary page from an SDDS dataset with detailed options.
int32_t SDDS_BufferedRead(void *target, int64_t targetSize, FILE *fp, SDDS_FILEBUFFER *fBuffer, int32_t type, int32_t byteOrder)
int32_t SDDS_UpdateBinaryPage(SDDS_DATASET *SDDS_dataset, uint32_t mode)
Updates the binary page of an SDDS dataset.
int32_t SDDS_ReadNonNativeBinaryColumns(SDDS_DATASET *SDDS_dataset)
Reads the non-native endian binary columns from an SDDS dataset.
void SDDS_SetReadRecoveryMode(SDDS_DATASET *SDDS_dataset, int32_t mode)
Sets the read recovery mode for an SDDS dataset.
int32_t SDDS_ReadRecoveryPossible(SDDS_DATASET *SDDS_dataset)
Checks if any data in an SDDS page was recovered after an error was detected.
double makeFloat64FromFloat80(unsigned char x[16], int32_t byteOrder)
Converts a 16-byte array representing a float80 value to a double.
int32_t SDDS_FlushBuffer(FILE *fp, SDDS_FILEBUFFER *fBuffer)
int32_t SDDS_ReadNonNativeBinaryRow(SDDS_DATASET *SDDS_dataset, int64_t row, int32_t skip)
Reads a non-native endian binary row from an SDDS dataset.
int32_t SDDS_WriteBinaryParameters(SDDS_DATASET *SDDS_dataset)
Writes the binary parameters of the SDDS dataset.
int32_t SDDS_SwapEndsArrayData(SDDS_DATASET *SDDSin)
Swaps the endianness of the array data in an SDDS dataset.
int32_t SDDS_ReadNonNativePageLastRows(SDDS_DATASET *SDDS_dataset, int64_t last_rows)
Reads the last few rows from a non-native endian page in an SDDS dataset.
int32_t SDDS_ReadBinaryPage(SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset, int32_t sparse_statistics)
Reads a binary page from an SDDS dataset.
int32_t SDDS_SwapEndsParameterData(SDDS_DATASET *SDDSin)
Swaps the endianness of the parameter data in an SDDS dataset.
int32_t SDDS_ReadNonNativeBinaryParameters(SDDS_DATASET *SDDS_dataset)
Reads non-native endian binary parameters from an SDDS dataset.
int32_t SDDS_ReadBinaryColumns(SDDS_DATASET *SDDS_dataset)
Reads the binary columns from an SDDS dataset.
void SDDS_SwapLong(int32_t *data)
Swaps the endianness of a 32-bit integer.
int32_t SDDS_ReadNonNativeBinaryArrays(SDDS_DATASET *SDDS_dataset)
Reads non-native endian binary arrays from an SDDS dataset.
void SDDS_SwapDouble(double *data)
Swaps the endianness of a double.
int32_t SDDS_WriteBinaryPage(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_fseek(FILE *fp, int64_t offset, int32_t dir)
Sets the file position indicator for a given file stream with retry logic.
int32_t SDDS_WriteNonNativeBinaryColumns(SDDS_DATASET *SDDS_dataset)
Writes non-native endian binary columns of an SDDS dataset to the associated file.
int32_t SDDS_WriteNonNativeBinaryParameters(SDDS_DATASET *SDDS_dataset)
Writes non-native endian binary parameters to an SDDS dataset.
void SDDS_SwapShort(short *data)
Swaps the endianness of a short integer.
int32_t SDDS_lzmaseek(struct lzmafile *lzmafp, int64_t offset, int32_t dir)
Sets the file position indicator for a given LZMA file stream with retry logic.
char * SDDS_ReadNonNativeBinaryString(FILE *fp, SDDS_FILEBUFFER *fBuffer, int32_t skip)
Reads a non-native endian binary string from a file.
int32_t SDDS_ReadNonNativePageDetailed(SDDS_DATASET *SDDS_dataset, uint32_t mode, int64_t sparse_interval, int64_t sparse_offset, int64_t last_rows)
Reads a detailed non-native endian page from an SDDS dataset.
int32_t SDDS_LZMAFlushBuffer(struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer)
void SDDS_SwapFloat(float *data)
Swaps the endianness of a float.
int32_t SDDS_ReadBinaryArrays(SDDS_DATASET *SDDS_dataset)
Reads binary arrays from an SDDS dataset.
int32_t SDDS_LZMABufferedWrite(void *target, int64_t targetSize, struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer)
int32_t SDDS_LZMAWriteNonNativeBinaryString(char *string, struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer)
Writes a non-native endian binary string to an LZMA-compressed file.
int32_t SDDS_ReadBinaryPageLastRows(SDDS_DATASET *SDDS_dataset, int64_t last_rows)
Reads the last specified number of rows from a binary page of an SDDS dataset.
char * SDDS_ReadLZMABinaryString(struct lzmafile *lzmafp, SDDS_FILEBUFFER *fBuffer, int32_t skip)
Reads a binary string from an LZMA-compressed file with buffering.
int32_t SDDS_ReadBinaryParameters(SDDS_DATASET *SDDS_dataset)
Reads binary parameters from the specified SDDS dataset.
int32_t SDDS_type_size[SDDS_NUM_TYPES]
Array of sizes for each supported data type.
int32_t SDDS_LengthenTable(SDDS_DATASET *SDDS_dataset, int64_t n_additional_rows)
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
Internal definitions and function declarations for SDDS with LZMA support.
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
int32_t SDDS_FreeArrayDefinition(ARRAY_DEFINITION *source)
Frees memory allocated for an array definition.
int32_t SDDS_CheckDataset(SDDS_DATASET *SDDS_dataset, const char *caller)
Validates the SDDS dataset pointer.
void * SDDS_Malloc(size_t size)
Allocates memory of a specified size.
void SDDS_ClearErrors()
Clears all recorded error messages from the SDDS error stack.
ARRAY_DEFINITION * SDDS_CopyArrayDefinition(ARRAY_DEFINITION **target, ARRAY_DEFINITION *source)
Creates a copy of an array definition.
int32_t SDDS_IsBigEndianMachine()
Determines whether the current machine uses big-endian byte ordering.
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
#define SDDS_FLOAT
Identifier for the float data type.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_ULONG64
Identifier for the unsigned 64-bit integer data type.
#define SDDS_FLOATING_TYPE(type)
Checks if the given type identifier corresponds to a floating-point type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_SHORT
Identifier for the signed short integer data type.
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
#define SDDS_DOUBLE
Identifier for the double data type.
#define SDDS_LONGDOUBLE
Identifier for the long double data type.
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.