24#include "mdb_thread.h"
30# if defined(__BORLANDC__)
31# define _setmode(handle, amode) setmode(handle, amode)
38# error "SDDS_VERSION does not match version of this file"
73 if (SDDS_dataset->parallel_io)
78 if (!SDDS_dataset->layout.filename) {
79 SDDS_SetError(
"Can't disconnect file. No filename given. (SDDS_DisconnectFile)");
82 if (SDDS_dataset->layout.gzipFile) {
83 SDDS_SetError(
"Can't disconnect file because it is a gzip file. (SDDS_DisconnectFile)");
86 if (SDDS_dataset->layout.lzmaFile) {
87 SDDS_SetError(
"Can't disconnect file because it is a lzma or xz file. (SDDS_DisconnectFile)");
90 if (SDDS_dataset->layout.disconnected) {
91 SDDS_SetError(
"Can't disconnect file. Already disconnected. (SDDS_DisconnectFile)");
94 if (SDDS_dataset->page_started && !
SDDS_UpdatePage(SDDS_dataset, FLUSH_TABLE)) {
95 SDDS_SetError(
"Can't disconnect file. Problem updating page. (SDDS_DisconnectFile)");
98 if (fclose(SDDS_dataset->layout.fp)) {
99 SDDS_SetError(
"Can't disconnect file. Problem closing file. (SDDS_DisconnectFile)");
102 SDDS_dataset->layout.disconnected = 1;
129 if (SDDS_dataset->parallel_io)
134 if (!SDDS_dataset->layout.disconnected || !SDDS_dataset->layout.filename) {
135 SDDS_SetError(
"Can't reconnect file. Not disconnected or missing filename. (SDDS_ReconnectFile)");
138 if (!(SDDS_dataset->layout.fp = fopen(SDDS_dataset->layout.filename, FOPEN_READ_AND_WRITE_MODE))) {
140 sprintf(s,
"Unable to open file %s (SDDS_ReconnectFile)", SDDS_dataset->layout.filename);
144 if (fseek(SDDS_dataset->layout.fp, 0, 2) == -1) {
145 SDDS_SetError(
"Can't reconnect file. Fseek failed. (SDDS_ReconnectFile)");
148 SDDS_dataset->original_layout.fp = SDDS_dataset->layout.fp;
149 SDDS_dataset->layout.disconnected = 0;
174 if (SDDS_dataset->parallel_io) {
175 SDDS_SetError(
"Error: MPI mode not supported yet in SDDS_DisconnectInputFile");
181 if (!SDDS_dataset->layout.filename) {
182 SDDS_SetError(
"Can't disconnect file. No filename given. (SDDS_DisconnectInputFile)");
185 if (SDDS_dataset->layout.gzipFile) {
186 SDDS_SetError(
"Can't disconnect file because it is a gzip file. (SDDS_DisconnectInputFile)");
189 if (SDDS_dataset->layout.lzmaFile) {
190 SDDS_SetError(
"Can't disconnect file because it is a lzma or xz file. (SDDS_DisconnectInputFile)");
193 if (SDDS_dataset->layout.disconnected) {
194 SDDS_SetError(
"Can't disconnect file. Already disconnected. (SDDS_DisconnectInputFile)");
197 position = ftell(SDDS_dataset->layout.fp);
198 if (fclose(SDDS_dataset->layout.fp)) {
199 SDDS_SetError(
"Can't disconnect file. Problem closing file. (SDDS_DisconnectInputFile)");
202 SDDS_dataset->layout.disconnected = 1;
232 if (SDDS_dataset->parallel_io) {
233 SDDS_SetError(
"Error: MPI mode not supported yet in SDDS_ReconnectInputFile");
239 if (!SDDS_dataset->layout.disconnected || !SDDS_dataset->layout.filename) {
240 SDDS_SetError(
"Can't reconnect file. Not disconnected or missing filename. (SDDS_ReconnectInputFile)");
243 if (!(SDDS_dataset->layout.fp = fopen(SDDS_dataset->layout.filename, FOPEN_READ_MODE))) {
245 sprintf(s,
"Unable to open file %s (SDDS_ReconnectInputFile)", SDDS_dataset->layout.filename);
249 if (fseek(SDDS_dataset->layout.fp, position, SEEK_SET) == -1) {
250 SDDS_SetError(
"Can't reconnect file. Fseek failed. (SDDS_ReconnectInputFile)");
253 SDDS_dataset->original_layout.fp = SDDS_dataset->layout.fp;
254 SDDS_dataset->layout.disconnected = 0;
290 char s[SDDS_MAXLINE];
291 int64_t endOfLayoutOffset, endOfFileOffset;
297 sprintf(s,
"Unable to initialize input for file %s--can't zero SDDS_DATASET structure (SDDS_InitializeAppend)", filename);
301 SDDS_dataset->layout.popenUsed = SDDS_dataset->layout.gzipFile = SDDS_dataset->layout.lzmaFile = SDDS_dataset->layout.disconnected = 0;
302 SDDS_dataset->layout.depth = SDDS_dataset->layout.data_command_seen = SDDS_dataset->layout.commentFlags = SDDS_dataset->deferSavingLayout = 0;
304 SDDS_dataset->layout.filename = NULL;
306 sprintf(s,
"Memory allocation failure initializing file %s (SDDS_InitializeAppend)", filename);
309 }
else if ((extension = strrchr(filename,
'.')) && ((strcmp(extension,
".gz") == 0) || (strcmp(extension,
".lzma") == 0) || (strcmp(extension,
".xz") == 0))) {
310 sprintf(s,
"Cannot append to a compressed file %s (SDDS_InitializeAppend)", filename);
315 SDDS_dataset->layout.popenUsed = 0;
318 if (_setmode(_fileno(stdin), _O_BINARY) == -1) {
319 sprintf(s,
"unable to set stdin to binary mode");
324 SDDS_dataset->layout.fp = stdin;
327 sprintf(s,
"unable to open file %s for appending--file is locked (SDDS_InitializeAppend)", filename);
331 if (!(SDDS_dataset->layout.fp = fopen(filename, FOPEN_READ_AND_WRITE_MODE))) {
332 sprintf(s,
"Unable to open file %s for appending (SDDS_InitializeAppend)", filename);
336 if (!
SDDS_LockFile(SDDS_dataset->layout.fp, filename,
"SDDS_InitializeAppend"))
342 endOfLayoutOffset = ftell(SDDS_dataset->layout.fp);
343 if (SDDS_dataset->layout.n_columns &&
344 (!(SDDS_dataset->column_flag = (int32_t *)
SDDS_Malloc(
sizeof(int32_t) * SDDS_dataset->layout.n_columns)) ||
345 !(SDDS_dataset->column_order = (int32_t *)
SDDS_Malloc(
sizeof(int32_t) * SDDS_dataset->layout.n_columns)) ||
346 !
SDDS_SetMemory(SDDS_dataset->column_flag, SDDS_dataset->layout.n_columns,
SDDS_LONG, (int32_t)1, (int32_t)0) ||
347 !
SDDS_SetMemory(SDDS_dataset->column_order, SDDS_dataset->layout.n_columns,
SDDS_LONG, (int32_t)0, (int32_t)1))) {
348 SDDS_SetError(
"Unable to initialize input--memory allocation failure (SDDS_InitializeAppend)");
351 if (fseek(SDDS_dataset->layout.fp, 0, 2) == -1) {
352 SDDS_SetError(
"Unable to initialize append--seek failure (SDDS_InitializeAppend)");
355 endOfFileOffset = ftell(SDDS_dataset->layout.fp);
356 if (endOfFileOffset == endOfLayoutOffset)
357 SDDS_dataset->file_had_data = 0;
359 SDDS_dataset->file_had_data = 1;
360 SDDS_dataset->layout.layout_written = 1;
361 SDDS_dataset->mode = SDDS_WRITEMODE;
399 char s[SDDS_MAXLINE];
400 int64_t endOfLayoutOffset, endOfFileOffset, rowCountOffset, offset;
401 int32_t rowsPresent32;
404 int32_t previousBufferSize;
406 *rowsPresentReturn = -1;
410 sprintf(s,
"Unable to initialize input for file %s--can't zero SDDS_DATASET structure (SDDS_InitializeAppendToPage)", filename);
414 SDDS_dataset->layout.popenUsed = SDDS_dataset->layout.gzipFile = SDDS_dataset->layout.lzmaFile = SDDS_dataset->layout.disconnected = 0;
415 SDDS_dataset->layout.depth = SDDS_dataset->layout.data_command_seen = SDDS_dataset->layout.commentFlags = SDDS_dataset->deferSavingLayout = 0;
417 SDDS_dataset->layout.filename = NULL;
419 sprintf(s,
"Memory allocation failure initializing file %s (SDDS_InitializeAppendToPage)", filename);
422 }
else if ((extension = strrchr(filename,
'.')) && ((strcmp(extension,
".gz") == 0) || (strcmp(extension,
".lzma") == 0) || (strcmp(extension,
".xz") == 0))) {
423 sprintf(s,
"Cannot append to a compressed file %s (SDDS_InitializeAppendToPage)", filename);
430 if (_setmode(_fileno(stdin), _O_BINARY) == -1) {
431 sprintf(s,
"unable to set stdin to binary mode");
436 SDDS_dataset->layout.fp = stdin;
439 sprintf(s,
"unable to open file %s for appending--file is locked (SDDS_InitializeAppendToPage)", filename);
443 if (!(SDDS_dataset->layout.fp = fopen(filename, FOPEN_READ_AND_WRITE_MODE))) {
444 sprintf(s,
"Unable to open file %s for appending (SDDS_InitializeAppendToPage)", filename);
448 if (!
SDDS_LockFile(SDDS_dataset->layout.fp, filename,
"SDDS_InitializeAppendToPage")) {
456 endOfLayoutOffset = ftell(SDDS_dataset->layout.fp);
457 if (SDDS_dataset->layout.n_columns &&
458 (!(SDDS_dataset->column_flag = (int32_t *)
SDDS_Malloc(
sizeof(int32_t) * SDDS_dataset->layout.n_columns)) ||
459 !(SDDS_dataset->column_order = (int32_t *)
SDDS_Malloc(
sizeof(int32_t) * SDDS_dataset->layout.n_columns)) ||
460 !
SDDS_SetMemory(SDDS_dataset->column_flag, SDDS_dataset->layout.n_columns,
SDDS_LONG, (int32_t)1, (int32_t)0) ||
461 !
SDDS_SetMemory(SDDS_dataset->column_order, SDDS_dataset->layout.n_columns,
SDDS_LONG, (int32_t)0, (int32_t)1))) {
462 SDDS_SetError(
"Unable to initialize input--memory allocation failure (SDDS_InitializeAppendToPage)");
468 fprintf(stderr,
"Data mode is %s\n",
SDDS_data_mode[SDDS_dataset->layout.data_mode.mode - 1]);
470 SDDS_dataset->pagecount_offset = NULL;
472 if (!SDDS_dataset->layout.data_mode.no_row_counts) {
475 rowCountOffset = SDDS_dataset->rowcount_offset;
476 offset = ftell(SDDS_dataset->layout.fp);
477 fseek(SDDS_dataset->layout.fp, rowCountOffset, 0);
479 if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY) {
480 if (fread(&rowsPresent32,
sizeof(rowsPresent32), 1, SDDS_dataset->layout.fp) == 0) {
481 SDDS_SetError(
"Error: row count not present or not correct length");
484 if (SDDS_dataset->swapByteOrder) {
487 if (rowsPresent32 == INT32_MIN) {
488 if (fread(&rowsPresent,
sizeof(rowsPresent), 1, SDDS_dataset->layout.fp) == 0) {
489 SDDS_SetError(
"Error: row count not present or not correct length");
492 if (SDDS_dataset->swapByteOrder) {
496 rowsPresent = rowsPresent32;
500 if (!fgets(buffer, 30, SDDS_dataset->layout.fp) || strlen(buffer) != 21 || sscanf(buffer,
"%" SCNd64, &rowsPresent) != 1) {
502 fprintf(stderr,
"buffer for row count data: >%s<\n", buffer);
504 SDDS_SetError(
"Unable to initialize input--row count not present or not correct length (SDDS_InitializeAppendToPage)");
509 fseek(SDDS_dataset->layout.fp, offset, 0);
511 fprintf(stderr,
"%" PRId64
" rows present\n", rowsPresent);
514 if (rowCountOffset == -1) {
516 SDDS_SetError(
"Unable to initialize input--problem finding row count offset (SDDS_InitializeAppendToPage)");
521 SDDS_dataset->fBuffer.bytesLeft = SDDS_dataset->fBuffer.bufferSize;
524 fprintf(stderr,
"Starting page with %" PRId64
" rows\n", updateInterval);
527 SDDS_SetError(
"Unable to initialize input--problem starting page (SDDS_InitializeAppendToPage)");
532 if (fseek(SDDS_dataset->layout.fp, 0, 2) == -1) {
533 SDDS_SetError(
"Unable to initialize append--seek failure (SDDS_InitializeAppendToPage)");
536 endOfFileOffset = ftell(SDDS_dataset->layout.fp);
537 if (endOfFileOffset == endOfLayoutOffset)
538 SDDS_dataset->file_had_data = 0;
540 SDDS_dataset->file_had_data = 1;
541 if (rowCountOffset != -1) {
542 SDDS_dataset->rowcount_offset = rowCountOffset;
543 SDDS_dataset->n_rows_written = rowsPresent;
544 SDDS_dataset->first_row_in_mem = rowsPresent;
545 SDDS_dataset->last_row_written = -1;
546 *rowsPresentReturn = rowsPresent;
547 SDDS_dataset->writing_page = 1;
551 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);
553 SDDS_dataset->page_number = 1;
554 SDDS_dataset->layout.layout_written = 1;
555 SDDS_dataset->mode = SDDS_WRITEMODE;
603 char s[SDDS_MAXLINE];
605 char *outputEndianess = NULL;
607 if (data_mode == SDDS_PARALLEL)
610 if (
sizeof(gzFile) !=
sizeof(
void *)) {
611 SDDS_SetError(
"gzFile is not the same size as void *, possible corruption of the SDDS_LAYOUT structure");
617 sprintf(s,
"Unable to initialize output for file %s--can't zero SDDS_DATASET structure (SDDS_InitializeOutput)", filename);
621 SDDS_dataset->layout.popenUsed = SDDS_dataset->layout.gzipFile = SDDS_dataset->layout.lzmaFile = SDDS_dataset->layout.disconnected = 0;
622 SDDS_dataset->layout.depth = SDDS_dataset->layout.data_command_seen = SDDS_dataset->layout.commentFlags = SDDS_dataset->deferSavingLayout = 0;
625 if (_setmode(_fileno(stdout), _O_BINARY) == -1) {
626 sprintf(s,
"unable to set stdout to binary mode");
631 SDDS_dataset->layout.fp = stdout;
634 sprintf(s,
"unable to open file %s for writing--file is locked (SDDS_InitializeOutput)", filename);
638 if ((extension = strrchr(filename,
'.')) && ((strcmp(extension,
".xz") == 0) || (strcmp(extension,
".lzma") == 0))) {
639 SDDS_dataset->layout.lzmaFile = 1;
640 data_mode = SDDS_BINARY;
641 if (!(SDDS_dataset->layout.lzmafp = lzma_open(filename, FOPEN_WRITE_MODE))) {
642 sprintf(s,
"Unable to open file %s for writing (SDDS_InitializeOutput)", filename);
646 SDDS_dataset->layout.fp = SDDS_dataset->layout.lzmafp->fp;
648 if (!(SDDS_dataset->layout.fp = fopen(filename, FOPEN_WRITE_MODE))) {
649 sprintf(s,
"Unable to open file %s for writing (SDDS_InitializeOutput)", filename);
654 if (!
SDDS_LockFile(SDDS_dataset->layout.fp, filename,
"SDDS_InitializeOutput"))
657 if ((extension = strrchr(filename,
'.')) && (strcmp(extension,
".gz") == 0)) {
658 SDDS_dataset->layout.gzipFile = 1;
659 if ((SDDS_dataset->layout.gzfp = gzdopen(fileno(SDDS_dataset->layout.fp), FOPEN_WRITE_MODE)) == NULL) {
660 sprintf(s,
"Unable to open compressed file %s for writing (SDDS_InitializeOutput)", filename);
667 SDDS_dataset->page_number = SDDS_dataset->page_started = 0;
668 SDDS_dataset->file_had_data = SDDS_dataset->layout.layout_written = 0;
670 SDDS_dataset->layout.filename = NULL;
672 sprintf(s,
"Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename);
676 if ((outputEndianess = getenv(
"SDDS_OUTPUT_ENDIANESS"))) {
677 if (strncmp(outputEndianess,
"big", 3) == 0)
678 SDDS_dataset->layout.byteOrderDeclared = SDDS_BIGENDIAN;
679 else if (strncmp(outputEndianess,
"little", 6) == 0)
680 SDDS_dataset->layout.byteOrderDeclared = SDDS_LITTLEENDIAN;
685 if (data_mode < 0 || data_mode > SDDS_NUM_DATA_MODES) {
686 sprintf(s,
"Invalid data mode for file %s (SDDS_InitializeOutput)", filename ? filename :
"stdout");
690 if (data_mode == SDDS_ASCII && lines_per_row <= 0) {
691 sprintf(s,
"Invalid number of lines per row for file %s (SDDS_InitializeOutput)", filename ? filename :
"stdout");
695 SDDS_dataset->layout.version = SDDS_VERSION;
696 SDDS_dataset->layout.data_mode.mode = data_mode;
697 SDDS_dataset->layout.data_mode.lines_per_row = lines_per_row;
698 SDDS_dataset->layout.data_mode.no_row_counts = 0;
699 SDDS_dataset->layout.data_mode.fixed_row_count = 0;
700 SDDS_dataset->layout.data_mode.fsync_data = 0;
701 SDDS_dataset->layout.data_mode.column_memory_mode = DEFAULT_COLUMN_MEMORY_MODE;
703 SDDS_dataset->layout.data_mode.column_major = 0;
704 if (description && !
SDDS_CopyString(&SDDS_dataset->layout.description, description)) {
705 sprintf(s,
"Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename ? filename :
"stdout");
709 if (contents && !
SDDS_CopyString(&SDDS_dataset->layout.contents, contents)) {
710 sprintf(s,
"Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename ? filename :
"stdout");
714 SDDS_dataset->mode = SDDS_WRITEMODE;
715 SDDS_dataset->pagecount_offset = NULL;
716 SDDS_dataset->parallel_io = 0;
757 char s[SDDS_MAXLINE];
758 char *outputEndianess = NULL;
761 if (
sizeof(gzFile) !=
sizeof(
void *)) {
762 SDDS_SetError(
"gzFile is not the same size as void *, possible corruption of the SDDS_LAYOUT structure");
775 SDDS_dataset->layout.popenUsed = SDDS_dataset->layout.gzipFile = SDDS_dataset->layout.lzmaFile = SDDS_dataset->layout.disconnected = 0;
776 SDDS_dataset->layout.depth = SDDS_dataset->layout.data_command_seen = SDDS_dataset->layout.commentFlags = SDDS_dataset->deferSavingLayout = 0;
777 SDDS_dataset->layout.fp = NULL;
779 SDDS_dataset->page_number = SDDS_dataset->page_started = 0;
780 SDDS_dataset->file_had_data = SDDS_dataset->layout.layout_written = 0;
782 SDDS_dataset->layout.filename = NULL;
784 sprintf(s,
"Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename);
788 if ((outputEndianess = getenv(
"SDDS_OUTPUT_ENDIANESS"))) {
789 if (strncmp(outputEndianess,
"big", 3) == 0)
790 SDDS_dataset->layout.byteOrderDeclared = SDDS_BIGENDIAN;
791 else if (strncmp(outputEndianess,
"little", 6) == 0)
792 SDDS_dataset->layout.byteOrderDeclared = SDDS_LITTLEENDIAN;
798 SDDS_dataset->layout.version = SDDS_VERSION;
800 SDDS_dataset->layout.data_mode.mode = SDDS_BINARY;
801 SDDS_dataset->layout.data_mode.lines_per_row = 0;
802 SDDS_dataset->layout.data_mode.no_row_counts = 0;
803 SDDS_dataset->layout.data_mode.fixed_row_count = 0;
804 SDDS_dataset->layout.data_mode.fsync_data = 0;
805 SDDS_dataset->layout.data_mode.column_memory_mode = DEFAULT_COLUMN_MEMORY_MODE;
807 SDDS_dataset->layout.data_mode.column_major = 0;
808 if (description && !
SDDS_CopyString(&SDDS_dataset->layout.description, description)) {
809 sprintf(s,
"Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename ? filename :
"stdout");
813 if (contents && !
SDDS_CopyString(&SDDS_dataset->layout.contents, contents)) {
814 sprintf(s,
"Memory allocation failure initializing file %s (SDDS_InitializeOutput)", filename ? filename :
"stdout");
818 SDDS_dataset->layout.n_parameters = SDDS_dataset->layout.n_columns = SDDS_dataset->layout.n_arrays = SDDS_dataset->layout.n_associates = 0;
819 SDDS_dataset->mode = SDDS_WRITEMODE;
820 SDDS_dataset->pagecount_offset = NULL;
821 SDDS_dataset->parallel_io = 1;
857 if (SDDS_dataset->layout.layout_written) {
858 SDDS_SetError(
"Can't change no_row_counts after writing the layout, or for a file you are reading.");
861 SDDS_dataset->layout.data_mode.no_row_counts = value ? 1 : 0;
908 char *outputEndianess = NULL;
911 if (SDDS_dataset->parallel_io)
920 layout = &SDDS_dataset->layout;
922 if (SDDS_dataset->layout.disconnected) {
923 SDDS_SetError(
"Can't write layout--file is disconnected (SDDS_WriteLayout)");
927 if (layout->layout_written) {
928 SDDS_SetError(
"Can't write layout--already written to file (SDDS_WriteLayout)");
932 if ((outputEndianess = getenv(
"SDDS_OUTPUT_ENDIANESS"))) {
933 if (strncmp(outputEndianess,
"big", 3) == 0)
934 layout->byteOrderDeclared = SDDS_BIGENDIAN;
935 else if (strncmp(outputEndianess,
"little", 6) == 0)
936 layout->byteOrderDeclared = SDDS_LITTLEENDIAN;
939 if (!layout->byteOrderDeclared)
943 for (i = 0; i < layout->n_parameters; i++) {
944 if ((layout->parameter_definition[i].type ==
SDDS_ULONG) || (layout->parameter_definition[i].type ==
SDDS_USHORT)) {
949 for (i = 0; i < layout->n_arrays; i++) {
950 if ((layout->array_definition[i].type ==
SDDS_ULONG) || (layout->array_definition[i].type ==
SDDS_USHORT)) {
955 for (i = 0; i < layout->n_columns; i++) {
956 if ((layout->column_definition[i].type ==
SDDS_ULONG) || (layout->column_definition[i].type ==
SDDS_USHORT)) {
961 if ((layout->data_mode.column_major) && (layout->data_mode.mode == SDDS_BINARY)) {
964 for (i = 0; i < layout->n_parameters; i++) {
970 for (i = 0; i < layout->n_arrays; i++) {
976 for (i = 0; i < layout->n_columns; i++) {
982 if ((LDBL_DIG != 18) && (layout->version == 4)) {
983 if (getenv(
"SDDS_LONGDOUBLE_64BITS") == NULL) {
984 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");
988 for (i = 0; i < layout->n_parameters; i++) {
989 if ((layout->parameter_definition[i].type ==
SDDS_ULONG64) || (layout->parameter_definition[i].type ==
SDDS_LONG64)) {
994 for (i = 0; i < layout->n_arrays; i++) {
1000 for (i = 0; i < layout->n_columns; i++) {
1001 if ((layout->column_definition[i].type ==
SDDS_ULONG64) || (layout->column_definition[i].type ==
SDDS_LONG64)) {
1002 layout->version = 5;
1011 if (SDDS_dataset->layout.gzipFile) {
1012 if (!(gzfp = layout->gzfp)) {
1013 SDDS_SetError(
"Can't write SDDS layout--file pointer is NULL (SDDS_WriteLayout)");
1018 if (!SDDS_GZipWriteVersion(layout->version, gzfp)) {
1019 SDDS_SetError(
"Can't write SDDS layout--error writing version (SDDS_WriteLayout)");
1022 if (layout->version < 3) {
1023 if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY) {
1024 if (layout->byteOrderDeclared == SDDS_BIGENDIAN)
1025 gzprintf(gzfp,
"!# big-endian\n");
1027 gzprintf(gzfp,
"!# little-endian\n");
1029 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
1030 gzprintf(gzfp,
"!# fixed-rowcount\n");
1033 if (!SDDS_GZipWriteDescription(layout->description, layout->contents, gzfp)) {
1034 SDDS_SetError(
"Can't write SDDS layout--error writing description (SDDS_WriteLayout)");
1038 for (i = 0; i < layout->n_parameters; i++)
1039 if (!SDDS_GZipWriteParameterDefinition(layout->parameter_definition + i, gzfp)) {
1040 SDDS_SetError(
"Unable to write layout--error writing parameter definition (SDDS_WriteLayout)");
1044 for (i = 0; i < layout->n_arrays; i++)
1045 if (!SDDS_GZipWriteArrayDefinition(layout->array_definition + i, gzfp)) {
1046 SDDS_SetError(
"Unable to write layout--error writing array definition (SDDS_WriteLayout)");
1050 for (i = 0; i < layout->n_columns; i++)
1051 if (!SDDS_GZipWriteColumnDefinition(layout->column_definition + i, gzfp)) {
1052 SDDS_SetError(
"Unable to write layout--error writing column definition (SDDS_WriteLayout)");
1056# if RW_ASSOCIATES != 0
1057 for (i = 0; i < layout->n_associates; i++)
1058 if (!SDDS_GZipWriteAssociateDefinition(layout->associate_definition + i, gzfp)) {
1059 SDDS_SetError(
"Unable to write layout--error writing associated file data (SDDS_WriteLayout)");
1064 if (!SDDS_GZipWriteDataMode(layout, gzfp)) {
1065 SDDS_SetError(
"Unable to write layout--error writing data mode (SDDS_WriteLayout)");
1069 layout->layout_written = 1;
1073 if (SDDS_dataset->layout.lzmaFile) {
1074 if (!(lzmafp = layout->lzmafp)) {
1075 SDDS_SetError(
"Can't write SDDS layout--file pointer is NULL (SDDS_WriteLayout)");
1081 SDDS_SetError(
"Can't write SDDS layout--error writing version (SDDS_WriteLayout)");
1084 if (layout->version < 3) {
1085 if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY) {
1086 if (layout->byteOrderDeclared == SDDS_BIGENDIAN)
1087 lzma_printf(lzmafp,
"!# big-endian\n");
1089 lzma_printf(lzmafp,
"!# little-endian\n");
1091 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
1092 lzma_printf(lzmafp,
"!# fixed-rowcount\n");
1096 SDDS_SetError(
"Can't write SDDS layout--error writing description (SDDS_WriteLayout)");
1099 for (i = 0; i < layout->n_parameters; i++)
1101 SDDS_SetError(
"Unable to write layout--error writing parameter definition (SDDS_WriteLayout)");
1104 for (i = 0; i < layout->n_arrays; i++)
1106 SDDS_SetError(
"Unable to write layout--error writing array definition (SDDS_WriteLayout)");
1109 for (i = 0; i < layout->n_columns; i++)
1111 SDDS_SetError(
"Unable to write layout--error writing column definition (SDDS_WriteLayout)");
1115#if RW_ASSOCIATES != 0
1116 for (i = 0; i < layout->n_associates; i++)
1118 SDDS_SetError(
"Unable to write layout--error writing associated file data (SDDS_WriteLayout)");
1124 SDDS_SetError(
"Unable to write layout--error writing data mode (SDDS_WriteLayout)");
1128 layout->layout_written = 1;
1131 if (!(fp = layout->fp)) {
1132 SDDS_SetError(
"Can't write SDDS layout--file pointer is NULL (SDDS_WriteLayout)");
1138 SDDS_SetError(
"Can't write SDDS layout--error writing version (SDDS_WriteLayout)");
1141 if (layout->version < 3) {
1142 if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY) {
1143 if (layout->byteOrderDeclared == SDDS_BIGENDIAN)
1144 fprintf(fp,
"!# big-endian\n");
1146 fprintf(fp,
"!# little-endian\n");
1148 if (SDDS_dataset->layout.data_mode.fixed_row_count) {
1149 fprintf(fp,
"!# fixed-rowcount\n");
1153 SDDS_SetError(
"Can't write SDDS layout--error writing description (SDDS_WriteLayout)");
1157 for (i = 0; i < layout->n_parameters; i++)
1159 SDDS_SetError(
"Unable to write layout--error writing parameter definition (SDDS_WriteLayout)");
1163 for (i = 0; i < layout->n_arrays; i++)
1165 SDDS_SetError(
"Unable to write layout--error writing array definition (SDDS_WriteLayout)");
1169 for (i = 0; i < layout->n_columns; i++)
1171 SDDS_SetError(
"Unable to write layout--error writing column definition (SDDS_WriteLayout)");
1175#if RW_ASSOCIATES != 0
1176 for (i = 0; i < layout->n_associates; i++)
1178 SDDS_SetError(
"Unable to write layout--error writing associated file data (SDDS_WriteLayout)");
1184 SDDS_SetError(
"Unable to write layout--error writing data mode (SDDS_WriteLayout)");
1188 layout->layout_written = 1;
1232 if (SDDS_dataset->parallel_io)
1237 if (!SDDS_dataset->layout.layout_written) {
1238 SDDS_SetError(
"Unable to write page--layout not written (SDDS_WritePage)");
1241 if (SDDS_dataset->layout.disconnected) {
1242 SDDS_SetError(
"Can't write page--file is disconnected (SDDS_WritePage)");
1245 if (SDDS_dataset->layout.data_mode.mode == SDDS_ASCII)
1247 else if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY)
1250 SDDS_SetError(
"Unable to write page--unknown data mode (SDDS_WritePage)");
1296 if (SDDS_dataset->layout.disconnected) {
1297 SDDS_SetError(
"Can't write page--file is disconnected (SDDS_UpdatePage)");
1300 if (SDDS_dataset->page_started == 0) {
1301 SDDS_SetError(
"Can't update page--no page started (SDDS_UpdatePage)");
1304 if (SDDS_dataset->layout.data_mode.mode == SDDS_ASCII)
1306 else if (SDDS_dataset->layout.data_mode.mode == SDDS_BINARY)
1309 SDDS_SetError(
"Unable to update page--unknown data mode (SDDS_UpdatePage)");
1341#if defined(vxWorks) || defined(_WIN32) || defined(linux) || defined(__APPLE__)
1344 if (!(SDDS_dataset->layout.fp)) {
1345 SDDS_SetError(
"Unable to sync file--file pointer is NULL (SDDS_SyncDataSet)");
1348 if (SDDS_dataset->layout.data_mode.fsync_data == 0)
1350 if (fsync(fileno(SDDS_dataset->layout.fp)) == 0)
1408int32_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) {
1409 char buffer[SDDS_MAXLINE];
1413 return SDDS_DefineParameter(SDDS_dataset, name, symbol, units, description, format_string, type, fixed_value);
1418 buffer[SDDS_MAXLINE - 1] = 0;
1419 if (!
SDDS_SprintTypedValue(fixed_value, 0, type, format_string, buffer, 0) || buffer[SDDS_MAXLINE - 1] != 0) {
1420 SDDS_SetError(
"Unable to define fixed value for parameter (SDDS_DefineParameter1)");
1423 return SDDS_DefineParameter(SDDS_dataset, name, symbol, units, description, format_string, type, buffer);
1473int32_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) {
1476 char s[SDDS_MAXLINE];
1478 int32_t index, duplicate;
1485 SDDS_SetError(
"NULL name not allowed for parameter definition");
1488 layout = &SDDS_dataset->layout;
1489 if (!(layout->parameter_definition =
1490 SDDS_Realloc(layout->parameter_definition,
sizeof(*layout->parameter_definition) * (layout->n_parameters + 1))) ||
1491 !(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)))) {
1492 SDDS_SetError(
"Memory allocation failure (SDDS_DefineParameter)");
1499 sprintf(s,
"Parameter %s already exists (SDDS_DefineParameter)", name);
1503 layout->parameter_index[index]->index = layout->n_parameters;
1506 SDDS_SetError(
"Unable to define parameter--can't zero memory for parameter definition (SDDS_DefineParameter)");
1509 definition->name = new_indexed_parameter->name;
1511 SDDS_SetError(
"Memory allocation failure (SDDS_DefineParameter)");
1515 SDDS_SetError(
"Memory allocation failure (SDDS_DefineParameter)");
1518 if (description && !
SDDS_CopyString(&definition->description, description)) {
1519 SDDS_SetError(
"Memory allocation failure (SDDS_DefineParameter)");
1526 definition->type = type;
1527 if (format_string) {
1529 SDDS_SetError(
"Invalid format string (SDDS_DefineParameter)");
1533 SDDS_SetError(
"Memory allocation failure (SDDS_DefineParameter)");
1537 if (fixed_value && !
SDDS_CopyString(&(definition->fixed_value), fixed_value)) {
1538 SDDS_SetError(
"Couldn't copy fixed_value string (SDDS_DefineParameter)");
1541 definition->definition_mode = SDDS_NORMAL_DEFINITION;
1546 layout->n_parameters += 1;
1547 return (layout->n_parameters - 1);
1599int32_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) {
1602 char s[SDDS_MAXLINE];
1604 int32_t index, duplicate;
1611 SDDS_SetError(
"NULL name not allowed for array definition");
1614 layout = &SDDS_dataset->layout;
1615 if (!(layout->array_definition =
1616 SDDS_Realloc(layout->array_definition,
sizeof(*layout->array_definition) * (layout->n_arrays + 1))) ||
1617 !(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)))) {
1618 SDDS_SetError(
"Memory allocation failure (SDDS_DefineArray)");
1626 sprintf(s,
"Array %s already exists (SDDS_DefineArray)", name);
1630 layout->array_index[index]->index = layout->n_arrays;
1633 SDDS_SetError(
"Unable to define array--can't zero memory for array definition (SDDS_DefineArray)");
1636 definition->name = new_indexed_array->name;
1638 SDDS_SetError(
"Memory allocation failure (SDDS_DefineArray)");
1645 definition->type = type;
1646 if (format_string) {
1652 SDDS_SetError(
"Memory allocation failure (SDDS_DefineArray)");
1656 if ((definition->field_length = field_length) < 0 && type !=
SDDS_STRING) {
1660 if ((definition->dimensions = dimensions) < 1) {
1661 SDDS_SetError(
"Invalid number of dimensions for array (SDDS_DefineArray)");
1664 layout->n_arrays += 1;
1665 return (layout->n_arrays - 1);
1716int32_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) {
1719 char s[SDDS_MAXLINE];
1729 SDDS_SetError(
"NULL name not allowed for column definition");
1732 layout = &SDDS_dataset->layout;
1733 if (!(layout->column_definition =
1734 SDDS_Realloc(layout->column_definition,
sizeof(*layout->column_definition) * (layout->n_columns + 1))) ||
1735 !(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)))) {
1736 SDDS_SetError(
"Memory allocation failure (SDDS_DefineColumn)");
1743 sprintf(s,
"Column %s already exists (SDDS_DefineColumn)", name);
1747 layout->column_index[index]->index = layout->n_columns;
1749 SDDS_SetError(
"Unable to define column--can't zero memory for column definition (SDDS_DefineColumn)");
1752 definition->name = new_indexed_column->name;
1754 SDDS_SetError(
"Memory allocation failure (SDDS_DefineColumn)");
1758 SDDS_SetError(
"Memory allocation failure (SDDS_DefineColumn)");
1761 if (description && !
SDDS_CopyString(&definition->description, description)) {
1762 SDDS_SetError(
"Memory allocation failure (SDDS_DefineColumn)");
1769 definition->type = type;
1770 if (format_string) {
1776 SDDS_SetError(
"Memory allocation failure (SDDS_DefineColumn)");
1780 if ((definition->field_length = field_length) < 0 && type !=
SDDS_STRING) {
1785 if (SDDS_dataset->n_rows_allocated) {
1786 if (!SDDS_dataset->data) {
1787 SDDS_SetError(
"data array NULL but rows have been allocated! (SDDS_DefineColumn)");
1791 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]))) {
1792 SDDS_SetError(
"Memory allocation failure (SDDS_DefineColumn)");
1798 definition->definition_mode = SDDS_NORMAL_DEFINITION;
1804 sprintf(s,
"&%s", name);
1807 layout->n_columns += 1;
1808 return (layout->n_columns - 1);
1958 for (i = 0; i < number; i++)
1959 if (
SDDS_DefineColumn(SDDS_dataset, name[i], NULL, unit ? unit[i] : NULL, NULL, NULL, type, 0) < 0)
2015 for (i = 0; i < number; i++)
2016 if (
SDDS_DefineParameter(SDDS_dataset, name[i], NULL, unit ? unit[i] : NULL, NULL, NULL, type, NULL) < 0)
2021static MDB_THREAD_LOCK nameValidityFlagsLock = MDB_THREAD_LOCK_INITIALIZER;
2022static uint32_t nameValidityFlags = 0;
2024static uint32_t SDDS_GetLockedNameValidityFlags(
void) {
2026 mdb_thread_lock(&nameValidityFlagsLock);
2027 flags = nameValidityFlags;
2028 mdb_thread_unlock(&nameValidityFlagsLock);
2062 mdb_thread_lock(&nameValidityFlagsLock);
2063 oldFlags = nameValidityFlags;
2064 nameValidityFlags = flags;
2065 mdb_thread_unlock(&nameValidityFlagsLock);
2101 int32_t isValid = 1;
2102 char s[SDDS_MAXLINE];
2103 static const char *
const validChars =
"@:#+%-._$&/[]";
2104 static const char *
const startChars =
".:";
2105 uint32_t flags = SDDS_GetLockedNameValidityFlags();
2107 if (flags & SDDS_ALLOW_ANY_NAME)
2110 if (strlen(name) == 0)
2112 else if (!(flags & SDDS_ALLOW_V15_NAME)) {
2115 if (!(isalpha(*ptr) || strchr(startChars, *ptr)))
2118 while (isValid && *ptr) {
2119 if (!(isalnum(*ptr) || strchr(validChars, *ptr)))
2124 sprintf(s,
"The following %s name is invalid: >%s<\n(sddsconvert may be used to change the name)\n",
class, name);
2173int32_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) {
2175#if RW_ASSOCIATES == 0
2180 char s[SDDS_MAXLINE];
2185 layout = &SDDS_dataset->layout;
2186 if (!(layout->associate_definition =
SDDS_Realloc(layout->associate_definition,
sizeof(*layout->associate_definition) * (layout->n_associates + 1)))) {
2187 SDDS_SetError(
"Memory allocation failure (SDDS_DefineAssociate)");
2191 SDDS_SetError(
"NULL name not allowed for associate file (SDDS_DefineAssociate)");
2195 SDDS_SetError(
"NULL filename not allowed for associate file (SDDS_DefineAssociate)");
2199 sprintf(s,
"Associate with name %s already exists (SDDS_DefineAssociate)", name);
2204 SDDS_SetError(
"Unable to define associate--can't zero memory for associate (SDDS_DefineAssociate)");
2209 SDDS_SetError(
"Memory allocation failure (SDDS_DefineAssociate)");
2213 SDDS_SetError(
"Memory allocation failure (SDDS_DefineAssociate)");
2217 SDDS_SetError(
"Memory allocation failure (SDDS_DefineAssociate)");
2221 SDDS_SetError(
"Memory allocation failure (SDDS_DefineAssociate)");
2224 if (description && !
SDDS_CopyString(&definition->description, description)) {
2225 SDDS_SetError(
"Memory allocation failure (SDDS_DefineAssociate)");
2228 definition->sdds = sdds;
2229 layout->n_associates += 1;
2230 return (layout->n_associates - 1);
2269 layout = &SDDS_dataset->layout;
2270 if (SDDS_dataset->data) {
2271 for (i = 0; i < layout->n_columns; i++) {
2272 if (!SDDS_dataset->data[i])
2274 if (layout->column_definition[i].type ==
SDDS_STRING) {
2275 for (j = 0; j < SDDS_dataset->n_rows; j++) {
2276 if (((
char **)SDDS_dataset->data[i])[j]) {
2277 free(((
char **)SDDS_dataset->data[i])[j]);
2278 ((
char **)SDDS_dataset->data[i])[j] = NULL;
2284 SDDS_dataset->n_rows = 0;
2286 if (SDDS_dataset->parameter) {
2287 for (i = 0; i < layout->n_parameters; i++) {
2288 if (!SDDS_dataset->parameter[i])
2290 if (layout->parameter_definition[i].type ==
SDDS_STRING && *(
char **)(SDDS_dataset->parameter[i])) {
2291 free(*(
char **)(SDDS_dataset->parameter[i]));
2292 *(
char **)SDDS_dataset->parameter[i] = NULL;
2297 if (SDDS_dataset->array) {
2298 for (i = 0; i < layout->n_arrays; i++) {
2299 if (SDDS_dataset->array[i].definition->type ==
SDDS_STRING) {
2300 for (j = 0; j < SDDS_dataset->array[i].elements; j++) {
2301 if (((
char **)SDDS_dataset->array[i].data)[j]) {
2302 free(((
char **)SDDS_dataset->array[i].data)[j]);
2303 ((
char **)SDDS_dataset->array[i].data)[j] = NULL;
2349 if (SDDS_dataset->layout.layout_written) {
2350 SDDS_SetError(
"Can't change row count mode after writing the layout, or for a file you are reading.");
2353 if (mode & SDDS_VARIABLEROWCOUNT) {
2354 SDDS_dataset->layout.data_mode.fixed_row_count = 0;
2355 SDDS_dataset->layout.data_mode.no_row_counts = 0;
2356 }
else if (mode & SDDS_FIXEDROWCOUNT) {
2357 SDDS_dataset->layout.data_mode.fixed_row_count = 1;
2358 SDDS_dataset->layout.data_mode.fixed_row_increment = 500;
2359 SDDS_dataset->layout.data_mode.no_row_counts = 0;
2360 SDDS_dataset->layout.data_mode.fsync_data = 0;
2361 }
else if (mode & SDDS_NOROWCOUNT) {
2362 SDDS_dataset->layout.data_mode.fixed_row_count = 0;
2363 SDDS_dataset->layout.data_mode.no_row_counts = 1;
2365 SDDS_SetError(
"Invalid row count mode (SDDS_SetRowCountMode).");
2395 SDDS_dataset->layout.data_mode.fsync_data = 0;
2419 SDDS_dataset->layout.data_mode.fsync_data = 1;
2444#if defined(vxWorks) || defined(_WIN32) || defined(__APPLE__)
2447 if (SDDS_dataset && SDDS_dataset->layout.fp)
2448 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.
long binaryInsert(void **array, long members, void *newMember, int(*compare)(const void *c1, const void *c2), int32_t *duplicate)
Inserts a new member into a sorted array using binary search.