/* GUIDELINES Do not exit or print to stdout or stderr from any of the functions in this file */ /* TODO Ensure that strtod returns HUGE_VAL on all operating systems. Modify setType so that it can change the type of an existing column. Update so that you can not read pages out of order (this may be needed for blank pages) fix nonnative binary reads. */ #include #include #include #include #include #include #include #include #include "SDDS3.h" /*********************************************************************************************** * SDDSColumn * * * * C++ Arguments: none * * * * Results: pointer to SDDSColumn object * ***********************************************************************************************/ SDDSColumn::SDDSColumn() { pageCount = 0; rowCount = NULL; rowsAllocated = NULL; rowAllocationIncrement = 1000; columnType = 0; columnName = NULL; columnSymbol = NULL; columnUnits = NULL; columnDescription = NULL; columnFormatString = NULL; columnFieldLength = 0; int32Value = NULL; int16Value = NULL; uint32Value = NULL; uint16Value = NULL; real64Value = NULL; real32Value = NULL; stringValue = NULL; charValue = NULL; } /*********************************************************************************************** * ~SDDSColumn * * * * C++ Arguments: none * * * * Results: none * ***********************************************************************************************/ SDDSColumn::~SDDSColumn() { uint32_t i, j; if (columnName != NULL) SDDS_free(columnName); if (columnSymbol != NULL) SDDS_free(columnSymbol); if (columnUnits != NULL) SDDS_free(columnUnits); if (columnDescription != NULL) SDDS_free(columnDescription); if (columnFormatString != NULL) SDDS_free(columnFormatString); if (int16Value != NULL) { for (i=0; i pageCount)) { return(0); } return(rowCount[page-1]); } /*********************************************************************************************** * setValues * * * * C++ Arguments: int16_t *values, uint32_t page, uint32_t startRow, uint32_t rows * * uint16_t *value, uint32_t page, uint32_t startRow, uint32_t rows * * int32_t *values, uint32_t page, uint32_t startRow, uint32_t rows * * uint32_t *value, uint32_t page, uint32_t startRow, uint32_t rows * * float *value, uint32_t page, uint32_t startRow, uint32_t rows * * double *value, uint32_t page, uint32_t startRow, uint32_t rows * * char **value, uint32_t page, uint32_t startRow, uint32_t rows * * char *value, uint32_t page, uint32_t startRow, uint32_t rows * * * * Results: 0 for success * * 1 for invalid page number * * 2 for invalid startRow number * * 3 for the case where the value cannot be converted to the proper column type * * 4 for invalid column type * ***********************************************************************************************/ int32_t SDDSColumn::setValues(int16_t *values, uint32_t page, uint32_t startRow, uint32_t rows) { uint32_t rowsNeeded, i, n=0, p; bool newPage=false; char s[SDDS_MAXLINE]; if (page == 0) return(1); if (startRow == 0) return(2); startRow--; if (page > pageCount) { newPage = true; n = page - pageCount; } p = page - 1; rowsNeeded = rows + startRow; if (newPage) { rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page); rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]); } if (startRow > 0) { for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]); } for (i=rowCount[p] ; i pageCount) { newPage = true; n = page - pageCount; } p = page - 1; rowsNeeded = rows + startRow; if (newPage) { rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page); rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]); } if (startRow > 0) { for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]); } for (i=rowCount[p] ; i pageCount) { newPage = true; n = page - pageCount; } p = page - 1; rowsNeeded = rows + startRow; if (newPage) { rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page); rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]); } if (startRow > 0) { for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]); } for (i=rowCount[p] ; i pageCount) { newPage = true; n = page - pageCount; } p = page - 1; rowsNeeded = rows + startRow; if (newPage) { rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page); rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]); } if (startRow > 0) { for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]); } for (i=rowCount[p] ; i pageCount) { newPage = true; n = page - pageCount; } p = page - 1; rowsNeeded = rows + startRow; if (newPage) { rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page); rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]); } if (startRow > 0) { for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]); } for (i=rowCount[p] ; i pageCount) { newPage = true; n = page - pageCount; } p = page - 1; rowsNeeded = rows + startRow; if (newPage) { rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page); rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]); } if (startRow > 0) { for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]); } for (i=rowCount[p] ; i pageCount) { newPage = true; n = page - pageCount; } p = page - 1; rowsNeeded = rows + startRow; if (newPage) { rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page); rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]); } for (i=rowCount[p] ; i pageCount) { newPage = true; n = page - pageCount; } p = page - 1; rowsNeeded = rows + startRow; if (newPage) { rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page); rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]); } for (i=rowCount[p] ; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]); } if (startRow > 0) { for (i=rowCount[p] ; isetError((char*)"Unable to read column--invalid page number (SDDSColumn::readAsciiValue)"); return(1); } startRow = getRowCount(page); if (startRow == UINT_MAX) { startRow = 0; } if (bufferSize==0) { bufferSize=SDDS_MAXLINE; buffer = (char*)SDDS_malloc(sizeof(*buffer)*(bufferSize)); } length = *bigBufferSize; if (length < columnFieldLength) { length = columnFieldLength; } if (bufferSize <= length) { bufferSize = 2 * length; buffer = (char*)SDDS_realloc(buffer, sizeof(*buffer)*(bufferSize)); } if (columnType != SDDS_STRING) { if (columnFieldLength) { if (columnFieldLength > *bigBufferSize) { strcpy(buffer, *bigBuffer); **bigBuffer = 0; *bigBufferSize = 0; } else { strncpy(buffer, *bigBuffer, columnFieldLength); buffer[columnFieldLength] = 0; *bigBuffer += columnFieldLength; *bigBufferSize -= columnFieldLength; } } } if (SDDS_INTEGER_TYPE(columnType)) { if (SDDS_getToken(bigBuffer, bigBufferSize, buffer, bufferSize) < 0) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column (SDDSColumn::readAsciiValue)"); returnVal=1; iValue=0; } else { iValue = strtoll(buffer, (char**)NULL, 10); if ((iValue == LLONG_MIN) || (iValue == LLONG_MAX)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--not a valid integer (SDDSColumn::readAsciiValue)"); returnVal=1; iValue=0; } } } else if (SDDS_FLOATING_TYPE(columnType)) { if (SDDS_getToken(bigBuffer, bigBufferSize, buffer, bufferSize) < 0) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column (SDDSColumn::readAsciiValue)"); returnVal=1; dValue=0; } else { dValue = strtod(buffer, (char**)NULL); if ((dValue == HUGE_VAL) || (dValue == -HUGE_VAL)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--not a valid number (SDDSColumn::readAsciiValue)"); returnVal=1; dValue=0; } } } if (page > pageCount) { newPage = true; n = page - pageCount; } p = page - 1; rowsNeeded = 1 + startRow; if (newPage) { rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page); rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]); } int16Value[p][startRow] = (int16_t)iValue; break; case SDDS_UINT16: if (newPage) { /* new page */ uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]); } uint16Value[p][startRow] = (uint16_t)iValue; break; case SDDS_INT32: if (newPage) { /* new page */ int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]); } int32Value[p][startRow] = (int32_t)iValue; break; case SDDS_UINT32: if (newPage) { /* new page */ uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]); } uint32Value[p][startRow] = (uint32_t)iValue; break; case SDDS_REAL32: if (newPage) { /* new pages */ real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]); } real32Value[p][startRow] = (float)dValue; break; case SDDS_REAL64: if (newPage) { /* new pages */ real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]); } real64Value[p][startRow] = (double)dValue; break; case SDDS_STRING: if (newPage) { /* new pages */ stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]); } length = strlen(*bigBuffer); if (length > 0) { if ((*bigBuffer)[length-1] == '\r') { (*bigBuffer)[length-1] = 0; } } if (SDDS_getToken(bigBuffer, bigBufferSize, buffer, bufferSize) < 0) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column (SDDSColumn::readAsciiValue)"); returnVal=1; stringValue[p][startRow] = (char*)SDDS_malloc(sizeof(char) * 4); strcpy(stringValue[p][startRow], "\"\""); } else { SDDS_interpretEscapes(buffer); stringValue[p][startRow] = (char*)SDDS_malloc(sizeof(char) * strlen(buffer) + 1); strcpy(stringValue[p][startRow], buffer); } break; case SDDS_CHARACTER: if (newPage) { /* new pages */ charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]); } if (SDDS_getToken(bigBuffer, bigBufferSize, buffer, bufferSize) < 0) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column (SDDSColumn::readAsciiValue)"); returnVal=1; charValue[p][startRow] = '-'; } else { charValue[p][startRow] = (char)(buffer[0]); } break; default: ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--invalid column type (SDDSColumn::readAsciiValue)"); return(1); } if (newPage) { pageCount = page; rowCount[p] = 1; } else { rowCount[p]++; } return(returnVal); } /*********************************************************************************************** * getInteralValues * * * * C++ Arguments: uint32_t page * * * * Results: pointer to values * * NULL for column value undefined * ***********************************************************************************************/ void* SDDSColumn::getInternalValues(uint32_t page) { uint32_t p; if ((page == 0) || (pageCount < page)) { ((SDDSFile*)sddsfile)->setError((char*)"Invalid page (SDDSColumn::getInternalValues)"); return(NULL); } p = page - 1; if (rowCount[p] == 0) { return(NULL); } switch (columnType) { case SDDS_INT16: return(int16Value[p]); case SDDS_UINT16: return(uint16Value[p]); case SDDS_INT32: return(int32Value[p]); case SDDS_UINT32: return(uint32Value[p]); case SDDS_REAL32: return(real32Value[p]); case SDDS_REAL64: return(real64Value[p]); case SDDS_STRING: return(stringValue[p]); case SDDS_CHARACTER: return(charValue[p]); default: ((SDDSFile*)sddsfile)->setError((char*)"Invalid data type (SDDSColumn::getInternalValues)"); return(NULL); } } /*********************************************************************************************** * getValuesInInt32 * * * * C++ Arguments: uint32_t page, int32_t *errorcode * * * * Results: pointer to values and errorcode=0 for success * * NULL and errorcode=1 for column value undefined * * NULL and errorcode=2 for the case where the value cannot be * * converted to the proper type * * NULL and errorcode=3 for invalid column type * ***********************************************************************************************/ int32_t* SDDSColumn::getValuesInInt32(uint32_t page, int32_t *errorcode) { int64_t iValue; int32_t* rValues; uint32_t p; uint32_t i; if ((page == 0) || (pageCount < page)) { *errorcode = 1; return((int32_t*)NULL); } *errorcode = 0; p = page - 1; if (rowCount[p] == 0) { return((int32_t*)NULL); } rValues = (int32_t*)SDDS_malloc(sizeof(int32_t) * rowCount[p]); switch (columnType) { case SDDS_INT16: for (i=0; i SDDS_NUM_TYPES)) { return(1); } if (fp == NULL) { return(1); } fputs("&column ", fp); if (SDDS_printNamelistField(fp, (char*)"name", columnName)) { return(1); } if (SDDS_printNamelistField(fp, (char*)"symbol", SDDS_blankToNull(columnSymbol))) { return(1); } if (SDDS_printNamelistField(fp, (char*)"units", SDDS_blankToNull(columnUnits))) { return(1); } if (SDDS_printNamelistField(fp, (char*)"description", SDDS_blankToNull(columnDescription))) { return(1); } if (SDDS_printNamelistField(fp, (char*)"format_string", SDDS_blankToNull(columnFormatString))) { return(1); } if (((SDDSFile*)sddsfile)->layoutVersion == 1) { if (SDDS_printNamelistField(fp, (char*)"type", SDDS_getVer1TypeName(columnType))) { return(1); } } else if (((SDDSFile*)sddsfile)->layoutVersion == 2) { if (SDDS_printNamelistField(fp, (char*)"type", SDDS_getVer2TypeName(columnType))) { return(1); } } else { if (SDDS_printNamelistField(fp, (char*)"type", SDDS_getTypeName(columnType))) { return(1); } } fputs("&end\n", fp); return(0); } int32_t SDDSColumn::writeDefinition(voidp *gzfp) { if ((columnType <= 0) || (columnType > SDDS_NUM_TYPES)) { return(1); } if (gzfp == NULL) { return(1); } gzputs(gzfp, "&column "); if (SDDS_printNamelistField(gzfp, (char*)"name", columnName)) { return(1); } if (SDDS_printNamelistField(gzfp, (char*)"symbol", SDDS_blankToNull(columnSymbol))) { return(1); } if (SDDS_printNamelistField(gzfp, (char*)"units", SDDS_blankToNull(columnUnits))) { return(1); } if (SDDS_printNamelistField(gzfp, (char*)"description", SDDS_blankToNull(columnDescription))) { return(1); } if (SDDS_printNamelistField(gzfp, (char*)"format_string", SDDS_blankToNull(columnFormatString))) { return(1); } if (((SDDSFile*)sddsfile)->layoutVersion == 1) { if (SDDS_printNamelistField(gzfp, (char*)"type", SDDS_getVer1TypeName(columnType))) { return(1); } } else if (((SDDSFile*)sddsfile)->layoutVersion == 2) { if (SDDS_printNamelistField(gzfp, (char*)"type", SDDS_getVer2TypeName(columnType))) { return(1); } } else { if (SDDS_printNamelistField(gzfp, (char*)"type", SDDS_getTypeName(columnType))) { return(1); } } gzputs(gzfp, "&end\n"); return(0); } /*********************************************************************************************** * writeAsciiValue * * * * C++ Arguments: FILE *fp, uint32_t page, uint32_t row * * C++ Arguments: voidp *gzfp, uint32_t page, uint32_t row * * * * Results: 0 on success * * 1 on failure * ***********************************************************************************************/ int32_t SDDSColumn::writeAsciiValue(FILE *fp, uint32_t page, uint32_t row) { char c; char *s; int32_t hasWhitespace; if ((page == 0) || (page > pageCount) || (row == 0) || (row > rowCount[page-1])) { return(1); } page--; row--; switch (columnType) { case SDDS_INT16: fprintf(fp, "%" PRId16 " ", int16Value[page][row]); break; case SDDS_UINT16: fprintf(fp, "%" PRIu16 " ", uint16Value[page][row]); break; case SDDS_INT32: fprintf(fp, "%" PRId32 " ", int32Value[page][row]); break; case SDDS_UINT32: fprintf(fp, "%" PRIu32 " ", uint32Value[page][row]); break; case SDDS_REAL32: fprintf(fp, "%.*g ", FLT_DIG, real32Value[page][row]); break; case SDDS_REAL64: fprintf(fp, "%.*g ", DBL_DIG, real64Value[page][row]); break; case SDDS_STRING: s = stringValue[page][row]; hasWhitespace=0; if (SDDS_hasWhitespace(s) || SDDS_stringIsBlank(s)) { fputc('"', fp); hasWhitespace = 1; } while (s && *s) { c = *s++; if (c=='!') { fputs("\\!", fp); } else if (c=='\\') { fputs("\\\\", fp); } else if (c=='"') { fputs("\\\"", fp); } else if (c==' ') { fputc(' ', fp); /* don't escape plain spaces */ } else if (isspace(c) || !isprint(c)) { fprintf(fp, "\\%03o", c); } else { fputc(c, fp); } } if (hasWhitespace) { fputc('"', fp); } fputc(' ', fp); break; case SDDS_CHARACTER: c = charValue[page][row]; if (c=='!') fputs("\\!", fp); else if (c=='\\') fputs("\\\\", fp); else if (c=='"') fputs("\\\"", fp); else if (!c || isspace(c) || !isprint(c)) fprintf(fp, "\\%03o", c); else fputc(c, fp); fputc(' ', fp); break; default: return(1); } return(0); } int32_t SDDSColumn::writeAsciiValue(voidp *gzfp, uint32_t page, uint32_t row) { char c; char *s; int32_t hasWhitespace; if ((page == 0) || (page > pageCount) || (row == 0) || (row > rowCount[page-1])) { return(1); } page--; row--; switch (columnType) { case SDDS_INT16: gzprintf(gzfp, "%" PRId16 " ", int16Value[page][row]); break; case SDDS_UINT16: gzprintf(gzfp, "%" PRIu16 " ", uint16Value[page][row]); break; case SDDS_INT32: gzprintf(gzfp, "%" PRId32 " ", int32Value[page][row]); break; case SDDS_UINT32: gzprintf(gzfp, "%" PRIu32 " ", uint32Value[page][row]); break; case SDDS_REAL32: gzprintf(gzfp, "%.*g ", FLT_DIG, real32Value[page][row]); break; case SDDS_REAL64: gzprintf(gzfp, "%.*g ", DBL_DIG, real64Value[page][row]); break; case SDDS_STRING: s = stringValue[page][row]; hasWhitespace=0; if (SDDS_hasWhitespace(s) || SDDS_stringIsBlank(s)) { gzputc(gzfp, '"'); hasWhitespace = 1; } while (s && *s) { c = *s++; if (c=='!') { gzputs(gzfp, "\\!"); } else if (c=='\\') { gzputs(gzfp, "\\\\"); } else if (c=='"') { gzputs(gzfp, "\\\""); } else if (c==' ') { gzputc(gzfp, ' '); /* don't escape plain spaces */ } else if (isspace(c) || !isprint(c)) { gzprintf(gzfp, "\\%03o", c); } else { gzputc(gzfp, c); } } if (hasWhitespace) { gzputc(gzfp, '"'); } gzputc(gzfp, ' '); break; case SDDS_CHARACTER: c = charValue[page][row]; if (c=='!') gzputs(gzfp, "\\!"); else if (c=='\\') gzputs(gzfp, "\\\\"); else if (c=='"') gzputs(gzfp, "\\\""); else if (!c || isspace(c) || !isprint(c)) gzprintf(gzfp, "\\%03o", c); else gzputc(gzfp, c); gzputc(gzfp, ' '); break; default: return(1); } return(0); } /*********************************************************************************************** * writeAsciiValues * * * * C++ Arguments: FILE *fp, uint32_t page * * C++ Arguments: voidp *gzfp, uint32_t page * * * * Note: column-major-order of ascii files is not implemented yet * * * * Results: 0 on success * * 1 on failure * ***********************************************************************************************/ /* int32_t SDDSColumn::writeAsciiValues(FILE *fp, uint32_t page) { char c; char *s; int32_t hasWhitespace; uint32_t i; if ((page == 0) || (page > pageCount)) { return(1); } page--; switch (columnType) { case SDDS_INT16: for (i=0; i pageCount)) { return(1); } page--; switch (columnType) { case SDDS_INT16: for (i=0; isetError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)"); return(1); } return(0); case SDDS_UINT16: if (SDDS_bufferedWrite(&(uint16Value[page][row]), 2, fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)"); return(1); } return(0); case SDDS_INT32: if (SDDS_bufferedWrite(&(int32Value[page][row]), 4, fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)"); return(1); } return(0); case SDDS_UINT32: if (SDDS_bufferedWrite(&(uint32Value[page][row]), 4, fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)"); return(1); } return(0); case SDDS_REAL32: if (SDDS_bufferedWrite(&(real32Value[page][row]), 4, fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)"); return(1); } return(0); case SDDS_REAL64: if (SDDS_bufferedWrite(&(real64Value[page][row]), 8, fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)"); return(1); } return(0); case SDDS_STRING: if (SDDS_writeBinaryString(stringValue[page][row], fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing string (SDDSColumn::writeBinaryValue)"); return(1); } return(0); case SDDS_CHARACTER: if (SDDS_bufferedWrite(&(charValue[page][row]), 1, fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)"); return(1); } return(0); } ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--unknown type (SDDSColumn::writeBinaryValue)"); return(1); } int32_t SDDSColumn::writeBinaryValue(voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, uint32_t row, bool nonNativeEndian) { switch (columnType) { case SDDS_INT16: if (SDDS_bufferedWrite(&(int16Value[page][row]), 2, gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)"); return(1); } return(0); case SDDS_UINT16: if (SDDS_bufferedWrite(&(uint16Value[page][row]), 2, gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)"); return(1); } return(0); case SDDS_INT32: if (SDDS_bufferedWrite(&(int32Value[page][row]), 4, gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)"); return(1); } return(0); case SDDS_UINT32: if (SDDS_bufferedWrite(&(uint32Value[page][row]), 4, gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)"); return(1); } return(0); case SDDS_REAL32: if (SDDS_bufferedWrite(&(real32Value[page][row]), 4, gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)"); return(1); } return(0); case SDDS_REAL64: if (SDDS_bufferedWrite(&(real64Value[page][row]), 8, gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)"); return(1); } return(0); case SDDS_STRING: if (SDDS_writeBinaryString(stringValue[page][row], gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing string (SDDSColumn::writeBinaryValue)"); return(1); } return(0); case SDDS_CHARACTER: if (SDDS_bufferedWrite(&(charValue[page][row]), 1, gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValue)"); return(1); } return(0); } ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--unknown type (SDDSColumn::writeBinaryValue)"); return(1); } /*********************************************************************************************** * writeBinaryValues * * * * C++ Arguments: FILE *fp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian * * C++ Arguments: voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian * * * * Results: 0 on success * * 1 on failure * ***********************************************************************************************/ int32_t SDDSColumn::writeBinaryValues(FILE *fp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian) { uint32_t row; switch (columnType) { case SDDS_INT16: if (SDDS_bufferedWrite(&(int16Value[page][0]), 2 * rowCount[page], fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)"); return(1); } return(0); case SDDS_UINT16: if (SDDS_bufferedWrite(&(uint16Value[page][0]), 2 * rowCount[page], fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)"); return(1); } return(0); case SDDS_INT32: if (SDDS_bufferedWrite(&(int32Value[page][0]), 4 * rowCount[page], fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)"); return(1); } return(0); case SDDS_UINT32: if (SDDS_bufferedWrite(&(uint32Value[page][0]), 4 * rowCount[page], fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)"); return(1); } return(0); case SDDS_REAL32: if (SDDS_bufferedWrite(&(real32Value[page][0]), 4 * rowCount[page], fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)"); return(1); } return(0); case SDDS_REAL64: if (SDDS_bufferedWrite(&(real64Value[page][0]), 8 * rowCount[page], fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)"); return(1); } return(0); case SDDS_STRING: for (row=0; rowsetError((char*)"Unable to write column--failure writing string (SDDSColumn::writeBinaryValues)"); return(1); } } return(0); case SDDS_CHARACTER: if (SDDS_bufferedWrite(&(charValue[page][0]), rowCount[page], fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)"); return(1); } return(0); } ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--unknown type (SDDSColumn::writeBinaryValues)"); return(1); } int32_t SDDSColumn::writeBinaryValues(voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian) { uint32_t row; switch (columnType) { case SDDS_INT16: if (SDDS_bufferedWrite(&(int16Value[page][0]), 2 * rowCount[page], gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)"); return(1); } return(0); case SDDS_UINT16: if (SDDS_bufferedWrite(&(uint16Value[page][0]), 2 * rowCount[page], gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)"); return(1); } return(0); case SDDS_INT32: if (SDDS_bufferedWrite(&(int32Value[page][0]), 4 * rowCount[page], gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)"); return(1); } return(0); case SDDS_UINT32: if (SDDS_bufferedWrite(&(uint32Value[page][0]), 4 * rowCount[page], gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)"); return(1); } return(0); case SDDS_REAL32: if (SDDS_bufferedWrite(&(real32Value[page][0]), 4 * rowCount[page], gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)"); return(1); } return(0); case SDDS_REAL64: if (SDDS_bufferedWrite(&(real64Value[page][0]), 8 * rowCount[page], gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)"); return(1); } return(0); case SDDS_STRING: for (row=0; rowsetError((char*)"Unable to write column--failure writing string (SDDSColumn::writeBinaryValues)"); return(1); } } return(0); case SDDS_CHARACTER: if (SDDS_bufferedWrite(&(charValue[page][0]), rowCount[page], gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--failure writing value (SDDSColumn::writeBinaryValues)"); return(1); } return(0); } ((SDDSFile*)sddsfile)->setError((char*)"Unable to write column--unknown type (SDDSColumn::writeBinaryValues)"); return(1); } /*********************************************************************************************** * readBinaryValue * * * * C++ Arguments: FILE *fp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian * * C++ Arguments: voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian * * * * Results: 0 on success * * 1 on failure * ***********************************************************************************************/ int32_t SDDSColumn::readBinaryValue(FILE *fp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian) { uint32_t i, n=0, p, rowsNeeded; bool newPage=false; if (page == 0) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--invalid page number (SDDSColumn::readBinaryValue)"); return(1); } if (page > pageCount) { newPage = true; n = page - pageCount; } p = page - 1; if (newPage) { rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page); rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]); } if (SDDS_bufferedRead(&(int16Value[p][rowCount[p]]), 2, fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)"); return(1); } break; case SDDS_UINT16: if (newPage) { /* new page */ uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]); } if (SDDS_bufferedRead(&(uint16Value[p][rowCount[p]]), 2, fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)"); return(1); } break; case SDDS_INT32: if (newPage) { /* new page */ int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]); } if (SDDS_bufferedRead(&(int32Value[p][rowCount[p]]), 4, fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)"); return(1); } break; case SDDS_UINT32: if (newPage) { /* new page */ uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]); } if (SDDS_bufferedRead(&(uint32Value[p][rowCount[p]]), 4, fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)"); return(1); } break; case SDDS_REAL32: if (newPage) { /* new page */ real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]); } if (SDDS_bufferedRead(&(real32Value[p][rowCount[p]]), 4, fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)"); return(1); } break; case SDDS_REAL64: if (newPage) { /* new page */ real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]); } if (SDDS_bufferedRead(&(real64Value[p][rowCount[p]]), 8, fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)"); return(1); } break; case SDDS_STRING: if (newPage) { /* new pages */ stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]); } stringValue[p][rowCount[p]] = NULL; if (SDDS_readBinaryString(&(stringValue[p][rowCount[p]]), fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading string (SDDSColumn::readBinaryValue)"); return(1); } break; case SDDS_CHARACTER: if (newPage) { /* new page */ charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]); } if (SDDS_bufferedRead(&(charValue[p][rowCount[p]]), 1, fp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)"); return(1); } break; default: ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--unknown type (SDDSColumn::readBinaryValue)"); return(1); } if (newPage) { pageCount = page; rowCount[p] = 1; } else { rowCount[p]++; } return(0); } int32_t SDDSColumn::readBinaryValue(voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, bool nonNativeEndian) { uint32_t i, n=0, p, rowsNeeded; bool newPage=false; if (page == 0) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--invalid page number (SDDSColumn::readBinaryValue)"); return(1); } if (page > pageCount) { newPage = true; n = page - pageCount; } p = page - 1; if (newPage) { rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page); rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int16Value[p] = (int16_t*)SDDS_realloc(int16Value[p], sizeof(int16_t) * rowsAllocated[p]); } if (SDDS_bufferedRead(&(int16Value[p][rowCount[p]]), 2, gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)"); return(1); } break; case SDDS_UINT16: if (newPage) { /* new page */ uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint16Value[p] = (uint16_t*)SDDS_realloc(uint16Value[p], sizeof(uint16_t) * rowsAllocated[p]); } if (SDDS_bufferedRead(&(uint16Value[p][rowCount[p]]), 2, gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)"); return(1); } break; case SDDS_INT32: if (newPage) { /* new page */ int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; int32Value[p] = (int32_t*)SDDS_realloc(int32Value[p], sizeof(int32_t) * rowsAllocated[p]); } if (SDDS_bufferedRead(&(int32Value[p][rowCount[p]]), 4, gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)"); return(1); } break; case SDDS_UINT32: if (newPage) { /* new page */ uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; uint32Value[p] = (uint32_t*)SDDS_realloc(uint32Value[p], sizeof(uint32_t) * rowsAllocated[p]); } if (SDDS_bufferedRead(&(uint32Value[p][rowCount[p]]), 4, gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)"); return(1); } break; case SDDS_REAL32: if (newPage) { /* new page */ real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real32Value[p] = (float*)SDDS_realloc(real32Value[p], sizeof(float) * rowsAllocated[p]); } if (SDDS_bufferedRead(&(real32Value[p][rowCount[p]]), 4, gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)"); return(1); } break; case SDDS_REAL64: if (newPage) { /* new page */ real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; real64Value[p] = (double*)SDDS_realloc(real64Value[p], sizeof(double) * rowsAllocated[p]); } if (SDDS_bufferedRead(&(real64Value[p][rowCount[p]]), 8, gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)"); return(1); } break; case SDDS_STRING: if (newPage) { /* new pages */ stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; stringValue[p] = (char**)SDDS_realloc(stringValue[p], sizeof(char*) * rowsAllocated[p]); } stringValue[p][rowCount[p]] = NULL; if (SDDS_readBinaryString(&(stringValue[p][rowCount[p]]), gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading string (SDDSColumn::readBinaryValue)"); return(1); } break; case SDDS_CHARACTER: if (newPage) { /* new page */ charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page); for (i=0; i rowsAllocated[p]) { rowsAllocated[p] = rowsNeeded + rowAllocationIncrement; charValue[p] = (char*)SDDS_realloc(charValue[p], sizeof(char) * rowsAllocated[p]); } if (SDDS_bufferedRead(&(charValue[p][rowCount[p]]), 1, gzfp, fBuffer, sddsfile)) { ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--failure reading value (SDDSColumn::readBinaryValue)"); return(1); } break; default: ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--unknown type (SDDSColumn::readBinaryValue)"); return(1); } if (newPage) { pageCount = page; rowCount[p] = 1; } else { rowCount[p]++; } return(0); } /************************* * readBinaryValues C++ Arguments: FILE *fp, SDDS_FILEBUFFER *fBuffer, uint32_t page, uint32_t rows, bool nonNativeEndian voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, uint32_t rows, bool nonNativeEndian Note: used for column-major-order Results: 0 on success 1 on failure *************************/ int32_t SDDSColumn::readBinaryValues(FILE *fp, SDDS_FILEBUFFER *fBuffer, uint32_t page, uint32_t rows, bool nonNativeEndian) { uint32_t i, n, p; if (page == 0) { ((SDDSFile*)sddsfile)->setError((char*)"Invalid page number--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } if (page > pageCount) { n = page - pageCount; } else { ((SDDSFile*)sddsfile)->setError((char*)"Invalid page number--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } p = page - 1; rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page); rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page); for (i=0; isetError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } break; case SDDS_UINT16: uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page); for (i=0; isetError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } break; case SDDS_INT32: int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page); for (i=0; isetError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } break; case SDDS_UINT32: uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page); for (i=0; isetError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } break; case SDDS_REAL32: real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page); for (i=0; isetError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } break; case SDDS_REAL64: real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page); for (i=0; isetError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } break; case SDDS_STRING: stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page); for (i=0; isetError((char*)"Unable to read column--failure reading strings (SDDSColumn::readBinaryValues)"); return(1); } } break; case SDDS_CHARACTER: charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page); for (i=0; isetError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } break; default: ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--unknown type (SDDSColumn::readBinaryValues)"); return(1); } pageCount = page; rowCount[p] = rows; return(0); } int32_t SDDSColumn::readBinaryValues(voidp *gzfp, SDDS_FILEBUFFER *fBuffer, uint32_t page, uint32_t rows, bool nonNativeEndian) { uint32_t i, n, p; if (page == 0) { ((SDDSFile*)sddsfile)->setError((char*)"Invalid page number--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } if (page > pageCount) { n = page - pageCount; } else { ((SDDSFile*)sddsfile)->setError((char*)"Invalid page number--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } p = page - 1; rowCount = (uint32_t*)SDDS_realloc(rowCount, sizeof(uint32_t) * page); rowsAllocated = (uint32_t*)SDDS_realloc(rowsAllocated, sizeof(uint32_t) * page); for (i=0; isetError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } break; case SDDS_UINT16: uint16Value = (uint16_t**)SDDS_realloc(uint16Value, sizeof(uint16_t*) * page); for (i=0; isetError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } break; case SDDS_INT32: int32Value = (int32_t**)SDDS_realloc(int32Value, sizeof(int32_t*) * page); for (i=0; isetError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } break; case SDDS_UINT32: uint32Value = (uint32_t**)SDDS_realloc(uint32Value, sizeof(uint32_t*) * page); for (i=0; isetError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } break; case SDDS_REAL32: real32Value = (float**)SDDS_realloc(real32Value, sizeof(float*) * page); for (i=0; isetError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } break; case SDDS_REAL64: real64Value = (double**)SDDS_realloc(real64Value, sizeof(double*) * page); for (i=0; isetError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } break; case SDDS_STRING: stringValue = (char***)SDDS_realloc(stringValue, sizeof(char**) * page); for (i=0; isetError((char*)"Unable to read column--failure reading strings (SDDSColumn::readBinaryValues)"); return(1); } } break; case SDDS_CHARACTER: charValue = (char**)SDDS_realloc(charValue, sizeof(char*) * page); for (i=0; isetError((char*)"Unable to read column--failure reading values (SDDSColumn::readBinaryValues)"); return(1); } break; default: ((SDDSFile*)sddsfile)->setError((char*)"Unable to read column--unknown type (SDDSColumn::readBinaryValues)"); return(1); } pageCount = page; rowCount[p] = rows; return(0); }