45SDDSArray::SDDSArray() {
48 elementsAllocated = NULL;
49 elementAllocationIncrement = 10;
54 arrayDescription = NULL;
55 arrayFormatString = NULL;
56 arrayGroupName = NULL;
79SDDSArray::~SDDSArray() {
81 if (arrayName != NULL)
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]);
102 if (int16Value != NULL) {
103 for (i=0; i<pageCount; i++) {
104 if (int16Value[i] != NULL) {
105 SDDS_free(int16Value[i]);
108 SDDS_free(int16Value);
110 if (uint16Value != NULL) {
111 for (i=0; i<pageCount; i++) {
112 if (uint16Value[i] != NULL) {
113 SDDS_free(uint16Value[i]);
116 SDDS_free(uint16Value);
118 if (int32Value != NULL) {
119 for (i=0; i<pageCount; i++) {
120 if (int32Value[i] != NULL) {
121 SDDS_free(int32Value[i]);
124 SDDS_free(int32Value);
126 if (uint32Value != NULL) {
127 for (i=0; i<pageCount; i++) {
128 if (uint32Value[i] != NULL) {
129 SDDS_free(uint32Value[i]);
132 SDDS_free(uint32Value);
134 if (real32Value != NULL) {
135 for (i=0; i<pageCount; i++) {
136 if (real32Value[i] != NULL) {
137 SDDS_free(real32Value[i]);
140 SDDS_free(real32Value);
142 if (real64Value != NULL) {
143 for (i=0; i<pageCount; i++) {
144 if (real64Value[i] != NULL) {
145 SDDS_free(real64Value[i]);
148 SDDS_free(real64Value);
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]);
158 SDDS_free(stringValue[i]);
161 SDDS_free(stringValue);
163 if (charValue != NULL) {
164 for (i=0; i<pageCount; i++) {
165 if (charValue[i] != NULL) {
166 SDDS_free(charValue[i]);
169 SDDS_free(charValue);
171 if (elementCount != NULL) {
172 SDDS_free(elementCount);
174 if (elementsAllocated != NULL) {
175 SDDS_free(elementsAllocated);
186void SDDSArray::freePage() {
190 if (int16Value != NULL) {
191 for (i=0; i<pageCount; i++) {
192 if (int16Value[i] != NULL) {
193 SDDS_free(int16Value[i]);
196 SDDS_free(int16Value);
201 if (uint16Value != NULL) {
202 for (i=0; i<pageCount; i++) {
203 if (uint16Value[i] != NULL) {
204 SDDS_free(uint16Value[i]);
207 SDDS_free(uint16Value);
212 if (int32Value != NULL) {
213 for (i=0; i<pageCount; i++) {
214 if (int32Value[i] != NULL) {
215 SDDS_free(int32Value[i]);
218 SDDS_free(int32Value);
223 if (uint32Value != NULL) {
224 for (i=0; i<pageCount; i++) {
225 if (uint32Value[i] != NULL) {
226 SDDS_free(uint32Value[i]);
229 SDDS_free(uint32Value);
234 if (real32Value != NULL) {
235 for (i=0; i<pageCount; i++) {
236 if (real32Value[i] != NULL) {
237 SDDS_free(real32Value[i]);
240 SDDS_free(real32Value);
245 if (real64Value != NULL) {
246 for (i=0; i<pageCount; i++) {
247 if (real64Value[i] != NULL) {
248 SDDS_free(real64Value[i]);
251 SDDS_free(real64Value);
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]);
264 SDDS_free(stringValue[i]);
267 SDDS_free(stringValue);
272 if (charValue != NULL) {
273 for (i=0; i<pageCount; i++) {
274 if (charValue[i] != NULL) {
275 SDDS_free(charValue[i]);
278 SDDS_free(charValue);
285 if (arrayDim != NULL) {
286 for (i=0; i<pageCount; i++) {
287 if (arrayDim[i] != NULL) {
288 SDDS_free(arrayDim[i]);
294 if (elementCount != NULL) {
295 SDDS_free(elementCount);
298 if (elementsAllocated != NULL) {
299 SDDS_free(elementsAllocated);
300 elementsAllocated = NULL;
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);
331 arrayName = (
char*)SDDS_malloc(
sizeof(
char) * strlen(name) + 1);
332 strcpy(arrayName, name);
337 arraySymbol = (
char*)SDDS_malloc(
sizeof(
char) * strlen(symbol) + 1);
338 strcpy(arraySymbol, symbol);
343 arrayUnits = (
char*)SDDS_malloc(
sizeof(
char) * strlen(units) + 1);
344 strcpy(arrayUnits, units);
346 if (description == NULL)
347 arrayDescription = NULL;
349 arrayDescription = (
char*)SDDS_malloc(
sizeof(
char) * strlen(description) + 1);
350 strcpy(arrayDescription, description);
352 if (format_string == NULL)
353 arrayFormatString = NULL;
355 arrayFormatString = (
char*)SDDS_malloc(
sizeof(
char) * strlen(format_string) + 1);
356 strcpy(arrayFormatString, format_string);
358 if (group_name == NULL)
359 arrayGroupName = NULL;
361 arrayGroupName = (
char*)SDDS_malloc(
sizeof(
char) * strlen(group_name) + 1);
362 strcpy(arrayGroupName, group_name);
365 arrayFieldLength = field_length;
366 arrayDimensions = dimensions;
376void SDDSArray::informAboutParent(
void *parent) {
387char* SDDSArray::getName() {
398void SDDSArray::setName(
char *name) {
399 if (arrayName != NULL)
400 SDDS_free(arrayName);
404 arrayName = (
char*)SDDS_malloc(
sizeof(
char) * strlen(name) + 1);
405 strcpy(arrayName, name);
416char* SDDSArray::getSymbol() {
427void SDDSArray::setSymbol(
char *symbol) {
428 if (arraySymbol != NULL)
429 SDDS_free(arraySymbol);
433 arraySymbol = (
char*)SDDS_malloc(
sizeof(
char) * strlen(symbol) + 1);
434 strcpy(arraySymbol, symbol);
445char* SDDSArray::getUnits() {
456void SDDSArray::setUnits(
char *units) {
457 if (arrayUnits != NULL)
458 SDDS_free(arrayUnits);
462 arrayUnits = (
char*)SDDS_malloc(
sizeof(
char) * strlen(units) + 1);
463 strcpy(arrayUnits, units);
474char* SDDSArray::getDescription() {
475 return(arrayDescription);
485void SDDSArray::setDescription(
char *description) {
486 if (arrayDescription != NULL)
487 SDDS_free(arrayDescription);
488 if (description == NULL)
489 arrayDescription = NULL;
491 arrayDescription = (
char*)SDDS_malloc(
sizeof(
char) * strlen(description) + 1);
492 strcpy(arrayDescription, description);
503char* SDDSArray::getFormatString() {
504 return(arrayFormatString);
514void SDDSArray::setFormatString(
char *format_string) {
515 if (arrayFormatString != NULL)
516 SDDS_free(arrayFormatString);
517 if (format_string == NULL)
518 arrayFormatString = NULL;
520 arrayFormatString = (
char*)SDDS_malloc(
sizeof(
char) * strlen(format_string) + 1);
521 strcpy(arrayFormatString, format_string);
532char* SDDSArray::getGroupName() {
533 return(arrayGroupName);
543void SDDSArray::setGroupName(
char *group_name) {
544 if (arrayGroupName != NULL)
545 SDDS_free(arrayGroupName);
546 if (group_name == NULL)
547 arrayGroupName = NULL;
549 arrayGroupName = (
char*)SDDS_malloc(
sizeof(
char) * strlen(group_name) + 1);
550 strcpy(arrayGroupName, group_name);
561int32_t SDDSArray::getType() {
572void SDDSArray::setType(int32_t type) {
583uint32_t SDDSArray::getFieldLength() {
584 return(arrayFieldLength);
594void SDDSArray::setFieldLength(uint32_t field_length) {
595 arrayFieldLength = field_length;
605uint32_t SDDSArray::getDimensions() {
606 return(arrayDimensions);
616void SDDSArray::setDimensions(uint32_t dimensions) {
617 arrayDimensions = dimensions;
627uint32_t* SDDSArray::getDim(uint32_t page) {
628 if (page > pageCount)
630 if (arrayDim == NULL)
632 if (arrayDim[page-1] == NULL)
634 return arrayDim[page-1];
644void SDDSArray::setDim(uint32_t page, uint32_t *dimensions) {
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];
665uint32_t SDDSArray::getPageCount() {
678int32_t SDDSArray::writeDefinition(FILE *fp) {
685 fputs(
"&array ", fp);
686 if (SDDS_printNamelistField(fp, (
char*)
"name", arrayName)) {
689 if (SDDS_printNamelistField(fp, (
char*)
"symbol", SDDS_blankToNull(arraySymbol))) {
692 if (SDDS_printNamelistField(fp, (
char*)
"units", SDDS_blankToNull(arrayUnits))) {
695 if (SDDS_printNamelistField(fp, (
char*)
"description", SDDS_blankToNull(arrayDescription))) {
698 if (SDDS_printNamelistField(fp, (
char*)
"format_string", SDDS_blankToNull(arrayFormatString))) {
701 if (SDDS_printNamelistField(fp, (
char*)
"group_name", SDDS_blankToNull(arrayGroupName))) {
704 if (((SDDSFile*)sddsfile)->layoutVersion == 1) {
705 if (SDDS_printNamelistField(fp, (
char*)
"type", SDDS_getVer1TypeName(arrayType))) {
708 }
else if (((SDDSFile*)sddsfile)->layoutVersion == 2) {
709 if (SDDS_printNamelistField(fp, (
char*)
"type", SDDS_getVer2TypeName(arrayType))) {
713 if (SDDS_printNamelistField(fp, (
char*)
"type", SDDS_getTypeName(arrayType))) {
717 fprintf(fp,
"dimensions=%" PRIu32
", ", arrayDimensions);
722int32_t SDDSArray::writeDefinition(voidp *gzfp) {
729 gzputs(gzfp,
"&array ");
730 if (SDDS_printNamelistField(gzfp, (
char*)
"name", arrayName)) {
733 if (SDDS_printNamelistField(gzfp, (
char*)
"symbol", SDDS_blankToNull(arraySymbol))) {
736 if (SDDS_printNamelistField(gzfp, (
char*)
"units", SDDS_blankToNull(arrayUnits))) {
739 if (SDDS_printNamelistField(gzfp, (
char*)
"description", SDDS_blankToNull(arrayDescription))) {
742 if (SDDS_printNamelistField(gzfp, (
char*)
"format_string", SDDS_blankToNull(arrayFormatString))) {
745 if (SDDS_printNamelistField(gzfp, (
char*)
"group_name", SDDS_blankToNull(arrayGroupName))) {
748 if (((SDDSFile*)sddsfile)->layoutVersion == 1) {
749 if (SDDS_printNamelistField(gzfp, (
char*)
"type", SDDS_getVer1TypeName(arrayType))) {
752 }
else if (((SDDSFile*)sddsfile)->layoutVersion == 2) {
753 if (SDDS_printNamelistField(gzfp, (
char*)
"type", SDDS_getVer2TypeName(arrayType))) {
757 if (SDDS_printNamelistField(gzfp, (
char*)
"type", SDDS_getTypeName(arrayType))) {
761 gzprintf(gzfp,
"dimensions=%" PRIu32
", ", arrayDimensions);
762 gzputs(gzfp,
"&end\n");
783int32_t SDDSArray::setValues(int16_t *values, uint32_t page, uint32_t elements) {
786 char s[SDDS_MAXLINE];
789 if (page > pageCount) {
791 n = page - pageCount;
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;
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;
810 if (elements > elementsAllocated[p]) {
811 elementsAllocated[p] = elements + elementAllocationIncrement;
812 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p],
sizeof(int16_t) * elementsAllocated[p]);
814 memcpy(int16Value[p], values, elements * 2);
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;
823 if (elements > elementsAllocated[p]) {
824 elementsAllocated[p] = elements + elementAllocationIncrement;
825 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p],
sizeof(uint16_t) * elementsAllocated[p]);
827 for (i=0; i<elements; i++) {
828 uint16Value[p][i] = (uint16_t)(values[i]);
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;
838 if (elements > elementsAllocated[p]) {
839 elementsAllocated[p] = elements + elementAllocationIncrement;
840 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p],
sizeof(int32_t) * elementsAllocated[p]);
842 for (i=0; i<elements; i++) {
843 int32Value[p][i] = (int32_t)(values[i]);
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;
853 if (elements > elementsAllocated[p]) {
854 elementsAllocated[p] = elements + elementAllocationIncrement;
855 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p],
sizeof(uint32_t) * elementsAllocated[p]);
857 for (i=0; i<elements; i++) {
858 uint32Value[p][i] = (uint32_t)(values[i]);
863 real32Value = (
float**)SDDS_realloc(real32Value,
sizeof(
float*) * page);
864 for (i=0; i<n; i++) {
865 real32Value[p - i] = (
float*)NULL;
868 if (elements > elementsAllocated[p]) {
869 elementsAllocated[p] = elements + elementAllocationIncrement;
870 real32Value[p] = (
float*)SDDS_realloc(real32Value[p],
sizeof(
float) * elementsAllocated[p]);
872 for (i=0; i<elements; i++) {
873 real32Value[p][i] = (float)(values[i]);
878 real64Value = (
double**)SDDS_realloc(real64Value,
sizeof(
double*) * page);
879 for (i=0; i<n; i++) {
880 real64Value[p - i] = (
double*)NULL;
883 if (elements > elementsAllocated[p]) {
884 elementsAllocated[p] = elements + elementAllocationIncrement;
885 real64Value[p] = (
double*)SDDS_realloc(real64Value[p],
sizeof(
double) * elementsAllocated[p]);
887 for (i=0; i<elements; i++) {
888 real64Value[p][i] = (double)(values[i]);
893 stringValue = (
char***)SDDS_realloc(stringValue,
sizeof(
char**) * page);
894 for (i=0; i<n; i++) {
895 stringValue[p - i] = NULL;
898 if (elements > elementsAllocated[p]) {
899 elementsAllocated[p] = elements + elementAllocationIncrement;
900 stringValue[p] = (
char**)SDDS_realloc(stringValue[p],
sizeof(
char*) * elementsAllocated[p]);
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);
910 charValue = (
char**)SDDS_realloc(charValue,
sizeof(
char*) * page);
911 for (i=0; i<n; i++) {
912 charValue[p - i] = NULL;
915 if (elements > elementsAllocated[p]) {
916 elementsAllocated[p] = elements + elementAllocationIncrement;
917 charValue[p] = (
char*)SDDS_realloc(charValue[p],
sizeof(
char) * elementsAllocated[p]);
919 for (i=0; i<elements; i++) {
920 charValue[p][i] = (char)(values[i]);
928 if (elementCount[p] < elements) {
929 elementCount[p] = elements;
934int32_t SDDSArray::setValues(uint16_t *values, uint32_t page, uint32_t elements) {
937 char s[SDDS_MAXLINE];
940 if (page > pageCount) {
942 n = page - pageCount;
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;
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;
961 if (elements > elementsAllocated[p]) {
962 elementsAllocated[p] = elements + elementAllocationIncrement;
963 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p],
sizeof(int16_t) * elementsAllocated[p]);
965 for (i=0; i<elements; i++) {
966 int16Value[p][i] = (int16_t)(values[i]);
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;
976 if (elements > elementsAllocated[p]) {
977 elementsAllocated[p] = elements + elementAllocationIncrement;
978 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p],
sizeof(uint16_t) * elementsAllocated[p]);
980 memcpy(uint16Value[p], values, elements * 2);
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;
989 if (elements > elementsAllocated[p]) {
990 elementsAllocated[p] = elements + elementAllocationIncrement;
991 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p],
sizeof(int32_t) * elementsAllocated[p]);
993 for (i=0; i<elements; i++) {
994 int32Value[p][i] = (int32_t)(values[i]);
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;
1004 if (elements > elementsAllocated[p]) {
1005 elementsAllocated[p] = elements + elementAllocationIncrement;
1006 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p],
sizeof(uint32_t) * elementsAllocated[p]);
1008 for (i=0; i<elements; i++) {
1009 uint32Value[p][i] = (uint32_t)(values[i]);
1014 real32Value = (
float**)SDDS_realloc(real32Value,
sizeof(
float*) * page);
1015 for (i=0; i<n; i++) {
1016 real32Value[p - i] = (
float*)NULL;
1019 if (elements > elementsAllocated[p]) {
1020 elementsAllocated[p] = elements + elementAllocationIncrement;
1021 real32Value[p] = (
float*)SDDS_realloc(real32Value[p],
sizeof(
float) * elementsAllocated[p]);
1023 for (i=0; i<elements; i++) {
1024 real32Value[p][i] = (float)(values[i]);
1029 real64Value = (
double**)SDDS_realloc(real64Value,
sizeof(
double*) * page);
1030 for (i=0; i<n; i++) {
1031 real64Value[p - i] = (
double*)NULL;
1034 if (elements > elementsAllocated[p]) {
1035 elementsAllocated[p] = elements + elementAllocationIncrement;
1036 real64Value[p] = (
double*)SDDS_realloc(real64Value[p],
sizeof(
double) * elementsAllocated[p]);
1038 for (i=0; i<elements; i++) {
1039 real64Value[p][i] = (double)(values[i]);
1044 stringValue = (
char***)SDDS_realloc(stringValue,
sizeof(
char**) * page);
1045 for (i=0; i<n; i++) {
1046 stringValue[p - i] = NULL;
1049 if (elements > elementsAllocated[p]) {
1050 elementsAllocated[p] = elements + elementAllocationIncrement;
1051 stringValue[p] = (
char**)SDDS_realloc(stringValue[p],
sizeof(
char*) * elementsAllocated[p]);
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);
1061 charValue = (
char**)SDDS_realloc(charValue,
sizeof(
char*) * page);
1062 for (i=0; i<n; i++) {
1063 charValue[p - i] = NULL;
1066 if (elements > elementsAllocated[p]) {
1067 elementsAllocated[p] = elements + elementAllocationIncrement;
1068 charValue[p] = (
char*)SDDS_realloc(charValue[p],
sizeof(
char) * elementsAllocated[p]);
1070 for (i=0; i<elements; i++) {
1071 charValue[p][i] = (char)(values[i]);
1079 if (elementCount[p] < elements) {
1080 elementCount[p] = elements;
1085int32_t SDDSArray::setValues(int32_t *values, uint32_t page, uint32_t elements) {
1088 char s[SDDS_MAXLINE];
1091 if (page > pageCount) {
1093 n = page - pageCount;
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;
1104 switch (arrayType) {
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;
1112 if (elements > elementsAllocated[p]) {
1113 elementsAllocated[p] = elements + elementAllocationIncrement;
1114 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p],
sizeof(int16_t) * elementsAllocated[p]);
1116 for (i=0; i<elements; i++) {
1117 int16Value[p][i] = (int16_t)(values[i]);
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;
1127 if (elements > elementsAllocated[p]) {
1128 elementsAllocated[p] = elements + elementAllocationIncrement;
1129 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p],
sizeof(uint16_t) * elementsAllocated[p]);
1131 for (i=0; i<elements; i++) {
1132 uint16Value[p][i] = (int16_t)(values[i]);
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;
1142 if (elements > elementsAllocated[p]) {
1143 elementsAllocated[p] = elements + elementAllocationIncrement;
1144 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p],
sizeof(int32_t) * elementsAllocated[p]);
1146 memcpy(int32Value[p], values, elements * 4);
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;
1155 if (elements > elementsAllocated[p]) {
1156 elementsAllocated[p] = elements + elementAllocationIncrement;
1157 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p],
sizeof(uint32_t) * elementsAllocated[p]);
1159 for (i=0; i<elements; i++) {
1160 uint32Value[p][i] = (uint32_t)(values[i]);
1165 real32Value = (
float**)SDDS_realloc(real32Value,
sizeof(
float*) * page);
1166 for (i=0; i<n; i++) {
1167 real32Value[p - i] = (
float*)NULL;
1170 if (elements > elementsAllocated[p]) {
1171 elementsAllocated[p] = elements + elementAllocationIncrement;
1172 real32Value[p] = (
float*)SDDS_realloc(real32Value[p],
sizeof(
float) * elementsAllocated[p]);
1174 for (i=0; i<elements; i++) {
1175 real32Value[p][i] = (float)(values[i]);
1180 real64Value = (
double**)SDDS_realloc(real64Value,
sizeof(
double*) * page);
1181 for (i=0; i<n; i++) {
1182 real64Value[p - i] = (
double*)NULL;
1185 if (elements > elementsAllocated[p]) {
1186 elementsAllocated[p] = elements + elementAllocationIncrement;
1187 real64Value[p] = (
double*)SDDS_realloc(real64Value[p],
sizeof(
double) * elementsAllocated[p]);
1189 for (i=0; i<elements; i++) {
1190 real64Value[p][i] = (double)(values[i]);
1195 stringValue = (
char***)SDDS_realloc(stringValue,
sizeof(
char**) * page);
1196 for (i=0; i<n; i++) {
1197 stringValue[p - i] = NULL;
1200 if (elements > elementsAllocated[p]) {
1201 elementsAllocated[p] = elements + elementAllocationIncrement;
1202 stringValue[p] = (
char**)SDDS_realloc(stringValue[p],
sizeof(
char*) * elementsAllocated[p]);
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);
1212 charValue = (
char**)SDDS_realloc(charValue,
sizeof(
char*) * page);
1213 for (i=0; i<n; i++) {
1214 charValue[p - i] = NULL;
1217 if (elements > elementsAllocated[p]) {
1218 elementsAllocated[p] = elements + elementAllocationIncrement;
1219 charValue[p] = (
char*)SDDS_realloc(charValue[p],
sizeof(
char) * elementsAllocated[p]);
1221 for (i=0; i<elements; i++) {
1222 charValue[p][i] = (char)(values[i]);
1230 if (elementCount[p] < elements) {
1231 elementCount[p] = elements;
1236int32_t SDDSArray::setValues(uint32_t *values, uint32_t page, uint32_t elements) {
1239 char s[SDDS_MAXLINE];
1242 if (page > pageCount) {
1244 n = page - pageCount;
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;
1255 switch (arrayType) {
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;
1263 if (elements > elementsAllocated[p]) {
1264 elementsAllocated[p] = elements + elementAllocationIncrement;
1265 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p],
sizeof(int16_t) * elementsAllocated[p]);
1267 for (i=0; i<elements; i++) {
1268 int16Value[p][i] = (int16_t)(values[i]);
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;
1278 if (elements > elementsAllocated[p]) {
1279 elementsAllocated[p] = elements + elementAllocationIncrement;
1280 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p],
sizeof(uint16_t) * elementsAllocated[p]);
1282 for (i=0; i<elements; i++) {
1283 uint16Value[p][i] = (int16_t)(values[i]);
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;
1293 if (elements > elementsAllocated[p]) {
1294 elementsAllocated[p] = elements + elementAllocationIncrement;
1295 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p],
sizeof(int32_t) * elementsAllocated[p]);
1297 for (i=0; i<elements; i++) {
1298 int32Value[p][i] = (int32_t)(values[i]);
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;
1308 if (elements > elementsAllocated[p]) {
1309 elementsAllocated[p] = elements + elementAllocationIncrement;
1310 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p],
sizeof(uint32_t) * elementsAllocated[p]);
1312 memcpy(uint32Value[p], values, elements * 4);
1316 real32Value = (
float**)SDDS_realloc(real32Value,
sizeof(
float*) * page);
1317 for (i=0; i<n; i++) {
1318 real32Value[p - i] = (
float*)NULL;
1321 if (elements > elementsAllocated[p]) {
1322 elementsAllocated[p] = elements + elementAllocationIncrement;
1323 real32Value[p] = (
float*)SDDS_realloc(real32Value[p],
sizeof(
float) * elementsAllocated[p]);
1325 for (i=0; i<elements; i++) {
1326 real32Value[p][i] = (float)(values[i]);
1331 real64Value = (
double**)SDDS_realloc(real64Value,
sizeof(
double*) * page);
1332 for (i=0; i<n; i++) {
1333 real64Value[p - i] = (
double*)NULL;
1336 if (elements > elementsAllocated[p]) {
1337 elementsAllocated[p] = elements + elementAllocationIncrement;
1338 real64Value[p] = (
double*)SDDS_realloc(real64Value[p],
sizeof(
double) * elementsAllocated[p]);
1340 for (i=0; i<elements; i++) {
1341 real64Value[p][i] = (double)(values[i]);
1346 stringValue = (
char***)SDDS_realloc(stringValue,
sizeof(
char**) * page);
1347 for (i=0; i<n; i++) {
1348 stringValue[p - i] = NULL;
1351 if (elements > elementsAllocated[p]) {
1352 elementsAllocated[p] = elements + elementAllocationIncrement;
1353 stringValue[p] = (
char**)SDDS_realloc(stringValue[p],
sizeof(
char*) * elementsAllocated[p]);
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);
1363 charValue = (
char**)SDDS_realloc(charValue,
sizeof(
char*) * page);
1364 for (i=0; i<n; i++) {
1365 charValue[p - i] = NULL;
1368 if (elements > elementsAllocated[p]) {
1369 elementsAllocated[p] = elements + elementAllocationIncrement;
1370 charValue[p] = (
char*)SDDS_realloc(charValue[p],
sizeof(
char) * elementsAllocated[p]);
1372 for (i=0; i<elements; i++) {
1373 charValue[p][i] = (char)(values[i]);
1381 if (elementCount[p] < elements) {
1382 elementCount[p] = elements;
1387int32_t SDDSArray::setValues(
float *values, uint32_t page, uint32_t elements) {
1390 char s[SDDS_MAXLINE];
1393 if (page > pageCount) {
1395 n = page - pageCount;
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;
1406 switch (arrayType) {
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;
1414 if (elements > elementsAllocated[p]) {
1415 elementsAllocated[p] = elements + elementAllocationIncrement;
1416 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p],
sizeof(int16_t) * elementsAllocated[p]);
1418 for (i=0; i<elements; i++) {
1419 int16Value[p][i] = (int16_t)(values[i]);
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;
1429 if (elements > elementsAllocated[p]) {
1430 elementsAllocated[p] = elements + elementAllocationIncrement;
1431 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p],
sizeof(uint16_t) * elementsAllocated[p]);
1433 for (i=0; i<elements; i++) {
1434 uint16Value[p][i] = (int16_t)(values[i]);
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;
1444 if (elements > elementsAllocated[p]) {
1445 elementsAllocated[p] = elements + elementAllocationIncrement;
1446 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p],
sizeof(int32_t) * elementsAllocated[p]);
1448 for (i=0; i<elements; i++) {
1449 int32Value[p][i] = (int32_t)(values[i]);
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;
1459 if (elements > elementsAllocated[p]) {
1460 elementsAllocated[p] = elements + elementAllocationIncrement;
1461 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p],
sizeof(uint32_t) * elementsAllocated[p]);
1463 for (i=0; i<elements; i++) {
1464 uint32Value[p][i] = (uint32_t)(values[i]);
1469 real32Value = (
float**)SDDS_realloc(real32Value,
sizeof(
float*) * page);
1470 for (i=0; i<n; i++) {
1471 real32Value[p - i] = (
float*)NULL;
1474 if (elements > elementsAllocated[p]) {
1475 elementsAllocated[p] = elements + elementAllocationIncrement;
1476 real32Value[p] = (
float*)SDDS_realloc(real32Value[p],
sizeof(
float) * elementsAllocated[p]);
1478 memcpy(real32Value[p], values, elements * 4);
1482 real64Value = (
double**)SDDS_realloc(real64Value,
sizeof(
double*) * page);
1483 for (i=0; i<n; i++) {
1484 real64Value[p - i] = (
double*)NULL;
1487 if (elements > elementsAllocated[p]) {
1488 elementsAllocated[p] = elements + elementAllocationIncrement;
1489 real64Value[p] = (
double*)SDDS_realloc(real64Value[p],
sizeof(
double) * elementsAllocated[p]);
1491 for (i=0; i<elements; i++) {
1492 real64Value[p][i] = (double)(values[i]);
1497 stringValue = (
char***)SDDS_realloc(stringValue,
sizeof(
char**) * page);
1498 for (i=0; i<n; i++) {
1499 stringValue[p - i] = NULL;
1502 if (elements > elementsAllocated[p]) {
1503 elementsAllocated[p] = elements + elementAllocationIncrement;
1504 stringValue[p] = (
char**)SDDS_realloc(stringValue[p],
sizeof(
char*) * elementsAllocated[p]);
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);
1514 charValue = (
char**)SDDS_realloc(charValue,
sizeof(
char*) * page);
1515 for (i=0; i<n; i++) {
1516 charValue[p - i] = NULL;
1519 if (elements > elementsAllocated[p]) {
1520 elementsAllocated[p] = elements + elementAllocationIncrement;
1521 charValue[p] = (
char*)SDDS_realloc(charValue[p],
sizeof(
char) * elementsAllocated[p]);
1523 for (i=0; i<elements; i++) {
1524 charValue[p][i] = (char)(values[i]);
1532 if (elementCount[p] < elements) {
1533 elementCount[p] = elements;
1538int32_t SDDSArray::setValues(
double *values, uint32_t page, uint32_t elements) {
1541 char s[SDDS_MAXLINE];
1544 if (page > pageCount) {
1546 n = page - pageCount;
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;
1557 switch (arrayType) {
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;
1565 if (elements > elementsAllocated[p]) {
1566 elementsAllocated[p] = elements + elementAllocationIncrement;
1567 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p],
sizeof(int16_t) * elementsAllocated[p]);
1569 for (i=0; i<elements; i++) {
1570 int16Value[p][i] = (int16_t)(values[i]);
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;
1580 if (elements > elementsAllocated[p]) {
1581 elementsAllocated[p] = elements + elementAllocationIncrement;
1582 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p],
sizeof(uint16_t) * elementsAllocated[p]);
1584 for (i=0; i<elements; i++) {
1585 uint16Value[p][i] = (int16_t)(values[i]);
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;
1595 if (elements > elementsAllocated[p]) {
1596 elementsAllocated[p] = elements + elementAllocationIncrement;
1597 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p],
sizeof(int32_t) * elementsAllocated[p]);
1599 for (i=0; i<elements; i++) {
1600 int32Value[p][i] = (int32_t)(values[i]);
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;
1610 if (elements > elementsAllocated[p]) {
1611 elementsAllocated[p] = elements + elementAllocationIncrement;
1612 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p],
sizeof(uint32_t) * elementsAllocated[p]);
1614 for (i=0; i<elements; i++) {
1615 uint32Value[p][i] = (uint32_t)(values[i]);
1620 real32Value = (
float**)SDDS_realloc(real32Value,
sizeof(
float*) * page);
1621 for (i=0; i<n; i++) {
1622 real32Value[p - i] = (
float*)NULL;
1625 if (elements > elementsAllocated[p]) {
1626 elementsAllocated[p] = elements + elementAllocationIncrement;
1627 real32Value[p] = (
float*)SDDS_realloc(real32Value[p],
sizeof(
float) * elementsAllocated[p]);
1629 for (i=0; i<elements; i++) {
1630 real32Value[p][i] = (float)(values[i]);
1635 real64Value = (
double**)SDDS_realloc(real64Value,
sizeof(
double*) * page);
1636 for (i=0; i<n; i++) {
1637 real64Value[p - i] = (
double*)NULL;
1640 if (elements > elementsAllocated[p]) {
1641 elementsAllocated[p] = elements + elementAllocationIncrement;
1642 real64Value[p] = (
double*)SDDS_realloc(real64Value[p],
sizeof(
double) * elementsAllocated[p]);
1644 memcpy(real64Value[p], values, elements * 8);
1648 stringValue = (
char***)SDDS_realloc(stringValue,
sizeof(
char**) * page);
1649 for (i=0; i<n; i++) {
1650 stringValue[p - i] = NULL;
1653 if (elements > elementsAllocated[p]) {
1654 elementsAllocated[p] = elements + elementAllocationIncrement;
1655 stringValue[p] = (
char**)SDDS_realloc(stringValue[p],
sizeof(
char*) * elementsAllocated[p]);
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);
1665 charValue = (
char**)SDDS_realloc(charValue,
sizeof(
char*) * page);
1666 for (i=0; i<n; i++) {
1667 charValue[p - i] = NULL;
1670 if (elements > elementsAllocated[p]) {
1671 elementsAllocated[p] = elements + elementAllocationIncrement;
1672 charValue[p] = (
char*)SDDS_realloc(charValue[p],
sizeof(
char) * elementsAllocated[p]);
1674 for (i=0; i<elements; i++) {
1675 charValue[p][i] = (char)(values[i]);
1683 if (elementCount[p] < elements) {
1684 elementCount[p] = elements;
1689int32_t SDDSArray::setValues(
char **values, uint32_t page, uint32_t elements) {
1690 int32_t returnVal=0;
1693 int64_t *iValue=NULL;
1694 double *dValue=NULL;
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)) {
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)) {
1720 if (page > pageCount) {
1722 n = page - pageCount;
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;
1733 switch (arrayType) {
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;
1741 if (elements > elementsAllocated[p]) {
1742 elementsAllocated[p] = elements + elementAllocationIncrement;
1743 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p],
sizeof(int16_t) * elementsAllocated[p]);
1745 for (i=0; i<elements; i++) {
1746 int16Value[p][i] = (int16_t)(iValue[i]);
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;
1756 if (elements > elementsAllocated[p]) {
1757 elementsAllocated[p] = elements + elementAllocationIncrement;
1758 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p],
sizeof(uint16_t) * elementsAllocated[p]);
1760 for (i=0; i<elements; i++) {
1761 uint16Value[p][i] = (int16_t)(iValue[i]);
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;
1771 if (elements > elementsAllocated[p]) {
1772 elementsAllocated[p] = elements + elementAllocationIncrement;
1773 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p],
sizeof(int32_t) * elementsAllocated[p]);
1775 for (i=0; i<elements; i++) {
1776 int32Value[p][i] = (int32_t)(iValue[i]);
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;
1786 if (elements > elementsAllocated[p]) {
1787 elementsAllocated[p] = elements + elementAllocationIncrement;
1788 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p],
sizeof(uint32_t) * elementsAllocated[p]);
1790 for (i=0; i<elements; i++) {
1791 uint32Value[p][i] = (uint32_t)(iValue[i]);
1796 real32Value = (
float**)SDDS_realloc(real32Value,
sizeof(
float*) * page);
1797 for (i=0; i<n; i++) {
1798 real32Value[p - i] = (
float*)NULL;
1801 if (elements > elementsAllocated[p]) {
1802 elementsAllocated[p] = elements + elementAllocationIncrement;
1803 real32Value[p] = (
float*)SDDS_realloc(real32Value[p],
sizeof(
float) * elementsAllocated[p]);
1805 for (i=0; i<elements; i++) {
1806 real32Value[p][i] = (float)(dValue[i]);
1811 real64Value = (
double**)SDDS_realloc(real64Value,
sizeof(
double*) * page);
1812 for (i=0; i<n; i++) {
1813 real64Value[p - i] = (
double*)NULL;
1816 if (elements > elementsAllocated[p]) {
1817 elementsAllocated[p] = elements + elementAllocationIncrement;
1818 real64Value[p] = (
double*)SDDS_realloc(real64Value[p],
sizeof(
double) * elementsAllocated[p]);
1820 for (i=0; i<elements; i++) {
1821 real64Value[p][i] = (double)(dValue[i]);
1826 stringValue = (
char***)SDDS_realloc(stringValue,
sizeof(
char**) * page);
1827 for (i=0; i<n; i++) {
1828 stringValue[p - i] = NULL;
1831 if (elements > elementsAllocated[p]) {
1832 elementsAllocated[p] = elements + elementAllocationIncrement;
1833 stringValue[p] = (
char**)SDDS_realloc(stringValue[p],
sizeof(
char*) * elementsAllocated[p]);
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]);
1842 charValue = (
char**)SDDS_realloc(charValue,
sizeof(
char*) * page);
1843 for (i=0; i<n; i++) {
1844 charValue[p - i] = NULL;
1847 if (elements > elementsAllocated[p]) {
1848 elementsAllocated[p] = elements + elementAllocationIncrement;
1849 charValue[p] = (
char*)SDDS_realloc(charValue[p],
sizeof(
char) * elementsAllocated[p]);
1851 for (i=0; i<elements; i++) {
1852 charValue[p][i] = (char)(values[i][0]);
1860 if (elementCount[p] < elements) {
1861 elementCount[p] = elements;
1866int32_t SDDSArray::setValues(
char *values, uint32_t page, uint32_t elements) {
1869 char s[SDDS_MAXLINE];
1872 if (page > pageCount) {
1874 n = page - pageCount;
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;
1885 switch (arrayType) {
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;
1893 if (elements > elementsAllocated[p]) {
1894 elementsAllocated[p] = elements + elementAllocationIncrement;
1895 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p],
sizeof(int16_t) * elementsAllocated[p]);
1897 for (i=0; i<elements; i++) {
1898 int16Value[p][i] = (int16_t)(values[i]);
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;
1908 if (elements > elementsAllocated[p]) {
1909 elementsAllocated[p] = elements + elementAllocationIncrement;
1910 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p],
sizeof(uint16_t) * elementsAllocated[p]);
1912 for (i=0; i<elements; i++) {
1913 uint16Value[p][i] = (int16_t)(values[i]);
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;
1923 if (elements > elementsAllocated[p]) {
1924 elementsAllocated[p] = elements + elementAllocationIncrement;
1925 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p],
sizeof(int32_t) * elementsAllocated[p]);
1927 for (i=0; i<elements; i++) {
1928 int32Value[p][i] = (int32_t)(values[i]);
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;
1938 if (elements > elementsAllocated[p]) {
1939 elementsAllocated[p] = elements + elementAllocationIncrement;
1940 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p],
sizeof(uint32_t) * elementsAllocated[p]);
1942 for (i=0; i<elements; i++) {
1943 uint32Value[p][i] = (uint32_t)(values[i]);
1948 real32Value = (
float**)SDDS_realloc(real32Value,
sizeof(
float*) * page);
1949 for (i=0; i<n; i++) {
1950 real32Value[p - i] = (
float*)NULL;
1953 if (elements > elementsAllocated[p]) {
1954 elementsAllocated[p] = elements + elementAllocationIncrement;
1955 real32Value[p] = (
float*)SDDS_realloc(real32Value[p],
sizeof(
float) * elementsAllocated[p]);
1957 for (i=0; i<elements; i++) {
1958 real32Value[p][i] = (float)(values[i]);
1963 real64Value = (
double**)SDDS_realloc(real64Value,
sizeof(
double*) * page);
1964 for (i=0; i<n; i++) {
1965 real64Value[p - i] = (
double*)NULL;
1968 if (elements > elementsAllocated[p]) {
1969 elementsAllocated[p] = elements + elementAllocationIncrement;
1970 real64Value[p] = (
double*)SDDS_realloc(real64Value[p],
sizeof(
double) * elementsAllocated[p]);
1972 for (i=0; i<elements; i++) {
1973 real64Value[p][i] = (double)(values[i]);
1978 stringValue = (
char***)SDDS_realloc(stringValue,
sizeof(
char**) * page);
1979 for (i=0; i<n; i++) {
1980 stringValue[p - i] = NULL;
1983 if (elements > elementsAllocated[p]) {
1984 elementsAllocated[p] = elements + elementAllocationIncrement;
1985 stringValue[p] = (
char**)SDDS_realloc(stringValue[p],
sizeof(
char*) * elementsAllocated[p]);
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);
1995 charValue = (
char**)SDDS_realloc(charValue,
sizeof(
char*) * page);
1996 for (i=0; i<n; i++) {
1997 charValue[p - i] = NULL;
2000 if (elements > elementsAllocated[p]) {
2001 elementsAllocated[p] = elements + elementAllocationIncrement;
2002 charValue[p] = (
char*)SDDS_realloc(charValue[p],
sizeof(
char) * elementsAllocated[p]);
2004 memcpy(charValue[p], values, elements);
2011 if (elementCount[p] < elements) {
2012 elementCount[p] = elements;
2025int32_t SDDSArray::readAsciiValues(
char **bigBuffer, int32_t *bigBufferSize, uint32_t page) {
2026 int32_t returnVal=0, length;
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)");
2036 if (arrayDimensions == 0) {
2037 ((SDDSFile*)sddsfile)->setError((
char*)
"Unable to read array--invalid array dimensions (SDDSArray::readAsciiValues)");
2040 if (arrayDim == NULL) {
2041 ((SDDSFile*)sddsfile)->setError((
char*)
"Unable to read array--invalid array dimensions (SDDSArray::readAsciiValues)");
2044 if (arrayDim[page - 1] == NULL) {
2045 ((SDDSFile*)sddsfile)->setError((
char*)
"Unable to read array--invalid array dimensions (SDDSArray::readAsciiValues)");
2048 if (bufferSize==0) {
2049 bufferSize=SDDS_MAXLINE;
2050 buffer = (
char*)SDDS_malloc(
sizeof(*buffer)*(bufferSize));
2052 if (bufferSize <= *bigBufferSize) {
2053 bufferSize = 2 * *bigBufferSize;
2054 buffer = (
char*)SDDS_realloc(buffer,
sizeof(*buffer)*(bufferSize));
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];
2064 elementsAllocated[p] = elementCount[p];
2065 switch (arrayType) {
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)");
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)");
2082 int16Value[p][i] = (int16_t)iValue;
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)");
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)");
2101 uint16Value[p][i] = (uint16_t)iValue;
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)");
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)");
2120 int32Value[p][i] = (int32_t)iValue;
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)");
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)");
2139 uint32Value[p][i] = (uint32_t)iValue;
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)");
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)");
2158 real32Value[p][i] = (float)dValue;
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)");
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)");
2177 real64Value[p][i] = (double)dValue;
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);
2185 if ((*bigBuffer)[length-1] ==
'\r') {
2186 (*bigBuffer)[length-1] = 0;
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)");
2193 stringValue[p][i] = (
char*)SDDS_malloc(
sizeof(
char) * 4);
2194 strcpy(stringValue[p][i],
"\"\"");
2196 SDDS_interpretEscapes(buffer);
2197 stringValue[p][i] = (
char*)SDDS_malloc(
sizeof(
char) * strlen(buffer) + 1);
2198 strcpy(stringValue[p][i], buffer);
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)");
2209 charValue[p][i] =
'-';
2211 charValue[p][i] = buffer[0];
2216 ((SDDSFile*)sddsfile)->setError((
char*)
"Unable to read array--invalid array type (SDDSArray::readAsciiValues)");
2232int32_t SDDSArray::readBinaryValues(FILE *fp,
SDDS_FILEBUFFER *fBuffer, uint32_t page,
bool nonNativeEndian) {
2235 if ((page == 0) || (page - 1 != pageCount)) {
2236 ((SDDSFile*)sddsfile)->setError((
char*)
"Unable to read array--invalid page number (SDDSArray::readBinaryValues)");
2239 if (arrayDimensions == 0) {
2240 ((SDDSFile*)sddsfile)->setError((
char*)
"Unable to read array--invalid array dimensions (SDDSArray::readBinaryValues)");
2243 if (arrayDim == NULL) {
2244 ((SDDSFile*)sddsfile)->setError((
char*)
"Unable to read array--invalid array dimensions (SDDSArray::readBinaryValues)");
2247 if (arrayDim[page - 1] == NULL) {
2248 ((SDDSFile*)sddsfile)->setError((
char*)
"Unable to read array--invalid array dimensions (SDDSArray::readBinaryValues)");
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];
2258 elementsAllocated[p] = elementCount[p];
2259 switch (arrayType) {
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)");
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)");
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)");
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)");
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)");
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)");
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)");
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)");
2328 ((SDDSFile*)sddsfile)->setError((
char*)
"Unable to read array--unknown type (SDDSArray::readBinaryValues)");
2335int32_t SDDSArray::readBinaryValues(voidp *gzfp,
SDDS_FILEBUFFER *fBuffer, uint32_t page,
bool nonNativeEndian) {
2338 if ((page == 0) || (page - 1 != pageCount)) {
2339 ((SDDSFile*)sddsfile)->setError((
char*)
"Unable to read array--invalid page number (SDDSArray::readBinaryValues)");
2342 if (arrayDimensions == 0) {
2343 ((SDDSFile*)sddsfile)->setError((
char*)
"Unable to read array--invalid array dimensions (SDDSArray::readBinaryValues)");
2346 if (arrayDim == NULL) {
2347 ((SDDSFile*)sddsfile)->setError((
char*)
"Unable to read array--invalid array dimensions (SDDSArray::readBinaryValues)");
2350 if (arrayDim[page - 1] == NULL) {
2351 ((SDDSFile*)sddsfile)->setError((
char*)
"Unable to read array--invalid array dimensions (SDDSArray::readBinaryValues)");
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];
2361 elementsAllocated[p] = elementCount[p];
2362 switch (arrayType) {
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)");
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)");
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)");
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)");
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)");
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)");
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)");
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)");
2431 ((SDDSFile*)sddsfile)->setError((
char*)
"Unable to read array--unknown type (SDDSArray::readBinaryValues)");
2446void* SDDSArray::getInternalValues(uint32_t page) {
2448 if ((page == 0) || (pageCount < page)) {
2449 ((SDDSFile*)sddsfile)->setError((
char*)
"Invalid page (SDDSArray::getInternalValues)");
2453 if (elementCount[p] == 0) {
2456 switch (arrayType) {
2458 return(int16Value[p]);
2460 return(uint16Value[p]);
2462 return(int32Value[p]);
2464 return(uint32Value[p]);
2466 return(real32Value[p]);
2468 return(real64Value[p]);
2470 return(stringValue[p]);
2472 return(charValue[p]);
2474 ((SDDSFile*)sddsfile)->setError((
char*)
"Invalid data type (SDDSArray::getInternalValues)");
2490int32_t* SDDSArray::getValuesInInt32(uint32_t page, int32_t *errorcode) {
2494 if ((page == 0) || (pageCount < page)) {
2496 return((int32_t*)NULL);
2500 if (elementCount[p] == 0) {
2501 return((int32_t*)NULL);
2503 rValues = (int32_t*)SDDS_malloc(
sizeof(int32_t) * elementCount[p]);
2504 switch (arrayType) {
2506 for (i=0; i<elementCount[p]; i++)
2507 rValues[i] = (int32_t)int16Value[p][i];
2508 return((int32_t*)rValues);
2510 for (i=0; i<elementCount[p]; i++)
2511 rValues[i] = (int32_t)uint16Value[p][i];
2512 return((int32_t*)rValues);
2514 for (i=0; i<elementCount[p]; i++)
2515 rValues[i] = (int32_t)int32Value[p][i];
2516 return((int32_t*)rValues);
2518 for (i=0; i<elementCount[p]; i++)
2519 rValues[i] = (int32_t)uint32Value[p][i];
2520 return((int32_t*)rValues);
2522 for (i=0; i<elementCount[p]; i++)
2523 rValues[i] = (int32_t)real32Value[p][i];
2524 return((int32_t*)rValues);
2526 for (i=0; i<elementCount[p]; i++)
2527 rValues[i] = (int32_t)real64Value[p][i];
2528 return((int32_t*)rValues);
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)) {
2536 return((int32_t*)NULL);
2538 rValues[i] = (int32_t)iValue;
2540 return((int32_t*)rValues);
2542 for (i=0; i<elementCount[p]; i++)
2543 rValues[i] = (int32_t)charValue[p][i];
2544 return((int32_t*)rValues);
2547 return((int32_t*)NULL);
2562uint32_t* SDDSArray::getValuesInUInt32(uint32_t page, int32_t *errorcode) {
2566 if ((page == 0) || (pageCount < page)) {
2568 return((uint32_t*)NULL);
2572 if (elementCount[p] == 0) {
2573 return((uint32_t*)NULL);
2575 rValues = (uint32_t*)SDDS_malloc(
sizeof(uint32_t) * elementCount[p]);
2576 switch (arrayType) {
2578 for (i=0; i<elementCount[p]; i++)
2579 rValues[i] = (uint32_t)int16Value[p][i];
2580 return((uint32_t*)rValues);
2582 for (i=0; i<elementCount[p]; i++)
2583 rValues[i] = (uint32_t)uint16Value[p][i];
2584 return((uint32_t*)rValues);
2586 for (i=0; i<elementCount[p]; i++)
2587 rValues[i] = (uint32_t)int32Value[p][i];
2588 return((uint32_t*)rValues);
2590 for (i=0; i<elementCount[p]; i++)
2591 rValues[i] = (uint32_t)uint32Value[p][i];
2592 return((uint32_t*)rValues);
2594 for (i=0; i<elementCount[p]; i++)
2595 rValues[i] = (uint32_t)real32Value[p][i];
2596 return((uint32_t*)rValues);
2598 for (i=0; i<elementCount[p]; i++)
2599 rValues[i] = (uint32_t)real64Value[p][i];
2600 return((uint32_t*)rValues);
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)) {
2608 return((uint32_t*)NULL);
2610 rValues[i] = (uint32_t)iValue;
2612 return((uint32_t*)rValues);
2614 for (i=0; i<elementCount[p]; i++)
2615 rValues[i] = (uint32_t)charValue[p][i];
2616 return((uint32_t*)rValues);
2619 return((uint32_t*)NULL);
2634double* SDDSArray::getValuesInDouble(uint32_t page, int32_t *errorcode) {
2638 if ((page == 0) || (pageCount < page)) {
2640 return((
double*)NULL);
2644 if (elementCount[p] == 0) {
2645 return((
double*)NULL);
2647 rValues = (
double*)SDDS_malloc(
sizeof(
double) * elementCount[p]);
2648 switch (arrayType) {
2650 for (i=0; i<elementCount[p]; i++)
2651 rValues[i] = (
double)int16Value[p][i];
2652 return((
double*)rValues);
2654 for (i=0; i<elementCount[p]; i++)
2655 rValues[i] = (
double)uint16Value[p][i];
2656 return((
double*)rValues);
2658 for (i=0; i<elementCount[p]; i++)
2659 rValues[i] = (
double)int32Value[p][i];
2660 return((
double*)rValues);
2662 for (i=0; i<elementCount[p]; i++)
2663 rValues[i] = (
double)uint32Value[p][i];
2664 return((
double*)rValues);
2666 for (i=0; i<elementCount[p]; i++)
2667 rValues[i] = (
double)real32Value[p][i];
2668 return((
double*)rValues);
2670 for (i=0; i<elementCount[p]; i++)
2671 rValues[i] = (
double)real64Value[p][i];
2672 return((
double*)rValues);
2674 for (i=0; i<elementCount[p]; i++) {
2675 dValue = strtod(stringValue[p][i], (
char**)NULL);
2676 if ((dValue == HUGE_VAL) || (dValue == -HUGE_VAL)) {
2680 return((
double*)NULL);
2682 rValues[i] = (double)dValue;
2684 return((
double*)rValues);
2686 for (i=0; i<elementCount[p]; i++)
2687 rValues[i] = (
double)charValue[p][i];
2688 return((
double*)rValues);
2691 return((
double*)NULL);
2706char** SDDSArray::getValuesInString(uint32_t page, int32_t *errorcode) {
2709 char s[SDDS_MAXLINE];
2710 if ((page == 0) || (pageCount < page)) {
2712 return((
char**)NULL);
2716 if (elementCount[p] == 0) {
2717 return((
char**)NULL);
2719 rValues = (
char**)SDDS_malloc(
sizeof(
char*) * elementCount[p]);
2720 switch (arrayType) {
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);
2727 return((
char**)rValues);
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);
2734 return((
char**)rValues);
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);
2741 return((
char**)rValues);
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);
2748 return((
char**)rValues);
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);
2755 return((
char**)rValues);
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);
2762 return((
char**)rValues);
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]);
2768 return((
char**)rValues);
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);
2775 return((
char**)rValues);
2778 return((
char**)NULL);
2791int32_t SDDSArray::writeAsciiValues(FILE *fp, uint32_t page) {
2794 int32_t hasWhitespace;
2797 if ((page == 0) || (page > pageCount)) {
2801 switch (arrayType) {
2803 for (i=0; i<elementCount[page]; i++) {
2804 fprintf(fp,
"%" PRId16
" ", int16Value[page][i]);
2808 for (i=0; i<elementCount[page]; i++) {
2809 fprintf(fp,
"%" PRIu16
" ", uint16Value[page][i]);
2813 for (i=0; i<elementCount[page]; i++) {
2814 fprintf(fp,
"%" PRId32
" ", int32Value[page][i]);
2818 for (i=0; i<elementCount[page]; i++) {
2819 fprintf(fp,
"%" PRIu32
" ", uint32Value[page][i]);
2823 for (i=0; i<elementCount[page]; i++) {
2824 fprintf(fp,
"%.*g ", FLT_DIG, real32Value[page][i]);
2828 for (i=0; i<elementCount[page]; i++) {
2829 fprintf(fp,
"%.*g ", DBL_DIG, real64Value[page][i]);
2833 for (i=0; i<elementCount[page]; i++) {
2834 s = stringValue[page][i];
2836 if (SDDS_hasWhitespace(s) || SDDS_stringIsBlank(s)) {
2844 }
else if (c==
'\\') {
2846 }
else if (c==
'"') {
2848 }
else if (c==
' ') {
2850 }
else if (isspace(c) || !isprint(c)) {
2851 fprintf(fp,
"\\%03o", c);
2856 if (hasWhitespace) {
2863 for (i=0; i<elementCount[page]; i++) {
2864 c = charValue[page][i];
2871 else if (!c || isspace(c) || !isprint(c))
2872 fprintf(fp,
"\\%03o", c);
2885int32_t SDDSArray::writeAsciiValues(voidp *gzfp, uint32_t page) {
2888 int32_t hasWhitespace;
2891 if ((page == 0) || (page > pageCount)) {
2895 switch (arrayType) {
2897 for (i=0; i<elementCount[page]; i++) {
2898 gzprintf(gzfp,
"%" PRId16
" ", int16Value[page][i]);
2902 for (i=0; i<elementCount[page]; i++) {
2903 gzprintf(gzfp,
"%" PRIu16
" ", uint16Value[page][i]);
2907 for (i=0; i<elementCount[page]; i++) {
2908 gzprintf(gzfp,
"%" PRId32
" ", int32Value[page][i]);
2912 for (i=0; i<elementCount[page]; i++) {
2913 gzprintf(gzfp,
"%" PRIu32
" ", uint32Value[page][i]);
2917 for (i=0; i<elementCount[page]; i++) {
2918 gzprintf(gzfp,
"%.*g ", FLT_DIG, real32Value[page][i]);
2922 for (i=0; i<elementCount[page]; i++) {
2923 gzprintf(gzfp,
"%.*g ", DBL_DIG, real64Value[page][i]);
2927 for (i=0; i<elementCount[page]; i++) {
2928 s = stringValue[page][i];
2930 if (SDDS_hasWhitespace(s) || SDDS_stringIsBlank(s)) {
2937 gzputs(gzfp,
"\\!");
2938 }
else if (c==
'\\') {
2939 gzputs(gzfp,
"\\\\");
2940 }
else if (c==
'"') {
2941 gzputs(gzfp,
"\\\"");
2942 }
else if (c==
' ') {
2944 }
else if (isspace(c) || !isprint(c)) {
2945 gzprintf(gzfp,
"\\%03o", c);
2950 if (hasWhitespace) {
2957 for (i=0; i<elementCount[page]; i++) {
2958 c = charValue[page][i];
2960 gzputs(gzfp,
"\\!");
2962 gzputs(gzfp,
"\\\\");
2964 gzputs(gzfp,
"\\\"");
2965 else if (!c || isspace(c) || !isprint(c))
2966 gzprintf(gzfp,
"\\%03o", c);
2975 gzprintf(gzfp,
"\n");
2988int32_t SDDSArray::writeBinaryValues(FILE *fp,
SDDS_FILEBUFFER *fBuffer, uint32_t page,
bool nonNativeEndian) {
2990 if ((page == 0) || (page > pageCount)) {
2994 switch (arrayType) {
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)");
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)");
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)");
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)");
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)");
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)");
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)");
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)");
3046 ((SDDSFile*)sddsfile)->setError((
char*)
"Unable to write array--unknown type (SDDSArray::writeBinaryValues)");
3052int32_t SDDSArray::writeBinaryValues(voidp *gzfp,
SDDS_FILEBUFFER *fBuffer, uint32_t page,
bool nonNativeEndian) {
3054 if ((page == 0) || (page > pageCount)) {
3058 switch (arrayType) {
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)");
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)");
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)");
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)");
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)");
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)");
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)");
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)");
3110 ((SDDSFile*)sddsfile)->setError((
char*)
"Unable to write array--unknown type (SDDSArray::writeBinaryValues)");
#define SDDS_NUM_TYPES
Total number of defined SDDS data types.
#define SDDS_INTEGER_TYPE(type)
Checks if the given type identifier corresponds to an integer type.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_FLOATING_TYPE(type)
Checks if the given type identifier corresponds to a floating-point type.
#define SDDS_CHARACTER
Identifier for the character data type.