21#include "match_string.h"
24#include "mdb_thread.h"
32# define pclose(x) _pclose(x)
34# if defined(__BORLANDC__)
35# define _setmode(handle, amode) setmode(handle, amode)
56 if (
sizeof(gzFile) !=
sizeof(
void *)) {
57 SDDS_SetError(
"gzFile is not the same size as void *, possible corruption of the SDDS_LAYOUT structure");
64 sprintf(s,
"Unable to initialize input for file %s--can't zero SDDS_DATASET structure (SDDS_InitializeInput)", filename);
68 SDDS_dataset->layout.gzipFile = SDDS_dataset->layout.lzmaFile = SDDS_dataset->layout.disconnected = SDDS_dataset->layout.popenUsed = 0;
69 SDDS_dataset->layout.depth = SDDS_dataset->layout.data_command_seen = SDDS_dataset->layout.commentFlags = SDDS_dataset->deferSavingLayout = 0;
70 SDDS_dataset->layout.data_mode.column_memory_mode = DEFAULT_COLUMN_MEMORY_MODE;
72 SDDS_dataset->layout.filename = NULL;
74 sprintf(s,
"Memory allocation failure initializing file \"%s\" (SDDS_InitializeInput)", filename);
80 if (_setmode(_fileno(stdin), _O_BINARY) == -1) {
81 sprintf(s,
"unable to set stdin to binary mode");
86 SDDS_dataset->layout.fp = stdin;
89 if (!(extension = strrchr(filename,
'.')) || strcmp(extension,
".gz") != 0) {
91 if ((extension = strrchr(filename,
'.')) && ((strcmp(extension,
".lzma") == 0) || (strcmp(extension,
".xz") == 0))) {
92 SDDS_dataset->layout.lzmaFile = 1;
93 if (!(SDDS_dataset->layout.lzmafp = UnpackLZMAOpen(filename))) {
94 sprintf(s,
"Unable to open file \"%s\" for reading (SDDS_InitializeInput)", filename);
98 SDDS_dataset->layout.fp = SDDS_dataset->layout.lzmafp->fp;
100 if (!(SDDS_dataset->layout.fp =
UnpackFopen(filename, UNPACK_REQUIRE_SDDS | UNPACK_USE_PIPE, &SDDS_dataset->layout.popenUsed, NULL))) {
101 sprintf(s,
"Unable to open file \"%s\" for reading (SDDS_InitializeInput)", filename);
108 SDDS_dataset->layout.gzipFile = 1;
109 if (!(SDDS_dataset->layout.gzfp = gzopen(filename,
"rb"))) {
110 sprintf(s,
"Unable to open file \"%s\" for reading (SDDS_InitializeInput)", filename);
117 SDDS_dataset->page_number = SDDS_dataset->page_started = 0;
118 SDDS_dataset->file_had_data = 0;
121 if (SDDS_dataset->layout.gzipFile) {
122 if (!SDDS_GZipReadLayout(SDDS_dataset, SDDS_dataset->layout.gzfp))
126 if (SDDS_dataset->layout.lzmaFile) {
136 SDDS_dataset->layout.layout_written = 0;
140 if (SDDS_dataset->layout.n_columns &&
141 ((!(SDDS_dataset->column_flag = (int32_t *)
SDDS_Malloc(
sizeof(int32_t) * SDDS_dataset->layout.n_columns)) ||
142 !(SDDS_dataset->column_order = (int32_t *)
SDDS_Malloc(
sizeof(int32_t) * SDDS_dataset->layout.n_columns))) ||
143 (!
SDDS_SetMemory(SDDS_dataset->column_flag, SDDS_dataset->layout.n_columns,
SDDS_LONG, (int32_t)1, (int32_t)0) ||
144 !
SDDS_SetMemory(SDDS_dataset->column_order, SDDS_dataset->layout.n_columns,
SDDS_LONG, (int32_t)0, (int32_t)1)))) {
145 SDDS_SetError(
"Unable to initialize input--memory allocation failure (SDDS_InitializeInput)");
148 SDDS_dataset->mode = SDDS_READMODE;
149 SDDS_dataset->pagecount_offset = NULL;
150 if (!SDDS_dataset->layout.gzipFile && !SDDS_dataset->layout.lzmaFile && !SDDS_dataset->layout.popenUsed && SDDS_dataset->layout.filename) {
156 SDDS_dataset->pages_read = 0;
157 SDDS_dataset->pagecount_offset = malloc(
sizeof(*SDDS_dataset->pagecount_offset));
158 SDDS_dataset->pagecount_offset[0] = ftell(SDDS_dataset->layout.fp);
159 fseek(SDDS_dataset->layout.fp, 0, 2);
160 SDDS_dataset->endOfFile_offset = ftell(SDDS_dataset->layout.fp);
161 fseek(SDDS_dataset->layout.fp, SDDS_dataset->pagecount_offset[0], 0);
182 SDDS_SetError(
"Unable to initialize input--can't zero SDDS_DATASET structure (SDDS_InitializeInput)");
185 SDDS_dataset->layout.gzipFile = SDDS_dataset->layout.lzmaFile = 0;
186 SDDS_dataset->layout.depth = SDDS_dataset->layout.data_command_seen = SDDS_dataset->layout.commentFlags = SDDS_dataset->deferSavingLayout = 0;
187 if (!(SDDS_dataset->layout.fp = fopen(filename, FOPEN_READ_MODE))) {
192 SDDS_SetError(
"Memory allocation failure (SDDS_InitializeInput)");
195 SDDS_dataset->mode = SDDS_READMODE;
196 SDDS_dataset->page_number = SDDS_dataset->page_started = 0;
197 SDDS_dataset->pages_read = 0;
198 SDDS_dataset->pagecount_offset = malloc(
sizeof(*SDDS_dataset->pagecount_offset));
199 SDDS_dataset->pagecount_offset[0] = ftell(SDDS_dataset->layout.fp);
200 fseek(SDDS_dataset->layout.fp, 0, 2);
201 SDDS_dataset->endOfFile_offset = ftell(SDDS_dataset->layout.fp);
202 fseek(SDDS_dataset->layout.fp, SDDS_dataset->pagecount_offset[0], 0);
219 int32_t in_quoted_section;
222 if (*position == quotation_mark)
225 in_quoted_section = 0;
228 if (*
string == quotation_mark && (
string == string0 || *(
string - 1) !=
'\\'))
229 in_quoted_section = !in_quoted_section;
230 else if (
string == position)
231 return (in_quoted_section);
250 char *ptr, *flag, *buffer0;
256 if ((ptr = strchr(buffer,
'&')) && !
SDDS_IsQuoted(buffer, ptr,
'"'))
261 n = strlen(buffer) - 1;
262 if (buffer[n] ==
'\n') {
264 if ((n - 1 >= 0) && (buffer[n - 1] ==
'\r'))
274 while (*ptr !=
'"' && *ptr)
281 if (strncmp(ptr,
"&end", 4) == 0)
291 if ((n = strlen(buffer)) >= 4) {
292 ptr = buffer + n - 4;
294 if (*ptr ==
'&' && (ptr == buffer || *(ptr - 1) !=
'\\') && strncmp(ptr,
"&end", 4) == 0 && !
SDDS_IsQuoted(buffer, ptr,
'"')) {
306 buflen -= strlen(buffer);
307 buffer += strlen(buffer);
310 n = strlen(buffer) - 1;
311 if (buffer[n] ==
'\n') {
313 if ((n - 1 >= 0) && (buffer[n - 1] ==
'\r'))
316 if ((ptr = strstr(buffer,
"&end")) && !
SDDS_IsQuoted(buffer0, ptr,
'"'))
318 buflen -= strlen(buffer);
319 buffer += strlen(buffer);
346 char *ptr, *flag, *buffer0;
352 if ((ptr = strchr(buffer,
'&')) && !
SDDS_IsQuoted(buffer, ptr,
'"'))
357 n = strlen(buffer) - 1;
358 if (buffer[n] ==
'\n') {
360 if ((n - 1 >= 0) && (buffer[n - 1] ==
'\r'))
370 while (*ptr !=
'"' && *ptr)
377 if (strncmp(ptr,
"&end", 4) == 0)
387 if ((n = strlen(buffer)) >= 4) {
388 ptr = buffer + n - 4;
390 if (*ptr ==
'&' && (ptr == buffer || *(ptr - 1) !=
'\\') && strncmp(ptr,
"&end", 4) == 0 && !
SDDS_IsQuoted(buffer, ptr,
'"')) {
402 buflen -= strlen(buffer);
403 buffer += strlen(buffer);
405 n = strlen(buffer) - 1;
406 if (buffer[n] ==
'\n') {
408 if ((n - 1 >= 0) && (buffer[n - 1] ==
'\r'))
411 if ((ptr = strstr(buffer,
"&end")) && !
SDDS_IsQuoted(buffer0, ptr,
'"'))
413 buflen -= strlen(buffer);
414 buffer += strlen(buffer);
434int32_t SDDS_GetGZipNamelist(
SDDS_DATASET *SDDS_dataset,
char *buffer, int32_t buflen, gzFile gzfp) {
435 char *ptr, *flag, *buffer0;
440 while ((flag = fgetsGZipSkipComments(SDDS_dataset, buffer, buflen, gzfp,
'!'))) {
441 if ((ptr = strchr(buffer,
'&')) && !
SDDS_IsQuoted(buffer, ptr,
'"'))
446 n = strlen(buffer) - 1;
447 if (buffer[n] ==
'\n') {
449 if ((n - 1 >= 0) && (buffer[n - 1] ==
'\r'))
459 while (*ptr !=
'"' && *ptr)
466 if (strncmp(ptr,
"&end", 4) == 0)
476 if ((n = strlen(buffer)) >= 4) {
477 ptr = buffer + n - 4;
479 if (*ptr ==
'&' && (ptr == buffer || *(ptr - 1) !=
'\\') && strncmp(ptr,
"&end", 4) == 0 && !
SDDS_IsQuoted(buffer, ptr,
'"')) {
491 buflen -= strlen(buffer);
492 buffer += strlen(buffer);
493 while ((flag = fgetsGZipSkipComments(SDDS_dataset, buffer, buflen, gzfp,
'!'))) {
494 n = strlen(buffer) - 1;
495 if (buffer[n] ==
'\n') {
497 if ((n - 1 >= 0) && (buffer[n - 1] ==
'\r'))
500 if ((ptr = strstr(buffer,
"&end")) && !
SDDS_IsQuoted(buffer0, ptr,
'"'))
502 buflen -= strlen(buffer);
503 buffer += strlen(buffer);
519 char buffer[SDDS_MAXLINE];
520 char *groupName, *ptr;
522 int32_t retval, bigEndianMachine;
523 uint32_t commentFlags;
526 SDDS_SetError(
"Unable to read layout--NULL file pointer (SDDS_ReadLayout)");
529 if (SDDS_dataset->layout.depth == 0) {
530 if (SDDS_dataset->layout.disconnected) {
531 SDDS_SetError(
"Can't read layout--file is disconnected (SDDS_ReadLayout)");
538 SDDS_dataset->layout.layout_written = 1;
539 if (!fgets(SDDS_dataset->layout.s, SDDS_MAXLINE, fp)) {
541 SDDS_SetError(
"Unable to read layout--no header lines found (SDDS_ReadLayout)");
544 if (strncmp(SDDS_dataset->layout.s,
"SDDS", 4) != 0) {
546 SDDS_SetError(
"Unable to read layout--no header lines found (SDDS_ReadLayout)");
549 if (sscanf(SDDS_dataset->layout.s + 4,
"%" SCNd32, &SDDS_dataset->layout.version) != 1) {
551 SDDS_SetError(
"Unable to read layout--no version number on first line (SDDS_ReadLayout)");
555 SDDS_dataset->layout.data_command_seen = 0;
557 while (
SDDS_GetNamelist(SDDS_dataset, SDDS_dataset->layout.s, SDDS_MAXLINE, fp)) {
559 strcpy(buffer, SDDS_dataset->layout.s);
561 groupName = SDDS_dataset->layout.s + 1;
562 if (!(ptr = strpbrk(SDDS_dataset->layout.s,
" \t"))) {
563 SDDS_SetError(
"Unable to read layout---no groupname in namelist (SDDS_ReadLayout)");
568 case SDDS_DESCRIPTION_COMMAND:
571 SDDS_SetError(
"Unable to process description (SDDS_ReadLayout)");
575 case SDDS_COLUMN_COMMAND:
578 SDDS_SetError(
"Unable to process column definition (SDDS_ReadLayout)");
582 case SDDS_PARAMETER_COMMAND:
585 SDDS_SetError(
"Unable to process parameter definition (SDDS_ReadLayout)");
589 case SDDS_ASSOCIATE_COMMAND:
590#if RW_ASSOCIATES != 0
593 SDDS_SetError(
"Unable to process associate definition (SDDS_ReadLayout)");
598 case SDDS_DATA_COMMAND:
601 SDDS_SetError(
"Unable to process data mode (SDDS_ReadLayout)");
604 if (SDDS_dataset->layout.data_command_seen) {
607 SDDS_SetError(
"Unable to read layout--multiple data commands (SDDS_ReadLayout)");
611 SDDS_SetError(
"Unable to read layout--couldn't save layout (SDDS_ReadLayout)");
614 SDDS_dataset->layout.data_command_seen = 1;
616 if ((commentFlags & SDDS_BIGENDIAN_SEEN) && (commentFlags & SDDS_LITTLEENDIAN_SEEN)) {
617 SDDS_SetError(
"Unable to read data as it says it is both big and little endian (SDDS_ReadLayout)");
621 SDDS_dataset->swapByteOrder = SDDS_dataset->layout.byteOrderDeclared = 0;
622 SDDS_dataset->autoRecover = 0;
623 if ((commentFlags & SDDS_BIGENDIAN_SEEN) || (SDDS_dataset->layout.data_mode.endian == SDDS_BIGENDIAN)) {
624 SDDS_dataset->layout.byteOrderDeclared = SDDS_BIGENDIAN_SEEN;
625 if (!bigEndianMachine)
626 SDDS_dataset->swapByteOrder = 1;
628 if ((commentFlags & SDDS_LITTLEENDIAN_SEEN) || (SDDS_dataset->layout.data_mode.endian == SDDS_LITTLEENDIAN)) {
629 SDDS_dataset->layout.byteOrderDeclared = SDDS_LITTLEENDIAN_SEEN;
630 if (bigEndianMachine)
631 SDDS_dataset->swapByteOrder = 1;
633 if ((commentFlags & SDDS_FIXED_ROWCOUNT_SEEN) || (SDDS_dataset->layout.data_mode.fixed_row_count))
637 case SDDS_INCLUDE_COMMAND:
640 SDDS_SetError(
"Unable to process include command (SDDS_ReadLayout)");
643 SDDS_dataset->layout.depth += 1;
645 SDDS_dataset->layout.depth -= 1;
650 if (SDDS_dataset->layout.data_command_seen) {
654 case SDDS_ARRAY_COMMAND:
657 SDDS_SetError(
"Unable to process array definition (SDDS_ReadLayout)");
663 sprintf(buffer,
"Unknown layout entry %s given (SDDS_ReadLayout)", groupName);
669 if ((feof(fp) && SDDS_dataset->layout.depth != 0) || SDDS_dataset->layout.data_command_seen)
682 char buffer[SDDS_MAXLINE];
683 char *groupName, *ptr;
685 int32_t retval, bigEndianMachine;
686 uint32_t commentFlags;
689 SDDS_SetError(
"Unable to read layout--NULL file pointer (SDDS_LZMAReadLayout)");
692 if (SDDS_dataset->layout.depth == 0) {
693 if (SDDS_dataset->layout.disconnected) {
694 SDDS_SetError(
"Can't read layout--file is disconnected (SDDS_LZMAReadLayout)");
701 SDDS_dataset->layout.layout_written = 1;
702 if (!lzma_gets(SDDS_dataset->layout.s, SDDS_MAXLINE, lzmafp)) {
704 SDDS_SetError(
"Unable to read layout--no header lines found (SDDS_LZMAReadLayout)");
707 if (strncmp(SDDS_dataset->layout.s,
"SDDS", 4) != 0) {
709 SDDS_SetError(
"Unable to read layout--no header lines found (SDDS_LZMAReadLayout)");
712 if (sscanf(SDDS_dataset->layout.s + 4,
"%" SCNd32, &SDDS_dataset->layout.version) != 1) {
714 SDDS_SetError(
"Unable to read layout--no version number on first line (SDDS_LZMAReadLayout)");
718 SDDS_dataset->layout.data_command_seen = 0;
722 strcpy(buffer, SDDS_dataset->layout.s);
724 groupName = SDDS_dataset->layout.s + 1;
725 if (!(ptr = strpbrk(SDDS_dataset->layout.s,
" \t"))) {
726 SDDS_SetError(
"Unable to read layout---no groupname in namelist (SDDS_LZMAReadLayout)");
731 case SDDS_DESCRIPTION_COMMAND:
734 SDDS_SetError(
"Unable to process description (SDDS_LZMAReadLayout)");
738 case SDDS_COLUMN_COMMAND:
741 SDDS_SetError(
"Unable to process column definition (SDDS_LZMAReadLayout)");
745 case SDDS_PARAMETER_COMMAND:
748 SDDS_SetError(
"Unable to process parameter definition (SDDS_LZMAReadLayout)");
752 case SDDS_ASSOCIATE_COMMAND:
753#if RW_ASSOCIATES != 0
756 SDDS_SetError(
"Unable to process associate definition (SDDS_LZMAReadLayout)");
761 case SDDS_DATA_COMMAND:
764 SDDS_SetError(
"Unable to process data mode (SDDS_LZMAReadLayout)");
767 if (SDDS_dataset->layout.data_command_seen) {
770 SDDS_SetError(
"Unable to read layout--multiple data commands (SDDS_LZMAReadLayout)");
774 SDDS_SetError(
"Unable to read layout--couldn't save layout (SDDS_LZMAReadLayout)");
777 SDDS_dataset->layout.data_command_seen = 1;
779 if ((commentFlags & SDDS_BIGENDIAN_SEEN) && (commentFlags & SDDS_LITTLEENDIAN_SEEN)) {
780 SDDS_SetError(
"Unable to read data as it says it is both big and little endian (SDDS_LZMAReadLayout)");
784 SDDS_dataset->swapByteOrder = SDDS_dataset->layout.byteOrderDeclared = 0;
785 SDDS_dataset->autoRecover = 0;
786 if ((commentFlags & SDDS_BIGENDIAN_SEEN) || (SDDS_dataset->layout.data_mode.endian == SDDS_BIGENDIAN)) {
787 SDDS_dataset->layout.byteOrderDeclared = SDDS_BIGENDIAN_SEEN;
788 if (!bigEndianMachine)
789 SDDS_dataset->swapByteOrder = 1;
791 if ((commentFlags & SDDS_LITTLEENDIAN_SEEN) || (SDDS_dataset->layout.data_mode.endian == SDDS_LITTLEENDIAN)) {
792 SDDS_dataset->layout.byteOrderDeclared = SDDS_LITTLEENDIAN_SEEN;
793 if (bigEndianMachine)
794 SDDS_dataset->swapByteOrder = 1;
796 if ((commentFlags & SDDS_FIXED_ROWCOUNT_SEEN) || (SDDS_dataset->layout.data_mode.fixed_row_count))
800 case SDDS_INCLUDE_COMMAND:
803 SDDS_SetError(
"Unable to process include command (SDDS_LZMAReadLayout)");
806 SDDS_dataset->layout.depth += 1;
808 SDDS_dataset->layout.depth -= 1;
813 if (SDDS_dataset->layout.data_command_seen) {
817 case SDDS_ARRAY_COMMAND:
820 SDDS_SetError(
"Unable to process array definition (SDDS_LZMAReadLayout)");
826 sprintf(buffer,
"Unknown layout entry %s given (SDDS_LZMAReadLayout)", groupName);
832 if ((lzma_eof(lzmafp) && SDDS_dataset->layout.depth != 0) || SDDS_dataset->layout.data_command_seen)
845int32_t SDDS_GZipReadLayout(
SDDS_DATASET *SDDS_dataset, gzFile gzfp) {
846 char buffer[SDDS_MAXLINE];
847 char *groupName, *ptr;
849 int32_t retval, bigEndianMachine;
850 uint32_t commentFlags;
853 SDDS_SetError(
"Unable to read layout--NULL file pointer (SDDS_GZipReadLayout)");
856 if (SDDS_dataset->layout.disconnected) {
857 SDDS_SetError(
"Can't read layout--file is disconnected (SDDS_GZipReadLayout)");
864 SDDS_dataset->layout.layout_written = 1;
865 if (!gzgets(gzfp, SDDS_dataset->layout.s, SDDS_MAXLINE)) {
867 SDDS_SetError(
"Unable to read layout--no header lines found (SDDS_GZipReadLayout)");
870 if (strncmp(SDDS_dataset->layout.s,
"SDDS", 4) != 0) {
872 SDDS_SetError(
"Unable to read layout--no header lines found (SDDS_GZipReadLayout)");
875 if (sscanf(SDDS_dataset->layout.s + 4,
"%" SCNd32, &SDDS_dataset->layout.version) != 1) {
877 SDDS_SetError(
"Unable to read layout--no version number on first line (SDDS_GZipReadLayout)");
881 if (SDDS_dataset->layout.depth == 0)
882 SDDS_dataset->layout.data_command_seen = 0;
883 while (SDDS_GetGZipNamelist(SDDS_dataset, SDDS_dataset->layout.s, SDDS_MAXLINE, gzfp)) {
885 strcpy(buffer, SDDS_dataset->layout.s);
887 groupName = SDDS_dataset->layout.s + 1;
888 if (!(ptr = strpbrk(SDDS_dataset->layout.s,
" \t"))) {
889 SDDS_SetError(
"Unable to read layout---no groupname in namelist (SDDS_GZipReadLayout)");
894 case SDDS_DESCRIPTION_COMMAND:
897 SDDS_SetError(
"Unable to process description (SDDS_GZipReadLayout)");
901 case SDDS_COLUMN_COMMAND:
904 SDDS_SetError(
"Unable to process column definition (SDDS_GZipReadLayout)");
908 case SDDS_PARAMETER_COMMAND:
911 SDDS_SetError(
"Unable to process parameter definition (SDDS_GZipReadLayout)");
915 case SDDS_ASSOCIATE_COMMAND:
916# if RW_ASSOCIATES != 0
919 SDDS_SetError(
"Unable to process associate definition (SDDS_GZipReadLayout)");
924 case SDDS_DATA_COMMAND:
927 SDDS_SetError(
"Unable to process data mode (SDDS_GZipReadLayout)");
930 if (SDDS_dataset->layout.data_command_seen) {
933 SDDS_SetError(
"Unable to read layout--multiple data commands (SDDS_GZipReadLayout)");
937 SDDS_SetError(
"Unable to read layout--couldn't save layout (SDDS_GZipReadLayout)");
940 SDDS_dataset->layout.data_command_seen = 1;
942 if ((commentFlags & SDDS_BIGENDIAN_SEEN) && (commentFlags & SDDS_LITTLEENDIAN_SEEN)) {
943 SDDS_SetError(
"Unable to read data as it says it is both big and little endian (SDDS_ReadLayout)");
947 SDDS_dataset->swapByteOrder = SDDS_dataset->layout.byteOrderDeclared = 0;
948 SDDS_dataset->autoRecover = 0;
949 if ((commentFlags & SDDS_BIGENDIAN_SEEN) || (SDDS_dataset->layout.data_mode.endian == SDDS_BIGENDIAN)) {
950 SDDS_dataset->layout.byteOrderDeclared = SDDS_BIGENDIAN_SEEN;
951 if (!bigEndianMachine)
952 SDDS_dataset->swapByteOrder = 1;
954 if ((commentFlags & SDDS_LITTLEENDIAN_SEEN) || (SDDS_dataset->layout.data_mode.endian == SDDS_LITTLEENDIAN)) {
955 SDDS_dataset->layout.byteOrderDeclared = SDDS_LITTLEENDIAN_SEEN;
956 if (bigEndianMachine)
957 SDDS_dataset->swapByteOrder = 1;
959 if ((commentFlags & SDDS_FIXED_ROWCOUNT_SEEN) || (SDDS_dataset->layout.data_mode.fixed_row_count))
963 case SDDS_INCLUDE_COMMAND:
966 SDDS_SetError(
"Unable to process include command (SDDS_GZipReadLayout)");
969 SDDS_dataset->layout.depth += 1;
971 SDDS_dataset->layout.depth -= 1;
976 if (SDDS_dataset->layout.data_command_seen) {
980 case SDDS_ARRAY_COMMAND:
983 SDDS_SetError(
"Unable to process array definition (SDDS_GZipReadLayout)");
989 sprintf(buffer,
"Unknown layout entry %s given (SDDS_GZipReadLayout)", groupName);
995 if ((gzeof(gzfp) && SDDS_dataset->layout.depth != 0) || SDDS_dataset->layout.data_command_seen)
1009 if (SDDS_dataset->parallel_io)
1024 if (SDDS_dataset->layout.disconnected) {
1025 SDDS_SetError(
"Can't check status--file is disconnected (SDDS_EndOfFile)");
1029 if (SDDS_dataset->layout.gzipFile) {
1030 if (!SDDS_dataset->layout.gzfp) {
1031 SDDS_SetError(
"Unable to check status--NULL file pointer (SDDS_EndOfFile)");
1036 if (SDDS_dataset->layout.lzmaFile) {
1037 if (!SDDS_dataset->layout.lzmafp) {
1038 SDDS_SetError(
"Unable to check status--NULL file pointer (SDDS_EndOfFile)");
1042 if (!SDDS_dataset->layout.fp) {
1043 SDDS_SetError(
"Unable to check status--NULL file pointer (SDDS_EndOfFile)");
1050 if (SDDS_dataset->fBuffer.bufferSize && SDDS_dataset->fBuffer.bytesLeft) {
1055 if (SDDS_dataset->layout.gzipFile) {
1056 if (gzeof(SDDS_dataset->layout.gzfp))
1060 if (SDDS_dataset->layout.lzmaFile) {
1061 if (lzma_eof(SDDS_dataset->layout.lzmafp))
1064 if (feof(SDDS_dataset->layout.fp))
1091 if (SDDS_dataset->layout.disconnected) {
1092 SDDS_SetError(
"Can't read page--file is disconnected (SDDS_ReadPageSparse)");
1096 if (SDDS_dataset->layout.gzipFile) {
1097 if (!SDDS_dataset->layout.gzfp) {
1098 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadPageSparse)");
1103 if (SDDS_dataset->layout.lzmaFile) {
1104 if (!SDDS_dataset->layout.lzmafp) {
1105 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadPageSparse)");
1109 if (!SDDS_dataset->layout.fp) {
1110 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadPageSparse)");
1117 if (SDDS_dataset->original_layout.data_mode.mode == SDDS_ASCII) {
1118 if ((retval =
SDDS_ReadAsciiPage(SDDS_dataset, sparse_interval, sparse_offset, sparse_statistics)) < 1) {
1121 }
else if (SDDS_dataset->original_layout.data_mode.mode == SDDS_BINARY) {
1122 if ((retval =
SDDS_ReadBinaryPage(SDDS_dataset, sparse_interval, sparse_offset, sparse_statistics)) < 1) {
1126 SDDS_SetError(
"Unable to read page--unrecognized data mode (SDDS_ReadPageSparse)");
1129 if (!SDDS_dataset->layout.gzipFile && !SDDS_dataset->layout.lzmaFile && !SDDS_dataset->layout.popenUsed && SDDS_dataset->layout.filename && SDDS_dataset->pagecount_offset) {
1136 if (SDDS_dataset->pagecount_offset[SDDS_dataset->pages_read] < SDDS_dataset->endOfFile_offset) {
1137 SDDS_dataset->pages_read++;
1138 if (!(SDDS_dataset->pagecount_offset = realloc(SDDS_dataset->pagecount_offset,
sizeof(int64_t) * (SDDS_dataset->pages_read + 1)))) {
1139 SDDS_SetError(
"Unable to allocate memory for pagecount_offset (SDDS_ReadPageSparse)");
1142 SDDS_dataset->pagecount_offset[SDDS_dataset->pages_read] = ftell(SDDS_dataset->layout.fp);
1145 SDDS_dataset->pages_read++;
1162 if (SDDS_dataset->layout.disconnected) {
1163 SDDS_SetError(
"Can't read page--file is disconnected (SDDS_ReadPageLastRows)");
1167 if (SDDS_dataset->layout.gzipFile) {
1168 if (!SDDS_dataset->layout.gzfp) {
1169 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadPageLastRows)");
1174 if (SDDS_dataset->layout.lzmaFile) {
1175 if (!SDDS_dataset->layout.lzmafp) {
1176 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadPageLastRows)");
1180 if (!SDDS_dataset->layout.fp) {
1181 SDDS_SetError(
"Unable to read page--NULL file pointer (SDDS_ReadPageLastRows)");
1188 if (SDDS_dataset->original_layout.data_mode.mode == SDDS_ASCII) {
1192 }
else if (SDDS_dataset->original_layout.data_mode.mode == SDDS_BINARY) {
1197 SDDS_SetError(
"Unable to read page--unrecognized data mode (SDDS_ReadPageLastRows)");
1200 if (!SDDS_dataset->layout.gzipFile && !SDDS_dataset->layout.lzmaFile && !SDDS_dataset->layout.popenUsed && SDDS_dataset->layout.filename && SDDS_dataset->pagecount_offset) {
1207 if (SDDS_dataset->pagecount_offset[SDDS_dataset->pages_read] < SDDS_dataset->endOfFile_offset) {
1208 SDDS_dataset->pages_read++;
1209 if (!(SDDS_dataset->pagecount_offset = realloc(SDDS_dataset->pagecount_offset,
sizeof(int64_t) * (SDDS_dataset->pages_read + 1)))) {
1210 SDDS_SetError(
"Unable to allocate memory for pagecount_offset (SDDS_ReadPageLastRows)");
1213 SDDS_dataset->pagecount_offset[SDDS_dataset->pages_read] = ftell(SDDS_dataset->layout.fp);
1216 SDDS_dataset->pages_read++;
1227static int64_t SDDS_RowLimit = INT64_MAX;
1229static int64_t SDDS_GetLockedRowLimit(
void) {
1232 limit = SDDS_RowLimit;
1248 previous = SDDS_RowLimit;
1249 SDDS_RowLimit = limit;
1260 return SDDS_GetLockedRowLimit();
1278 if (SDDS_dataset->layout.disconnected) {
1279 SDDS_SetError(
"Can't go to page--file is disconnected (SDDS_GotoPage)");
1282 if (SDDS_dataset->layout.popenUsed || !SDDS_dataset->layout.filename) {
1283 SDDS_SetError(
"Can't go to page of pipe is used (SDDS_GotoPage)");
1287 if (SDDS_dataset->layout.gzipFile) {
1288 SDDS_SetError(
"Can not go to page of a gzip file (SDDS_GotoPage)");
1292 if (SDDS_dataset->layout.lzmaFile) {
1293 SDDS_SetError(
"Can not go to page of an .lzma or .xz file (SDDS_GotoPage)");
1296 if (!SDDS_dataset->layout.fp) {
1297 SDDS_SetError(
"Unable to go to page--NULL file pointer (SDDS_GotoPage)");
1304 if (!SDDS_dataset->layout.filename) {
1305 SDDS_SetError(
"Can't go to page--NULL filename pointer (SDDS_GotoPage)");
1308 if (SDDS_dataset->mode != SDDS_READMODE) {
1309 SDDS_SetError(
"Can't go to page--file mode has to be reading mode (SDDS_GotoPage)");
1312 if (SDDS_dataset->fBuffer.bufferSize) {
1313 SDDS_SetError(
"Can't go to page--file buffering is turned on (SDDS_GotoPage)");
1316 if (page_number < 1) {
1317 SDDS_SetError(
"The page_number can not be less than 1 (SDDS_GotoPage)");
1320 if (page_number > SDDS_dataset->pages_read) {
1321 offset = SDDS_dataset->pagecount_offset[SDDS_dataset->pages_read] - ftell(SDDS_dataset->layout.fp);
1322 fseek(SDDS_dataset->layout.fp, offset, 1);
1323 SDDS_dataset->page_number = SDDS_dataset->pages_read;
1324 while (SDDS_dataset->pages_read < page_number) {
1325 if (
SDDS_ReadPageSparse(SDDS_dataset, 0, SDDS_dataset->layout.data_mode.column_major ? 1 : 10000, 0, 0) <= 0) {
1326 SDDS_SetError(
"The page_number is greater than the total pages (SDDS_GotoPage)");
1331 offset = SDDS_dataset->pagecount_offset[page_number - 1] - ftell(SDDS_dataset->layout.fp);
1332 fseek(SDDS_dataset->layout.fp, offset, 1);
1333 SDDS_dataset->page_number = page_number - 1;
1344static int32_t terminateMode = 0;
1346int32_t SDDS_GetTerminateMode(
void) {
1349 mode = terminateMode;
1361 terminateMode = mode;
1372 SDDS_dataset->layout.data_mode.column_memory_mode = mode;
1382 return (SDDS_dataset->layout.data_mode.column_memory_mode);
1403 layout = &SDDS_dataset->original_layout;
1405 if (SDDS_dataset->parameter) {
1406 for (i = 0; i < layout->n_parameters; i++) {
1407 if (layout->parameter_definition[i].type ==
SDDS_STRING) {
1408 free(*(
char **)(SDDS_dataset->parameter[i]));
1409 *(
char **)(SDDS_dataset->parameter[i]) = NULL;
1413 if (SDDS_dataset->array) {
1414 for (i = 0; i < layout->n_arrays; i++) {
1415 if (layout->array_definition[i].type ==
SDDS_STRING) {
1416 for (j = 0; j < SDDS_dataset->array[i].elements; j++)
1417 if (((
char **)SDDS_dataset->array[i].data)[j]) {
1418 free(((
char **)SDDS_dataset->array[i].data)[j]);
1419 ((
char **)SDDS_dataset->array[i].data)[j] = NULL;
1424 if (SDDS_dataset->data) {
1425 for (i = 0; i < layout->n_columns; i++)
1426 if (SDDS_dataset->data[i]) {
1427 if (layout->column_definition[i].type ==
SDDS_STRING) {
1428 ptr = (
char **)SDDS_dataset->data[i];
1429 for (j = 0; j < SDDS_dataset->n_rows_allocated; j++, ptr++)
1454 for (i = 0; i < SDDS_dataset->layout.n_columns; i++)
1455 if (SDDS_dataset->layout.column_definition[i].type ==
SDDS_STRING) {
1456 ptr = (
char **)SDDS_dataset->data[i];
1457 for (j = 0; j < SDDS_dataset->n_rows; j++, ptr++)
1476 char termBuffer[16384];
1477 int32_t terminateMode;
1479 if (SDDS_dataset->parallel_io)
1484 layout = &SDDS_dataset->original_layout;
1485 terminateMode = SDDS_GetTerminateMode();
1487 fp = SDDS_dataset->layout.fp;
1489 if (SDDS_dataset->layout.gzipFile) {
1490 if (SDDS_dataset->layout.gzfp && layout->filename) {
1491 if ((SDDS_dataset->writing_page) && (SDDS_dataset->layout.data_mode.fixed_row_count)) {
1495 gzclose(SDDS_dataset->layout.gzfp);
1499 if (SDDS_dataset->layout.lzmaFile) {
1500 if (SDDS_dataset->layout.lzmafp && layout->filename) {
1501 if ((SDDS_dataset->writing_page) && (SDDS_dataset->layout.data_mode.fixed_row_count)) {
1505 lzma_close(SDDS_dataset->layout.lzmafp);
1508 if (fp && layout->filename) {
1509 if ((SDDS_dataset->writing_page) && (SDDS_dataset->layout.data_mode.fixed_row_count)) {
1513 if (layout->popenUsed) {
1514 while (fread(termBuffer,
sizeof(*termBuffer), 16384, fp)) {
1517 fprintf(stderr,
"pclose is not supported in vxWorks\n");
1532 fprintf(stderr,
"Freeing data for file %s\n", SDDS_dataset->layout.filename ? SDDS_dataset->layout.filename :
"NULL");
1535 if (SDDS_dataset->pagecount_offset)
1536 free(SDDS_dataset->pagecount_offset);
1537 if (SDDS_dataset->row_flag)
1538 free(SDDS_dataset->row_flag);
1539 if (SDDS_dataset->column_order)
1540 free(SDDS_dataset->column_order);
1541 if (SDDS_dataset->column_flag)
1542 free(SDDS_dataset->column_flag);
1543 if (SDDS_dataset->fBuffer.buffer)
1544 free(SDDS_dataset->fBuffer.buffer);
1546 fprintf(stderr,
"freeing parameter data...\n");
1548 if (SDDS_dataset->parameter) {
1549 for (i = 0; i < layout->n_parameters; i++) {
1550 if (layout->parameter_definition[i].type ==
SDDS_STRING && *(
char **)(SDDS_dataset->parameter[i]))
1551 free(*(
char **)(SDDS_dataset->parameter[i]));
1552 if (SDDS_dataset->parameter[i])
1553 free(SDDS_dataset->parameter[i]);
1555 free(SDDS_dataset->parameter);
1558 fprintf(stderr,
"freeing array data...\n");
1560 if (SDDS_dataset->array) {
1561 for (i = 0; i < layout->n_arrays; i++) {
1562 if (layout->array_definition[i].type ==
SDDS_STRING && !(terminateMode & TERMINATE_DONT_FREE_ARRAY_STRINGS)) {
1563 for (j = 0; j < SDDS_dataset->array[i].elements; j++)
1564 if (((
char **)SDDS_dataset->array[i].data)[j])
1565 free(((
char **)SDDS_dataset->array[i].data)[j]);
1575 if (SDDS_dataset->array[i].data)
1576 free(SDDS_dataset->array[i].data);
1578 if (SDDS_dataset->array[i].pointer && SDDS_dataset->array[i].definition->dimensions != 1)
1579 free(SDDS_dataset->array[i].pointer);
1580 if (SDDS_dataset->array[i].dimension)
1581 free(SDDS_dataset->array[i].dimension);
1583 if (SDDS_dataset->array[i].definition && SDDS_dataset->array[i].definition->name) {
1584 if (SDDS_dataset->array[i].definition->name != layout->array_definition[i].name)
1587 SDDS_dataset->array[i].definition = NULL;
1589 free(SDDS_dataset->array);
1592 fprintf(stderr,
"freeing tabular data...\n");
1594 if (SDDS_dataset->data) {
1595 for (i = 0; i < layout->n_columns; i++)
1596 if (SDDS_dataset->data[i]) {
1597 if ((SDDS_dataset->column_track_memory == NULL) || (SDDS_dataset->column_track_memory[i])) {
1598 if (layout->column_definition[i].type ==
SDDS_STRING && !(terminateMode & TERMINATE_DONT_FREE_TABLE_STRINGS)) {
1599 ptr = (
char **)SDDS_dataset->data[i];
1600 for (j = 0; j < SDDS_dataset->n_rows_allocated; j++, ptr++)
1604 free(SDDS_dataset->data[i]);
1607 free(SDDS_dataset->data);
1609 if (SDDS_dataset->column_track_memory)
1610 free(SDDS_dataset->column_track_memory);
1612 fprintf(stderr,
"freeing layout data...\n");
1614 if (layout->description)
1615 free(layout->description);
1616 if (layout->contents == (&SDDS_dataset->layout)->contents)
1617 (&SDDS_dataset->layout)->contents = NULL;
1618 if (layout->contents)
1619 free(layout->contents);
1620 if (layout->filename)
1621 free(layout->filename);
1622 if (layout->column_definition) {
1623 for (i = 0; i < layout->n_columns; i++) {
1624 if (layout->column_index[i])
1625 free(layout->column_index[i]);
1626 if (layout->column_definition[i].name)
1627 free(layout->column_definition[i].name);
1628 if (layout->column_definition[i].symbol)
1629 free(layout->column_definition[i].symbol);
1630 if (layout->column_definition[i].units)
1631 free(layout->column_definition[i].units);
1632 if (layout->column_definition[i].description)
1633 free(layout->column_definition[i].description);
1634 if (layout->column_definition[i].format_string)
1635 free(layout->column_definition[i].format_string);
1637 free(layout->column_definition);
1638 free(layout->column_index);
1640 if (layout->parameter_definition) {
1641 for (i = 0; i < layout->n_parameters; i++) {
1642 if (layout->parameter_index[i])
1643 free(layout->parameter_index[i]);
1644 if (layout->parameter_definition[i].name)
1645 free(layout->parameter_definition[i].name);
1646 if (layout->parameter_definition[i].symbol)
1647 free(layout->parameter_definition[i].symbol);
1648 if (layout->parameter_definition[i].units)
1649 free(layout->parameter_definition[i].units);
1650 if (layout->parameter_definition[i].description)
1651 free(layout->parameter_definition[i].description);
1652 if (layout->parameter_definition[i].format_string)
1653 free(layout->parameter_definition[i].format_string);
1654 if (layout->parameter_definition[i].fixed_value)
1655 free(layout->parameter_definition[i].fixed_value);
1657 free(layout->parameter_definition);
1658 free(layout->parameter_index);
1660 if (layout->array_definition) {
1661 for (i = 0; i < layout->n_arrays; i++) {
1662 if (layout->array_index[i])
1663 free(layout->array_index[i]);
1664 if (layout->array_definition[i].name)
1665 free(layout->array_definition[i].name);
1666 if (layout->array_definition[i].symbol)
1667 free(layout->array_definition[i].symbol);
1668 if (layout->array_definition[i].units)
1669 free(layout->array_definition[i].units);
1670 if (layout->array_definition[i].description)
1671 free(layout->array_definition[i].description);
1672 if (layout->array_definition[i].format_string)
1673 free(layout->array_definition[i].format_string);
1674 if (layout->array_definition[i].group_name)
1675 free(layout->array_definition[i].group_name);
1677 free(layout->array_definition);
1678 free(layout->array_index);
1680 if (layout->associate_definition) {
1681 for (i = 0; i < layout->n_associates; i++) {
1682 if (layout->associate_definition[i].name)
1683 free(layout->associate_definition[i].name);
1684 if (layout->associate_definition[i].filename)
1685 free(layout->associate_definition[i].filename);
1686 if (layout->associate_definition[i].path)
1687 free(layout->associate_definition[i].path);
1688 if (layout->associate_definition[i].description)
1689 free(layout->associate_definition[i].description);
1690 if (layout->associate_definition[i].contents)
1691 free(layout->associate_definition[i].contents);
1693 free(layout->associate_definition);
1696 layout = &SDDS_dataset->layout;
1697 if (layout->contents)
1698 free(layout->contents);
1699 if (layout->column_definition)
1700 free(layout->column_definition);
1701 if (layout->array_definition)
1702 free(layout->array_definition);
1703 if (layout->associate_definition)
1704 free(layout->associate_definition);
1705 if (layout->parameter_definition)
1706 free(layout->parameter_definition);
1707 if (layout->column_index)
1708 free(layout->column_index);
1709 if (layout->parameter_index)
1710 free(layout->parameter_index);
1711 if (layout->array_index)
1712 free(layout->array_index);
1716 fprintf(stderr,
"done\n");
1730 int64_t offset, rows;
1732 char *outputEndianess = NULL;
1734 if ((SDDS_dataset->layout.gzipFile) || (SDDS_dataset->layout.lzmaFile))
1736 if (!(fp = SDDS_dataset->layout.fp)) {
1737 SDDS_SetError(
"Unable to update page--file pointer is NULL (SDDS_UpdateRowCount)");
1741 fprintf(stderr,
"Updating rowcount in file %s with pointer %p\n", SDDS_dataset->layout.filename ? SDDS_dataset->layout.filename :
"NULL", fp);
1743 fBuffer = &SDDS_dataset->fBuffer;
1745 SDDS_SetError(
"Unable to write page--buffer flushing problem (SDDS_UpdateRowCount)");
1749 if (
SDDS_fseek(fp, SDDS_dataset->rowcount_offset, 0) == -1) {
1750 SDDS_SetError(
"Unable to update page--failure doing fseek (SDDS_UpdateRowCount)");
1754 if (SDDS_dataset->layout.data_mode.mode == SDDS_ASCII) {
1755 fprintf(fp,
"%20" PRId64
"\n", rows);
1758 if (rows > INT32_MAX) {
1760 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateRowCount)");
1763 rows32 = (int32_t)rows;
1764 if ((outputEndianess = getenv(
"SDDS_OUTPUT_ENDIANESS"))) {
1768 if (fwrite(&rows32,
sizeof(rows32), 1, fp) != 1) {
1769 SDDS_SetError(
"Unable to update page--failure writing number of rows (SDDS_UpdateRowCount)");
1774 SDDS_SetError(
"Unable to update page--failure doing fseek to end of page (SDDS_UpdateRowCount)");
1790 if (mode & SDDS_AUTOREADRECOVER) {
1791 SDDS_dataset->autoRecover = 1;
1792 }
else if (mode & SDDS_NOAUTOREADRECOVER) {
1793 SDDS_dataset->autoRecover = 0;
1795 SDDS_SetError(
"Invalid Auto Read Recovery mode (SDDS_SetAutoReadRecovery).");
1816 if (!(s =
SDDS_Malloc(
sizeof(*s) * (strlen(file) + 100))))
1817 SDDS_SetError(
"file does not exist in search path (InitializeInputFromSearchPath)");
1819 sprintf(s,
"file %s does not exist in search path (InitializeInputFromSearchPath)", file);
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_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_FlushBuffer(FILE *fp, SDDS_FILEBUFFER *fBuffer)
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.
void SDDS_SwapLong(int32_t *data)
Swaps the endianness of a 32-bit integer.
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_ReadBinaryPageLastRows(SDDS_DATASET *SDDS_dataset, int64_t last_rows)
Reads the last specified number of rows from a binary page of an SDDS dataset.
void SDDS_DeferSavingLayout(SDDS_DATASET *SDDS_dataset, int32_t mode)
int32_t SDDS_SaveLayout(SDDS_DATASET *SDDS_dataset)
char * SDDS_command[SDDS_NUM_COMMANDS]
Array of supported SDDS command names.
Internal definitions and function declarations for SDDS with LZMA support.
int32_t SDDS_ProcessArrayDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Process the array definition section of the SDDS dataset.
int32_t SDDS_ProcessParameterDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Process the parameter definition section of the SDDS dataset.
int32_t SDDS_ProcessAssociateDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Process the associate definition section of the SDDS dataset.
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.
FILE * SDDS_ProcessIncludeCommand(SDDS_DATASET *SDDS_dataset, char *s)
Process the include command within the SDDS dataset.
int32_t SDDS_ProcessDataMode(SDDS_DATASET *SDDS_dataset, char *s)
Process the data mode section of the SDDS dataset.
uint32_t SDDS_GetSpecialCommentsModes(SDDS_DATASET *SDDS_dataset)
Retrieves the current special comments modes set in the SDDS dataset.
int32_t SDDS_ProcessDescription(SDDS_DATASET *SDDS_dataset, char *s)
Process the description section of the SDDS dataset.
void SDDS_ResetSpecialCommentsModes(SDDS_DATASET *SDDS_dataset)
Resets the special comments modes in the SDDS dataset.
int32_t SDDS_ProcessColumnDefinition(SDDS_DATASET *SDDS_dataset, char *s)
Process the column definition section of the SDDS dataset.
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_SetMemory(void *mem, int64_t n_elements, int32_t data_type,...)
Initializes a memory block with a sequence of values based on a specified data type.
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.
int32_t SDDS_CopyString(char **target, const char *source)
Copies a source string to a target string with memory allocation.
int32_t SDDS_IsBigEndianMachine()
Determines whether the current machine uses big-endian byte ordering.
int32_t SDDS_MPI_Terminate(SDDS_DATASET *SDDS_dataset)
Terminates the SDDS dataset by freeing all allocated resources and closing MPI files.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
long match_string(char *string, char **option, long n_options, long mode)
Matches a given string against an array of option strings based on specified modes.
char * findFileInSearchPath(const char *filename)
Finds a file within the configured search path.
FILE * UnpackFopen(char *filename, unsigned long mode, short *popenUsed, char **tmpFileUsed)
Opens a file, potentially unpacking it based on its extension and mode.