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 && sparse_statistics != 0) {
2337 SDDS_SetError(
"sparse_statistics is not yet supported for column-major layout. Use sddsconvert -majorOrder=row to convert first.\n");
2342 sparse_interval = 1;
2343 sparse_offset = n_rows - last_rows;
2345 if (sparse_interval <= 0)
2346 sparse_interval = 1;
2347 if (sparse_offset < 0)
2350 rows_to_store = (n_rows - sparse_offset) / sparse_interval + 2;
2351 alloc_rows = rows_to_store - SDDS_dataset->n_rows_allocated;
2354 SDDS_SetError(
"Unable to read page--couldn't start page (SDDS_ReadBinaryPageDetailed)");
2360 SDDS_SetError(
"Unable to read page--parameter reading error (SDDS_ReadBinaryPageDetailed)");
2366 SDDS_SetError(
"Unable to read page--array reading error (SDDS_ReadBinaryPageDetailed)");
2369 if (SDDS_dataset->layout.data_mode.column_major) {
2370 SDDS_dataset->n_rows = n_rows;
2372 SDDS_SetError(
"Unable to read page--column reading error (SDDS_ReadBinaryPageDetailed)");
2375 return (SDDS_dataset->page_number);
2377 if ((sparse_interval <= 1) && (sparse_offset == 0)) {
2378 for (j = 0; j < n_rows; j++) {
2380 SDDS_dataset->n_rows = j;
2381 if (SDDS_dataset->autoRecover) {
2383 fprintf(stderr,
"Doing auto-read recovery\n");
2385 SDDS_dataset->autoRecovered = 1;
2387 return (SDDS_dataset->page_number);
2389 SDDS_SetError(
"Unable to read page--error reading data row (SDDS_ReadBinaryPageDetailed)");
2394 SDDS_dataset->n_rows = j;
2395 return (SDDS_dataset->page_number);
2397 for (j = 0; j < sparse_offset; j++) {
2399 SDDS_dataset->n_rows = 0;
2400 if (SDDS_dataset->autoRecover) {
2401 SDDS_dataset->autoRecovered = 1;
2403 return (SDDS_dataset->page_number);
2405 SDDS_SetError(
"Unable to read page--error reading data row (SDDS_ReadBinaryPageDetailed)");
2410 n_rows -= sparse_offset;
2411 if (sparse_statistics != 0) {
2413 statData = (
void**)malloc(SDDS_dataset->layout.n_columns *
sizeof(
void*));
2414 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2417 statData[i] = (
double*)calloc(sparse_interval,
sizeof(
double));
2420 for (j = k = 0; j < n_rows; j++) {
2422 SDDS_dataset->n_rows = k;
2423 if (SDDS_dataset->autoRecover) {
2424 SDDS_dataset->autoRecovered = 1;
2426 return (SDDS_dataset->page_number);
2428 SDDS_SetError(
"Unable to read page--error reading data row (SDDS_ReadBinaryPageDetailed)");
2432 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2433 switch (SDDS_dataset->layout.column_definition[i].type) {
2435 ((
double*)statData[i])[j % sparse_interval] = (double)(((
float*)SDDS_dataset->data[i])[k]);
2438 ((
double*)statData[i])[j % sparse_interval] = ((
double*)SDDS_dataset->data[i])[k];
2441 ((
double*)statData[i])[j % sparse_interval] = (double)(((
long double*)SDDS_dataset->data[i])[k]);
2445 if (sparse_statistics == 1) {
2447 compute_average(&statResult, (
double*)statData[i], (j % sparse_interval) + 1);
2448 }
else if (sparse_statistics == 2) {
2450 compute_median(&statResult, (
double*)statData[i], (j % sparse_interval) + 1);
2451 }
else if (sparse_statistics == 3) {
2453 statResult =
min_in_array((
double*)statData[i], (j % sparse_interval) + 1);
2454 }
else if (sparse_statistics == 4) {
2456 statResult =
max_in_array((
double*)statData[i], (j % sparse_interval) + 1);
2459 switch (SDDS_dataset->layout.column_definition[i].type) {
2461 ((
float*)SDDS_dataset->data[i])[k] = statResult;
2464 ((
double*)SDDS_dataset->data[i])[k] = statResult;
2467 ((
long double*)SDDS_dataset->data[i])[k] = statResult;
2471 if (j % sparse_interval == sparse_interval - 1) {
2475 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
2482 for (j = k = 0; j < n_rows; j++) {
2484 SDDS_dataset->n_rows = k;
2485 if (SDDS_dataset->autoRecover) {
2486 SDDS_dataset->autoRecovered = 1;
2488 return (SDDS_dataset->page_number);
2490 SDDS_SetError(
"Unable to read page--error reading data row (SDDS_ReadBinaryPageDetailed)");
2497 SDDS_dataset->n_rows = k;
2498 return (SDDS_dataset->page_number);
2519 static char *dummy_string =
"";
2521 string = dummy_string;
2522 length = strlen(
string);
2524 SDDS_SetError(
"Unable to write string--error writing length");
2528 SDDS_SetError(
"Unable to write string--error writing contents");
2551 static char *dummy_string =
"";
2553 string = dummy_string;
2554 length = strlen(
string);
2556 SDDS_SetError(
"Unable to write string--error writing length");
2560 SDDS_SetError(
"Unable to write string--error writing contents");
2582int32_t SDDS_GZipWriteBinaryString(
char *
string, gzFile gzfp,
SDDS_FILEBUFFER *fBuffer) {
2584 static char *dummy_string =
"";
2586 string = dummy_string;
2587 length = strlen(
string);
2588 if (!SDDS_GZipBufferedWrite(&length,
sizeof(length), gzfp, fBuffer)) {
2589 SDDS_SetError(
"Unable to write string--error writing length");
2592 if (length && !SDDS_GZipBufferedWrite(
string,
sizeof(*
string) * length, gzfp, fBuffer)) {
2593 SDDS_SetError(
"Unable to write string--error writing contents");
2622 if (!(
string =
SDDS_Malloc(
sizeof(*
string) * (length + 1))))
2652 if (!(
string =
SDDS_Malloc(
sizeof(*
string) * (length + 1))))
2677char *SDDS_ReadGZipBinaryString(gzFile gzfp,
SDDS_FILEBUFFER *fBuffer, int32_t skip) {
2681 if (!SDDS_GZipBufferedRead(&length,
sizeof(length), gzfp, fBuffer,
SDDS_LONG, 0) || length < 0)
2683 if (!(
string =
SDDS_Malloc(
sizeof(*
string) * (length + 1))))
2685 if (length && !SDDS_GZipBufferedRead(skip ? NULL :
string,
sizeof(*
string) * length, gzfp, fBuffer,
SDDS_STRING, 0))
2712 int64_t i, type, size;
2723 layout = &SDDS_dataset->layout;
2724 fBuffer = &SDDS_dataset->fBuffer;
2727 if (SDDS_dataset->layout.gzipFile) {
2728 gzfp = layout->gzfp;
2729 for (i = 0; i < layout->n_columns; i++) {
2730 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
2732 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
2734 if (((
char ***)SDDS_dataset->data)[i][row])
2735 free((((
char ***)SDDS_dataset->data)[i][row]));
2736 if (!(((
char ***)SDDS_dataset->data)[i][row] = SDDS_ReadGZipBinaryString(gzfp, fBuffer, 0))) {
2737 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2741 if (!SDDS_ReadGZipBinaryString(gzfp, fBuffer, 1)) {
2742 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2748 if (!SDDS_GZipBufferedRead(skip ? NULL : (
char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
2749 SDDS_SetError(
"Unable to read row--failure reading value (SDDS_ReadBinaryRow)");
2756 if (SDDS_dataset->layout.lzmaFile) {
2757 lzmafp = layout->lzmafp;
2758 for (i = 0; i < layout->n_columns; i++) {
2759 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
2761 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
2763 if (((
char ***)SDDS_dataset->data)[i][row])
2764 free((((
char ***)SDDS_dataset->data)[i][row]));
2766 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2771 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2777 if (!
SDDS_LZMABufferedRead(skip ? NULL : (
char *)SDDS_dataset->data[i] + row * size, size, lzmafp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
2778 SDDS_SetError(
"Unable to read row--failure reading value (SDDS_ReadBinaryRow)");
2785 for (i = 0; i < layout->n_columns; i++) {
2786 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
2788 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
2790 if (((
char ***)SDDS_dataset->data)[i][row])
2791 free((((
char ***)SDDS_dataset->data)[i][row]));
2793 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2798 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadBinaryRows)");
2804 if (!
SDDS_BufferedRead(skip ? NULL : (
char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
2805 SDDS_SetError(
"Unable to read row--failure reading value (SDDS_ReadBinaryRow)");
2838 int64_t row, offset, newRows = 0;
2839 int32_t rowsPresent32;
2840 int64_t rowsPresent;
2843 if (SDDS_dataset->parallel_io) {
2844 SDDS_SetError(
"Error: MPI mode not supported yet in SDDS_ReadNewBinaryRows");
2848 if (SDDS_dataset->original_layout.data_mode.mode == SDDS_ASCII) {
2849 SDDS_SetError(
"Error: ASCII files not supported in SDDS_ReadNewBinaryRows");
2852 if (SDDS_dataset->layout.data_mode.column_major) {
2853 SDDS_SetError(
"Error: column-major order binary files not supported in SDDS_ReadNewBinaryRows");
2856 if (SDDS_dataset->swapByteOrder) {
2857 SDDS_SetError(
"Error: Non-native endian not supported yet in SDDS_ReadNewBinaryRows");
2861 if (SDDS_dataset->layout.gzipFile) {
2862 SDDS_SetError(
"Error: gzip compressed files not supported yet in SDDS_ReadNewBinaryRows");
2866 if (SDDS_dataset->layout.lzmaFile) {
2867 SDDS_SetError(
"Error: lzma compressed files not supported yet in SDDS_ReadNewBinaryRows");
2875 offset = ftell(SDDS_dataset->layout.fp);
2876 fseek(SDDS_dataset->layout.fp, SDDS_dataset->rowcount_offset, 0);
2877 if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY) {
2878 fread(&rowsPresent32,
sizeof(rowsPresent32), 1, SDDS_dataset->layout.fp);
2879 if (SDDS_dataset->swapByteOrder) {
2882 if (rowsPresent32 == INT32_MIN) {
2883 fread(&rowsPresent,
sizeof(rowsPresent), 1, SDDS_dataset->layout.fp);
2884 if (SDDS_dataset->swapByteOrder) {
2888 rowsPresent = rowsPresent32;
2892 if (!fgets(buffer, 30, SDDS_dataset->layout.fp) || strlen(buffer) != 21 || sscanf(buffer,
"%" SCNd64, &rowsPresent) != 1) {
2893 SDDS_SetError(
"Error: row count not present or not correct length");
2897 fseek(SDDS_dataset->layout.fp, offset, 0);
2900 if (rowsPresent > SDDS_dataset->n_rows_allocated) {
2906 for (row = SDDS_dataset->n_rows; row < rowsPresent; row++) {
2908 if (SDDS_dataset->autoRecover) {
2910 SDDS_dataset->autoRecovered = 1;
2914 SDDS_SetError(
"Unable to read page--error reading data row");
2918 newRows = row + 1 - SDDS_dataset->n_rows;
2919 SDDS_dataset->n_rows = row + 1;
2945 char buffer[SDDS_MAXLINE];
2955 layout = &SDDS_dataset->layout;
2956 if (!layout->n_parameters)
2959 if (SDDS_dataset->layout.gzipFile) {
2960 gzfp = layout->gzfp;
2963 if (SDDS_dataset->layout.lzmaFile) {
2964 lzmafp = layout->lzmafp;
2971 fBuffer = &SDDS_dataset->fBuffer;
2972 for (i = 0; i < layout->n_parameters; i++) {
2973 if (layout->parameter_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
2975 if (layout->parameter_definition[i].fixed_value) {
2976 strcpy(buffer, layout->parameter_definition[i].fixed_value);
2977 if (!
SDDS_ScanData(buffer, layout->parameter_definition[i].type, 0, SDDS_dataset->parameter[i], 0, 1)) {
2978 SDDS_SetError(
"Unable to read page--parameter scanning error (SDDS_ReadBinaryParameters)");
2981 }
else if (layout->parameter_definition[i].type ==
SDDS_STRING) {
2982 if (*(
char **)SDDS_dataset->parameter[i])
2983 free(*(
char **)SDDS_dataset->parameter[i]);
2985 if (SDDS_dataset->layout.gzipFile) {
2986 if (!(*((
char **)SDDS_dataset->parameter[i]) = SDDS_ReadGZipBinaryString(gzfp, fBuffer, 0))) {
2987 SDDS_SetError(
"Unable to read parameters--failure reading string (SDDS_ReadBinaryParameters)");
2992 if (SDDS_dataset->layout.lzmaFile) {
2994 SDDS_SetError(
"Unable to read parameters--failure reading string (SDDS_ReadBinaryParameters)");
2999 SDDS_SetError(
"Unable to read parameters--failure reading string (SDDS_ReadBinaryParameters)");
3008 if (SDDS_dataset->layout.gzipFile) {
3009 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)) {
3010 SDDS_SetError(
"Unable to read parameters--failure reading value (SDDS_ReadBinaryParameters)");
3015 if (SDDS_dataset->layout.lzmaFile) {
3016 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)) {
3017 SDDS_SetError(
"Unable to read parameters--failure reading value (SDDS_ReadBinaryParameters)");
3021 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)) {
3022 SDDS_SetError(
"Unable to read parameters--failure reading value (SDDS_ReadBinaryParameters)");
3068 layout = &SDDS_dataset->layout;
3069 if (!layout->n_arrays)
3072 if (SDDS_dataset->layout.gzipFile) {
3073 gzfp = layout->gzfp;
3076 if (SDDS_dataset->layout.lzmaFile) {
3077 lzmafp = layout->lzmafp;
3084 fBuffer = &SDDS_dataset->fBuffer;
3085 if (!SDDS_dataset->array) {
3086 SDDS_SetError(
"Unable to read array--pointer to structure storage area is NULL (SDDS_ReadBinaryArrays)");
3089 for (i = 0; i < layout->n_arrays; i++) {
3090 array = SDDS_dataset->array + i;
3092 SDDS_SetError(
"Unable to get array--array definition corrupted (SDDS_ReadBinaryArrays)");
3096 SDDS_SetError(
"Unable to read array--definition copy failed (SDDS_ReadBinaryArrays)");
3100 if (!(array->dimension =
SDDS_Realloc(array->dimension,
sizeof(*array->dimension) * array->definition->dimensions))) {
3101 SDDS_SetError(
"Unable to read array--allocation failure (SDDS_ReadBinaryArrays)");
3105 if (SDDS_dataset->layout.gzipFile) {
3106 if (!SDDS_GZipBufferedRead(array->dimension,
sizeof(*array->dimension) * array->definition->dimensions, gzfp, fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
3107 SDDS_SetError(
"Unable to read arrays--failure reading dimensions (SDDS_ReadBinaryArrays)");
3112 if (SDDS_dataset->layout.lzmaFile) {
3113 if (!
SDDS_LZMABufferedRead(array->dimension,
sizeof(*array->dimension) * array->definition->dimensions, lzmafp, fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
3114 SDDS_SetError(
"Unable to read arrays--failure reading dimensions (SDDS_ReadBinaryArrays)");
3118 if (!
SDDS_BufferedRead(array->dimension,
sizeof(*array->dimension) * array->definition->dimensions, fp, fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
3119 SDDS_SetError(
"Unable to read arrays--failure reading dimensions (SDDS_ReadBinaryArrays)");
3126 array->elements = 1;
3127 for (j = 0; j < array->definition->dimensions; j++)
3128 array->elements *= array->dimension[j];
3131 array->data = array->pointer = NULL;
3132 if (array->elements == 0)
3134 if (array->elements < 0) {
3135 SDDS_SetError(
"Unable to read array--number of elements is negative (SDDS_ReadBinaryArrays)");
3139 SDDS_SetError(
"Unable to read array--allocation failure (SDDS_ReadBinaryArrays)");
3144 if (SDDS_dataset->layout.gzipFile) {
3145 for (j = 0; j < array->elements; j++) {
3146 if (!(((
char **)(array->data))[j] = SDDS_ReadGZipBinaryString(gzfp, fBuffer, 0))) {
3147 SDDS_SetError(
"Unable to read arrays--failure reading string (SDDS_ReadBinaryArrays)");
3153 if (SDDS_dataset->layout.lzmaFile) {
3154 for (j = 0; j < array->elements; j++) {
3156 SDDS_SetError(
"Unable to read arrays--failure reading string (SDDS_ReadBinaryArrays)");
3161 for (j = 0; j < array->elements; j++) {
3163 SDDS_SetError(
"Unable to read arrays--failure reading string (SDDS_ReadBinaryArrays)");
3173 if (SDDS_dataset->layout.gzipFile) {
3174 if (!SDDS_GZipBufferedRead(array->data,
SDDS_type_size[array->definition->type - 1] * array->elements, gzfp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
3175 SDDS_SetError(
"Unable to read arrays--failure reading values (SDDS_ReadBinaryArrays)");
3180 if (SDDS_dataset->layout.lzmaFile) {
3181 if (!
SDDS_LZMABufferedRead(array->data,
SDDS_type_size[array->definition->type - 1] * array->elements, lzmafp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
3182 SDDS_SetError(
"Unable to read arrays--failure reading values (SDDS_ReadBinaryArrays)");
3186 if (!
SDDS_BufferedRead(array->data,
SDDS_type_size[array->definition->type - 1] * array->elements, fp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
3187 SDDS_SetError(
"Unable to read arrays--failure reading values (SDDS_ReadBinaryArrays)");
3219 int64_t i, j, k, row;
3232 layout = &SDDS_dataset->layout;
3233 if (!layout->n_columns || !SDDS_dataset->n_rows)
3236 if (SDDS_dataset->layout.gzipFile) {
3237 gzfp = layout->gzfp;
3240 if (SDDS_dataset->layout.lzmaFile) {
3241 lzmafp = layout->lzmafp;
3248 fBuffer = &SDDS_dataset->fBuffer;
3250 for (i = 0; i < layout->n_columns; i++) {
3251 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
3253 if (layout->column_definition[i].type ==
SDDS_STRING) {
3255 if (SDDS_dataset->layout.gzipFile) {
3256 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3257 if (((
char ***)SDDS_dataset->data)[i][row])
3258 free((((
char ***)SDDS_dataset->data)[i][row]));
3259 if (!(((
char ***)SDDS_dataset->data)[i][row] = SDDS_ReadGZipBinaryString(gzfp, fBuffer, 0))) {
3260 SDDS_SetError(
"Unable to read columns--failure reading string (SDDS_ReadBinaryColumns)");
3266 if (SDDS_dataset->layout.lzmaFile) {
3267 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3268 if (((
char ***)SDDS_dataset->data)[i][row])
3269 free((((
char ***)SDDS_dataset->data)[i][row]));
3271 SDDS_SetError(
"Unable to read columns--failure reading string (SDDS_ReadBinaryColumms)");
3276 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3277 if (((
char ***)SDDS_dataset->data)[i][row])
3278 free((((
char ***)SDDS_dataset->data)[i][row]));
3280 SDDS_SetError(
"Unable to read columns--failure reading string (SDDS_ReadBinaryColumms)");
3290 if (SDDS_dataset->layout.gzipFile) {
3291 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)) {
3292 SDDS_SetError(
"Unable to read columns--failure reading values (SDDS_ReadBinaryColumns)");
3297 if (SDDS_dataset->layout.lzmaFile) {
3298 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)) {
3299 SDDS_SetError(
"Unable to read columns--failure reading values (SDDS_ReadBinaryColumns)");
3303 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)) {
3304 SDDS_SetError(
"Unable to read columns--failure reading values (SDDS_ReadBinaryColumns)");
3314 if (sparse_interval == 1 && sparse_offset == 0) {
3318 j = SDDS_dataset->n_rows;
3319 for (i = 0; i < layout->n_columns; i++) {
3321 switch (layout->column_definition[i].type) {
3323 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3324 if (k % sparse_interval == 0) {
3325 ((
short*)SDDS_dataset->data[i])[j] = ((
short*)SDDS_dataset->data[i])[row];
3332 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3333 if (k % sparse_interval == 0) {
3334 ((
unsigned short*)SDDS_dataset->data[i])[j] = ((
unsigned short*)SDDS_dataset->data[i])[row];
3341 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3342 if (k % sparse_interval == 0) {
3343 ((int32_t*)SDDS_dataset->data[i])[j] = ((int32_t*)SDDS_dataset->data[i])[row];
3350 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3351 if (k % sparse_interval == 0) {
3352 ((uint32_t*)SDDS_dataset->data[i])[j] = ((uint32_t*)SDDS_dataset->data[i])[row];
3359 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3360 if (k % sparse_interval == 0) {
3361 ((int64_t*)SDDS_dataset->data[i])[j] = ((int64_t*)SDDS_dataset->data[i])[row];
3368 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3369 if (k % sparse_interval == 0) {
3370 ((uint64_t*)SDDS_dataset->data[i])[j] = ((uint64_t*)SDDS_dataset->data[i])[row];
3377 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3378 if (k % sparse_interval == 0) {
3379 ((
float*)SDDS_dataset->data[i])[j] = ((
float*)SDDS_dataset->data[i])[row];
3386 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3387 if (k % sparse_interval == 0) {
3388 ((
double*)SDDS_dataset->data[i])[j] = ((
double*)SDDS_dataset->data[i])[row];
3395 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3396 if (k % sparse_interval == 0) {
3397 ((
long double*)SDDS_dataset->data[i])[j] = ((
long double*)SDDS_dataset->data[i])[row];
3404 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3405 if (k % sparse_interval == 0) {
3406 ((
char**)SDDS_dataset->data[i])[j] = ((
char**)SDDS_dataset->data[i])[row];
3411 for (k=j; k<SDDS_dataset->n_rows; k++) {
3412 if (((
char ***)SDDS_dataset->data)[i][k]) {
3413 free((((
char ***)SDDS_dataset->data)[i][k]));
3414 ((
char ***)SDDS_dataset->data)[i][k] = NULL;
3420 for (row = sparse_offset; row < SDDS_dataset->n_rows; row++) {
3421 if (k % sparse_interval == 0) {
3422 ((
char*)SDDS_dataset->data[i])[j] = ((
char*)SDDS_dataset->data[i])[row];
3433 SDDS_dataset->n_rows = j;
3473 layout = &SDDS_dataset->layout;
3474 if (!layout->n_columns || !SDDS_dataset->n_rows)
3477 if (SDDS_dataset->layout.gzipFile) {
3478 gzfp = layout->gzfp;
3481 if (SDDS_dataset->layout.lzmaFile) {
3482 lzmafp = layout->lzmafp;
3489 fBuffer = &SDDS_dataset->fBuffer;
3491 for (i = 0; i < layout->n_columns; i++) {
3492 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
3494 if (layout->column_definition[i].type ==
SDDS_STRING) {
3496 if (SDDS_dataset->layout.gzipFile) {
3497 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3498 if (((
char ***)SDDS_dataset->data)[i][row])
3499 free((((
char ***)SDDS_dataset->data)[i][row]));
3500 if (!(((
char ***)SDDS_dataset->data)[i][row] = SDDS_ReadNonNativeGZipBinaryString(gzfp, fBuffer, 0))) {
3501 SDDS_SetError(
"Unable to read columns--failure reading string (SDDS_ReadNonNativeBinaryColumns)");
3507 if (SDDS_dataset->layout.lzmaFile) {
3508 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3509 if (((
char ***)SDDS_dataset->data)[i][row])
3510 free((((
char ***)SDDS_dataset->data)[i][row]));
3512 SDDS_SetError(
"Unable to read columns--failure reading string (SDDS_ReadNonNativeBinaryColumms)");
3517 for (row = 0; row < SDDS_dataset->n_rows; row++) {
3518 if (((
char ***)SDDS_dataset->data)[i][row])
3519 free((((
char ***)SDDS_dataset->data)[i][row]));
3521 SDDS_SetError(
"Unable to read columns--failure reading string (SDDS_ReadNonNativeBinaryColumms)");
3531 if (SDDS_dataset->layout.gzipFile) {
3532 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)) {
3533 SDDS_SetError(
"Unable to read columns--failure reading values (SDDS_ReadNonNativeBinaryColumns)");
3538 if (SDDS_dataset->layout.lzmaFile) {
3539 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)) {
3540 SDDS_SetError(
"Unable to read columns--failure reading values (SDDS_ReadNonNativeBinaryColumns)");
3544 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)) {
3545 SDDS_SetError(
"Unable to read columns--failure reading values (SDDS_ReadNonNativeBinaryColumns)");
3580 unsigned short *suData;
3587 long double *ldData;
3589 layout = &SDDSin->layout;
3590 for (i = 0; i < layout->n_columns; i++) {
3591 switch (layout->column_definition[i].type) {
3593 sData = SDDSin->data[i];
3594 for (row = 0; row < SDDSin->n_rows; row++)
3598 suData = SDDSin->data[i];
3599 for (row = 0; row < SDDSin->n_rows; row++)
3603 lData = SDDSin->data[i];
3604 for (row = 0; row < SDDSin->n_rows; row++)
3608 luData = SDDSin->data[i];
3609 for (row = 0; row < SDDSin->n_rows; row++)
3613 lData64 = SDDSin->data[i];
3614 for (row = 0; row < SDDSin->n_rows; row++)
3618 luData64 = SDDSin->data[i];
3619 for (row = 0; row < SDDSin->n_rows; row++)
3623 ldData = SDDSin->data[i];
3624 for (row = 0; row < SDDSin->n_rows; row++)
3628 dData = SDDSin->data[i];
3629 for (row = 0; row < SDDSin->n_rows; row++)
3633 fData = SDDSin->data[i];
3634 for (row = 0; row < SDDSin->n_rows; row++)
3666 unsigned short *suData;
3673 long double *ldData;
3675 layout = &SDDSin->layout;
3676 for (i = 0; i < layout->n_parameters; i++) {
3677 if (layout->parameter_definition[i].fixed_value) {
3680 switch (layout->parameter_definition[i].type) {
3682 sData = SDDSin->parameter[i];
3686 suData = SDDSin->parameter[i];
3690 lData = SDDSin->parameter[i];
3694 luData = SDDSin->parameter[i];
3698 lData64 = SDDSin->parameter[i];
3702 luData64 = SDDSin->parameter[i];
3706 ldData = SDDSin->parameter[i];
3710 dData = SDDSin->parameter[i];
3714 fData = SDDSin->parameter[i];
3745 unsigned short *suData;
3752 long double *ldData;
3754 layout = &SDDSin->layout;
3756 for (i = 0; i < layout->n_arrays; i++) {
3757 switch (layout->array_definition[i].type) {
3759 sData = SDDSin->array[i].data;
3760 for (j = 0; j < SDDSin->array[i].elements; j++)
3764 suData = SDDSin->array[i].data;
3765 for (j = 0; j < SDDSin->array[i].elements; j++)
3769 lData = SDDSin->array[i].data;
3770 for (j = 0; j < SDDSin->array[i].elements; j++)
3774 luData = SDDSin->array[i].data;
3775 for (j = 0; j < SDDSin->array[i].elements; j++)
3779 lData64 = SDDSin->array[i].data;
3780 for (j = 0; j < SDDSin->array[i].elements; j++)
3784 luData64 = SDDSin->array[i].data;
3785 for (j = 0; j < SDDSin->array[i].elements; j++)
3789 ldData = SDDSin->array[i].data;
3790 for (j = 0; j < SDDSin->array[i].elements; j++)
3794 dData = SDDSin->array[i].data;
3795 for (j = 0; j < SDDSin->array[i].elements; j++)
3799 fData = SDDSin->array[i].data;
3800 for (j = 0; j < SDDSin->array[i].elements; j++)
3823 c1 = *((
char *)data);
3824 *((
char *)data) = *(((
char *)data) + 1);
3825 *(((
char *)data) + 1) = c1;
3841 c1 = *((
char *)data);
3842 *((
char *)data) = *(((
char *)data) + 1);
3843 *(((
char *)data) + 1) = c1;
3861 for (i = 0, j = 3; i < 4; i++, j--)
3862 *(((
char *)data) + i) = *(((
char *)©) + j);
3880 for (i = 0, j = 3; i < 4; i++, j--)
3881 *(((
char *)data) + i) = *(((
char *)©) + j);
3899 for (i = 0, j = 7; i < 8; i++, j--)
3900 *(((
char *)data) + i) = *(((
char *)©) + j);
3918 for (i = 0, j = 7; i < 8; i++, j--)
3919 *(((
char *)data) + i) = *(((
char *)©) + j);
3937 for (i = 0, j = 3; i < 4; i++, j--)
3938 *(((
char *)data) + i) = *(((
char *)©) + j);
3956 for (i = 0, j = 7; i < 8; i++, j--)
3957 *(((
char *)data) + i) = *(((
char *)©) + j);
3976 if (LDBL_DIG == 18) {
3977 for (i = 0, j = 11; i < 12; i++, j--)
3978 *(((
char *)data) + i) = *(((
char *)©) + j);
3980 for (i = 0, j = 7; i < 8; i++, j--)
3981 *(((
char *)data) + i) = *(((
char *)©) + j);
4059 if (SDDS_dataset->layout.disconnected) {
4060 SDDS_SetError(
"Can't read page--file is disconnected (SDDS_ReadNonNativePageDetailed)");
4064 if (SDDS_dataset->layout.gzipFile) {
4065 if (!SDDS_dataset->layout.gzfp) {
4066 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadNonNativePageDetailed)");
4071 if (SDDS_dataset->layout.lzmaFile) {
4072 if (!SDDS_dataset->layout.lzmafp) {
4073 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadNonNativePageDetailed)");
4077 if (!SDDS_dataset->layout.fp) {
4078 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadNonNativePageDetailed)");
4085 if (SDDS_dataset->original_layout.data_mode.mode == SDDS_ASCII) {
4086 if ((retval =
SDDS_ReadAsciiPage(SDDS_dataset, sparse_interval, sparse_offset, 0)) < 1) {
4089 }
else if (SDDS_dataset->original_layout.data_mode.mode == SDDS_BINARY) {
4094 SDDS_SetError(
"Unable to read page--unrecognized data mode (SDDS_ReadNonNativePageDetailed)");
4122 if (SDDS_dataset->layout.disconnected) {
4123 SDDS_SetError(
"Can't read page--file is disconnected (SDDS_ReadNonNativePageLastRows)");
4127 if (SDDS_dataset->layout.gzipFile) {
4128 if (!SDDS_dataset->layout.gzfp) {
4129 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadNonNativePageLastRows)");
4134 if (SDDS_dataset->layout.lzmaFile) {
4135 if (!SDDS_dataset->layout.lzmafp) {
4136 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadNonNativePageLastRows)");
4140 if (!SDDS_dataset->layout.fp) {
4141 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadNonNativePageLastRows)");
4148 if (SDDS_dataset->original_layout.data_mode.mode == SDDS_ASCII) {
4152 }
else if (SDDS_dataset->original_layout.data_mode.mode == SDDS_BINARY) {
4157 SDDS_SetError(
"Unable to read page--unrecognized data mode (SDDS_ReadNonNativePageLastRows)");
4231 int32_t n_rows32 = 0;
4232 int64_t n_rows, j, k, alloc_rows, rows_to_store, mod;
4245 if (SDDS_dataset->layout.gzipFile) {
4246 gzfp = SDDS_dataset->layout.gzfp;
4249 if (SDDS_dataset->layout.lzmaFile) {
4250 lzmafp = SDDS_dataset->layout.lzmafp;
4252 fp = SDDS_dataset->layout.fp;
4257 fBuffer = &SDDS_dataset->fBuffer;
4258 if (!fBuffer->buffer) {
4259 if (!(fBuffer->buffer = fBuffer->data =
SDDS_Malloc(
sizeof(
char) * defaultIOBufferSize))) {
4260 SDDS_SetError(
"Unable to do buffered read--allocation failure");
4263 fBuffer->bufferSize = defaultIOBufferSize;
4264 fBuffer->bytesLeft = 0;
4266 SDDS_dataset->rowcount_offset = -1;
4268 if (SDDS_dataset->layout.gzipFile) {
4269 if (!SDDS_GZipBufferedRead(&n_rows32,
sizeof(n_rows32), gzfp, &SDDS_dataset->fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4271 return (SDDS_dataset->page_number = -1);
4272 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4276 if (n_rows32 == INT32_MIN) {
4277 if (!SDDS_GZipBufferedRead(&n_rows,
sizeof(n_rows), gzfp, &SDDS_dataset->fBuffer,
SDDS_LONG64, SDDS_dataset->layout.byteOrderDeclared)) {
4279 return (SDDS_dataset->page_number = -1);
4280 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4293 if (SDDS_dataset->layout.lzmaFile) {
4295 if (lzma_eof(lzmafp))
4296 return (SDDS_dataset->page_number = -1);
4297 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4301 if (n_rows32 == INT32_MIN) {
4303 if (lzma_eof(lzmafp))
4304 return (SDDS_dataset->page_number = -1);
4305 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4313 SDDS_dataset->rowcount_offset = ftell(fp);
4314 if (!
SDDS_BufferedRead(&n_rows32,
sizeof(n_rows32), fp, &SDDS_dataset->fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4316 return (SDDS_dataset->page_number = -1);
4317 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4321 if (n_rows32 == INT32_MIN) {
4324 return (SDDS_dataset->page_number = -1);
4325 SDDS_SetError(
"Unable to read page--failure reading number of rows (SDDS_ReadNonNativeBinaryPage)");
4337 SDDS_SetError(
"Unable to read page--negative number of rows (SDDS_ReadNonNativeBinaryPage)");
4343 if (SDDS_dataset->layout.data_mode.column_major) {
4344 sparse_interval = 1;
4349 sparse_interval = 1;
4350 sparse_offset = n_rows - last_rows;
4351 rows_to_store = last_rows + 2;
4352 alloc_rows = rows_to_store - SDDS_dataset->n_rows_allocated;
4354 if (sparse_interval <= 0)
4355 sparse_interval = 1;
4356 if (sparse_offset < 0)
4359 rows_to_store = (n_rows - sparse_offset) / sparse_interval + 2;
4360 alloc_rows = rows_to_store - SDDS_dataset->n_rows_allocated;
4362 SDDS_SetError(
"Unable to read page--couldn't start page (SDDS_ReadNonNativeBinaryPage)");
4368 SDDS_SetError(
"Unable to read page--parameter reading error (SDDS_ReadNonNativeBinaryPage)");
4374 SDDS_SetError(
"Unable to read page--array reading error (SDDS_ReadNonNativeBinaryPage)");
4377 if (SDDS_dataset->layout.data_mode.column_major) {
4378 SDDS_dataset->n_rows = n_rows;
4380 SDDS_SetError(
"Unable to read page--column reading error (SDDS_ReadNonNativeBinaryPage)");
4384 return (SDDS_dataset->page_number);
4386 if ((sparse_interval <= 1) && (sparse_offset == 0)) {
4387 for (j = 0; j < n_rows; j++) {
4389 SDDS_dataset->n_rows = j - 1;
4390 if (SDDS_dataset->autoRecover) {
4393 return (SDDS_dataset->page_number);
4395 SDDS_SetError(
"Unable to read page--error reading data row (SDDS_ReadNonNativeBinaryPage)");
4400 SDDS_dataset->n_rows = j;
4402 return (SDDS_dataset->page_number);
4404 for (j = 0; j < sparse_offset; j++) {
4406 SDDS_dataset->n_rows = 0;
4407 if (SDDS_dataset->autoRecover) {
4410 return (SDDS_dataset->page_number);
4412 SDDS_SetError(
"Unable to read page--error reading data row (SDDS_ReadNonNativeBinaryPage)");
4417 n_rows -= sparse_offset;
4418 for (j = k = 0; j < n_rows; j++) {
4420 SDDS_dataset->n_rows = k - 1;
4421 if (SDDS_dataset->autoRecover) {
4424 return (SDDS_dataset->page_number);
4426 SDDS_SetError(
"Unable to read page--error reading data row (SDDS_ReadNonNativeBinaryPage)");
4432 SDDS_dataset->n_rows = k;
4434 return (SDDS_dataset->page_number);
4464 char buffer[SDDS_MAXLINE];
4474 layout = &SDDS_dataset->layout;
4475 if (!layout->n_parameters)
4478 if (SDDS_dataset->layout.gzipFile) {
4479 gzfp = layout->gzfp;
4482 if (SDDS_dataset->layout.lzmaFile) {
4483 lzmafp = layout->lzmafp;
4490 fBuffer = &SDDS_dataset->fBuffer;
4491 for (i = 0; i < layout->n_parameters; i++) {
4492 if (layout->parameter_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
4494 if (layout->parameter_definition[i].fixed_value) {
4495 strcpy(buffer, layout->parameter_definition[i].fixed_value);
4496 if (!
SDDS_ScanData(buffer, layout->parameter_definition[i].type, 0, SDDS_dataset->parameter[i], 0, 1)) {
4497 SDDS_SetError(
"Unable to read page--parameter scanning error (SDDS_ReadNonNativeBinaryParameters)");
4500 }
else if (layout->parameter_definition[i].type ==
SDDS_STRING) {
4501 if (*(
char **)SDDS_dataset->parameter[i])
4502 free(*(
char **)SDDS_dataset->parameter[i]);
4504 if (SDDS_dataset->layout.gzipFile) {
4505 if (!(*((
char **)SDDS_dataset->parameter[i]) = SDDS_ReadNonNativeGZipBinaryString(gzfp, fBuffer, 0))) {
4506 SDDS_SetError(
"Unable to read parameters--failure reading string (SDDS_ReadNonNativeBinaryParameters)");
4511 if (SDDS_dataset->layout.lzmaFile) {
4513 SDDS_SetError(
"Unable to read parameters--failure reading string (SDDS_ReadNonNativeBinaryParameters)");
4518 SDDS_SetError(
"Unable to read parameters--failure reading string (SDDS_ReadNonNativeBinaryParameters)");
4527 if (SDDS_dataset->layout.gzipFile) {
4528 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)) {
4529 SDDS_SetError(
"Unable to read parameters--failure reading value (SDDS_ReadNonNativeBinaryParameters)");
4534 if (SDDS_dataset->layout.lzmaFile) {
4535 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)) {
4536 SDDS_SetError(
"Unable to read parameters--failure reading value (SDDS_ReadNonNativeBinaryParameters)");
4540 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)) {
4541 SDDS_SetError(
"Unable to read parameters--failure reading value (SDDS_ReadNonNativeBinaryParameters)");
4591 layout = &SDDS_dataset->layout;
4592 if (!layout->n_arrays)
4595 if (SDDS_dataset->layout.gzipFile) {
4596 gzfp = layout->gzfp;
4599 if (SDDS_dataset->layout.lzmaFile) {
4600 lzmafp = layout->lzmafp;
4607 fBuffer = &SDDS_dataset->fBuffer;
4608 if (!SDDS_dataset->array) {
4609 SDDS_SetError(
"Unable to read array--pointer to structure storage area is NULL (SDDS_ReadNonNativeBinaryArrays)");
4612 for (i = 0; i < layout->n_arrays; i++) {
4613 array = SDDS_dataset->array + i;
4615 SDDS_SetError(
"Unable to get array--array definition corrupted (SDDS_ReadNonNativeBinaryArrays)");
4619 SDDS_SetError(
"Unable to read array--definition copy failed (SDDS_ReadNonNativeBinaryArrays)");
4623 if (!(array->dimension =
SDDS_Realloc(array->dimension,
sizeof(*array->dimension) * array->definition->dimensions))) {
4624 SDDS_SetError(
"Unable to read array--allocation failure (SDDS_ReadNonNativeBinaryArrays)");
4628 if (SDDS_dataset->layout.gzipFile) {
4629 if (!SDDS_GZipBufferedRead(array->dimension,
sizeof(*array->dimension) * array->definition->dimensions, gzfp, fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4630 SDDS_SetError(
"Unable to read arrays--failure reading dimensions (SDDS_ReadNonNativeBinaryArrays)");
4635 if (SDDS_dataset->layout.lzmaFile) {
4636 if (!
SDDS_LZMABufferedRead(array->dimension,
sizeof(*array->dimension) * array->definition->dimensions, lzmafp, fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4637 SDDS_SetError(
"Unable to read arrays--failure reading dimensions (SDDS_ReadNonNativeBinaryArrays)");
4641 if (!
SDDS_BufferedRead(array->dimension,
sizeof(*array->dimension) * array->definition->dimensions, fp, fBuffer,
SDDS_LONG, SDDS_dataset->layout.byteOrderDeclared)) {
4642 SDDS_SetError(
"Unable to read arrays--failure reading dimensions (SDDS_ReadNonNativeBinaryArrays)");
4649 array->elements = 1;
4650 for (j = 0; j < array->definition->dimensions; j++) {
4652 array->elements *= array->dimension[j];
4656 array->data = array->pointer = NULL;
4657 if (array->elements == 0)
4659 if (array->elements < 0) {
4660 SDDS_SetError(
"Unable to read array--number of elements is negative (SDDS_ReadNonNativeBinaryArrays)");
4664 SDDS_SetError(
"Unable to read array--allocation failure (SDDS_ReadNonNativeBinaryArrays)");
4669 if (SDDS_dataset->layout.gzipFile) {
4670 for (j = 0; j < array->elements; j++) {
4671 if (!(((
char **)(array->data))[j] = SDDS_ReadNonNativeGZipBinaryString(gzfp, fBuffer, 0))) {
4672 SDDS_SetError(
"Unable to read arrays--failure reading string (SDDS_ReadNonNativeBinaryArrays)");
4678 if (SDDS_dataset->layout.lzmaFile) {
4679 for (j = 0; j < array->elements; j++) {
4681 SDDS_SetError(
"Unable to read arrays--failure reading string (SDDS_ReadNonNativeBinaryArrays)");
4686 for (j = 0; j < array->elements; j++) {
4688 SDDS_SetError(
"Unable to read arrays--failure reading string (SDDS_ReadNonNativeBinaryArrays)");
4698 if (SDDS_dataset->layout.gzipFile) {
4699 if (!SDDS_GZipBufferedRead(array->data,
SDDS_type_size[array->definition->type - 1] * array->elements, gzfp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
4700 SDDS_SetError(
"Unable to read arrays--failure reading values (SDDS_ReadNonNativeBinaryArrays)");
4705 if (SDDS_dataset->layout.lzmaFile) {
4706 if (!
SDDS_LZMABufferedRead(array->data,
SDDS_type_size[array->definition->type - 1] * array->elements, lzmafp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
4707 SDDS_SetError(
"Unable to read arrays--failure reading values (SDDS_ReadNonNativeBinaryArrays)");
4711 if (!
SDDS_BufferedRead(array->data,
SDDS_type_size[array->definition->type - 1] * array->elements, fp, fBuffer, array->definition->type, SDDS_dataset->layout.byteOrderDeclared)) {
4712 SDDS_SetError(
"Unable to read arrays--failure reading values (SDDS_ReadNonNativeBinaryArrays)");
4747 int64_t i, type, size;
4758 layout = &SDDS_dataset->layout;
4759 fBuffer = &SDDS_dataset->fBuffer;
4762 if (SDDS_dataset->layout.gzipFile) {
4763 gzfp = layout->gzfp;
4764 for (i = 0; i < layout->n_columns; i++) {
4765 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
4767 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
4769 if (((
char ***)SDDS_dataset->data)[i][row])
4770 free((((
char ***)SDDS_dataset->data)[i][row]));
4771 if (!(((
char ***)SDDS_dataset->data)[i][row] = SDDS_ReadNonNativeGZipBinaryString(gzfp, fBuffer, 0))) {
4772 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4776 if (!SDDS_ReadNonNativeGZipBinaryString(gzfp, fBuffer, 1)) {
4777 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4783 if (!SDDS_GZipBufferedRead(skip ? NULL : (
char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
4784 SDDS_SetError(
"Unable to read row--failure reading value (SDDS_ReadNonNativeBinaryRow)");
4791 if (SDDS_dataset->layout.lzmaFile) {
4792 lzmafp = layout->lzmafp;
4793 for (i = 0; i < layout->n_columns; i++) {
4794 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
4796 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
4798 if (((
char ***)SDDS_dataset->data)[i][row])
4799 free((((
char ***)SDDS_dataset->data)[i][row]));
4801 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4806 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4812 if (!
SDDS_LZMABufferedRead(skip ? NULL : (
char *)SDDS_dataset->data[i] + row * size, size, lzmafp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
4813 SDDS_SetError(
"Unable to read row--failure reading value (SDDS_ReadNonNativeBinaryRow)");
4820 for (i = 0; i < layout->n_columns; i++) {
4821 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
4823 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
4825 if (((
char ***)SDDS_dataset->data)[i][row])
4826 free((((
char ***)SDDS_dataset->data)[i][row]));
4828 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4833 SDDS_SetError(
"Unable to read rows--failure reading string (SDDS_ReadNonNativeBinaryRow)");
4839 if (!
SDDS_BufferedRead(skip ? NULL : (
char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer, type, SDDS_dataset->layout.byteOrderDeclared)) {
4840 SDDS_SetError(
"Unable to read row--failure reading value (SDDS_ReadNonNativeBinaryRow)");
4878 if (!(
string =
SDDS_Malloc(
sizeof(*
string) * (length + 1))))
4912 if (!(
string =
SDDS_Malloc(
sizeof(*
string) * (length + 1))))
4938char *SDDS_ReadNonNativeGZipBinaryString(gzFile gzfp,
SDDS_FILEBUFFER *fBuffer, int32_t skip) {
4942 if (!SDDS_GZipBufferedRead(&length,
sizeof(length), gzfp, fBuffer,
SDDS_LONG, 0))
4947 if (!(
string =
SDDS_Malloc(
sizeof(*
string) * (length + 1))))
4949 if (length && !SDDS_GZipBufferedRead(skip ? NULL :
string,
sizeof(*
string) * length, gzfp, fBuffer,
SDDS_STRING, 0))
4987 int64_t i, rows, fixed_rows;
4988 int32_t min32 = INT32_MIN, rows32;
4996 if (!(fp = SDDS_dataset->layout.fp)) {
4997 SDDS_SetError(
"Unable to write page--file pointer is NULL (SDDS_WriteNonNativeBinaryPage)");
5000 fBuffer = &SDDS_dataset->fBuffer;
5002 if (!fBuffer->buffer) {
5003 if (!(fBuffer->buffer = fBuffer->data =
SDDS_Malloc(
sizeof(
char) * defaultIOBufferSize))) {
5004 SDDS_SetError(
"Unable to do buffered read--allocation failure (SDDS_WriteNonNativeBinaryPage)");
5007 fBuffer->bufferSize = defaultIOBufferSize;
5008 fBuffer->bytesLeft = defaultIOBufferSize;
5014 if (SDDS_dataset->layout.gzipFile) {
5015 if (!(gzfp = SDDS_dataset->layout.gzfp)) {
5016 SDDS_SetError(
"Unable to write page--file pointer is NULL (SDDS_WriteNonNativeBinaryPage)");
5019 SDDS_dataset->rowcount_offset = gztell(gzfp);
5020 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
5021 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
5022 if (fixed_rows > INT32_MAX) {
5023 if (!SDDS_GZipBufferedWrite(&min32,
sizeof(min32), gzfp, fBuffer)) {
5024 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5028 if (!SDDS_GZipBufferedWrite(&fixed_rows,
sizeof(fixed_rows), gzfp, fBuffer)) {
5029 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5034 rows32 = (int32_t)fixed_rows;
5036 if (!SDDS_GZipBufferedWrite(&rows32,
sizeof(rows32), gzfp, fBuffer)) {
5037 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5042 if (rows > INT32_MAX) {
5043 if (!SDDS_GZipBufferedWrite(&min32,
sizeof(min32), gzfp, fBuffer)) {
5044 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5048 if (!SDDS_GZipBufferedWrite(&rows,
sizeof(rows), gzfp, fBuffer)) {
5049 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5054 rows32 = (int32_t)rows;
5056 if (!SDDS_GZipBufferedWrite(&rows32,
sizeof(rows32), gzfp, fBuffer)) {
5057 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5064 if (SDDS_dataset->layout.lzmaFile) {
5065 if (!(lzmafp = SDDS_dataset->layout.lzmafp)) {
5066 SDDS_SetError(
"Unable to write page--file pointer is NULL (SDDS_WriteNonNativeBinaryPage)");
5069 SDDS_dataset->rowcount_offset = lzma_tell(lzmafp);
5070 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
5071 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
5072 if (fixed_rows > INT32_MAX) {
5074 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5079 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5084 rows32 = (int32_t)fixed_rows;
5087 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5092 if (rows > INT32_MAX) {
5094 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5099 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5104 rows32 = (int32_t)rows;
5107 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5113 SDDS_dataset->rowcount_offset = ftell(fp);
5114 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
5115 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
5116 if (fixed_rows > INT32_MAX) {
5118 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5123 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5128 rows32 = (int32_t)fixed_rows;
5131 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5136 if (rows > INT32_MAX) {
5138 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5143 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5148 rows32 = (int32_t)rows;
5151 SDDS_SetError(
"Unable to write page--failure writing number of rows (SDDS_WriteNonNativeBinaryPage)");
5161 SDDS_SetError(
"Unable to write page--parameter writing problem (SDDS_WriteNonNativeBinaryPage)");
5165 SDDS_SetError(
"Unable to write page--array writing problem (SDDS_WriteNonNativeBinaryPage)");
5169 if (SDDS_dataset->layout.n_columns) {
5170 if (SDDS_dataset->layout.data_mode.column_major) {
5172 SDDS_SetError(
"Unable to write page--column writing problem (SDDS_WriteNonNativeBinaryPage)");
5176 for (i = 0; i < SDDS_dataset->n_rows; i++) {
5177 if (SDDS_dataset->row_flag[i]) {
5179 SDDS_SetError(
"Unable to write page--row writing problem (SDDS_WriteNonNativeBinaryPage)");
5188 if (SDDS_dataset->layout.gzipFile) {
5189 if (!SDDS_GZipFlushBuffer(gzfp, fBuffer)) {
5190 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_WriteNonNativeBinaryPage)");
5195 if (SDDS_dataset->layout.lzmaFile) {
5197 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_WriteNonNativeBinaryPage)");
5202 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_WriteNonNativeBinaryPage)");
5209 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
5210 SDDS_dataset->n_rows_written = rows;
5211 SDDS_dataset->writing_page = 1;
5251 layout = &SDDS_dataset->layout;
5252 fBuffer = &SDDS_dataset->fBuffer;
5254 if (SDDS_dataset->layout.gzipFile) {
5255 if (!(gzfp = layout->gzfp)) {
5256 SDDS_SetError(
"Unable to write parameters--file pointer is NULL (SDDS_WriteNonNativeBinaryParameters)");
5259 for (i = 0; i < layout->n_parameters; i++) {
5260 if (layout->parameter_definition[i].fixed_value)
5262 if (layout->parameter_definition[i].type ==
SDDS_STRING) {
5263 if (!SDDS_GZipWriteNonNativeBinaryString(*((
char **)SDDS_dataset->parameter[i]), gzfp, fBuffer)) {
5264 SDDS_SetError(
"Unable to write parameters--failure writing string (SDDS_WriteNonNativeBinaryParameters)");
5268 }
else if (!SDDS_GZipBufferedWrite(SDDS_dataset->parameter[i],
SDDS_type_size[layout->parameter_definition[i].type - 1], gzfp, fBuffer)) {
5269 SDDS_SetError(
"Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
5276 if (SDDS_dataset->layout.lzmaFile) {
5277 if (!(lzmafp = layout->lzmafp)) {
5278 SDDS_SetError(
"Unable to write parameters--file pointer is NULL (SDDS_WriteNonNativeBinaryParameters)");
5281 for (i = 0; i < layout->n_parameters; i++) {
5282 if (layout->parameter_definition[i].fixed_value)
5284 if (layout->parameter_definition[i].type ==
SDDS_STRING) {
5286 SDDS_SetError(
"Unable to write parameters--failure writing string (SDDS_WriteNonNativeBinaryParameters)");
5291 SDDS_SetError(
"Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
5298 for (i = 0; i < layout->n_parameters; i++) {
5299 if (layout->parameter_definition[i].fixed_value)
5301 if (layout->parameter_definition[i].type ==
SDDS_STRING) {
5303 SDDS_SetError(
"Unable to write parameters--failure writing string (SDDS_WriteNonNativeBinaryParameters)");
5308 SDDS_SetError(
"Unable to write parameters--failure writing value (SDDS_WriteBinaryParameters)");
5345 int32_t i, j, dimension, zero = 0;
5357 layout = &SDDS_dataset->layout;
5358 fBuffer = &SDDS_dataset->fBuffer;
5360 if (SDDS_dataset->layout.gzipFile) {
5361 gzfp = layout->gzfp;
5362 for (i = 0; i < layout->n_arrays; i++) {
5363 if (!SDDS_dataset->array[i].dimension) {
5364 for (j = 0; j < layout->array_definition[i].dimensions; j++)
5365 if (!SDDS_GZipBufferedWrite(&zero,
sizeof(zero), gzfp, fBuffer)) {
5366 SDDS_SetError(
"Unable to write null array--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5373 for (j = 0; j < layout->array_definition[i].dimensions; j++) {
5374 dimension = SDDS_dataset->array[i].dimension[j];
5376 if (!SDDS_GZipBufferedWrite(&dimension,
sizeof(dimension), gzfp, fBuffer)) {
5377 SDDS_SetError(
"Unable to write arrays--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5382 if (layout->array_definition[i].type ==
SDDS_STRING) {
5383 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
5384 if (!SDDS_GZipWriteNonNativeBinaryString(((
char **)SDDS_dataset->array[i].data)[j], gzfp, fBuffer)) {
5385 SDDS_SetError(
"Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryArrays)");
5390 }
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)) {
5391 SDDS_SetError(
"Unable to write arrays--failure writing values (SDDS_WriteNonNativeBinaryArrays)");
5398 if (SDDS_dataset->layout.lzmaFile) {
5399 lzmafp = layout->lzmafp;
5400 for (i = 0; i < layout->n_arrays; i++) {
5401 if (!SDDS_dataset->array[i].dimension) {
5402 for (j = 0; j < layout->array_definition[i].dimensions; j++)
5404 SDDS_SetError(
"Unable to write null array--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5411 for (j = 0; j < layout->array_definition[i].dimensions; j++) {
5412 dimension = SDDS_dataset->array[i].dimension[j];
5415 SDDS_SetError(
"Unable to write arrays--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5420 if (layout->array_definition[i].type ==
SDDS_STRING) {
5421 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
5423 SDDS_SetError(
"Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryArrays)");
5429 SDDS_SetError(
"Unable to write arrays--failure writing values (SDDS_WriteNonNativeBinaryArrays)");
5436 for (i = 0; i < layout->n_arrays; i++) {
5437 if (!SDDS_dataset->array[i].dimension) {
5438 for (j = 0; j < layout->array_definition[i].dimensions; j++)
5440 SDDS_SetError(
"Unable to write null array--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5447 for (j = 0; j < layout->array_definition[i].dimensions; j++) {
5448 dimension = SDDS_dataset->array[i].dimension[j];
5451 SDDS_SetError(
"Unable to write arrays--failure writing dimensions (SDDS_WriteNonNativeBinaryArrays)");
5456 if (layout->array_definition[i].type ==
SDDS_STRING) {
5457 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
5459 SDDS_SetError(
"Unable to write arrays--failure writing string (SDDS_WriteNonNativeBinaryArrays)");
5464 }
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)) {
5465 SDDS_SetError(
"Unable to write arrays--failure writing values (SDDS_WriteNonNativeBinaryArrays)");
5500 int64_t i, type, size;
5511 layout = &SDDS_dataset->layout;
5512 fBuffer = &SDDS_dataset->fBuffer;
5514 if (SDDS_dataset->layout.gzipFile) {
5515 gzfp = layout->gzfp;
5516 for (i = 0; i < layout->n_columns; i++) {
5517 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
5518 if (!SDDS_GZipWriteNonNativeBinaryString(*((
char **)SDDS_dataset->data[i] + row), gzfp, fBuffer)) {
5519 SDDS_SetError(
"Unable to write rows--failure writing string (SDDS_WriteNonNativeBinaryRows)");
5524 if (!SDDS_GZipBufferedWrite((
char *)SDDS_dataset->data[i] + row * size, size, gzfp, fBuffer)) {
5525 SDDS_SetError(
"Unable to write row--failure writing value (SDDS_WriteNonNativeBinaryRow)");
5532 if (SDDS_dataset->layout.lzmaFile) {
5533 lzmafp = layout->lzmafp;
5534 for (i = 0; i < layout->n_columns; i++) {
5535 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
5537 SDDS_SetError(
"Unable to write rows--failure writing string (SDDS_WriteNonNativeBinaryRows)");
5543 SDDS_SetError(
"Unable to write row--failure writing value (SDDS_WriteNonNativeBinaryRow)");
5550 for (i = 0; i < layout->n_columns; i++) {
5551 if ((type = layout->column_definition[i].type) ==
SDDS_STRING) {
5553 SDDS_SetError(
"Unable to write rows--failure writing string (SDDS_WriteNonNativeBinaryRows)");
5558 if (!
SDDS_BufferedWrite((
char *)SDDS_dataset->data[i] + row * size, size, fp, fBuffer)) {
5559 SDDS_SetError(
"Unable to write row--failure writing value (SDDS_WriteNonNativeBinaryRow)");
5593 static char *dummy_string =
"";
5595 string = dummy_string;
5596 length = strlen(
string);
5599 SDDS_SetError(
"Unable to write string--error writing length");
5604 SDDS_SetError(
"Unable to write string--error writing contents");
5632 static char *dummy_string =
"";
5634 string = dummy_string;
5635 length = strlen(
string);
5638 SDDS_SetError(
"Unable to write string--error writing length");
5643 SDDS_SetError(
"Unable to write string--error writing contents");
5670int32_t SDDS_GZipWriteNonNativeBinaryString(
char *
string, gzFile gzfp,
SDDS_FILEBUFFER *fBuffer) {
5672 static char *dummy_string =
"";
5674 string = dummy_string;
5675 length = strlen(
string);
5677 if (!SDDS_GZipBufferedWrite(&length,
sizeof(length), gzfp, fBuffer)) {
5678 SDDS_SetError(
"Unable to write string--error writing length");
5682 if (length && !SDDS_GZipBufferedWrite(
string,
sizeof(*
string) * length, gzfp, fBuffer)) {
5683 SDDS_SetError(
"Unable to write string--error writing contents");
5713 int32_t code, min32 = INT32_MIN, rows32;
5714 int64_t i, rows, offset, fixed_rows;
5720 if (SDDS_dataset->layout.gzipFile) {
5721 SDDS_SetError(
"Unable to perform page updates on a gzip file (SDDS_UpdateNonNativeBinaryPage)");
5725 if (SDDS_dataset->layout.lzmaFile) {
5726 SDDS_SetError(
"Unable to perform page updates on .lzma or .xz files (SDDS_UpdateNonNativeBinaryPage)");
5729 if (SDDS_dataset->layout.data_mode.column_major) {
5730 SDDS_SetError(
"Unable to perform page updates on a column major order file (SDDS_UpdateNonNativeBinaryPage)");
5733 if (!SDDS_dataset->writing_page) {
5735 fprintf(stderr,
"Page not being written---calling SDDS_UpdateNonNativeBinaryPage\n");
5740 if (mode & FLUSH_TABLE) {
5743 SDDS_dataset->last_row_written = -1;
5744 SDDS_dataset->n_rows = 0;
5749 if (!(fp = SDDS_dataset->layout.fp)) {
5750 SDDS_SetError(
"Unable to update page--file pointer is NULL (SDDS_UpdateNonNativeBinaryPage)");
5753 fBuffer = &SDDS_dataset->fBuffer;
5755 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_UpdateNonNativeBinaryPage)");
5762 fprintf(stderr,
"%" PRId64
" rows stored in table, %" PRId32
" already written\n", rows, SDDS_dataset->n_rows_written);
5764 if (rows == SDDS_dataset->n_rows_written) {
5767 if (rows < SDDS_dataset->n_rows_written) {
5768 SDDS_SetError(
"Unable to update page--new number of rows less than previous number (SDDS_UpdateNonNativeBinaryPage)");
5772 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))) {
5773 if (
SDDS_fseek(fp, SDDS_dataset->rowcount_offset, 0) == -1) {
5774 SDDS_SetError(
"Unable to update page--failure doing fseek (SDDS_UpdateNonNativeBinaryPage)");
5777 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
5778 if ((rows - SDDS_dataset->n_rows_written) + 1 > SDDS_dataset->layout.data_mode.fixed_row_increment) {
5779 SDDS_dataset->layout.data_mode.fixed_row_increment = (rows - SDDS_dataset->n_rows_written) + 1;
5781 fixed_rows = ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment;
5783 fprintf(stderr,
"Setting %" PRId64
" fixed rows\n", fixed_rows);
5785 if ((fixed_rows > INT32_MAX) && (SDDS_dataset->n_rows_written <= INT32_MAX)) {
5786 SDDS_SetError(
"Unable to update page--crossed the INT32_MAX row boundary (SDDS_UpdateNonNativeBinaryPage)");
5789 if (fixed_rows > INT32_MAX) {
5790 if (fwrite(&min32,
sizeof(min32), 1, fp) != 1) {
5791 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
5795 if (fwrite(&fixed_rows,
sizeof(fixed_rows), 1, fp) != 1) {
5796 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateNonNativeBinaryPage)");
5801 rows32 = (int32_t)fixed_rows;
5803 if (fwrite(&rows32,
sizeof(rows32), 1, fp) != 1) {
5804 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateNonNativeBinaryPage)");
5810 fprintf(stderr,
"Setting %" PRId64
" rows\n", rows);
5812 if ((rows > INT32_MAX) && (SDDS_dataset->n_rows_written <= INT32_MAX)) {
5813 SDDS_SetError(
"Unable to update page--crossed the INT32_MAX row boundary (SDDS_UpdateNonNativeBinaryPage)");
5816 if (rows > INT32_MAX) {
5817 if (fwrite(&min32,
sizeof(min32), 1, fp) != 1) {
5818 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateBinaryPage)");
5822 if (fwrite(&rows,
sizeof(rows), 1, fp) != 1) {
5823 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateNonNativeBinaryPage)");
5828 rows32 = (int32_t)rows;
5830 if (fwrite(&rows32,
sizeof(rows32), 1, fp) != 1) {
5831 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateNonNativeBinaryPage)");
5837 SDDS_SetError(
"Unable to update page--failure doing fseek to end of page (SDDS_UpdateNonNativeBinaryPage)");
5842 for (i = SDDS_dataset->last_row_written + 1; i < SDDS_dataset->n_rows; i++) {
5844 SDDS_SetError(
"Unable to update page--failure writing row (SDDS_UpdateNonNativeBinaryPage)");
5850 fprintf(stderr,
"Flushing buffer\n");
5853 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_UpdateNonNativeBinaryPage)");
5856 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
5857 SDDS_dataset->n_rows_written = rows;
5858 if (mode & FLUSH_TABLE) {
5860 SDDS_dataset->first_row_in_mem = rows;
5861 SDDS_dataset->last_row_written = -1;
5862 SDDS_dataset->n_rows = 0;
5889 unsigned char d[8] = {0};
5892 if (byteOrder == SDDS_BIGENDIAN_SEEN) {
5896 for (i = 0; i < 6; i++) {
5898 x[0 + i] = x[11 - i];
5903 exponent = (((x[9] << 8) | x[8]) & 0x7FFF);
5905 ((uint64_t)x[7] << 56) | ((uint64_t)x[6] << 48) | ((uint64_t)x[5] << 40) | ((uint64_t)x[4] << 32) |
5906 ((uint64_t)x[3] << 24) | ((uint64_t)x[2] << 16) | ((uint64_t)x[1] << 8) | (uint64_t)x[0];
5910 if ((exponent == 0x7FFF) || (exponent == 0)) {
5912 if (exponent == 0x7FFF) {
5918 memcpy(&result, d, 8);
5923 exponent = exponent - 0x3FFF + 0x03FF;
5925 if (exponent <= -52)
5927 memcpy(&result, d, 8);
5929 }
else if (exponent < 0) {
5931 }
else if (exponent >= 0x7FF)
5936 memcpy(&result, d, 8);
5940 d[7] |= (exponent & 0x7F0) >> 4;
5941 d[6] |= (exponent & 0xF) << 4;
5950 mantissa >>= (-exponent + 1);
5953 d[0] = mantissa & 0xFF;
5954 d[1] = (mantissa >> 8) & 0xFF;
5955 d[2] = (mantissa >> 16) & 0xFF;
5956 d[3] = (mantissa >> 24) & 0xFF;
5957 d[4] = (mantissa >> 32) & 0xFF;
5958 d[5] = (mantissa >> 40) & 0xFF;
5959 d[6] |= (mantissa >> 48) & 0x0F;
5961 memcpy(&result, d, 8);
5963 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_ReadBinaryColumns(SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset)
Reads the binary columns from an SDDS dataset.
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.
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_CHARACTER
Identifier for the character 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.
double max_in_array(double *array, long n)
Finds the maximum value in an array of doubles.
double min_in_array(double *array, long n)
Finds the minimum value in an array of doubles.