29# if defined(__BORLANDC__)
30# define _setmode(handle, amode) setmode(handle, amode)
37# error "SDDS_VERSION does not match version of this file"
72 if (SDDS_dataset->parallel_io)
77 if (!SDDS_dataset->layout.filename) {
78 SDDS_SetError(
"Can't disconnect file. No filename given. (SDDS_DisconnectFile)");
81 if (SDDS_dataset->layout.gzipFile) {
82 SDDS_SetError(
"Can't disconnect file because it is a gzip file. (SDDS_DisconnectFile)");
85 if (SDDS_dataset->layout.lzmaFile) {
86 SDDS_SetError(
"Can't disconnect file because it is a lzma or xz file. (SDDS_DisconnectFile)");
89 if (SDDS_dataset->layout.disconnected) {
90 SDDS_SetError(
"Can't disconnect file. Already disconnected. (SDDS_DisconnectFile)");
93 if (SDDS_dataset->page_started && !
SDDS_UpdatePage(SDDS_dataset, FLUSH_TABLE)) {
94 SDDS_SetError(
"Can't disconnect file. Problem updating page. (SDDS_DisconnectFile)");
97 if (fclose(SDDS_dataset->layout.fp)) {
98 SDDS_SetError(
"Can't disconnect file. Problem closing file. (SDDS_DisconnectFile)");
101 SDDS_dataset->layout.disconnected = 1;
128 if (SDDS_dataset->parallel_io)
133 if (!SDDS_dataset->layout.disconnected || !SDDS_dataset->layout.filename) {
134 SDDS_SetError(
"Can't reconnect file. Not disconnected or missing filename. (SDDS_ReconnectFile)");
137 if (!(SDDS_dataset->layout.fp = fopen(SDDS_dataset->layout.filename, FOPEN_READ_AND_WRITE_MODE))) {
139 sprintf(s,
"Unable to open file %s (SDDS_ReconnectFile)", SDDS_dataset->layout.filename);
143 if (fseek(SDDS_dataset->layout.fp, 0, 2) == -1) {
144 SDDS_SetError(
"Can't reconnect file. Fseek failed. (SDDS_ReconnectFile)");
147 SDDS_dataset->original_layout.fp = SDDS_dataset->layout.fp;
148 SDDS_dataset->layout.disconnected = 0;
173 if (SDDS_dataset->parallel_io) {
174 SDDS_SetError(
"Error: MPI mode not supported yet in SDDS_DisconnectInputFile");
180 if (!SDDS_dataset->layout.filename) {
181 SDDS_SetError(
"Can't disconnect file. No filename given. (SDDS_DisconnectInputFile)");
184 if (SDDS_dataset->layout.gzipFile) {
185 SDDS_SetError(
"Can't disconnect file because it is a gzip file. (SDDS_DisconnectInputFile)");
188 if (SDDS_dataset->layout.lzmaFile) {
189 SDDS_SetError(
"Can't disconnect file because it is a lzma or xz file. (SDDS_DisconnectInputFile)");
192 if (SDDS_dataset->layout.disconnected) {
193 SDDS_SetError(
"Can't disconnect file. Already disconnected. (SDDS_DisconnectInputFile)");
196 position = ftell(SDDS_dataset->layout.fp);
197 if (fclose(SDDS_dataset->layout.fp)) {
198 SDDS_SetError(
"Can't disconnect file. Problem closing file. (SDDS_DisconnectInputFile)");
201 SDDS_dataset->layout.disconnected = 1;
231 if (SDDS_dataset->parallel_io) {
232 SDDS_SetError(
"Error: MPI mode not supported yet in SDDS_ReconnectInputFile");
238 if (!SDDS_dataset->layout.disconnected || !SDDS_dataset->layout.filename) {
239 SDDS_SetError(
"Can't reconnect file. Not disconnected or missing filename. (SDDS_ReconnectInputFile)");
242 if (!(SDDS_dataset->layout.fp = fopen(SDDS_dataset->layout.filename, FOPEN_READ_MODE))) {
244 sprintf(s,
"Unable to open file %s (SDDS_ReconnectInputFile)", SDDS_dataset->layout.filename);
248 if (fseek(SDDS_dataset->layout.fp, position, SEEK_SET) == -1) {
249 SDDS_SetError(
"Can't reconnect file. Fseek failed. (SDDS_ReconnectInputFile)");
252 SDDS_dataset->original_layout.fp = SDDS_dataset->layout.fp;
253 SDDS_dataset->layout.disconnected = 0;
289 char s[SDDS_MAXLINE];
290 int64_t endOfLayoutOffset, endOfFileOffset;
296 sprintf(s,
"Unable to initialize input for file %s--can't zero SDDS_DATASET structure (SDDS_InitializeAppend)", filename);
300 SDDS_dataset->layout.popenUsed = SDDS_dataset->layout.gzipFile = SDDS_dataset->layout.lzmaFile = SDDS_dataset->layout.disconnected = 0;
301 SDDS_dataset->layout.depth = SDDS_dataset->layout.data_command_seen = SDDS_dataset->layout.commentFlags = SDDS_dataset->deferSavingLayout = 0;
303 SDDS_dataset->layout.filename = NULL;
305 sprintf(s,
"Memory allocation failure initializing file %s (SDDS_InitializeAppend)", filename);
308 }
else if ((extension = strrchr(filename,
'.')) && ((strcmp(extension,
".gz") == 0) || (strcmp(extension,
".lzma") == 0) || (strcmp(extension,
".xz") == 0))) {
309 sprintf(s,
"Cannot append to a compressed file %s (SDDS_InitializeAppend)", filename);
314 SDDS_dataset->layout.popenUsed = 0;
317 if (_setmode(_fileno(stdin), _O_BINARY) == -1) {
318 sprintf(s,
"unable to set stdin to binary mode");
323 SDDS_dataset->layout.fp = stdin;
326 sprintf(s,
"unable to open file %s for appending--file is locked (SDDS_InitializeAppend)", filename);
330 if (!(SDDS_dataset->layout.fp = fopen(filename, FOPEN_READ_AND_WRITE_MODE))) {
331 sprintf(s,
"Unable to open file %s for appending (SDDS_InitializeAppend)", filename);
335 if (!
SDDS_LockFile(SDDS_dataset->layout.fp, filename,
"SDDS_InitializeAppend"))
341 endOfLayoutOffset = ftell(SDDS_dataset->layout.fp);
342 if (SDDS_dataset->layout.n_columns &&
343 (!(SDDS_dataset->column_flag = (int32_t *)
SDDS_Malloc(
sizeof(int32_t) * SDDS_dataset->layout.n_columns)) ||
344 !(SDDS_dataset->column_order = (int32_t *)
SDDS_Malloc(
sizeof(int32_t) * SDDS_dataset->layout.n_columns)) ||
345 !
SDDS_SetMemory(SDDS_dataset->column_flag, SDDS_dataset->layout.n_columns,
SDDS_LONG, (int32_t)1, (int32_t)0) ||
346 !
SDDS_SetMemory(SDDS_dataset->column_order, SDDS_dataset->layout.n_columns,
SDDS_LONG, (int32_t)0, (int32_t)1))) {
347 SDDS_SetError(
"Unable to initialize input--memory allocation failure (SDDS_InitializeAppend)");
350 if (fseek(SDDS_dataset->layout.fp, 0, 2) == -1) {
351 SDDS_SetError(
"Unable to initialize append--seek failure (SDDS_InitializeAppend)");
354 endOfFileOffset = ftell(SDDS_dataset->layout.fp);
355 if (endOfFileOffset == endOfLayoutOffset)
356 SDDS_dataset->file_had_data = 0;
358 SDDS_dataset->file_had_data = 1;
359 SDDS_dataset->layout.layout_written = 1;
360 SDDS_dataset->mode = SDDS_WRITEMODE;
398 char s[SDDS_MAXLINE];
399 int64_t endOfLayoutOffset, endOfFileOffset, rowCountOffset, offset;
400 int32_t rowsPresent32;
403 int32_t previousBufferSize;
405 *rowsPresentReturn = -1;
409 sprintf(s,
"Unable to initialize input for file %s--can't zero SDDS_DATASET structure (SDDS_InitializeAppendToPage)", filename);
413 SDDS_dataset->layout.popenUsed = SDDS_dataset->layout.gzipFile = SDDS_dataset->layout.lzmaFile = SDDS_dataset->layout.disconnected = 0;
414 SDDS_dataset->layout.depth = SDDS_dataset->layout.data_command_seen = SDDS_dataset->layout.commentFlags = SDDS_dataset->deferSavingLayout = 0;
416 SDDS_dataset->layout.filename = NULL;
418 sprintf(s,
"Memory allocation failure initializing file %s (SDDS_InitializeAppendToPage)", filename);
421 }
else if ((extension = strrchr(filename,
'.')) && ((strcmp(extension,
".gz") == 0) || (strcmp(extension,
".lzma") == 0) || (strcmp(extension,
".xz") == 0))) {
422 sprintf(s,
"Cannot append to a compressed file %s (SDDS_InitializeAppendToPage)", filename);
429 if (_setmode(_fileno(stdin), _O_BINARY) == -1) {
430 sprintf(s,
"unable to set stdin to binary mode");
435 SDDS_dataset->layout.fp = stdin;
438 sprintf(s,
"unable to open file %s for appending--file is locked (SDDS_InitializeAppendToPage)", filename);
442 if (!(SDDS_dataset->layout.fp = fopen(filename, FOPEN_READ_AND_WRITE_MODE))) {
443 sprintf(s,
"Unable to open file %s for appending (SDDS_InitializeAppendToPage)", filename);
447 if (!
SDDS_LockFile(SDDS_dataset->layout.fp, filename,
"SDDS_InitializeAppendToPage")) {
455 endOfLayoutOffset = ftell(SDDS_dataset->layout.fp);
456 if (SDDS_dataset->layout.n_columns &&
457 (!(SDDS_dataset->column_flag = (int32_t *)
SDDS_Malloc(
sizeof(int32_t) * SDDS_dataset->layout.n_columns)) ||
458 !(SDDS_dataset->column_order = (int32_t *)
SDDS_Malloc(
sizeof(int32_t) * SDDS_dataset->layout.n_columns)) ||
459 !
SDDS_SetMemory(SDDS_dataset->column_flag, SDDS_dataset->layout.n_columns,
SDDS_LONG, (int32_t)1, (int32_t)0) ||
460 !
SDDS_SetMemory(SDDS_dataset->column_order, SDDS_dataset->layout.n_columns,
SDDS_LONG, (int32_t)0, (int32_t)1))) {
461 SDDS_SetError(
"Unable to initialize input--memory allocation failure (SDDS_InitializeAppendToPage)");
467 fprintf(stderr,
"Data mode is %s\n",
SDDS_data_mode[SDDS_dataset->layout.data_mode.mode - 1]);
469 SDDS_dataset->pagecount_offset = NULL;
471 if (!SDDS_dataset->layout.data_mode.no_row_counts) {
474 rowCountOffset = SDDS_dataset->rowcount_offset;
475 offset = ftell(SDDS_dataset->layout.fp);
476 fseek(SDDS_dataset->layout.fp, rowCountOffset, 0);
478 if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY) {
479 fread(&rowsPresent32,
sizeof(rowsPresent32), 1, SDDS_dataset->layout.fp);
480 if (SDDS_dataset->swapByteOrder) {
483 if (rowsPresent32 == INT32_MIN) {
484 fread(&rowsPresent,
sizeof(rowsPresent), 1, SDDS_dataset->layout.fp);
485 if (SDDS_dataset->swapByteOrder) {
489 rowsPresent = rowsPresent32;
493 if (!fgets(buffer, 30, SDDS_dataset->layout.fp) || strlen(buffer) != 21 || sscanf(buffer,
"%" SCNd64, &rowsPresent) != 1) {
495 fprintf(stderr,
"buffer for row count data: >%s<\n", buffer);
497 SDDS_SetError(
"Unable to initialize input--row count not present or not correct length (SDDS_InitializeAppendToPage)");
502 fseek(SDDS_dataset->layout.fp, offset, 0);
504 fprintf(stderr,
"%" PRId64
" rows present\n", rowsPresent);
507 if (rowCountOffset == -1) {
509 SDDS_SetError(
"Unable to initialize input--problem finding row count offset (SDDS_InitializeAppendToPage)");
514 SDDS_dataset->fBuffer.bytesLeft = SDDS_dataset->fBuffer.bufferSize;
517 fprintf(stderr,
"Starting page with %" PRId64
" rows\n", updateInterval);
520 SDDS_SetError(
"Unable to initialize input--problem starting page (SDDS_InitializeAppendToPage)");
525 if (fseek(SDDS_dataset->layout.fp, 0, 2) == -1) {
526 SDDS_SetError(
"Unable to initialize append--seek failure (SDDS_InitializeAppendToPage)");
529 endOfFileOffset = ftell(SDDS_dataset->layout.fp);
530 if (endOfFileOffset == endOfLayoutOffset)
531 SDDS_dataset->file_had_data = 0;
533 SDDS_dataset->file_had_data = 1;
534 if (rowCountOffset != -1) {
535 SDDS_dataset->rowcount_offset = rowCountOffset;
536 SDDS_dataset->n_rows_written = rowsPresent;
537 SDDS_dataset->first_row_in_mem = rowsPresent;
538 SDDS_dataset->last_row_written = -1;
539 *rowsPresentReturn = rowsPresent;
540 SDDS_dataset->writing_page = 1;
544 fprintf(stderr,
"rowcount_offset = %" PRId64
", n_rows_written = %" PRId64
", first_row_in_mem = %" PRId64
", last_row_written = %" PRId64
"\n", SDDS_dataset->rowcount_offset, SDDS_dataset->n_rows_written, SDDS_dataset->first_row_in_mem, SDDS_dataset->last_row_written);
546 SDDS_dataset->page_number = 1;
547 SDDS_dataset->layout.layout_written = 1;
548 SDDS_dataset->mode = SDDS_WRITEMODE;
596 char s[SDDS_MAXLINE];
598 char *outputEndianess = NULL;
600 if (data_mode == SDDS_PARALLEL)
603 if (
sizeof(gzFile) !=
sizeof(
void *)) {
604 SDDS_SetError(
"gzFile is not the same size as void *, possible corruption of the SDDS_LAYOUT structure");
610 sprintf(s,
"Unable to initialize output for file %s--can't zero SDDS_DATASET structure (SDDS_InitializeOutput)", filename);
614 SDDS_dataset->layout.popenUsed = SDDS_dataset->layout.gzipFile = SDDS_dataset->layout.lzmaFile = SDDS_dataset->layout.disconnected = 0;
615 SDDS_dataset->layout.depth = SDDS_dataset->layout.data_command_seen = SDDS_dataset->layout.commentFlags = SDDS_dataset->deferSavingLayout = 0;
618 if (_setmode(_fileno(stdout), _O_BINARY) == -1) {
619 sprintf(s,
"unable to set stdout to binary mode");
624 SDDS_dataset->layout.fp = stdout;
627 sprintf(s,
"unable to open file %s for writing--file is locked (SDDS_InitializeOutput)", filename);
631 if ((extension = strrchr(filename,
'.')) && ((strcmp(extension,
".xz") == 0) || (strcmp(extension,
".lzma") == 0))) {
632 SDDS_dataset->layout.lzmaFile = 1;
633 data_mode = SDDS_BINARY;
634 if (!(SDDS_dataset->layout.lzmafp = lzma_open(filename, FOPEN_WRITE_MODE))) {
635 sprintf(s,
"Unable to open file %s for writing (SDDS_InitializeOutput)", filename);
639 SDDS_dataset->layout.fp = SDDS_dataset->layout.lzmafp->fp;
641 if (!(SDDS_dataset->layout.fp = fopen(filename, FOPEN_WRITE_MODE))) {
642 sprintf(s,
"Unable to open file %s for writing (SDDS_InitializeOutput)", filename);
647 if (!
SDDS_LockFile(SDDS_dataset->layout.fp, filename,
"SDDS_InitializeOutput"))
650 if ((extension = strrchr(filename,
'.')) && (strcmp(extension,
".gz") == 0)) {
651 SDDS_dataset->layout.gzipFile = 1;
652 if ((SDDS_dataset->layout.gzfp = gzdopen(fileno(SDDS_dataset->layout.fp), FOPEN_WRITE_MODE)) == NULL) {
653 sprintf(s,
"Unable to open compressed file %s for writing (SDDS_InitializeOutput)", filename);
660 SDDS_dataset->page_number = SDDS_dataset->page_started = 0;
661 SDDS_dataset->file_had_data = SDDS_dataset->layout.layout_written = 0;
663 SDDS_dataset->layout.filename = NULL;
665 sprintf(s,
"Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename);
669 if ((outputEndianess = getenv(
"SDDS_OUTPUT_ENDIANESS"))) {
670 if (strncmp(outputEndianess,
"big", 3) == 0)
671 SDDS_dataset->layout.byteOrderDeclared = SDDS_BIGENDIAN;
672 else if (strncmp(outputEndianess,
"little", 6) == 0)
673 SDDS_dataset->layout.byteOrderDeclared = SDDS_LITTLEENDIAN;
678 if (data_mode < 0 || data_mode > SDDS_NUM_DATA_MODES) {
679 sprintf(s,
"Invalid data mode for file %s (SDDS_InitializeOutput)", filename ? filename :
"stdout");
683 if (data_mode == SDDS_ASCII && lines_per_row <= 0) {
684 sprintf(s,
"Invalid number of lines per row for file %s (SDDS_InitializeOutput)", filename ? filename :
"stdout");
688 SDDS_dataset->layout.version = SDDS_VERSION;
689 SDDS_dataset->layout.data_mode.mode = data_mode;
690 SDDS_dataset->layout.data_mode.lines_per_row = lines_per_row;
691 SDDS_dataset->layout.data_mode.no_row_counts = 0;
692 SDDS_dataset->layout.data_mode.fixed_row_count = 0;
693 SDDS_dataset->layout.data_mode.fsync_data = 0;
694 SDDS_dataset->layout.data_mode.column_memory_mode = DEFAULT_COLUMN_MEMORY_MODE;
696 SDDS_dataset->layout.data_mode.column_major = 0;
697 if (description && !
SDDS_CopyString(&SDDS_dataset->layout.description, description)) {
698 sprintf(s,
"Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename ? filename :
"stdout");
702 if (contents && !
SDDS_CopyString(&SDDS_dataset->layout.contents, contents)) {
703 sprintf(s,
"Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename ? filename :
"stdout");
707 SDDS_dataset->mode = SDDS_WRITEMODE;
708 SDDS_dataset->pagecount_offset = NULL;
709 SDDS_dataset->parallel_io = 0;
750 char s[SDDS_MAXLINE];
751 char *outputEndianess = NULL;
754 if (
sizeof(gzFile) !=
sizeof(
void *)) {
755 SDDS_SetError(
"gzFile is not the same size as void *, possible corruption of the SDDS_LAYOUT structure");
768 SDDS_dataset->layout.popenUsed = SDDS_dataset->layout.gzipFile = SDDS_dataset->layout.lzmaFile = SDDS_dataset->layout.disconnected = 0;
769 SDDS_dataset->layout.depth = SDDS_dataset->layout.data_command_seen = SDDS_dataset->layout.commentFlags = SDDS_dataset->deferSavingLayout = 0;
770 SDDS_dataset->layout.fp = NULL;
772 SDDS_dataset->page_number = SDDS_dataset->page_started = 0;
773 SDDS_dataset->file_had_data = SDDS_dataset->layout.layout_written = 0;
775 SDDS_dataset->layout.filename = NULL;
777 sprintf(s,
"Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename);
781 if ((outputEndianess = getenv(
"SDDS_OUTPUT_ENDIANESS"))) {
782 if (strncmp(outputEndianess,
"big", 3) == 0)
783 SDDS_dataset->layout.byteOrderDeclared = SDDS_BIGENDIAN;
784 else if (strncmp(outputEndianess,
"little", 6) == 0)
785 SDDS_dataset->layout.byteOrderDeclared = SDDS_LITTLEENDIAN;
791 SDDS_dataset->layout.version = SDDS_VERSION;
793 SDDS_dataset->layout.data_mode.mode = SDDS_BINARY;
794 SDDS_dataset->layout.data_mode.lines_per_row = 0;
795 SDDS_dataset->layout.data_mode.no_row_counts = 0;
796 SDDS_dataset->layout.data_mode.fixed_row_count = 0;
797 SDDS_dataset->layout.data_mode.fsync_data = 0;
798 SDDS_dataset->layout.data_mode.column_memory_mode = DEFAULT_COLUMN_MEMORY_MODE;
800 SDDS_dataset->layout.data_mode.column_major = 0;
801 if (description && !
SDDS_CopyString(&SDDS_dataset->layout.description, description)) {
802 sprintf(s,
"Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename ? filename :
"stdout");
806 if (contents && !
SDDS_CopyString(&SDDS_dataset->layout.contents, contents)) {
807 sprintf(s,
"Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename ? filename :
"stdout");
811 SDDS_dataset->layout.n_parameters = SDDS_dataset->layout.n_columns = SDDS_dataset->layout.n_arrays = SDDS_dataset->layout.n_associates = 0;
812 SDDS_dataset->mode = SDDS_WRITEMODE;
813 SDDS_dataset->pagecount_offset = NULL;
814 SDDS_dataset->parallel_io = 1;
850 if (SDDS_dataset->layout.layout_written) {
851 SDDS_SetError(
"Can't change no_row_counts after writing the layout, or for a file you are reading.");
854 SDDS_dataset->layout.data_mode.no_row_counts = value ? 1 : 0;
901 char *outputEndianess = NULL;
904 if (SDDS_dataset->parallel_io)
913 layout = &SDDS_dataset->layout;
915 if (SDDS_dataset->layout.disconnected) {
916 SDDS_SetError(
"Can't write layout--file is disconnected (SDDS_WriteLayout)");
920 if (layout->layout_written) {
921 SDDS_SetError(
"Can't write layout--already written to file (SDDS_WriteLayout)");
925 if ((outputEndianess = getenv(
"SDDS_OUTPUT_ENDIANESS"))) {
926 if (strncmp(outputEndianess,
"big", 3) == 0)
927 layout->byteOrderDeclared = SDDS_BIGENDIAN;
928 else if (strncmp(outputEndianess,
"little", 6) == 0)
929 layout->byteOrderDeclared = SDDS_LITTLEENDIAN;
932 if (!layout->byteOrderDeclared)
936 for (i = 0; i < layout->n_parameters; i++) {
937 if ((layout->parameter_definition[i].type ==
SDDS_ULONG) || (layout->parameter_definition[i].type ==
SDDS_USHORT)) {
942 for (i = 0; i < layout->n_arrays; i++) {
943 if ((layout->array_definition[i].type ==
SDDS_ULONG) || (layout->array_definition[i].type ==
SDDS_USHORT)) {
948 for (i = 0; i < layout->n_columns; i++) {
949 if ((layout->column_definition[i].type ==
SDDS_ULONG) || (layout->column_definition[i].type ==
SDDS_USHORT)) {
954 if ((layout->data_mode.column_major) && (layout->data_mode.mode == SDDS_BINARY)) {
957 for (i = 0; i < layout->n_parameters; i++) {
963 for (i = 0; i < layout->n_arrays; i++) {
969 for (i = 0; i < layout->n_columns; i++) {
975 if ((LDBL_DIG != 18) && (layout->version == 4)) {
976 if (getenv(
"SDDS_LONGDOUBLE_64BITS") == NULL) {
977 SDDS_SetError(
"Error: Operating system does not support 80bit float variables used by SDDS_LONGDOUBLE (SDDS_WriteLayout)\nSet SDDS_LONGDOUBLE_64BITS environment variable to read old files that used 64bit float variables for SDDS_LONGDOUBLE");
981 for (i = 0; i < layout->n_parameters; i++) {
982 if ((layout->parameter_definition[i].type ==
SDDS_ULONG64) || (layout->parameter_definition[i].type ==
SDDS_LONG64)) {
987 for (i = 0; i < layout->n_arrays; i++) {
993 for (i = 0; i < layout->n_columns; i++) {
994 if ((layout->column_definition[i].type ==
SDDS_ULONG64) || (layout->column_definition[i].type ==
SDDS_LONG64)) {
1004 if (SDDS_dataset->layout.gzipFile) {
1005 if (!(gzfp = layout->gzfp)) {
1006 SDDS_SetError(
"Can't write SDDS layout--file pointer is NULL (SDDS_WriteLayout)");
1011 if (!SDDS_GZipWriteVersion(layout->version, gzfp)) {
1012 SDDS_SetError(
"Can't write SDDS layout--error writing version (SDDS_WriteLayout)");
1015 if (layout->version < 3) {
1016 if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY) {
1017 if (layout->byteOrderDeclared == SDDS_BIGENDIAN)
1018 gzprintf(gzfp,
"!# big-endian\n");
1020 gzprintf(gzfp,
"!# little-endian\n");
1022 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
1023 gzprintf(gzfp,
"!# fixed-rowcount\n");
1026 if (!SDDS_GZipWriteDescription(layout->description, layout->contents, gzfp)) {
1027 SDDS_SetError(
"Can't write SDDS layout--error writing description (SDDS_WriteLayout)");
1031 for (i = 0; i < layout->n_parameters; i++)
1032 if (!SDDS_GZipWriteParameterDefinition(layout->parameter_definition + i, gzfp)) {
1033 SDDS_SetError(
"Unable to write layout--error writing parameter definition (SDDS_WriteLayout)");
1037 for (i = 0; i < layout->n_arrays; i++)
1038 if (!SDDS_GZipWriteArrayDefinition(layout->array_definition + i, gzfp)) {
1039 SDDS_SetError(
"Unable to write layout--error writing array definition (SDDS_WriteLayout)");
1043 for (i = 0; i < layout->n_columns; i++)
1044 if (!SDDS_GZipWriteColumnDefinition(layout->column_definition + i, gzfp)) {
1045 SDDS_SetError(
"Unable to write layout--error writing column definition (SDDS_WriteLayout)");
1049# if RW_ASSOCIATES != 0
1050 for (i = 0; i < layout->n_associates; i++)
1051 if (!SDDS_GZipWriteAssociateDefinition(layout->associate_definition + i, gzfp)) {
1052 SDDS_SetError(
"Unable to write layout--error writing associated file data (SDDS_WriteLayout)");
1057 if (!SDDS_GZipWriteDataMode(layout, gzfp)) {
1058 SDDS_SetError(
"Unable to write layout--error writing data mode (SDDS_WriteLayout)");
1062 layout->layout_written = 1;
1066 if (SDDS_dataset->layout.lzmaFile) {
1067 if (!(lzmafp = layout->lzmafp)) {
1068 SDDS_SetError(
"Can't write SDDS layout--file pointer is NULL (SDDS_WriteLayout)");
1074 SDDS_SetError(
"Can't write SDDS layout--error writing version (SDDS_WriteLayout)");
1077 if (layout->version < 3) {
1078 if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY) {
1079 if (layout->byteOrderDeclared == SDDS_BIGENDIAN)
1080 lzma_printf(lzmafp,
"!# big-endian\n");
1082 lzma_printf(lzmafp,
"!# little-endian\n");
1084 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
1085 lzma_printf(lzmafp,
"!# fixed-rowcount\n");
1089 SDDS_SetError(
"Can't write SDDS layout--error writing description (SDDS_WriteLayout)");
1092 for (i = 0; i < layout->n_parameters; i++)
1094 SDDS_SetError(
"Unable to write layout--error writing parameter definition (SDDS_WriteLayout)");
1097 for (i = 0; i < layout->n_arrays; i++)
1099 SDDS_SetError(
"Unable to write layout--error writing array definition (SDDS_WriteLayout)");
1102 for (i = 0; i < layout->n_columns; i++)
1104 SDDS_SetError(
"Unable to write layout--error writing column definition (SDDS_WriteLayout)");
1108#if RW_ASSOCIATES != 0
1109 for (i = 0; i < layout->n_associates; i++)
1111 SDDS_SetError(
"Unable to write layout--error writing associated file data (SDDS_WriteLayout)");
1117 SDDS_SetError(
"Unable to write layout--error writing data mode (SDDS_WriteLayout)");
1121 layout->layout_written = 1;
1124 if (!(fp = layout->fp)) {
1125 SDDS_SetError(
"Can't write SDDS layout--file pointer is NULL (SDDS_WriteLayout)");
1131 SDDS_SetError(
"Can't write SDDS layout--error writing version (SDDS_WriteLayout)");
1134 if (layout->version < 3) {
1135 if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY) {
1136 if (layout->byteOrderDeclared == SDDS_BIGENDIAN)
1137 fprintf(fp,
"!# big-endian\n");
1139 fprintf(fp,
"!# little-endian\n");
1141 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
1142 fprintf(fp,
"!# fixed-rowcount\n");
1146 SDDS_SetError(
"Can't write SDDS layout--error writing description (SDDS_WriteLayout)");
1150 for (i = 0; i < layout->n_parameters; i++)
1152 SDDS_SetError(
"Unable to write layout--error writing parameter definition (SDDS_WriteLayout)");
1156 for (i = 0; i < layout->n_arrays; i++)
1158 SDDS_SetError(
"Unable to write layout--error writing array definition (SDDS_WriteLayout)");
1162 for (i = 0; i < layout->n_columns; i++)
1164 SDDS_SetError(
"Unable to write layout--error writing column definition (SDDS_WriteLayout)");
1168#if RW_ASSOCIATES != 0
1169 for (i = 0; i < layout->n_associates; i++)
1171 SDDS_SetError(
"Unable to write layout--error writing associated file data (SDDS_WriteLayout)");
1177 SDDS_SetError(
"Unable to write layout--error writing data mode (SDDS_WriteLayout)");
1181 layout->layout_written = 1;
1225 if (SDDS_dataset->parallel_io)
1230 if (!SDDS_dataset->layout.layout_written) {
1231 SDDS_SetError(
"Unable to write page--layout not written (SDDS_WritePage)");
1234 if (SDDS_dataset->layout.disconnected) {
1235 SDDS_SetError(
"Can't write page--file is disconnected (SDDS_WritePage)");
1238 if (SDDS_dataset->layout.data_mode.mode == SDDS_ASCII)
1240 else if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY)
1243 SDDS_SetError(
"Unable to write page--unknown data mode (SDDS_WritePage)");
1289 if (SDDS_dataset->layout.disconnected) {
1290 SDDS_SetError(
"Can't write page--file is disconnected (SDDS_UpdatePage)");
1293 if (SDDS_dataset->page_started == 0) {
1294 SDDS_SetError(
"Can't update page--no page started (SDDS_UpdatePage)");
1297 if (SDDS_dataset->layout.data_mode.mode == SDDS_ASCII)
1299 else if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY)
1302 SDDS_SetError(
"Unable to update page--unknown data mode (SDDS_UpdatePage)");
1334#if defined(vxWorks) || defined(_WIN32) || defined(linux) || defined(__APPLE__)
1337 if (!(SDDS_dataset->layout.fp)) {
1338 SDDS_SetError(
"Unable to sync file--file pointer is NULL (SDDS_SyncDataSet)");
1341 if (SDDS_dataset->layout.data_mode.fsync_data == 0)
1343 if (fsync(fileno(SDDS_dataset->layout.fp)) == 0)
1401int32_t
SDDS_DefineParameter1(
SDDS_DATASET *SDDS_dataset,
const char *name,
const char *symbol,
const char *units,
const char *description,
const char *format_string, int32_t type,
void *fixed_value) {
1402 char buffer[SDDS_MAXLINE];
1406 return SDDS_DefineParameter(SDDS_dataset, name, symbol, units, description, format_string, type, fixed_value);
1411 buffer[SDDS_MAXLINE - 1] = 0;
1412 if (!
SDDS_SprintTypedValue(fixed_value, 0, type, format_string, buffer, 0) || buffer[SDDS_MAXLINE - 1] != 0) {
1413 SDDS_SetError(
"Unable to define fixed value for parameter (SDDS_DefineParameter1)");
1416 return SDDS_DefineParameter(SDDS_dataset, name, symbol, units, description, format_string, type, buffer);
1466int32_t
SDDS_DefineParameter(
SDDS_DATASET *SDDS_dataset,
const char *name,
const char *symbol,
const char *units,
const char *description,
const char *format_string, int32_t type,
char *fixed_value) {
1469 char s[SDDS_MAXLINE];
1471 int32_t index, duplicate;
1478 SDDS_SetError(
"NULL name not allowed for parameter definition");
1481 layout = &SDDS_dataset->layout;
1482 if (!(layout->parameter_definition =
1483 SDDS_Realloc(layout->parameter_definition,
sizeof(*layout->parameter_definition) * (layout->n_parameters + 1))) ||
1484 !(layout->parameter_index =
SDDS_Realloc(layout->parameter_index,
sizeof(*layout->parameter_index) * (layout->n_parameters + 1))) || !(new_indexed_parameter = (
SORTED_INDEX *)
SDDS_Malloc(
sizeof(*new_indexed_parameter)))) {
1485 SDDS_SetError(
"Memory allocation failure (SDDS_DefineParameter)");
1490 index = binaryInsert((
void **)layout->parameter_index, layout->n_parameters, new_indexed_parameter,
SDDS_CompareIndexedNames, &duplicate);
1492 sprintf(s,
"Parameter %s already exists (SDDS_DefineParameter)", name);
1496 layout->parameter_index[index]->index = layout->n_parameters;
1499 SDDS_SetError(
"Unable to define parameter--can't zero memory for parameter definition (SDDS_DefineParameter)");
1502 definition->name = new_indexed_parameter->name;
1504 SDDS_SetError(
"Memory allocation failure (SDDS_DefineParameter)");
1508 SDDS_SetError(
"Memory allocation failure (SDDS_DefineParameter)");
1511 if (description && !
SDDS_CopyString(&definition->description, description)) {
1512 SDDS_SetError(
"Memory allocation failure (SDDS_DefineParameter)");
1519 definition->type = type;
1520 if (format_string) {
1522 SDDS_SetError(
"Invalid format string (SDDS_DefineParameter)");
1526 SDDS_SetError(
"Memory allocation failure (SDDS_DefineParameter)");
1530 if (fixed_value && !
SDDS_CopyString(&(definition->fixed_value), fixed_value)) {
1531 SDDS_SetError(
"Couldn't copy fixed_value string (SDDS_DefineParameter)");
1534 definition->definition_mode = SDDS_NORMAL_DEFINITION;
1539 layout->n_parameters += 1;
1540 return (layout->n_parameters - 1);
1592int32_t
SDDS_DefineArray(
SDDS_DATASET *SDDS_dataset,
const char *name,
const char *symbol,
const char *units,
const char *description,
const char *format_string, int32_t type, int32_t field_length, int32_t dimensions,
const char *group_name) {
1595 char s[SDDS_MAXLINE];
1597 int32_t index, duplicate;
1604 SDDS_SetError(
"NULL name not allowed for array definition");
1607 layout = &SDDS_dataset->layout;
1608 if (!(layout->array_definition =
1609 SDDS_Realloc(layout->array_definition,
sizeof(*layout->array_definition) * (layout->n_arrays + 1))) ||
1610 !(layout->array_index =
SDDS_Realloc(layout->array_index,
sizeof(*layout->array_index) * (layout->n_arrays + 1))) || !(new_indexed_array = (
SORTED_INDEX *)
SDDS_Malloc(
sizeof(*new_indexed_array)))) {
1611 SDDS_SetError(
"Memory allocation failure (SDDS_DefineArray)");
1617 index = binaryInsert((
void **)layout->array_index, layout->n_arrays, new_indexed_array,
SDDS_CompareIndexedNames, &duplicate);
1619 sprintf(s,
"Array %s already exists (SDDS_DefineArray)", name);
1623 layout->array_index[index]->index = layout->n_arrays;
1626 SDDS_SetError(
"Unable to define array--can't zero memory for array definition (SDDS_DefineArray)");
1629 definition->name = new_indexed_array->name;
1631 SDDS_SetError(
"Memory allocation failure (SDDS_DefineArray)");
1638 definition->type = type;
1639 if (format_string) {
1645 SDDS_SetError(
"Memory allocation failure (SDDS_DefineArray)");
1649 if ((definition->field_length = field_length) < 0 && type !=
SDDS_STRING) {
1653 if ((definition->dimensions = dimensions) < 1) {
1654 SDDS_SetError(
"Invalid number of dimensions for array (SDDS_DefineArray)");
1657 layout->n_arrays += 1;
1658 return (layout->n_arrays - 1);
1709int32_t
SDDS_DefineColumn(
SDDS_DATASET *SDDS_dataset,
const char *name,
const char *symbol,
const char *units,
const char *description,
const char *format_string, int32_t type, int32_t field_length) {
1712 char s[SDDS_MAXLINE];
1722 SDDS_SetError(
"NULL name not allowed for column definition");
1725 layout = &SDDS_dataset->layout;
1726 if (!(layout->column_definition =
1727 SDDS_Realloc(layout->column_definition,
sizeof(*layout->column_definition) * (layout->n_columns + 1))) ||
1728 !(layout->column_index =
SDDS_Realloc(layout->column_index,
sizeof(*layout->column_index) * (layout->n_columns + 1))) || !(new_indexed_column = (
SORTED_INDEX *)
SDDS_Malloc(
sizeof(*new_indexed_column)))) {
1729 SDDS_SetError(
"Memory allocation failure (SDDS_DefineColumn)");
1734 index = binaryInsert((
void **)layout->column_index, layout->n_columns, new_indexed_column,
SDDS_CompareIndexedNames, &duplicate);
1736 sprintf(s,
"Column %s already exists (SDDS_DefineColumn)", name);
1740 layout->column_index[index]->index = layout->n_columns;
1742 SDDS_SetError(
"Unable to define column--can't zero memory for column definition (SDDS_DefineColumn)");
1745 definition->name = new_indexed_column->name;
1747 SDDS_SetError(
"Memory allocation failure (SDDS_DefineColumn)");
1751 SDDS_SetError(
"Memory allocation failure (SDDS_DefineColumn)");
1754 if (description && !
SDDS_CopyString(&definition->description, description)) {
1755 SDDS_SetError(
"Memory allocation failure (SDDS_DefineColumn)");
1762 definition->type = type;
1763 if (format_string) {
1769 SDDS_SetError(
"Memory allocation failure (SDDS_DefineColumn)");
1773 if ((definition->field_length = field_length) < 0 && type !=
SDDS_STRING) {
1778 if (SDDS_dataset->n_rows_allocated) {
1779 if (!SDDS_dataset->data) {
1780 SDDS_SetError(
"data array NULL but rows have been allocated! (SDDS_DefineColumn)");
1784 if (!(SDDS_dataset->data =
SDDS_Realloc(SDDS_dataset->data,
sizeof(*SDDS_dataset->data) * (layout->n_columns + 1))) || !(SDDS_dataset->data[layout->n_columns] = calloc(SDDS_dataset->n_rows_allocated,
SDDS_type_size[type - 1]))) {
1785 SDDS_SetError(
"Memory allocation failure (SDDS_DefineColumn)");
1791 definition->definition_mode = SDDS_NORMAL_DEFINITION;
1797 sprintf(s,
"&%s", name);
1800 layout->n_columns += 1;
1801 return (layout->n_columns - 1);
1951 for (i = 0; i < number; i++)
1952 if (
SDDS_DefineColumn(SDDS_dataset, name[i], NULL, unit ? unit[i] : NULL, NULL, NULL, type, 0) < 0)
2008 for (i = 0; i < number; i++)
2009 if (
SDDS_DefineParameter(SDDS_dataset, name[i], NULL, unit ? unit[i] : NULL, NULL, NULL, type, NULL) < 0)
2014static uint32_t nameValidityFlags = 0;
2045 oldFlags = nameValidityFlags;
2046 nameValidityFlags = flags;
2082 int32_t isValid = 1;
2083 char s[SDDS_MAXLINE];
2084 static char *validChars =
"@:#+%-._$&/[]";
2085 static char *startChars =
".:";
2087 if (nameValidityFlags & SDDS_ALLOW_ANY_NAME)
2090 if (strlen(name) == 0)
2092 else if (!(nameValidityFlags & SDDS_ALLOW_V15_NAME)) {
2095 if (!(isalpha(*ptr) || strchr(startChars, *ptr)))
2098 while (isValid && *ptr) {
2099 if (!(isalnum(*ptr) || strchr(validChars, *ptr)))
2104 sprintf(s,
"The following %s name is invalid: >%s<\n(sddsconvert may be used to change the name)\n",
class, name);
2153int32_t
SDDS_DefineAssociate(
SDDS_DATASET *SDDS_dataset,
const char *name,
const char *filename,
const char *path,
const char *description,
const char *contents, int32_t sdds) {
2155#if RW_ASSOCIATES == 0
2160 char s[SDDS_MAXLINE];
2165 layout = &SDDS_dataset->layout;
2166 if (!(layout->associate_definition =
SDDS_Realloc(layout->associate_definition,
sizeof(*layout->associate_definition) * (layout->n_associates + 1)))) {
2167 SDDS_SetError(
"Memory allocation failure (SDDS_DefineAssociate)");
2171 SDDS_SetError(
"NULL name not allowed for associate file (SDDS_DefineAssociate)");
2175 SDDS_SetError(
"NULL filename not allowed for associate file (SDDS_DefineAssociate)");
2179 sprintf(s,
"Associate with name %s already exists (SDDS_DefineAssociate)", name);
2184 SDDS_SetError(
"Unable to define associate--can't zero memory for associate (SDDS_DefineAssociate)");
2189 SDDS_SetError(
"Memory allocation failure (SDDS_DefineAssociate)");
2193 SDDS_SetError(
"Memory allocation failure (SDDS_DefineAssociate)");
2197 SDDS_SetError(
"Memory allocation failure (SDDS_DefineAssociate)");
2201 SDDS_SetError(
"Memory allocation failure (SDDS_DefineAssociate)");
2204 if (description && !
SDDS_CopyString(&definition->description, description)) {
2205 SDDS_SetError(
"Memory allocation failure (SDDS_DefineAssociate)");
2208 definition->sdds = sdds;
2209 layout->n_associates += 1;
2210 return (layout->n_associates - 1);
2249 layout = &SDDS_dataset->layout;
2250 if (SDDS_dataset->data) {
2251 for (i = 0; i < layout->n_columns; i++) {
2252 if (!SDDS_dataset->data[i])
2254 if (layout->column_definition[i].type ==
SDDS_STRING) {
2255 for (j = 0; j < SDDS_dataset->n_rows; j++) {
2256 if (((
char **)SDDS_dataset->data[i])[j]) {
2257 free(((
char **)SDDS_dataset->data[i])[j]);
2258 ((
char **)SDDS_dataset->data[i])[j] = NULL;
2264 SDDS_dataset->n_rows = 0;
2266 if (SDDS_dataset->parameter) {
2267 for (i = 0; i < layout->n_parameters; i++) {
2268 if (!SDDS_dataset->parameter[i])
2270 if (layout->parameter_definition[i].type ==
SDDS_STRING && *(
char **)(SDDS_dataset->parameter[i])) {
2271 free(*(
char **)(SDDS_dataset->parameter[i]));
2272 *(
char **)SDDS_dataset->parameter[i] = NULL;
2277 if (SDDS_dataset->array) {
2278 for (i = 0; i < layout->n_arrays; i++) {
2279 if (SDDS_dataset->array[i].definition->type ==
SDDS_STRING) {
2280 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
2281 if (((
char **)SDDS_dataset->array[i].data)[j]) {
2282 free(((
char **)SDDS_dataset->array[i].data)[j]);
2283 ((
char **)SDDS_dataset->array[i].data)[j] = NULL;
2329 if (SDDS_dataset->layout.layout_written) {
2330 SDDS_SetError(
"Can't change row count mode after writing the layout, or for a file you are reading.");
2333 if (mode & SDDS_VARIABLEROWCOUNT) {
2334 SDDS_dataset->layout.data_mode.fixed_row_count = 0;
2335 SDDS_dataset->layout.data_mode.no_row_counts = 0;
2336 }
else if (mode & SDDS_FIXEDROWCOUNT) {
2337 SDDS_dataset->layout.data_mode.fixed_row_count = 1;
2338 SDDS_dataset->layout.data_mode.fixed_row_increment = 500;
2339 SDDS_dataset->layout.data_mode.no_row_counts = 0;
2340 SDDS_dataset->layout.data_mode.fsync_data = 0;
2341 }
else if (mode & SDDS_NOROWCOUNT) {
2342 SDDS_dataset->layout.data_mode.fixed_row_count = 0;
2343 SDDS_dataset->layout.data_mode.no_row_counts = 1;
2345 SDDS_SetError(
"Invalid row count mode (SDDS_SetRowCountMode).");
2375 SDDS_dataset->layout.data_mode.fsync_data = 0;
2399 SDDS_dataset->layout.data_mode.fsync_data = 1;
2424#if defined(vxWorks) || defined(_WIN32) || defined(__APPLE__)
2427 if (SDDS_dataset && SDDS_dataset->layout.fp)
2428 return fsync(fileno(SDDS_dataset->layout.fp)) == 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_WriteAsciiPage(SDDS_DATASET *SDDS_dataset)
Writes a page of data in ASCII format to the SDDS dataset.
int32_t SDDS_SetDefaultIOBufferSize(int32_t newValue)
void SDDS_SwapLong64(int64_t *data)
Swaps the endianness of a 64-bit integer.
int32_t SDDS_UpdateBinaryPage(SDDS_DATASET *SDDS_dataset, uint32_t mode)
Updates the binary page of an SDDS dataset.
void SDDS_SwapLong(int32_t *data)
Swaps the endianness of a 32-bit integer.
int32_t SDDS_WriteBinaryPage(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_SaveLayout(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_type_size[SDDS_NUM_TYPES]
Array of sizes for each supported data type.
char * SDDS_data_mode[SDDS_NUM_DATA_MODES]
Array of supported data modes.
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
Internal definitions and function declarations for SDDS with LZMA support.
int32_t SDDS_LZMAWriteVersion(int32_t version_number, struct lzmafile *lzmafp)
Writes the SDDS protocol version to an LZMA-compressed file.
int32_t SDDS_LZMAWriteArrayDefinition(ARRAY_DEFINITION *array_definition, struct lzmafile *lzmafp)
Writes an array definition to an LZMA-compressed file.
int32_t SDDS_LZMAWriteColumnDefinition(COLUMN_DEFINITION *column, struct lzmafile *lzmafp)
Writes a column definition to an LZMA-compressed file.
int32_t SDDS_WriteAssociateDefinition(ASSOCIATE_DEFINITION *associate, FILE *fp)
Writes an associate definition to a standard file.
int32_t SDDS_LZMAWriteDescription(char *description, char *contents, struct lzmafile *lzmafp)
Writes the SDDS description section to an LZMA-compressed file.
int32_t SDDS_WriteVersion(int32_t version_number, FILE *fp)
Writes the SDDS protocol version to a standard file.
int32_t SDDS_WriteColumnDefinition(COLUMN_DEFINITION *column, FILE *fp)
Writes a column definition to a standard file.
int32_t SDDS_LZMAWriteDataMode(SDDS_LAYOUT *layout, struct lzmafile *lzmafp)
Writes the data mode section to an LZMA-compressed file.
int32_t SDDS_WriteArrayDefinition(ARRAY_DEFINITION *array_definition, FILE *fp)
Writes an array definition to a standard file.
int32_t SDDS_LZMAWriteAssociateDefinition(ASSOCIATE_DEFINITION *associate, struct lzmafile *lzmafp)
Writes an associate definition to an LZMA-compressed file.
int32_t SDDS_WriteDataMode(SDDS_LAYOUT *layout, FILE *fp)
Writes the data mode section to a standard file.
int32_t SDDS_WriteParameterDefinition(PARAMETER_DEFINITION *parameter, FILE *fp)
Writes a parameter definition to a standard file.
int32_t SDDS_WriteDescription(char *description, char *contents, FILE *fp)
Writes the SDDS description section to a standard file.
int32_t SDDS_LZMAWriteParameterDefinition(PARAMETER_DEFINITION *parameter, struct lzmafile *lzmafp)
Writes a parameter definition to an LZMA-compressed file.
void SDDS_DisableFSync(SDDS_DATASET *SDDS_dataset)
Disables file synchronization for the SDDS dataset.
int32_t SDDS_DefineParameter1(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, void *fixed_value)
Defines a data parameter with a fixed numerical value.
int32_t SDDS_InitializeAppend(SDDS_DATASET *SDDS_dataset, const char *filename)
Initializes the SDDS dataset for appending data by adding a new page to an existing file.
int32_t SDDS_InitializeOutput(SDDS_DATASET *SDDS_dataset, int32_t data_mode, int32_t lines_per_row, const char *description, const char *contents, const char *filename)
Initializes the SDDS output dataset.
int32_t SDDS_InitializeAppendToPage(SDDS_DATASET *SDDS_dataset, const char *filename, int64_t updateInterval, int64_t *rowsPresentReturn)
Initializes the SDDS dataset for appending data to the last page of an existing file.
int32_t SDDS_DefineSimpleColumn(SDDS_DATASET *SDDS_dataset, const char *name, const char *unit, int32_t type)
Defines a simple data column within the SDDS dataset.
int32_t SDDS_EraseData(SDDS_DATASET *SDDS_dataset)
Erases all data entries in the SDDS dataset.
int32_t SDDS_DisconnectFile(SDDS_DATASET *SDDS_dataset)
Disconnects the SDDS dataset from its associated file.
int32_t SDDS_SyncDataSet(SDDS_DATASET *SDDS_dataset)
Synchronizes the SDDS dataset with the disk by flushing buffered data.
int32_t SDDS_DefineAssociate(SDDS_DATASET *SDDS_dataset, const char *name, const char *filename, const char *path, const char *description, const char *contents, int32_t sdds)
Defines an associate for the SDDS dataset.
int32_t SDDS_Parallel_InitializeOutput(SDDS_DATASET *SDDS_dataset, const char *description, const char *contents, const char *filename)
Initializes the SDDS output dataset for parallel processing.
void SDDS_EnableFSync(SDDS_DATASET *SDDS_dataset)
Enables file synchronization for the SDDS dataset.
int32_t SDDS_DefineSimpleParameters(SDDS_DATASET *SDDS_dataset, int32_t number, char **name, char **unit, int32_t type)
Defines multiple simple data parameters of the same data type within the SDDS dataset.
int32_t SDDS_DefineSimpleParameter(SDDS_DATASET *SDDS_dataset, const char *name, const char *unit, int32_t type)
Defines a simple data parameter within the SDDS dataset.
int32_t SDDS_SetRowCountMode(SDDS_DATASET *SDDS_dataset, uint32_t mode)
Sets the row count mode for the SDDS dataset.
int32_t SDDS_DefineArray(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, int32_t field_length, int32_t dimensions, const char *group_name)
Defines a data array within the SDDS dataset.
int32_t SDDS_DefineSimpleColumns(SDDS_DATASET *SDDS_dataset, int32_t number, char **name, char **unit, int32_t type)
Defines multiple simple data columns of the same data type within the SDDS dataset.
int32_t SDDS_ReconnectInputFile(SDDS_DATASET *SDDS_dataset, long position)
Reconnects the input file for the SDDS dataset at a specified position.
int32_t SDDS_DoFSync(SDDS_DATASET *SDDS_dataset)
Synchronizes the SDDS dataset's file to disk.
int32_t SDDS_UpdatePage(SDDS_DATASET *SDDS_dataset, uint32_t mode)
Updates the current page of the SDDS dataset.
int32_t SDDS_SetNameValidityFlags(uint32_t flags)
Sets the validity flags for parameter and column names in the SDDS dataset.
int32_t SDDS_SetNoRowCounts(SDDS_DATASET *SDDS_dataset, int32_t value)
Sets the flag to enable or disable row counts in the SDDS dataset.
int32_t SDDS_WritePage(SDDS_DATASET *SDDS_dataset)
Writes the current data table to the output file.
int32_t SDDS_DefineColumn(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, int32_t field_length)
Defines a data column within the SDDS dataset.
int32_t SDDS_WriteLayout(SDDS_DATASET *SDDS_dataset)
Writes the SDDS layout header to the output file.
int32_t SDDS_ReconnectFile(SDDS_DATASET *SDDS_dataset)
Reconnects the SDDS dataset to its previously associated file.
int32_t SDDS_IsValidName(const char *name, const char *class)
Checks if a given name is valid for a specified class within the SDDS dataset.
long SDDS_DisconnectInputFile(SDDS_DATASET *SDDS_dataset)
Disconnects the input file from the SDDS dataset.
int32_t SDDS_DefineParameter(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, char *fixed_value)
Defines a data parameter with a fixed string value.
int64_t SDDS_CreateRpnMemory(const char *name, short is_string)
Stub function for creating RPN memory when RPN_SUPPORT is not enabled.
int64_t SDDS_CreateRpnArray(char *name)
Stub function for creating RPN arrays when RPN_SUPPORT is not enabled.
int32_t SDDS_FileIsLocked(const char *filename)
Determines if a specified file is locked.
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.
int SDDS_CompareIndexedNames(const void *s1, const void *s2)
Compares two SORTED_INDEX structures by their name fields.
int32_t SDDS_VerifyPrintfFormat(const char *string, int32_t type)
Verifies that a printf format string is compatible with a specified data type.
int32_t SDDS_SprintTypedValue(void *data, int64_t index, int32_t type, const char *format, char *buffer, uint32_t mode)
Formats a data value of a specified type into a string buffer using an optional printf format string.
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_LockFile(FILE *fp, const char *filename, const char *caller)
Attempts to lock a specified file.
int32_t SDDS_GetAssociateIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named associate in the SDDS dataset.
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.
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
int32_t SDDS_MPI_WriteLayout(SDDS_DATASET *SDDS_dataset)
Writes the layout of the SDDS dataset to the MPI file.
int32_t SDDS_MPI_ReconnectFile(SDDS_DATASET *SDDS_dataset)
Reconnects the MPI file associated with the SDDS dataset.
int32_t SDDS_MPI_DisconnectFile(SDDS_DATASET *SDDS_dataset)
Disconnects the MPI file associated with the SDDS dataset.
int32_t SDDS_MPI_WritePage(SDDS_DATASET *SDDS_dataset)
Writes a page of data to the MPI file associated with the SDDS dataset.
#define SDDS_NUM_TYPES
Total number of defined SDDS data types.
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer 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_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
#define SDDS_LONGDOUBLE
Identifier for the long double data type.
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.