SDDS ToolKit Programs and Libraries for C and Python
Loading...
Searching...
No Matches
SDDSColumn.cc
Go to the documentation of this file.
1/**
2 * @file SDDSColumn.cc
3 * @brief Archived implementation of the original SDDS3 column class.
4 *
5 * @details Provides legacy column 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
24 Ensure that strtod returns HUGE_VAL on all operating systems.
25 Modify setType so that it can change the type of an existing column.
26 Update so that you can not read pages out of order (this may be needed for blank pages)
27 fix nonnative binary reads.
28*/
29
30#include <stdio.h>
31#include <string.h>
32#include <stdlib.h>
33#include <stdarg.h>
34#include <ctype.h>
35#include <limits.h>
36#include <math.h>
37#include <float.h>
38#include "SDDS3.h"
39
40
41/***********************************************************************************************
42 * SDDSColumn *
43 * *
44 * C++ Arguments: none *
45 * *
46 * Results: pointer to SDDSColumn object *
47 ***********************************************************************************************/
48SDDSColumn::SDDSColumn() {
49 pageCount = 0;
50 rowCount = NULL;
51 rowsAllocated = NULL;
52 rowAllocationIncrement = 1000;
53 columnType = 0;
54 columnName = NULL;
55 columnSymbol = NULL;
56 columnUnits = NULL;
57 columnDescription = NULL;
58 columnFormatString = NULL;
59 columnFieldLength = 0;
60 int32Value = NULL;
61 int16Value = NULL;
62 uint32Value = NULL;
63 uint16Value = NULL;
64 real64Value = NULL;
65 real32Value = NULL;
66 stringValue = NULL;
67 charValue = NULL;
68}
69
70/***********************************************************************************************
71 * ~SDDSColumn *
72 * *
73 * C++ Arguments: none *
74 * *
75 * Results: none *
76 ***********************************************************************************************/
77SDDSColumn::~SDDSColumn() {
78 uint32_t i, j;
79 if (columnName != NULL)
80 SDDS_free(columnName);
81 if (columnSymbol != NULL)
82 SDDS_free(columnSymbol);
83 if (columnUnits != NULL)
84 SDDS_free(columnUnits);
85 if (columnDescription != NULL)
86 SDDS_free(columnDescription);
87 if (columnFormatString != NULL)
88 SDDS_free(columnFormatString);
89 if (int16Value != NULL) {
90 for (i=0; i<pageCount; i++) {
91 if (int16Value[i] != NULL) {
92 SDDS_free(int16Value[i]);
93 }
94 }
95 SDDS_free(int16Value);
96 }
97 if (uint16Value != NULL) {
98 for (i=0; i<pageCount; i++) {
99 if (uint16Value[i] != NULL) {
100 SDDS_free(uint16Value[i]);
101 }
102 }
103 SDDS_free(uint16Value);
104 }
105 if (int32Value != NULL) {
106 for (i=0; i<pageCount; i++) {
107 if (int32Value[i] != NULL) {
108 SDDS_free(int32Value[i]);
109 }
110 }
111 SDDS_free(int32Value);
112 }
113 if (uint32Value != NULL) {
114 for (i=0; i<pageCount; i++) {
115 if (uint32Value[i] != NULL) {
116 SDDS_free(uint32Value[i]);
117 }
118 }
119 SDDS_free(uint32Value);
120 }
121 if (real32Value != NULL) {
122 for (i=0; i<pageCount; i++) {
123 if (real32Value[i] != NULL) {
124 SDDS_free(real32Value[i]);
125 }
126 }
127 SDDS_free(real32Value);
128 }
129 if (real64Value != NULL) {
130 for (i=0; i<pageCount; i++) {
131 if (real64Value[i] != NULL) {
132 SDDS_free(real64Value[i]);
133 }
134 }
135 SDDS_free(real64Value);
136 }
137 if (stringValue != NULL) {
138 for (i=0; i<pageCount; i++) {
139 if (stringValue[i] != NULL) {
140 for (j=0; j<rowCount[i] ; j++) {
141 if (stringValue[i][j] != NULL) {
142 SDDS_free(stringValue[i][j]);
143 }
144 }
145 SDDS_free(stringValue[i]);
146 }
147 }
148 SDDS_free(stringValue);
149 }
150 if (charValue != NULL) {
151 for (i=0; i<pageCount; i++) {
152 if (charValue[i] != NULL) {
153 SDDS_free(charValue[i]);
154 }
155 }
156 SDDS_free(charValue);
157 }
158 if (rowCount != NULL) {
159 SDDS_free(rowCount);
160 }
161 if (rowsAllocated != NULL) {
162 SDDS_free(rowsAllocated);
163 }
164}
165
166/***********************************************************************************************
167 * freePage *
168 * *
169 * C++ Arguments: none *
170 * *
171 * Results: none *
172 ***********************************************************************************************/
173void SDDSColumn::freePage() {
174 uint32_t i, j;
175 switch (columnType) {
176 case SDDS_INT16:
177 if (int16Value != NULL) {
178 for (i=0; i<pageCount; i++) {
179 if (int16Value[i] != NULL) {
180 SDDS_free(int16Value[i]);
181 }
182 }
183 SDDS_free(int16Value);
184 }
185 int16Value = NULL;
186 break;
187 case SDDS_UINT16:
188 if (uint16Value != NULL) {
189 for (i=0; i<pageCount; i++) {
190 if (uint16Value[i] != NULL) {
191 SDDS_free(uint16Value[i]);
192 }
193 }
194 SDDS_free(uint16Value);
195 }
196 uint16Value = NULL;
197 break;
198 case SDDS_INT32:
199 if (int32Value != NULL) {
200 for (i=0; i<pageCount; i++) {
201 if (int32Value[i] != NULL) {
202 SDDS_free(int32Value[i]);
203 }
204 }
205 SDDS_free(int32Value);
206 }
207 int32Value = NULL;
208 break;
209 case SDDS_UINT32:
210 if (uint32Value != NULL) {
211 for (i=0; i<pageCount; i++) {
212 if (uint32Value[i] != NULL) {
213 SDDS_free(uint32Value[i]);
214 }
215 }
216 SDDS_free(uint32Value);
217 }
218 uint32Value = NULL;
219 break;
220 case SDDS_REAL32:
221 if (real32Value != NULL) {
222 for (i=0; i<pageCount; i++) {
223 if (real32Value[i] != NULL) {
224 SDDS_free(real32Value[i]);
225 }
226 }
227 SDDS_free(real32Value);
228 }
229 real32Value = NULL;
230 break;
231 case SDDS_REAL64:
232 if (real64Value != NULL) {
233 for (i=0; i<pageCount; i++) {
234 if (real64Value[i] != NULL) {
235 SDDS_free(real64Value[i]);
236 }
237 }
238 SDDS_free(real64Value);
239 }
240 real64Value = NULL;
241 break;
242 case SDDS_STRING:
243 if (stringValue != NULL) {
244 for (i=0; i<pageCount; i++) {
245 if (stringValue[i] != NULL) {
246 for (j=0; j<rowCount[i] ; j++) {
247 if (stringValue[i][j] != NULL) {
248 SDDS_free(stringValue[i][j]);
249 }
250 }
251 SDDS_free(stringValue[i]);
252 }
253 }
254 SDDS_free(stringValue);
255 }
256 stringValue = NULL;
257 break;
258 case SDDS_CHARACTER:
259 if (charValue != NULL) {
260 for (i=0; i<pageCount; i++) {
261 if (charValue[i] != NULL) {
262 SDDS_free(charValue[i]);
263 }
264 }
265 SDDS_free(charValue);
266 }
267 charValue = NULL;
268 break;
269 default:
270 break;
271 }
272 if (rowCount != NULL) {
273 SDDS_free(rowCount);
274 }
275 rowCount = NULL;
276 if (rowsAllocated != NULL) {
277 SDDS_free(rowsAllocated);
278 }
279 rowsAllocated = NULL;
280 pageCount = 0;
281}
282
283/***********************************************************************************************
284 * setupColumn *
285 * *
286 * C++ Arguments: char *name, char *symbol, char *units, char *description, *
287 * char *format_string, int32_t type, uint32_t field_length *
288 * *
289 * Results: none *
290 ***********************************************************************************************/
291void SDDSColumn::setupColumn(char *name, char *symbol, char *units, char *description, char *format_string, int32_t type, uint32_t field_length) {
292 if (columnName != NULL)
293 SDDS_free(columnName);
294 if (columnSymbol != NULL)
295 SDDS_free(columnSymbol);
296 if (columnUnits != NULL)
297 SDDS_free(columnUnits);
298 if (columnDescription != NULL)
299 SDDS_free(columnDescription);
300 if (columnFormatString != NULL)
301 SDDS_free(columnFormatString);
302
303 if (name == NULL)
304 columnName = NULL;
305 else {
306 columnName = (char*)SDDS_malloc(sizeof(char) * strlen(name) + 1);
307 strcpy(columnName, name);
308 }
309 if (symbol == NULL)
310 columnSymbol = NULL;
311 else {
312 columnSymbol = (char*)SDDS_malloc(sizeof(char) * strlen(symbol) + 1);
313 strcpy(columnSymbol, symbol);
314 }
315 if (units == NULL)
316 columnUnits = NULL;
317 else {
318 columnUnits = (char*)SDDS_malloc(sizeof(char) * strlen(units) + 1);
319 strcpy(columnUnits, units);
320 }
321 if (description == NULL)
322 columnDescription = NULL;
323 else {
324 columnDescription = (char*)SDDS_malloc(sizeof(char) * strlen(description) + 1);
325 strcpy(columnDescription, description);
326 }
327 if (format_string == NULL)
328 columnFormatString = NULL;
329 else {
330 columnFormatString = (char*)SDDS_malloc(sizeof(char) * strlen(format_string) + 1);
331 strcpy(columnFormatString, format_string);
332 }
333 columnType = type;
334 columnFieldLength = field_length;
335}
336
337/***********************************************************************************************
338 * informAboutParent *
339 * *
340 * C++ Arguments: SDDSFile *parent *
341 * *
342 * Results: none *
343 ***********************************************************************************************/
344void SDDSColumn::informAboutParent(void *parent) {
345 sddsfile = parent;
346}
347
348/***********************************************************************************************
349 * getName *
350 * *
351 * C++ Arguments: none *
352 * *
353 * Results: pointer to name (do not free the result) *
354 ***********************************************************************************************/
355char* SDDSColumn::getName() {
356 return(columnName);
357}
358
359/***********************************************************************************************
360 * setName *
361 * *
362 * C++ Arguments: char *name *
363 * *
364 * Results: none *
365 ***********************************************************************************************/
366void SDDSColumn::setName(char *name) {
367 if (columnName != NULL)
368 SDDS_free(columnName);
369 if (name == NULL)
370 columnName = NULL;
371 else {
372 columnName = (char*)SDDS_malloc(sizeof(char) * strlen(name) + 1);
373 strcpy(columnName, name);
374 }
375}
376
377/***********************************************************************************************
378 * getSymbol *
379 * *
380 * C++ Arguments: none *
381 * *
382 * Results: pointer to symbol (do not free the result) *
383 ***********************************************************************************************/
384char* SDDSColumn::getSymbol() {
385 return(columnSymbol);
386}
387
388/***********************************************************************************************
389 * setSymbol *
390 * *
391 * C++ Arguments: char *symbol *
392 * *
393 * Results: none *
394 ***********************************************************************************************/
395void SDDSColumn::setSymbol(char *symbol) {
396 if (columnSymbol != NULL)
397 SDDS_free(columnSymbol);
398 if (symbol == NULL)
399 columnSymbol = NULL;
400 else {
401 columnSymbol = (char*)SDDS_malloc(sizeof(char) * strlen(symbol) + 1);
402 strcpy(columnSymbol, symbol);
403 }
404}
405
406/***********************************************************************************************
407 * getUnits *
408 * *
409 * C++ Arguments: none *
410 * *
411 * Results: pointer to the units (do not free the result) *
412 ***********************************************************************************************/
413char* SDDSColumn::getUnits() {
414 return(columnUnits);
415}
416
417/***********************************************************************************************
418 * setUnits *
419 * *
420 * C++ Arguments: char *units *
421 * *
422 * Results: none *
423 ***********************************************************************************************/
424void SDDSColumn::setUnits(char *units) {
425 if (columnUnits != NULL)
426 SDDS_free(columnUnits);
427 if (units == NULL)
428 columnUnits = NULL;
429 else {
430 columnUnits = (char*)SDDS_malloc(sizeof(char) * strlen(units) + 1);
431 strcpy(columnUnits, units);
432 }
433}
434
435/***********************************************************************************************
436 * getDescription *
437 * *
438 * C++ Arguments: none *
439 * *
440 * Results: pointer to the description (do not free the result) *
441 ***********************************************************************************************/
442char* SDDSColumn::getDescription() {
443 return(columnDescription);
444}
445
446/***********************************************************************************************
447 * setDescription *
448 * *
449 * C++ Arguments: char *description *
450 * *
451 * Results: none *
452 ***********************************************************************************************/
453void SDDSColumn::setDescription(char *description) {
454 if (columnDescription != NULL)
455 SDDS_free(columnDescription);
456 if (description == NULL)
457 columnDescription = NULL;
458 else {
459 columnDescription = (char*)SDDS_malloc(sizeof(char) * strlen(description) + 1);
460 strcpy(columnDescription, description);
461 }
462}
463
464/***********************************************************************************************
465 * getFormatString *
466 * *
467 * C++ Arguments: none *
468 * *
469 * Results: pointer to the format string (do not free the result) *
470 ***********************************************************************************************/
471char* SDDSColumn::getFormatString() {
472 return(columnFormatString);
473}
474
475/***********************************************************************************************
476 * setFormatString *
477 * *
478 * C++ Arguments: char *format_string *
479 * *
480 * Results: none *
481 ***********************************************************************************************/
482void SDDSColumn::setFormatString(char *format_string) {
483 if (columnFormatString != NULL)
484 SDDS_free(columnFormatString);
485 if (format_string == NULL)
486 columnFormatString = NULL;
487 else {
488 columnFormatString = (char*)SDDS_malloc(sizeof(char) * strlen(format_string) + 1);
489 strcpy(columnFormatString, format_string);
490 }
491}
492
493/***********************************************************************************************
494 * getFieldLength *
495 * *
496 * C++ Arguments: none *
497 * *
498 * Results: the column field length in integer form *
499 ***********************************************************************************************/
500uint32_t SDDSColumn::getFieldLength() {
501 return(columnFieldLength);
502}
503
504/***********************************************************************************************
505 * setFieldLength *
506 * *
507 * C++ Arguments:uint32_t field_length *
508 * *
509 * Results: none *
510 ***********************************************************************************************/
511void SDDSColumn::setFieldLength(uint32_t field_length) {
512 columnFieldLength = field_length;
513}
514
515/***********************************************************************************************
516 * getType *
517 * *
518 * C++ Arguments: none *
519 * *
520 * Results: the column type in integer form *
521 ***********************************************************************************************/
522int32_t SDDSColumn::getType() {
523 return(columnType);
524}
525
526/***********************************************************************************************
527 * setType *
528 * *
529 * C++ Arguments:int32_t type *
530 * *
531 * Results: none *
532 ***********************************************************************************************/
533void SDDSColumn::setType(int32_t type) {
534 columnType = type;
535}
536
537/***********************************************************************************************
538 * getPageCount *
539 * *
540 * C++ Arguments: none *
541 * *
542 * Results: the page count *
543 ***********************************************************************************************/
544uint32_t SDDSColumn::getPageCount() {
545 return(pageCount);
546}
547
548/***********************************************************************************************
549 * getRowCount *
550 * *
551 * C++ Arguments: uint32_t page *
552 * *
553 * Results: the row count on success *
554 * 0 on failure *
555 ***********************************************************************************************/
556uint32_t SDDSColumn::getRowCount(uint32_t page) {
557 if (rowCount == NULL) {
558 return(0);
559 }
560 if ((page == 0) || (page > pageCount)) {
561 return(0);
562 }
563 return(rowCount[page-1]);
564}
565
566
567
568/***********************************************************************************************
569 * setValues *
570 * *
571 * C++ Arguments: int16_t *values, uint32_t page, uint32_t startRow, uint32_t rows *
572 * uint16_t *value, uint32_t page, uint32_t startRow, uint32_t rows *
573 * int32_t *values, uint32_t page, uint32_t startRow, uint32_t rows *
574 * uint32_t *value, uint32_t page, uint32_t startRow, uint32_t rows *
575 * float *value, uint32_t page, uint32_t startRow, uint32_t rows *
576 * double *value, uint32_t page, uint32_t startRow, uint32_t rows *
577 * char **value, uint32_t page, uint32_t startRow, uint32_t rows *
578 * char *value, uint32_t page, uint32_t startRow, uint32_t rows *
579 * *
580 * Results: 0 for success *
581 * 1 for invalid page number *
582 * 2 for invalid startRow number *
583 * 3 for the case where the value cannot be converted to the proper column type *
584 * 4 for invalid column type *
585 ***********************************************************************************************/
586int32_t SDDSColumn::setValues(int16_t *values, uint32_t page, uint32_t startRow, uint32_t rows) {
587 uint32_t rowsNeeded, i, n=0, p;
588 bool newPage=false;
589 char s[SDDS_MAXLINE];
590 if (page == 0)
591 return(1);
592 if (startRow == 0)
593 return(2);
594 startRow--;
595 if (page > pageCount) {
596 newPage = true;
597 n = page - pageCount;
598 }
599 p = page - 1;
600 rowsNeeded = rows + startRow;
601 if (newPage) {
602 rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page);
603 rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page);
604 for (i=0; i<n; i++) {
605 rowCount[p-i] = 0;
606 rowsAllocated[p-i] = 0;
607 }
608 }
609 switch (columnType) {
610 case SDDS_INT16:
611 if (newPage) { /* new pages */
612 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
613 for (i=0; i<n; i++) {
614 int16Value[p-i] = (int16_t*)NULL;
615 }
616 }
617 if (rowsNeeded > rowsAllocated[p]) {
618 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
619 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]);
620 }
621 if (startRow > 0) {
622 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
623 int16Value[p][i] = (int16_t)0;
624 }
625 for (i=0; i<rows; i++) {
626 int16Value[p][i+startRow] = (int16_t)(values[i]);
627 }
628 } else {
629 memcpy(int16Value[p], values, rows * 2);
630 }
631 break;
632 case SDDS_UINT16:
633 if (newPage) { /* new pages */
634 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
635 for (i=0; i<n; i++) {
636 uint16Value[p-i] = (uint16_t*)NULL;
637 }
638 }
639 if (rowsNeeded > rowsAllocated[p]) {
640 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
641 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]);
642 }
643 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
644 uint16Value[p][i] = (uint16_t)0;
645 }
646 for (i=0; i<rows; i++) {
647 uint16Value[p][i+startRow] = (uint16_t)(values[i]);
648 }
649 break;
650 case SDDS_INT32:
651 if (newPage) { /* new pages */
652 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
653 for (i=0; i<n; i++) {
654 int32Value[p-i] = (int32_t*)NULL;
655 }
656 }
657 if (rowsNeeded > rowsAllocated[p]) {
658 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
659 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]);
660 }
661 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
662 int32Value[p][i] = (int32_t)0;
663 }
664 for (i=0; i<rows; i++) {
665 int32Value[p][i+startRow] = (int32_t)(values[i]);
666 }
667 break;
668 case SDDS_UINT32:
669 if (newPage) { /* new pages */
670 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
671 for (i=0; i<n; i++) {
672 uint32Value[p-i] = (uint32_t*)NULL;
673 }
674 }
675 if (rowsNeeded > rowsAllocated[p]) {
676 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
677 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]);
678 }
679 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
680 uint32Value[p][i] = (uint32_t)0;
681 }
682 for (i=0; i<rows; i++) {
683 uint32Value[p][i+startRow] = (uint32_t)(values[i]);
684 }
685 break;
686 case SDDS_REAL32:
687 if (newPage) { /* new pages */
688 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
689 for (i=0; i<n; i++) {
690 real32Value[p-i] = (float*)NULL;
691 }
692 }
693 if (rowsNeeded > rowsAllocated[p]) {
694 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
695 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]);
696 }
697 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
698 real32Value[p][i] = (float)0;
699 }
700 for (i=0; i<rows; i++) {
701 real32Value[p][i+startRow] = (float)(values[i]);
702 }
703 break;
704 case SDDS_REAL64:
705 if (newPage) { /* new pages */
706 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
707 for (i=0; i<n; i++) {
708 real64Value[p-i] = (double*)NULL;
709 }
710 }
711 if (rowsNeeded > rowsAllocated[p]) {
712 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
713 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]);
714 }
715 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
716 real64Value[p][i] = (double)0;
717 }
718 for (i=0; i<rows; i++) {
719 real64Value[p][i+startRow] = (double)(values[i]);
720 }
721 break;
722 case SDDS_STRING:
723 if (newPage) { /* new pages */
724 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
725 for (i=0; i<n; i++) {
726 stringValue[p-i] = (char**)NULL;
727 }
728 }
729 if (rowsNeeded > rowsAllocated[p]) {
730 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
731 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]);
732 }
733 for (i=rowCount[p] ; i<startRow; i++) { /* put NULL in skiped rows */
734 stringValue[p][i] = (char*)NULL;
735 }
736 for (i=0; i<rows; i++) {
737 sprintf(s, "%" PRId16, values[i]);
738 stringValue[p][i+startRow] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
739 strcpy(stringValue[p][i+startRow], s);
740 }
741 break;
742 case SDDS_CHARACTER:
743 if (newPage) { /* new pages */
744 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
745 for (i=0; i<n; i++) {
746 charValue[p-i] = (char*)NULL;
747 }
748 }
749 if (rowsNeeded > rowsAllocated[p]) {
750 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
751 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]);
752 }
753 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
754 charValue[p][i] = (char)0;
755 }
756 for (i=0; i<rows; i++) {
757 charValue[p][i+startRow] = (char)(values[i]);
758 }
759 break;
760 default:
761 return(4);
762 }
763 if (newPage) {
764 pageCount = page;
765 }
766 if (rowCount[p] < rowsNeeded) {
767 rowCount[p] = rowsNeeded;
768 }
769 return(0);
770}
771
772int32_t SDDSColumn::setValues(uint16_t *values, uint32_t page, uint32_t startRow, uint32_t rows) {
773 uint32_t rowsNeeded, i, n=0, p;
774 bool newPage=false;
775 char s[SDDS_MAXLINE];
776 if (page < 1)
777 return(1);
778 if (startRow == 0)
779 return(2);
780 startRow--;
781 if (page > pageCount) {
782 newPage = true;
783 n = page - pageCount;
784 }
785 p = page - 1;
786 rowsNeeded = rows + startRow;
787 if (newPage) {
788 rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page);
789 rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page);
790 for (i=0; i<n; i++) {
791 rowCount[p-i] = 0;
792 rowsAllocated[p-i] = 0;
793 }
794 }
795 switch (columnType) {
796 case SDDS_INT16:
797 if (newPage) { /* new pages */
798 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
799 for (i=0; i<n; i++) {
800 int16Value[p-i] = (int16_t*)NULL;
801 }
802 }
803 if (rowsNeeded > rowsAllocated[p]) {
804 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
805 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]);
806 }
807 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
808 int16Value[p][i] = (int16_t)0;
809 }
810 for (i=0; i<rows; i++) {
811 int16Value[p][i+startRow] = (int16_t)(values[i]);
812 }
813 break;
814 case SDDS_UINT16:
815 if (newPage) { /* new pages */
816 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
817 for (i=0; i<n; i++) {
818 uint16Value[p-i] = (uint16_t*)NULL;
819 }
820 }
821 if (rowsNeeded > rowsAllocated[p]) {
822 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
823 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]);
824 }
825 if (startRow > 0) {
826 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
827 uint16Value[p][i] = (uint16_t)0;
828 }
829 for (i=0; i<rows; i++) {
830 uint16Value[p][i+startRow] = (uint16_t)(values[i]);
831 }
832 } else {
833 memcpy(uint16Value[p], values, rows * 2);
834 }
835 break;
836 case SDDS_INT32:
837 if (newPage) { /* new pages */
838 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
839 for (i=0; i<n; i++) {
840 int32Value[p-i] = (int32_t*)NULL;
841 }
842 }
843 if (rowsNeeded > rowsAllocated[p]) {
844 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
845 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]);
846 }
847 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
848 int32Value[p][i] = (int32_t)0;
849 }
850 for (i=0; i<rows; i++) {
851 int32Value[p][i+startRow] = (int32_t)(values[i]);
852 }
853 break;
854 case SDDS_UINT32:
855 if (newPage) { /* new pages */
856 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
857 for (i=0; i<n; i++) {
858 uint32Value[p-i] = (uint32_t*)NULL;
859 }
860 }
861 if (rowsNeeded > rowsAllocated[p]) {
862 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
863 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]);
864 }
865 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
866 uint32Value[p][i] = (uint32_t)0;
867 }
868 for (i=0; i<rows; i++) {
869 uint32Value[p][i+startRow] = (uint32_t)(values[i]);
870 }
871 break;
872 case SDDS_REAL32:
873 if (newPage) { /* new pages */
874 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
875 for (i=0; i<n; i++) {
876 real32Value[p-i] = (float*)NULL;
877 }
878 }
879 if (rowsNeeded > rowsAllocated[p]) {
880 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
881 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]);
882 }
883 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
884 real32Value[p][i] = (float)0;
885 }
886 for (i=0; i<rows; i++) {
887 real32Value[p][i+startRow] = (float)(values[i]);
888 }
889 break;
890 case SDDS_REAL64:
891 if (newPage) { /* new pages */
892 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
893 for (i=0; i<n; i++) {
894 real64Value[p-i] = (double*)NULL;
895 }
896 }
897 if (rowsNeeded > rowsAllocated[p]) {
898 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
899 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]);
900 }
901 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
902 real64Value[p][i] = (double)0;
903 }
904 for (i=0; i<rows; i++) {
905 real64Value[p][i+startRow] = (double)(values[i]);
906 }
907 break;
908 case SDDS_STRING:
909 if (newPage) { /* new pages */
910 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
911 for (i=0; i<n; i++) {
912 stringValue[p-i] = (char**)NULL;
913 }
914 }
915 if (rowsNeeded > rowsAllocated[p]) {
916 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
917 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]);
918 }
919 for (i=rowCount[p] ; i<startRow; i++) { /* put NULL in skiped rows */
920 stringValue[p][i] = (char*)NULL;
921 }
922 for (i=0; i<rows; i++) {
923 sprintf(s, "%" PRIu16, values[i]);
924 stringValue[p][i+startRow] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
925 strcpy(stringValue[p][i+startRow], s);
926 }
927 break;
928 case SDDS_CHARACTER:
929 if (newPage) { /* new pages */
930 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
931 for (i=0; i<n; i++) {
932 charValue[p-i] = (char*)NULL;
933 }
934 }
935 if (rowsNeeded > rowsAllocated[p]) {
936 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
937 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]);
938 }
939 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
940 charValue[p][i] = (char)0;
941 }
942 for (i=0; i<rows; i++) {
943 charValue[p][i+startRow] = (char)(values[i]);
944 }
945 break;
946 default:
947 return(4);
948 }
949 if (newPage) {
950 pageCount = page;
951 }
952 if (rowCount[p] < rowsNeeded) {
953 rowCount[p] = rowsNeeded;
954 }
955 return(0);
956}
957
958int32_t SDDSColumn::setValues(int32_t *values, uint32_t page, uint32_t startRow, uint32_t rows) {
959 uint32_t rowsNeeded, i, n=0, p;;
960 bool newPage=false;
961 char s[SDDS_MAXLINE];
962 if (page < 1)
963 return(1);
964 if (startRow == 0)
965 return(2);
966 startRow--;
967 if (page > pageCount) {
968 newPage = true;
969 n = page - pageCount;
970 }
971 p = page - 1;
972 rowsNeeded = rows + startRow;
973 if (newPage) {
974 rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page);
975 rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page);
976 for (i=0; i<n; i++) {
977 rowCount[p-i] = 0;
978 rowsAllocated[p-i] = 0;
979 }
980 }
981 switch (columnType) {
982 case SDDS_INT16:
983 if (newPage) { /* new pages */
984 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
985 for (i=0; i<n; i++) {
986 int16Value[p-i] = (int16_t*)NULL;
987 }
988 }
989 if (rowsNeeded > rowsAllocated[p]) {
990 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
991 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]);
992 }
993 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
994 int16Value[p][i] = (int16_t)0;
995 }
996 for (i=0; i<rows; i++) {
997 int16Value[p][i+startRow] = (int16_t)(values[i]);
998 }
999 break;
1000 case SDDS_UINT16:
1001 if (newPage) { /* new pages */
1002 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
1003 for (i=0; i<n; i++) {
1004 uint16Value[p-i] = (uint16_t*)NULL;
1005 }
1006 }
1007 if (rowsNeeded > rowsAllocated[p]) {
1008 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1009 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]);
1010 }
1011 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1012 uint16Value[p][i] = (uint16_t)0;
1013 }
1014 for (i=0; i<rows; i++) {
1015 uint16Value[p][i+startRow] = (uint16_t)(values[i]);
1016 }
1017 break;
1018 case SDDS_INT32:
1019 if (newPage) { /* new pages */
1020 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
1021 for (i=0; i<n; i++) {
1022 int32Value[p-i] = (int32_t*)NULL;
1023 }
1024 }
1025 if (rowsNeeded > rowsAllocated[p]) {
1026 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1027 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]);
1028 }
1029 if (startRow > 0) {
1030 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1031 int32Value[p][i] = (int32_t)0;
1032 }
1033 for (i=0; i<rows; i++) {
1034 int32Value[p][i+startRow] = (int32_t)(values[i]);
1035 }
1036 } else {
1037 memcpy(int32Value[p], values, rows * 4);
1038 }
1039 break;
1040 case SDDS_UINT32:
1041 if (newPage) { /* new pages */
1042 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
1043 for (i=0; i<n; i++) {
1044 uint32Value[p-i] = (uint32_t*)NULL;
1045 }
1046 }
1047 if (rowsNeeded > rowsAllocated[p]) {
1048 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1049 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]);
1050 }
1051 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1052 uint32Value[p][i] = (uint32_t)0;
1053 }
1054 for (i=0; i<rows; i++) {
1055 uint32Value[p][i+startRow] = (uint32_t)(values[i]);
1056 }
1057 break;
1058 case SDDS_REAL32:
1059 if (newPage) { /* new pages */
1060 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
1061 for (i=0; i<n; i++) {
1062 real32Value[p-i] = (float*)NULL;
1063 }
1064 }
1065 if (rowsNeeded > rowsAllocated[p]) {
1066 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1067 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]);
1068 }
1069 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1070 real32Value[p][i] = (float)0;
1071 }
1072 for (i=0; i<rows; i++) {
1073 real32Value[p][i+startRow] = (float)(values[i]);
1074 }
1075 break;
1076 case SDDS_REAL64:
1077 if (newPage) { /* new pages */
1078 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
1079 for (i=0; i<n; i++) {
1080 real64Value[p-i] = (double*)NULL;
1081 }
1082 }
1083 if (rowsNeeded > rowsAllocated[p]) {
1084 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1085 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]);
1086 }
1087 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1088 real64Value[p][i] = (double)0;
1089 }
1090 for (i=0; i<rows; i++) {
1091 real64Value[p][i+startRow] = (double)(values[i]);
1092 }
1093 break;
1094 case SDDS_STRING:
1095 if (newPage) { /* new pages */
1096 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
1097 for (i=0; i<n; i++) {
1098 stringValue[p-i] = (char**)NULL;
1099 }
1100 }
1101 if (rowsNeeded > rowsAllocated[p]) {
1102 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1103 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]);
1104 }
1105 for (i=rowCount[p] ; i<startRow; i++) { /* put NULL in skiped rows */
1106 stringValue[p][i] = (char*)NULL;
1107 }
1108 for (i=0; i<rows; i++) {
1109 sprintf(s, "%" PRId32, values[i]);
1110 stringValue[p][i+startRow] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
1111 strcpy(stringValue[p][i+startRow], s);
1112 }
1113 break;
1114 case SDDS_CHARACTER:
1115 if (newPage) { /* new pages */
1116 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
1117 for (i=0; i<n; i++) {
1118 charValue[p-i] = (char*)NULL;
1119 }
1120 }
1121 if (rowsNeeded > rowsAllocated[p]) {
1122 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1123 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]);
1124 }
1125 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1126 charValue[p][i] = (char)0;
1127 }
1128 for (i=0; i<rows; i++) {
1129 charValue[p][i+startRow] = (char)(values[i]);
1130 }
1131 break;
1132 default:
1133 return(4);
1134 }
1135 if (newPage) {
1136 pageCount = page;
1137 }
1138 if (rowCount[p] < rowsNeeded) {
1139 rowCount[p] = rowsNeeded;
1140 }
1141 return(0);
1142}
1143
1144int32_t SDDSColumn::setValues(uint32_t *values, uint32_t page, uint32_t startRow, uint32_t rows) {
1145 uint32_t rowsNeeded, i, n=0, p;
1146 bool newPage=false;
1147 char s[SDDS_MAXLINE];
1148 if (page == 0)
1149 return(1);
1150 if (startRow == 0)
1151 return(2);
1152 startRow--;
1153 if (page > pageCount) {
1154 newPage = true;
1155 n = page - pageCount;
1156 }
1157 p = page - 1;
1158 rowsNeeded = rows + startRow;
1159 if (newPage) {
1160 rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page);
1161 rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page);
1162 for (i=0; i<n; i++) {
1163 rowCount[p-i] = 0;
1164 rowsAllocated[p-i] = 0;
1165 }
1166 }
1167 switch (columnType) {
1168 case SDDS_INT16:
1169 if (newPage) { /* new pages */
1170 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
1171 for (i=0; i<n; i++) {
1172 int16Value[p-i] = (int16_t*)NULL;
1173 }
1174 }
1175 if (rowsNeeded > rowsAllocated[p]) {
1176 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1177 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]);
1178 }
1179 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1180 int16Value[p][i] = (int16_t)0;
1181 }
1182 for (i=0; i<rows; i++) {
1183 int16Value[p][i+startRow] = (int16_t)(values[i]);
1184 }
1185 break;
1186 case SDDS_UINT16:
1187 if (newPage) { /* new pages */
1188 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
1189 for (i=0; i<n; i++) {
1190 uint16Value[p-i] = (uint16_t*)NULL;
1191 }
1192 }
1193 if (rowsNeeded > rowsAllocated[p]) {
1194 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1195 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]);
1196 }
1197 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1198 uint16Value[p][i] = (uint16_t)0;
1199 }
1200 for (i=0; i<rows; i++) {
1201 uint16Value[p][i+startRow] = (uint16_t)(values[i]);
1202 }
1203 break;
1204 case SDDS_INT32:
1205 if (newPage) { /* new pages */
1206 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
1207 for (i=0; i<n; i++) {
1208 int32Value[p-i] = (int32_t*)NULL;
1209 }
1210 }
1211 if (rowsNeeded > rowsAllocated[p]) {
1212 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1213 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]);
1214 }
1215 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1216 int32Value[p][i] = (int32_t)0;
1217 }
1218 for (i=0; i<rows; i++) {
1219 int32Value[p][i+startRow] = (int32_t)(values[i]);
1220 }
1221 break;
1222 case SDDS_UINT32:
1223 if (newPage) { /* new pages */
1224 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
1225 for (i=0; i<n; i++) {
1226 uint32Value[p-i] = (uint32_t*)NULL;
1227 }
1228 }
1229 if (rowsNeeded > rowsAllocated[p]) {
1230 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1231 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]);
1232 }
1233 if (startRow > 0) {
1234 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1235 uint32Value[p][i] = (uint32_t)0;
1236 }
1237 for (i=0; i<rows; i++) {
1238 uint32Value[p][i+startRow] = (uint32_t)(values[i]);
1239 }
1240 } else {
1241 memcpy(uint32Value[p], values, rows * 4);
1242 }
1243 break;
1244 case SDDS_REAL32:
1245 if (newPage) { /* new pages */
1246 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
1247 for (i=0; i<n; i++) {
1248 real32Value[p-i] = (float*)NULL;
1249 }
1250 }
1251 if (rowsNeeded > rowsAllocated[p]) {
1252 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1253 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]);
1254 }
1255 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1256 real32Value[p][i] = (float)0;
1257 }
1258 for (i=0; i<rows; i++) {
1259 real32Value[p][i+startRow] = (float)(values[i]);
1260 }
1261 break;
1262 case SDDS_REAL64:
1263 if (newPage) { /* new pages */
1264 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
1265 for (i=0; i<n; i++) {
1266 real64Value[p-i] = (double*)NULL;
1267 }
1268 }
1269 if (rowsNeeded > rowsAllocated[p]) {
1270 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1271 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]);
1272 }
1273 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1274 real64Value[p][i] = (double)0;
1275 }
1276 for (i=0; i<rows; i++) {
1277 real64Value[p][i+startRow] = (double)(values[i]);
1278 }
1279 break;
1280 case SDDS_STRING:
1281 if (newPage) { /* new pages */
1282 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
1283 for (i=0; i<n; i++) {
1284 stringValue[p-i] = (char**)NULL;
1285 }
1286 }
1287 if (rowsNeeded > rowsAllocated[p]) {
1288 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1289 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]);
1290 }
1291 for (i=rowCount[p] ; i<startRow; i++) { /* put NULL in skiped rows */
1292 stringValue[p][i] = (char*)NULL;
1293 }
1294 for (i=0; i<rows; i++) {
1295 sprintf(s, "%" PRIu32, values[i]);
1296 stringValue[p][i+startRow] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
1297 strcpy(stringValue[p][i+startRow], s);
1298 }
1299 break;
1300 case SDDS_CHARACTER:
1301 if (newPage) { /* new pages */
1302 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
1303 for (i=0; i<n; i++) {
1304 charValue[p-i] = (char*)NULL;
1305 }
1306 }
1307 if (rowsNeeded > rowsAllocated[p]) {
1308 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1309 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]);
1310 }
1311 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1312 charValue[p][i] = (char)0;
1313 }
1314 for (i=0; i<rows; i++) {
1315 charValue[p][i+startRow] = (char)(values[i]);
1316 }
1317 break;
1318 default:
1319 return(4);
1320 }
1321 if (newPage) {
1322 pageCount = page;
1323 }
1324 if (rowCount[p] < rowsNeeded) {
1325 rowCount[p] = rowsNeeded;
1326 }
1327 return(0);
1328}
1329
1330int32_t SDDSColumn::setValues(float *values, uint32_t page, uint32_t startRow, uint32_t rows) {
1331 uint32_t rowsNeeded, i, n=0, p;
1332 bool newPage=false;
1333 char s[SDDS_MAXLINE];
1334 if (page == 0)
1335 return(1);
1336 if (startRow == 0)
1337 return(2);
1338 startRow--;
1339 if (page > pageCount) {
1340 newPage = true;
1341 n = page - pageCount;
1342 }
1343 p = page - 1;
1344 rowsNeeded = rows + startRow;
1345 if (newPage) {
1346 rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page);
1347 rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page);
1348 for (i=0; i<n; i++) {
1349 rowCount[p-i] = 0;
1350 rowsAllocated[p-i] = 0;
1351 }
1352 }
1353 switch (columnType) {
1354 case SDDS_INT16:
1355 if (newPage) { /* new pages */
1356 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
1357 for (i=0; i<n; i++) {
1358 int16Value[p-i] = (int16_t*)NULL;
1359 }
1360 }
1361 if (rowsNeeded > rowsAllocated[p]) {
1362 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1363 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]);
1364 }
1365 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1366 int16Value[p][i] = (int16_t)0;
1367 }
1368 for (i=0; i<rows; i++) {
1369 int16Value[p][i+startRow] = (int16_t)(values[i]);
1370 }
1371 break;
1372 case SDDS_UINT16:
1373 if (newPage) { /* new pages */
1374 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
1375 for (i=0; i<n; i++) {
1376 uint16Value[p-i] = (uint16_t*)NULL;
1377 }
1378 }
1379 if (rowsNeeded > rowsAllocated[p]) {
1380 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1381 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]);
1382 }
1383 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1384 uint16Value[p][i] = (uint16_t)0;
1385 }
1386 for (i=0; i<rows; i++) {
1387 uint16Value[p][i+startRow] = (uint16_t)(values[i]);
1388 }
1389 break;
1390 case SDDS_INT32:
1391 if (newPage) { /* new pages */
1392 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
1393 for (i=0; i<n; i++) {
1394 int32Value[p-i] = (int32_t*)NULL;
1395 }
1396 }
1397 if (rowsNeeded > rowsAllocated[p]) {
1398 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1399 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]);
1400 }
1401 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1402 int32Value[p][i] = (int32_t)0;
1403 }
1404 for (i=0; i<rows; i++) {
1405 int32Value[p][i+startRow] = (int32_t)(values[i]);
1406 }
1407 break;
1408 case SDDS_UINT32:
1409 if (newPage) { /* new pages */
1410 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
1411 for (i=0; i<n; i++) {
1412 uint32Value[p-i] = (uint32_t*)NULL;
1413 }
1414 }
1415 if (rowsNeeded > rowsAllocated[p]) {
1416 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1417 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]);
1418 }
1419 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1420 uint32Value[p][i] = (uint32_t)0;
1421 }
1422 for (i=0; i<rows; i++) {
1423 uint32Value[p][i+startRow] = (uint32_t)(values[i]);
1424 }
1425 break;
1426 case SDDS_REAL32:
1427 if (newPage) { /* new pages */
1428 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
1429 for (i=0; i<n; i++) {
1430 real32Value[p-i] = (float*)NULL;
1431 }
1432 }
1433 if (rowsNeeded > rowsAllocated[p]) {
1434 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1435 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]);
1436 }
1437 if (startRow > 0) {
1438 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1439 real32Value[p][i] = (float)0;
1440 }
1441 for (i=0; i<rows; i++) {
1442 real32Value[p][i+startRow] = (float)(values[i]);
1443 }
1444 } else {
1445 memcpy(real32Value[p], values, rows * 4);
1446 }
1447 break;
1448 case SDDS_REAL64:
1449 if (newPage) { /* new pages */
1450 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
1451 for (i=0; i<n; i++) {
1452 real64Value[p-i] = (double*)NULL;
1453 }
1454 }
1455 if (rowsNeeded > rowsAllocated[p]) {
1456 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1457 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]);
1458 }
1459 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1460 real64Value[p][i] = (double)0;
1461 }
1462 for (i=0; i<rows; i++) {
1463 real64Value[p][i+startRow] = (double)(values[i]);
1464 }
1465 break;
1466 case SDDS_STRING:
1467 if (newPage) { /* new pages */
1468 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
1469 for (i=0; i<n; i++) {
1470 stringValue[p-i] = (char**)NULL;
1471 }
1472 }
1473 if (rowsNeeded > rowsAllocated[p]) {
1474 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1475 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]);
1476 }
1477 for (i=rowCount[p] ; i<startRow; i++) { /* put NULL in skiped rows */
1478 stringValue[p][i] = (char*)NULL;
1479 }
1480 for (i=0; i<rows; i++) {
1481 sprintf(s, "%lf", values[i]);
1482 stringValue[p][i+startRow] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
1483 strcpy(stringValue[p][i+startRow], s);
1484 }
1485 break;
1486 case SDDS_CHARACTER:
1487 if (newPage) { /* new pages */
1488 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
1489 for (i=0; i<n; i++) {
1490 charValue[p-i] = (char*)NULL;
1491 }
1492 }
1493 if (rowsNeeded > rowsAllocated[p]) {
1494 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1495 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]);
1496 }
1497 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1498 charValue[p][i] = (char)0;
1499 }
1500 for (i=0; i<rows; i++) {
1501 charValue[p][i+startRow] = (char)(values[i]);
1502 }
1503 break;
1504 default:
1505 return(4);
1506 }
1507 if (newPage) {
1508 pageCount = page;
1509 }
1510 if (rowCount[p] < rowsNeeded) {
1511 rowCount[p] = rowsNeeded;
1512 }
1513 return(0);
1514}
1515
1516int32_t SDDSColumn::setValues(double *values, uint32_t page, uint32_t startRow, uint32_t rows) {
1517 uint32_t rowsNeeded, i, n=0, p;
1518 bool newPage=false;
1519 char s[SDDS_MAXLINE];
1520 if (page == 0)
1521 return(1);
1522 if (startRow == 0)
1523 return(2);
1524 startRow--;
1525 if (page > pageCount) {
1526 newPage = true;
1527 n = page - pageCount;
1528 }
1529 p = page - 1;
1530 rowsNeeded = rows + startRow;
1531 if (newPage) {
1532 rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page);
1533 rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page);
1534 for (i=0; i<n; i++) {
1535 rowCount[p-i] = 0;
1536 rowsAllocated[p-i] = 0;
1537 }
1538 }
1539 switch (columnType) {
1540 case SDDS_INT16:
1541 if (newPage) { /* new pages */
1542 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
1543 for (i=0; i<n; i++) {
1544 int16Value[p-i] = (int16_t*)NULL;
1545 }
1546 }
1547 if (rowsNeeded > rowsAllocated[p]) {
1548 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1549 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]);
1550 }
1551 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1552 int16Value[p][i] = (int16_t)0;
1553 }
1554 for (i=0; i<rows; i++) {
1555 int16Value[p][i+startRow] = (int16_t)(values[i]);
1556 }
1557 break;
1558 case SDDS_UINT16:
1559 if (newPage) { /* new pages */
1560 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
1561 for (i=0; i<n; i++) {
1562 uint16Value[p-i] = (uint16_t*)NULL;
1563 }
1564 }
1565 if (rowsNeeded > rowsAllocated[p]) {
1566 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1567 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]);
1568 }
1569 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1570 uint16Value[p][i] = (uint16_t)0;
1571 }
1572 for (i=0; i<rows; i++) {
1573 uint16Value[p][i+startRow] = (uint16_t)(values[i]);
1574 }
1575 break;
1576 case SDDS_INT32:
1577 if (newPage) { /* new pages */
1578 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
1579 for (i=0; i<n; i++) {
1580 int32Value[p-i] = (int32_t*)NULL;
1581 }
1582 }
1583 if (rowsNeeded > rowsAllocated[p]) {
1584 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1585 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]);
1586 }
1587 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1588 int32Value[p][i] = (int32_t)0;
1589 }
1590 for (i=0; i<rows; i++) {
1591 int32Value[p][i+startRow] = (int32_t)(values[i]);
1592 }
1593 break;
1594 case SDDS_UINT32:
1595 if (newPage) { /* new pages */
1596 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
1597 for (i=0; i<n; i++) {
1598 uint32Value[p-i] = (uint32_t*)NULL;
1599 }
1600 }
1601 if (rowsNeeded > rowsAllocated[p]) {
1602 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1603 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]);
1604 }
1605 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1606 uint32Value[p][i] = (uint32_t)0;
1607 }
1608 for (i=0; i<rows; i++) {
1609 uint32Value[p][i+startRow] = (uint32_t)(values[i]);
1610 }
1611 break;
1612 case SDDS_REAL32:
1613 if (newPage) { /* new pages */
1614 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
1615 for (i=0; i<n; i++) {
1616 real32Value[p-i] = (float*)NULL;
1617 }
1618 }
1619 if (rowsNeeded > rowsAllocated[p]) {
1620 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1621 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]);
1622 }
1623 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1624 real32Value[p][i] = (float)0;
1625 }
1626 for (i=0; i<rows; i++) {
1627 real32Value[p][i+startRow] = (float)(values[i]);
1628 }
1629 break;
1630 case SDDS_REAL64:
1631 if (newPage) { /* new pages */
1632 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
1633 for (i=0; i<n; i++) {
1634 real64Value[p-i] = (double*)NULL;
1635 }
1636 }
1637 if (rowsNeeded > rowsAllocated[p]) {
1638 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1639 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]);
1640 }
1641 if (startRow > 0) {
1642 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1643 real64Value[p][i] = (double)0;
1644 }
1645 for (i=0; i<rows; i++) {
1646 real64Value[p][i+startRow] = (double)(values[i]);
1647 }
1648 } else {
1649 memcpy(real64Value[p], values, rows * 8);
1650 }
1651 break;
1652 case SDDS_STRING:
1653 if (newPage) { /* new pages */
1654 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
1655 for (i=0; i<n; i++) {
1656 stringValue[p-i] = (char**)NULL;
1657 }
1658 }
1659 if (rowsNeeded > rowsAllocated[p]) {
1660 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1661 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]);
1662 }
1663 for (i=rowCount[p] ; i<startRow; i++) { /* put NULL in skiped rows */
1664 stringValue[p][i] = (char*)NULL;
1665 }
1666 for (i=0; i<rows; i++) {
1667 sprintf(s, "%lf", values[i]);
1668 stringValue[p][i+startRow] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
1669 strcpy(stringValue[p][i+startRow], s);
1670 }
1671 break;
1672 case SDDS_CHARACTER:
1673 if (newPage) { /* new pages */
1674 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
1675 for (i=0; i<n; i++) {
1676 charValue[p-i] = (char*)NULL;
1677 }
1678 }
1679 if (rowsNeeded > rowsAllocated[p]) {
1680 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1681 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]);
1682 }
1683 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1684 charValue[p][i] = (char)0;
1685 }
1686 for (i=0; i<rows; i++) {
1687 charValue[p][i+startRow] = (char)(values[i]);
1688 }
1689 break;
1690 default:
1691 return(4);
1692 }
1693 if (newPage) {
1694 pageCount = page;
1695 }
1696 if (rowCount[p] < rowsNeeded) {
1697 rowCount[p] = rowsNeeded;
1698 }
1699 return(0);
1700}
1701
1702int32_t SDDSColumn::setValues(char **values, uint32_t page, uint32_t startRow, uint32_t rows) {
1703 int32_t returnVal=0;
1704 uint32_t rowsNeeded, i, n=0, p;
1705 bool newPage=false;
1706 int64_t *iValue=NULL;
1707 double *dValue=NULL;
1708 if (page == 0)
1709 return(1);
1710 if (startRow == 0)
1711 return(2);
1712
1713 if (SDDS_INTEGER_TYPE(columnType)) {
1714 iValue = (int64_t*)SDDS_malloc(sizeof(int64_t) * rows);
1715 for (i=0; i<rows; i++) {
1716 iValue[i] = strtoll(values[i], (char**)NULL, 10);
1717 if ((iValue[i] == LLONG_MIN) || (iValue[i] == LLONG_MAX)) {
1718 /*unable to convert given string to integer*/
1719 returnVal=3;
1720 iValue[i]=0;
1721 }
1722 }
1723 } else if (SDDS_FLOATING_TYPE(columnType)) {
1724 dValue = (double*)SDDS_malloc(sizeof(double) * rows);
1725 for (i=0; i<rows; i++) {
1726 dValue[i] = strtod(values[i], (char**)NULL);
1727 if ((dValue[i] == HUGE_VAL) || (dValue[i] == -HUGE_VAL)) {
1728 /*unable to convert given string to floating point*/
1729 returnVal=3;
1730 dValue[i]=0;
1731 }
1732 }
1733 }
1734
1735 startRow--;
1736 if (page > pageCount) {
1737 newPage = true;
1738 n = page - pageCount;
1739 }
1740 p = page - 1;
1741 rowsNeeded = rows + startRow;
1742 if (newPage) {
1743 rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page);
1744 rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page);
1745 for (i=0; i<n; i++) {
1746 rowCount[p-i] = 0;
1747 rowsAllocated[p-i] = 0;
1748 }
1749 }
1750 switch (columnType) {
1751 case SDDS_INT16:
1752 if (newPage) { /* new pages */
1753 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
1754 for (i=0; i<n; i++) {
1755 int16Value[p-i] = (int16_t*)NULL;
1756 }
1757 }
1758 if (rowsNeeded > rowsAllocated[p]) {
1759 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1760 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]);
1761 }
1762 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1763 int16Value[p][i] = (int16_t)0;
1764 }
1765 for (i=0; i<rows; i++) {
1766 int16Value[p][i+startRow] = (int16_t)(iValue[i]);
1767 }
1768 break;
1769 case SDDS_UINT16:
1770 if (newPage) { /* new pages */
1771 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
1772 for (i=0; i<n; i++) {
1773 uint16Value[p-i] = (uint16_t*)NULL;
1774 }
1775 }
1776 if (rowsNeeded > rowsAllocated[p]) {
1777 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1778 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]);
1779 }
1780 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1781 uint16Value[p][i] = (uint16_t)0;
1782 }
1783 for (i=0; i<rows; i++) {
1784 uint16Value[p][i+startRow] = (uint16_t)(iValue[i]);
1785 }
1786 break;
1787 case SDDS_INT32:
1788 if (newPage) { /* new pages */
1789 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
1790 for (i=0; i<n; i++) {
1791 int32Value[p-i] = (int32_t*)NULL;
1792 }
1793 }
1794 if (rowsNeeded > rowsAllocated[p]) {
1795 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1796 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]);
1797 }
1798 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1799 int32Value[p][i] = (int32_t)0;
1800 }
1801 for (i=0; i<rows; i++) {
1802 int32Value[p][i+startRow] = (int32_t)(iValue[i]);
1803 }
1804 break;
1805 case SDDS_UINT32:
1806 if (newPage) { /* new pages */
1807 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
1808 for (i=0; i<n; i++) {
1809 uint32Value[p-i] = (uint32_t*)NULL;
1810 }
1811 }
1812 if (rowsNeeded > rowsAllocated[p]) {
1813 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1814 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]);
1815 }
1816 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1817 uint32Value[p][i] = (uint32_t)0;
1818 }
1819 for (i=0; i<rows; i++) {
1820 uint32Value[p][i+startRow] = (uint32_t)(iValue[i]);
1821 }
1822 break;
1823 case SDDS_REAL32:
1824 if (newPage) { /* new pages */
1825 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
1826 for (i=0; i<n; i++) {
1827 real32Value[p-i] = (float*)NULL;
1828 }
1829 }
1830 if (rowsNeeded > rowsAllocated[p]) {
1831 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1832 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]);
1833 }
1834 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1835 real32Value[p][i] = (float)0;
1836 }
1837 for (i=0; i<rows; i++) {
1838 real32Value[p][i+startRow] = (float)(dValue[i]);
1839 }
1840 break;
1841 case SDDS_REAL64:
1842 if (newPage) { /* new pages */
1843 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
1844 for (i=0; i<n; i++) {
1845 real64Value[p-i] = (double*)NULL;
1846 }
1847 }
1848 if (rowsNeeded > rowsAllocated[p]) {
1849 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1850 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]);
1851 }
1852 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1853 real64Value[p][i] = (double)0;
1854 }
1855 for (i=0; i<rows; i++) {
1856 real64Value[p][i+startRow] = (double)(dValue[i]);
1857 }
1858 break;
1859 case SDDS_STRING:
1860 if (newPage) { /* new pages */
1861 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
1862 for (i=0; i<n; i++) {
1863 stringValue[p-i] = (char**)NULL;
1864 }
1865 }
1866 if (rowsNeeded > rowsAllocated[p]) {
1867 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1868 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]);
1869 }
1870 for (i=rowCount[p] ; i<startRow; i++) { /* put NULL in skiped rows */
1871 stringValue[p][i] = (char*)NULL;
1872 }
1873 for (i=0; i<rows; i++) {
1874 stringValue[p][i+startRow] = (char*)SDDS_malloc(sizeof(char) * strlen(values[i]) + 1);
1875 strcpy(stringValue[p][i+startRow], values[i]);
1876 }
1877 break;
1878 case SDDS_CHARACTER:
1879 if (newPage) { /* new pages */
1880 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
1881 for (i=0; i<n; i++) {
1882 charValue[p-i] = (char*)NULL;
1883 }
1884 }
1885 if (rowsNeeded > rowsAllocated[p]) {
1886 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1887 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]);
1888 }
1889 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1890 charValue[p][i] = (char)0;
1891 }
1892 for (i=0; i<rows; i++) {
1893 charValue[p][i+startRow] = (char)(values[i][0]);
1894 }
1895 break;
1896 default:
1897 return(4);
1898 }
1899 if (newPage) {
1900 pageCount = page;
1901 }
1902 if (rowCount[p] < rowsNeeded) {
1903 rowCount[p] = rowsNeeded;
1904 }
1905 return(returnVal);
1906}
1907
1908int32_t SDDSColumn::setValues(char *values, uint32_t page, uint32_t startRow, uint32_t rows) {
1909 uint32_t rowsNeeded, i, n=0, p;
1910 bool newPage=false;
1911 char s[SDDS_MAXLINE];
1912 if (page == 0)
1913 return(1);
1914 if (startRow == 0)
1915 return(2);
1916 startRow--;
1917 if (page > pageCount) {
1918 newPage = true;
1919 n = page - pageCount;
1920 }
1921 p = page - 1;
1922 rowsNeeded = rows + startRow;
1923 if (newPage) {
1924 rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page);
1925 rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page);
1926 for (i=0; i<n; i++) {
1927 rowCount[p-i] = 0;
1928 rowsAllocated[p-i] = 0;
1929 }
1930 }
1931 switch (columnType) {
1932 case SDDS_INT16:
1933 if (newPage) { /* new pages */
1934 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
1935 for (i=0; i<n; i++) {
1936 int16Value[p-i] = (int16_t*)NULL;
1937 }
1938 }
1939 if (rowsNeeded > rowsAllocated[p]) {
1940 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1941 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]);
1942 }
1943 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1944 int16Value[p][i] = (int16_t)0;
1945 }
1946 for (i=0; i<rows; i++) {
1947 int16Value[p][i+startRow] = (int16_t)(values[i]);
1948 }
1949 break;
1950 case SDDS_UINT16:
1951 if (newPage) { /* new pages */
1952 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
1953 for (i=0; i<n; i++) {
1954 uint16Value[p-i] = (uint16_t*)NULL;
1955 }
1956 }
1957 if (rowsNeeded > rowsAllocated[p]) {
1958 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1959 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]);
1960 }
1961 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1962 uint16Value[p][i] = (uint16_t)0;
1963 }
1964 for (i=0; i<rows; i++) {
1965 uint16Value[p][i+startRow] = (uint16_t)(values[i]);
1966 }
1967 break;
1968 case SDDS_INT32:
1969 if (newPage) { /* new pages */
1970 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
1971 for (i=0; i<n; i++) {
1972 int32Value[p-i] = (int32_t*)NULL;
1973 }
1974 }
1975 if (rowsNeeded > rowsAllocated[p]) {
1976 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1977 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]);
1978 }
1979 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1980 int32Value[p][i] = (int32_t)0;
1981 }
1982 for (i=0; i<rows; i++) {
1983 int32Value[p][i+startRow] = (int32_t)(values[i]);
1984 }
1985 break;
1986 case SDDS_UINT32:
1987 if (newPage) { /* new pages */
1988 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
1989 for (i=0; i<n; i++) {
1990 uint32Value[p-i] = (uint32_t*)NULL;
1991 }
1992 }
1993 if (rowsNeeded > rowsAllocated[p]) {
1994 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
1995 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]);
1996 }
1997 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
1998 uint32Value[p][i] = (uint32_t)0;
1999 }
2000 for (i=0; i<rows; i++) {
2001 uint32Value[p][i+startRow] = (uint32_t)(values[i]);
2002 }
2003 break;
2004 case SDDS_REAL32:
2005 if (newPage) { /* new pages */
2006 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
2007 for (i=0; i<n; i++) {
2008 real32Value[p-i] = (float*)NULL;
2009 }
2010 }
2011 if (rowsNeeded > rowsAllocated[p]) {
2012 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
2013 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]);
2014 }
2015 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
2016 real32Value[p][i] = (float)0;
2017 }
2018 for (i=0; i<rows; i++) {
2019 real32Value[p][i+startRow] = (float)(values[i]);
2020 }
2021 break;
2022 case SDDS_REAL64:
2023 if (newPage) { /* new pages */
2024 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
2025 for (i=0; i<n; i++) {
2026 real64Value[p-i] = (double*)NULL;
2027 }
2028 }
2029 if (rowsNeeded > rowsAllocated[p]) {
2030 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
2031 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]);
2032 }
2033 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
2034 real64Value[p][i] = (double)0;
2035 }
2036 for (i=0; i<rows; i++) {
2037 real64Value[p][i+startRow] = (double)(values[i]);
2038 }
2039 break;
2040 case SDDS_STRING:
2041 if (newPage) { /* new pages */
2042 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
2043 for (i=0; i<n; i++) {
2044 stringValue[p-i] = (char**)NULL;
2045 }
2046 }
2047 if (rowsNeeded > rowsAllocated[p]) {
2048 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
2049 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]);
2050 }
2051 for (i=rowCount[p] ; i<startRow; i++) { /* put NULL in skiped rows */
2052 stringValue[p][i] = (char*)NULL;
2053 }
2054 for (i=0; i<rows; i++) {
2055 sprintf(s, "%" PRId32, values[i]);
2056 stringValue[p][i+startRow] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
2057 strcpy(stringValue[p][i+startRow], s);
2058 }
2059 break;
2060 case SDDS_CHARACTER:
2061 if (newPage) { /* new pages */
2062 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
2063 for (i=0; i<n; i++) {
2064 charValue[p-i] = (char*)NULL;
2065 }
2066 }
2067 if (rowsNeeded > rowsAllocated[p]) {
2068 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
2069 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]);
2070 }
2071 if (startRow > 0) {
2072 for (i=rowCount[p] ; i<startRow; i++) { /* put zeros in skiped rows */
2073 charValue[p][i] = (char)0;
2074 }
2075 for (i=0; i<rows; i++) {
2076 charValue[p][i+startRow] = (char)(values[i]);
2077 }
2078 } else {
2079 memcpy(charValue[p], values, rows);
2080 }
2081 break;
2082 default:
2083 return(4);
2084 }
2085 if (newPage) {
2086 pageCount = page;
2087 }
2088 if (rowCount[p] < rowsNeeded) {
2089 rowCount[p] = rowsNeeded;
2090 }
2091 return(0);
2092}
2093
2094/***********************************************************************************************
2095 * readAsciiValue *
2096 * *
2097 * C++ Arguments: char *value, uint32_t page *
2098 * *
2099 * Results: 0 for success *
2100 * 1 for failure *
2101 ***********************************************************************************************/
2102int32_t SDDSColumn::readAsciiValue(char **bigBuffer, int32_t *bigBufferSize, uint32_t page) {
2103 int32_t returnVal=0, length;
2104 uint32_t rowsNeeded, startRow, i, n=0, p;
2105 int64_t iValue=0;
2106 double dValue=0;
2107 bool newPage=false;
2108 static char *buffer=NULL;
2109 static int32_t bufferSize=0;
2110 if (page == 0) {
2111 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--invalid page number (SDDSColumn::readAsciiValue)");
2112 return(1);
2113 }
2114 startRow = getRowCount(page);
2115 if (startRow == UINT_MAX) {
2116 startRow = 0;
2117 }
2118 if (bufferSize==0) {
2119 bufferSize=SDDS_MAXLINE;
2120 buffer = (char*)SDDS_malloc(sizeof(*buffer)*(bufferSize));
2121 }
2122 length = *bigBufferSize;
2123 if (length < columnFieldLength) {
2124 length = columnFieldLength;
2125 }
2126 if (bufferSize <= length) {
2127 bufferSize = 2 * length;
2128 buffer = (char*)SDDS_realloc(buffer, sizeof(*buffer)*(bufferSize));
2129 }
2130 if (columnType != SDDS_STRING) {
2131 if (columnFieldLength) {
2132 if (columnFieldLength > *bigBufferSize) {
2133 strcpy(buffer, *bigBuffer);
2134 **bigBuffer = 0;
2135 *bigBufferSize = 0;
2136 } else {
2137 strncpy(buffer, *bigBuffer, columnFieldLength);
2138 buffer[columnFieldLength] = 0;
2139 *bigBuffer += columnFieldLength;
2140 *bigBufferSize -= columnFieldLength;
2141 }
2142 }
2143 }
2144 if (SDDS_INTEGER_TYPE(columnType)) {
2145 if (SDDS_getToken(bigBuffer, bigBufferSize, buffer, bufferSize) < 0) {
2146 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column (SDDSColumn::readAsciiValue)");
2147 returnVal=1;
2148 iValue=0;
2149 } else {
2150 iValue = strtoll(buffer, (char**)NULL, 10);
2151 if ((iValue == LLONG_MIN) || (iValue == LLONG_MAX)) {
2152 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--not a valid integer (SDDSColumn::readAsciiValue)");
2153 returnVal=1;
2154 iValue=0;
2155 }
2156 }
2157 } else if (SDDS_FLOATING_TYPE(columnType)) {
2158 if (SDDS_getToken(bigBuffer, bigBufferSize, buffer, bufferSize) < 0) {
2159 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column (SDDSColumn::readAsciiValue)");
2160 returnVal=1;
2161 dValue=0;
2162 } else {
2163 dValue = strtod(buffer, (char**)NULL);
2164 if ((dValue == HUGE_VAL) || (dValue == -HUGE_VAL)) {
2165 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--not a valid number (SDDSColumn::readAsciiValue)");
2166 returnVal=1;
2167 dValue=0;
2168 }
2169 }
2170 }
2171 if (page > pageCount) {
2172 newPage = true;
2173 n = page - pageCount;
2174 }
2175 p = page - 1;
2176 rowsNeeded = 1 + startRow;
2177 if (newPage) {
2178 rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page);
2179 rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page);
2180 for (i=0; i<n; i++) {
2181 rowCount[p-i] = 0;
2182 rowsAllocated[p-i] = 0;
2183 }
2184 }
2185 switch (columnType) {
2186 case SDDS_INT16:
2187 if (newPage) { /* new page */
2188 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
2189 for (i=0; i<n; i++) {
2190 int16Value[p-i] = NULL;
2191 }
2192 }
2193 if (rowsNeeded > rowsAllocated[p]) {
2194 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
2195 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]);
2196 }
2197 int16Value[p][startRow] = (int16_t)iValue;
2198 break;
2199 case SDDS_UINT16:
2200 if (newPage) { /* new page */
2201 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
2202 for (i=0; i<n; i++) {
2203 uint16Value[p-i] = NULL;
2204 }
2205 }
2206 if (rowsNeeded > rowsAllocated[p]) {
2207 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
2208 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]);
2209 }
2210 uint16Value[p][startRow] = (uint16_t)iValue;
2211 break;
2212 case SDDS_INT32:
2213 if (newPage) { /* new page */
2214 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
2215 for (i=0; i<n; i++) {
2216 int32Value[p-i] = NULL;
2217 }
2218 }
2219 if (rowsNeeded > rowsAllocated[p]) {
2220 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
2221 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]);
2222 }
2223 int32Value[p][startRow] = (int32_t)iValue;
2224 break;
2225 case SDDS_UINT32:
2226 if (newPage) { /* new page */
2227 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
2228 for (i=0; i<n; i++) {
2229 uint32Value[p-i] = NULL;
2230 }
2231 }
2232 if (rowsNeeded > rowsAllocated[p]) {
2233 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
2234 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]);
2235 }
2236 uint32Value[p][startRow] = (uint32_t)iValue;
2237 break;
2238 case SDDS_REAL32:
2239 if (newPage) { /* new pages */
2240 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
2241 for (i=0; i<n; i++) {
2242 real32Value[p-i] = NULL;
2243 }
2244 }
2245 if (rowsNeeded > rowsAllocated[p]) {
2246 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
2247 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]);
2248 }
2249 real32Value[p][startRow] = (float)dValue;
2250 break;
2251 case SDDS_REAL64:
2252 if (newPage) { /* new pages */
2253 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
2254 for (i=0; i<n; i++) {
2255 real64Value[p-i] = NULL;
2256 }
2257 }
2258 if (rowsNeeded > rowsAllocated[p]) {
2259 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
2260 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]);
2261 }
2262 real64Value[p][startRow] = (double)dValue;
2263 break;
2264 case SDDS_STRING:
2265 if (newPage) { /* new pages */
2266 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
2267 for (i=0; i<n; i++) {
2268 stringValue[p-i] = NULL;
2269 }
2270 }
2271 if (rowsNeeded > rowsAllocated[p]) {
2272 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
2273 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]);
2274 }
2275 length = strlen(*bigBuffer);
2276 if (length > 0) {
2277 if ((*bigBuffer)[length-1] == '\r') {
2278 (*bigBuffer)[length-1] = 0;
2279 }
2280 }
2281 if (SDDS_getToken(bigBuffer, bigBufferSize, buffer, bufferSize) < 0) {
2282 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column (SDDSColumn::readAsciiValue)");
2283 returnVal=1;
2284 stringValue[p][startRow] = (char*)SDDS_malloc(sizeof(char) * 4);
2285 strcpy(stringValue[p][startRow], "\"\"");
2286 } else {
2287 SDDS_interpretEscapes(buffer);
2288 stringValue[p][startRow] = (char*)SDDS_malloc(sizeof(char) * strlen(buffer) + 1);
2289 strcpy(stringValue[p][startRow], buffer);
2290 }
2291 break;
2292 case SDDS_CHARACTER:
2293 if (newPage) { /* new pages */
2294 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
2295 for (i=0; i<n; i++) {
2296 charValue[p-i] = NULL;
2297 }
2298 }
2299 if (rowsNeeded > rowsAllocated[p]) {
2300 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
2301 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]);
2302 }
2303 if (SDDS_getToken(bigBuffer, bigBufferSize, buffer, bufferSize) < 0) {
2304 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column (SDDSColumn::readAsciiValue)");
2305 returnVal=1;
2306 charValue[p][startRow] = '-';
2307 } else {
2308 charValue[p][startRow] = (char)(buffer[0]);
2309 }
2310 break;
2311 default:
2312 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--invalid column type (SDDSColumn::readAsciiValue)");
2313 return(1);
2314 }
2315 if (newPage) {
2316 pageCount = page;
2317 rowCount[p] = 1;
2318 } else {
2319 rowCount[p]++;
2320 }
2321 return(returnVal);
2322}
2323
2324/***********************************************************************************************
2325 * getInteralValues *
2326 * *
2327 * C++ Arguments: uint32_t page *
2328 * *
2329 * Results: pointer to values *
2330 * NULL for column value undefined *
2331 ***********************************************************************************************/
2332void* SDDSColumn::getInternalValues(uint32_t page) {
2333 uint32_t p;
2334 if ((page == 0) || (pageCount < page)) {
2335 ((SDDSFile*)sddsfile)->setError((char*)"Invalid page (SDDSColumn::getInternalValues)");
2336 return(NULL);
2337 }
2338 p = page - 1;
2339 if (rowCount[p] == 0) {
2340 return(NULL);
2341 }
2342 switch (columnType) {
2343 case SDDS_INT16:
2344 return(int16Value[p]);
2345 case SDDS_UINT16:
2346 return(uint16Value[p]);
2347 case SDDS_INT32:
2348 return(int32Value[p]);
2349 case SDDS_UINT32:
2350 return(uint32Value[p]);
2351 case SDDS_REAL32:
2352 return(real32Value[p]);
2353 case SDDS_REAL64:
2354 return(real64Value[p]);
2355 case SDDS_STRING:
2356 return(stringValue[p]);
2357 case SDDS_CHARACTER:
2358 return(charValue[p]);
2359 default:
2360 ((SDDSFile*)sddsfile)->setError((char*)"Invalid data type (SDDSColumn::getInternalValues)");
2361 return(NULL);
2362 }
2363}
2364
2365/***********************************************************************************************
2366 * getValuesInInt32 *
2367 * *
2368 * C++ Arguments: uint32_t page, int32_t *errorcode *
2369 * *
2370 * Results: pointer to values and errorcode=0 for success *
2371 * NULL and errorcode=1 for column value undefined *
2372 * NULL and errorcode=2 for the case where the value cannot be *
2373 * converted to the proper type *
2374 * NULL and errorcode=3 for invalid column type *
2375 ***********************************************************************************************/
2376int32_t* SDDSColumn::getValuesInInt32(uint32_t page, int32_t *errorcode) {
2377 int64_t iValue;
2378 int32_t* rValues;
2379 uint32_t p;
2380 uint32_t i;
2381 if ((page == 0) || (pageCount < page)) {
2382 *errorcode = 1;
2383 return((int32_t*)NULL);
2384 }
2385 *errorcode = 0;
2386 p = page - 1;
2387 if (rowCount[p] == 0) {
2388 return((int32_t*)NULL);
2389 }
2390 rValues = (int32_t*)SDDS_malloc(sizeof(int32_t) * rowCount[p]);
2391 switch (columnType) {
2392 case SDDS_INT16:
2393 for (i=0; i<rowCount[p]; i++)
2394 rValues[i] = (int32_t)int16Value[p][i];
2395 return((int32_t*)rValues);
2396 case SDDS_UINT16:
2397 for (i=0; i<rowCount[p]; i++)
2398 rValues[i] = (int32_t)uint16Value[p][i];
2399 return((int32_t*)rValues);
2400 case SDDS_INT32:
2401 for (i=0; i<rowCount[p]; i++)
2402 rValues[i] = (int32_t)int32Value[p][i];
2403 return((int32_t*)rValues);
2404 case SDDS_UINT32:
2405 for (i=0; i<rowCount[p]; i++)
2406 rValues[i] = (int32_t)uint32Value[p][i];
2407 return((int32_t*)rValues);
2408 case SDDS_REAL32:
2409 for (i=0; i<rowCount[p]; i++)
2410 rValues[i] = (int32_t)real32Value[p][i];
2411 return((int32_t*)rValues);
2412 case SDDS_REAL64:
2413 for (i=0; i<rowCount[p]; i++)
2414 rValues[i] = (int32_t)real64Value[p][i];
2415 return((int32_t*)rValues);
2416 case SDDS_STRING:
2417 for (i=0; i<rowCount[p]; i++) {
2418 iValue = strtoll(stringValue[p][i], (char**)NULL, 10);
2419 if ((iValue == LLONG_MIN) || (iValue == LLONG_MAX)) {
2420 /*unable to convert fixed value string to integer*/
2421 *errorcode = 2;
2422 SDDS_free(rValues);
2423 return((int32_t*)NULL);
2424 }
2425 rValues[i] = (int32_t)iValue;
2426 }
2427 return((int32_t*)rValues);
2428 case SDDS_CHARACTER:
2429 for (i=0; i<rowCount[p]; i++)
2430 rValues[i] = (int32_t)charValue[p][i];
2431 return((int32_t*)rValues);
2432 default:
2433 *errorcode = 3;
2434 return((int32_t*)NULL);
2435 }
2436}
2437
2438/***********************************************************************************************
2439 * getValuesInUInt32 *
2440 * *
2441 * C++ Arguments: uint32_t page, int32_t *errorcode *
2442 * *
2443 * Results: pointer to values and errorcode=0 for success *
2444 * NULL and errorcode=1 for column value undefined *
2445 * NULL and errorcode=2 for the case where the value cannot be *
2446 * converted to the proper type *
2447 * NULL and errorcode=3 for invalid column type *
2448 ***********************************************************************************************/
2449uint32_t* SDDSColumn::getValuesInUInt32(uint32_t page, int32_t *errorcode) {
2450 int64_t iValue;
2451 uint32_t* rValues;
2452 uint32_t i, p;
2453 if ((page == 0) || (pageCount < page)) {
2454 *errorcode = 1;
2455 return((uint32_t*)NULL);
2456 }
2457 *errorcode = 0;
2458 p = page - 1;
2459 if (rowCount[p] == 0) {
2460 return((uint32_t*)NULL);
2461 }
2462 rValues = (uint32_t*)SDDS_malloc(sizeof(uint32_t) * rowCount[p]);
2463 switch (columnType) {
2464 case SDDS_INT16:
2465 for (i=0; i<rowCount[p]; i++)
2466 rValues[i] = (uint32_t)int16Value[p][i];
2467 return((uint32_t*)rValues);
2468 case SDDS_UINT16:
2469 for (i=0; i<rowCount[p]; i++)
2470 rValues[i] = (uint32_t)uint16Value[p][i];
2471 return((uint32_t*)rValues);
2472 case SDDS_INT32:
2473 for (i=0; i<rowCount[p]; i++)
2474 rValues[i] = (uint32_t)int32Value[p][i];
2475 return((uint32_t*)rValues);
2476 case SDDS_UINT32:
2477 for (i=0; i<rowCount[p]; i++)
2478 rValues[i] = (uint32_t)uint32Value[p][i];
2479 return((uint32_t*)rValues);
2480 case SDDS_REAL32:
2481 for (i=0; i<rowCount[p]; i++)
2482 rValues[i] = (uint32_t)real32Value[p][i];
2483 return((uint32_t*)rValues);
2484 case SDDS_REAL64:
2485 for (i=0; i<rowCount[p]; i++)
2486 rValues[i] = (uint32_t)real64Value[p][i];
2487 return((uint32_t*)rValues);
2488 case SDDS_STRING:
2489 for (i=0; i<rowCount[p]; i++) {
2490 iValue = strtoll(stringValue[p][i], (char**)NULL, 10);
2491 if ((iValue == LLONG_MIN) || (iValue == LLONG_MAX)) {
2492 /*unable to convert fixed value string to integer*/
2493 *errorcode = 2;
2494 SDDS_free(rValues);
2495 return((uint32_t*)NULL);
2496 }
2497 rValues[i] = (uint32_t)iValue;
2498 }
2499 return((uint32_t*)rValues);
2500 case SDDS_CHARACTER:
2501 for (i=0; i<rowCount[p]; i++)
2502 rValues[i] = (uint32_t)charValue[p][i];
2503 return((uint32_t*)rValues);
2504 default:
2505 *errorcode = 3;
2506 return((uint32_t*)NULL);
2507 }
2508}
2509
2510/***********************************************************************************************
2511 * getValuesInDouble *
2512 * *
2513 * C++ Arguments: uint32_t page, int32_t *errorcode *
2514 * *
2515 * Results: pointer to values and errorcode=0 for success *
2516 * NULL and errorcode=1 for column value undefined *
2517 * NULL and errorcode=2 for the case where the value cannot be *
2518 * converted to the proper type *
2519 * NULL and errorcode=3 for invalid column type *
2520 ***********************************************************************************************/
2521double* SDDSColumn::getValuesInDouble(uint32_t page, int32_t *errorcode) {
2522 double dValue;
2523 double* rValues;
2524 uint32_t i, p;
2525 if ((page == 0) || (pageCount < page)) {
2526 *errorcode = 1;
2527 return((double*)NULL);
2528 }
2529 *errorcode = 0;
2530 p = page - 1;
2531 if (rowCount[p] == 0) {
2532 return((double*)NULL);
2533 }
2534 rValues = (double*)SDDS_malloc(sizeof(double) * rowCount[p]);
2535 switch (columnType) {
2536 case SDDS_INT16:
2537 for (i=0; i<rowCount[p]; i++)
2538 rValues[i] = (double)int16Value[p][i];
2539 return((double*)rValues);
2540 case SDDS_UINT16:
2541 for (i=0; i<rowCount[p]; i++)
2542 rValues[i] = (double)uint16Value[p][i];
2543 return((double*)rValues);
2544 case SDDS_INT32:
2545 for (i=0; i<rowCount[p]; i++)
2546 rValues[i] = (double)int32Value[p][i];
2547 return((double*)rValues);
2548 case SDDS_UINT32:
2549 for (i=0; i<rowCount[p]; i++)
2550 rValues[i] = (double)uint32Value[p][i];
2551 return((double*)rValues);
2552 case SDDS_REAL32:
2553 for (i=0; i<rowCount[p]; i++)
2554 rValues[i] = (double)real32Value[p][i];
2555 return((double*)rValues);
2556 case SDDS_REAL64:
2557 for (i=0; i<rowCount[p]; i++)
2558 rValues[i] = (double)real64Value[p][i];
2559 return((double*)rValues);
2560 case SDDS_STRING:
2561 for (i=0; i<rowCount[p]; i++) {
2562 dValue = strtod(stringValue[p][i], (char**)NULL);
2563 if ((dValue == HUGE_VAL) || (dValue == -HUGE_VAL)) {
2564 /*unable to convert string to floating point*/
2565 *errorcode = 2;
2566 SDDS_free(rValues);
2567 return((double*)NULL);
2568 }
2569 rValues[i] = (double)dValue;
2570 }
2571 return((double*)rValues);
2572 case SDDS_CHARACTER:
2573 for (i=0; i<rowCount[p]; i++)
2574 rValues[i] = (double)charValue[p][i];
2575 return((double*)rValues);
2576 default:
2577 *errorcode = 3;
2578 return((double*)NULL);
2579 }
2580}
2581
2582/***********************************************************************************************
2583 * getValuesInString *
2584 * *
2585 * C++ Arguments: uint32_t page, int32_t *errorcode *
2586 * *
2587 * Results: pointer to values and errorcode=0 for success *
2588 * NULL and errorcode=1 for column value undefined *
2589 * NULL and errorcode=2 for the case where the value cannot be *
2590 * converted to the proper type *
2591 * NULL and errorcode=3 for invalid column type *
2592 ***********************************************************************************************/
2593char** SDDSColumn::getValuesInString(uint32_t page, int32_t *errorcode) {
2594 char** rValues;
2595 uint32_t i, p;
2596 char s[SDDS_MAXLINE];
2597 if ((page == 0) || (pageCount < page)) {
2598 *errorcode = 1;
2599 return((char**)NULL);
2600 }
2601 *errorcode = 0;
2602 p = page - 1;
2603 if (rowCount[p] == 0) {
2604 return((char**)NULL);
2605 }
2606 rValues = (char**)SDDS_malloc(sizeof(char*) * rowCount[p]);
2607 switch (columnType) {
2608 case SDDS_INT16:
2609 for (i=0; i<rowCount[p]; i++) {
2610 sprintf(s, "%" PRId16, int16Value[p][i]);
2611 rValues[i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
2612 strcpy(rValues[i], s);
2613 }
2614 return((char**)rValues);
2615 case SDDS_UINT16:
2616 for (i=0; i<rowCount[p]; i++) {
2617 sprintf(s, "%" PRIu16, uint16Value[p][i]);
2618 rValues[i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
2619 strcpy(rValues[i], s);
2620 }
2621 return((char**)rValues);
2622 case SDDS_INT32:
2623 for (i=0; i<rowCount[p]; i++) {
2624 sprintf(s, "%" PRId32, int32Value[p][i]);
2625 rValues[i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
2626 strcpy(rValues[i], s);
2627 }
2628 return((char**)rValues);
2629 case SDDS_UINT32:
2630 for (i=0; i<rowCount[p]; i++) {
2631 sprintf(s, "%" PRIu32, uint32Value[p][i]);
2632 rValues[i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
2633 strcpy(rValues[i], s);
2634 }
2635 return((char**)rValues);
2636 case SDDS_REAL32:
2637 for (i=0; i<rowCount[p]; i++) {
2638 sprintf(s, "%f", real32Value[p][i]);
2639 rValues[i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
2640 strcpy(rValues[i], s);
2641 }
2642 return((char**)rValues);
2643 case SDDS_REAL64:
2644 for (i=0; i<rowCount[p]; i++) {
2645 sprintf(s, "%lf", real64Value[p][i]);
2646 rValues[i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
2647 strcpy(rValues[i], s);
2648 }
2649 return((char**)rValues);
2650 case SDDS_STRING:
2651 for (i=0; i<rowCount[p]; i++) {
2652 rValues[i] = (char*)SDDS_malloc(sizeof(char) * strlen(stringValue[p][i]) + 1);
2653 strcpy(rValues[i], stringValue[p][i]);
2654 }
2655 return((char**)rValues);
2656 case SDDS_CHARACTER:
2657 for (i=0; i<rowCount[p]; i++) {
2658 sprintf(s, "%c", charValue[p][i]);
2659 rValues[i] = (char*)SDDS_malloc(sizeof(char) * strlen(s) + 1);
2660 strcpy(rValues[i], s);
2661 }
2662 return((char**)rValues);
2663 default:
2664 *errorcode = 3;
2665 return((char**)NULL);
2666 }
2667}
2668
2669/***********************************************************************************************
2670 * writeDefinition *
2671 * *
2672 * C++ Arguments: FILE *fp *
2673 * voidp *gzfp *
2674 * *
2675 * Results: 0 on success *
2676 * 1 on failure *
2677 ***********************************************************************************************/
2678int32_t SDDSColumn::writeDefinition(FILE *fp) {
2679 if ((columnType <= 0) || (columnType > SDDS_NUM_TYPES)) {
2680 return(1);
2681 }
2682 if (fp == NULL) {
2683 return(1);
2684 }
2685 fputs("&column ", fp);
2686 if (SDDS_printNamelistField(fp, (char*)"name", columnName)) {
2687 return(1);
2688 }
2689 if (SDDS_printNamelistField(fp, (char*)"symbol", SDDS_blankToNull(columnSymbol))) {
2690 return(1);
2691 }
2692 if (SDDS_printNamelistField(fp, (char*)"units", SDDS_blankToNull(columnUnits))) {
2693 return(1);
2694 }
2695 if (SDDS_printNamelistField(fp, (char*)"description", SDDS_blankToNull(columnDescription))) {
2696 return(1);
2697 }
2698 if (SDDS_printNamelistField(fp, (char*)"format_string", SDDS_blankToNull(columnFormatString))) {
2699 return(1);
2700 }
2701 if (((SDDSFile*)sddsfile)->layoutVersion == 1) {
2702 if (SDDS_printNamelistField(fp, (char*)"type", SDDS_getVer1TypeName(columnType))) {
2703 return(1);
2704 }
2705 } else if (((SDDSFile*)sddsfile)->layoutVersion == 2) {
2706 if (SDDS_printNamelistField(fp, (char*)"type", SDDS_getVer2TypeName(columnType))) {
2707 return(1);
2708 }
2709 } else {
2710 if (SDDS_printNamelistField(fp, (char*)"type", SDDS_getTypeName(columnType))) {
2711 return(1);
2712 }
2713 }
2714 fputs("&end\n", fp);
2715 return(0);
2716}
2717
2718int32_t SDDSColumn::writeDefinition(voidp *gzfp) {
2719 if ((columnType <= 0) || (columnType > SDDS_NUM_TYPES)) {
2720 return(1);
2721 }
2722 if (gzfp == NULL) {
2723 return(1);
2724 }
2725 gzputs(gzfp, "&column ");
2726 if (SDDS_printNamelistField(gzfp, (char*)"name", columnName)) {
2727 return(1);
2728 }
2729 if (SDDS_printNamelistField(gzfp, (char*)"symbol", SDDS_blankToNull(columnSymbol))) {
2730 return(1);
2731 }
2732 if (SDDS_printNamelistField(gzfp, (char*)"units", SDDS_blankToNull(columnUnits))) {
2733 return(1);
2734 }
2735 if (SDDS_printNamelistField(gzfp, (char*)"description", SDDS_blankToNull(columnDescription))) {
2736 return(1);
2737 }
2738 if (SDDS_printNamelistField(gzfp, (char*)"format_string", SDDS_blankToNull(columnFormatString))) {
2739 return(1);
2740 }
2741 if (((SDDSFile*)sddsfile)->layoutVersion == 1) {
2742 if (SDDS_printNamelistField(gzfp, (char*)"type", SDDS_getVer1TypeName(columnType))) {
2743 return(1);
2744 }
2745 } else if (((SDDSFile*)sddsfile)->layoutVersion == 2) {
2746 if (SDDS_printNamelistField(gzfp, (char*)"type", SDDS_getVer2TypeName(columnType))) {
2747 return(1);
2748 }
2749 } else {
2750 if (SDDS_printNamelistField(gzfp, (char*)"type", SDDS_getTypeName(columnType))) {
2751 return(1);
2752 }
2753 }
2754 gzputs(gzfp, "&end\n");
2755 return(0);
2756}
2757
2758/***********************************************************************************************
2759 * writeAsciiValue *
2760 * *
2761 * C++ Arguments: FILE *fp, uint32_t page, uint32_t row *
2762 * C++ Arguments: voidp *gzfp, uint32_t page, uint32_t row *
2763 * *
2764 * Results: 0 on success *
2765 * 1 on failure *
2766 ***********************************************************************************************/
2767int32_t SDDSColumn::writeAsciiValue(FILE *fp, uint32_t page, uint32_t row) {
2768 char c;
2769 char *s;
2770 int32_t hasWhitespace;
2771
2772 if ((page == 0) || (page > pageCount) || (row == 0) || (row > rowCount[page-1])) {
2773 return(1);
2774 }
2775 page--;
2776 row--;
2777 switch (columnType) {
2778 case SDDS_INT16:
2779 fprintf(fp, "%" PRId16 " ", int16Value[page][row]);
2780 break;
2781 case SDDS_UINT16:
2782 fprintf(fp, "%" PRIu16 " ", uint16Value[page][row]);
2783 break;
2784 case SDDS_INT32:
2785 fprintf(fp, "%" PRId32 " ", int32Value[page][row]);
2786 break;
2787 case SDDS_UINT32:
2788 fprintf(fp, "%" PRIu32 " ", uint32Value[page][row]);
2789 break;
2790 case SDDS_REAL32:
2791 fprintf(fp, "%.*g ", FLT_DIG, real32Value[page][row]);
2792 break;
2793 case SDDS_REAL64:
2794 fprintf(fp, "%.*g ", DBL_DIG, real64Value[page][row]);
2795 break;
2796 case SDDS_STRING:
2797 s = stringValue[page][row];
2798 hasWhitespace=0;
2799 if (SDDS_hasWhitespace(s) || SDDS_stringIsBlank(s)) {
2800 fputc('"', fp);
2801 hasWhitespace = 1;
2802 }
2803 while (s && *s) {
2804 c = *s++;
2805 if (c=='!') {
2806 fputs("\\!", fp);
2807 } else if (c=='\\') {
2808 fputs("\\\\", fp);
2809 } else if (c=='"') {
2810 fputs("\\\"", fp);
2811 } else if (c==' ') {
2812 fputc(' ', fp); /* don't escape plain spaces */
2813 } else if (isspace(c) || !isprint(c)) {
2814 fprintf(fp, "\\%03o", c);
2815 } else {
2816 fputc(c, fp);
2817 }
2818 }
2819 if (hasWhitespace) {
2820 fputc('"', fp);
2821 }
2822 fputc(' ', fp);
2823 break;
2824 case SDDS_CHARACTER:
2825 c = charValue[page][row];
2826 if (c=='!')
2827 fputs("\\!", fp);
2828 else if (c=='\\')
2829 fputs("\\\\", fp);
2830 else if (c=='"')
2831 fputs("\\\"", fp);
2832 else if (!c || isspace(c) || !isprint(c))
2833 fprintf(fp, "\\%03o", c);
2834 else
2835 fputc(c, fp);
2836 fputc(' ', fp);
2837 break;
2838 default:
2839 return(1);
2840 }
2841 return(0);
2842}
2843
2844int32_t SDDSColumn::writeAsciiValue(voidp *gzfp, uint32_t page, uint32_t row) {
2845 char c;
2846 char *s;
2847 int32_t hasWhitespace;
2848
2849 if ((page == 0) || (page > pageCount) || (row == 0) || (row > rowCount[page-1])) {
2850 return(1);
2851 }
2852 page--;
2853 row--;
2854 switch (columnType) {
2855 case SDDS_INT16:
2856 gzprintf(gzfp, "%" PRId16 " ", int16Value[page][row]);
2857 break;
2858 case SDDS_UINT16:
2859 gzprintf(gzfp, "%" PRIu16 " ", uint16Value[page][row]);
2860 break;
2861 case SDDS_INT32:
2862 gzprintf(gzfp, "%" PRId32 " ", int32Value[page][row]);
2863 break;
2864 case SDDS_UINT32:
2865 gzprintf(gzfp, "%" PRIu32 " ", uint32Value[page][row]);
2866 break;
2867 case SDDS_REAL32:
2868 gzprintf(gzfp, "%.*g ", FLT_DIG, real32Value[page][row]);
2869 break;
2870 case SDDS_REAL64:
2871 gzprintf(gzfp, "%.*g ", DBL_DIG, real64Value[page][row]);
2872 break;
2873 case SDDS_STRING:
2874 s = stringValue[page][row];
2875 hasWhitespace=0;
2876 if (SDDS_hasWhitespace(s) || SDDS_stringIsBlank(s)) {
2877 gzputc(gzfp, '"');
2878 hasWhitespace = 1;
2879 }
2880 while (s && *s) {
2881 c = *s++;
2882 if (c=='!') {
2883 gzputs(gzfp, "\\!");
2884 } else if (c=='\\') {
2885 gzputs(gzfp, "\\\\");
2886 } else if (c=='"') {
2887 gzputs(gzfp, "\\\"");
2888 } else if (c==' ') {
2889 gzputc(gzfp, ' '); /* don't escape plain spaces */
2890 } else if (isspace(c) || !isprint(c)) {
2891 gzprintf(gzfp, "\\%03o", c);
2892 } else {
2893 gzputc(gzfp, c);
2894 }
2895 }
2896 if (hasWhitespace) {
2897 gzputc(gzfp, '"');
2898 }
2899 gzputc(gzfp, ' ');
2900 break;
2901 case SDDS_CHARACTER:
2902 c = charValue[page][row];
2903 if (c=='!')
2904 gzputs(gzfp, "\\!");
2905 else if (c=='\\')
2906 gzputs(gzfp, "\\\\");
2907 else if (c=='"')
2908 gzputs(gzfp, "\\\"");
2909 else if (!c || isspace(c) || !isprint(c))
2910 gzprintf(gzfp, "\\%03o", c);
2911 else
2912 gzputc(gzfp, c);
2913 gzputc(gzfp, ' ');
2914 break;
2915 default:
2916 return(1);
2917 }
2918 return(0);
2919}
2920
2921/***********************************************************************************************
2922 * writeAsciiValues *
2923 * *
2924 * C++ Arguments: FILE *fp, uint32_t page *
2925 * C++ Arguments: voidp *gzfp, uint32_t page *
2926 * *
2927 * Note: column-major-order of ascii files is not implemented yet *
2928 * *
2929 * Results: 0 on success *
2930 * 1 on failure *
2931 ***********************************************************************************************/
2932/*
2933int32_t SDDSColumn::writeAsciiValues(FILE *fp, uint32_t page) {
2934 char c;
2935 char *s;
2936 int32_t hasWhitespace;
2937 uint32_t i;
2938
2939 if ((page == 0) || (page > pageCount)) {
2940 return(1);
2941 }
2942 page--;
2943 switch (columnType) {
2944 case SDDS_INT16:
2945 for (i=0; i<rowCount[page]; i++) {
2946 fprintf(fp, "%" PRId16 " ", int16Value[page][i]);
2947 }
2948 break;
2949 case SDDS_UINT16:
2950 for (i=0; i<rowCount[page]; i++) {
2951 fprintf(fp, "%" PRIu16 " ", uint16Value[page][i]);
2952 }
2953 break;
2954 case SDDS_INT32:
2955 for (i=0; i<rowCount[page]; i++) {
2956 fprintf(fp, "%" PRId32 " ", int32Value[page][i]);
2957 }
2958 break;
2959 case SDDS_UINT32:
2960 for (i=0; i<rowCount[page]; i++) {
2961 fprintf(fp, "%" PRIu32 " ", uint32Value[page][i]);
2962 }
2963 break;
2964 case SDDS_REAL32:
2965 for (i=0; i<rowCount[page]; i++) {
2966 fprintf(fp, "%.*g ", FLT_DIG, real32Value[page][i]);
2967 }
2968 break;
2969 case SDDS_REAL64:
2970 for (i=0; i<rowCount[page]; i++) {
2971 fprintf(fp, "%.*g ", DBL_DIG, real64Value[page][i]);
2972 }
2973 break;
2974 case SDDS_STRING:
2975 for (i=0; i<rowCount[page]; i++) {
2976 s = stringValue[page][i];
2977 hasWhitespace=0;
2978 if (SDDS_hasWhitespace(s) || SDDS_stringIsBlank(s)) {
2979 fputc('"', fp);
2980 hasWhitespace = 1;
2981 }
2982 while (s && *s) {
2983 c = *s++;
2984 if (c=='!') {
2985 fputs("\\!", fp);
2986 } else if (c=='\\') {
2987 fputs("\\\\", fp);
2988 } else if (c=='"') {
2989 fputs("\\\"", fp);
2990 } else if (c==' ') {
2991 fputc(' ', fp);
2992 } else if (isspace(c) || !isprint(c)) {
2993 fprintf(fp, "\\%03o", c);
2994 } else {
2995 fputc(c, fp);
2996 }
2997 }
2998 if (hasWhitespace) {
2999 fputc('"', fp);
3000 }
3001 fputc(' ', fp);
3002 }
3003 break;
3004 case SDDS_CHARACTER:
3005 for (i=0; i<rowCount[page]; i++) {
3006 c = charValue[page][i];
3007 if (c=='!')
3008 fputs("\\!", fp);
3009 else if (c=='\\')
3010 fputs("\\\\", fp);
3011 else if (c=='"')
3012 fputs("\\\"", fp);
3013 else if (!c || isspace(c) || !isprint(c))
3014 fprintf(fp, "\\%03o", c);
3015 else
3016 fputc(c, fp);
3017 fputc(' ', fp);
3018 }
3019 break;
3020 default:
3021 return(1);
3022 }
3023 return(0);
3024}
3025
3026int32_t SDDSColumn::writeAsciiValues(voidp *gzfp, uint32_t page) {
3027 char c;
3028 char *s;
3029 int32_t hasWhitespace;
3030 uint32_t i;
3031
3032 if ((page == 0) || (page > pageCount)) {
3033 return(1);
3034 }
3035 page--;
3036 switch (columnType) {
3037 case SDDS_INT16:
3038 for (i=0; i<rowCount[page]; i++) {
3039 gzprintf(gzfp, "%" PRId16 " ", int16Value[page][i]);
3040 }
3041 break;
3042 case SDDS_UINT16:
3043 for (i=0; i<rowCount[page]; i++) {
3044 gzprintf(gzfp, "%" PRIu16 " ", uint16Value[page][i]);
3045 }
3046 break;
3047 case SDDS_INT32:
3048 for (i=0; i<rowCount[page]; i++) {
3049 gzprintf(gzfp, "%" PRId32 " ", int32Value[page][i]);
3050 }
3051 break;
3052 case SDDS_UINT32:
3053 for (i=0; i<rowCount[page]; i++) {
3054 gzprintf(gzfp, "%" PRIu32 " ", uint32Value[page][i]);
3055 }
3056 break;
3057 case SDDS_REAL32:
3058 for (i=0; i<rowCount[page]; i++) {
3059 gzprintf(gzfp, "%.*g ", FLT_DIG, real32Value[page][i]);
3060 }
3061 break;
3062 case SDDS_REAL64:
3063 for (i=0; i<rowCount[page]; i++) {
3064 gzprintf(gzfp, "%.*g ", DBL_DIG, real64Value[page][i]);
3065 }
3066 break;
3067 case SDDS_STRING:
3068 for (i=0; i<rowCount[page]; i++) {
3069 s = stringValue[page][i];
3070 hasWhitespace=0;
3071 if (SDDS_hasWhitespace(s) || SDDS_stringIsBlank(s)) {
3072 gzputc(gzfp, '"');
3073 hasWhitespace = 1;
3074 }
3075 while (s && *s) {
3076 c = *s++;
3077 if (c=='!') {
3078 gzputs(gzfp, "\\!");
3079 } else if (c=='\\') {
3080 gzputs(gzfp, "\\\\");
3081 } else if (c=='"') {
3082 gzputs(gzfp, "\\\"");
3083 } else if (c==' ') {
3084 gzputc(gzfp, ' ');
3085 } else if (isspace(c) || !isprint(c)) {
3086 gzprintf(gzfp, "\\%03o", c);
3087 } else {
3088 gzputc(gzfp, c);
3089 }
3090 }
3091 if (hasWhitespace) {
3092 gzputc(gzfp, '"');
3093 }
3094 gzputc(gzfp, ' ');
3095 }
3096 break;
3097 case SDDS_CHARACTER:
3098 for (i=0; i<rowCount[page]; i++) {
3099 c = charValue[page][i];
3100 if (c=='!')
3101 gzputs(gzfp, "\\!");
3102 else if (c=='\\')
3103 gzputs(gzfp, "\\\\");
3104 else if (c=='"')
3105 gzputs(gzfp, "\\\"");
3106 else if (!c || isspace(c) || !isprint(c))
3107 gzprintf(gzfp, "\\%03o", c);
3108 else
3109 gzputc(gzfp, c);
3110 gzputc(gzfp, ' ');
3111 }
3112 break;
3113 default:
3114 return(1);
3115 }
3116 return(0);
3117}
3118*/
3119
3120/***********************************************************************************************
3121 * writeBinaryValue *
3122 * *
3123 * C++ Arguments: FILE *fp, uint32_t page, uint32_t row *
3124 * C++ Arguments: voidp *gzfp, uint32_t page, uint32_t row *
3125 * *
3126 * Results: 0 on success *
3127 * 1 on failure *
3128 ***********************************************************************************************/
3129int32_t SDDSColumn::writeBinaryValue(FILE *fp, SDDS_FILEBUFFER *fBuffer, uint32_t page, uint32_t row, bool nonNativeEndian) {
3130 switch (columnType) {
3131 case SDDS_INT16:
3132 if (SDDS_bufferedWrite(&(int16Value[page][row]), 2, fp, fBuffer, sddsfile)) {
3133 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)");
3134 return(1);
3135 }
3136 return(0);
3137 case SDDS_UINT16:
3138 if (SDDS_bufferedWrite(&(uint16Value[page][row]), 2, fp, fBuffer, sddsfile)) {
3139 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)");
3140 return(1);
3141 }
3142 return(0);
3143 case SDDS_INT32:
3144 if (SDDS_bufferedWrite(&(int32Value[page][row]), 4, fp, fBuffer, sddsfile)) {
3145 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)");
3146 return(1);
3147 }
3148 return(0);
3149 case SDDS_UINT32:
3150 if (SDDS_bufferedWrite(&(uint32Value[page][row]), 4, fp, fBuffer, sddsfile)) {
3151 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)");
3152 return(1);
3153 }
3154 return(0);
3155 case SDDS_REAL32:
3156 if (SDDS_bufferedWrite(&(real32Value[page][row]), 4, fp, fBuffer, sddsfile)) {
3157 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)");
3158 return(1);
3159 }
3160 return(0);
3161 case SDDS_REAL64:
3162 if (SDDS_bufferedWrite(&(real64Value[page][row]), 8, fp, fBuffer, sddsfile)) {
3163 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)");
3164 return(1);
3165 }
3166 return(0);
3167 case SDDS_STRING:
3168 if (SDDS_writeBinaryString(stringValue[page][row], fp, fBuffer, sddsfile)) {
3169 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing string (SDDSColumn::writeBinaryValue)");
3170 return(1);
3171 }
3172 return(0);
3173 case SDDS_CHARACTER:
3174 if (SDDS_bufferedWrite(&(charValue[page][row]), 1, fp, fBuffer, sddsfile)) {
3175 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)");
3176 return(1);
3177 }
3178 return(0);
3179 }
3180 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--unknown type (SDDSColumn::writeBinaryValue)");
3181 return(1);
3182}
3183
3184int32_t SDDSColumn::writeBinaryValue(voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, uint32_t row, bool nonNativeEndian) {
3185 switch (columnType) {
3186 case SDDS_INT16:
3187 if (SDDS_bufferedWrite(&(int16Value[page][row]), 2, gzfp, fBuffer, sddsfile)) {
3188 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)");
3189 return(1);
3190 }
3191 return(0);
3192 case SDDS_UINT16:
3193 if (SDDS_bufferedWrite(&(uint16Value[page][row]), 2, gzfp, fBuffer, sddsfile)) {
3194 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)");
3195 return(1);
3196 }
3197 return(0);
3198 case SDDS_INT32:
3199 if (SDDS_bufferedWrite(&(int32Value[page][row]), 4, gzfp, fBuffer, sddsfile)) {
3200 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)");
3201 return(1);
3202 }
3203 return(0);
3204 case SDDS_UINT32:
3205 if (SDDS_bufferedWrite(&(uint32Value[page][row]), 4, gzfp, fBuffer, sddsfile)) {
3206 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)");
3207 return(1);
3208 }
3209 return(0);
3210 case SDDS_REAL32:
3211 if (SDDS_bufferedWrite(&(real32Value[page][row]), 4, gzfp, fBuffer, sddsfile)) {
3212 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)");
3213 return(1);
3214 }
3215 return(0);
3216 case SDDS_REAL64:
3217 if (SDDS_bufferedWrite(&(real64Value[page][row]), 8, gzfp, fBuffer, sddsfile)) {
3218 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)");
3219 return(1);
3220 }
3221 return(0);
3222 case SDDS_STRING:
3223 if (SDDS_writeBinaryString(stringValue[page][row], gzfp, fBuffer, sddsfile)) {
3224 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing string (SDDSColumn::writeBinaryValue)");
3225 return(1);
3226 }
3227 return(0);
3228 case SDDS_CHARACTER:
3229 if (SDDS_bufferedWrite(&(charValue[page][row]), 1, gzfp, fBuffer, sddsfile)) {
3230 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)");
3231 return(1);
3232 }
3233 return(0);
3234 }
3235 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--unknown type (SDDSColumn::writeBinaryValue)");
3236 return(1);
3237}
3238
3239/***********************************************************************************************
3240 * writeBinaryValues *
3241 * *
3242 * C++ Arguments: FILE *fp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian *
3243 * C++ Arguments: voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian *
3244 * *
3245 * Results: 0 on success *
3246 * 1 on failure *
3247 ***********************************************************************************************/
3248int32_t SDDSColumn::writeBinaryValues(FILE *fp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian) {
3249 uint32_t row;
3250 switch (columnType) {
3251 case SDDS_INT16:
3252 if (SDDS_bufferedWrite(&(int16Value[page][0]), 2 * rowCount[page], fp, fBuffer, sddsfile)) {
3253 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)");
3254 return(1);
3255 }
3256 return(0);
3257 case SDDS_UINT16:
3258 if (SDDS_bufferedWrite(&(uint16Value[page][0]), 2 * rowCount[page], fp, fBuffer, sddsfile)) {
3259 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)");
3260 return(1);
3261 }
3262 return(0);
3263 case SDDS_INT32:
3264 if (SDDS_bufferedWrite(&(int32Value[page][0]), 4 * rowCount[page], fp, fBuffer, sddsfile)) {
3265 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)");
3266 return(1);
3267 }
3268 return(0);
3269 case SDDS_UINT32:
3270 if (SDDS_bufferedWrite(&(uint32Value[page][0]), 4 * rowCount[page], fp, fBuffer, sddsfile)) {
3271 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)");
3272 return(1);
3273 }
3274 return(0);
3275 case SDDS_REAL32:
3276 if (SDDS_bufferedWrite(&(real32Value[page][0]), 4 * rowCount[page], fp, fBuffer, sddsfile)) {
3277 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)");
3278 return(1);
3279 }
3280 return(0);
3281 case SDDS_REAL64:
3282 if (SDDS_bufferedWrite(&(real64Value[page][0]), 8 * rowCount[page], fp, fBuffer, sddsfile)) {
3283 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)");
3284 return(1);
3285 }
3286 return(0);
3287 case SDDS_STRING:
3288 for (row=0; row<rowCount[page]; row++) {
3289 if (SDDS_writeBinaryString(stringValue[page][row], fp, fBuffer, sddsfile)) {
3290 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing string (SDDSColumn::writeBinaryValues)");
3291 return(1);
3292 }
3293 }
3294 return(0);
3295 case SDDS_CHARACTER:
3296 if (SDDS_bufferedWrite(&(charValue[page][0]), rowCount[page], fp, fBuffer, sddsfile)) {
3297 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)");
3298 return(1);
3299 }
3300 return(0);
3301 }
3302 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--unknown type (SDDSColumn::writeBinaryValues)");
3303 return(1);
3304}
3305
3306int32_t SDDSColumn::writeBinaryValues(voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian) {
3307 uint32_t row;
3308 switch (columnType) {
3309 case SDDS_INT16:
3310 if (SDDS_bufferedWrite(&(int16Value[page][0]), 2 * rowCount[page], gzfp, fBuffer, sddsfile)) {
3311 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)");
3312 return(1);
3313 }
3314 return(0);
3315 case SDDS_UINT16:
3316 if (SDDS_bufferedWrite(&(uint16Value[page][0]), 2 * rowCount[page], gzfp, fBuffer, sddsfile)) {
3317 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)");
3318 return(1);
3319 }
3320 return(0);
3321 case SDDS_INT32:
3322 if (SDDS_bufferedWrite(&(int32Value[page][0]), 4 * rowCount[page], gzfp, fBuffer, sddsfile)) {
3323 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)");
3324 return(1);
3325 }
3326 return(0);
3327 case SDDS_UINT32:
3328 if (SDDS_bufferedWrite(&(uint32Value[page][0]), 4 * rowCount[page], gzfp, fBuffer, sddsfile)) {
3329 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)");
3330 return(1);
3331 }
3332 return(0);
3333 case SDDS_REAL32:
3334 if (SDDS_bufferedWrite(&(real32Value[page][0]), 4 * rowCount[page], gzfp, fBuffer, sddsfile)) {
3335 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)");
3336 return(1);
3337 }
3338 return(0);
3339 case SDDS_REAL64:
3340 if (SDDS_bufferedWrite(&(real64Value[page][0]), 8 * rowCount[page], gzfp, fBuffer, sddsfile)) {
3341 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)");
3342 return(1);
3343 }
3344 return(0);
3345 case SDDS_STRING:
3346 for (row=0; row<rowCount[page]; row++) {
3347 if (SDDS_writeBinaryString(stringValue[page][row], gzfp, fBuffer, sddsfile)) {
3348 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing string (SDDSColumn::writeBinaryValues)");
3349 return(1);
3350 }
3351 }
3352 return(0);
3353 case SDDS_CHARACTER:
3354 if (SDDS_bufferedWrite(&(charValue[page][0]), rowCount[page], gzfp, fBuffer, sddsfile)) {
3355 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)");
3356 return(1);
3357 }
3358 return(0);
3359 }
3360 ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--unknown type (SDDSColumn::writeBinaryValues)");
3361 return(1);
3362}
3363
3364/***********************************************************************************************
3365 * readBinaryValue *
3366 * *
3367 * C++ Arguments: FILE *fp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian *
3368 * C++ Arguments: voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian *
3369 * *
3370 * Results: 0 on success *
3371 * 1 on failure *
3372 ***********************************************************************************************/
3373int32_t SDDSColumn::readBinaryValue(FILE *fp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian) {
3374 uint32_t i, n=0, p, rowsNeeded;
3375 bool newPage=false;
3376
3377 if (page == 0) {
3378 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--invalid page number (SDDSColumn::readBinaryValue)");
3379 return(1);
3380 }
3381 if (page > pageCount) {
3382 newPage = true;
3383 n = page - pageCount;
3384 }
3385 p = page - 1;
3386 if (newPage) {
3387 rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page);
3388 rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page);
3389 for (i=0; i<n; i++) {
3390 rowCount[p-i] = 0;
3391 rowsAllocated[p-i] = 0;
3392 }
3393 }
3394 rowsNeeded = 1 + rowCount[p];
3395 switch (columnType) {
3396 case SDDS_INT16:
3397 if (newPage) { /* new page */
3398 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
3399 for (i=0; i<n; i++) {
3400 int16Value[p-i] = NULL;
3401 }
3402 }
3403 if (rowsNeeded > rowsAllocated[p]) {
3404 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
3405 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]);
3406 }
3407 if (SDDS_bufferedRead(&(int16Value[p][rowCount[p]]), 2, fp, fBuffer, sddsfile)) {
3408 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)");
3409 return(1);
3410 }
3411 break;
3412 case SDDS_UINT16:
3413 if (newPage) { /* new page */
3414 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
3415 for (i=0; i<n; i++) {
3416 uint16Value[p-i] = NULL;
3417 }
3418 }
3419 if (rowsNeeded > rowsAllocated[p]) {
3420 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
3421 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]);
3422 }
3423 if (SDDS_bufferedRead(&(uint16Value[p][rowCount[p]]), 2, fp, fBuffer, sddsfile)) {
3424 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)");
3425 return(1);
3426 }
3427 break;
3428 case SDDS_INT32:
3429 if (newPage) { /* new page */
3430 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
3431 for (i=0; i<n; i++) {
3432 int32Value[p-i] = NULL;
3433 }
3434 }
3435 if (rowsNeeded > rowsAllocated[p]) {
3436 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
3437 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]);
3438 }
3439 if (SDDS_bufferedRead(&(int32Value[p][rowCount[p]]), 4, fp, fBuffer, sddsfile)) {
3440 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)");
3441 return(1);
3442 }
3443 break;
3444 case SDDS_UINT32:
3445 if (newPage) { /* new page */
3446 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
3447 for (i=0; i<n; i++) {
3448 uint32Value[p-i] = NULL;
3449 }
3450 }
3451 if (rowsNeeded > rowsAllocated[p]) {
3452 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
3453 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]);
3454 }
3455 if (SDDS_bufferedRead(&(uint32Value[p][rowCount[p]]), 4, fp, fBuffer, sddsfile)) {
3456 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)");
3457 return(1);
3458 }
3459 break;
3460 case SDDS_REAL32:
3461 if (newPage) { /* new page */
3462 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
3463 for (i=0; i<n; i++) {
3464 real32Value[p-i] = NULL;
3465 }
3466 }
3467 if (rowsNeeded > rowsAllocated[p]) {
3468 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
3469 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]);
3470 }
3471 if (SDDS_bufferedRead(&(real32Value[p][rowCount[p]]), 4, fp, fBuffer, sddsfile)) {
3472 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)");
3473 return(1);
3474 }
3475 break;
3476 case SDDS_REAL64:
3477 if (newPage) { /* new page */
3478 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
3479 for (i=0; i<n; i++) {
3480 real64Value[p-i] = NULL;
3481 }
3482 }
3483 if (rowsNeeded > rowsAllocated[p]) {
3484 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
3485 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]);
3486 }
3487 if (SDDS_bufferedRead(&(real64Value[p][rowCount[p]]), 8, fp, fBuffer, sddsfile)) {
3488 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)");
3489 return(1);
3490 }
3491 break;
3492 case SDDS_STRING:
3493 if (newPage) { /* new pages */
3494 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
3495 for (i=0; i<n; i++) {
3496 stringValue[p-i] = NULL;
3497 }
3498 }
3499 if (rowsNeeded > rowsAllocated[p]) {
3500 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
3501 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]);
3502 }
3503 stringValue[p][rowCount[p]] = NULL;
3504 if (SDDS_readBinaryString(&(stringValue[p][rowCount[p]]), fp, fBuffer, sddsfile)) {
3505 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading string (SDDSColumn::readBinaryValue)");
3506 return(1);
3507 }
3508 break;
3509 case SDDS_CHARACTER:
3510 if (newPage) { /* new page */
3511 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
3512 for (i=0; i<n; i++) {
3513 charValue[p-i] = NULL;
3514 }
3515 }
3516 if (rowsNeeded > rowsAllocated[p]) {
3517 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
3518 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]);
3519 }
3520 if (SDDS_bufferedRead(&(charValue[p][rowCount[p]]), 1, fp, fBuffer, sddsfile)) {
3521 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)");
3522 return(1);
3523 }
3524 break;
3525 default:
3526 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--unknown type (SDDSColumn::readBinaryValue)");
3527 return(1);
3528 }
3529 if (newPage) {
3530 pageCount = page;
3531 rowCount[p] = 1;
3532 } else {
3533 rowCount[p]++;
3534 }
3535 return(0);
3536}
3537
3538int32_t SDDSColumn::readBinaryValue(voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian) {
3539 uint32_t i, n=0, p, rowsNeeded;
3540 bool newPage=false;
3541
3542 if (page == 0) {
3543 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--invalid page number (SDDSColumn::readBinaryValue)");
3544 return(1);
3545 }
3546 if (page > pageCount) {
3547 newPage = true;
3548 n = page - pageCount;
3549 }
3550 p = page - 1;
3551 if (newPage) {
3552 rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page);
3553 rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page);
3554 for (i=0; i<n; i++) {
3555 rowCount[p-i] = 0;
3556 rowsAllocated[p-i] = 0;
3557 }
3558 }
3559 rowsNeeded = 1 + rowCount[p];
3560 switch (columnType) {
3561 case SDDS_INT16:
3562 if (newPage) { /* new page */
3563 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
3564 for (i=0; i<n; i++) {
3565 int16Value[p-i] = NULL;
3566 }
3567 }
3568 if (rowsNeeded > rowsAllocated[p]) {
3569 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
3570 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]);
3571 }
3572 if (SDDS_bufferedRead(&(int16Value[p][rowCount[p]]), 2, gzfp, fBuffer, sddsfile)) {
3573 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)");
3574 return(1);
3575 }
3576 break;
3577 case SDDS_UINT16:
3578 if (newPage) { /* new page */
3579 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
3580 for (i=0; i<n; i++) {
3581 uint16Value[p-i] = NULL;
3582 }
3583 }
3584 if (rowsNeeded > rowsAllocated[p]) {
3585 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
3586 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]);
3587 }
3588 if (SDDS_bufferedRead(&(uint16Value[p][rowCount[p]]), 2, gzfp, fBuffer, sddsfile)) {
3589 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)");
3590 return(1);
3591 }
3592 break;
3593 case SDDS_INT32:
3594 if (newPage) { /* new page */
3595 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
3596 for (i=0; i<n; i++) {
3597 int32Value[p-i] = NULL;
3598 }
3599 }
3600 if (rowsNeeded > rowsAllocated[p]) {
3601 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
3602 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]);
3603 }
3604 if (SDDS_bufferedRead(&(int32Value[p][rowCount[p]]), 4, gzfp, fBuffer, sddsfile)) {
3605 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)");
3606 return(1);
3607 }
3608 break;
3609 case SDDS_UINT32:
3610 if (newPage) { /* new page */
3611 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
3612 for (i=0; i<n; i++) {
3613 uint32Value[p-i] = NULL;
3614 }
3615 }
3616 if (rowsNeeded > rowsAllocated[p]) {
3617 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
3618 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]);
3619 }
3620 if (SDDS_bufferedRead(&(uint32Value[p][rowCount[p]]), 4, gzfp, fBuffer, sddsfile)) {
3621 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)");
3622 return(1);
3623 }
3624 break;
3625 case SDDS_REAL32:
3626 if (newPage) { /* new page */
3627 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
3628 for (i=0; i<n; i++) {
3629 real32Value[p-i] = NULL;
3630 }
3631 }
3632 if (rowsNeeded > rowsAllocated[p]) {
3633 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
3634 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]);
3635 }
3636 if (SDDS_bufferedRead(&(real32Value[p][rowCount[p]]), 4, gzfp, fBuffer, sddsfile)) {
3637 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)");
3638 return(1);
3639 }
3640 break;
3641 case SDDS_REAL64:
3642 if (newPage) { /* new page */
3643 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
3644 for (i=0; i<n; i++) {
3645 real64Value[p-i] = NULL;
3646 }
3647 }
3648 if (rowsNeeded > rowsAllocated[p]) {
3649 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
3650 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]);
3651 }
3652 if (SDDS_bufferedRead(&(real64Value[p][rowCount[p]]), 8, gzfp, fBuffer, sddsfile)) {
3653 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)");
3654 return(1);
3655 }
3656 break;
3657 case SDDS_STRING:
3658 if (newPage) { /* new pages */
3659 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
3660 for (i=0; i<n; i++) {
3661 stringValue[p-i] = NULL;
3662 }
3663 }
3664 if (rowsNeeded > rowsAllocated[p]) {
3665 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
3666 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]);
3667 }
3668 stringValue[p][rowCount[p]] = NULL;
3669 if (SDDS_readBinaryString(&(stringValue[p][rowCount[p]]), gzfp, fBuffer, sddsfile)) {
3670 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading string (SDDSColumn::readBinaryValue)");
3671 return(1);
3672 }
3673 break;
3674 case SDDS_CHARACTER:
3675 if (newPage) { /* new page */
3676 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
3677 for (i=0; i<n; i++) {
3678 charValue[p-i] = NULL;
3679 }
3680 }
3681 if (rowsNeeded > rowsAllocated[p]) {
3682 rowsAllocated[p] = rowsNeeded + rowAllocationIncrement;
3683 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]);
3684 }
3685 if (SDDS_bufferedRead(&(charValue[p][rowCount[p]]), 1, gzfp, fBuffer, sddsfile)) {
3686 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)");
3687 return(1);
3688 }
3689 break;
3690 default:
3691 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--unknown type (SDDSColumn::readBinaryValue)");
3692 return(1);
3693 }
3694 if (newPage) {
3695 pageCount = page;
3696 rowCount[p] = 1;
3697 } else {
3698 rowCount[p]++;
3699 }
3700 return(0);
3701}
3702
3703/*************************
3704 * readBinaryValues
3705
3706 C++ Arguments: FILE *fp, SDDS_FILEBUFFER *fBuffer, uint32_t page, uint32_t rows, bool nonNativeEndian
3707 voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, uint32_t rows, bool nonNativeEndian
3708
3709 Note: used for column-major-order
3710
3711 Results: 0 on success
3712 1 on failure
3713 *************************/
3714int32_t SDDSColumn::readBinaryValues(FILE *fp, SDDS_FILEBUFFER *fBuffer, uint32_t page, uint32_t rows, bool nonNativeEndian) {
3715 uint32_t i, n, p;
3716
3717 if (page == 0) {
3718 ((SDDSFile*)sddsfile)->setError((char*)"Invalid page number--failure reading values (SDDSColumn::readBinaryValues)");
3719 return(1);
3720 }
3721 if (page > pageCount) {
3722 n = page - pageCount;
3723 } else {
3724 ((SDDSFile*)sddsfile)->setError((char*)"Invalid page number--failure reading values (SDDSColumn::readBinaryValues)");
3725 return(1);
3726 }
3727 p = page - 1;
3728 rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page);
3729 rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page);
3730 for (i=0; i<n; i++) {
3731 rowCount[p-i] = 0;
3732 rowsAllocated[p-i] = 0;
3733 }
3734 if (rows == 0) {
3735 return(0);
3736 }
3737 switch (columnType) {
3738 case SDDS_INT16:
3739 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
3740 for (i=0; i<n; i++) {
3741 int16Value[p-i] = NULL;
3742 }
3743 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rows);
3744 rowsAllocated[p] = rows;
3745 if (SDDS_bufferedRead(&(int16Value[p][0]), 2 * rows, fp, fBuffer, sddsfile)) {
3746 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)");
3747 return(1);
3748 }
3749 break;
3750 case SDDS_UINT16:
3751 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
3752 for (i=0; i<n; i++) {
3753 uint16Value[p-i] = NULL;
3754 }
3755 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rows);
3756 rowsAllocated[p] = rows;
3757 if (SDDS_bufferedRead(&(uint16Value[p][0]), 2 * rows, fp, fBuffer, sddsfile)) {
3758 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)");
3759 return(1);
3760 }
3761 break;
3762 case SDDS_INT32:
3763 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
3764 for (i=0; i<n; i++) {
3765 int32Value[p-i] = NULL;
3766 }
3767 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rows);
3768 rowsAllocated[p] = rows;
3769 if (SDDS_bufferedRead(&(int32Value[p][0]), 4 * rows, fp, fBuffer, sddsfile)) {
3770 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)");
3771 return(1);
3772 }
3773 break;
3774 case SDDS_UINT32:
3775 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
3776 for (i=0; i<n; i++) {
3777 uint32Value[p-i] = NULL;
3778 }
3779 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rows);
3780 rowsAllocated[p] = rows;
3781 if (SDDS_bufferedRead(&(uint32Value[p][0]), 4 * rows, fp, fBuffer, sddsfile)) {
3782 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)");
3783 return(1);
3784 }
3785 break;
3786 case SDDS_REAL32:
3787 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
3788 for (i=0; i<n; i++) {
3789 real32Value[p-i] = NULL;
3790 }
3791 rowsAllocated[p] = rows;
3792 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rows);
3793 if (SDDS_bufferedRead(&(real32Value[p][0]), 4 * rows, fp, fBuffer, sddsfile)) {
3794 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)");
3795 return(1);
3796 }
3797 break;
3798 case SDDS_REAL64:
3799 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
3800 for (i=0; i<n; i++) {
3801 real64Value[p-i] = NULL;
3802 }
3803 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rows);
3804 rowsAllocated[p] = rows;
3805 if (SDDS_bufferedRead(&(real64Value[p][0]), 8 * rows, fp, fBuffer, sddsfile)) {
3806 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)");
3807 return(1);
3808 }
3809 break;
3810 case SDDS_STRING:
3811 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
3812 for (i=0; i<n; i++) {
3813 stringValue[p-i] = NULL;
3814 }
3815 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rows);
3816 rowsAllocated[p] = rows;
3817 for (i=0; i<rows; i++) {
3818 stringValue[p][i] = NULL;
3819 if (SDDS_readBinaryString(&(stringValue[p][i]), fp, fBuffer, sddsfile)) {
3820 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading strings (SDDSColumn::readBinaryValues)");
3821 return(1);
3822 }
3823 }
3824 break;
3825 case SDDS_CHARACTER:
3826 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
3827 for (i=0; i<n; i++) {
3828 charValue[p-i] = NULL;
3829 }
3830 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rows);
3831 rowsAllocated[p] = rows;
3832 if (SDDS_bufferedRead(&(charValue[p][0]), rows, fp, fBuffer, sddsfile)) {
3833 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)");
3834 return(1);
3835 }
3836 break;
3837 default:
3838 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--unknown type (SDDSColumn::readBinaryValues)");
3839 return(1);
3840 }
3841 pageCount = page;
3842 rowCount[p] = rows;
3843 return(0);
3844}
3845
3846int32_t SDDSColumn::readBinaryValues(voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, uint32_t rows, bool nonNativeEndian) {
3847 uint32_t i, n, p;
3848
3849 if (page == 0) {
3850 ((SDDSFile*)sddsfile)->setError((char*)"Invalid page number--failure reading values (SDDSColumn::readBinaryValues)");
3851 return(1);
3852 }
3853 if (page > pageCount) {
3854 n = page - pageCount;
3855 } else {
3856 ((SDDSFile*)sddsfile)->setError((char*)"Invalid page number--failure reading values (SDDSColumn::readBinaryValues)");
3857 return(1);
3858 }
3859 p = page - 1;
3860 rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page);
3861 rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page);
3862 for (i=0; i<n; i++) {
3863 rowCount[p-i] = 0;
3864 rowsAllocated[p-i] = 0;
3865 }
3866 if (rows == 0) {
3867 return(0);
3868 }
3869 switch (columnType) {
3870 case SDDS_INT16:
3871 int16Value = (int16_t**)SDDS_realloc(int16Value, sizeof(int16_t*) * page);
3872 for (i=0; i<n; i++) {
3873 int16Value[p-i] = NULL;
3874 }
3875 int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rows);
3876 rowsAllocated[p] = rows;
3877 if (SDDS_bufferedRead(&(int16Value[p][0]), 2 * rows, gzfp, fBuffer, sddsfile)) {
3878 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)");
3879 return(1);
3880 }
3881 break;
3882 case SDDS_UINT16:
3883 uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page);
3884 for (i=0; i<n; i++) {
3885 uint16Value[p-i] = NULL;
3886 }
3887 uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rows);
3888 rowsAllocated[p] = rows;
3889 if (SDDS_bufferedRead(&(uint16Value[p][0]), 2 * rows, gzfp, fBuffer, sddsfile)) {
3890 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)");
3891 return(1);
3892 }
3893 break;
3894 case SDDS_INT32:
3895 int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page);
3896 for (i=0; i<n; i++) {
3897 int32Value[p-i] = NULL;
3898 }
3899 int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rows);
3900 rowsAllocated[p] = rows;
3901 if (SDDS_bufferedRead(&(int32Value[p][0]), 4 * rows, gzfp, fBuffer, sddsfile)) {
3902 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)");
3903 return(1);
3904 }
3905 break;
3906 case SDDS_UINT32:
3907 uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page);
3908 for (i=0; i<n; i++) {
3909 uint32Value[p-i] = NULL;
3910 }
3911 uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rows);
3912 rowsAllocated[p] = rows;
3913 if (SDDS_bufferedRead(&(uint32Value[p][0]), 4 * rows, gzfp, fBuffer, sddsfile)) {
3914 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)");
3915 return(1);
3916 }
3917 break;
3918 case SDDS_REAL32:
3919 real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page);
3920 for (i=0; i<n; i++) {
3921 real32Value[p-i] = NULL;
3922 }
3923 rowsAllocated[p] = rows;
3924 real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rows);
3925 if (SDDS_bufferedRead(&(real32Value[p][0]), 4 * rows, gzfp, fBuffer, sddsfile)) {
3926 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)");
3927 return(1);
3928 }
3929 break;
3930 case SDDS_REAL64:
3931 real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page);
3932 for (i=0; i<n; i++) {
3933 real64Value[p-i] = NULL;
3934 }
3935 real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rows);
3936 rowsAllocated[p] = rows;
3937 if (SDDS_bufferedRead(&(real64Value[p][0]), 8 * rows, gzfp, fBuffer, sddsfile)) {
3938 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)");
3939 return(1);
3940 }
3941 break;
3942 case SDDS_STRING:
3943 stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page);
3944 for (i=0; i<n; i++) {
3945 stringValue[p-i] = NULL;
3946 }
3947 stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rows);
3948 rowsAllocated[p] = rows;
3949 for (i=0; i<rows; i++) {
3950 stringValue[p][i] = NULL;
3951 if (SDDS_readBinaryString(&(stringValue[p][i]), gzfp, fBuffer, sddsfile)) {
3952 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading strings (SDDSColumn::readBinaryValues)");
3953 return(1);
3954 }
3955 }
3956 break;
3957 case SDDS_CHARACTER:
3958 charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page);
3959 for (i=0; i<n; i++) {
3960 charValue[p-i] = NULL;
3961 }
3962 charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rows);
3963 rowsAllocated[p] = rows;
3964 if (SDDS_bufferedRead(&(charValue[p][0]), rows, gzfp, fBuffer, sddsfile)) {
3965 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)");
3966 return(1);
3967 }
3968 break;
3969 default:
3970 ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--unknown type (SDDSColumn::readBinaryValues)");
3971 return(1);
3972 }
3973 pageCount = page;
3974 rowCount[p] = rows;
3975 return(0);
3976}
#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