29#define COMMENT_POSITION 40
32# error "SDDS_VERSION does not match the version number of this file"
39#define INITIAL_BIG_BUFFER_SIZE SDDS_MAXLINE
62 SDDS_SetError(
"Unable to write value--data pointer is NULL (SDDS_WriteTypedValue)");
66 SDDS_SetError(
"Unable to print value--file pointer is NULL (SDDS_WriteTypedValue)");
71 fprintf(fp, format ? format :
"%hd", *((
short *)data + index));
74 fprintf(fp, format ? format :
"%hu", *((
unsigned short *)data + index));
77 fprintf(fp, format ? format :
"%" PRId32, *((int32_t *)data + index));
80 fprintf(fp, format ? format :
"%" PRIu32, *((uint32_t *)data + index));
83 fprintf(fp, format ? format :
"%" PRId64, *((int64_t *)data + index));
86 fprintf(fp, format ? format :
"%" PRIu64, *((uint64_t *)data + index));
89 fprintf(fp, format ? format :
"%15.8e", *((
float *)data + index));
92 fprintf(fp, format ? format :
"%22.15e", *((
double *)data + index));
96 fprintf(fp, format ? format :
"%22.18Le", *((
long double *)data + index));
98 fprintf(fp, format ? format :
"%22.15Le", *((
long double *)data + index));
103 s = *((
char **)data + index);
119 else if (isspace(c) || !isprint(c))
120 fprintf(fp,
"\\%03o", c);
129 c = *((
char *)data + index);
136 else if (!c || isspace(c) || !isprint(c))
137 fprintf(fp,
"\\%03o", c);
142 SDDS_SetError(
"Unable to write value--unknown data type (SDDS_WriteTypedValue)");
185 SDDS_SetError(
"Unable to write value--data pointer is NULL (SDDS_LZMAWriteTypedValue)");
189 SDDS_SetError(
"Unable to print value--file pointer is NULL (SDDS_LZMAWriteTypedValue)");
194 lzma_printf(lzmafp, format ? format :
"%hd", *((
short *)data + index));
197 lzma_printf(lzmafp, format ? format :
"%hu", *((
unsigned short *)data + index));
200 lzma_printf(lzmafp, format ? format :
"%" PRId32, *((int32_t *)data + index));
203 lzma_printf(lzmafp, format ? format :
"%" PRIu32, *((uint32_t *)data + index));
206 lzma_printf(lzmafp, format ? format :
"%" PRId64, *((int64_t *)data + index));
209 lzma_printf(lzmafp, format ? format :
"%" PRIu64, *((uint64_t *)data + index));
212 lzma_printf(lzmafp, format ? format :
"%15.8e", *((
float *)data + index));
215 lzma_printf(lzmafp, format ? format :
"%22.15e", *((
double *)data + index));
218 if (LDBL_DIG == 18) {
219 lzma_printf(lzmafp, format ? format :
"%22.18Le", *((
long double *)data + index));
221 lzma_printf(lzmafp, format ? format :
"%22.15Le", *((
long double *)data + index));
226 s = *((
char **)data + index);
229 lzma_putc(
'"', lzmafp);
235 lzma_puts(
"\\!", lzmafp);
237 lzma_puts(
"\\\\", lzmafp);
239 lzma_puts(
"\\\"", lzmafp);
241 lzma_putc(
' ', lzmafp);
242 else if (isspace(c) || !isprint(c))
243 lzma_printf(lzmafp,
"\\%03o", c);
245 lzma_putc(c, lzmafp);
248 lzma_putc(
'"', lzmafp);
252 c = *((
char *)data + index);
254 lzma_puts(
"\\!", lzmafp);
256 lzma_puts(
"\\\\", lzmafp);
258 lzma_puts(
"\\\"", lzmafp);
259 else if (!c || isspace(c) || !isprint(c))
260 lzma_printf(lzmafp,
"\\%03o", c);
262 lzma_putc(c, lzmafp);
265 SDDS_SetError(
"Unable to write value--unknown data type (SDDS_LZMAWriteTypedValue)");
304int32_t SDDS_GZipWriteTypedValue(
void *data, int64_t index, int32_t type,
char *format, gzFile gzfp) {
309 SDDS_SetError(
"Unable to write value--data pointer is NULL (SDDS_GZipWriteTypedValue)");
313 SDDS_SetError(
"Unable to print value--file pointer is NULL (SDDS_GZipWriteTypedValue)");
318 gzprintf(gzfp, format ? format :
"%hd", *((
short *)data + index));
321 gzprintf(gzfp, format ? format :
"%hu", *((
unsigned short *)data + index));
324 gzprintf(gzfp, format ? format :
"%" PRId32, *((int32_t *)data + index));
327 gzprintf(gzfp, format ? format :
"%" PRIu32, *((uint32_t *)data + index));
330 gzprintf(gzfp, format ? format :
"%" PRId64, *((int64_t *)data + index));
333 gzprintf(gzfp, format ? format :
"%" PRIu64, *((uint64_t *)data + index));
336 gzprintf(gzfp, format ? format :
"%15.8e", *((
float *)data + index));
339 gzprintf(gzfp, format ? format :
"%22.15e", *((
double *)data + index));
342 if (LDBL_DIG == 18) {
343 gzprintf(gzfp, format ? format :
"%22.18Le", *((
long double *)data + index));
345 gzprintf(gzfp, format ? format :
"%22.15Le", *((
long double *)data + index));
350 s = *((
char **)data + index);
361 gzputs(gzfp,
"\\\\");
363 gzputs(gzfp,
"\\\"");
366 else if (isspace(c) || !isprint(c))
367 gzprintf(gzfp,
"\\%03o", c);
376 c = *((
char *)data + index);
380 gzputs(gzfp,
"\\\\");
382 gzputs(gzfp,
"\\\"");
383 else if (!c || isspace(c) || !isprint(c))
384 gzprintf(gzfp,
"\\%03o", c);
389 SDDS_SetError(
"Unable to write value--unknown data type (SDDS_GZipWriteTypedValue)");
421 if (SDDS_dataset->layout.gzipFile) {
422 if (!(gzfp = SDDS_dataset->layout.gzfp)) {
423 SDDS_SetError(
"Unable to write page--file pointer is NULL (SDDS_WriteAsciiPage)");
426 if (SDDS_dataset->layout.data_mode.no_row_counts && (SDDS_dataset->page_number > 1 || SDDS_dataset->file_had_data))
428 gzprintf(gzfp,
"! page number %" PRId32
"\n", SDDS_dataset->page_number);
430 if (!SDDS_GZipWriteAsciiParameters(SDDS_dataset, gzfp) || !SDDS_GZipWriteAsciiArrays(SDDS_dataset, gzfp))
433 if (SDDS_dataset->layout.n_columns) {
435 if (!SDDS_dataset->layout.data_mode.no_row_counts) {
436 SDDS_dataset->rowcount_offset = gztell(gzfp);
437 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
438 gzprintf(gzfp,
"%20" PRId64
"\n", ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment);
440 gzprintf(gzfp,
"%20" PRId64
"\n", rows);
442 for (i = 0; i < SDDS_dataset->n_rows; i++)
443 if (SDDS_dataset->row_flag[i] && !SDDS_GZipWriteAsciiRow(SDDS_dataset, i, gzfp))
446 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
447 SDDS_dataset->n_rows_written = rows;
448 SDDS_dataset->writing_page = 1;
452 if (SDDS_dataset->layout.lzmaFile) {
453 if (!(lzmafp = SDDS_dataset->layout.lzmafp)) {
454 SDDS_SetError(
"Unable to write page--file pointer is NULL (SDDS_WriteAsciiPage)");
457 if (SDDS_dataset->layout.data_mode.no_row_counts && (SDDS_dataset->page_number > 1 || SDDS_dataset->file_had_data))
458 lzma_putc(
'\n', lzmafp);
459 lzma_printf(lzmafp,
"! page number %" PRId32
"\n", SDDS_dataset->page_number);
464 if (SDDS_dataset->layout.n_columns) {
466 if (!SDDS_dataset->layout.data_mode.no_row_counts) {
467 SDDS_dataset->rowcount_offset = lzma_tell(lzmafp);
468 if (SDDS_dataset->layout.data_mode.fixed_row_count)
469 lzma_printf(lzmafp,
"%20" PRId64
"\n", ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment);
471 lzma_printf(lzmafp,
"%20" PRId64
"\n", rows);
473 for (i = 0; i < SDDS_dataset->n_rows; i++)
477 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
478 SDDS_dataset->n_rows_written = rows;
479 SDDS_dataset->writing_page = 1;
481 if (!(fp = SDDS_dataset->layout.fp)) {
482 SDDS_SetError(
"Unable to write page--file pointer is NULL (SDDS_WriteAsciiPage)");
485 if (SDDS_dataset->layout.data_mode.no_row_counts && (SDDS_dataset->page_number > 1 || SDDS_dataset->file_had_data))
487 fprintf(fp,
"! page number %" PRId32
"\n", SDDS_dataset->page_number);
492 if (SDDS_dataset->layout.n_columns) {
494 if (!SDDS_dataset->layout.data_mode.no_row_counts) {
495 SDDS_dataset->rowcount_offset = ftell(fp);
496 if (SDDS_dataset->layout.data_mode.fixed_row_count)
497 fprintf(fp,
"%20" PRId64
"\n", ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment);
499 fprintf(fp,
"%20" PRId64
"\n", rows);
501 for (i = 0; i < SDDS_dataset->n_rows; i++)
505 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
506 SDDS_dataset->n_rows_written = rows;
507 SDDS_dataset->writing_page = 1;
538 layout = &SDDS_dataset->layout;
539 for (i = 0; i < layout->n_parameters; i++) {
540 if (layout->parameter_definition[i].fixed_value)
542 if (!
SDDS_WriteTypedValue(SDDS_dataset->parameter[i], 0, layout->parameter_definition[i].type, NULL, fp)) {
543 SDDS_SetError(
"Unable to write ascii parameters (SDDS_WriteAsciiParameters)");
572 layout = &SDDS_dataset->layout;
573 for (i = 0; i < layout->n_parameters; i++) {
574 if (layout->parameter_definition[i].fixed_value)
577 SDDS_SetError(
"Unable to write ascii parameters (SDDS_LZMAWriteAsciiParameters)");
580 lzma_putc(
'\n', lzmafp);
600int32_t SDDS_GZipWriteAsciiParameters(
SDDS_DATASET *SDDS_dataset, gzFile gzfp) {
607 layout = &SDDS_dataset->layout;
608 for (i = 0; i < layout->n_parameters; i++) {
609 if (layout->parameter_definition[i].fixed_value)
611 if (!SDDS_GZipWriteTypedValue(SDDS_dataset->parameter[i], 0, layout->parameter_definition[i].type, NULL, gzfp)) {
612 SDDS_SetError(
"Unable to write ascii parameters (SDDS_GZipWriteAsciiParameters)");
644 layout = &SDDS_dataset->layout;
645 for (j = 0; j < layout->n_arrays; j++) {
646 array_definition = layout->array_definition + j;
647 array = &SDDS_dataset->array[j];
648 for (i = 0; i < array_definition->dimensions; i++)
649 fprintf(fp,
"%" PRId32
" ", array->dimension[i]);
650 fprintf(fp,
" ! %" PRId32
"-dimensional array %s:\n", array_definition->dimensions, array_definition->name);
651 for (i = 0; i < array->elements;) {
653 SDDS_SetError(
"Unable to write array--couldn't write ASCII data (SDDS_WriteAsciiArrays)");
657 if (i % 6 == 0 || i == array->elements)
689 layout = &SDDS_dataset->layout;
690 for (j = 0; j < layout->n_arrays; j++) {
691 array_definition = layout->array_definition + j;
692 array = &SDDS_dataset->array[j];
693 for (i = 0; i < array_definition->dimensions; i++)
694 lzma_printf(lzmafp,
"%" PRId32
" ", array->dimension[i]);
695 lzma_printf(lzmafp,
" ! %" PRId32
"-dimensional array %s:\n", array_definition->dimensions, array_definition->name);
696 for (i = 0; i < array->elements;) {
698 SDDS_SetError(
"Unable to write array--couldn't write ASCII data (SDDS_LZMAWriteAsciiArrays)");
702 if (i % 6 == 0 || i == array->elements)
703 lzma_putc(
'\n', lzmafp);
705 lzma_putc(
' ', lzmafp);
726int32_t SDDS_GZipWriteAsciiArrays(
SDDS_DATASET *SDDS_dataset, gzFile gzfp) {
735 layout = &SDDS_dataset->layout;
736 for (j = 0; j < layout->n_arrays; j++) {
737 array_definition = layout->array_definition + j;
738 array = &SDDS_dataset->array[j];
739 for (i = 0; i < array_definition->dimensions; i++)
740 gzprintf(gzfp,
"%" PRId32
" ", array->dimension[i]);
741 gzprintf(gzfp,
" ! %" PRId32
"-dimensional array %s:\n", array_definition->dimensions, array_definition->name);
742 for (i = 0; i < array->elements;) {
743 if (!SDDS_GZipWriteTypedValue(array->data, i, array_definition->type, NULL, gzfp)) {
744 SDDS_SetError(
"Unable to write array--couldn't write ASCII data (SDDS_GZipWriteAsciiArrays)");
748 if (i % 6 == 0 || i == array->elements)
776 int32_t newline_needed;
777 int64_t i, n_per_line, line;
784 layout = &SDDS_dataset->layout;
785 if (SDDS_dataset->layout.data_mode.lines_per_row <= 0)
786 SDDS_dataset->layout.data_mode.lines_per_row = 1;
787 n_per_line = SDDS_dataset->layout.n_columns / SDDS_dataset->layout.data_mode.lines_per_row;
790 for (i = 0; i < layout->n_columns; i++) {
791 if (!
SDDS_WriteTypedValue(SDDS_dataset->data[i], row, layout->column_definition[i].type, NULL, fp)) {
792 SDDS_SetError(
"Unable to write ascii row (SDDS_WriteAsciiRow)");
795 if ((i + 1) % n_per_line == 0 && line != SDDS_dataset->layout.data_mode.lines_per_row) {
827 int32_t newline_needed;
828 int64_t i, n_per_line, line;
835 layout = &SDDS_dataset->layout;
836 if (SDDS_dataset->layout.data_mode.lines_per_row <= 0)
837 SDDS_dataset->layout.data_mode.lines_per_row = 1;
838 n_per_line = SDDS_dataset->layout.n_columns / SDDS_dataset->layout.data_mode.lines_per_row;
841 for (i = 0; i < layout->n_columns; i++) {
843 SDDS_SetError(
"Unable to write ascii row (SDDS_LZMAWriteAsciiRow)");
846 if ((i + 1) % n_per_line == 0 && line != SDDS_dataset->layout.data_mode.lines_per_row) {
848 lzma_putc(
'\n', lzmafp);
851 lzma_putc(
' ', lzmafp);
856 lzma_putc(
'\n', lzmafp);
878int32_t SDDS_GZipWriteAsciiRow(
SDDS_DATASET *SDDS_dataset, int64_t row, gzFile gzfp) {
879 int32_t newline_needed;
880 int64_t i, n_per_line, line;
887 layout = &SDDS_dataset->layout;
888 if (SDDS_dataset->layout.data_mode.lines_per_row <= 0)
889 SDDS_dataset->layout.data_mode.lines_per_row = 1;
890 n_per_line = SDDS_dataset->layout.n_columns / SDDS_dataset->layout.data_mode.lines_per_row;
893 for (i = 0; i < layout->n_columns; i++) {
894 if (!SDDS_GZipWriteTypedValue(SDDS_dataset->data[i], row, layout->column_definition[i].type, NULL, gzfp)) {
895 SDDS_SetError(
"Unable to write ascii row (SDDS_GZipWriteAsciiRow)");
898 if ((i + 1) % n_per_line == 0 && line != SDDS_dataset->layout.data_mode.lines_per_row) {
928 int32_t i, first_read;
935 char *bigBuffer = NULL;
936 int32_t bigBufferSize = 0;
938 layout = &SDDS_dataset->layout;
940 if (layout->n_parameters > 0) {
941 if (!(bigBuffer =
SDDS_Malloc(
sizeof(*bigBuffer) * (bigBufferSize = INITIAL_BIG_BUFFER_SIZE)))) {
942 SDDS_SetError(
"Unable to read parameters--buffer allocation failure (SDDS_ReadAsciiParameters)");
947 if (SDDS_dataset->layout.gzipFile) {
949 for (i = 0; i < layout->n_parameters; i++) {
950 if (layout->parameter_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
953 if (!layout->parameter_definition[i].fixed_value) {
954 if (!fgetsGZipSkipCommentsResize(SDDS_dataset, &bigBuffer, &bigBufferSize, gzfp,
'!')) {
960 SDDS_SetError(
"Unable to read parameters--data ends prematurely (SDDS_ReadAsciiParameters)");
964 bigBuffer[strlen(bigBuffer) - 1] = 0;
966 strcpy(bigBuffer, layout->parameter_definition[i].fixed_value);
967 if (!
SDDS_ScanData(bigBuffer, layout->parameter_definition[i].type, 0, SDDS_dataset->parameter[i], 0, 1)) {
968 SDDS_SetError(
"Unable to read page--parameter scanning error (SDDS_ReadAsciiParameters)");
974 if (SDDS_dataset->layout.lzmaFile) {
975 lzmafp = layout->lzmafp;
976 for (i = 0; i < layout->n_parameters; i++) {
977 if (layout->parameter_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
980 if (!layout->parameter_definition[i].fixed_value) {
987 SDDS_SetError(
"Unable to read parameters--data ends prematurely (SDDS_ReadAsciiParameters)");
991 bigBuffer[strlen(bigBuffer) - 1] = 0;
993 strcpy(bigBuffer, layout->parameter_definition[i].fixed_value);
994 if (!
SDDS_ScanData(bigBuffer, layout->parameter_definition[i].type, 0, SDDS_dataset->parameter[i], 0, 1)) {
995 SDDS_SetError(
"Unable to read page--parameter scanning error (SDDS_ReadAsciiParameters)");
1001 for (i = 0; i < layout->n_parameters; i++) {
1002 if (layout->parameter_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
1005 if (!layout->parameter_definition[i].fixed_value) {
1012 SDDS_SetError(
"Unable to read parameters--data ends prematurely (SDDS_ReadAsciiParameters)");
1016 bigBuffer[strlen(bigBuffer) - 1] = 0;
1018 strcpy(bigBuffer, layout->parameter_definition[i].fixed_value);
1019 if (!
SDDS_ScanData(bigBuffer, layout->parameter_definition[i].type, 0, SDDS_dataset->parameter[i], 0, 1)) {
1020 SDDS_SetError(
"Unable to read page--parameter scanning error (SDDS_ReadAsciiParameters)");
1048 int32_t i, j, length;
1050 char *buffer = NULL;
1051 int32_t bufferSize = 0;
1052 char *bigBuffer = NULL;
1053 int32_t bigBufferSize = 0;
1054 char *bigBufferCopy;
1055 int32_t bigBufferCopySize;
1064 layout = &SDDS_dataset->layout;
1066 if (SDDS_dataset->layout.gzipFile) {
1067 gzfp = layout->gzfp;
1070 if (SDDS_dataset->layout.lzmaFile) {
1071 lzmafp = layout->lzmafp;
1078 if (layout->n_arrays > 0) {
1079 if (!(bigBuffer =
SDDS_Malloc(
sizeof(*bigBuffer) * (bigBufferSize = INITIAL_BIG_BUFFER_SIZE)))) {
1080 SDDS_SetError(
"Unable to read parameters--buffer allocation failure (SDDS_ReadAsciiArrays)");
1084 for (i = 0; i < layout->n_arrays; i++) {
1086 if (SDDS_dataset->layout.gzipFile) {
1087 if (!fgetsGZipSkipCommentsResize(SDDS_dataset, &bigBuffer, &bigBufferSize, gzfp,
'!') ||
SDDS_StringIsBlank(bigBuffer)) {
1090 SDDS_SetError(
"Unable to read array--dimensions missing (SDDS_ReadAsciiArrays)");
1095 if (SDDS_dataset->layout.lzmaFile) {
1099 SDDS_SetError(
"Unable to read array--dimensions missing (SDDS_ReadAsciiArrays)");
1106 SDDS_SetError(
"Unable to read array--dimensions missing (SDDS_ReadAsciiArrays)");
1113 if (!(array = SDDS_dataset->array + i)) {
1114 SDDS_SetError(
"Unable to read array--pointer to structure storage area is NULL (SDDS_ReadAsciiArrays)");
1118 SDDS_SetError(
"Unable to get array--array definition corrupted (SDDS_ReadAsciiArrays)");
1122 SDDS_SetError(
"Unable to read array--definition copy failed (SDDS_ReadAsciiArrays)");
1126 if (!(array->dimension =
SDDS_Realloc(array->dimension,
sizeof(*array->dimension) * array->definition->dimensions))) {
1127 SDDS_SetError(
"Unable to read array--allocation failure (SDDS_ReadAsciiArrays)");
1130 array->elements = 1;
1131 if ((length = strlen(bigBuffer)) >= bufferSize) {
1132 if (!(buffer =
SDDS_Realloc(buffer,
sizeof(*buffer) * (bufferSize = 2 * length)))) {
1133 SDDS_SetError(
"Unable to scan data--allocation failure (SDDS_ReadAsciiArrays");
1137 for (j = 0; j < array->definition->dimensions; j++) {
1138 if (
SDDS_GetToken(bigBuffer, buffer, SDDS_MAXLINE) <= 0 || sscanf(buffer,
"%" SCNd32, array->dimension + j) != 1 || array->dimension[j] < 0) {
1139 SDDS_SetError(
"Unable to read array--dimensions missing or negative (SDDS_ReadAsciiArrays)");
1142 array->elements *= array->dimension[j];
1144 if (!array->elements)
1148 array->data = array->pointer = NULL;
1150 SDDS_SetError(
"Unable to read array--allocation failure (SDDS_ReadAsciiArrays)");
1160 if (SDDS_dataset->layout.gzipFile) {
1161 if (!fgetsGZipSkipCommentsResize(SDDS_dataset, &bigBuffer, &bigBufferSize, gzfp,
'!') ||
SDDS_StringIsBlank(bigBuffer)) {
1162 SDDS_SetError(
"Unable to read array--dimensions missing (SDDS_ReadAsciiArrays)");
1167 if (SDDS_dataset->layout.lzmaFile) {
1169 SDDS_SetError(
"Unable to read array--dimensions missing (SDDS_ReadAsciiArrays)");
1174 SDDS_SetError(
"Unable to read array--dimensions missing (SDDS_ReadAsciiArrays)");
1186 bigBufferCopy = bigBuffer;
1187 bigBufferCopySize = strlen(bigBufferCopy);
1189 if (!
SDDS_ScanData2(bigBufferCopy, &bigBufferCopy, &bigBufferCopySize, array->definition->type, array->definition->field_length, array->data, j, 0)) {
1190 SDDS_SetError(
"Unable to read array--error scanning data element (SDDS_ReadAsciiArrays)");
1195 }
while (j < array->elements);
1275 int32_t no_row_counts, end_of_data, retval, lineCount;
1276 int64_t n_rows, i, j, k, rows_to_store;
1278 char s[SDDS_MAXLINE];
1279 char *dataRead, *bigBufferCopy;
1280 int32_t bigBufferCopySize;
1281 char *bigBuffer = NULL;
1282 int32_t bigBufferSize = 0;
1288 void **statData=NULL;
1293 if (SDDS_dataset->autoRecovered)
1299 if (SDDS_dataset->layout.gzipFile) {
1300 gzfp = SDDS_dataset->layout.gzfp;
1303 if (SDDS_dataset->layout.lzmaFile) {
1304 lzmafp = SDDS_dataset->layout.lzmafp;
1306 fp = SDDS_dataset->layout.fp;
1311 if (SDDS_dataset->page_number == -1)
1315 if (SDDS_dataset->layout.gzipFile) {
1316 if (gzeof(gzfp) && SDDS_dataset->page_number > 0)
1318 return SDDS_dataset->page_number = -1;
1321 if (SDDS_dataset->layout.lzmaFile) {
1322 if (lzma_eof(lzmafp) && SDDS_dataset->page_number > 0)
1324 return SDDS_dataset->page_number = -1;
1326 if (feof(fp) && SDDS_dataset->page_number > 0)
1328 return SDDS_dataset->page_number = -1;
1335 return (SDDS_dataset->page_number = -1);
1338 if (SDDS_dataset->layout.gzipFile) {
1339 if (SDDS_dataset->page_number == 0)
1340 for (i = 0; i < SDDS_dataset->layout.data_mode.additional_header_lines; i++) {
1341 if (!fgetsGZipSkipComments(SDDS_dataset, s, SDDS_MAXLINE, gzfp,
'!'))
1342 return (SDDS_dataset->page_number = -1);
1346 if (SDDS_dataset->layout.lzmaFile) {
1347 if (SDDS_dataset->page_number == 0)
1348 for (i = 0; i < SDDS_dataset->layout.data_mode.additional_header_lines; i++) {
1350 return (SDDS_dataset->page_number = -1);
1353 if (SDDS_dataset->page_number == 0)
1354 for (i = 0; i < SDDS_dataset->layout.data_mode.additional_header_lines; i++) {
1356 return (SDDS_dataset->page_number = -1);
1365 SDDS_SetError(
"Unable to read page--couldn't start page (SDDS_ReadAsciiPage)");
1369 layout = &SDDS_dataset->layout;
1373 return (SDDS_dataset->page_number = retval);
1374 SDDS_SetError(
"Unable to read page--couldn't read parameters (SDDS_ReadAsciiPage)");
1379 return (SDDS_dataset->page_number = retval);
1380 SDDS_SetError(
"Unable to read page--couldn't read arrays (SDDS_ReadAsciiPage)");
1386 if (sparse_interval <= 0)
1387 sparse_interval = 1;
1388 if (sparse_offset < 0)
1391 SDDS_dataset->rowcount_offset = -1;
1392 if (layout->n_columns) {
1393 if (!(bigBuffer =
SDDS_Malloc(
sizeof(*bigBuffer) * (bigBufferSize = INITIAL_BIG_BUFFER_SIZE)))) {
1394 SDDS_SetError(
"Unable to read parameters--buffer allocation failure (SDDS_ReadAsciiPage)");
1400 if (!SDDS_dataset->layout.data_mode.no_row_counts) {
1403 if (SDDS_dataset->layout.gzipFile) {
1404 if (!fgetsGZipSkipComments(SDDS_dataset, s, SDDS_MAXLINE, gzfp,
'!')) {
1407 return (SDDS_dataset->page_number = -1);
1411 if (SDDS_dataset->layout.lzmaFile) {
1415 return (SDDS_dataset->page_number = -1);
1419 SDDS_dataset->rowcount_offset = ftell(fp);
1420 if (!fgets(s, SDDS_MAXLINE, fp)) {
1423 return (SDDS_dataset->page_number = -1);
1425 }
while (s[0] ==
'!');
1430 if (sscanf(s,
"%" SCNd64, &n_rows) != 1 || n_rows < 0) {
1431 SDDS_SetError(
"Unable to read page--file has no (valid) number-of-rows entry (SDDS_ReadAsciiPage)");
1438 return (SDDS_dataset->page_number = -1);
1441 sparse_interval = 1;
1442 sparse_offset = n_rows - last_rows;
1443 if (sparse_offset < 0)
1446 rows_to_store = (n_rows - sparse_offset) / sparse_interval + 2;
1450 n_rows = TABLE_LENGTH_INCREMENT;
1451 rows_to_store = n_rows;
1454 if (rows_to_store >= SDDS_dataset->n_rows_allocated) {
1456 if (!
SDDS_LengthenTable(SDDS_dataset, rows_to_store - SDDS_dataset->n_rows_allocated)) {
1457 SDDS_SetError(
"Unable to read page--couldn't lengthen data page (SDDS_ReadAsciiPage)");
1463 j = end_of_data = k = 0;
1465 if (!no_row_counts && n_rows == 0) {
1466 SDDS_dataset->n_rows = 0;
1469 return (SDDS_dataset->page_number);
1472 bigBufferCopy = bigBuffer;
1474 if (j >= SDDS_dataset->n_rows_allocated) {
1477 SDDS_SetError(
"Unable to read page--couldn't lengthen data page (SDDS_ReadAsciiPage)");
1483 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
1485 if (sparse_statistics != 0) {
1488 statData = (
void**)malloc(SDDS_dataset->layout.n_columns *
sizeof(
void*));
1492 statData[i] = (
double*)calloc(sparse_interval,
sizeof(
double));
1497 if (layout->column_definition[i].definition_mode & SDDS_WRITEONLY_DEFINITION)
1501 bigBufferCopy = bigBuffer;
1504 if (SDDS_dataset->layout.gzipFile) {
1505 if (!(dataRead = fgetsGZipSkipCommentsResize(SDDS_dataset, &bigBuffer, &bigBufferSize, gzfp,
'!')) ||
SDDS_StringIsBlank(bigBuffer)) {
1506 SDDS_dataset->n_rows = j;
1507 if (no_row_counts) {
1513 gzseek(gzfp, 0L, SEEK_END);
1514 if (SDDS_dataset->autoRecover) {
1515 SDDS_dataset->autoRecovered = 1;
1519 return (SDDS_dataset->page_number);
1527 if (SDDS_dataset->layout.lzmaFile) {
1529 SDDS_dataset->n_rows = j;
1530 if (no_row_counts) {
1536 lzma_seek(lzmafp, 0L, SEEK_END);
1537 if (SDDS_dataset->autoRecover) {
1538 SDDS_dataset->autoRecovered = 1;
1542 return (SDDS_dataset->page_number);
1550 SDDS_dataset->n_rows = j;
1551 if (no_row_counts) {
1557 fseek(fp, 0L, SEEK_END);
1558 if (SDDS_dataset->autoRecover) {
1559 SDDS_dataset->autoRecovered = 1;
1563 return (SDDS_dataset->page_number);
1574 bigBufferCopy = bigBuffer;
1575 bigBufferCopySize = strlen(bigBufferCopy);
1577 if (!
SDDS_ScanData2(bigBufferCopy, &bigBufferCopy, &bigBufferCopySize, layout->column_definition[i].type, layout->column_definition[i].field_length, SDDS_dataset->data[i], j, 0)) {
1579 SDDS_dataset->n_rows = j;
1581 if (SDDS_dataset->layout.gzipFile) {
1582 gzseek(gzfp, 0L, SEEK_END);
1585 if (SDDS_dataset->layout.lzmaFile) {
1586 lzma_seek(lzmafp, 0L, SEEK_END);
1588 fseek(fp, 0L, SEEK_END);
1593 if (SDDS_dataset->autoRecover) {
1594 SDDS_dataset->autoRecovered = 1;
1598 return (SDDS_dataset->page_number);
1601 SDDS_SetError(
"Unable to read page--scanning error (SDDS_ReadAsciiPage)");
1604 if (sparse_statistics != 0) {
1605 switch (layout->column_definition[i].type) {
1607 ((
double*)statData[i])[k % sparse_interval] = (double)(((
float*)SDDS_dataset->data[i])[j]);
1610 ((
double*)statData[i])[k % sparse_interval] = ((
double*)SDDS_dataset->data[i])[j];
1613 ((
double*)statData[i])[k % sparse_interval] = (double)(((
long double*)SDDS_dataset->data[i])[j]);
1617 if (sparse_statistics == 1) {
1619 compute_average(&statResult, (
double*)statData[i], (k % sparse_interval) + 1);
1620 }
else if (sparse_statistics == 2) {
1622 compute_median(&statResult, (
double*)statData[i], (k % sparse_interval) + 1);
1623 }
else if (sparse_statistics == 3) {
1625 statResult = min_in_array((
double*)statData[i], (k % sparse_interval) + 1);
1626 }
else if (sparse_statistics == 4) {
1628 statResult = max_in_array((
double*)statData[i], (k % sparse_interval) + 1);
1631 switch (layout->column_definition[i].type) {
1633 ((
float*)SDDS_dataset->data[i])[j] = statResult;
1636 ((
double*)SDDS_dataset->data[i])[j] = statResult;
1639 ((
long double*)SDDS_dataset->data[i])[j] = statResult;
1645 fprintf(stderr,
"line remaining = %s\n", bigBuffer);
1651 if (layout->data_mode.lines_per_row != 0 && lineCount != layout->data_mode.lines_per_row) {
1652 sprintf(s,
"Unable to read page--line layout error at line %" PRId64
" of page %" PRId32
" (SDDS_ReadAsciiPage)", j + 1, SDDS_dataset->page_number);
1656 if (SDDS_dataset->layout.gzipFile) {
1657 gzseek(gzfp, 0L, SEEK_END);
1660 if (SDDS_dataset->layout.lzmaFile) {
1661 lzma_seek(lzmafp, 0L, SEEK_END);
1663 fseek(fp, 0L, SEEK_END);
1668 if (SDDS_dataset->autoRecover) {
1669 SDDS_dataset->autoRecovered = 1;
1673 return (SDDS_dataset->page_number);
1676 SDDS_dataset->n_rows = j;
1679 if (layout->data_mode.lines_per_row != 0) {
1681 bigBufferCopy = bigBuffer;
1683 if (--sparse_offset < 0 &&
1684 (((sparse_statistics == 0) && (k % sparse_interval == 0)) || ((sparse_statistics != 0) && (k % sparse_interval == sparse_interval - 1))))
1687 }
while (k < n_rows || no_row_counts);
1689 if (sparse_statistics != 0) {
1690 for (i = 0; i < SDDS_dataset->layout.n_columns; i++) {
1698 if (end_of_data && !(SDDS_dataset->page_number == 1) && j == 0 && !dataRead) {
1704 return SDDS_dataset->page_number = -1;
1706 SDDS_dataset->n_rows = j;
1711 return (SDDS_dataset->page_number);
1748int32_t
SDDS_ScanData(
char *
string, int32_t type, int32_t field_length,
void *data, int64_t index, int32_t is_parameter) {
1749 char *buffer = NULL;
1750 int32_t abs_field_length, length;
1751 int32_t bufferSize = 0;
1753 abs_field_length = abs(field_length);
1755 SDDS_SetError(
"Unable to scan data--input string is NULL (SDDS_ScanData)");
1759 SDDS_SetError(
"Unable to scan data--data pointer is NULL (SDDS_ScanData)");
1762 if (!(buffer =
SDDS_Malloc(
sizeof(*buffer) * (bufferSize = SDDS_MAXLINE)))) {
1763 SDDS_SetError(
"Unable to scan data--allocation failure (SDDS_ScanData)");
1766 if ((length = strlen(
string)) < abs_field_length)
1767 length = abs_field_length;
1768 if (bufferSize <= length) {
1769 if (!(buffer =
SDDS_Realloc(buffer,
sizeof(*buffer) * (bufferSize = 2 * length)))) {
1771 SDDS_SetError(
"Unable to scan data--allocation failure (SDDS_ScanData)");
1779 if (abs_field_length > (int32_t)strlen(
string)) {
1780 strcpy(buffer,
string);
1783 strncpy(buffer,
string, abs_field_length);
1784 buffer[field_length] = 0;
1785 strcpy(
string,
string + abs_field_length);
1788 SDDS_SetError(
"Unable to scan data--tokenizing error (SDDS_ScanData)");
1794 if (sscanf(buffer,
"%hd", ((
short *)data) + index) == 1) {
1801 if (sscanf(buffer,
"%hu", ((
unsigned short *)data) + index) == 1) {
1808 if (sscanf(buffer,
"%" SCNd32, ((int32_t *)data) + index) == 1) {
1815 if (sscanf(buffer,
"%" SCNu32, ((uint32_t *)data) + index) == 1) {
1822 if (sscanf(buffer,
"%" SCNd64, ((int64_t *)data) + index) == 1) {
1829 if (sscanf(buffer,
"%" SCNu64, ((uint64_t *)data) + index) == 1) {
1836 if (sscanf(buffer,
"%f", ((
float *)data) + index) == 1) {
1843 if (sscanf(buffer,
"%lf", ((
double *)data) + index) == 1) {
1850 if (sscanf(buffer,
"%Lf", ((
long double *)data) + index) == 1) {
1859 if (((
char **)data)[index]) {
1860 free(((
char **)data)[index]);
1861 ((
char **)data)[index] = NULL;
1863 if ((len = strlen(
string)) > 0) {
1864 if (
string[len - 1] ==
'\r')
1865 string[len - 1] = 0;
1867 if (
string[0] ==
'"')
1870 strcpy(buffer,
string);
1879 if (abs_field_length > (int32_t)strlen(
string)) {
1880 strcpy(buffer,
string);
1883 strncpy(buffer,
string, abs_field_length);
1884 buffer[abs_field_length] = 0;
1885 strcpy(
string,
string + abs_field_length);
1887 if (field_length < 0)
1891 if (((
char **)data)[index]) {
1892 free(((
char **)data)[index]);
1893 ((
char **)data)[index] = NULL;
1905 *(((
char *)data) + index) = buffer[0];
1910 SDDS_SetError(
"Unknown data type encountered (SDDS_ScanData)");
1913 SDDS_SetError(
"Unable to scan data--scanning or allocation error (SDDS_ScanData)");
1953int32_t
SDDS_ScanData2(
char *
string,
char **pstring, int32_t *strlength, int32_t type, int32_t field_length,
void *data, int64_t index, int32_t is_parameter) {
1954 char *buffer = NULL;
1955 int32_t abs_field_length, length;
1956 int32_t bufferSize = 0;
1958 abs_field_length = abs(field_length);
1960 SDDS_SetError(
"Unable to scan data--input string is NULL (SDDS_ScanData2)");
1964 SDDS_SetError(
"Unable to scan data--data pointer is NULL (SDDS_ScanData2)");
1967 if (!(buffer =
SDDS_Malloc(
sizeof(*buffer) * (bufferSize = SDDS_MAXLINE)))) {
1968 SDDS_SetError(
"Unable to scan data--allocation failure (SDDS_ScanData2)");
1971 length = *strlength;
1972 if (length < abs_field_length)
1973 length = abs_field_length;
1974 if (bufferSize <= length) {
1975 if (!(buffer =
SDDS_Realloc(buffer,
sizeof(*buffer) * (bufferSize = 2 * length)))) {
1977 SDDS_SetError(
"Unable to scan data--allocation failure (SDDS_ScanData2)");
1985 if (abs_field_length > *strlength) {
1986 strcpy(buffer,
string);
1990 strncpy(buffer,
string, abs_field_length);
1991 buffer[abs_field_length] = 0;
1992 *pstring += abs_field_length;
1993 *strlength -= abs_field_length;
1995 }
else if (
SDDS_GetToken2(
string, pstring, strlength, buffer, bufferSize) < 0) {
1996 SDDS_SetError(
"Unable to scan data--tokenizing error (SDDS_ScanData2)");
2002 if (sscanf(buffer,
"%hd", ((
short *)data) + index) == 1) {
2009 if (sscanf(buffer,
"%hu", ((
unsigned short *)data) + index) == 1) {
2016 if (sscanf(buffer,
"%" SCNd32, ((int32_t *)data) + index) == 1) {
2023 if (sscanf(buffer,
"%" SCNu32, ((uint32_t *)data) + index) == 1) {
2030 if (sscanf(buffer,
"%" SCNd64, ((int64_t *)data) + index) == 1) {
2037 if (sscanf(buffer,
"%" SCNu64, ((uint64_t *)data) + index) == 1) {
2044 if (sscanf(buffer,
"%f", ((
float *)data) + index) == 1) {
2051 if (sscanf(buffer,
"%lf", ((
double *)data) + index) == 1) {
2058 if (sscanf(buffer,
"%Lf", ((
long double *)data) + index) == 1) {
2067 if (((
char **)data)[index]) {
2068 free(((
char **)data)[index]);
2069 ((
char **)data)[index] = NULL;
2071 if ((len = *strlength) > 0) {
2072 if (*pstring[len - 1] ==
'\r') {
2073 *pstring[len - 1] = 0;
2077 if (*pstring[0] ==
'"')
2078 SDDS_GetToken2(*pstring, pstring, strlength, buffer, bufferSize);
2080 strcpy(buffer,
string);
2089 if (abs_field_length > *strlength) {
2090 strcpy(buffer,
string);
2094 strncpy(buffer,
string, abs_field_length);
2095 buffer[abs_field_length] = 0;
2096 *pstring += abs_field_length;
2097 *strlength -= abs_field_length;
2099 if (field_length < 0)
2101 }
else if (
SDDS_GetToken2(
string, pstring, strlength, buffer, bufferSize) < 0)
2103 if (((
char **)data)[index]) {
2104 free(((
char **)data)[index]);
2105 ((
char **)data)[index] = NULL;
2117 *(((
char *)data) + index) = buffer[0];
2122 SDDS_SetError(
"Unknown data type encountered (SDDS_ScanData2)");
2125 SDDS_SetError(
"Unable to scan data--scanning or allocation error (SDDS_ScanData2)");
2142 if (SDDS_dataset->layout.n_columns || SDDS_dataset->layout.n_arrays)
2144 for (i = 0; i < SDDS_dataset->layout.n_parameters; i++)
2145 if (!SDDS_dataset->layout.parameter_definition[i].fixed_value)
2170 int64_t i, rows, offset;
2174 fprintf(stderr,
"%" PRId64
" virtual rows present, first=%" PRId32
"\n",
SDDS_CountRowsOfInterest(SDDS_dataset), SDDS_dataset->first_row_in_mem);
2179 if (SDDS_dataset->layout.gzipFile) {
2180 SDDS_SetError(
"Unable to perform page updates on a gzip file (SDDS_UpdateAsciiPage)");
2184 if (SDDS_dataset->layout.lzmaFile) {
2185 SDDS_SetError(
"Unable to perform page updates on an .lzma or .xz file (SDDS_UpdateAsciiPage)");
2188 if (!SDDS_dataset->writing_page) {
2191 if (mode & FLUSH_TABLE) {
2194 SDDS_dataset->last_row_written = -1;
2195 SDDS_dataset->n_rows = 0;
2199 if (!(fp = SDDS_dataset->layout.fp)) {
2200 SDDS_SetError(
"Unable to update page--file pointer is NULL (SDDS_UpdateAsciiPage)");
2203 fBuffer = &SDDS_dataset->fBuffer;
2205 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_UpdateAsciiPage)");
2211 if (rows == SDDS_dataset->n_rows_written)
2213 if (rows < SDDS_dataset->n_rows_written) {
2214 SDDS_SetError(
"Unable to update page--new number of rows less than previous number (SDDS_UpdateAsciiPage)");
2217 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))) {
2218 if (!SDDS_dataset->layout.data_mode.no_row_counts) {
2219 if (
SDDS_fseek(fp, SDDS_dataset->rowcount_offset, SEEK_SET) == -1) {
2220 SDDS_SetError(
"Unable to update page--failure doing fseek (SDDS_UpdateAsciiPage)");
2224 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
2225 if ((rows - SDDS_dataset->n_rows_written) + 1 > SDDS_dataset->layout.data_mode.fixed_row_increment) {
2226 SDDS_dataset->layout.data_mode.fixed_row_increment = (rows - SDDS_dataset->n_rows_written) + 1;
2228 fprintf(fp,
"%20" PRId64
"\n", ((rows / SDDS_dataset->layout.data_mode.fixed_row_increment) + 2) * SDDS_dataset->layout.data_mode.fixed_row_increment);
2230 fprintf(fp,
"%20" PRId64
"\n", rows);
2231 if (
SDDS_fseek(fp, offset, SEEK_SET) == -1) {
2232 SDDS_SetError(
"Unable to update page--failure doing fseek to end of page (SDDS_UpdateAsciiPage)");
2237 for (i = SDDS_dataset->last_row_written + 1; i < SDDS_dataset->n_rows; i++)
2238 if (SDDS_dataset->row_flag[i])
2241 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_UpdateAsciiPage)");
2244 SDDS_dataset->last_row_written = SDDS_dataset->n_rows - 1;
2245 SDDS_dataset->n_rows_written = rows;
2246 if (mode & FLUSH_TABLE) {
2248 SDDS_dataset->first_row_in_mem = rows;
2249 SDDS_dataset->last_row_written = -1;
2250 SDDS_dataset->n_rows = 0;
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_UpdateAsciiPage(SDDS_DATASET *SDDS_dataset, uint32_t mode)
Updates the current ASCII page of an SDDS dataset with new data.
int32_t SDDS_ScanData2(char *string, char **pstring, int32_t *strlength, 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, optimized for long strings.
int32_t SDDS_LZMAWriteAsciiArrays(SDDS_DATASET *SDDS_dataset, struct lzmafile *lzmafp)
Writes the arrays of an SDDS dataset in ASCII format to an LZMA compressed file.
int32_t SDDS_ReadAsciiPageDetailed(SDDS_DATASET *SDDS_dataset, int64_t sparse_interval, int64_t sparse_offset, int64_t last_rows, int32_t sparse_statistics)
Reads a detailed page of data from an ASCII file into an SDDS dataset with optional sparsity and stat...
int32_t SDDS_WriteAsciiPage(SDDS_DATASET *SDDS_dataset)
Writes a page of data in ASCII format to the SDDS dataset.
int32_t SDDS_LZMAWriteAsciiParameters(SDDS_DATASET *SDDS_dataset, struct lzmafile *lzmafp)
Writes the parameter data of an SDDS dataset in ASCII format to an LZMA compressed file.
int32_t SDDS_WriteAsciiRow(SDDS_DATASET *SDDS_dataset, int64_t row, FILE *fp)
Writes a single row of data in ASCII format to a file.
int32_t SDDS_WriteAsciiParameters(SDDS_DATASET *SDDS_dataset, FILE *fp)
Writes the parameter data of an SDDS dataset in ASCII format to a file.
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_AsciiDataExpected(SDDS_DATASET *SDDS_dataset)
Checks whether the SDDS dataset expects ASCII data input.
int32_t SDDS_ReadAsciiArrays(SDDS_DATASET *SDDS_dataset)
Reads the arrays from an ASCII file into the SDDS dataset.
int32_t SDDS_LZMAWriteAsciiRow(SDDS_DATASET *SDDS_dataset, int64_t row, struct lzmafile *lzmafp)
Writes a single row of data in ASCII format to an LZMA compressed file.
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.
int32_t SDDS_WriteTypedValue(void *data, int64_t index, int32_t type, char *format, FILE *fp)
Writes a typed value to an ASCII file stream.
int32_t SDDS_ReadAsciiParameters(SDDS_DATASET *SDDS_dataset)
Reads the parameters from an ASCII file into the SDDS dataset.
int32_t SDDS_LZMAWriteTypedValue(void *data, int64_t index, int32_t type, char *format, struct lzmafile *lzmafp)
Writes a typed value to an LZMA compressed ASCII file stream.
int32_t SDDS_WriteAsciiArrays(SDDS_DATASET *SDDS_dataset, FILE *fp)
Writes the arrays of an SDDS dataset in ASCII format to a file.
void SDDS_SetReadRecoveryMode(SDDS_DATASET *SDDS_dataset, int32_t mode)
Sets the read recovery mode for an SDDS dataset.
int32_t SDDS_FlushBuffer(FILE *fp, SDDS_FILEBUFFER *fBuffer)
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_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.
char * fgetsLZMASkipCommentsResize(SDDS_DATASET *SDDS_dataset, char **s, int32_t *slen, struct lzmafile *lzmafp, char skip_char)
Reads a line from a LZMA-compressed file with dynamic buffer resizing while skipping comment lines.
char * fgetsLZMASkipComments(SDDS_DATASET *SDDS_dataset, char *s, int32_t slen, struct lzmafile *lzmafp, char skip_char)
Reads a line from a LZMA-compressed file while skipping comment lines.
void SDDS_InterpretEscapes(char *s)
Interprets and converts escape sequences in a string.
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
int32_t SDDS_ZeroMemory(void *mem, int64_t n_bytes)
Sets a block of memory to zero.
int32_t SDDS_FreeArrayDefinition(ARRAY_DEFINITION *source)
Frees memory allocated for an array definition.
char * fgetsSkipComments(SDDS_DATASET *SDDS_dataset, char *s, int32_t slen, FILE *fp, char skip_char)
Reads a line from a file while skipping comment lines.
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.
int32_t SDDS_StringIsBlank(char *s)
Checks if a string is blank (contains only whitespace characters).
int32_t SDDS_GetToken(char *s, char *buffer, int32_t buflen)
Extracts the next token from a string, handling quoted substrings and escape characters.
ARRAY_DEFINITION * SDDS_CopyArrayDefinition(ARRAY_DEFINITION **target, ARRAY_DEFINITION *source)
Creates a copy of an array definition.
int32_t SDDS_CopyString(char **target, const char *source)
Copies a source string to a target string with memory allocation.
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
int32_t SDDS_GetToken2(char *s, char **st, int32_t *strlength, char *buffer, int32_t buflen)
Extracts the next token from a string, handling quoted substrings and escape characters,...
char * fgetsSkipCommentsResize(SDDS_DATASET *SDDS_dataset, char **s, int32_t *slen, FILE *fp, char skip_char)
Reads a line from a file with dynamic buffer resizing while skipping comment lines.
void SDDS_RemovePadding(char *s)
Removes leading and trailing whitespace from a string.
int32_t SDDS_HasWhitespace(char *string)
Checks if a string contains any whitespace characters.
#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.