37 if (SDDS_target->layout.n_columns &&
38 ((!(SDDS_target->column_flag = (int32_t *)
SDDS_Malloc(
sizeof(int32_t) * SDDS_target->layout.n_columns)) ||
39 !(SDDS_target->column_order = (int32_t *)
SDDS_Malloc(
sizeof(int32_t) * SDDS_target->layout.n_columns))) ||
41 !
SDDS_SetMemory(SDDS_target->column_order, SDDS_target->layout.n_columns,
SDDS_LONG, (int32_t)0, (int32_t)1)))) {
42 SDDS_SetError(
"Unable to allocate column flags--memory allocation failure (SDDS_AllocateColumnFlags)");
71 if ((SDDS_dataset->writing_page) && (SDDS_dataset->layout.data_mode.fixed_row_count)) {
76 SDDS_SetError(
"Unable to start page--couldn't restore layout (SDDS_StartPage)");
79 if (expected_n_rows <= 0)
81 SDDS_dataset->n_rows_written = 0;
82 SDDS_dataset->last_row_written = -1;
83 SDDS_dataset->writing_page = 0;
84 SDDS_dataset->first_row_in_mem = 0;
85 layout = &SDDS_dataset->layout;
86 if (SDDS_dataset->page_started == 0) {
87 if (layout->n_parameters) {
88 if (!(SDDS_dataset->parameter = (
void **)calloc(
sizeof(*SDDS_dataset->parameter), layout->n_parameters))) {
89 SDDS_SetError(
"Unable to start page--memory allocation failure (SDDS_StartPage)");
92 for (i = 0; i < layout->n_parameters; i++) {
93 if (!(SDDS_dataset->parameter[i] = (
void *)calloc(
SDDS_type_size[layout->parameter_definition[i].type - 1], 1))) {
94 SDDS_SetError(
"Unable to start page--memory allocation failure (SDDS_StartPage)");
99 if (layout->n_arrays) {
100 if (!(SDDS_dataset->array = (
SDDS_ARRAY *)calloc(
sizeof(*SDDS_dataset->array), layout->n_arrays))) {
101 SDDS_SetError(
"Unable to start page--memory allocation failure (SDDS_StartPage)");
105 if (layout->n_columns) {
106 if (!(SDDS_dataset->data = (
void **)calloc(
sizeof(*SDDS_dataset->data), layout->n_columns))) {
107 SDDS_SetError(
"Unable to start page--memory allocation failure (SDDS_StartPage)");
110 SDDS_dataset->row_flag = NULL;
111 if (expected_n_rows) {
112 if (!(SDDS_dataset->row_flag = (int32_t *)
SDDS_Malloc(
sizeof(int32_t) * expected_n_rows))) {
113 SDDS_SetError(
"Unable to start page--memory allocation failure (SDDS_StartPage)");
116 for (i = 0; i < layout->n_columns; i++) {
117 if (!(SDDS_dataset->data[i] = (
void *)calloc(expected_n_rows,
SDDS_type_size[layout->column_definition[i].type - 1]))) {
118 SDDS_SetError(
"Unable to start page--memory allocation failure (SDDS_StartPage)");
123 SDDS_dataset->n_rows_allocated = expected_n_rows;
124 if (!(SDDS_dataset->column_flag = (int32_t *)
SDDS_Realloc(SDDS_dataset->column_flag,
sizeof(int32_t) * layout->n_columns)) ||
125 !(SDDS_dataset->column_order = (int32_t *)
SDDS_Realloc(SDDS_dataset->column_order,
sizeof(int32_t) * layout->n_columns))) {
126 SDDS_SetError(
"Unable to start page--memory allocation failure (SDDS_StartPage)");
130 }
else if (SDDS_dataset->n_rows_allocated >= expected_n_rows && layout->n_columns) {
131 for (i = 0; i < layout->n_columns; i++) {
132 if (SDDS_dataset->data[i] && layout->column_definition[i].type ==
SDDS_STRING)
135 }
else if (SDDS_dataset->n_rows_allocated < expected_n_rows && layout->n_columns) {
136 if (!SDDS_dataset->data) {
137 if (!(SDDS_dataset->column_flag = (int32_t *)
SDDS_Realloc(SDDS_dataset->column_flag,
sizeof(int32_t) * layout->n_columns)) ||
138 !(SDDS_dataset->column_order = (int32_t *)
SDDS_Realloc(SDDS_dataset->column_order,
sizeof(int32_t) * layout->n_columns)) ||
139 !(SDDS_dataset->data = (
void **)calloc(layout->n_columns,
sizeof(*SDDS_dataset->data)))) {
140 SDDS_SetError(
"Unable to start page--memory allocation failure (SDDS_StartPage)");
144 for (i = 0; i < layout->n_columns; i++) {
146 if (SDDS_dataset->data[i] && layout->column_definition[i].type ==
SDDS_STRING)
148 if (!(SDDS_dataset->data[i] = (
void *)
SDDS_Realloc(SDDS_dataset->data[i], expected_n_rows * size))) {
149 SDDS_SetError(
"Unable to start page--memory allocation failure (SDDS_StartPage)");
152 SDDS_ZeroMemory((
char *)SDDS_dataset->data[i] + size * SDDS_dataset->n_rows_allocated, size * (expected_n_rows - SDDS_dataset->n_rows_allocated));
154 if (!(SDDS_dataset->row_flag = (int32_t *)
SDDS_Realloc(SDDS_dataset->row_flag,
sizeof(int32_t) * expected_n_rows))) {
155 SDDS_SetError(
"Unable to start page--memory allocation failure (SDDS_StartPage)");
158 SDDS_dataset->n_rows_allocated = expected_n_rows;
160 if (SDDS_dataset->n_rows_allocated && layout->n_columns && !
SDDS_SetMemory(SDDS_dataset->row_flag, SDDS_dataset->n_rows_allocated,
SDDS_LONG, (int32_t)1, (int32_t)0)) {
161 SDDS_SetError(
"Unable to start page--memory initialization failure (SDDS_StartPage)");
164 if (layout->n_columns && (!
SDDS_SetMemory(SDDS_dataset->column_flag, layout->n_columns,
SDDS_LONG, (int32_t)1, (int32_t)0) ||
166 SDDS_SetError(
"Unable to start page--memory initialization failure (SDDS_StartPage)");
169 SDDS_dataset->n_of_interest = layout->n_columns;
170 SDDS_dataset->page_number++;
171 SDDS_dataset->page_started = 1;
172 SDDS_dataset->n_rows = 0;
195 layout = &SDDS_dataset->layout;
197 if (layout->n_columns && ((SDDS_dataset->column_flag && !
SDDS_SetMemory(SDDS_dataset->column_flag, layout->n_columns,
SDDS_LONG, (int32_t)1, (int32_t)0)) ||
198 ((SDDS_dataset->column_order && !
SDDS_SetMemory(SDDS_dataset->column_order, layout->n_columns,
SDDS_LONG, (int32_t)0, (int32_t)1))))) {
199 SDDS_SetError(
"Unable to start page--memory initialization failure (SDDS_ClearPage)");
203 if (SDDS_dataset->data) {
204 for (i = 0; i < layout->n_columns; i++) {
206 if (SDDS_dataset->data[i])
207 SDDS_ZeroMemory(SDDS_dataset->data[i], size * SDDS_dataset->n_rows_allocated);
210 if (SDDS_dataset->parameter) {
211 for (i = 0; i < layout->n_parameters; i++) {
216 for (i = 0; i < layout->n_arrays; i++) {
218 if (SDDS_dataset->array && SDDS_dataset->array[i].data && SDDS_dataset->array[i].elements)
219 SDDS_ZeroMemory(SDDS_dataset->array[i].data, size * SDDS_dataset->array[i].elements);
244 layout = &SDDS_dataset->layout;
245 if (!SDDS_dataset->data && !(SDDS_dataset->data = (
void **)calloc(layout->n_columns,
sizeof(*SDDS_dataset->data)))) {
246 SDDS_SetError(
"Unable to start page--memory allocation failure (SDDS_ShortenTable)");
251 for (i = 0; i < layout->n_columns; i++) {
253 if (SDDS_dataset->data[i])
254 free(SDDS_dataset->data[i]);
255 if (!(SDDS_dataset->data[i] = (
void *)calloc(rows, size))) {
256 SDDS_SetError(
"Unable to shorten page--memory allocation failure (SDDS_ShortenTable)");
260 if (SDDS_dataset->row_flag)
261 free(SDDS_dataset->row_flag);
262 if (!(SDDS_dataset->row_flag = (int32_t *)malloc(rows *
sizeof(int32_t)))) {
263 SDDS_SetError(
"Unable to shorten page--memory allocation failure (SDDS_ShortenTable)");
266 SDDS_dataset->n_rows_allocated = rows;
272 SDDS_dataset->n_rows = 0;
274 if (!
SDDS_SetMemory(SDDS_dataset->row_flag, SDDS_dataset->n_rows_allocated,
SDDS_LONG, (int32_t)1, (int32_t)0) ||
275 !
SDDS_SetMemory(SDDS_dataset->column_flag, SDDS_dataset->layout.n_columns,
SDDS_LONG, (int32_t)1, (int32_t)0) ||
276 !
SDDS_SetMemory(SDDS_dataset->column_order, SDDS_dataset->layout.n_columns,
SDDS_LONG, (int32_t)0, (int32_t)1)) {
277 SDDS_SetError(
"Unable to shorten page--memory initialization failure (SDDS_ShortenTable)");
302 layout = &SDDS_dataset->layout;
304 fprintf(stderr,
"table size being increased from %" PRId64
" to %" PRId64
" rows\n", SDDS_dataset->n_rows_allocated, SDDS_dataset->n_rows_allocated + n_additional_rows);
306 if (!SDDS_dataset->data && !(SDDS_dataset->data = (
void **)calloc(layout->n_columns,
sizeof(*SDDS_dataset->data)))) {
307 SDDS_SetError(
"Unable to start page--memory allocation failure1 (SDDS_LengthenTable)");
310 if (n_additional_rows < 0)
311 n_additional_rows = 0;
312 for (i = 0; i < layout->n_columns; i++) {
314 if (!(SDDS_dataset->data[i] = (
void *)
SDDS_Realloc(SDDS_dataset->data[i], (SDDS_dataset->n_rows_allocated + n_additional_rows) * size))) {
315 SDDS_SetError(
"Unable to lengthen page--memory allocation failure2 (SDDS_LengthenTable)");
318 SDDS_ZeroMemory((
char *)SDDS_dataset->data[i] + size * SDDS_dataset->n_rows_allocated, size * n_additional_rows);
320 if (!(SDDS_dataset->row_flag = (int32_t *)
SDDS_Realloc(SDDS_dataset->row_flag, (SDDS_dataset->n_rows_allocated + n_additional_rows) *
sizeof(int32_t)))) {
321 SDDS_SetError(
"Unable to lengthen page--memory allocation failure3 (SDDS_LengthenTable)");
324 SDDS_dataset->n_rows_allocated += n_additional_rows;
326 if (!
SDDS_SetMemory(SDDS_dataset->row_flag, SDDS_dataset->n_rows_allocated,
SDDS_LONG, (int32_t)1, (int32_t)0) ||
327 !
SDDS_SetMemory(SDDS_dataset->column_flag, SDDS_dataset->layout.n_columns,
SDDS_LONG, (int32_t)1, (int32_t)0) ||
328 !
SDDS_SetMemory(SDDS_dataset->column_order, SDDS_dataset->layout.n_columns,
SDDS_LONG, (int32_t)0, (int32_t)1)) {
329 SDDS_SetError(
"Unable to lengthen page--memory initialization failure4 (SDDS_LengthenTable)");
371 int32_t index, retval;
374 char s[SDDS_MAXLINE];
378 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME) || !(mode & SDDS_PASS_BY_VALUE || mode & SDDS_PASS_BY_REFERENCE)) {
379 SDDS_SetError(
"Unable to set parameter values--unknown mode (SDDS_SetParameters)");
383 va_start(argptr, mode);
384 layout = &SDDS_dataset->layout;
389 if (mode & SDDS_SET_BY_INDEX) {
390 if ((index = va_arg(argptr, int32_t)) == -1) {
394 if (index < 0 || index >= layout->n_parameters) {
395 SDDS_SetError(
"Unable to set parameter values--index out of range (SDDS_SetParameters)");
400 if ((name = va_arg(argptr,
char *)) == NULL) {
405 sprintf(s,
"Unable to set parameter values--name %s not recognized (SDDS_SetParameters)", name);
411 switch (layout->parameter_definition[index].type) {
413 if (mode & SDDS_PASS_BY_VALUE)
414 *((
short *)SDDS_dataset->parameter[index]) = (short)va_arg(argptr,
int);
416 *((
short *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
short *));
419 if (mode & SDDS_PASS_BY_VALUE)
420 *((
unsigned short *)SDDS_dataset->parameter[index]) = (
unsigned short)va_arg(argptr,
unsigned int);
422 *((
unsigned short *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
unsigned short *));
425 if (mode & SDDS_PASS_BY_VALUE)
426 *((int32_t *)SDDS_dataset->parameter[index]) = (int32_t)va_arg(argptr, int32_t);
428 *((int32_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, int32_t *));
431 if (mode & SDDS_PASS_BY_VALUE)
432 *((uint32_t *)SDDS_dataset->parameter[index]) = (uint32_t)va_arg(argptr, uint32_t);
434 *((uint32_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, uint32_t *));
437 if (mode & SDDS_PASS_BY_VALUE)
438 *((int64_t *)SDDS_dataset->parameter[index]) = (int64_t)va_arg(argptr, int64_t);
440 *((int64_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, int64_t *));
443 if (mode & SDDS_PASS_BY_VALUE)
444 *((uint64_t *)SDDS_dataset->parameter[index]) = (uint64_t)va_arg(argptr, uint64_t);
446 *((uint64_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, uint64_t *));
449 if (mode & SDDS_PASS_BY_VALUE)
450 *((
float *)SDDS_dataset->parameter[index]) = (float)va_arg(argptr,
double);
452 *((
float *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
float *));
455 if (mode & SDDS_PASS_BY_VALUE)
456 *((
double *)SDDS_dataset->parameter[index]) = va_arg(argptr,
double);
458 *((
double *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
double *));
461 if (mode & SDDS_PASS_BY_VALUE)
462 *((
long double *)SDDS_dataset->parameter[index]) = va_arg(argptr,
long double);
464 *((
long double *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
long double *));
467 if (*(
char **)SDDS_dataset->parameter[index])
468 free(*(
char **)SDDS_dataset->parameter[index]);
469 if (mode & SDDS_PASS_BY_VALUE) {
470 if (!
SDDS_CopyString((
char **)SDDS_dataset->parameter[index], va_arg(argptr,
char *))) {
471 SDDS_SetError(
"Unable to set string parameter value--allocation failure (SDDS_SetParameters)");
475 if (!
SDDS_CopyString((
char **)SDDS_dataset->parameter[index], *(va_arg(argptr,
char **)))) {
476 SDDS_SetError(
"Unable to set string parameter value--allocation failure (SDDS_SetParameters)");
482 if (mode & SDDS_PASS_BY_VALUE)
483 *((
char *)SDDS_dataset->parameter[index]) = (char)va_arg(argptr,
int);
485 *((
char *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
char *));
488 SDDS_SetError(
"Unknown data type encountered (SDDS_SetParameters)");
491 }
while (retval == -1);
538 char s[SDDS_MAXLINE];
542 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME) || !(mode & SDDS_PASS_BY_VALUE || mode & SDDS_PASS_BY_REFERENCE)) {
543 SDDS_SetError(
"Unable to set parameter values--unknown mode (SDDS_SetParameters)");
547 va_start(argptr, mode);
548 layout = &SDDS_dataset->layout;
551 if (mode & SDDS_SET_BY_INDEX) {
552 if ((index = va_arg(argptr, int32_t)) == -1) {
553 SDDS_SetError(
"Unable to set parameter values--index is null (SDDS_SetParameter)");
557 if (index < 0 || index >= layout->n_parameters) {
558 SDDS_SetError(
"Unable to set parameter values--index out of range (SDDS_SetParameter)");
563 if ((name = va_arg(argptr,
char *)) == NULL) {
564 SDDS_SetError(
"Unable to set parameter values--name is null (SDDS_SetParameter)");
569 sprintf(s,
"Unable to set parameter values--name %s not recognized (SDDS_SetParameter)", name);
575 switch (layout->parameter_definition[index].type) {
577 if (mode & SDDS_PASS_BY_VALUE)
578 *((
short *)SDDS_dataset->parameter[index]) = (short)va_arg(argptr,
int);
580 *((
short *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
short *));
583 if (mode & SDDS_PASS_BY_VALUE)
584 *((
unsigned short *)SDDS_dataset->parameter[index]) = (
unsigned short)va_arg(argptr,
unsigned int);
586 *((
unsigned short *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
unsigned short *));
589 if (mode & SDDS_PASS_BY_VALUE)
590 *((int32_t *)SDDS_dataset->parameter[index]) = (int32_t)va_arg(argptr, int32_t);
592 *((int32_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, int32_t *));
595 if (mode & SDDS_PASS_BY_VALUE)
596 *((uint32_t *)SDDS_dataset->parameter[index]) = (uint32_t)va_arg(argptr, uint32_t);
598 *((uint32_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, uint32_t *));
601 if (mode & SDDS_PASS_BY_VALUE)
602 *((int64_t *)SDDS_dataset->parameter[index]) = (int64_t)va_arg(argptr, int64_t);
604 *((int64_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, int64_t *));
607 if (mode & SDDS_PASS_BY_VALUE)
608 *((uint64_t *)SDDS_dataset->parameter[index]) = (uint64_t)va_arg(argptr, uint64_t);
610 *((uint64_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr, uint64_t *));
613 if (mode & SDDS_PASS_BY_VALUE)
614 *((
float *)SDDS_dataset->parameter[index]) = (float)va_arg(argptr,
double);
616 *((
float *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
float *));
619 if (mode & SDDS_PASS_BY_VALUE)
620 *((
double *)SDDS_dataset->parameter[index]) = va_arg(argptr,
double);
622 *((
double *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
double *));
625 if (mode & SDDS_PASS_BY_VALUE)
626 *((
long double *)SDDS_dataset->parameter[index]) = va_arg(argptr,
long double);
628 *((
long double *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
long double *));
631 if (*(
char **)SDDS_dataset->parameter[index])
632 free(*(
char **)SDDS_dataset->parameter[index]);
633 if (mode & SDDS_PASS_BY_VALUE) {
634 if (!
SDDS_CopyString((
char **)SDDS_dataset->parameter[index], va_arg(argptr,
char *))) {
635 SDDS_SetError(
"Unable to set string parameter value--allocation failure (SDDS_SetParameters)");
640 if (!
SDDS_CopyString((
char **)SDDS_dataset->parameter[index], *(va_arg(argptr,
char **)))) {
641 SDDS_SetError(
"Unable to set string parameter value--allocation failure (SDDS_SetParameters)");
648 if (mode & SDDS_PASS_BY_VALUE)
649 *((
char *)SDDS_dataset->parameter[index]) = (char)va_arg(argptr,
int);
651 *((
char *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
char *));
654 SDDS_SetError(
"Unknown data type encountered (SDDS_SetParameters)");
699 int32_t index, retval;
702 char s[SDDS_MAXLINE];
706 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME) || !(mode & SDDS_PASS_BY_VALUE || mode & SDDS_PASS_BY_REFERENCE)) {
707 SDDS_SetError(
"Unable to set parameter values--unknown mode (SDDS_SetParametersFromDoubles)");
711 va_start(argptr, mode);
712 layout = &SDDS_dataset->layout;
717 if (mode & SDDS_SET_BY_INDEX) {
718 if ((index = va_arg(argptr, int32_t)) == -1) {
722 if (index < 0 || index >= layout->n_parameters) {
723 sprintf(s,
"Unable to set parameter values--index %" PRId32
" out of range [%d, %" PRId32
"] (SDDS_SetParametersFromDoubles)", index, 0, layout->n_parameters);
729 if ((name = va_arg(argptr,
char *)) == NULL) {
734 sprintf(s,
"Unable to set parameter values--name %s not recognized (SDDS_SetParametersFromDoubles)", name);
740 switch (layout->parameter_definition[index].type) {
742 if (mode & SDDS_PASS_BY_VALUE)
743 *((
short *)SDDS_dataset->parameter[index]) = va_arg(argptr,
double);
745 *((
short *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
double *));
748 if (mode & SDDS_PASS_BY_VALUE)
749 *((
unsigned short *)SDDS_dataset->parameter[index]) = va_arg(argptr,
double);
751 *((
unsigned short *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
double *));
754 if (mode & SDDS_PASS_BY_VALUE)
755 *((int32_t *)SDDS_dataset->parameter[index]) = va_arg(argptr,
double);
757 *((int32_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
double *));
760 if (mode & SDDS_PASS_BY_VALUE)
761 *((uint32_t *)SDDS_dataset->parameter[index]) = va_arg(argptr,
double);
763 *((uint32_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
double *));
766 if (mode & SDDS_PASS_BY_VALUE)
767 *((int64_t *)SDDS_dataset->parameter[index]) = va_arg(argptr,
double);
769 *((int64_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
double *));
772 if (mode & SDDS_PASS_BY_VALUE)
773 *((uint64_t *)SDDS_dataset->parameter[index]) = va_arg(argptr,
double);
775 *((uint64_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
double *));
778 if (mode & SDDS_PASS_BY_VALUE)
779 *((
float *)SDDS_dataset->parameter[index]) = (float)va_arg(argptr,
double);
781 *((
float *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
double *));
784 if (mode & SDDS_PASS_BY_VALUE)
785 *((
double *)SDDS_dataset->parameter[index]) = va_arg(argptr,
double);
787 *((
double *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
double *));
791 SDDS_SetError(
"Nonnumeric data type encountered (SDDS_SetParametersFromDoubles)");
795 SDDS_SetError(
"Unknown data type encountered (SDDS_SetParametersFromDoubles)");
798 }
while (retval == -1);
840 int32_t index, retval;
843 char s[SDDS_MAXLINE];
847 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME) || !(mode & SDDS_PASS_BY_VALUE || mode & SDDS_PASS_BY_REFERENCE)) {
848 SDDS_SetError(
"Unable to set parameter values--unknown mode (SDDS_SetParametersFromLongDoubles)");
852 va_start(argptr, mode);
853 layout = &SDDS_dataset->layout;
858 if (mode & SDDS_SET_BY_INDEX) {
859 if ((index = va_arg(argptr, int32_t)) == -1) {
863 if (index < 0 || index >= layout->n_parameters) {
864 sprintf(s,
"Unable to set parameter values--index %" PRId32
" out of range [%d, %" PRId32
"] (SDDS_SetParametersFromLongDoubles)", index, 0, layout->n_parameters);
870 if ((name = va_arg(argptr,
char *)) == NULL) {
875 sprintf(s,
"Unable to set parameter values--name %s not recognized (SDDS_SetParametersFromLongDoubles)", name);
881 switch (layout->parameter_definition[index].type) {
883 if (mode & SDDS_PASS_BY_VALUE)
884 *((
short *)SDDS_dataset->parameter[index]) = va_arg(argptr,
long double);
886 *((
short *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
long double *));
889 if (mode & SDDS_PASS_BY_VALUE)
890 *((
unsigned short *)SDDS_dataset->parameter[index]) = va_arg(argptr,
long double);
892 *((
unsigned short *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
long double *));
895 if (mode & SDDS_PASS_BY_VALUE)
896 *((int32_t *)SDDS_dataset->parameter[index]) = va_arg(argptr,
long double);
898 *((int32_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
long double *));
901 if (mode & SDDS_PASS_BY_VALUE)
902 *((uint32_t *)SDDS_dataset->parameter[index]) = va_arg(argptr,
long double);
904 *((uint32_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
long double *));
907 if (mode & SDDS_PASS_BY_VALUE)
908 *((int64_t *)SDDS_dataset->parameter[index]) = va_arg(argptr,
long double);
910 *((int64_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
long double *));
913 if (mode & SDDS_PASS_BY_VALUE)
914 *((uint64_t *)SDDS_dataset->parameter[index]) = va_arg(argptr,
long double);
916 *((uint64_t *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
long double *));
919 if (mode & SDDS_PASS_BY_VALUE)
920 *((
float *)SDDS_dataset->parameter[index]) = (float)va_arg(argptr,
long double);
922 *((
float *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
long double *));
925 if (mode & SDDS_PASS_BY_VALUE)
926 *((
double *)SDDS_dataset->parameter[index]) = va_arg(argptr,
long double);
928 *((
double *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
long double *));
931 if (mode & SDDS_PASS_BY_VALUE)
932 *((
long double *)SDDS_dataset->parameter[index]) = va_arg(argptr,
long double);
934 *((
long double *)SDDS_dataset->parameter[index]) = *(va_arg(argptr,
long double *));
938 SDDS_SetError(
"Nonnumeric data type encountered (SDDS_SetParametersFromLongDoubles)");
942 SDDS_SetError(
"Unknown data type encountered (SDDS_SetParametersFromLongDoubles)");
945 }
while (retval == -1);
998 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME) || !(mode & SDDS_PASS_BY_VALUE || mode & SDDS_PASS_BY_REFERENCE)) {
999 SDDS_SetError(
"Unable to set column values--unknown mode (SDDS_SetRowValues)");
1004 row -= SDDS_dataset->first_row_in_mem;
1005 if (row >= SDDS_dataset->n_rows_allocated) {
1006 sprintf(buffer,
"Unable to set column values--row number (%" PRId64
") exceeds exceeds allocated memory (%" PRId64
") (SDDS_SetRowValues)", row, SDDS_dataset->n_rows_allocated);
1010 if (row > SDDS_dataset->n_rows - 1)
1011 SDDS_dataset->n_rows = row + 1;
1013 va_start(argptr, row);
1014 layout = &SDDS_dataset->layout;
1019 fprintf(stderr,
"setting row %" PRId64
" (mem slot %" PRId64
")\n", row + SDDS_dataset->first_row_in_mem, row);
1022 if (mode & SDDS_SET_BY_INDEX) {
1023 if ((index = va_arg(argptr, int32_t)) == -1) {
1027 if (index < 0 || index >= layout->n_columns) {
1028 SDDS_SetError(
"Unable to set column values--index out of range (SDDS_SetRowValues)");
1033 fprintf(stderr,
"Setting values for column #%" PRId32
"\n", index);
1036 if ((name = va_arg(argptr,
char *)) == NULL) {
1041 fprintf(stderr,
"Setting values for column %s\n", name);
1044 SDDS_SetError(
"Unable to set column values--name not recognized (SDDS_SetRowValues)");
1049 switch (layout->column_definition[index].type) {
1051 if (mode & SDDS_PASS_BY_VALUE)
1052 *(((
short *)SDDS_dataset->data[index]) + row) = (short)va_arg(argptr,
int);
1054 *(((
short *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr,
short *));
1057 if (mode & SDDS_PASS_BY_VALUE)
1058 *(((
unsigned short *)SDDS_dataset->data[index]) + row) = (
unsigned short)va_arg(argptr,
unsigned int);
1060 *(((
unsigned short *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr,
unsigned short *));
1063 if (mode & SDDS_PASS_BY_VALUE)
1064 *(((int32_t *)SDDS_dataset->data[index]) + row) = va_arg(argptr, int32_t);
1066 *(((int32_t *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, int32_t *));
1069 if (mode & SDDS_PASS_BY_VALUE)
1070 *(((uint32_t *)SDDS_dataset->data[index]) + row) = va_arg(argptr, uint32_t);
1072 *(((uint32_t *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, uint32_t *));
1075 if (mode & SDDS_PASS_BY_VALUE)
1076 *(((int64_t *)SDDS_dataset->data[index]) + row) = va_arg(argptr, int64_t);
1078 *(((int64_t *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, int64_t *));
1081 if (mode & SDDS_PASS_BY_VALUE)
1082 *(((uint64_t *)SDDS_dataset->data[index]) + row) = va_arg(argptr, uint64_t);
1084 *(((uint64_t *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr, uint64_t *));
1087 if (mode & SDDS_PASS_BY_VALUE)
1088 *(((
float *)SDDS_dataset->data[index]) + row) = (float)va_arg(argptr,
double);
1090 *(((
float *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr,
float *));
1093 if (mode & SDDS_PASS_BY_VALUE)
1094 *(((
double *)SDDS_dataset->data[index]) + row) = va_arg(argptr,
double);
1096 *(((
double *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr,
double *));
1099 if (mode & SDDS_PASS_BY_VALUE)
1100 *(((
long double *)SDDS_dataset->data[index]) + row) = va_arg(argptr,
long double);
1102 *(((
long double *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr,
long double *));
1105 if (((
char **)SDDS_dataset->data[index])[row]) {
1106 free(((
char **)SDDS_dataset->data[index])[row]);
1107 ((
char **)SDDS_dataset->data[index])[row] = NULL;
1109 if (mode & SDDS_PASS_BY_VALUE) {
1110 if (!
SDDS_CopyString((
char **)SDDS_dataset->data[index] + row, va_arg(argptr,
char *))) {
1111 SDDS_SetError(
"Unable to set string column value--allocation failure (SDDS_SetRowValues)");
1115 if (!
SDDS_CopyString((
char **)SDDS_dataset->data[index] + row, *(va_arg(argptr,
char **)))) {
1116 SDDS_SetError(
"Unable to set string column value--allocation failure (SDDS_SetRowValues)");
1122 if (mode & SDDS_PASS_BY_VALUE)
1123 *(((
char *)SDDS_dataset->data[index]) + row) = (char)va_arg(argptr,
int);
1125 *(((
char *)SDDS_dataset->data[index]) + row) = *(va_arg(argptr,
char *));
1128 SDDS_SetError(
"Unknown data type encountered (SDDS_SetRowValues");
1132 }
while (retval == -1);
1159 int32_t index, retval, i, size;
1160 int32_t *counter = NULL;
1167 if (!(mode & SDDS_POINTER_ARRAY) && !(mode & SDDS_CONTIGUOUS_DATA)) {
1168 SDDS_SetError(
"Unable to set array--invalid mode (SDDS_SetArrayVararg)");
1172 SDDS_SetError(
"Unable to set array--unknown array name given (SDDS_SetArrayVararg)");
1175 if (!SDDS_dataset->array) {
1176 SDDS_SetError(
"Unable to set array--internal array pointer is NULL (SDDS_SetArrayVararg)");
1180 layout = &SDDS_dataset->layout;
1181 array = SDDS_dataset->array + index;
1182 if (!layout->array_definition) {
1183 SDDS_SetError(
"Unable to set array--internal array definition pointer is NULL (SDDS_SetArrayVararg)");
1186 array->definition = layout->array_definition + index;
1187 if (!array->dimension && !(array->dimension = (int32_t *)
SDDS_Malloc(
sizeof(*array->dimension) * array->definition->dimensions))) {
1188 SDDS_SetError(
"Unable to set array--allocation failure (SDDS_SetArrayVararg)");
1192 va_start(argptr, data_pointer);
1197 array->elements = 1;
1199 if ((array->dimension[index] = va_arg(argptr, int32_t)) < 0) {
1200 SDDS_SetError(
"Unable to set array--negative dimension given (SDDS_SetArrayVararg)");
1204 array->elements *= array->dimension[index];
1205 }
while (retval == 1 && ++index < array->definition->dimensions);
1210 if (!array->elements)
1212 if (!data_pointer) {
1213 SDDS_SetError(
"Unable to set array--data pointer is NULL (SDDS_SetArrayVararg)");
1218 if (!(array->data =
SDDS_Realloc(array->data, size * array->elements))) {
1219 SDDS_SetError(
"Unable to set array--allocation failure (SDDS_SetArrayVararg");
1224 if (array->definition->dimensions == 1 || mode & SDDS_CONTIGUOUS_DATA) {
1226 memcpy(array->data, data_pointer, size * array->elements);
1228 SDDS_SetError(
"Unable to set array--string copy failure (SDDS_SetArrayVararg");
1234 if (!(counter =
SDDS_Realloc(counter,
sizeof(*counter) * (array->elements - 1)))) {
1235 SDDS_SetError(
"Unable to set array--allocation failure (SDDS_SetArrayVararg");
1242 for (i = 0; i < array->definition->dimensions - 1; i++)
1243 ptr = ((
void **)ptr)[counter[i]];
1245 memcpy((
char *)array->data + size * index, ptr, size * array->dimension[i]);
1247 SDDS_SetError(
"Unable to set array--string copy failure (SDDS_SetArrayVararg");
1250 index += array->dimension[i];
1251 }
while (
SDDS_AdvanceCounter(counter, array->dimension, array->definition->dimensions - 1) != -1);
1279 int32_t index, i, size;
1280 int32_t *counter = NULL;
1287 if (!(mode & SDDS_POINTER_ARRAY) && !(mode & SDDS_CONTIGUOUS_DATA)) {
1288 SDDS_SetError(
"Unable to set array--invalid mode (SDDS_SetArray)");
1292 SDDS_SetError(
"Unable to set array--unknown array name given (SDDS_SetArray)");
1297 SDDS_SetError(
"Unable to set array--dimension pointer is NULL (SDDS_SetArray)");
1300 if (!SDDS_dataset->array) {
1301 SDDS_SetError(
"Unable to set array--internal array pointer is NULL (SDDS_SetArray)");
1305 layout = &SDDS_dataset->layout;
1306 array = SDDS_dataset->array + index;
1307 if (!layout->array_definition) {
1308 SDDS_SetError(
"Unable to set array--internal array definition pointer is NULL (SDDS_SetArray)");
1311 array->definition = layout->array_definition + index;
1312 if (!array->dimension && !(array->dimension = (int32_t *)
SDDS_Malloc(
sizeof(*array->dimension) * array->definition->dimensions))) {
1313 SDDS_SetError(
"Unable to set array--allocation failure (SDDS_SetArray)");
1316 array->elements = 1;
1317 for (i = 0; i < array->definition->dimensions; i++) {
1318 if ((array->dimension[i] = dimension[i]) < 0) {
1319 SDDS_SetError(
"Unable to set array--negative dimension specified (SDDS_SetArray)");
1322 array->elements *= dimension[i];
1323 if (array->elements && !data_pointer) {
1324 SDDS_SetError(
"Unable to set array--data pointer is NULL (SDDS_SetArray)");
1328 if (!array->elements)
1332 if (!(array->data =
SDDS_Realloc(array->data, size * array->elements))) {
1333 SDDS_SetError(
"Unable to set array--allocation failure (SDDS_SetArray)");
1338 if (array->definition->dimensions == 1 || mode & SDDS_CONTIGUOUS_DATA) {
1340 memcpy(array->data, data_pointer, size * array->elements);
1342 SDDS_SetError(
"Unable to set array--string copy failure (SDDS_SetArrayVararg");
1348 if (!(counter =
SDDS_Realloc(counter,
sizeof(*counter) * (array->elements - 1)))) {
1349 SDDS_SetError(
"Unable to set array--allocation failure (SDDS_SetArray)");
1356 for (i = 0; i < array->definition->dimensions - 1; i++)
1357 ptr = ((
void **)ptr)[counter[i]];
1359 memcpy((
char *)array->data + size * index, ptr, size * array->dimension[i]);
1361 SDDS_SetError(
"Unable to set array--string copy failure (SDDS_SetArray)");
1364 index += array->dimension[i];
1365 }
while (
SDDS_AdvanceCounter(counter, array->dimension, array->definition->dimensions - 1) != -1);
1394 int32_t index, retval, size, startIndex = 0;
1400 if (!(mode & SDDS_POINTER_ARRAY) && !(mode & SDDS_CONTIGUOUS_DATA)) {
1401 SDDS_SetError(
"Unable to set array--invalid mode (SDDS_AppendToArrayVararg)");
1405 SDDS_SetError(
"Unable to set array--unknown array name given (SDDS_AppendToArrayVararg)");
1408 if (!data_pointer) {
1409 SDDS_SetError(
"Unable to set array--data pointer is NULL (SDDS_AppendToArrayVararg)");
1412 if (!SDDS_dataset->array) {
1413 SDDS_SetError(
"Unable to set array--internal array pointer is NULL (SDDS_AppendToArrayVararg)");
1417 layout = &SDDS_dataset->layout;
1418 array = SDDS_dataset->array + index;
1419 if (!layout->array_definition) {
1420 SDDS_SetError(
"Unable to set array--internal array definition pointer is NULL (SDDS_AppendToArrayVararg)");
1423 array->definition = layout->array_definition + index;
1424 if (!array->dimension && !(array->dimension = (int32_t *)
SDDS_Malloc(
sizeof(*array->dimension) * array->definition->dimensions))) {
1425 SDDS_SetError(
"Unable to set array--allocation failure (SDDS_SetArrayVararg)");
1428 if (!(array->definition->dimensions == 1 || mode & SDDS_CONTIGUOUS_DATA)) {
1429 SDDS_SetError(
"Unable to set array--append operation requires contiguous data (SDDS_AppendToArrayVararg)");
1433 va_start(argptr, elements);
1438 array->elements = 1;
1440 if ((array->dimension[index] = va_arg(argptr, int32_t)) < 0) {
1441 SDDS_SetError(
"Unable to set array--negative dimension given (SDDS_AppendToArrayVararg)");
1445 array->elements *= array->dimension[index];
1446 }
while (retval == 1 && ++index < array->definition->dimensions);
1451 if (!array->elements)
1455 if (!(array->data =
SDDS_Realloc(array->data, size * array->elements))) {
1456 SDDS_SetError(
"Unable to set array--allocation failure (SDDS_AppendToArrayVararg)");
1460 startIndex = array->elements - elements;
1463 if (array->definition->dimensions == 1 || mode & SDDS_CONTIGUOUS_DATA) {
1465 memcpy((
char *)array->data + size * startIndex, data_pointer, size * elements);
1467 SDDS_SetError(
"Unable to set array--string copy failure (SDDS_AppendToArrayVararg)");
1494 for (i = n_indices - 1; i >= 0; i--)
1495 if (counter[i] != (max_count[i] - 1))
1500 for (i = n_indices - 1; i >= 0; i--) {
1501 if (counter[i] < (max_count[i] - 1)) {
1545 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME)) {
1546 SDDS_SetError(
"Unable to set column values--unknown mode (SDDS_SetColumn)");
1549 if (rows > SDDS_dataset->n_rows_allocated) {
1550 SDDS_SetError(
"Unable to set column values--number of rows exceeds allocated memory (SDDS_SetColumn)");
1555 if (SDDS_dataset->n_rows != 0 && SDDS_dataset->n_rows != rows) {
1556 SDDS_SetError(
"Number of rows in new column unequal to number in other columns (SDDS_SetColumn)");
1559 SDDS_dataset->n_rows = rows;
1560 layout = &SDDS_dataset->layout;
1563 va_start(argptr, rows);
1564 if (mode & SDDS_SET_BY_INDEX) {
1565 index = va_arg(argptr, int32_t);
1566 if (index < 0 || index >= layout->n_columns) {
1567 SDDS_SetError(
"Unable to set column values--index out of range (SDDS_SetColumn)");
1571 name = va_arg(argptr,
char *);
1583 if (layout->column_definition[index].type ==
SDDS_STRING) {
1584 if (SDDS_dataset->data[index]) {
1587 for (i = 0; i < rows; i++) {
1588 ptr = *((
char **)SDDS_dataset->data[index] + i);
1591 *((
char **)SDDS_dataset->data[index] + i) = NULL;
1595 SDDS_SetError(
"Unable to set column--error copying string data (SDDS_SetColumn)");
1599 memcpy(SDDS_dataset->data[index], data, rows *
SDDS_type_size[layout->column_definition[index].type - 1]);
1645 int32_t index, retval, type, size;
1651 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME)) {
1652 SDDS_SetError(
"Unable to set column values--unknown mode (SDDS_SetColumnFromDoubles)");
1655 if (rows > SDDS_dataset->n_rows_allocated) {
1656 SDDS_SetError(
"Unable to set column values--number of rows exceeds allocated memory (SDDS_SetColumnFromDoubles)");
1661 if (SDDS_dataset->n_rows != 0 && SDDS_dataset->n_rows != rows) {
1662 SDDS_SetError(
"Number of rows in new column unequal to number in other columns (SDDS_SetColumnFromDoubles)");
1665 SDDS_dataset->n_rows = rows;
1666 layout = &SDDS_dataset->layout;
1669 va_start(argptr, rows);
1670 if (mode & SDDS_SET_BY_INDEX) {
1671 index = va_arg(argptr, int32_t);
1672 if (index < 0 || index >= layout->n_columns) {
1673 SDDS_SetError(
"Unable to set column values--index out of range (SDDS_SetColumnFromDoubles)");
1677 name = va_arg(argptr,
char *);
1679 SDDS_SetError(
"Unable to set column values--name not recognized (SDDS_SetColumnFromDoubles)");
1687 type = layout->column_definition[index].type;
1691 if (SDDS_dataset->data[index]) {
1694 for (i = 0; i < rows; i++) {
1695 ptr = *((
char **)SDDS_dataset->data[index] + i);
1698 *((
char **)SDDS_dataset->data[index] + i) = NULL;
1701 stringArray = (
char **)malloc(
sizeof(
char *) * rows);
1702 for (i = 0; i < rows; i++) {
1703 stringArray[i] = (
char *)malloc(
sizeof(
char) * 40);
1704 sprintf(stringArray[i],
"%.15lg", data[i]);
1707 SDDS_SetError(
"Unable to set column--error copying string data (SDDS_SetColumnFromDoubles)");
1710 for (i = 0; i < rows; i++) {
1711 free(stringArray[i]);
1716 SDDS_SetError(
"Unable to set column--source type is nonnumeric (SDDS_SetColumnFromDoubles)");
1720 size =
SDDS_type_size[layout->column_definition[index].type - 1];
1723 memcpy((
char *)SDDS_dataset->data[index], (
char *)data, rows * size);
1727 for (i = 0; i < rows; i++)
1729 SDDS_SetError(
"Unable to set column--cast error (SDDS_SetColumnFromDoubles)");
1778 int32_t index, retval, type, size;
1784 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME)) {
1785 SDDS_SetError(
"Unable to set column values--unknown mode (SDDS_SetColumnFromLongDoubles)");
1788 if (rows > SDDS_dataset->n_rows_allocated) {
1789 SDDS_SetError(
"Unable to set column values--number of rows exceeds allocated memory (SDDS_SetColumnFromLongDoubles)");
1794 if (SDDS_dataset->n_rows != 0 && SDDS_dataset->n_rows != rows) {
1795 SDDS_SetError(
"Number of rows in new column unequal to number in other columns (SDDS_SetColumnFromLongDoubles)");
1798 SDDS_dataset->n_rows = rows;
1799 layout = &SDDS_dataset->layout;
1802 va_start(argptr, rows);
1803 if (mode & SDDS_SET_BY_INDEX) {
1804 index = va_arg(argptr, int32_t);
1805 if (index < 0 || index >= layout->n_columns) {
1806 SDDS_SetError(
"Unable to set column values--index out of range (SDDS_SetColumnFromLongDoubles)");
1810 name = va_arg(argptr,
char *);
1812 SDDS_SetError(
"Unable to set column values--name not recognized (SDDS_SetColumnFromLongDoubles)");
1820 type = layout->column_definition[index].type;
1824 if (SDDS_dataset->data[index]) {
1827 for (i = 0; i < rows; i++) {
1828 ptr = *((
char **)SDDS_dataset->data[index] + i);
1831 *((
char **)SDDS_dataset->data[index] + i) = NULL;
1834 stringArray = (
char **)malloc(
sizeof(
char *) * rows);
1835 for (i = 0; i < rows; i++) {
1836 stringArray[i] = (
char *)malloc(
sizeof(
char) * 40);
1837 if (LDBL_DIG == 18) {
1838 sprintf(stringArray[i],
"%.18Lg", data[i]);
1840 sprintf(stringArray[i],
"%.15Lg", data[i]);
1844 SDDS_SetError(
"Unable to set column--error copying string data (SDDS_SetColumnFromLongDoubles)");
1847 for (i = 0; i < rows; i++) {
1848 free(stringArray[i]);
1853 SDDS_SetError(
"Unable to set column--source type is nonnumeric (SDDS_SetColumnFromLongDoubles)");
1857 size =
SDDS_type_size[layout->column_definition[index].type - 1];
1860 memcpy((
char *)SDDS_dataset->data[index], (
char *)data, rows * size);
1864 for (i = 0; i < rows; i++)
1866 SDDS_SetError(
"Unable to set column--cast error (SDDS_SetColumnFromLongDoubles)");
1915 int32_t index, retval, type, size;
1921 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME)) {
1922 SDDS_SetError(
"Unable to set column values--unknown mode (SDDS_SetColumnFromFloats)");
1925 if (rows > SDDS_dataset->n_rows_allocated) {
1926 SDDS_SetError(
"Unable to set column values--number of rows exceeds allocated memory (SDDS_SetColumnFromFloats)");
1931 if (SDDS_dataset->n_rows != 0 && SDDS_dataset->n_rows != rows) {
1932 SDDS_SetError(
"Number of rows in new column unequal to number in other columns (SDDS_SetColumnFromFloats)");
1935 SDDS_dataset->n_rows = rows;
1936 layout = &SDDS_dataset->layout;
1939 va_start(argptr, rows);
1940 if (mode & SDDS_SET_BY_INDEX) {
1941 index = va_arg(argptr, int32_t);
1942 if (index < 0 || index >= layout->n_columns) {
1943 SDDS_SetError(
"Unable to set column values--index out of range (SDDS_SetColumnFromFloats)");
1947 name = va_arg(argptr,
char *);
1949 SDDS_SetError(
"Unable to set column values--name not recognized (SDDS_SetColumnFromFloats)");
1957 type = layout->column_definition[index].type;
1961 if (SDDS_dataset->data[index]) {
1964 for (i = 0; i < rows; i++) {
1965 ptr = *((
char **)SDDS_dataset->data[index] + i);
1968 *((
char **)SDDS_dataset->data[index] + i) = NULL;
1971 stringArray = (
char **)malloc(
sizeof(
char *) * rows);
1972 for (i = 0; i < rows; i++) {
1973 stringArray[i] = (
char *)malloc(
sizeof(
char) * 40);
1974 sprintf(stringArray[i],
"%.8g", data[i]);
1977 SDDS_SetError(
"Unable to set column--error copying string data (SDDS_SetColumnFromFloats)");
1980 for (i = 0; i < rows; i++) {
1981 free(stringArray[i]);
1986 SDDS_SetError(
"Unable to set column--source type is nonnumeric (SDDS_SetColumnFromFloats)");
1990 size =
SDDS_type_size[layout->column_definition[index].type - 1];
1993 memcpy((
char *)SDDS_dataset->data[index], (
char *)data, rows * size);
1997 for (i = 0; i < rows; i++)
1999 SDDS_SetError(
"Unable to set column--cast error (SDDS_SetColumnFromFloats)");
2048 int32_t index, retval, type, size;
2054 if (!(mode & SDDS_SET_BY_INDEX || mode & SDDS_SET_BY_NAME)) {
2055 SDDS_SetError(
"Unable to set column values--unknown mode (SDDS_SetColumnFromLongs)");
2058 if (rows > SDDS_dataset->n_rows_allocated) {
2059 SDDS_SetError(
"Unable to set column values--number of rows exceeds allocated memory (SDDS_SetColumnFromLongs)");
2064 if (SDDS_dataset->n_rows != 0 && SDDS_dataset->n_rows != rows) {
2065 SDDS_SetError(
"Number of rows in new column unequal to number in other columns (SDDS_SetColumnFromLongs)");
2068 SDDS_dataset->n_rows = rows;
2069 layout = &SDDS_dataset->layout;
2072 va_start(argptr, rows);
2073 if (mode & SDDS_SET_BY_INDEX) {
2074 index = va_arg(argptr, int32_t);
2075 if (index < 0 || index >= layout->n_columns) {
2076 SDDS_SetError(
"Unable to set column values--index out of range (SDDS_SetColumnFromLongs)");
2080 name = va_arg(argptr,
char *);
2082 SDDS_SetError(
"Unable to set column values--name not recognized (SDDS_SetColumnFromLongs)");
2090 type = layout->column_definition[index].type;
2094 if (SDDS_dataset->data[index]) {
2097 for (i = 0; i < rows; i++) {
2098 ptr = *((
char **)SDDS_dataset->data[index] + i);
2101 *((
char **)SDDS_dataset->data[index] + i) = NULL;
2104 stringArray = (
char **)malloc(
sizeof(
char *) * rows);
2105 for (i = 0; i < rows; i++) {
2106 stringArray[i] = (
char *)malloc(
sizeof(
char) * 40);
2107 sprintf(stringArray[i],
"%" PRId32, data[i]);
2110 SDDS_SetError(
"Unable to set column--error copying string data (SDDS_SetColumnFromLongs)");
2113 for (i = 0; i < rows; i++) {
2114 free(stringArray[i]);
2119 SDDS_SetError(
"Unable to set column--source type is nonnumeric (SDDS_SetColumnFromLongs)");
2123 size =
SDDS_type_size[layout->column_definition[index].type - 1];
2126 memcpy((
char *)SDDS_dataset->data[index], (
char *)data, rows * size);
2130 for (i = 0; i < rows; i++)
2132 SDDS_SetError(
"Unable to set column--cast error (SDDS_SetColumnFromLongs)");
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
int32_t SDDS_RestoreLayout(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_type_size[SDDS_NUM_TYPES]
Array of sizes for each supported data type.
int32_t SDDS_LengthenTable(SDDS_DATASET *SDDS_dataset, int64_t n_additional_rows)
int32_t SDDS_AppendToArrayVararg(SDDS_DATASET *SDDS_dataset, char *array_name, int32_t mode, void *data_pointer, int32_t elements,...)
Appends data to an existing array variable in the SDDS dataset using variable arguments for dimension...
int32_t SDDS_AllocateColumnFlags(SDDS_DATASET *SDDS_target)
int32_t SDDS_SetRowValues(SDDS_DATASET *SDDS_dataset, int32_t mode, int64_t row,...)
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
int32_t SDDS_SetArrayVararg(SDDS_DATASET *SDDS_dataset, char *array_name, int32_t mode, void *data_pointer,...)
Sets the values of an array variable in the SDDS dataset using variable arguments for dimensions.
int32_t SDDS_SetColumnFromFloats(SDDS_DATASET *SDDS_dataset, int32_t mode, float *data, int64_t rows,...)
Sets the values for a single data column using single-precision floating-point numbers.
int32_t SDDS_SetParameter(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
int32_t SDDS_SetParametersFromDoubles(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
int32_t SDDS_SetParameters(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
int32_t SDDS_ClearPage(SDDS_DATASET *SDDS_dataset)
int32_t SDDS_SetColumnFromLongDoubles(SDDS_DATASET *SDDS_dataset, int32_t mode, long double *data, int64_t rows,...)
Sets the values for a single data column using long double-precision floating-point numbers.
int32_t SDDS_SetColumnFromDoubles(SDDS_DATASET *SDDS_dataset, int32_t mode, double *data, int64_t rows,...)
Sets the values for a single data column using double-precision floating-point numbers.
int32_t SDDS_SetColumn(SDDS_DATASET *SDDS_dataset, int32_t mode, void *data, int64_t rows,...)
Sets the values for one data column in the current data table of an SDDS dataset.
int32_t SDDS_ShortenTable(SDDS_DATASET *SDDS_dataset, int64_t rows)
int32_t SDDS_SetParametersFromLongDoubles(SDDS_DATASET *SDDS_dataset, int32_t mode,...)
int32_t SDDS_SetArray(SDDS_DATASET *SDDS_dataset, char *array_name, int32_t mode, void *data_pointer, int32_t *dimension)
Sets the values of an array variable in the SDDS dataset using specified dimensions.
int32_t SDDS_SetColumnFromLongs(SDDS_DATASET *SDDS_dataset, int32_t mode, int32_t *data, int64_t rows,...)
Sets the values for a single data column using long integer numbers.
int32_t SDDS_AdvanceCounter(int32_t *counter, int32_t *max_count, int32_t n_indices)
Advances a multi-dimensional counter based on maximum counts for each dimension.
Internal definitions and function declarations for SDDS with LZMA support.
int32_t SDDS_FreeStringArray(char **string, int64_t strings)
Frees an array of strings by deallocating each individual string.
void SDDS_SetError0(char *error_text)
Internal function to record an error message in the SDDS error stack.
void SDDS_SetError(char *error_text)
Records an error message in the SDDS error stack.
int32_t SDDS_ZeroMemory(void *mem, int64_t n_bytes)
Sets a block of memory to zero.
int32_t SDDS_GetArrayIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named array in the SDDS dataset.
int32_t SDDS_GetParameterIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named parameter in the SDDS dataset.
int32_t SDDS_GetColumnIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named column in the SDDS dataset.
void * SDDS_CastValue(void *data, int64_t index, int32_t data_type, int32_t desired_type, void *memory)
Casts a value from one SDDS data type to another.
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.
int32_t SDDS_CopyStringArray(char **target, char **source, int64_t n_strings)
Copies an array of strings from source to target.
void * SDDS_Malloc(size_t size)
Allocates memory of a specified size.
int32_t SDDS_CopyString(char **target, const char *source)
Copies a source string to a target string with memory allocation.
int32_t SDDS_CheckTabularData(SDDS_DATASET *SDDS_dataset, const char *caller)
Validates the consistency of tabular data within an SDDS dataset.
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
#define SDDS_FLOAT
Identifier for the float data type.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_ULONG64
Identifier for the unsigned 64-bit integer data type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_SHORT
Identifier for the signed short integer data type.
#define SDDS_CHARACTER
Identifier for the character data type.
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
#define SDDS_DOUBLE
Identifier for the double data type.
#define SDDS_NUMERIC_TYPE(type)
Checks if the given type identifier corresponds to any numeric type.
#define SDDS_LONGDOUBLE
Identifier for the long double data type.
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.