SDDS ToolKit Programs and Libraries for C and Python
Loading...
Searching...
No Matches
SDDSArray.cc
Go to the documentation of this file.
1/**
2 * @file SDDSArray.cc
3 * @brief Archived implementation of the original SDDS3 array class.
4 *
5 * @details Provides legacy array definition, conversion, and page-storage
6 * routines for builds that explicitly enable the unmodernized SDDS3 API.
7 *
8 * @note This source is retained for migration reference and is not compiled
9 * into libSDDSpp.
10 *
11 * @copyright
12 * - (c) The University of Chicago
13 *
14 * @license
15 * This file is distributed under the terms of the Software License Agreement
16 * found in the file LICENSE included with this distribution.
17 */
18
19/* GUIDELINES
20 Do not exit or print to stdout or stderr from any of the functions in this file
21*/
22
23/* TODO
24fix nonnative in everything
25*/
26
27#include <stdio.h>
28#include <string.h>
29#include <stdlib.h>
30#include <stdarg.h>
31#include <ctype.h>
32#include <limits.h>
33#include <math.h>
34#include <float.h>
35#include "SDDS3.h"
36
37
38/**
39 * @brief SDDSArray
40 *
41 * C++ Arguments: none
42 *
43 * Results: pointer to SDDSArray object
44 */
45SDDSArray::SDDSArray() {
46 pageCount = 0;
47 elementCount = NULL;
48 elementsAllocated = NULL;
49 elementAllocationIncrement = 10;
50 arrayType = 0;
51 arrayName = NULL;
52 arraySymbol = NULL;
53 arrayUnits = NULL;
54 arrayDescription = NULL;
55 arrayFormatString = NULL;
56 arrayGroupName = NULL;
57 arrayFieldLength = 0;
58 arrayDimensions = 0;
59 arrayDim = NULL;
60
61 int32Value = NULL;
62 int16Value = NULL;
63 uint32Value = NULL;
64 uint16Value = NULL;
65 real64Value = NULL;
66 real32Value = NULL;
67 stringValue = NULL;
68 charValue = NULL;
69 sddsfile = NULL;
70}
71
72/**
73 * @brief ~SDDSArray
74 *
75 * C++ Arguments: none
76 *
77 * Results: none
78 */
79SDDSArray::~SDDSArray() {
80 uint32_t i, j;
81 if (arrayName != NULL)
82 SDDS_free(arrayName);
83 if (arraySymbol != NULL)
84 SDDS_free(arraySymbol);
85 if (arrayUnits != NULL)
86 SDDS_free(arrayUnits);
87 if (arrayDescription != NULL)
88 SDDS_free(arrayDescription);
89 if (arrayFormatString != NULL)
90 SDDS_free(arrayFormatString);
91 if (arrayGroupName != NULL)
92 SDDS_free(arrayGroupName);
93 if (arrayDim != NULL) {
94 for (i=0; i<pageCount; i++) {
95 if (arrayDim[i] != NULL) {
96 SDDS_free(arrayDim[i]);
97 }
98 }
99 SDDS_free(arrayDim);
100 }
101
102 if (int16Value != NULL) {
103 for (i=0; i<pageCount; i++) {
104 if (int16Value[i] != NULL) {
105 SDDS_free(int16Value[i]);
106 }
107 }
108 SDDS_free(int16Value);
109 }
110 if (uint16Value != NULL) {
111 for (i=0; i<pageCount; i++) {
112 if (uint16Value[i] != NULL) {
113 SDDS_free(uint16Value[i]);
114 }
115 }
116 SDDS_free(uint16Value);
117 }
118 if (int32Value != NULL) {
119 for (i=0; i<pageCount; i++) {
120 if (int32Value[i] != NULL) {
121 SDDS_free(int32Value[i]);
122 }
123 }
124 SDDS_free(int32Value);
125 }
126 if (uint32Value != NULL) {
127 for (i=0; i<pageCount; i++) {
128 if (uint32Value[i] != NULL) {
129 SDDS_free(uint32Value[i]);
130 }
131 }
132 SDDS_free(uint32Value);
133 }
134 if (real32Value != NULL) {
135 for (i=0; i<pageCount; i++) {
136 if (real32Value[i] != NULL) {
137 SDDS_free(real32Value[i]);
138 }
139 }
140 SDDS_free(real32Value);
141 }
142 if (real64Value != NULL) {
143 for (i=0; i<pageCount; i++) {
144 if (real64Value[i] != NULL) {
145 SDDS_free(real64Value[i]);
146 }
147 }
148 SDDS_free(real64Value);
149 }
150 if (stringValue != NULL) {
151 for (i=0; i<pageCount; i++) {
152 if (stringValue[i] != NULL) {
153 for (j=0; j<elementCount[i]; j++) {
154 if (stringValue[i][j] != NULL) {
155 SDDS_free(stringValue[i][j]);
156 }
157 }
158 SDDS_free(stringValue[i]);
159 }
160 }
161 SDDS_free(stringValue);
162 }
163 if (charValue != NULL) {
164 for (i=0; i<pageCount; i++) {
165 if (charValue[i] != NULL) {
166 SDDS_free(charValue[i]);
167 }
168 }
169 SDDS_free(charValue);
170 }
171 if (elementCount != NULL) {
172 SDDS_free(elementCount);
173 }
174 if (elementsAllocated != NULL) {
175 SDDS_free(elementsAllocated);
176 }
177}
178
179/**
180 * @brief freePage
181 *
182 * C++ Arguments: none
183 *
184 * Results: none
185 */
186void SDDSArray::freePage() {
187 uint32_t i, j;
188 switch (arrayType) {
189 case SDDS_INT16:
190 if (int16Value != NULL) {
191 for (i=0; i<pageCount; i++) {
192 if (int16Value[i] != NULL) {
193 SDDS_free(int16Value[i]);
194 }
195 }
196 SDDS_free(int16Value);
197 int16Value = NULL;
198 }
199 break;
200 case SDDS_UINT16:
201 if (uint16Value != NULL) {
202 for (i=0; i<pageCount; i++) {
203 if (uint16Value[i] != NULL) {
204 SDDS_free(uint16Value[i]);
205 }
206 }
207 SDDS_free(uint16Value);
208 uint16Value = NULL;
209 }
210 break;
211 case SDDS_INT32:
212 if (int32Value != NULL) {
213 for (i=0; i<pageCount; i++) {
214 if (int32Value[i] != NULL) {
215 SDDS_free(int32Value[i]);
216 }
217 }
218 SDDS_free(int32Value);
219 int32Value = NULL;
220 }
221 break;
222 case SDDS_UINT32:
223 if (uint32Value != NULL) {
224 for (i=0; i<pageCount; i++) {
225 if (uint32Value[i] != NULL) {
226 SDDS_free(uint32Value[i]);
227 }
228 }
229 SDDS_free(uint32Value);
230 uint32Value = NULL;
231 }
232 break;
233 case SDDS_REAL32:
234 if (real32Value != NULL) {
235 for (i=0; i<pageCount; i++) {
236 if (real32Value[i] != NULL) {
237 SDDS_free(real32Value[i]);
238 }
239 }
240 SDDS_free(real32Value);
241 real32Value = NULL;
242 }
243 break;
244 case SDDS_REAL64:
245 if (real64Value != NULL) {
246 for (i=0; i<pageCount; i++) {
247 if (real64Value[i] != NULL) {
248 SDDS_free(real64Value[i]);
249 }
250 }
251 SDDS_free(real64Value);
252 real64Value = NULL;
253 }
254 break;
255 case SDDS_STRING:
256 if (stringValue != NULL) {
257 for (i=0; i<pageCount; i++) {
258 if (stringValue[i] != NULL) {
259 for (j=0; j<elementCount[i]; j++) {
260 if (stringValue[i][j] != NULL) {
261 SDDS_free(stringValue[i][j]);
262 }
263 }
264 SDDS_free(stringValue[i]);
265 }
266 }
267 SDDS_free(stringValue);
268 stringValue = NULL;
269 }
270 break;
271 case SDDS_CHARACTER:
272 if (charValue != NULL) {
273 for (i=0; i<pageCount; i++) {
274 if (charValue[i] != NULL) {
275 SDDS_free(charValue[i]);
276 }
277 }
278 SDDS_free(charValue);
279 charValue = NULL;
280 }
281 break;
282 default:
283 break;
284 }
285 if (arrayDim != NULL) {
286 for (i=0; i<pageCount; i++) {
287 if (arrayDim[i] != NULL) {
288 SDDS_free(arrayDim[i]);
289 }
290 }
291 SDDS_free(arrayDim);
292 }
293 arrayDim = NULL;
294 if (elementCount != NULL) {
295 SDDS_free(elementCount);
296 elementCount = NULL;
297 }
298 if (elementsAllocated != NULL) {
299 SDDS_free(elementsAllocated);
300 elementsAllocated = NULL;
301 }
302 pageCount = 0;
303}
304
305/**
306 * @brief setupArray
307 *
308 * C++ Arguments: char *name, char *symbol, char *units, char *description,
309 * char *format_string, char *group_name, int32_t type,
310 * uint32_t field_length, uint32_t dimensions
311 *
312 * Results: none
313 */
314void SDDSArray::setupArray(char *name, char *symbol, char *units, char *description, char *format_string, char *group_name, int32_t type, uint32_t field_length, uint32_t dimensions) {
315 if (arrayName != NULL)
316 SDDS_free(arrayName);
317 if (arraySymbol != NULL)
318 SDDS_free(arraySymbol);
319 if (arrayUnits != NULL)
320 SDDS_free(arrayUnits);
321 if (arrayDescription != NULL)
322 SDDS_free(arrayDescription);
323 if (arrayFormatString != NULL)
324 SDDS_free(arrayFormatString);
325 if (arrayGroupName != NULL)
326 SDDS_free(arrayGroupName);
327
328 if (name == NULL)
329 arrayName = NULL;
330 else {
331 arrayName = (char*)SDDS_malloc(sizeof(char) * strlen(name) + 1);
332 strcpy(arrayName, name);
333 }
334 if (symbol == NULL)
335 arraySymbol = NULL;
336 else {
337 arraySymbol = (char*)SDDS_malloc(sizeof(char) * strlen(symbol) + 1);
338 strcpy(arraySymbol, symbol);
339 }
340 if (units == NULL)
341 arrayUnits = NULL;
342 else {
343 arrayUnits = (char*)SDDS_malloc(sizeof(char) * strlen(units) + 1);
344 strcpy(arrayUnits, units);
345 }
346 if (description == NULL)
347 arrayDescription = NULL;
348 else {
349 arrayDescription = (char*)SDDS_malloc(sizeof(char) * strlen(description) + 1);
350 strcpy(arrayDescription, description);
351 }
352 if (format_string == NULL)
353 arrayFormatString = NULL;
354 else {
355 arrayFormatString = (char*)SDDS_malloc(sizeof(char) * strlen(format_string) + 1);
356 strcpy(arrayFormatString, format_string);
357 }
358 if (group_name == NULL)
359 arrayGroupName = NULL;
360 else {
361 arrayGroupName = (char*)SDDS_malloc(sizeof(char) * strlen(group_name) + 1);
362 strcpy(arrayGroupName, group_name);
363 }
364 arrayType = type;
365 arrayFieldLength = field_length;
366 arrayDimensions = dimensions;
367}
368
369/**
370 * @brief informAboutParent
371 *
372 * C++ Arguments: SDDSFile *parent
373 *
374 * Results: none
375 */
376void SDDSArray::informAboutParent(void *parent) {
377 sddsfile = parent;
378}
379
380/**
381 * @brief getName
382 *
383 * C++ Arguments: none
384 *
385 * Results: pointer to name (do not free the result)
386 */
387char* SDDSArray::getName() {
388 return(arrayName);
389}
390
391/**
392 * @brief setName
393 *
394 * C++ Arguments: char *name
395 *
396 * Results: none
397 */
398void SDDSArray::setName(char *name) {
399 if (arrayName != NULL)
400 SDDS_free(arrayName);
401 if (name == NULL)
402 arrayName = NULL;
403 else {
404 arrayName = (char*)SDDS_malloc(sizeof(char) * strlen(name) + 1);
405 strcpy(arrayName, name);
406 }
407}
408
409/**
410 * @brief getSymbol
411 *
412 * C++ Arguments: none
413 *
414 * Results: pointer to symbol (do not free the result)
415 */
416char* SDDSArray::getSymbol() {
417 return(arraySymbol);
418}
419
420/**
421 * @brief setSymbol
422 *
423 * C++ Arguments: char *symbol
424 *
425 * Results: none
426 */
427void SDDSArray::setSymbol(char *symbol) {
428 if (arraySymbol != NULL)
429 SDDS_free(arraySymbol);
430 if (symbol == NULL)
431 arraySymbol = NULL;
432 else {
433 arraySymbol = (char*)SDDS_malloc(sizeof(char) * strlen(symbol) + 1);
434 strcpy(arraySymbol, symbol);
435 }
436}
437
438/**
439 * @brief getUnits
440 *
441 * C++ Arguments: none
442 *
443 * Results: pointer to the units (do not free the result)
444 */
445char* SDDSArray::getUnits() {
446 return(arrayUnits);
447}
448
449/**
450 * @brief setUnits
451 *
452 * C++ Arguments: char *units
453 *
454 * Results: none
455 */
456void SDDSArray::setUnits(char *units) {
457 if (arrayUnits != NULL)
458 SDDS_free(arrayUnits);
459 if (units == NULL)
460 arrayUnits = NULL;
461 else {
462 arrayUnits = (char*)SDDS_malloc(sizeof(char) * strlen(units) + 1);
463 strcpy(arrayUnits, units);
464 }
465}
466
467/**
468 * @brief getDescription
469 *
470 * C++ Arguments: none
471 *
472 * Results: pointer to the description (do not free the result)
473 */
474char* SDDSArray::getDescription() {
475 return(arrayDescription);
476}
477
478/**
479 * @brief setDescription
480 *
481 * C++ Arguments: char *description
482 *
483 * Results: none
484 */
485void SDDSArray::setDescription(char *description) {
486 if (arrayDescription != NULL)
487 SDDS_free(arrayDescription);
488 if (description == NULL)
489 arrayDescription = NULL;
490 else {
491 arrayDescription = (char*)SDDS_malloc(sizeof(char) * strlen(description) + 1);
492 strcpy(arrayDescription, description);
493 }
494}
495
496/**
497 * @brief getFormatString
498 *
499 * C++ Arguments: none
500 *
501 * Results: pointer to the format string (do not free the result)
502 */
503char* SDDSArray::getFormatString() {
504 return(arrayFormatString);
505}
506
507/**
508 * @brief setFormatString
509 *
510 * C++ Arguments: char *format_string
511 *
512 * Results: none
513 */
514void SDDSArray::setFormatString(char *format_string) {
515 if (arrayFormatString != NULL)
516 SDDS_free(arrayFormatString);
517 if (format_string == NULL)
518 arrayFormatString = NULL;
519 else {
520 arrayFormatString = (char*)SDDS_malloc(sizeof(char) * strlen(format_string) + 1);
521 strcpy(arrayFormatString, format_string);
522 }
523}
524
525/**
526 * @brief getGroupName
527 *
528 * C++ Arguments: none
529 *
530 * Results: pointer to the group name (do not free the result)
531 */
532char* SDDSArray::getGroupName() {
533 return(arrayGroupName);
534}
535
536/**
537 * @brief setGroupName
538 *
539 * C++ Arguments: char *fixed_value
540 *
541 * Results: none
542 */
543void SDDSArray::setGroupName(char *group_name) {
544 if (arrayGroupName != NULL)
545 SDDS_free(arrayGroupName);
546 if (group_name == NULL)
547 arrayGroupName = NULL;
548 else {
549 arrayGroupName = (char*)SDDS_malloc(sizeof(char) * strlen(group_name) + 1);
550 strcpy(arrayGroupName, group_name);
551 }
552}
553
554/**
555 * @brief getType
556 *
557 * C++ Arguments: none
558 *
559 * Results: the array type in integer form
560 */
561int32_t SDDSArray::getType() {
562 return(arrayType);
563}
564
565/**
566 * @brief setType
567 *
568 * C++ Arguments:int32_t type
569 *
570 * Results: none
571 */
572void SDDSArray::setType(int32_t type) {
573 arrayType = type;
574}
575
576/**
577 * @brief getFieldLength
578 *
579 * C++ Arguments: none
580 *
581 * Results: the array field length
582 */
583uint32_t SDDSArray::getFieldLength() {
584 return(arrayFieldLength);
585}
586
587/**
588 * @brief setFieldLength
589 *
590 * C++ Arguments:int32_t field_length
591 *
592 * Results: none
593 */
594void SDDSArray::setFieldLength(uint32_t field_length) {
595 arrayFieldLength = field_length;
596}
597
598/**
599 * @brief getDimensions
600 *
601 * C++ Arguments: none
602 *
603 * Results: the array dimensions
604 */
605uint32_t SDDSArray::getDimensions() {
606 return(arrayDimensions);
607}
608
609/**
610 * @brief setDimensions
611 *
612 * C++ Arguments: uint32_t dimensions
613 *
614 * Results: none
615 */
616void SDDSArray::setDimensions(uint32_t dimensions) {
617 arrayDimensions = dimensions;
618}
619
620/**
621 * @brief getDim
622 *
623 * C++ Arguments: uint32_t page
624 *
625 * Results: the number of elements in each of the dimensions for this page, do not free the results
626 */
627uint32_t* SDDSArray::getDim(uint32_t page) {
628 if (page > pageCount)
629 return(NULL);
630 if (arrayDim == NULL)
631 return(NULL);
632 if (arrayDim[page-1] == NULL)
633 return(NULL);
634 return arrayDim[page-1];
635}
636
637/**
638 * @brief setDim
639 *
640 * C++ Arguments: uint32_t page, uint32_t *dimensions
641 *
642 * Results: none
643 */
644void SDDSArray::setDim(uint32_t page, uint32_t *dimensions) {
645 uint32_t i;
646 if ((page > 0) && (page <= pageCount)) {
647 arrayDim[page-1] = (uint32_t*)SDDS_malloc(sizeof(uint32_t) * arrayDimensions);
648 for (i=0 ; i<arrayDimensions ; i++)
649 arrayDim[page-1][i] = dimensions[i];
650 } else if (page == pageCount+1) {
651 arrayDim = (uint32_t**)SDDS_realloc(arrayDim, sizeof(uint32_t*) * page);
652 arrayDim[page-1] = (uint32_t*)SDDS_malloc(sizeof(uint32_t) * arrayDimensions);
653 for (i=0 ; i<arrayDimensions ; i++)
654 arrayDim[page-1][i] = dimensions[i];
655 }
656}
657
658/**
659 * @brief getPageCount
660 *
661 * C++ Arguments: none
662 *
663 * Results: the page count
664 */
665uint32_t SDDSArray::getPageCount() {
666 return(pageCount);
667}
668
669/**
670 * @brief writeDefinition
671 *
672 * C++ Arguments: FILE *fp
673 * voidp *gzfp
674 *
675 * Results: 0 on success
676 * 1 on failure
677 */
678int32_t SDDSArray::writeDefinition(FILE *fp) {
679 if ((arrayType <= 0) || (arrayType > SDDS_NUM_TYPES)) {
680 return(1);
681 }
682 if (fp == NULL) {
683 return(1);
684 }
685 fputs("&array ", fp);
686 if (SDDS_printNamelistField(fp, (char*)"name", arrayName)) {
687 return(1);
688 }
689 if (SDDS_printNamelistField(fp, (char*)"symbol", SDDS_blankToNull(arraySymbol))) {
690 return(1);
691 }
692 if (SDDS_printNamelistField(fp, (char*)"units", SDDS_blankToNull(arrayUnits))) {
693 return(1);
694 }
695 if (SDDS_printNamelistField(fp, (char*)"description", SDDS_blankToNull(arrayDescription))) {
696 return(1);
697 }
698 if (SDDS_printNamelistField(fp, (char*)"format_string", SDDS_blankToNull(arrayFormatString))) {
699 return(1);
700 }
701 if (SDDS_printNamelistField(fp, (char*)"group_name", SDDS_blankToNull(arrayGroupName))) {
702 return(1);
703 }
704 if (((SDDSFile*)sddsfile)->layoutVersion == 1) {
705 if (SDDS_printNamelistField(fp, (char*)"type", SDDS_getVer1TypeName(arrayType))) {
706 return(1);
707 }
708 } else if (((SDDSFile*)sddsfile)->layoutVersion == 2) {
709 if (SDDS_printNamelistField(fp, (char*)"type", SDDS_getVer2TypeName(arrayType))) {
710 return(1);
711 }
712 } else {
713 if (SDDS_printNamelistField(fp, (char*)"type", SDDS_getTypeName(arrayType))) {
714 return(1);
715 }
716 }
717 fprintf(fp, "dimensions=%" PRIu32 ", ", arrayDimensions);
718 fputs("&end\n", fp);
719 return(0);
720}
721
722int32_t SDDSArray::writeDefinition(voidp *gzfp) {
723 if ((arrayType <= 0) || (arrayType > SDDS_NUM_TYPES)) {
724 return(1);
725 }
726 if (gzfp == NULL) {
727 return(1);
728 }
729 gzputs(gzfp, "&array ");
730 if (SDDS_printNamelistField(gzfp, (char*)"name", arrayName)) {
731 return(1);
732 }
733 if (SDDS_printNamelistField(gzfp, (char*)"symbol", SDDS_blankToNull(arraySymbol))) {
734 return(1);
735 }
736 if (SDDS_printNamelistField(gzfp, (char*)"units", SDDS_blankToNull(arrayUnits))) {
737 return(1);
738 }
739 if (SDDS_printNamelistField(gzfp, (char*)"description", SDDS_blankToNull(arrayDescription))) {
740 return(1);
741 }
742 if (SDDS_printNamelistField(gzfp, (char*)"format_string", SDDS_blankToNull(arrayFormatString))) {
743 return(1);
744 }
745 if (SDDS_printNamelistField(gzfp, (char*)"group_name", SDDS_blankToNull(arrayGroupName))) {
746 return(1);
747 }
748 if (((SDDSFile*)sddsfile)->layoutVersion == 1) {
749 if (SDDS_printNamelistField(gzfp, (char*)"type", SDDS_getVer1TypeName(arrayType))) {
750 return(1);
751 }
752 } else if (((SDDSFile*)sddsfile)->layoutVersion == 2) {
753 if (SDDS_printNamelistField(gzfp, (char*)"type", SDDS_getVer2TypeName(arrayType))) {
754 return(1);
755 }
756 } else {
757 if (SDDS_printNamelistField(gzfp, (char*)"type", SDDS_getTypeName(arrayType))) {
758 return(1);
759 }
760 }
761 gzprintf(gzfp, "dimensions=%" PRIu32 ", ", arrayDimensions);
762 gzputs(gzfp, "&end\n");
763 return(0);
764}
765
766/**
767 * @brief setValues
768 *
769 * C++ Arguments: int16_t *values, uint32_t page, uint32_t elements
770 * uint16_t *values, uint32_t page, uint32_t elements
771 * int32_t *values, uint32_t page, uint32_t elements
772 * uint32_t *values, uint32_t page, uint32_t elements
773 * float *values, uint32_t page, uint32_t elements
774 * double *values, uint32_t page, uint32_t elements
775 * char **values, uint32_t page, uint32_t elements
776 * char *values, uint32_t page, uint32_t elements
777 *
778 * Results: 0 for success
779 * 1 for invalid page number
780 * 2 for the case where the value cannot be converted to the proper array type
781 * 3 for invalid array type
782 */
783int32_t SDDSArray::setValues(int16_t *values, uint32_t page, uint32_t elements) {
784 uint32_t i, n=0, p;
785 bool newPage=false;
786 char s[SDDS_MAXLINE];
787 if (page == 0)
788 return(1);
789 if (page > pageCount) {
790 newPage = true;
791 n = page - pageCount;
792 }
793 p = page - 1;
794 if (newPage) {
795 elementCount = (uint32_t*)SDDS_realloc(elementCount, sizeof(uint32_t) * page);
796 elementsAllocated = (uint32_t*)SDDS_realloc(elementsAllocated, sizeof(uint32_t) * page);
797 for (i=0; i<n; i++) {
798 elementCount[p-i] = 0;
799 elementsAllocated[p-i] = 0;
800 }
801 }
802 switch (arrayType) {
803 case SDDS_INT16:
804 if (newPage) {
805 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
806 for (i=0; i<n; i++) {
807 int16Value[p - i] = (int16_t*)NULL;
808 }
809 }
810 if (elements > elementsAllocated[p]) {
811 elementsAllocated[p] = elements + elementAllocationIncrement;
812 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * elementsAllocated[p]);
813 }
814 memcpy(int16Value[p], values, elements * 2);
815 break;
816 case SDDS_UINT16:
817 if (newPage) {
818 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
819 for (i=0; i<n; i++) {
820 uint16Value[p - i] = (uint16_t*)NULL;
821 }
822 }
823 if (elements > elementsAllocated[p]) {
824 elementsAllocated[p] = elements + elementAllocationIncrement;
825 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * elementsAllocated[p]);
826 }
827 for (i=0; i<elements; i++) {
828 uint16Value[p][i] = (uint16_t)(values[i]);
829 }
830 break;
831 case SDDS_INT32:
832 if (newPage) {
833 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
834 for (i=0; i<n; i++) {
835 int32Value[p - i] = (int32_t*)NULL;
836 }
837 }
838 if (elements > elementsAllocated[p]) {
839 elementsAllocated[p] = elements + elementAllocationIncrement;
840 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * elementsAllocated[p]);
841 }
842 for (i=0; i<elements; i++) {
843 int32Value[p][i] = (int32_t)(values[i]);
844 }
845 break;
846 case SDDS_UINT32:
847 if (newPage) {
848 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
849 for (i=0; i<n; i++) {
850 uint32Value[p - i] = (uint32_t*)NULL;
851 }
852 }
853 if (elements > elementsAllocated[p]) {
854 elementsAllocated[p] = elements + elementAllocationIncrement;
855 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * elementsAllocated[p]);
856 }
857 for (i=0; i<elements; i++) {
858 uint32Value[p][i] = (uint32_t)(values[i]);
859 }
860 break;
861 case SDDS_REAL32:
862 if (newPage) {
863 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
864 for (i=0; i<n; i++) {
865 real32Value[p - i] = (float*)NULL;
866 }
867 }
868 if (elements > elementsAllocated[p]) {
869 elementsAllocated[p] = elements + elementAllocationIncrement;
870 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * elementsAllocated[p]);
871 }
872 for (i=0; i<elements; i++) {
873 real32Value[p][i] = (float)(values[i]);
874 }
875 break;
876 case SDDS_REAL64:
877 if (newPage) {
878 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
879 for (i=0; i<n; i++) {
880 real64Value[p - i] = (double*)NULL;
881 }
882 }
883 if (elements > elementsAllocated[p]) {
884 elementsAllocated[p] = elements + elementAllocationIncrement;
885 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * elementsAllocated[p]);
886 }
887 for (i=0; i<elements; i++) {
888 real64Value[p][i] = (double)(values[i]);
889 }
890 break;
891 case SDDS_STRING:
892 if (newPage) {
893 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
894 for (i=0; i<n; i++) {
895 stringValue[p - i] = NULL;
896 }
897 }
898 if (elements > elementsAllocated[p]) {
899 elementsAllocated[p] = elements + elementAllocationIncrement;
900 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * elementsAllocated[p]);
901 }
902 for (i=0; i<elements; i++) {
903 sprintf(s, "%" PRId16, values[i]);
904 stringValue[p][i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
905 strcpy(stringValue[p][i], s);
906 }
907 break;
908 case SDDS_CHARACTER:
909 if (newPage) {
910 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
911 for (i=0; i<n; i++) {
912 charValue[p - i] = NULL;
913 }
914 }
915 if (elements > elementsAllocated[p]) {
916 elementsAllocated[p] = elements + elementAllocationIncrement;
917 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * elementsAllocated[p]);
918 }
919 for (i=0; i<elements; i++) {
920 charValue[p][i] = (char)(values[i]);
921 }
922 break;
923 default:
924 return(3);
925 }
926 if (newPage)
927 pageCount = page;
928 if (elementCount[p] < elements) {
929 elementCount[p] = elements;
930 }
931 return(0);
932}
933
934int32_t SDDSArray::setValues(uint16_t *values, uint32_t page, uint32_t elements) {
935 uint32_t i, n=0, p;
936 bool newPage=false;
937 char s[SDDS_MAXLINE];
938 if (page == 0)
939 return(1);
940 if (page > pageCount) {
941 newPage = true;
942 n = page - pageCount;
943 }
944 p = page - 1;
945 if (newPage) {
946 elementCount = (uint32_t*)SDDS_realloc(elementCount, sizeof(uint32_t) * page);
947 elementsAllocated = (uint32_t*)SDDS_realloc(elementsAllocated, sizeof(uint32_t) * page);
948 for (i=0; i<n; i++) {
949 elementCount[p-i] = 0;
950 elementsAllocated[p-i] = 0;
951 }
952 }
953 switch (arrayType) {
954 case SDDS_INT16:
955 if (newPage) {
956 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
957 for (i=0; i<n; i++) {
958 int16Value[p - i] = (int16_t*)NULL;
959 }
960 }
961 if (elements > elementsAllocated[p]) {
962 elementsAllocated[p] = elements + elementAllocationIncrement;
963 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * elementsAllocated[p]);
964 }
965 for (i=0; i<elements; i++) {
966 int16Value[p][i] = (int16_t)(values[i]);
967 }
968 break;
969 case SDDS_UINT16:
970 if (newPage) {
971 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
972 for (i=0; i<n; i++) {
973 uint16Value[p - i] = (uint16_t*)NULL;
974 }
975 }
976 if (elements > elementsAllocated[p]) {
977 elementsAllocated[p] = elements + elementAllocationIncrement;
978 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * elementsAllocated[p]);
979 }
980 memcpy(uint16Value[p], values, elements * 2);
981 break;
982 case SDDS_INT32:
983 if (newPage) {
984 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
985 for (i=0; i<n; i++) {
986 int32Value[p - i] = (int32_t*)NULL;
987 }
988 }
989 if (elements > elementsAllocated[p]) {
990 elementsAllocated[p] = elements + elementAllocationIncrement;
991 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * elementsAllocated[p]);
992 }
993 for (i=0; i<elements; i++) {
994 int32Value[p][i] = (int32_t)(values[i]);
995 }
996 break;
997 case SDDS_UINT32:
998 if (newPage) {
999 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
1000 for (i=0; i<n; i++) {
1001 uint32Value[p - i] = (uint32_t*)NULL;
1002 }
1003 }
1004 if (elements > elementsAllocated[p]) {
1005 elementsAllocated[p] = elements + elementAllocationIncrement;
1006 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * elementsAllocated[p]);
1007 }
1008 for (i=0; i<elements; i++) {
1009 uint32Value[p][i] = (uint32_t)(values[i]);
1010 }
1011 break;
1012 case SDDS_REAL32:
1013 if (newPage) {
1014 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
1015 for (i=0; i<n; i++) {
1016 real32Value[p - i] = (float*)NULL;
1017 }
1018 }
1019 if (elements > elementsAllocated[p]) {
1020 elementsAllocated[p] = elements + elementAllocationIncrement;
1021 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * elementsAllocated[p]);
1022 }
1023 for (i=0; i<elements; i++) {
1024 real32Value[p][i] = (float)(values[i]);
1025 }
1026 break;
1027 case SDDS_REAL64:
1028 if (newPage) {
1029 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
1030 for (i=0; i<n; i++) {
1031 real64Value[p - i] = (double*)NULL;
1032 }
1033 }
1034 if (elements > elementsAllocated[p]) {
1035 elementsAllocated[p] = elements + elementAllocationIncrement;
1036 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * elementsAllocated[p]);
1037 }
1038 for (i=0; i<elements; i++) {
1039 real64Value[p][i] = (double)(values[i]);
1040 }
1041 break;
1042 case SDDS_STRING:
1043 if (newPage) {
1044 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
1045 for (i=0; i<n; i++) {
1046 stringValue[p - i] = NULL;
1047 }
1048 }
1049 if (elements > elementsAllocated[p]) {
1050 elementsAllocated[p] = elements + elementAllocationIncrement;
1051 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * elementsAllocated[p]);
1052 }
1053 for (i=0; i<elements; i++) {
1054 sprintf(s, "%" PRId16, values[i]);
1055 stringValue[p][i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
1056 strcpy(stringValue[p][i], s);
1057 }
1058 break;
1059 case SDDS_CHARACTER:
1060 if (newPage) {
1061 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
1062 for (i=0; i<n; i++) {
1063 charValue[p - i] = NULL;
1064 }
1065 }
1066 if (elements > elementsAllocated[p]) {
1067 elementsAllocated[p] = elements + elementAllocationIncrement;
1068 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * elementsAllocated[p]);
1069 }
1070 for (i=0; i<elements; i++) {
1071 charValue[p][i] = (char)(values[i]);
1072 }
1073 break;
1074 default:
1075 return(3);
1076 }
1077 if (newPage)
1078 pageCount = page;
1079 if (elementCount[p] < elements) {
1080 elementCount[p] = elements;
1081 }
1082 return(0);
1083}
1084
1085int32_t SDDSArray::setValues(int32_t *values, uint32_t page, uint32_t elements) {
1086 uint32_t i, n=0, p;
1087 bool newPage=false;
1088 char s[SDDS_MAXLINE];
1089 if (page == 0)
1090 return(1);
1091 if (page > pageCount) {
1092 newPage = true;
1093 n = page - pageCount;
1094 }
1095 p = page - 1;
1096 if (newPage) {
1097 elementCount = (uint32_t*)SDDS_realloc(elementCount, sizeof(uint32_t) * page);
1098 elementsAllocated = (uint32_t*)SDDS_realloc(elementsAllocated, sizeof(uint32_t) * page);
1099 for (i=0; i<n; i++) {
1100 elementCount[p-i] = 0;
1101 elementsAllocated[p-i] = 0;
1102 }
1103 }
1104 switch (arrayType) {
1105 case SDDS_INT16:
1106 if (newPage) {
1107 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
1108 for (i=0; i<n; i++) {
1109 int16Value[p - i] = (int16_t*)NULL;
1110 }
1111 }
1112 if (elements > elementsAllocated[p]) {
1113 elementsAllocated[p] = elements + elementAllocationIncrement;
1114 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * elementsAllocated[p]);
1115 }
1116 for (i=0; i<elements; i++) {
1117 int16Value[p][i] = (int16_t)(values[i]);
1118 }
1119 break;
1120 case SDDS_UINT16:
1121 if (newPage) {
1122 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
1123 for (i=0; i<n; i++) {
1124 uint16Value[p - i] = (uint16_t*)NULL;
1125 }
1126 }
1127 if (elements > elementsAllocated[p]) {
1128 elementsAllocated[p] = elements + elementAllocationIncrement;
1129 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * elementsAllocated[p]);
1130 }
1131 for (i=0; i<elements; i++) {
1132 uint16Value[p][i] = (int16_t)(values[i]);
1133 }
1134 break;
1135 case SDDS_INT32:
1136 if (newPage) {
1137 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
1138 for (i=0; i<n; i++) {
1139 int32Value[p - i] = (int32_t*)NULL;
1140 }
1141 }
1142 if (elements > elementsAllocated[p]) {
1143 elementsAllocated[p] = elements + elementAllocationIncrement;
1144 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * elementsAllocated[p]);
1145 }
1146 memcpy(int32Value[p], values, elements * 4);
1147 break;
1148 case SDDS_UINT32:
1149 if (newPage) {
1150 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
1151 for (i=0; i<n; i++) {
1152 uint32Value[p - i] = (uint32_t*)NULL;
1153 }
1154 }
1155 if (elements > elementsAllocated[p]) {
1156 elementsAllocated[p] = elements + elementAllocationIncrement;
1157 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * elementsAllocated[p]);
1158 }
1159 for (i=0; i<elements; i++) {
1160 uint32Value[p][i] = (uint32_t)(values[i]);
1161 }
1162 break;
1163 case SDDS_REAL32:
1164 if (newPage) {
1165 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
1166 for (i=0; i<n; i++) {
1167 real32Value[p - i] = (float*)NULL;
1168 }
1169 }
1170 if (elements > elementsAllocated[p]) {
1171 elementsAllocated[p] = elements + elementAllocationIncrement;
1172 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * elementsAllocated[p]);
1173 }
1174 for (i=0; i<elements; i++) {
1175 real32Value[p][i] = (float)(values[i]);
1176 }
1177 break;
1178 case SDDS_REAL64:
1179 if (newPage) {
1180 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
1181 for (i=0; i<n; i++) {
1182 real64Value[p - i] = (double*)NULL;
1183 }
1184 }
1185 if (elements > elementsAllocated[p]) {
1186 elementsAllocated[p] = elements + elementAllocationIncrement;
1187 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * elementsAllocated[p]);
1188 }
1189 for (i=0; i<elements; i++) {
1190 real64Value[p][i] = (double)(values[i]);
1191 }
1192 break;
1193 case SDDS_STRING:
1194 if (newPage) {
1195 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
1196 for (i=0; i<n; i++) {
1197 stringValue[p - i] = NULL;
1198 }
1199 }
1200 if (elements > elementsAllocated[p]) {
1201 elementsAllocated[p] = elements + elementAllocationIncrement;
1202 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * elementsAllocated[p]);
1203 }
1204 for (i=0; i<elements; i++) {
1205 sprintf(s, "%" PRId16, values[i]);
1206 stringValue[p][i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
1207 strcpy(stringValue[p][i], s);
1208 }
1209 break;
1210 case SDDS_CHARACTER:
1211 if (newPage) {
1212 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
1213 for (i=0; i<n; i++) {
1214 charValue[p - i] = NULL;
1215 }
1216 }
1217 if (elements > elementsAllocated[p]) {
1218 elementsAllocated[p] = elements + elementAllocationIncrement;
1219 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * elementsAllocated[p]);
1220 }
1221 for (i=0; i<elements; i++) {
1222 charValue[p][i] = (char)(values[i]);
1223 }
1224 break;
1225 default:
1226 return(3);
1227 }
1228 if (newPage)
1229 pageCount = page;
1230 if (elementCount[p] < elements) {
1231 elementCount[p] = elements;
1232 }
1233 return(0);
1234}
1235
1236int32_t SDDSArray::setValues(uint32_t *values, uint32_t page, uint32_t elements) {
1237 uint32_t i, n=0, p;
1238 bool newPage=false;
1239 char s[SDDS_MAXLINE];
1240 if (page == 0)
1241 return(1);
1242 if (page > pageCount) {
1243 newPage = true;
1244 n = page - pageCount;
1245 }
1246 p = page - 1;
1247 if (newPage) {
1248 elementCount = (uint32_t*)SDDS_realloc(elementCount, sizeof(uint32_t) * page);
1249 elementsAllocated = (uint32_t*)SDDS_realloc(elementsAllocated, sizeof(uint32_t) * page);
1250 for (i=0; i<n; i++) {
1251 elementCount[p-i] = 0;
1252 elementsAllocated[p-i] = 0;
1253 }
1254 }
1255 switch (arrayType) {
1256 case SDDS_INT16:
1257 if (newPage) {
1258 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
1259 for (i=0; i<n; i++) {
1260 int16Value[p - i] = (int16_t*)NULL;
1261 }
1262 }
1263 if (elements > elementsAllocated[p]) {
1264 elementsAllocated[p] = elements + elementAllocationIncrement;
1265 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * elementsAllocated[p]);
1266 }
1267 for (i=0; i<elements; i++) {
1268 int16Value[p][i] = (int16_t)(values[i]);
1269 }
1270 break;
1271 case SDDS_UINT16:
1272 if (newPage) {
1273 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
1274 for (i=0; i<n; i++) {
1275 uint16Value[p - i] = (uint16_t*)NULL;
1276 }
1277 }
1278 if (elements > elementsAllocated[p]) {
1279 elementsAllocated[p] = elements + elementAllocationIncrement;
1280 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * elementsAllocated[p]);
1281 }
1282 for (i=0; i<elements; i++) {
1283 uint16Value[p][i] = (int16_t)(values[i]);
1284 }
1285 break;
1286 case SDDS_INT32:
1287 if (newPage) {
1288 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
1289 for (i=0; i<n; i++) {
1290 int32Value[p - i] = (int32_t*)NULL;
1291 }
1292 }
1293 if (elements > elementsAllocated[p]) {
1294 elementsAllocated[p] = elements + elementAllocationIncrement;
1295 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * elementsAllocated[p]);
1296 }
1297 for (i=0; i<elements; i++) {
1298 int32Value[p][i] = (int32_t)(values[i]);
1299 }
1300 break;
1301 case SDDS_UINT32:
1302 if (newPage) {
1303 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
1304 for (i=0; i<n; i++) {
1305 uint32Value[p - i] = (uint32_t*)NULL;
1306 }
1307 }
1308 if (elements > elementsAllocated[p]) {
1309 elementsAllocated[p] = elements + elementAllocationIncrement;
1310 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * elementsAllocated[p]);
1311 }
1312 memcpy(uint32Value[p], values, elements * 4);
1313 break;
1314 case SDDS_REAL32:
1315 if (newPage) {
1316 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
1317 for (i=0; i<n; i++) {
1318 real32Value[p - i] = (float*)NULL;
1319 }
1320 }
1321 if (elements > elementsAllocated[p]) {
1322 elementsAllocated[p] = elements + elementAllocationIncrement;
1323 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * elementsAllocated[p]);
1324 }
1325 for (i=0; i<elements; i++) {
1326 real32Value[p][i] = (float)(values[i]);
1327 }
1328 break;
1329 case SDDS_REAL64:
1330 if (newPage) {
1331 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
1332 for (i=0; i<n; i++) {
1333 real64Value[p - i] = (double*)NULL;
1334 }
1335 }
1336 if (elements > elementsAllocated[p]) {
1337 elementsAllocated[p] = elements + elementAllocationIncrement;
1338 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * elementsAllocated[p]);
1339 }
1340 for (i=0; i<elements; i++) {
1341 real64Value[p][i] = (double)(values[i]);
1342 }
1343 break;
1344 case SDDS_STRING:
1345 if (newPage) {
1346 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
1347 for (i=0; i<n; i++) {
1348 stringValue[p - i] = NULL;
1349 }
1350 }
1351 if (elements > elementsAllocated[p]) {
1352 elementsAllocated[p] = elements + elementAllocationIncrement;
1353 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * elementsAllocated[p]);
1354 }
1355 for (i=0; i<elements; i++) {
1356 sprintf(s, "%" PRId16, values[i]);
1357 stringValue[p][i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
1358 strcpy(stringValue[p][i], s);
1359 }
1360 break;
1361 case SDDS_CHARACTER:
1362 if (newPage) {
1363 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
1364 for (i=0; i<n; i++) {
1365 charValue[p - i] = NULL;
1366 }
1367 }
1368 if (elements > elementsAllocated[p]) {
1369 elementsAllocated[p] = elements + elementAllocationIncrement;
1370 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * elementsAllocated[p]);
1371 }
1372 for (i=0; i<elements; i++) {
1373 charValue[p][i] = (char)(values[i]);
1374 }
1375 break;
1376 default:
1377 return(3);
1378 }
1379 if (newPage)
1380 pageCount = page;
1381 if (elementCount[p] < elements) {
1382 elementCount[p] = elements;
1383 }
1384 return(0);
1385}
1386
1387int32_t SDDSArray::setValues(float *values, uint32_t page, uint32_t elements) {
1388 uint32_t i, n=0, p;
1389 bool newPage=false;
1390 char s[SDDS_MAXLINE];
1391 if (page == 0)
1392 return(1);
1393 if (page > pageCount) {
1394 newPage = true;
1395 n = page - pageCount;
1396 }
1397 p = page - 1;
1398 if (newPage) {
1399 elementCount = (uint32_t*)SDDS_realloc(elementCount, sizeof(uint32_t) * page);
1400 elementsAllocated = (uint32_t*)SDDS_realloc(elementsAllocated, sizeof(uint32_t) * page);
1401 for (i=0; i<n; i++) {
1402 elementCount[p-i] = 0;
1403 elementsAllocated[p-i] = 0;
1404 }
1405 }
1406 switch (arrayType) {
1407 case SDDS_INT16:
1408 if (newPage) {
1409 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
1410 for (i=0; i<n; i++) {
1411 int16Value[p - i] = (int16_t*)NULL;
1412 }
1413 }
1414 if (elements > elementsAllocated[p]) {
1415 elementsAllocated[p] = elements + elementAllocationIncrement;
1416 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * elementsAllocated[p]);
1417 }
1418 for (i=0; i<elements; i++) {
1419 int16Value[p][i] = (int16_t)(values[i]);
1420 }
1421 break;
1422 case SDDS_UINT16:
1423 if (newPage) {
1424 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
1425 for (i=0; i<n; i++) {
1426 uint16Value[p - i] = (uint16_t*)NULL;
1427 }
1428 }
1429 if (elements > elementsAllocated[p]) {
1430 elementsAllocated[p] = elements + elementAllocationIncrement;
1431 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * elementsAllocated[p]);
1432 }
1433 for (i=0; i<elements; i++) {
1434 uint16Value[p][i] = (int16_t)(values[i]);
1435 }
1436 break;
1437 case SDDS_INT32:
1438 if (newPage) {
1439 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
1440 for (i=0; i<n; i++) {
1441 int32Value[p - i] = (int32_t*)NULL;
1442 }
1443 }
1444 if (elements > elementsAllocated[p]) {
1445 elementsAllocated[p] = elements + elementAllocationIncrement;
1446 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * elementsAllocated[p]);
1447 }
1448 for (i=0; i<elements; i++) {
1449 int32Value[p][i] = (int32_t)(values[i]);
1450 }
1451 break;
1452 case SDDS_UINT32:
1453 if (newPage) {
1454 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
1455 for (i=0; i<n; i++) {
1456 uint32Value[p - i] = (uint32_t*)NULL;
1457 }
1458 }
1459 if (elements > elementsAllocated[p]) {
1460 elementsAllocated[p] = elements + elementAllocationIncrement;
1461 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * elementsAllocated[p]);
1462 }
1463 for (i=0; i<elements; i++) {
1464 uint32Value[p][i] = (uint32_t)(values[i]);
1465 }
1466 break;
1467 case SDDS_REAL32:
1468 if (newPage) {
1469 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
1470 for (i=0; i<n; i++) {
1471 real32Value[p - i] = (float*)NULL;
1472 }
1473 }
1474 if (elements > elementsAllocated[p]) {
1475 elementsAllocated[p] = elements + elementAllocationIncrement;
1476 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * elementsAllocated[p]);
1477 }
1478 memcpy(real32Value[p], values, elements * 4);
1479 break;
1480 case SDDS_REAL64:
1481 if (newPage) {
1482 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
1483 for (i=0; i<n; i++) {
1484 real64Value[p - i] = (double*)NULL;
1485 }
1486 }
1487 if (elements > elementsAllocated[p]) {
1488 elementsAllocated[p] = elements + elementAllocationIncrement;
1489 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * elementsAllocated[p]);
1490 }
1491 for (i=0; i<elements; i++) {
1492 real64Value[p][i] = (double)(values[i]);
1493 }
1494 break;
1495 case SDDS_STRING:
1496 if (newPage) {
1497 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
1498 for (i=0; i<n; i++) {
1499 stringValue[p - i] = NULL;
1500 }
1501 }
1502 if (elements > elementsAllocated[p]) {
1503 elementsAllocated[p] = elements + elementAllocationIncrement;
1504 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * elementsAllocated[p]);
1505 }
1506 for (i=0; i<elements; i++) {
1507 sprintf(s, "%f", values[i]);
1508 stringValue[p][i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
1509 strcpy(stringValue[p][i], s);
1510 }
1511 break;
1512 case SDDS_CHARACTER:
1513 if (newPage) {
1514 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
1515 for (i=0; i<n; i++) {
1516 charValue[p - i] = NULL;
1517 }
1518 }
1519 if (elements > elementsAllocated[p]) {
1520 elementsAllocated[p] = elements + elementAllocationIncrement;
1521 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * elementsAllocated[p]);
1522 }
1523 for (i=0; i<elements; i++) {
1524 charValue[p][i] = (char)(values[i]);
1525 }
1526 break;
1527 default:
1528 return(3);
1529 }
1530 if (newPage)
1531 pageCount = page;
1532 if (elementCount[p] < elements) {
1533 elementCount[p] = elements;
1534 }
1535 return(0);
1536}
1537
1538int32_t SDDSArray::setValues(double *values, uint32_t page, uint32_t elements) {
1539 uint32_t i, n=0, p;
1540 bool newPage=false;
1541 char s[SDDS_MAXLINE];
1542 if (page == 0)
1543 return(1);
1544 if (page > pageCount) {
1545 newPage = true;
1546 n = page - pageCount;
1547 }
1548 p = page - 1;
1549 if (newPage) {
1550 elementCount = (uint32_t*)SDDS_realloc(elementCount, sizeof(uint32_t) * page);
1551 elementsAllocated = (uint32_t*)SDDS_realloc(elementsAllocated, sizeof(uint32_t) * page);
1552 for (i=0; i<n; i++) {
1553 elementCount[p-i] = 0;
1554 elementsAllocated[p-i] = 0;
1555 }
1556 }
1557 switch (arrayType) {
1558 case SDDS_INT16:
1559 if (newPage) {
1560 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
1561 for (i=0; i<n; i++) {
1562 int16Value[p - i] = (int16_t*)NULL;
1563 }
1564 }
1565 if (elements > elementsAllocated[p]) {
1566 elementsAllocated[p] = elements + elementAllocationIncrement;
1567 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * elementsAllocated[p]);
1568 }
1569 for (i=0; i<elements; i++) {
1570 int16Value[p][i] = (int16_t)(values[i]);
1571 }
1572 break;
1573 case SDDS_UINT16:
1574 if (newPage) {
1575 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
1576 for (i=0; i<n; i++) {
1577 uint16Value[p - i] = (uint16_t*)NULL;
1578 }
1579 }
1580 if (elements > elementsAllocated[p]) {
1581 elementsAllocated[p] = elements + elementAllocationIncrement;
1582 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * elementsAllocated[p]);
1583 }
1584 for (i=0; i<elements; i++) {
1585 uint16Value[p][i] = (int16_t)(values[i]);
1586 }
1587 break;
1588 case SDDS_INT32:
1589 if (newPage) {
1590 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
1591 for (i=0; i<n; i++) {
1592 int32Value[p - i] = (int32_t*)NULL;
1593 }
1594 }
1595 if (elements > elementsAllocated[p]) {
1596 elementsAllocated[p] = elements + elementAllocationIncrement;
1597 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * elementsAllocated[p]);
1598 }
1599 for (i=0; i<elements; i++) {
1600 int32Value[p][i] = (int32_t)(values[i]);
1601 }
1602 break;
1603 case SDDS_UINT32:
1604 if (newPage) {
1605 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
1606 for (i=0; i<n; i++) {
1607 uint32Value[p - i] = (uint32_t*)NULL;
1608 }
1609 }
1610 if (elements > elementsAllocated[p]) {
1611 elementsAllocated[p] = elements + elementAllocationIncrement;
1612 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * elementsAllocated[p]);
1613 }
1614 for (i=0; i<elements; i++) {
1615 uint32Value[p][i] = (uint32_t)(values[i]);
1616 }
1617 break;
1618 case SDDS_REAL32:
1619 if (newPage) {
1620 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
1621 for (i=0; i<n; i++) {
1622 real32Value[p - i] = (float*)NULL;
1623 }
1624 }
1625 if (elements > elementsAllocated[p]) {
1626 elementsAllocated[p] = elements + elementAllocationIncrement;
1627 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * elementsAllocated[p]);
1628 }
1629 for (i=0; i<elements; i++) {
1630 real32Value[p][i] = (float)(values[i]);
1631 }
1632 break;
1633 case SDDS_REAL64:
1634 if (newPage) {
1635 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
1636 for (i=0; i<n; i++) {
1637 real64Value[p - i] = (double*)NULL;
1638 }
1639 }
1640 if (elements > elementsAllocated[p]) {
1641 elementsAllocated[p] = elements + elementAllocationIncrement;
1642 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * elementsAllocated[p]);
1643 }
1644 memcpy(real64Value[p], values, elements * 8);
1645 break;
1646 case SDDS_STRING:
1647 if (newPage) {
1648 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
1649 for (i=0; i<n; i++) {
1650 stringValue[p - i] = NULL;
1651 }
1652 }
1653 if (elements > elementsAllocated[p]) {
1654 elementsAllocated[p] = elements + elementAllocationIncrement;
1655 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * elementsAllocated[p]);
1656 }
1657 for (i=0; i<elements; i++) {
1658 sprintf(s, "%f", values[i]);
1659 stringValue[p][i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
1660 strcpy(stringValue[p][i], s);
1661 }
1662 break;
1663 case SDDS_CHARACTER:
1664 if (newPage) {
1665 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
1666 for (i=0; i<n; i++) {
1667 charValue[p - i] = NULL;
1668 }
1669 }
1670 if (elements > elementsAllocated[p]) {
1671 elementsAllocated[p] = elements + elementAllocationIncrement;
1672 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * elementsAllocated[p]);
1673 }
1674 for (i=0; i<elements; i++) {
1675 charValue[p][i] = (char)(values[i]);
1676 }
1677 break;
1678 default:
1679 return(3);
1680 }
1681 if (newPage)
1682 pageCount = page;
1683 if (elementCount[p] < elements) {
1684 elementCount[p] = elements;
1685 }
1686 return(0);
1687}
1688
1689int32_t SDDSArray::setValues(char **values, uint32_t page, uint32_t elements) {
1690 int32_t returnVal=0;
1691 uint32_t i, n=0, p;
1692 bool newPage=false;
1693 int64_t *iValue=NULL;
1694 double *dValue=NULL;
1695 if (page == 0)
1696 return(1);
1697
1698 if (SDDS_INTEGER_TYPE(arrayType)) {
1699 iValue = (int64_t*)SDDS_malloc(sizeof(int64_t) * elements);
1700 for (i=0; i<elements; i++) {
1701 iValue[i] = strtoll(values[i], (char**)NULL, 10);
1702 if ((iValue[i] == LLONG_MIN) || (iValue[i] == LLONG_MAX)) {
1703 /*unable to convert given string to integer*/
1704 returnVal=2;
1705 iValue[i]=0;
1706 }
1707 }
1708 } else if (SDDS_FLOATING_TYPE(arrayType)) {
1709 dValue = (double*)SDDS_malloc(sizeof(double) * elements);
1710 for (i=0; i<elements; i++) {
1711 dValue[i] = strtod(values[i], (char**)NULL);
1712 if ((dValue[i] == HUGE_VAL) || (dValue[i] == -HUGE_VAL)) {
1713 /*unable to convert given string to floating point*/
1714 returnVal=2;
1715 dValue[i]=0;
1716 }
1717 }
1718 }
1719
1720 if (page > pageCount) {
1721 newPage = true;
1722 n = page - pageCount;
1723 }
1724 p = page - 1;
1725 if (newPage) {
1726 elementCount = (uint32_t*)SDDS_realloc(elementCount, sizeof(uint32_t) * page);
1727 elementsAllocated = (uint32_t*)SDDS_realloc(elementsAllocated, sizeof(uint32_t) * page);
1728 for (i=0; i<n; i++) {
1729 elementCount[p-i] = 0;
1730 elementsAllocated[p-i] = 0;
1731 }
1732 }
1733 switch (arrayType) {
1734 case SDDS_INT16:
1735 if (newPage) {
1736 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
1737 for (i=0; i<n; i++) {
1738 int16Value[p - i] = (int16_t*)NULL;
1739 }
1740 }
1741 if (elements > elementsAllocated[p]) {
1742 elementsAllocated[p] = elements + elementAllocationIncrement;
1743 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * elementsAllocated[p]);
1744 }
1745 for (i=0; i<elements; i++) {
1746 int16Value[p][i] = (int16_t)(iValue[i]);
1747 }
1748 break;
1749 case SDDS_UINT16:
1750 if (newPage) {
1751 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
1752 for (i=0; i<n; i++) {
1753 uint16Value[p - i] = (uint16_t*)NULL;
1754 }
1755 }
1756 if (elements > elementsAllocated[p]) {
1757 elementsAllocated[p] = elements + elementAllocationIncrement;
1758 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * elementsAllocated[p]);
1759 }
1760 for (i=0; i<elements; i++) {
1761 uint16Value[p][i] = (int16_t)(iValue[i]);
1762 }
1763 break;
1764 case SDDS_INT32:
1765 if (newPage) {
1766 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
1767 for (i=0; i<n; i++) {
1768 int32Value[p - i] = (int32_t*)NULL;
1769 }
1770 }
1771 if (elements > elementsAllocated[p]) {
1772 elementsAllocated[p] = elements + elementAllocationIncrement;
1773 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * elementsAllocated[p]);
1774 }
1775 for (i=0; i<elements; i++) {
1776 int32Value[p][i] = (int32_t)(iValue[i]);
1777 }
1778 break;
1779 case SDDS_UINT32:
1780 if (newPage) {
1781 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
1782 for (i=0; i<n; i++) {
1783 uint32Value[p - i] = (uint32_t*)NULL;
1784 }
1785 }
1786 if (elements > elementsAllocated[p]) {
1787 elementsAllocated[p] = elements + elementAllocationIncrement;
1788 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * elementsAllocated[p]);
1789 }
1790 for (i=0; i<elements; i++) {
1791 uint32Value[p][i] = (uint32_t)(iValue[i]);
1792 }
1793 break;
1794 case SDDS_REAL32:
1795 if (newPage) {
1796 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
1797 for (i=0; i<n; i++) {
1798 real32Value[p - i] = (float*)NULL;
1799 }
1800 }
1801 if (elements > elementsAllocated[p]) {
1802 elementsAllocated[p] = elements + elementAllocationIncrement;
1803 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * elementsAllocated[p]);
1804 }
1805 for (i=0; i<elements; i++) {
1806 real32Value[p][i] = (float)(dValue[i]);
1807 }
1808 break;
1809 case SDDS_REAL64:
1810 if (newPage) {
1811 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
1812 for (i=0; i<n; i++) {
1813 real64Value[p - i] = (double*)NULL;
1814 }
1815 }
1816 if (elements > elementsAllocated[p]) {
1817 elementsAllocated[p] = elements + elementAllocationIncrement;
1818 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * elementsAllocated[p]);
1819 }
1820 for (i=0; i<elements; i++) {
1821 real64Value[p][i] = (double)(dValue[i]);
1822 }
1823 break;
1824 case SDDS_STRING:
1825 if (newPage) {
1826 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
1827 for (i=0; i<n; i++) {
1828 stringValue[p - i] = NULL;
1829 }
1830 }
1831 if (elements > elementsAllocated[p]) {
1832 elementsAllocated[p] = elements + elementAllocationIncrement;
1833 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * elementsAllocated[p]);
1834 }
1835 for (i=0; i<elements; i++) {
1836 stringValue[p][i] = (char*)SDDS_malloc(sizeof(char) * strlen(values[i]) + 1);
1837 strcpy(stringValue[p][i], values[i]);
1838 }
1839 break;
1840 case SDDS_CHARACTER:
1841 if (newPage) {
1842 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
1843 for (i=0; i<n; i++) {
1844 charValue[p - i] = NULL;
1845 }
1846 }
1847 if (elements > elementsAllocated[p]) {
1848 elementsAllocated[p] = elements + elementAllocationIncrement;
1849 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * elementsAllocated[p]);
1850 }
1851 for (i=0; i<elements; i++) {
1852 charValue[p][i] = (char)(values[i][0]);
1853 }
1854 break;
1855 default:
1856 return(3);
1857 }
1858 if (newPage)
1859 pageCount = page;
1860 if (elementCount[p] < elements) {
1861 elementCount[p] = elements;
1862 }
1863 return(returnVal);
1864}
1865
1866int32_t SDDSArray::setValues(char *values, uint32_t page, uint32_t elements) {
1867 uint32_t i, n=0, p;
1868 bool newPage=false;
1869 char s[SDDS_MAXLINE];
1870 if (page == 0)
1871 return(1);
1872 if (page > pageCount) {
1873 newPage = true;
1874 n = page - pageCount;
1875 }
1876 p = page - 1;
1877 if (newPage) {
1878 elementCount = (uint32_t*)SDDS_realloc(elementCount, sizeof(uint32_t) * page);
1879 elementsAllocated = (uint32_t*)SDDS_realloc(elementsAllocated, sizeof(uint32_t) * page);
1880 for (i=0; i<n; i++) {
1881 elementCount[p-i] = 0;
1882 elementsAllocated[p-i] = 0;
1883 }
1884 }
1885 switch (arrayType) {
1886 case SDDS_INT16:
1887 if (newPage) {
1888 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
1889 for (i=0; i<n; i++) {
1890 int16Value[p - i] = (int16_t*)NULL;
1891 }
1892 }
1893 if (elements > elementsAllocated[p]) {
1894 elementsAllocated[p] = elements + elementAllocationIncrement;
1895 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * elementsAllocated[p]);
1896 }
1897 for (i=0; i<elements; i++) {
1898 int16Value[p][i] = (int16_t)(values[i]);
1899 }
1900 break;
1901 case SDDS_UINT16:
1902 if (newPage) {
1903 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
1904 for (i=0; i<n; i++) {
1905 uint16Value[p - i] = (uint16_t*)NULL;
1906 }
1907 }
1908 if (elements > elementsAllocated[p]) {
1909 elementsAllocated[p] = elements + elementAllocationIncrement;
1910 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * elementsAllocated[p]);
1911 }
1912 for (i=0; i<elements; i++) {
1913 uint16Value[p][i] = (int16_t)(values[i]);
1914 }
1915 break;
1916 case SDDS_INT32:
1917 if (newPage) {
1918 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
1919 for (i=0; i<n; i++) {
1920 int32Value[p - i] = (int32_t*)NULL;
1921 }
1922 }
1923 if (elements > elementsAllocated[p]) {
1924 elementsAllocated[p] = elements + elementAllocationIncrement;
1925 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * elementsAllocated[p]);
1926 }
1927 for (i=0; i<elements; i++) {
1928 int32Value[p][i] = (int32_t)(values[i]);
1929 }
1930 break;
1931 case SDDS_UINT32:
1932 if (newPage) {
1933 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
1934 for (i=0; i<n; i++) {
1935 uint32Value[p - i] = (uint32_t*)NULL;
1936 }
1937 }
1938 if (elements > elementsAllocated[p]) {
1939 elementsAllocated[p] = elements + elementAllocationIncrement;
1940 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * elementsAllocated[p]);
1941 }
1942 for (i=0; i<elements; i++) {
1943 uint32Value[p][i] = (uint32_t)(values[i]);
1944 }
1945 break;
1946 case SDDS_REAL32:
1947 if (newPage) {
1948 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
1949 for (i=0; i<n; i++) {
1950 real32Value[p - i] = (float*)NULL;
1951 }
1952 }
1953 if (elements > elementsAllocated[p]) {
1954 elementsAllocated[p] = elements + elementAllocationIncrement;
1955 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * elementsAllocated[p]);
1956 }
1957 for (i=0; i<elements; i++) {
1958 real32Value[p][i] = (float)(values[i]);
1959 }
1960 break;
1961 case SDDS_REAL64:
1962 if (newPage) {
1963 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
1964 for (i=0; i<n; i++) {
1965 real64Value[p - i] = (double*)NULL;
1966 }
1967 }
1968 if (elements > elementsAllocated[p]) {
1969 elementsAllocated[p] = elements + elementAllocationIncrement;
1970 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * elementsAllocated[p]);
1971 }
1972 for (i=0; i<elements; i++) {
1973 real64Value[p][i] = (double)(values[i]);
1974 }
1975 break;
1976 case SDDS_STRING:
1977 if (newPage) {
1978 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
1979 for (i=0; i<n; i++) {
1980 stringValue[p - i] = NULL;
1981 }
1982 }
1983 if (elements > elementsAllocated[p]) {
1984 elementsAllocated[p] = elements + elementAllocationIncrement;
1985 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * elementsAllocated[p]);
1986 }
1987 for (i=0; i<elements; i++) {
1988 sprintf(s, "%" PRId16, values[i]);
1989 stringValue[p][i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
1990 strcpy(stringValue[p][i], s);
1991 }
1992 break;
1993 case SDDS_CHARACTER:
1994 if (newPage) {
1995 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
1996 for (i=0; i<n; i++) {
1997 charValue[p - i] = NULL;
1998 }
1999 }
2000 if (elements > elementsAllocated[p]) {
2001 elementsAllocated[p] = elements + elementAllocationIncrement;
2002 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * elementsAllocated[p]);
2003 }
2004 memcpy(charValue[p], values, elements);
2005 break;
2006 default:
2007 return(3);
2008 }
2009 if (newPage)
2010 pageCount = page;
2011 if (elementCount[p] < elements) {
2012 elementCount[p] = elements;
2013 }
2014 return(0);
2015}
2016
2017/**
2018 * @brief readAsciiValues
2019 *
2020 * C++ Arguments: char *value, uint32_t page
2021 *
2022 * Results: 0 for success
2023 * 1 for failure
2024 */
2025int32_t SDDSArray::readAsciiValues(char **bigBuffer, int32_t *bigBufferSize, uint32_t page) {
2026 int32_t returnVal=0, length;
2027 uint32_t i, p;
2028 int64_t iValue;
2029 double dValue;
2030 static char *buffer=NULL;
2031 static int32_t bufferSize=0;
2032 if ((page == 0) || (page - 1 != pageCount)) {
2033 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--invalid page number (SDDSArray::readAsciiValues)");
2034 return(1);
2035 }
2036 if (arrayDimensions == 0) {
2037 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--invalid array dimensions (SDDSArray::readAsciiValues)");
2038 return(1);
2039 }
2040 if (arrayDim == NULL) {
2041 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--invalid array dimensions (SDDSArray::readAsciiValues)");
2042 return(1);
2043 }
2044 if (arrayDim[page - 1] == NULL) {
2045 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--invalid array dimensions (SDDSArray::readAsciiValues)");
2046 return(1);
2047 }
2048 if (bufferSize==0) {
2049 bufferSize=SDDS_MAXLINE;
2050 buffer = (char*)SDDS_malloc(sizeof(*buffer)*(bufferSize));
2051 }
2052 if (bufferSize <= *bigBufferSize) {
2053 bufferSize = 2 * *bigBufferSize;
2054 buffer = (char*)SDDS_realloc(buffer, sizeof(*buffer)*(bufferSize));
2055 }
2056
2057 p = page - 1;
2058 elementCount = (uint32_t*)SDDS_realloc(elementCount, sizeof(uint32_t) * page);
2059 elementsAllocated = (uint32_t*)SDDS_realloc(elementsAllocated, sizeof(uint32_t) * page);
2060 elementCount[p] = arrayDim[page - 1][0];
2061 for (i=1;i<arrayDimensions;i++) {
2062 elementCount[p] *= arrayDim[p][i];
2063 }
2064 elementsAllocated[p] = elementCount[p];
2065 switch (arrayType) {
2066 case SDDS_INT16:
2067 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
2068 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * elementsAllocated[p]);
2069 for (i=0; i<elementCount[p] ; i++) {
2070 if (SDDS_getToken(bigBuffer, bigBufferSize, buffer, bufferSize) < 0) {
2071 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array (SDDSArray::readAsciiValues)");
2072 returnVal=1;
2073 iValue=0;
2074 } else {
2075 iValue = strtoll(buffer, (char**)NULL, 10);
2076 if ((iValue == LLONG_MIN) || (iValue == LLONG_MAX)) {
2077 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--not a valid integer (SDDSArray::readAsciiValues)");
2078 returnVal=1;
2079 iValue=0;
2080 }
2081 }
2082 int16Value[p][i] = (int16_t)iValue;
2083 }
2084 break;
2085 case SDDS_UINT16:
2086 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
2087 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * elementsAllocated[p]);
2088 for (i=0; i<elementCount[p] ; i++) {
2089 if (SDDS_getToken(bigBuffer, bigBufferSize, buffer, bufferSize) < 0) {
2090 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array (SDDSArray::readAsciiValues)");
2091 returnVal=1;
2092 iValue=0;
2093 } else {
2094 iValue = strtoll(buffer, (char**)NULL, 10);
2095 if ((iValue == LLONG_MIN) || (iValue == LLONG_MAX)) {
2096 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--not a valid integer (SDDSArray::readAsciiValues)");
2097 returnVal=1;
2098 iValue=0;
2099 }
2100 }
2101 uint16Value[p][i] = (uint16_t)iValue;
2102 }
2103 break;
2104 case SDDS_INT32:
2105 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
2106 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * elementsAllocated[p]);
2107 for (i=0; i<elementCount[p] ; i++) {
2108 if (SDDS_getToken(bigBuffer, bigBufferSize, buffer, bufferSize) < 0) {
2109 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array (SDDSArray::readAsciiValues)");
2110 returnVal=1;
2111 iValue=0;
2112 } else {
2113 iValue = strtoll(buffer, (char**)NULL, 10);
2114 if ((iValue == LLONG_MIN) || (iValue == LLONG_MAX)) {
2115 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--not a valid integer (SDDSArray::readAsciiValues)");
2116 returnVal=1;
2117 iValue=0;
2118 }
2119 }
2120 int32Value[p][i] = (int32_t)iValue;
2121 }
2122 break;
2123 case SDDS_UINT32:
2124 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
2125 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * elementsAllocated[p]);
2126 for (i=0; i<elementCount[p] ; i++) {
2127 if (SDDS_getToken(bigBuffer, bigBufferSize, buffer, bufferSize) < 0) {
2128 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array (SDDSArray::readAsciiValues)");
2129 returnVal=1;
2130 iValue=0;
2131 } else {
2132 iValue = strtoll(buffer, (char**)NULL, 10);
2133 if ((iValue == LLONG_MIN) || (iValue == LLONG_MAX)) {
2134 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--not a valid integer (SDDSArray::readAsciiValues)");
2135 returnVal=1;
2136 iValue=0;
2137 }
2138 }
2139 uint32Value[p][i] = (uint32_t)iValue;
2140 }
2141 break;
2142 case SDDS_REAL32:
2143 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
2144 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * elementsAllocated[p]);
2145 for (i=0; i<elementCount[p] ; i++) {
2146 if (SDDS_getToken(bigBuffer, bigBufferSize, buffer, bufferSize) < 0) {
2147 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array (SDDSArray::readAsciiValues)");
2148 returnVal=1;
2149 dValue=0;
2150 } else {
2151 dValue = strtod(buffer, (char**)NULL);
2152 if ((dValue == HUGE_VAL) || (dValue == -HUGE_VAL)) {
2153 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--not a valid number (SDDSArray::readAsciiValues)");
2154 returnVal=1;
2155 dValue=0;
2156 }
2157 }
2158 real32Value[p][i] = (float)dValue;
2159 }
2160 break;
2161 case SDDS_REAL64:
2162 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
2163 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * elementsAllocated[p]);
2164 for (i=0; i<elementCount[p] ; i++) {
2165 if (SDDS_getToken(bigBuffer, bigBufferSize, buffer, bufferSize) < 0) {
2166 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array (SDDSArray::readAsciiValues)");
2167 returnVal=1;
2168 dValue=0;
2169 } else {
2170 dValue = strtod(buffer, (char**)NULL);
2171 if ((dValue == HUGE_VAL) || (dValue == -HUGE_VAL)) {
2172 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--not a valid number (SDDSArray::readAsciiValues)");
2173 returnVal=1;
2174 dValue=0;
2175 }
2176 }
2177 real64Value[p][i] = (double)dValue;
2178 }
2179 break;
2180 case SDDS_STRING:
2181 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
2182 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * elementsAllocated[p]);
2183 length = strlen(*bigBuffer);
2184 if (length > 0) {
2185 if ((*bigBuffer)[length-1] == '\r') {
2186 (*bigBuffer)[length-1] = 0;
2187 }
2188 }
2189 for (i=0; i<elementCount[p] ; i++) {
2190 if (SDDS_getToken(bigBuffer, bigBufferSize, buffer, bufferSize) < 0) {
2191 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array (SDDSArray::readAsciiValues)");
2192 returnVal=1;
2193 stringValue[p][i] = (char*)SDDS_malloc(sizeof(char) * 4);
2194 strcpy(stringValue[p][i], "\"\"");
2195 } else {
2196 SDDS_interpretEscapes(buffer);
2197 stringValue[p][i] = (char*)SDDS_malloc(sizeof(char) * strlen(buffer) + 1);
2198 strcpy(stringValue[p][i], buffer);
2199 }
2200 }
2201 break;
2202 case SDDS_CHARACTER:
2203 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
2204 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * elementsAllocated[p]);
2205 for (i=0; i<elementCount[p] ; i++) {
2206 if (SDDS_getToken(bigBuffer, bigBufferSize, buffer, bufferSize) < 0) {
2207 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array (SDDSArray::readAsciiValues)");
2208 returnVal=1;
2209 charValue[p][i] = '-';
2210 } else {
2211 charValue[p][i] = buffer[0];
2212 }
2213 }
2214 break;
2215 default:
2216 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--invalid array type (SDDSArray::readAsciiValues)");
2217 return(1);
2218 }
2219 pageCount = page;
2220 return(returnVal);
2221}
2222
2223/**
2224 * @brief readBinaryValues
2225 *
2226 * C++ Arguments: FILE *fp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian
2227 * C++ Arguments: voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian
2228 *
2229 * Results: 0 on success
2230 * 1 on failure
2231 */
2232int32_t SDDSArray::readBinaryValues(FILE *fp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian) {
2233 uint32_t i, p;
2234
2235 if ((page == 0) || (page - 1 != pageCount)) {
2236 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--invalid page number (SDDSArray::readBinaryValues)");
2237 return(1);
2238 }
2239 if (arrayDimensions == 0) {
2240 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--invalid array dimensions (SDDSArray::readBinaryValues)");
2241 return(1);
2242 }
2243 if (arrayDim == NULL) {
2244 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--invalid array dimensions (SDDSArray::readBinaryValues)");
2245 return(1);
2246 }
2247 if (arrayDim[page - 1] == NULL) {
2248 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--invalid array dimensions (SDDSArray::readBinaryValues)");
2249 return(1);
2250 }
2251 p = page - 1;
2252 elementCount = (uint32_t*)SDDS_realloc(elementCount, sizeof(uint32_t) * page);
2253 elementsAllocated = (uint32_t*)SDDS_realloc(elementsAllocated, sizeof(uint32_t) * page);
2254 elementCount[p] = arrayDim[page - 1][0];
2255 for (i=1;i<arrayDimensions;i++) {
2256 elementCount[p] *= arrayDim[p][i];
2257 }
2258 elementsAllocated[p] = elementCount[p];
2259 switch (arrayType) {
2260 case SDDS_INT16:
2261 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
2262 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * elementCount[p]);
2263 if (SDDS_bufferedRead(&(int16Value[p][0]), 2 * elementCount[p], fp, fBuffer, sddsfile)) {
2264 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--failure reading value (SDDSArray::readBinaryValues)");
2265 return(1);
2266 }
2267 break;
2268 case SDDS_UINT16:
2269 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
2270 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * elementCount[p]);
2271 if (SDDS_bufferedRead(&(uint16Value[p][0]), 2 * elementCount[p], fp, fBuffer, sddsfile)) {
2272 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--failure reading value (SDDSArray::readBinaryValues)");
2273 return(1);
2274 }
2275 break;
2276 case SDDS_INT32:
2277 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
2278 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * elementCount[p]);
2279 if (SDDS_bufferedRead(&(int32Value[p][0]), 4 * elementCount[p], fp, fBuffer, sddsfile)) {
2280 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--failure reading value (SDDSArray::readBinaryValues)");
2281 return(1);
2282 }
2283 break;
2284 case SDDS_UINT32:
2285 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
2286 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * elementCount[p]);
2287 if (SDDS_bufferedRead(&(uint32Value[p][0]), 4 * elementCount[p], fp, fBuffer, sddsfile)) {
2288 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--failure reading value (SDDSArray::readBinaryValues)");
2289 return(1);
2290 }
2291 break;
2292 case SDDS_REAL32:
2293 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
2294 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * elementCount[p]);
2295 if (SDDS_bufferedRead(&(real32Value[p][0]), 4 * elementCount[p], fp, fBuffer, sddsfile)) {
2296 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--failure reading value (SDDSArray::readBinaryValues)");
2297 return(1);
2298 }
2299 break;
2300 case SDDS_REAL64:
2301 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
2302 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * elementCount[p]);
2303 if (SDDS_bufferedRead(&(real64Value[p][0]), 8 * elementCount[p], fp, fBuffer, sddsfile)) {
2304 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--failure reading value (SDDSArray::readBinaryValues)");
2305 return(1);
2306 }
2307 break;
2308 case SDDS_STRING:
2309 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
2310 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * elementCount[p]);
2311 for (i=0; i<elementCount[p]; i++) {
2312 stringValue[p][i] = NULL;
2313 if (SDDS_readBinaryString(&(stringValue[p][i]), fp, fBuffer, sddsfile)) {
2314 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--failure reading value (SDDSArray::readBinaryValues)");
2315 return(1);
2316 }
2317 }
2318 break;
2319 case SDDS_CHARACTER:
2320 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
2321 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * elementCount[p]);
2322 if (SDDS_bufferedRead(&(charValue[p][0]), elementCount[p], fp, fBuffer, sddsfile)) {
2323 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--failure reading value (SDDSArray::readBinaryValues)");
2324 return(1);
2325 }
2326 break;
2327 default:
2328 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--unknown type (SDDSArray::readBinaryValues)");
2329 return(1);
2330 }
2331 pageCount = page;
2332 return(0);
2333}
2334
2335int32_t SDDSArray::readBinaryValues(voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian) {
2336 uint32_t i, p;
2337
2338 if ((page == 0) || (page - 1 != pageCount)) {
2339 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--invalid page number (SDDSArray::readBinaryValues)");
2340 return(1);
2341 }
2342 if (arrayDimensions == 0) {
2343 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--invalid array dimensions (SDDSArray::readBinaryValues)");
2344 return(1);
2345 }
2346 if (arrayDim == NULL) {
2347 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--invalid array dimensions (SDDSArray::readBinaryValues)");
2348 return(1);
2349 }
2350 if (arrayDim[page - 1] == NULL) {
2351 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--invalid array dimensions (SDDSArray::readBinaryValues)");
2352 return(1);
2353 }
2354 p = page - 1;
2355 elementCount = (uint32_t*)SDDS_realloc(elementCount, sizeof(uint32_t) * page);
2356 elementsAllocated = (uint32_t*)SDDS_realloc(elementsAllocated, sizeof(uint32_t) * page);
2357 elementCount[p] = arrayDim[page - 1][0];
2358 for (i=1;i<arrayDimensions;i++) {
2359 elementCount[p] *= arrayDim[p][i];
2360 }
2361 elementsAllocated[p] = elementCount[p];
2362 switch (arrayType) {
2363 case SDDS_INT16:
2364 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
2365 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * elementCount[p]);
2366 if (SDDS_bufferedRead(&(int16Value[p][0]), 2 * elementCount[p], gzfp, fBuffer, sddsfile)) {
2367 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--failure reading value (SDDSArray::readBinaryValues)");
2368 return(1);
2369 }
2370 break;
2371 case SDDS_UINT16:
2372 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
2373 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * elementCount[p]);
2374 if (SDDS_bufferedRead(&(uint16Value[p][0]), 2 * elementCount[p], gzfp, fBuffer, sddsfile)) {
2375 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--failure reading value (SDDSArray::readBinaryValues)");
2376 return(1);
2377 }
2378 break;
2379 case SDDS_INT32:
2380 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
2381 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * elementCount[p]);
2382 if (SDDS_bufferedRead(&(int32Value[p][0]), 4 * elementCount[p], gzfp, fBuffer, sddsfile)) {
2383 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--failure reading value (SDDSArray::readBinaryValues)");
2384 return(1);
2385 }
2386 break;
2387 case SDDS_UINT32:
2388 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
2389 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * elementCount[p]);
2390 if (SDDS_bufferedRead(&(uint32Value[p][0]), 4 * elementCount[p], gzfp, fBuffer, sddsfile)) {
2391 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--failure reading value (SDDSArray::readBinaryValues)");
2392 return(1);
2393 }
2394 break;
2395 case SDDS_REAL32:
2396 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
2397 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * elementCount[p]);
2398 if (SDDS_bufferedRead(&(real32Value[p][0]), 4 * elementCount[p], gzfp, fBuffer, sddsfile)) {
2399 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--failure reading value (SDDSArray::readBinaryValues)");
2400 return(1);
2401 }
2402 break;
2403 case SDDS_REAL64:
2404 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
2405 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * elementCount[p]);
2406 if (SDDS_bufferedRead(&(real64Value[p][0]), 8 * elementCount[p], gzfp, fBuffer, sddsfile)) {
2407 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--failure reading value (SDDSArray::readBinaryValues)");
2408 return(1);
2409 }
2410 break;
2411 case SDDS_STRING:
2412 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
2413 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * elementCount[p]);
2414 for (i=0; i<elementCount[p]; i++) {
2415 stringValue[p][i] = NULL;
2416 if (SDDS_readBinaryString(&(stringValue[p][i]), gzfp, fBuffer, sddsfile)) {
2417 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--failure reading value (SDDSArray::readBinaryValues)");
2418 return(1);
2419 }
2420 }
2421 break;
2422 case SDDS_CHARACTER:
2423 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
2424 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * elementCount[p]);
2425 if (SDDS_bufferedRead(&(charValue[p][0]), elementCount[p], gzfp, fBuffer, sddsfile)) {
2426 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--failure reading value (SDDSArray::readBinaryValues)");
2427 return(1);
2428 }
2429 break;
2430 default:
2431 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read array--unknown type (SDDSArray::readBinaryValues)");
2432 return(1);
2433 }
2434 pageCount = page;
2435 return(0);
2436}
2437
2438/**
2439 * @brief getInteralValues
2440 *
2441 * C++ Arguments: uint32_t page
2442 *
2443 * Results: pointer to values
2444 * NULL for array value undefined
2445 */
2446void* SDDSArray::getInternalValues(uint32_t page) {
2447 uint32_t p;
2448 if ((page == 0) || (pageCount < page)) {
2449 ((SDDSFile*)sddsfile)->setError((char*)"Invalid page (SDDSArray::getInternalValues)");
2450 return(NULL);
2451 }
2452 p = page - 1;
2453 if (elementCount[p] == 0) {
2454 return(NULL);
2455 }
2456 switch (arrayType) {
2457 case SDDS_INT16:
2458 return(int16Value[p]);
2459 case SDDS_UINT16:
2460 return(uint16Value[p]);
2461 case SDDS_INT32:
2462 return(int32Value[p]);
2463 case SDDS_UINT32:
2464 return(uint32Value[p]);
2465 case SDDS_REAL32:
2466 return(real32Value[p]);
2467 case SDDS_REAL64:
2468 return(real64Value[p]);
2469 case SDDS_STRING:
2470 return(stringValue[p]);
2471 case SDDS_CHARACTER:
2472 return(charValue[p]);
2473 default:
2474 ((SDDSFile*)sddsfile)->setError((char*)"Invalid data type (SDDSArray::getInternalValues)");
2475 return(NULL);
2476 }
2477}
2478
2479/**
2480 * @brief getValuesInInt32
2481 *
2482 * C++ Arguments: uint32_t page, int32_t *errorcode
2483 *
2484 * Results: pointer to values and errorcode=0 for success
2485 * NULL and errorcode=1 for array value undefined
2486 * NULL and errorcode=2 for the case where the value cannot be
2487 * converted to the proper type
2488 * NULL and errorcode=3 for invalid array type
2489 */
2490int32_t* SDDSArray::getValuesInInt32(uint32_t page, int32_t *errorcode) {
2491 int64_t iValue;
2492 int32_t* rValues;
2493 uint32_t i, p;
2494 if ((page == 0) || (pageCount < page)) {
2495 *errorcode = 1;
2496 return((int32_t*)NULL);
2497 }
2498 *errorcode = 0;
2499 p = page - 1;
2500 if (elementCount[p] == 0) {
2501 return((int32_t*)NULL);
2502 }
2503 rValues = (int32_t*)SDDS_malloc(sizeof(int32_t) * elementCount[p]);
2504 switch (arrayType) {
2505 case SDDS_INT16:
2506 for (i=0; i<elementCount[p]; i++)
2507 rValues[i] = (int32_t)int16Value[p][i];
2508 return((int32_t*)rValues);
2509 case SDDS_UINT16:
2510 for (i=0; i<elementCount[p]; i++)
2511 rValues[i] = (int32_t)uint16Value[p][i];
2512 return((int32_t*)rValues);
2513 case SDDS_INT32:
2514 for (i=0; i<elementCount[p]; i++)
2515 rValues[i] = (int32_t)int32Value[p][i];
2516 return((int32_t*)rValues);
2517 case SDDS_UINT32:
2518 for (i=0; i<elementCount[p]; i++)
2519 rValues[i] = (int32_t)uint32Value[p][i];
2520 return((int32_t*)rValues);
2521 case SDDS_REAL32:
2522 for (i=0; i<elementCount[p]; i++)
2523 rValues[i] = (int32_t)real32Value[p][i];
2524 return((int32_t*)rValues);
2525 case SDDS_REAL64:
2526 for (i=0; i<elementCount[p]; i++)
2527 rValues[i] = (int32_t)real64Value[p][i];
2528 return((int32_t*)rValues);
2529 case SDDS_STRING:
2530 for (i=0; i<elementCount[p]; i++) {
2531 iValue = strtoll(stringValue[p][i], (char**)NULL, 10);
2532 if ((iValue == LLONG_MIN) || (iValue == LLONG_MAX)) {
2533 /*unable to convert fixed value string to integer*/
2534 *errorcode = 2;
2535 SDDS_free(rValues);
2536 return((int32_t*)NULL);
2537 }
2538 rValues[i] = (int32_t)iValue;
2539 }
2540 return((int32_t*)rValues);
2541 case SDDS_CHARACTER:
2542 for (i=0; i<elementCount[p]; i++)
2543 rValues[i] = (int32_t)charValue[p][i];
2544 return((int32_t*)rValues);
2545 default:
2546 *errorcode = 3;
2547 return((int32_t*)NULL);
2548 }
2549}
2550
2551/**
2552 * @brief getValuesInUInt32
2553 *
2554 * C++ Arguments: uint32_t page, int32_t *errorcode
2555 *
2556 * Results: pointer to values and errorcode=0 for success
2557 * NULL and errorcode=1 for array value undefined
2558 * NULL and errorcode=2 for the case where the value cannot be
2559 * converted to the proper type
2560 * NULL and errorcode=3 for invalid array type
2561 */
2562uint32_t* SDDSArray::getValuesInUInt32(uint32_t page, int32_t *errorcode) {
2563 int64_t iValue;
2564 uint32_t* rValues;
2565 uint32_t i, p;
2566 if ((page == 0) || (pageCount < page)) {
2567 *errorcode = 1;
2568 return((uint32_t*)NULL);
2569 }
2570 *errorcode = 0;
2571 p = page - 1;
2572 if (elementCount[p] == 0) {
2573 return((uint32_t*)NULL);
2574 }
2575 rValues = (uint32_t*)SDDS_malloc(sizeof(uint32_t) * elementCount[p]);
2576 switch (arrayType) {
2577 case SDDS_INT16:
2578 for (i=0; i<elementCount[p]; i++)
2579 rValues[i] = (uint32_t)int16Value[p][i];
2580 return((uint32_t*)rValues);
2581 case SDDS_UINT16:
2582 for (i=0; i<elementCount[p]; i++)
2583 rValues[i] = (uint32_t)uint16Value[p][i];
2584 return((uint32_t*)rValues);
2585 case SDDS_INT32:
2586 for (i=0; i<elementCount[p]; i++)
2587 rValues[i] = (uint32_t)int32Value[p][i];
2588 return((uint32_t*)rValues);
2589 case SDDS_UINT32:
2590 for (i=0; i<elementCount[p]; i++)
2591 rValues[i] = (uint32_t)uint32Value[p][i];
2592 return((uint32_t*)rValues);
2593 case SDDS_REAL32:
2594 for (i=0; i<elementCount[p]; i++)
2595 rValues[i] = (uint32_t)real32Value[p][i];
2596 return((uint32_t*)rValues);
2597 case SDDS_REAL64:
2598 for (i=0; i<elementCount[p]; i++)
2599 rValues[i] = (uint32_t)real64Value[p][i];
2600 return((uint32_t*)rValues);
2601 case SDDS_STRING:
2602 for (i=0; i<elementCount[p]; i++) {
2603 iValue = strtoll(stringValue[p][i], (char**)NULL, 10);
2604 if ((iValue == LLONG_MIN) || (iValue == LLONG_MAX)) {
2605 /*unable to convert fixed value string to integer*/
2606 *errorcode = 2;
2607 SDDS_free(rValues);
2608 return((uint32_t*)NULL);
2609 }
2610 rValues[i] = (uint32_t)iValue;
2611 }
2612 return((uint32_t*)rValues);
2613 case SDDS_CHARACTER:
2614 for (i=0; i<elementCount[p]; i++)
2615 rValues[i] = (uint32_t)charValue[p][i];
2616 return((uint32_t*)rValues);
2617 default:
2618 *errorcode = 3;
2619 return((uint32_t*)NULL);
2620 }
2621}
2622
2623/**
2624 * @brief getValuesInDouble
2625 *
2626 * C++ Arguments: uint32_t page, int32_t *errorcode
2627 *
2628 * Results: pointer to values and errorcode=0 for success
2629 * NULL and errorcode=1 for array value undefined
2630 * NULL and errorcode=2 for the case where the value cannot be
2631 * converted to the proper type
2632 * NULL and errorcode=3 for invalid array type
2633 */
2634double* SDDSArray::getValuesInDouble(uint32_t page, int32_t *errorcode) {
2635 double dValue;
2636 double* rValues;
2637 uint32_t i, p;
2638 if ((page == 0) || (pageCount < page)) {
2639 *errorcode = 1;
2640 return((double*)NULL);
2641 }
2642 *errorcode = 0;
2643 p = page - 1;
2644 if (elementCount[p] == 0) {
2645 return((double*)NULL);
2646 }
2647 rValues = (double*)SDDS_malloc(sizeof(double) * elementCount[p]);
2648 switch (arrayType) {
2649 case SDDS_INT16:
2650 for (i=0; i<elementCount[p]; i++)
2651 rValues[i] = (double)int16Value[p][i];
2652 return((double*)rValues);
2653 case SDDS_UINT16:
2654 for (i=0; i<elementCount[p]; i++)
2655 rValues[i] = (double)uint16Value[p][i];
2656 return((double*)rValues);
2657 case SDDS_INT32:
2658 for (i=0; i<elementCount[p]; i++)
2659 rValues[i] = (double)int32Value[p][i];
2660 return((double*)rValues);
2661 case SDDS_UINT32:
2662 for (i=0; i<elementCount[p]; i++)
2663 rValues[i] = (double)uint32Value[p][i];
2664 return((double*)rValues);
2665 case SDDS_REAL32:
2666 for (i=0; i<elementCount[p]; i++)
2667 rValues[i] = (double)real32Value[p][i];
2668 return((double*)rValues);
2669 case SDDS_REAL64:
2670 for (i=0; i<elementCount[p]; i++)
2671 rValues[i] = (double)real64Value[p][i];
2672 return((double*)rValues);
2673 case SDDS_STRING:
2674 for (i=0; i<elementCount[p]; i++) {
2675 dValue = strtod(stringValue[p][i], (char**)NULL);
2676 if ((dValue == HUGE_VAL) || (dValue == -HUGE_VAL)) {
2677 /*unable to convert string to floating point*/
2678 *errorcode = 2;
2679 SDDS_free(rValues);
2680 return((double*)NULL);
2681 }
2682 rValues[i] = (double)dValue;
2683 }
2684 return((double*)rValues);
2685 case SDDS_CHARACTER:
2686 for (i=0; i<elementCount[p]; i++)
2687 rValues[i] = (double)charValue[p][i];
2688 return((double*)rValues);
2689 default:
2690 *errorcode = 3;
2691 return((double*)NULL);
2692 }
2693}
2694
2695/**
2696 * @brief getValuesInString
2697 *
2698 * C++ Arguments: uint32_t page, int32_t *errorcode
2699 *
2700 * Results: pointer to values and errorcode=0 for success
2701 * NULL and errorcode=1 for array value undefined
2702 * NULL and errorcode=2 for the case where the value cannot be
2703 * converted to the proper type
2704 * NULL and errorcode=3 for invalid array type
2705 */
2706char** SDDSArray::getValuesInString(uint32_t page, int32_t *errorcode) {
2707 char** rValues;
2708 uint32_t i, p;
2709 char s[SDDS_MAXLINE];
2710 if ((page == 0) || (pageCount < page)) {
2711 *errorcode = 1;
2712 return((char**)NULL);
2713 }
2714 *errorcode = 0;
2715 p = page - 1;
2716 if (elementCount[p] == 0) {
2717 return((char**)NULL);
2718 }
2719 rValues = (char**)SDDS_malloc(sizeof(char*) * elementCount[p]);
2720 switch (arrayType) {
2721 case SDDS_INT16:
2722 for (i=0; i<elementCount[p]; i++) {
2723 sprintf(s, "%" PRId16, int16Value[p][i]);
2724 rValues[i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
2725 strcpy(rValues[i], s);
2726 }
2727 return((char**)rValues);
2728 case SDDS_UINT16:
2729 for (i=0; i<elementCount[p]; i++) {
2730 sprintf(s, "%" PRIu16, uint16Value[p][i]);
2731 rValues[i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
2732 strcpy(rValues[i], s);
2733 }
2734 return((char**)rValues);
2735 case SDDS_INT32:
2736 for (i=0; i<elementCount[p]; i++) {
2737 sprintf(s, "%" PRId32, int32Value[p][i]);
2738 rValues[i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
2739 strcpy(rValues[i], s);
2740 }
2741 return((char**)rValues);
2742 case SDDS_UINT32:
2743 for (i=0; i<elementCount[p]; i++) {
2744 sprintf(s, "%" PRIu32, uint32Value[p][i]);
2745 rValues[i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
2746 strcpy(rValues[i], s);
2747 }
2748 return((char**)rValues);
2749 case SDDS_REAL32:
2750 for (i=0; i<elementCount[p]; i++) {
2751 sprintf(s, "%f", real32Value[p][i]);
2752 rValues[i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
2753 strcpy(rValues[i], s);
2754 }
2755 return((char**)rValues);
2756 case SDDS_REAL64:
2757 for (i=0; i<elementCount[p]; i++) {
2758 sprintf(s, "%lf", real64Value[p][i]);
2759 rValues[i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
2760 strcpy(rValues[i], s);
2761 }
2762 return((char**)rValues);
2763 case SDDS_STRING:
2764 for (i=0; i<elementCount[p]; i++) {
2765 rValues[i] = (char*)SDDS_malloc(sizeof(char) * strlen(stringValue[p][i]) + 1);
2766 strcpy(rValues[i], stringValue[p][i]);
2767 }
2768 return((char**)rValues);
2769 case SDDS_CHARACTER:
2770 for (i=0; i<elementCount[p]; i++) {
2771 sprintf(s, "%c", charValue[p][i]);
2772 rValues[i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
2773 strcpy(rValues[i], s);
2774 }
2775 return((char**)rValues);
2776 default:
2777 *errorcode = 3;
2778 return((char**)NULL);
2779 }
2780}
2781
2782/**
2783 * @brief writeAsciiValues
2784 *
2785 * C++ Arguments: FILE *fp, uint32_t page
2786 * C++ Arguments: voidp *gzfp, uint32_t page
2787 *
2788 * Results: 0 on success
2789 * 1 on failure
2790 */
2791int32_t SDDSArray::writeAsciiValues(FILE *fp, uint32_t page) {
2792 char c;
2793 char *s;
2794 int32_t hasWhitespace;
2795 uint32_t i;
2796
2797 if ((page == 0) || (page > pageCount)) {
2798 return(1);
2799 }
2800 page--;
2801 switch (arrayType) {
2802 case SDDS_INT16:
2803 for (i=0; i<elementCount[page]; i++) {
2804 fprintf(fp, "%" PRId16 " ", int16Value[page][i]);
2805 }
2806 break;
2807 case SDDS_UINT16:
2808 for (i=0; i<elementCount[page]; i++) {
2809 fprintf(fp, "%" PRIu16 " ", uint16Value[page][i]);
2810 }
2811 break;
2812 case SDDS_INT32:
2813 for (i=0; i<elementCount[page]; i++) {
2814 fprintf(fp, "%" PRId32 " ", int32Value[page][i]);
2815 }
2816 break;
2817 case SDDS_UINT32:
2818 for (i=0; i<elementCount[page]; i++) {
2819 fprintf(fp, "%" PRIu32 " ", uint32Value[page][i]);
2820 }
2821 break;
2822 case SDDS_REAL32:
2823 for (i=0; i<elementCount[page]; i++) {
2824 fprintf(fp, "%.*g ", FLT_DIG, real32Value[page][i]);
2825 }
2826 break;
2827 case SDDS_REAL64:
2828 for (i=0; i<elementCount[page]; i++) {
2829 fprintf(fp, "%.*g ", DBL_DIG, real64Value[page][i]);
2830 }
2831 break;
2832 case SDDS_STRING:
2833 for (i=0; i<elementCount[page]; i++) {
2834 s = stringValue[page][i];
2835 hasWhitespace=0;
2836 if (SDDS_hasWhitespace(s) || SDDS_stringIsBlank(s)) {
2837 fputc('"', fp);
2838 hasWhitespace = 1;
2839 }
2840 while (s && *s) {
2841 c = *s++;
2842 if (c=='!') {
2843 fputs("\\!", fp);
2844 } else if (c=='\\') {
2845 fputs("\\\\", fp);
2846 } else if (c=='"') {
2847 fputs("\\\"", fp);
2848 } else if (c==' ') {
2849 fputc(' ', fp); /* don't escape plain spaces */
2850 } else if (isspace(c) || !isprint(c)) {
2851 fprintf(fp, "\\%03o", c);
2852 } else {
2853 fputc(c, fp);
2854 }
2855 }
2856 if (hasWhitespace) {
2857 fputc('"', fp);
2858 }
2859 fputc(' ', fp);
2860 }
2861 break;
2862 case SDDS_CHARACTER:
2863 for (i=0; i<elementCount[page]; i++) {
2864 c = charValue[page][i];
2865 if (c=='!')
2866 fputs("\\!", fp);
2867 else if (c=='\\')
2868 fputs("\\\\", fp);
2869 else if (c=='"')
2870 fputs("\\\"", fp);
2871 else if (!c || isspace(c) || !isprint(c))
2872 fprintf(fp, "\\%03o", c);
2873 else
2874 fputc(c, fp);
2875 fputc(' ', fp);
2876 }
2877 break;
2878 default:
2879 return(1);
2880 }
2881 fprintf(fp, "\n");
2882 return(0);
2883}
2884
2885int32_t SDDSArray::writeAsciiValues(voidp *gzfp, uint32_t page) {
2886 char c;
2887 char *s;
2888 int32_t hasWhitespace;
2889 uint32_t i;
2890
2891 if ((page == 0) || (page > pageCount)) {
2892 return(1);
2893 }
2894 page--;
2895 switch (arrayType) {
2896 case SDDS_INT16:
2897 for (i=0; i<elementCount[page]; i++) {
2898 gzprintf(gzfp, "%" PRId16 " ", int16Value[page][i]);
2899 }
2900 break;
2901 case SDDS_UINT16:
2902 for (i=0; i<elementCount[page]; i++) {
2903 gzprintf(gzfp, "%" PRIu16 " ", uint16Value[page][i]);
2904 }
2905 break;
2906 case SDDS_INT32:
2907 for (i=0; i<elementCount[page]; i++) {
2908 gzprintf(gzfp, "%" PRId32 " ", int32Value[page][i]);
2909 }
2910 break;
2911 case SDDS_UINT32:
2912 for (i=0; i<elementCount[page]; i++) {
2913 gzprintf(gzfp, "%" PRIu32 " ", uint32Value[page][i]);
2914 }
2915 break;
2916 case SDDS_REAL32:
2917 for (i=0; i<elementCount[page]; i++) {
2918 gzprintf(gzfp, "%.*g ", FLT_DIG, real32Value[page][i]);
2919 }
2920 break;
2921 case SDDS_REAL64:
2922 for (i=0; i<elementCount[page]; i++) {
2923 gzprintf(gzfp, "%.*g ", DBL_DIG, real64Value[page][i]);
2924 }
2925 break;
2926 case SDDS_STRING:
2927 for (i=0; i<elementCount[page]; i++) {
2928 s = stringValue[page][i];
2929 hasWhitespace=0;
2930 if (SDDS_hasWhitespace(s) || SDDS_stringIsBlank(s)) {
2931 gzputc(gzfp, '"');
2932 hasWhitespace = 1;
2933 }
2934 while (s && *s) {
2935 c = *s++;
2936 if (c=='!') {
2937 gzputs(gzfp, "\\!");
2938 } else if (c=='\\') {
2939 gzputs(gzfp, "\\\\");
2940 } else if (c=='"') {
2941 gzputs(gzfp, "\\\"");
2942 } else if (c==' ') {
2943 gzputc(gzfp, ' '); /* don't escape plain spaces */
2944 } else if (isspace(c) || !isprint(c)) {
2945 gzprintf(gzfp, "\\%03o", c);
2946 } else {
2947 gzputc(gzfp, c);
2948 }
2949 }
2950 if (hasWhitespace) {
2951 gzputc(gzfp, '"');
2952 }
2953 gzputc(gzfp, ' ');
2954 }
2955 break;
2956 case SDDS_CHARACTER:
2957 for (i=0; i<elementCount[page]; i++) {
2958 c = charValue[page][i];
2959 if (c=='!')
2960 gzputs(gzfp, "\\!");
2961 else if (c=='\\')
2962 gzputs(gzfp, "\\\\");
2963 else if (c=='"')
2964 gzputs(gzfp, "\\\"");
2965 else if (!c || isspace(c) || !isprint(c))
2966 gzprintf(gzfp, "\\%03o", c);
2967 else
2968 gzputc(gzfp, c);
2969 gzputc(gzfp, ' ');
2970 }
2971 break;
2972 default:
2973 return(1);
2974 }
2975 gzprintf(gzfp, "\n");
2976 return(0);
2977}
2978
2979/**
2980 * @brief writeBinaryValues
2981 *
2982 * C++ Arguments: FILE *fp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian
2983 * C++ Arguments: voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian
2984 *
2985 * Results: 0 on success
2986 * 1 on failure
2987 */
2988int32_t SDDSArray::writeBinaryValues(FILE *fp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian) {
2989 uint32_t i;
2990 if ((page == 0) || (page > pageCount)) {
2991 return(1);
2992 }
2993 page--;
2994 switch (arrayType) {
2995 case SDDS_INT16:
2996 if (SDDS_bufferedWrite(&(int16Value[page][0]), 2 * elementCount[page], fp, fBuffer, sddsfile)) {
2997 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--failure writing value (SDDSArray::writeBinaryValues)");
2998 return(1);
2999 }
3000 break;
3001 case SDDS_UINT16:
3002 if (SDDS_bufferedWrite(&(uint16Value[page][0]), 2 * elementCount[page], fp, fBuffer, sddsfile)) {
3003 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--failure writing value (SDDSArray::writeBinaryValues)");
3004 return(1);
3005 }
3006 break;
3007 case SDDS_INT32:
3008 if (SDDS_bufferedWrite(&(int32Value[page][0]), 4 * elementCount[page], fp, fBuffer, sddsfile)) {
3009 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--failure writing value (SDDSArray::writeBinaryValues)");
3010 return(1);
3011 }
3012 break;
3013 case SDDS_UINT32:
3014 if (SDDS_bufferedWrite(&(uint32Value[page][0]), 4 * elementCount[page], fp, fBuffer, sddsfile)) {
3015 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--failure writing value (SDDSArray::writeBinaryValues)");
3016 return(1);
3017 }
3018 break;
3019 case SDDS_REAL32:
3020 if (SDDS_bufferedWrite(&(real32Value[page][0]), 4 * elementCount[page], fp, fBuffer, sddsfile)) {
3021 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--failure writing value (SDDSArray::writeBinaryValues)");
3022 return(1);
3023 }
3024 break;
3025 case SDDS_REAL64:
3026 if (SDDS_bufferedWrite(&(real64Value[page][0]), 8 * elementCount[page], fp, fBuffer, sddsfile)) {
3027 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--failure writing value (SDDSArray::writeBinaryValues)");
3028 return(1);
3029 }
3030 break;
3031 case SDDS_STRING:
3032 for (i=0; i<elementCount[page]; i++) {
3033 if (SDDS_writeBinaryString(stringValue[page][i], fp, fBuffer, sddsfile)) {
3034 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--failure writing string (SDDSArray::writeBinaryValues)");
3035 return(1);
3036 }
3037 }
3038 break;
3039 case SDDS_CHARACTER:
3040 if (SDDS_bufferedWrite(&(charValue[page][0]), elementCount[page], fp, fBuffer, sddsfile)) {
3041 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--failure writing value (SDDSArray::writeBinaryValues)");
3042 return(1);
3043 }
3044 break;
3045 default:
3046 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--unknown type (SDDSArray::writeBinaryValues)");
3047 return(1);
3048 }
3049 return(0);
3050}
3051
3052int32_t SDDSArray::writeBinaryValues(voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian) {
3053 uint32_t i;
3054 if ((page == 0) || (page > pageCount)) {
3055 return(1);
3056 }
3057 page--;
3058 switch (arrayType) {
3059 case SDDS_INT16:
3060 if (SDDS_bufferedWrite(&(int16Value[page][0]), 2 * elementCount[page], gzfp, fBuffer, sddsfile)) {
3061 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--failure writing value (SDDSArray::writeBinaryValues)");
3062 return(1);
3063 }
3064 break;
3065 case SDDS_UINT16:
3066 if (SDDS_bufferedWrite(&(uint16Value[page][0]), 2 * elementCount[page], gzfp, fBuffer, sddsfile)) {
3067 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--failure writing value (SDDSArray::writeBinaryValues)");
3068 return(1);
3069 }
3070 break;
3071 case SDDS_INT32:
3072 if (SDDS_bufferedWrite(&(int32Value[page][0]), 4 * elementCount[page], gzfp, fBuffer, sddsfile)) {
3073 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--failure writing value (SDDSArray::writeBinaryValues)");
3074 return(1);
3075 }
3076 break;
3077 case SDDS_UINT32:
3078 if (SDDS_bufferedWrite(&(uint32Value[page][0]), 4 * elementCount[page], gzfp, fBuffer, sddsfile)) {
3079 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--failure writing value (SDDSArray::writeBinaryValues)");
3080 return(1);
3081 }
3082 break;
3083 case SDDS_REAL32:
3084 if (SDDS_bufferedWrite(&(real32Value[page][0]), 4 * elementCount[page], gzfp, fBuffer, sddsfile)) {
3085 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--failure writing value (SDDSArray::writeBinaryValues)");
3086 return(1);
3087 }
3088 break;
3089 case SDDS_REAL64:
3090 if (SDDS_bufferedWrite(&(real64Value[page][0]), 8 * elementCount[page], gzfp, fBuffer, sddsfile)) {
3091 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--failure writing value (SDDSArray::writeBinaryValues)");
3092 return(1);
3093 }
3094 break;
3095 case SDDS_STRING:
3096 for (i=0; i<elementCount[page]; i++) {
3097 if (SDDS_writeBinaryString(stringValue[page][i], gzfp, fBuffer, sddsfile)) {
3098 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--failure writing string (SDDSArray::writeBinaryValues)");
3099 return(1);
3100 }
3101 }
3102 break;
3103 case SDDS_CHARACTER:
3104 if (SDDS_bufferedWrite(&(charValue[page][0]), elementCount[page], gzfp, fBuffer, sddsfile)) {
3105 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--failure writing value (SDDSArray::writeBinaryValues)");
3106 return(1);
3107 }
3108 break;
3109 default:
3110 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write array--unknown type (SDDSArray::writeBinaryValues)");
3111 return(1);
3112 }
3113 return(0);
3114}
#define SDDS_NUM_TYPES
Total number of defined SDDS data types.
Definition SDDStypes.h:97
#define SDDS_INTEGER_TYPE(type)
Checks if the given type identifier corresponds to an integer type.
Definition SDDStypes.h:109
#define SDDS_STRING
Identifier for the string data type.
Definition SDDStypes.h:85
#define SDDS_FLOATING_TYPE(type)
Checks if the given type identifier corresponds to a floating-point type.
Definition SDDStypes.h:124
#define SDDS_CHARACTER
Identifier for the character data type.
Definition SDDStypes.h:91