From fd3482f77d0afc3357d3e3d076aa2a412ffd5309 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Tue, 13 Jul 2021 08:06:48 -0600 Subject: [PATCH 01/28] pop spaces at end of line --- lib/vdc/BOVCollection.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index 502834915d..45e69e4908 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -339,12 +339,13 @@ template int BOVCollection::_findToken(const std::string &token, std for (size_t i = 0; i < line.length(); i++) { if (line[i] == '#') { line.erase(line.begin() + i, line.end()); - if (line[line.length() - 1] == ' ') // If last char is a space, pop it - line.pop_back(); break; } } + if (line[line.length() - 1] == ' ') // If last char is a space, pop it + line.pop_back(); + size_t pos = line.find(token); if (pos != std::string::npos) { // We found the token _findTokenValue(line); From 3a53e0db1b25e5d22e0aec1f33e1da2d11d3c3f7 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Tue, 13 Jul 2021 12:27:52 -0600 Subject: [PATCH 02/28] some bugs fixed --- include/vapor/BOVCollection.h | 4 ++++ lib/vdc/BOVCollection.cpp | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/vapor/BOVCollection.h b/include/vapor/BOVCollection.h index 9249f34536..6c593620bc 100644 --- a/include/vapor/BOVCollection.h +++ b/include/vapor/BOVCollection.h @@ -84,6 +84,7 @@ class BOVCollection : public Wasp::MyBase { int _invalidDimensionError(std::string token) const; int _invalidFormatError(std::string token) const; + int _invalidEndianError(std::string token) const; int _failureToReadError(std::string token) const; int _inconsistentValueError(std::string token) const; int _invalidValueError(std::string token) const; @@ -122,6 +123,9 @@ class BOVCollection : public Wasp::MyBase { static const std::string _zDim; static const std::string _timeDim; + static const std::string _bigEndianString; + static const std::string _littleEndianString; + static const std::string _byteFormatString; static const std::string _shortFormatString; static const std::string _intFormatString; diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index 45e69e4908..9db8d8dac9 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -7,6 +7,7 @@ #include #include #include "vapor/VAssert.h" +#include "vapor/utils.h" #include #ifdef _WINDOWS @@ -52,6 +53,9 @@ const std::string BOVCollection::_yDim = "y"; const std::string BOVCollection::_zDim = "z"; const std::string BOVCollection::_timeDim = "t"; +const std::string BOVCollection::_bigEndianString = "BIG"; +const std::string BOVCollection::_littleEndianString = "LITTLE"; + const std::string BOVCollection::_byteFormatString = "BYTE"; const std::string BOVCollection::_shortFormatString = "SHORT"; const std::string BOVCollection::_intFormatString = "INT"; @@ -218,6 +222,8 @@ int BOVCollection::_validateParsedValues() } // Validate endian type + if (_tmpDataEndian != _bigEndianString && _tmpDataEndian != _littleEndianString ) + return _invalidEndianError(ENDIAN_TOKEN); if (_tmpDataEndian != _dataEndian && _dataEndianAssigned == true) return _inconsistentValueError(ENDIAN_TOKEN); else { @@ -264,6 +270,13 @@ int BOVCollection::_invalidFormatError(std::string token) const return -1; } +int BOVCollection::_invalidEndianError(std::string token) const +{ + std::string message = token + " must be either " + _littleEndianString + " or " + _bigEndianString; + SetErrMsg(message.c_str()); + return -1; +} + int BOVCollection::_failureToReadError(std::string token) const { SetErrMsg(("Failure reading BOV time token: " + token).c_str()); @@ -474,11 +487,9 @@ template int BOVCollection::ReadRegion(std::string varname, size_t ts, return -1; } - size_t numValues = _gridSize[0] * _gridSize[1] * _gridSize[2]; - int n = 1; bool systemLittleEndian = *(char *)&n == 1 ? true : false; - bool dataLittleEndian = _dataEndian == "LITTLE" ? true : false; + bool dataLittleEndian = _dataEndian == _littleEndianString ? true : false; bool needSwap = systemLittleEndian != dataLittleEndian ? true : false; // Read a "pencil" of data along the X axis, one row at a time @@ -486,6 +497,7 @@ template int BOVCollection::ReadRegion(std::string varname, size_t ts, // Note: allocate buffer once and reuse for many times, so repeated allocation is avoided. std::vector vReadBuffer(count * formatSize); unsigned char * readBuffer = vReadBuffer.data(); + for (size_t k = min[2]; k <= max[2]; k++) { size_t zOffset = _gridSize[0] * _gridSize[1] * k; for (size_t j = min[1]; j <= max[1]; j++) { @@ -506,8 +518,8 @@ template int BOVCollection::ReadRegion(std::string varname, size_t ts, return -1; } - if (needSwap) { _swapBytes(readBuffer, formatSize, numValues); } - + if (needSwap) { _swapBytes(readBuffer, formatSize, count); } + if (_dataFormat == DC::XType::INT32) { int *castBuffer = (int *)readBuffer; for (int i = 0; i < count; i++) { *region++ = (typename std::remove_pointer::type)castBuffer[i]; } From eb6d03299c49e8f0dcb8b5adbd75db28ca5d38f0 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Tue, 13 Jul 2021 14:08:21 -0600 Subject: [PATCH 03/28] add relative file path search --- include/vapor/BOVCollection.h | 17 +++++---- lib/vdc/BOVCollection.cpp | 65 +++++++++++++++++++++++++++-------- 2 files changed, 61 insertions(+), 21 deletions(-) diff --git a/include/vapor/BOVCollection.h b/include/vapor/BOVCollection.h index 6c593620bc..343ebb28d9 100644 --- a/include/vapor/BOVCollection.h +++ b/include/vapor/BOVCollection.h @@ -29,6 +29,8 @@ class BOVCollection : public Wasp::MyBase { template int ReadRegion(std::string varname, size_t ts, const std::vector &min, const std::vector &max, T region); private: + std::string _currentFilePath; + float _time; std::vector _times; std::string _dataFile; @@ -82,13 +84,14 @@ class BOVCollection : public Wasp::MyBase { int _sizeOfFormat(DC::XType) const; void _swapBytes(void *vptr, size_t size, size_t n) const; - int _invalidDimensionError(std::string token) const; - int _invalidFormatError(std::string token) const; - int _invalidEndianError(std::string token) const; - int _failureToReadError(std::string token) const; - int _inconsistentValueError(std::string token) const; - int _invalidValueError(std::string token) const; - int _missingValueError(std::string token) const; + int _invalidFileError(const std::string &token, const std::string &file) const; + int _invalidDimensionError(const std::string &token) const; + int _invalidFormatError(const std::string &token) const; + int _invalidEndianError(const std::string &token) const; + int _failureToReadError(const std::string &token) const; + int _inconsistentValueError(const std::string &token) const; + int _invalidValueError(const std::string &token) const; + int _missingValueError(const std::string &token) const; static const std::string TIME_TOKEN; static const std::string DATA_FILE_TOKEN; diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index 9db8d8dac9..b190d0a13e 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -62,6 +62,17 @@ const std::string BOVCollection::_intFormatString = "INT"; const std::string BOVCollection::_floatFormatString = "FLOAT"; const std::string BOVCollection::_doubleFormatString = "DOUBLE"; +namespace { + void SplitFilename (const string& str) + { + size_t found; + cout << "Splitting: " << str << endl; + found=str.find_last_of("/\\"); + cout << " folder: " << str.substr(0,found) << endl; + cout << " file: " << str.substr(found+1) << endl; + } +} + BOVCollection::BOVCollection() : _time(_defaultTime), _dataFile(_defaultFile), _dataFormat(_defaultFormat), _variable(_defaultVar), _dataEndian(_defaultEndian), _centering(_defaultCentering), _byteOffset(_defaultByteOffset), _divideBrick(_defaultDivBrick), _dataComponents(_defaultComponents), _tmpDataFormat(_defaultFormat), _tmpDataEndian(_defaultEndian), _tmpByteOffset(_defaultByteOffset), _gridSizeAssigned(false), @@ -87,6 +98,11 @@ int BOVCollection::Initialize(const std::vector &paths) std::ifstream header; for (int i = 0; i < paths.size(); i++) { _dataFile = _defaultFile; + + _currentFilePath = paths[i]; + size_t found = _currentFilePath.find_last_of("/\\"); + _currentFilePath = _currentFilePath.substr(0,found); + header.open(paths[i]); if (header.is_open()) { rc = _parseHeader(header); @@ -97,7 +113,7 @@ int BOVCollection::Initialize(const std::vector &paths) rc = _validateParsedValues(); if (rc < 0) { - SetErrMsg("Inconsistency found in BOV token."); + SetErrMsg("Validating BOV tokens failed"); return -1; } @@ -136,8 +152,9 @@ int BOVCollection::_parseHeader(std::ifstream &header) rc = _findToken(DATA_FILE_TOKEN, line, dataFile); if (rc == (int)parseCodes::ERROR) return _failureToReadError(DATA_FILE_TOKEN); - else if (rc == (int)parseCodes::FOUND) + else if (rc == (int)parseCodes::FOUND) { _dataFile = dataFile; + } double time; rc = _findToken(TIME_TOKEN, line, time); @@ -185,6 +202,18 @@ int BOVCollection::_parseHeader(std::ifstream &header) int BOVCollection::_validateParsedValues() { + char actualPath[PATH_MAX+1]; + char* success = realpath(_dataFile.c_str(), actualPath); + if (success == nullptr) + // At this point we can't find the absolute path, so it might be a relative path. + // Try prepending the directory of the .bov file to the data file + _dataFile = _currentFilePath + "//" + _dataFile; + success = realpath(_dataFile.c_str(), actualPath); + if (success == nullptr) + return _invalidFileError(DATA_FILE_TOKEN, _dataFile); + else + _dataFile = std::string(actualPath); + // Validate grid dimensions if (_tmpGridSize[0] < 1 || _tmpGridSize[1] < 1 || _tmpGridSize[2] < 1) return _invalidDimensionError(GRID_SIZE_TOKEN); @@ -251,45 +280,51 @@ void BOVCollection::_populateDataFileMap() _dataFileMap[_variable][_time] = _dataFile; } -int BOVCollection::_missingValueError(std::string token) const +int BOVCollection::_invalidFileError(const std::string &token, const std::string &file) const +{ + SetErrMsg((token + " was unable to be identified").c_str()); + return -1; +} + +int BOVCollection::_missingValueError(const std::string &token) const { SetErrMsg(("BOV file must contain token: " + token).c_str()); return -1; } -int BOVCollection::_invalidDimensionError(std::string token) const +int BOVCollection::_invalidDimensionError(const std::string &token) const { SetErrMsg((token + " must have all dimensions > 1").c_str()); return -1; } -int BOVCollection::_invalidFormatError(std::string token) const +int BOVCollection::_invalidFormatError(const std::string &token) const { std::string message = token + " must be either INT, FLOAT, or DOUBLE."; SetErrMsg(message.c_str()); return -1; } -int BOVCollection::_invalidEndianError(std::string token) const +int BOVCollection::_invalidEndianError(const std::string &token) const { std::string message = token + " must be either " + _littleEndianString + " or " + _bigEndianString; SetErrMsg(message.c_str()); return -1; } -int BOVCollection::_failureToReadError(std::string token) const +int BOVCollection::_failureToReadError(const std::string &token) const { - SetErrMsg(("Failure reading BOV time token: " + token).c_str()); + SetErrMsg(("Failure reading BOV token: " + token).c_str()); return -1; } -int BOVCollection::_inconsistentValueError(std::string token) const +int BOVCollection::_inconsistentValueError(const std::string &token) const { SetErrMsg((token + " must be consistent in all BOV files").c_str()); return -1; } -int BOVCollection::_invalidValueError(std::string token) const +int BOVCollection::_invalidValueError(const std::string &token) const { SetErrMsg(("Invalid value for token: " + token).c_str()); return -1; @@ -320,12 +355,13 @@ template<> int BOVCollection::_findToken(const std::string &token, st for (size_t i = 0; i < line.length(); i++) { if (line[i] == '#') { line.erase(line.begin() + i, line.end()); - if (line[line.length() - 1] == ' ') // If last char is a space, pop it - line.pop_back(); break; } } + if (line[line.length() - 1] == ' ') // If last char is a space, pop it + line.pop_back(); + size_t pos = line.find(token); if (pos != std::string::npos) { // We found the token std::string format = line; @@ -395,11 +431,12 @@ template int BOVCollection::_findToken(const std::string &token, std for (size_t i = 0; i < line.length(); i++) { if (line[i] == '#') { line.erase(line.begin() + i, line.end()); - if (line[line.length() - 1] == ' ') // If last char is a space, pop it - line.pop_back(); break; } } + + if (line[line.length() - 1] == ' ') // If last char is a space, pop it + line.pop_back(); size_t pos = line.find(token); if (pos != std::string::npos) { // We found the token From 38f17f9d7398a0d76d56d0a54f3023d2dad00ed3 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Wed, 14 Jul 2021 08:28:01 -0600 Subject: [PATCH 04/28] incremental time fix --- include/vapor/BOVCollection.h | 2 ++ lib/vdc/BOVCollection.cpp | 54 ++++++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/include/vapor/BOVCollection.h b/include/vapor/BOVCollection.h index 343ebb28d9..f05b9987b8 100644 --- a/include/vapor/BOVCollection.h +++ b/include/vapor/BOVCollection.h @@ -84,6 +84,8 @@ class BOVCollection : public Wasp::MyBase { int _sizeOfFormat(DC::XType) const; void _swapBytes(void *vptr, size_t size, size_t n) const; + int _invalidFileSizeError(size_t dataSize, size_t fileSize) const; + int _cannotStatFileError() const; int _invalidFileError(const std::string &token, const std::string &file) const; int _invalidDimensionError(const std::string &token) const; int _invalidFormatError(const std::string &token) const; diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index b190d0a13e..5e95bee5a4 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "vapor/VAssert.h" #include "vapor/utils.h" #include @@ -62,17 +63,6 @@ const std::string BOVCollection::_intFormatString = "INT"; const std::string BOVCollection::_floatFormatString = "FLOAT"; const std::string BOVCollection::_doubleFormatString = "DOUBLE"; -namespace { - void SplitFilename (const string& str) - { - size_t found; - cout << "Splitting: " << str << endl; - found=str.find_last_of("/\\"); - cout << " folder: " << str.substr(0,found) << endl; - cout << " file: " << str.substr(found+1) << endl; - } -} - BOVCollection::BOVCollection() : _time(_defaultTime), _dataFile(_defaultFile), _dataFormat(_defaultFormat), _variable(_defaultVar), _dataEndian(_defaultEndian), _centering(_defaultCentering), _byteOffset(_defaultByteOffset), _divideBrick(_defaultDivBrick), _dataComponents(_defaultComponents), _tmpDataFormat(_defaultFormat), _tmpDataEndian(_defaultEndian), _tmpByteOffset(_defaultByteOffset), _gridSizeAssigned(false), @@ -99,10 +89,15 @@ int BOVCollection::Initialize(const std::vector &paths) for (int i = 0; i < paths.size(); i++) { _dataFile = _defaultFile; + // Save the path to the BOV header so we can add it + // to data files given with a relative path _currentFilePath = paths[i]; size_t found = _currentFilePath.find_last_of("/\\"); _currentFilePath = _currentFilePath.substr(0,found); + _timeAssigned = false; + _variableAssigned = false; + header.open(paths[i]); if (header.is_open()) { rc = _parseHeader(header); @@ -160,15 +155,21 @@ int BOVCollection::_parseHeader(std::ifstream &header) rc = _findToken(TIME_TOKEN, line, time); if (rc == (int)parseCodes::ERROR) return _failureToReadError(TIME_TOKEN); - else if (rc == (int)parseCodes::FOUND) + else if (rc == (int)parseCodes::FOUND) { + if (_timeAssigned == true) return _multipleTimestepError(); _time = time; + _timeAssigned = true; + } std::string variable; rc = _findToken(VARIABLE_TOKEN, line, variable); if (rc == (int)parseCodes::ERROR) return _invalidValueError(VARIABLE_TOKEN); - else if (rc == (int)parseCodes::FOUND) + else if (rc == (int)parseCodes::FOUND) { + if (_variableAssigned == true) return _multipleVariablesError(); _variable = variable; + _variableAssigned = true; + } rc = _findToken(GRID_SIZE_TOKEN, line, _tmpGridSize); if (rc == (int)parseCodes::ERROR) return _failureToReadError(GRID_SIZE_TOKEN); @@ -202,6 +203,9 @@ int BOVCollection::_parseHeader(std::ifstream &header) int BOVCollection::_validateParsedValues() { + // Validate that the data file exists. + // If not given an absolute path, construct one + // from the header file's containing directory. char actualPath[PATH_MAX+1]; char* success = realpath(_dataFile.c_str(), actualPath); if (success == nullptr) @@ -267,6 +271,19 @@ int BOVCollection::_validateParsedValues() _byteOffset = _tmpByteOffset; _byteOffsetAssigned = true; } + + // Validate file size + size_t fileSize; + size_t dataSize = _gridSize[0]*_gridSize[1]*_gridSize[2]*_sizeOfFormat(_dataFormat); + struct stat stat_buf; + int rc = stat(_dataFile.c_str(), &stat_buf); + if (rc == 0) + fileSize = stat_buf.st_size; + else + return _cannotStatFileError(); + if (dataSize != fileSize) + return _invalidFileSizeError(dataSize, fileSize); + return 0; } @@ -280,6 +297,17 @@ void BOVCollection::_populateDataFileMap() _dataFileMap[_variable][_time] = _dataFile; } +int BOVCollection::_cannotStatFileError() const { + SetErrMsg(("Unable to get file status for " + _dataFile).c_str()); + return -1; +} + +int BOVCollection::_invalidFileSizeError(size_t dataSize, size_t fileSize) const { + SetErrMsg(("Data file " + _dataFile + " of size " + to_string(fileSize) + " bytes does not match the size of the the data " + "specified in BOV header (" + to_string(dataSize) + " bytes).").c_str()); + return -1; +} + int BOVCollection::_invalidFileError(const std::string &token, const std::string &file) const { SetErrMsg((token + " was unable to be identified").c_str()); From 05ab55c205d9445ab8114133f65c4d5f94678bf7 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Wed, 14 Jul 2021 10:35:16 -0600 Subject: [PATCH 05/28] inc --- lib/vdc/BOVCollection.cpp | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index 5e95bee5a4..d02edcd49a 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -95,9 +95,6 @@ int BOVCollection::Initialize(const std::vector &paths) size_t found = _currentFilePath.find_last_of("/\\"); _currentFilePath = _currentFilePath.substr(0,found); - _timeAssigned = false; - _variableAssigned = false; - header.open(paths[i]); if (header.is_open()) { rc = _parseHeader(header); @@ -155,21 +152,13 @@ int BOVCollection::_parseHeader(std::ifstream &header) rc = _findToken(TIME_TOKEN, line, time); if (rc == (int)parseCodes::ERROR) return _failureToReadError(TIME_TOKEN); - else if (rc == (int)parseCodes::FOUND) { - if (_timeAssigned == true) return _multipleTimestepError(); - _time = time; - _timeAssigned = true; - } + else if (rc == (int)parseCodes::FOUND) _time = time; std::string variable; rc = _findToken(VARIABLE_TOKEN, line, variable); if (rc == (int)parseCodes::ERROR) return _invalidValueError(VARIABLE_TOKEN); - else if (rc == (int)parseCodes::FOUND) { - if (_variableAssigned == true) return _multipleVariablesError(); - _variable = variable; - _variableAssigned = true; - } + else if (rc == (int)parseCodes::FOUND) _variable = variable; rc = _findToken(GRID_SIZE_TOKEN, line, _tmpGridSize); if (rc == (int)parseCodes::ERROR) return _failureToReadError(GRID_SIZE_TOKEN); @@ -387,8 +376,9 @@ template<> int BOVCollection::_findToken(const std::string &token, st } } - if (line[line.length() - 1] == ' ') // If last char is a space, pop it + while (line[line.length() - 1] == ' ') // If last char is a space, pop it line.pop_back(); + size_t pos = line.find(token); if (pos != std::string::npos) { // We found the token @@ -420,7 +410,7 @@ template int BOVCollection::_findToken(const std::string &token, std } } - if (line[line.length() - 1] == ' ') // If last char is a space, pop it + while (line[line.length() - 1] == ' ') // If last char is a space, pop it line.pop_back(); size_t pos = line.find(token); @@ -463,7 +453,7 @@ template int BOVCollection::_findToken(const std::string &token, std } } - if (line[line.length() - 1] == ' ') // If last char is a space, pop it + while (line[line.length() - 1] == ' ') // If last char is a space, pop it line.pop_back(); size_t pos = line.find(token); From e29fbd7c29be17d88a8664f596ad5f929f33a8c1 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Wed, 14 Jul 2021 15:54:12 -0600 Subject: [PATCH 06/28] limits test --- lib/vdc/BOVCollection.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index d02edcd49a..31fac829d9 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -11,9 +11,12 @@ #include "vapor/utils.h" #include -#ifdef _WINDOWS +#ifdef WIN32 + #include #define _USE_MATH_DEFINES #pragma warning(disable : 4251 4100) +#else + #include #endif #include From 6ccdc2149cbf79d0f38854331676731b0e4fa20a Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Wed, 14 Jul 2021 16:20:33 -0600 Subject: [PATCH 07/28] close if guard --- lib/vdc/BOVCollection.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index 31fac829d9..f78d5a8550 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -200,15 +200,15 @@ int BOVCollection::_validateParsedValues() // from the header file's containing directory. char actualPath[PATH_MAX+1]; char* success = realpath(_dataFile.c_str(), actualPath); - if (success == nullptr) + if (success == nullptr) { // At this point we can't find the absolute path, so it might be a relative path. // Try prepending the directory of the .bov file to the data file _dataFile = _currentFilePath + "//" + _dataFile; success = realpath(_dataFile.c_str(), actualPath); if (success == nullptr) return _invalidFileError(DATA_FILE_TOKEN, _dataFile); - else - _dataFile = std::string(actualPath); + } + else _dataFile = std::string(actualPath); // Validate grid dimensions if (_tmpGridSize[0] < 1 || _tmpGridSize[1] < 1 || _tmpGridSize[2] < 1) From c58ee0a89bd41aed24f0debb040e4323d6debebd Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Wed, 14 Jul 2021 16:25:15 -0600 Subject: [PATCH 08/28] clang format --- lib/vdc/BOVCollection.cpp | 50 +++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index f78d5a8550..744b1dfe63 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -96,7 +96,7 @@ int BOVCollection::Initialize(const std::vector &paths) // to data files given with a relative path _currentFilePath = paths[i]; size_t found = _currentFilePath.find_last_of("/\\"); - _currentFilePath = _currentFilePath.substr(0,found); + _currentFilePath = _currentFilePath.substr(0, found); header.open(paths[i]); if (header.is_open()) { @@ -155,13 +155,15 @@ int BOVCollection::_parseHeader(std::ifstream &header) rc = _findToken(TIME_TOKEN, line, time); if (rc == (int)parseCodes::ERROR) return _failureToReadError(TIME_TOKEN); - else if (rc == (int)parseCodes::FOUND) _time = time; + else if (rc == (int)parseCodes::FOUND) + _time = time; std::string variable; rc = _findToken(VARIABLE_TOKEN, line, variable); if (rc == (int)parseCodes::ERROR) return _invalidValueError(VARIABLE_TOKEN); - else if (rc == (int)parseCodes::FOUND) _variable = variable; + else if (rc == (int)parseCodes::FOUND) + _variable = variable; rc = _findToken(GRID_SIZE_TOKEN, line, _tmpGridSize); if (rc == (int)parseCodes::ERROR) return _failureToReadError(GRID_SIZE_TOKEN); @@ -198,17 +200,16 @@ int BOVCollection::_validateParsedValues() // Validate that the data file exists. // If not given an absolute path, construct one // from the header file's containing directory. - char actualPath[PATH_MAX+1]; - char* success = realpath(_dataFile.c_str(), actualPath); + char actualPath[PATH_MAX + 1]; + char *success = realpath(_dataFile.c_str(), actualPath); if (success == nullptr) { // At this point we can't find the absolute path, so it might be a relative path. // Try prepending the directory of the .bov file to the data file _dataFile = _currentFilePath + "//" + _dataFile; success = realpath(_dataFile.c_str(), actualPath); - if (success == nullptr) - return _invalidFileError(DATA_FILE_TOKEN, _dataFile); - } - else _dataFile = std::string(actualPath); + if (success == nullptr) return _invalidFileError(DATA_FILE_TOKEN, _dataFile); + } else + _dataFile = std::string(actualPath); // Validate grid dimensions if (_tmpGridSize[0] < 1 || _tmpGridSize[1] < 1 || _tmpGridSize[2] < 1) @@ -247,8 +248,7 @@ int BOVCollection::_validateParsedValues() } // Validate endian type - if (_tmpDataEndian != _bigEndianString && _tmpDataEndian != _littleEndianString ) - return _invalidEndianError(ENDIAN_TOKEN); + if (_tmpDataEndian != _bigEndianString && _tmpDataEndian != _littleEndianString) return _invalidEndianError(ENDIAN_TOKEN); if (_tmpDataEndian != _dataEndian && _dataEndianAssigned == true) return _inconsistentValueError(ENDIAN_TOKEN); else { @@ -265,16 +265,15 @@ int BOVCollection::_validateParsedValues() } // Validate file size - size_t fileSize; - size_t dataSize = _gridSize[0]*_gridSize[1]*_gridSize[2]*_sizeOfFormat(_dataFormat); + size_t fileSize; + size_t dataSize = _gridSize[0] * _gridSize[1] * _gridSize[2] * _sizeOfFormat(_dataFormat); struct stat stat_buf; - int rc = stat(_dataFile.c_str(), &stat_buf); + int rc = stat(_dataFile.c_str(), &stat_buf); if (rc == 0) fileSize = stat_buf.st_size; else return _cannotStatFileError(); - if (dataSize != fileSize) - return _invalidFileSizeError(dataSize, fileSize); + if (dataSize != fileSize) return _invalidFileSizeError(dataSize, fileSize); return 0; } @@ -289,14 +288,19 @@ void BOVCollection::_populateDataFileMap() _dataFileMap[_variable][_time] = _dataFile; } -int BOVCollection::_cannotStatFileError() const { +int BOVCollection::_cannotStatFileError() const +{ SetErrMsg(("Unable to get file status for " + _dataFile).c_str()); return -1; } -int BOVCollection::_invalidFileSizeError(size_t dataSize, size_t fileSize) const { - SetErrMsg(("Data file " + _dataFile + " of size " + to_string(fileSize) + " bytes does not match the size of the the data " - "specified in BOV header (" + to_string(dataSize) + " bytes).").c_str()); +int BOVCollection::_invalidFileSizeError(size_t dataSize, size_t fileSize) const +{ + SetErrMsg(("Data file " + _dataFile + " of size " + to_string(fileSize) + + " bytes does not match the size of the the data " + "specified in BOV header (" + + to_string(dataSize) + " bytes).") + .c_str()); return -1; } @@ -381,7 +385,7 @@ template<> int BOVCollection::_findToken(const std::string &token, st while (line[line.length() - 1] == ' ') // If last char is a space, pop it line.pop_back(); - + size_t pos = line.find(token); if (pos != std::string::npos) { // We found the token @@ -455,7 +459,7 @@ template int BOVCollection::_findToken(const std::string &token, std break; } } - + while (line[line.length() - 1] == ' ') // If last char is a space, pop it line.pop_back(); @@ -577,7 +581,7 @@ template int BOVCollection::ReadRegion(std::string varname, size_t ts, } if (needSwap) { _swapBytes(readBuffer, formatSize, count); } - + if (_dataFormat == DC::XType::INT32) { int *castBuffer = (int *)readBuffer; for (int i = 0; i < count; i++) { *region++ = (typename std::remove_pointer::type)castBuffer[i]; } From a4f4924ad15112a439c27429b1911faa96b1f904 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Wed, 14 Jul 2021 16:28:29 -0600 Subject: [PATCH 09/28] clang format --- include/vapor/BOVCollection.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/vapor/BOVCollection.h b/include/vapor/BOVCollection.h index f05b9987b8..6e9c5ff17c 100644 --- a/include/vapor/BOVCollection.h +++ b/include/vapor/BOVCollection.h @@ -29,7 +29,7 @@ class BOVCollection : public Wasp::MyBase { template int ReadRegion(std::string varname, size_t ts, const std::vector &min, const std::vector &max, T region); private: - std::string _currentFilePath; + std::string _currentFilePath; float _time; std::vector _times; From 2bba7e4280bc86456af1c77dff51b939aac78132 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Tue, 20 Jul 2021 12:43:02 -0600 Subject: [PATCH 10/28] updated error handling in BOV reader --- include/vapor/BOVCollection.h | 15 +-- lib/vdc/BOVCollection.cpp | 187 ++++++++++++++++------------------ 2 files changed, 90 insertions(+), 112 deletions(-) diff --git a/include/vapor/BOVCollection.h b/include/vapor/BOVCollection.h index 6e9c5ff17c..710f5b8a5c 100644 --- a/include/vapor/BOVCollection.h +++ b/include/vapor/BOVCollection.h @@ -24,7 +24,6 @@ class BOVCollection : public Wasp::MyBase { DC::XType GetDataFormat() const; std::array GetBrickOrigin() const; std::array GetBrickSize() const; - std::string GetDataEndian() const; template int ReadRegion(std::string varname, size_t ts, const std::vector &min, const std::vector &max, T region); @@ -53,7 +52,6 @@ class BOVCollection : public Wasp::MyBase { // assigning to "actual" values such as _gridSize, declaired above. std::array _tmpGridSize; DC::XType _tmpDataFormat; - std::string _tmpDataEndian; std::array _tmpBrickOrigin; std::array _tmpBrickSize; size_t _tmpByteOffset; @@ -62,7 +60,6 @@ class BOVCollection : public Wasp::MyBase { bool _formatAssigned; bool _brickOriginAssigned; bool _brickSizeAssigned; - bool _dataEndianAssigned; bool _byteOffsetAssigned; // _dataFileMap allows us to access binary data files with a @@ -82,14 +79,13 @@ class BOVCollection : public Wasp::MyBase { void _findTokenValue(std::string &line) const; int _sizeOfFormat(DC::XType) const; - void _swapBytes(void *vptr, size_t size, size_t n) const; - int _invalidFileSizeError(size_t dataSize, size_t fileSize) const; - int _cannotStatFileError() const; - int _invalidFileError(const std::string &token, const std::string &file) const; + int _invalidFileSizeError(size_t numElements) const; + int _byteOffsetError() const; + int _fileTooBigError() const; + int _invalidFileError() const; int _invalidDimensionError(const std::string &token) const; int _invalidFormatError(const std::string &token) const; - int _invalidEndianError(const std::string &token) const; int _failureToReadError(const std::string &token) const; int _inconsistentValueError(const std::string &token) const; int _invalidValueError(const std::string &token) const; @@ -128,9 +124,6 @@ class BOVCollection : public Wasp::MyBase { static const std::string _zDim; static const std::string _timeDim; - static const std::string _bigEndianString; - static const std::string _littleEndianString; - static const std::string _byteFormatString; static const std::string _shortFormatString; static const std::string _intFormatString; diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index 744b1dfe63..388f779005 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -9,6 +10,7 @@ #include #include "vapor/VAssert.h" #include "vapor/utils.h" +#include "vapor/FileUtils.h" #include #ifdef WIN32 @@ -44,8 +46,8 @@ const std::array BOVCollection::_defaultBricklets = {0, 0, 0}; const std::array BOVCollection::_defaultGridSize = {0, 0, 0}; const DC::XType BOVCollection::_defaultFormat = DC::XType::INVALID; const std::string BOVCollection::_defaultFile = ""; -const std::string BOVCollection::_defaultVar = "brickVar"; const std::string BOVCollection::_defaultEndian = "LITTLE"; +const std::string BOVCollection::_defaultVar = "brickVar"; const std::string BOVCollection::_defaultCentering = "ZONAL"; const double BOVCollection::_defaultTime = 0.; const size_t BOVCollection::_defaultByteOffset = 0; @@ -57,9 +59,6 @@ const std::string BOVCollection::_yDim = "y"; const std::string BOVCollection::_zDim = "z"; const std::string BOVCollection::_timeDim = "t"; -const std::string BOVCollection::_bigEndianString = "BIG"; -const std::string BOVCollection::_littleEndianString = "LITTLE"; - const std::string BOVCollection::_byteFormatString = "BYTE"; const std::string BOVCollection::_shortFormatString = "SHORT"; const std::string BOVCollection::_intFormatString = "INT"; @@ -68,8 +67,8 @@ const std::string BOVCollection::_doubleFormatString = "DOUBLE"; BOVCollection::BOVCollection() : _time(_defaultTime), _dataFile(_defaultFile), _dataFormat(_defaultFormat), _variable(_defaultVar), _dataEndian(_defaultEndian), _centering(_defaultCentering), _byteOffset(_defaultByteOffset), - _divideBrick(_defaultDivBrick), _dataComponents(_defaultComponents), _tmpDataFormat(_defaultFormat), _tmpDataEndian(_defaultEndian), _tmpByteOffset(_defaultByteOffset), _gridSizeAssigned(false), - _formatAssigned(false), _brickOriginAssigned(false), _brickSizeAssigned(false), _dataEndianAssigned(false), _byteOffsetAssigned(false), _timeDimension(_timeDim) + _divideBrick(_defaultDivBrick), _dataComponents(_defaultComponents), _tmpDataFormat(_defaultFormat), _tmpByteOffset(_defaultByteOffset), _gridSizeAssigned(false), + _formatAssigned(false), _brickOriginAssigned(false), _brickSizeAssigned(false), _byteOffsetAssigned(false), _timeDimension(_timeDim) { _dataFiles.clear(); _times.clear(); @@ -149,44 +148,52 @@ int BOVCollection::_parseHeader(std::ifstream &header) return _failureToReadError(DATA_FILE_TOKEN); else if (rc == (int)parseCodes::FOUND) { _dataFile = dataFile; + continue; } double time; rc = _findToken(TIME_TOKEN, line, time); if (rc == (int)parseCodes::ERROR) return _failureToReadError(TIME_TOKEN); - else if (rc == (int)parseCodes::FOUND) + else if (rc == (int)parseCodes::FOUND) { _time = time; + continue; + } std::string variable; rc = _findToken(VARIABLE_TOKEN, line, variable); if (rc == (int)parseCodes::ERROR) return _invalidValueError(VARIABLE_TOKEN); - else if (rc == (int)parseCodes::FOUND) + else if (rc == (int)parseCodes::FOUND) { _variable = variable; + continue; + } rc = _findToken(GRID_SIZE_TOKEN, line, _tmpGridSize); if (rc == (int)parseCodes::ERROR) return _failureToReadError(GRID_SIZE_TOKEN); + else if (rc == (int)parseCodes::FOUND) continue; rc = _findToken(FORMAT_TOKEN, line, _tmpDataFormat); if (rc == (int)parseCodes::ERROR) return _failureToReadError(FORMAT_TOKEN); + else if (rc == (int)parseCodes::FOUND) continue; // Optional tokens. If their values are invalid, SetErrMsg, and return -1. // rc = _findToken(ORIGIN_TOKEN, line, _tmpBrickOrigin); if (rc == (int)parseCodes::ERROR) return _invalidValueError(ORIGIN_TOKEN); + else if (rc == (int)parseCodes::FOUND) continue; rc = _findToken(BRICK_SIZE_TOKEN, line, _tmpBrickSize); if (rc == (int)parseCodes::ERROR) return _invalidValueError(BRICK_SIZE_TOKEN); - - rc = _findToken(ENDIAN_TOKEN, line, _tmpDataEndian); - if (rc == (int)parseCodes::ERROR) return _invalidValueError(ENDIAN_TOKEN); + else if (rc == (int)parseCodes::FOUND) continue; rc = _findToken(OFFSET_TOKEN, line, _tmpByteOffset); if (rc == (int)parseCodes::ERROR) return _invalidValueError(OFFSET_TOKEN); + else if (rc == (int)parseCodes::FOUND) continue; // All other variables are currently unused. // + _findToken(ENDIAN_TOKEN, line, _dataEndian); _findToken(CENTERING_TOKEN, line, _centering); _findToken(DIVIDE_BRICK_TOKEN, line, _divideBrick); _findToken(DATA_BRICKLETS_TOKEN, line, _dataBricklets); @@ -197,20 +204,6 @@ int BOVCollection::_parseHeader(std::ifstream &header) int BOVCollection::_validateParsedValues() { - // Validate that the data file exists. - // If not given an absolute path, construct one - // from the header file's containing directory. - char actualPath[PATH_MAX + 1]; - char *success = realpath(_dataFile.c_str(), actualPath); - if (success == nullptr) { - // At this point we can't find the absolute path, so it might be a relative path. - // Try prepending the directory of the .bov file to the data file - _dataFile = _currentFilePath + "//" + _dataFile; - success = realpath(_dataFile.c_str(), actualPath); - if (success == nullptr) return _invalidFileError(DATA_FILE_TOKEN, _dataFile); - } else - _dataFile = std::string(actualPath); - // Validate grid dimensions if (_tmpGridSize[0] < 1 || _tmpGridSize[1] < 1 || _tmpGridSize[2] < 1) return _invalidDimensionError(GRID_SIZE_TOKEN); @@ -247,15 +240,6 @@ int BOVCollection::_validateParsedValues() _brickSizeAssigned = true; } - // Validate endian type - if (_tmpDataEndian != _bigEndianString && _tmpDataEndian != _littleEndianString) return _invalidEndianError(ENDIAN_TOKEN); - if (_tmpDataEndian != _dataEndian && _dataEndianAssigned == true) - return _inconsistentValueError(ENDIAN_TOKEN); - else { - _dataEndian = _tmpDataEndian; - _dataEndianAssigned = true; - } - // Validate byte offest if (_tmpByteOffset != _byteOffset && _byteOffsetAssigned == true) return _inconsistentValueError(OFFSET_TOKEN); @@ -264,16 +248,49 @@ int BOVCollection::_validateParsedValues() _byteOffsetAssigned = true; } - // Validate file size - size_t fileSize; - size_t dataSize = _gridSize[0] * _gridSize[1] * _gridSize[2] * _sizeOfFormat(_dataFormat); - struct stat stat_buf; - int rc = stat(_dataFile.c_str(), &stat_buf); - if (rc == 0) - fileSize = stat_buf.st_size; - else - return _cannotStatFileError(); - if (dataSize != fileSize) return _invalidFileSizeError(dataSize, fileSize); + // If _dataFile is not an absolute path, prepend with the BOV header's path + if (!Wasp::FileUtils::IsPathAbsolute(_dataFile)) { + _dataFile = _currentFilePath + "//" + _dataFile; + } + + // Validate that the file is not a directory + FILE *fp = fopen(_dataFile.c_str(), "r+"); + if (fp == nullptr) return _invalidFileError(); + fclose(fp); + + // Validate whether we can open the data file + fp = fopen(_dataFile.c_str(), "rb"); + if (fp == nullptr) return _invalidFileError(); + + // Validate that we can seek the data file. + // If we seek to the end of the file, there's no data to read, so report error + int rc = fseek(fp, _byteOffset, SEEK_SET); + if (rc != 0 || feof(fp)) { + fclose(fp); + return _byteOffsetError(); + } + + // Validate the data file's size + int formatSize = _sizeOfFormat(_dataFormat); + size_t count = _gridSize[0] * _gridSize[1] * _gridSize[2]; + auto readBuffer = std::unique_ptr(new unsigned char[count * formatSize]); + size_t numElements = fread(readBuffer.get(), formatSize, count, fp); + if (numElements != count) { + fclose(fp); + return _invalidFileSizeError( numElements ); + } + if (ferror(fp)) { + fclose(fp); + return _invalidFileError(); + } + + // If we can read another byte in the file, the file is too big + if (fread(readBuffer.get(), formatSize, 1, fp) != 0) { + fclose(fp); + return _fileTooBigError(); + } + + fclose(fp); return 0; } @@ -288,25 +305,27 @@ void BOVCollection::_populateDataFileMap() _dataFileMap[_variable][_time] = _dataFile; } -int BOVCollection::_cannotStatFileError() const -{ - SetErrMsg(("Unable to get file status for " + _dataFile).c_str()); +int BOVCollection::_fileTooBigError() const { + SetErrMsg((_dataFile + " contains more data than specified in BOV header.").c_str()); + return -1; +} + +int BOVCollection::_byteOffsetError() const { + SetErrMsg(("Seeking by " + to_string(_byteOffset) + " bytes results in error: " + strerror(errno)).c_str()); return -1; } -int BOVCollection::_invalidFileSizeError(size_t dataSize, size_t fileSize) const +int BOVCollection::_invalidFileSizeError(size_t numElements) const { - SetErrMsg(("Data file " + _dataFile + " of size " + to_string(fileSize) - + " bytes does not match the size of the the data " - "specified in BOV header (" - + to_string(dataSize) + " bytes).") - .c_str()); + SetErrMsg(("Data file " + _dataFile + ", which has " + to_string(numElements) + + " values, does not match the size of the the data and offset " + "specified in BOV header.").c_str()); return -1; } -int BOVCollection::_invalidFileError(const std::string &token, const std::string &file) const +int BOVCollection::_invalidFileError() const { - SetErrMsg((token + " was unable to be identified").c_str()); + SetErrMsg(("Reading " + _dataFile + " failed with error: " + strerror(errno)).c_str()); return -1; } @@ -329,13 +348,6 @@ int BOVCollection::_invalidFormatError(const std::string &token) const return -1; } -int BOVCollection::_invalidEndianError(const std::string &token) const -{ - std::string message = token + " must be either " + _littleEndianString + " or " + _bigEndianString; - SetErrMsg(message.c_str()); - return -1; -} - int BOVCollection::_failureToReadError(const std::string &token) const { SetErrMsg(("Failure reading BOV token: " + token).c_str()); @@ -370,8 +382,6 @@ std::array BOVCollection::GetBrickOrigin() const { return _brickOrigi std::array BOVCollection::GetBrickSize() const { return _brickSize; } -std::string BOVCollection::GetDataEndian() const { return _dataEndian; } - // Template specialization for reading data of type DC::XType template<> int BOVCollection::_findToken(const std::string &token, std::string &line, DC::XType &value, bool verbose) { @@ -383,10 +393,11 @@ template<> int BOVCollection::_findToken(const std::string &token, st } } + if (line.length() == 0) return (int)parseCodes::NOT_FOUND; + while (line[line.length() - 1] == ' ') // If last char is a space, pop it line.pop_back(); - size_t pos = line.find(token); if (pos != std::string::npos) { // We found the token std::string format = line; @@ -417,6 +428,8 @@ template int BOVCollection::_findToken(const std::string &token, std } } + if (line.length() == 0) return (int)parseCodes::NOT_FOUND; + while (line[line.length() - 1] == ' ') // If last char is a space, pop it line.pop_back(); @@ -433,16 +446,10 @@ template int BOVCollection::_findToken(const std::string &token, std if (verbose) { std::cout << std::setw(20) << token << " " << value << std::endl; } if (ss.fail()) { - std::string message = "Invalid value for " + token + " in BOV header file."; - SetErrMsg(message.c_str()); - return (int)parseCodes::ERROR; - } - - if (ss.eof() == 0) { - std::string message = "The keyword " + token + " should only contain one value."; - SetErrMsg(message.c_str()); return (int)parseCodes::ERROR; } + // If there is more than one value, throw error + if (ss.eof() == false) return (int)parseCodes::ERROR; return (int)parseCodes::FOUND; } @@ -460,6 +467,8 @@ template int BOVCollection::_findToken(const std::string &token, std } } + if (line.length() == 0) return (int)parseCodes::NOT_FOUND; + while (line[line.length() - 1] == ' ') // If last char is a space, pop it line.pop_back(); @@ -471,14 +480,13 @@ template int BOVCollection::_findToken(const std::string &token, std for (int i = 0; i < value.size(); i++) { lineStream >> lineValue; + if (lineStream.fail()) return (int)parseCodes::ERROR; + value[i] = lineValue; } - if (lineStream.bad()) { - std::string message = "Invalid value for " + token + " in BOV header file."; - SetErrMsg(message.c_str()); - return (int)parseCodes::ERROR; - } + // If there are more than 3 values, throw error + if(!lineStream.eof()) return (int)parseCodes::ERROR; if (verbose) { std::cout << std::setw(20) << token << " "; @@ -512,22 +520,6 @@ int BOVCollection::_sizeOfFormat(DC::XType type) const } } -void BOVCollection::_swapBytes(void *vptr, size_t size, size_t n) const -{ - unsigned char *ucptr = (unsigned char *)vptr; - unsigned char uc; - size_t i, j; - - for (j = 0; j < n; j++) { - for (i = 0; i < size / 2; i++) { - uc = ucptr[i]; - ucptr[i] = ucptr[size - i - 1]; - ucptr[size - i - 1] = uc; - } - ucptr += size; - } -} - template int BOVCollection::ReadRegion(std::string varname, size_t ts, const std::vector &min, const std::vector &max, T region) { float time = _times[ts]; @@ -549,11 +541,6 @@ template int BOVCollection::ReadRegion(std::string varname, size_t ts, return -1; } - int n = 1; - bool systemLittleEndian = *(char *)&n == 1 ? true : false; - bool dataLittleEndian = _dataEndian == _littleEndianString ? true : false; - bool needSwap = systemLittleEndian != dataLittleEndian ? true : false; - // Read a "pencil" of data along the X axis, one row at a time size_t count = max[0] - min[0] + 1; // Note: allocate buffer once and reuse for many times, so repeated allocation is avoided. @@ -580,8 +567,6 @@ template int BOVCollection::ReadRegion(std::string varname, size_t ts, return -1; } - if (needSwap) { _swapBytes(readBuffer, formatSize, count); } - if (_dataFormat == DC::XType::INT32) { int *castBuffer = (int *)readBuffer; for (int i = 0; i < count; i++) { *region++ = (typename std::remove_pointer::type)castBuffer[i]; } From 8725d20c085838747bcc331a9539ec698559ceb9 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Tue, 20 Jul 2021 12:45:24 -0600 Subject: [PATCH 11/28] clang format --- include/vapor/BOVCollection.h | 2 +- lib/vdc/BOVCollection.cpp | 65 ++++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/include/vapor/BOVCollection.h b/include/vapor/BOVCollection.h index 710f5b8a5c..cd61340150 100644 --- a/include/vapor/BOVCollection.h +++ b/include/vapor/BOVCollection.h @@ -78,7 +78,7 @@ class BOVCollection : public Wasp::MyBase { void _findTokenValue(std::string &line) const; - int _sizeOfFormat(DC::XType) const; + int _sizeOfFormat(DC::XType) const; int _invalidFileSizeError(size_t numElements) const; int _byteOffsetError() const; diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index 388f779005..d9548846e6 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -67,8 +67,8 @@ const std::string BOVCollection::_doubleFormatString = "DOUBLE"; BOVCollection::BOVCollection() : _time(_defaultTime), _dataFile(_defaultFile), _dataFormat(_defaultFormat), _variable(_defaultVar), _dataEndian(_defaultEndian), _centering(_defaultCentering), _byteOffset(_defaultByteOffset), - _divideBrick(_defaultDivBrick), _dataComponents(_defaultComponents), _tmpDataFormat(_defaultFormat), _tmpByteOffset(_defaultByteOffset), _gridSizeAssigned(false), - _formatAssigned(false), _brickOriginAssigned(false), _brickSizeAssigned(false), _byteOffsetAssigned(false), _timeDimension(_timeDim) + _divideBrick(_defaultDivBrick), _dataComponents(_defaultComponents), _tmpDataFormat(_defaultFormat), _tmpByteOffset(_defaultByteOffset), _gridSizeAssigned(false), _formatAssigned(false), + _brickOriginAssigned(false), _brickSizeAssigned(false), _byteOffsetAssigned(false), _timeDimension(_timeDim) { _dataFiles.clear(); _times.clear(); @@ -170,26 +170,36 @@ int BOVCollection::_parseHeader(std::ifstream &header) } rc = _findToken(GRID_SIZE_TOKEN, line, _tmpGridSize); - if (rc == (int)parseCodes::ERROR) return _failureToReadError(GRID_SIZE_TOKEN); - else if (rc == (int)parseCodes::FOUND) continue; + if (rc == (int)parseCodes::ERROR) + return _failureToReadError(GRID_SIZE_TOKEN); + else if (rc == (int)parseCodes::FOUND) + continue; rc = _findToken(FORMAT_TOKEN, line, _tmpDataFormat); - if (rc == (int)parseCodes::ERROR) return _failureToReadError(FORMAT_TOKEN); - else if (rc == (int)parseCodes::FOUND) continue; + if (rc == (int)parseCodes::ERROR) + return _failureToReadError(FORMAT_TOKEN); + else if (rc == (int)parseCodes::FOUND) + continue; // Optional tokens. If their values are invalid, SetErrMsg, and return -1. // rc = _findToken(ORIGIN_TOKEN, line, _tmpBrickOrigin); - if (rc == (int)parseCodes::ERROR) return _invalidValueError(ORIGIN_TOKEN); - else if (rc == (int)parseCodes::FOUND) continue; + if (rc == (int)parseCodes::ERROR) + return _invalidValueError(ORIGIN_TOKEN); + else if (rc == (int)parseCodes::FOUND) + continue; rc = _findToken(BRICK_SIZE_TOKEN, line, _tmpBrickSize); - if (rc == (int)parseCodes::ERROR) return _invalidValueError(BRICK_SIZE_TOKEN); - else if (rc == (int)parseCodes::FOUND) continue; + if (rc == (int)parseCodes::ERROR) + return _invalidValueError(BRICK_SIZE_TOKEN); + else if (rc == (int)parseCodes::FOUND) + continue; rc = _findToken(OFFSET_TOKEN, line, _tmpByteOffset); - if (rc == (int)parseCodes::ERROR) return _invalidValueError(OFFSET_TOKEN); - else if (rc == (int)parseCodes::FOUND) continue; + if (rc == (int)parseCodes::ERROR) + return _invalidValueError(OFFSET_TOKEN); + else if (rc == (int)parseCodes::FOUND) + continue; // All other variables are currently unused. // @@ -249,11 +259,9 @@ int BOVCollection::_validateParsedValues() } // If _dataFile is not an absolute path, prepend with the BOV header's path - if (!Wasp::FileUtils::IsPathAbsolute(_dataFile)) { - _dataFile = _currentFilePath + "//" + _dataFile; - } + if (!Wasp::FileUtils::IsPathAbsolute(_dataFile)) { _dataFile = _currentFilePath + "//" + _dataFile; } - // Validate that the file is not a directory + // Validate that the file is not a directory FILE *fp = fopen(_dataFile.c_str(), "r+"); if (fp == nullptr) return _invalidFileError(); fclose(fp); @@ -271,19 +279,19 @@ int BOVCollection::_validateParsedValues() } // Validate the data file's size - int formatSize = _sizeOfFormat(_dataFormat); + int formatSize = _sizeOfFormat(_dataFormat); size_t count = _gridSize[0] * _gridSize[1] * _gridSize[2]; - auto readBuffer = std::unique_ptr(new unsigned char[count * formatSize]); + auto readBuffer = std::unique_ptr(new unsigned char[count * formatSize]); size_t numElements = fread(readBuffer.get(), formatSize, count, fp); if (numElements != count) { fclose(fp); - return _invalidFileSizeError( numElements ); + return _invalidFileSizeError(numElements); } if (ferror(fp)) { fclose(fp); return _invalidFileError(); } - + // If we can read another byte in the file, the file is too big if (fread(readBuffer.get(), formatSize, 1, fp) != 0) { fclose(fp); @@ -305,12 +313,14 @@ void BOVCollection::_populateDataFileMap() _dataFileMap[_variable][_time] = _dataFile; } -int BOVCollection::_fileTooBigError() const { +int BOVCollection::_fileTooBigError() const +{ SetErrMsg((_dataFile + " contains more data than specified in BOV header.").c_str()); return -1; } -int BOVCollection::_byteOffsetError() const { +int BOVCollection::_byteOffsetError() const +{ SetErrMsg(("Seeking by " + to_string(_byteOffset) + " bytes results in error: " + strerror(errno)).c_str()); return -1; } @@ -319,7 +329,8 @@ int BOVCollection::_invalidFileSizeError(size_t numElements) const { SetErrMsg(("Data file " + _dataFile + ", which has " + to_string(numElements) + " values, does not match the size of the the data and offset " - "specified in BOV header.").c_str()); + "specified in BOV header.") + .c_str()); return -1; } @@ -445,11 +456,9 @@ template int BOVCollection::_findToken(const std::string &token, std if (verbose) { std::cout << std::setw(20) << token << " " << value << std::endl; } - if (ss.fail()) { - return (int)parseCodes::ERROR; - } + if (ss.fail()) { return (int)parseCodes::ERROR; } // If there is more than one value, throw error - if (ss.eof() == false) return (int)parseCodes::ERROR; + if (ss.eof() == false) return (int)parseCodes::ERROR; return (int)parseCodes::FOUND; } @@ -486,7 +495,7 @@ template int BOVCollection::_findToken(const std::string &token, std } // If there are more than 3 values, throw error - if(!lineStream.eof()) return (int)parseCodes::ERROR; + if (!lineStream.eof()) return (int)parseCodes::ERROR; if (verbose) { std::cout << std::setw(20) << token << " "; From cdbe3fc00e1ebcc063eb6ca023e495405b81e6da Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Tue, 20 Jul 2021 12:52:43 -0600 Subject: [PATCH 12/28] remove unnecessary error check --- include/vapor/BOVCollection.h | 1 - lib/vdc/BOVCollection.cpp | 14 -------------- 2 files changed, 15 deletions(-) diff --git a/include/vapor/BOVCollection.h b/include/vapor/BOVCollection.h index cd61340150..5f9306e08b 100644 --- a/include/vapor/BOVCollection.h +++ b/include/vapor/BOVCollection.h @@ -81,7 +81,6 @@ class BOVCollection : public Wasp::MyBase { int _sizeOfFormat(DC::XType) const; int _invalidFileSizeError(size_t numElements) const; - int _byteOffsetError() const; int _fileTooBigError() const; int _invalidFileError() const; int _invalidDimensionError(const std::string &token) const; diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index d9548846e6..f0a7c871e0 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -270,14 +270,6 @@ int BOVCollection::_validateParsedValues() fp = fopen(_dataFile.c_str(), "rb"); if (fp == nullptr) return _invalidFileError(); - // Validate that we can seek the data file. - // If we seek to the end of the file, there's no data to read, so report error - int rc = fseek(fp, _byteOffset, SEEK_SET); - if (rc != 0 || feof(fp)) { - fclose(fp); - return _byteOffsetError(); - } - // Validate the data file's size int formatSize = _sizeOfFormat(_dataFormat); size_t count = _gridSize[0] * _gridSize[1] * _gridSize[2]; @@ -319,12 +311,6 @@ int BOVCollection::_fileTooBigError() const return -1; } -int BOVCollection::_byteOffsetError() const -{ - SetErrMsg(("Seeking by " + to_string(_byteOffset) + " bytes results in error: " + strerror(errno)).c_str()); - return -1; -} - int BOVCollection::_invalidFileSizeError(size_t numElements) const { SetErrMsg(("Data file " + _dataFile + ", which has " + to_string(numElements) From 1b5027dc7d130fea0e841bd1193bde9a4b994d44 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Tue, 20 Jul 2021 13:29:09 -0600 Subject: [PATCH 13/28] remove stat.h for windows, and remove directory checker --- lib/vdc/BOVCollection.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index f0a7c871e0..1aed7cf6c2 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include "vapor/VAssert.h" #include "vapor/utils.h" #include "vapor/FileUtils.h" @@ -261,11 +260,6 @@ int BOVCollection::_validateParsedValues() // If _dataFile is not an absolute path, prepend with the BOV header's path if (!Wasp::FileUtils::IsPathAbsolute(_dataFile)) { _dataFile = _currentFilePath + "//" + _dataFile; } - // Validate that the file is not a directory - FILE *fp = fopen(_dataFile.c_str(), "r+"); - if (fp == nullptr) return _invalidFileError(); - fclose(fp); - // Validate whether we can open the data file fp = fopen(_dataFile.c_str(), "rb"); if (fp == nullptr) return _invalidFileError(); From 5c50ff61f30662732eeb14a0e07395f2c94895a2 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Tue, 20 Jul 2021 13:40:59 -0600 Subject: [PATCH 14/28] fix typo --- lib/vdc/BOVCollection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index 1aed7cf6c2..9c69e0b7ec 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -261,7 +261,7 @@ int BOVCollection::_validateParsedValues() if (!Wasp::FileUtils::IsPathAbsolute(_dataFile)) { _dataFile = _currentFilePath + "//" + _dataFile; } // Validate whether we can open the data file - fp = fopen(_dataFile.c_str(), "rb"); + FILE* fp = fopen(_dataFile.c_str(), "rb"); if (fp == nullptr) return _invalidFileError(); // Validate the data file's size From 94d1a527e12ba4ecba7f74242f83c903fc8ca1de Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Tue, 20 Jul 2021 13:47:29 -0600 Subject: [PATCH 15/28] clang-format --- lib/vdc/BOVCollection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index 9c69e0b7ec..eca2d06bf5 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -261,7 +261,7 @@ int BOVCollection::_validateParsedValues() if (!Wasp::FileUtils::IsPathAbsolute(_dataFile)) { _dataFile = _currentFilePath + "//" + _dataFile; } // Validate whether we can open the data file - FILE* fp = fopen(_dataFile.c_str(), "rb"); + FILE *fp = fopen(_dataFile.c_str(), "rb"); if (fp == nullptr) return _invalidFileError(); // Validate the data file's size From 7735facc51efce56364849aa8976f108d535dab7 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Tue, 20 Jul 2021 14:23:05 -0600 Subject: [PATCH 16/28] merge with windows fix --- include/vapor/BOVCollection.h | 2 +- lib/vdc/BOVCollection.cpp | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/vapor/BOVCollection.h b/include/vapor/BOVCollection.h index 5f9306e08b..2669d88320 100644 --- a/include/vapor/BOVCollection.h +++ b/include/vapor/BOVCollection.h @@ -10,7 +10,7 @@ namespace VAPoR { class BOVCollection : public Wasp::MyBase { public: - enum class parseCodes { ERROR = -1, NOT_FOUND = 0, FOUND = 1 }; + enum class parseCodes { PARSE_ERROR = -1, NOT_FOUND = 0, FOUND = 1 }; BOVCollection(); int Initialize(const std::vector &paths); diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index eca2d06bf5..1b625dc7be 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -143,7 +143,7 @@ int BOVCollection::_parseHeader(std::ifstream &header) // the BOV. Try to find them, and report errors if we can't. // rc = _findToken(DATA_FILE_TOKEN, line, dataFile); - if (rc == (int)parseCodes::ERROR) + if (rc == (int)parseCodes::PARSE_ERROR) return _failureToReadError(DATA_FILE_TOKEN); else if (rc == (int)parseCodes::FOUND) { _dataFile = dataFile; @@ -152,7 +152,7 @@ int BOVCollection::_parseHeader(std::ifstream &header) double time; rc = _findToken(TIME_TOKEN, line, time); - if (rc == (int)parseCodes::ERROR) + if (rc == (int)parseCodes::PARSE_ERROR) return _failureToReadError(TIME_TOKEN); else if (rc == (int)parseCodes::FOUND) { _time = time; @@ -161,7 +161,7 @@ int BOVCollection::_parseHeader(std::ifstream &header) std::string variable; rc = _findToken(VARIABLE_TOKEN, line, variable); - if (rc == (int)parseCodes::ERROR) + if (rc == (int)parseCodes::PARSE_ERROR) return _invalidValueError(VARIABLE_TOKEN); else if (rc == (int)parseCodes::FOUND) { _variable = variable; @@ -169,13 +169,13 @@ int BOVCollection::_parseHeader(std::ifstream &header) } rc = _findToken(GRID_SIZE_TOKEN, line, _tmpGridSize); - if (rc == (int)parseCodes::ERROR) + if (rc == (int)parseCodes::PARSE_ERROR) return _failureToReadError(GRID_SIZE_TOKEN); else if (rc == (int)parseCodes::FOUND) continue; rc = _findToken(FORMAT_TOKEN, line, _tmpDataFormat); - if (rc == (int)parseCodes::ERROR) + if (rc == (int)parseCodes::PARSE_ERROR) return _failureToReadError(FORMAT_TOKEN); else if (rc == (int)parseCodes::FOUND) continue; @@ -183,19 +183,19 @@ int BOVCollection::_parseHeader(std::ifstream &header) // Optional tokens. If their values are invalid, SetErrMsg, and return -1. // rc = _findToken(ORIGIN_TOKEN, line, _tmpBrickOrigin); - if (rc == (int)parseCodes::ERROR) + if (rc == (int)parseCodes::PARSE_ERROR) return _invalidValueError(ORIGIN_TOKEN); else if (rc == (int)parseCodes::FOUND) continue; rc = _findToken(BRICK_SIZE_TOKEN, line, _tmpBrickSize); - if (rc == (int)parseCodes::ERROR) + if (rc == (int)parseCodes::PARSE_ERROR) return _invalidValueError(BRICK_SIZE_TOKEN); else if (rc == (int)parseCodes::FOUND) continue; rc = _findToken(OFFSET_TOKEN, line, _tmpByteOffset); - if (rc == (int)parseCodes::ERROR) + if (rc == (int)parseCodes::PARSE_ERROR) return _invalidValueError(OFFSET_TOKEN); else if (rc == (int)parseCodes::FOUND) continue; @@ -436,9 +436,9 @@ template int BOVCollection::_findToken(const std::string &token, std if (verbose) { std::cout << std::setw(20) << token << " " << value << std::endl; } - if (ss.fail()) { return (int)parseCodes::ERROR; } + if (ss.fail()) { return (int)parseCodes::PARSE_ERROR; } // If there is more than one value, throw error - if (ss.eof() == false) return (int)parseCodes::ERROR; + if (ss.eof() == false) return (int)parseCodes::PARSE_ERROR; return (int)parseCodes::FOUND; } @@ -469,13 +469,13 @@ template int BOVCollection::_findToken(const std::string &token, std for (int i = 0; i < value.size(); i++) { lineStream >> lineValue; - if (lineStream.fail()) return (int)parseCodes::ERROR; + if (lineStream.fail()) return (int)parseCodes::PARSE_ERROR; value[i] = lineValue; } // If there are more than 3 values, throw error - if (!lineStream.eof()) return (int)parseCodes::ERROR; + if (!lineStream.eof()) return (int)parseCodes::PARSE_ERROR; if (verbose) { std::cout << std::setw(20) << token << " "; From de196178ca4e3e0905a4e38204fb0916bcfe429f Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Tue, 20 Jul 2021 15:37:07 -0600 Subject: [PATCH 17/28] remove fileTooBig error --- include/vapor/BOVCollection.h | 1 - lib/vdc/BOVCollection.cpp | 12 ------------ 2 files changed, 13 deletions(-) diff --git a/include/vapor/BOVCollection.h b/include/vapor/BOVCollection.h index 2669d88320..2974e0f769 100644 --- a/include/vapor/BOVCollection.h +++ b/include/vapor/BOVCollection.h @@ -81,7 +81,6 @@ class BOVCollection : public Wasp::MyBase { int _sizeOfFormat(DC::XType) const; int _invalidFileSizeError(size_t numElements) const; - int _fileTooBigError() const; int _invalidFileError() const; int _invalidDimensionError(const std::string &token) const; int _invalidFormatError(const std::string &token) const; diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index 1b625dc7be..6e9de2f57c 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -278,12 +278,6 @@ int BOVCollection::_validateParsedValues() return _invalidFileError(); } - // If we can read another byte in the file, the file is too big - if (fread(readBuffer.get(), formatSize, 1, fp) != 0) { - fclose(fp); - return _fileTooBigError(); - } - fclose(fp); return 0; @@ -299,12 +293,6 @@ void BOVCollection::_populateDataFileMap() _dataFileMap[_variable][_time] = _dataFile; } -int BOVCollection::_fileTooBigError() const -{ - SetErrMsg((_dataFile + " contains more data than specified in BOV header.").c_str()); - return -1; -} - int BOVCollection::_invalidFileSizeError(size_t numElements) const { SetErrMsg(("Data file " + _dataFile + ", which has " + to_string(numElements) From 2dede488b68d66eb4e0a7a0b34e798a94340740c Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Tue, 20 Jul 2021 16:07:06 -0600 Subject: [PATCH 18/28] switch to climits --- lib/vdc/BOVCollection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index 6e9de2f57c..87609f2d63 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -17,7 +17,7 @@ #define _USE_MATH_DEFINES #pragma warning(disable : 4251 4100) #else - #include + #include #endif #include From 527fa55a484b2af30478774dbbe6ecea8e07c00d Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Tue, 20 Jul 2021 16:57:30 -0600 Subject: [PATCH 19/28] update DCBOV.h documentation --- include/vapor/DCBOV.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/vapor/DCBOV.h b/include/vapor/DCBOV.h index 20b5c7d51e..ea0d29753e 100644 --- a/include/vapor/DCBOV.h +++ b/include/vapor/DCBOV.h @@ -31,11 +31,11 @@ class BOVCollection; //! The following BOV tags are optional: //! - BRICK_ORIGIN //! - BRICK_SIZE -//! - DATA_ENDIAN //! - TIME //! - VARIABLE //! //! The following BOV tags are currently unsupported: +//! - DATA_ENDIAN //! - CENTERING //! - BYTE_OFFSET //! - DIVIDE_BRICK From 8dd8e2aa032f96d41233a0ad9f4d2a4e50f3c759 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Tue, 20 Jul 2021 18:05:17 -0600 Subject: [PATCH 20/28] remove windows funk --- lib/vdc/BOVCollection.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index 87609f2d63..63bbdbc5b0 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -11,14 +11,7 @@ #include "vapor/utils.h" #include "vapor/FileUtils.h" #include - -#ifdef WIN32 - #include - #define _USE_MATH_DEFINES - #pragma warning(disable : 4251 4100) -#else - #include -#endif +#include #include #include From eed8cea3d3e590de3d625835447d81b4454ae7bc Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Wed, 21 Jul 2021 07:16:33 -0600 Subject: [PATCH 21/28] use more FileUtils --- lib/vdc/BOVCollection.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index 63bbdbc5b0..14a4a89ee5 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -85,9 +85,7 @@ int BOVCollection::Initialize(const std::vector &paths) // Save the path to the BOV header so we can add it // to data files given with a relative path - _currentFilePath = paths[i]; - size_t found = _currentFilePath.find_last_of("/\\"); - _currentFilePath = _currentFilePath.substr(0, found); + _currentFilePath = Wasp::FileUtils::Dirname(paths[i]); header.open(paths[i]); if (header.is_open()) { @@ -251,7 +249,10 @@ int BOVCollection::_validateParsedValues() } // If _dataFile is not an absolute path, prepend with the BOV header's path - if (!Wasp::FileUtils::IsPathAbsolute(_dataFile)) { _dataFile = _currentFilePath + "//" + _dataFile; } + if (!Wasp::FileUtils::IsPathAbsolute(_dataFile)) { + auto paths = {_currentFilePath, _dataFile}; + _dataFile = Wasp::FileUtils::JoinPaths(paths); + } // Validate whether we can open the data file FILE *fp = fopen(_dataFile.c_str(), "rb"); From f70d912c40f64e628639367ec83ec34dc16504ed Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Wed, 21 Jul 2021 08:51:29 -0600 Subject: [PATCH 22/28] Fix review requests --- include/vapor/DCBOV.h | 10 +++---- lib/vdc/BOVCollection.cpp | 57 +++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 38 deletions(-) diff --git a/include/vapor/DCBOV.h b/include/vapor/DCBOV.h index ea0d29753e..745891581d 100644 --- a/include/vapor/DCBOV.h +++ b/include/vapor/DCBOV.h @@ -29,15 +29,15 @@ class BOVCollection; //! - DATA_FORMAT //! //! The following BOV tags are optional: -//! - BRICK_ORIGIN -//! - BRICK_SIZE -//! - TIME -//! - VARIABLE +//! - BRICK_ORIGIN (default: 0., 0., 0.) +//! - BRICK_SIZE (default: 1., 1., 1.) +//! - TIME (default: 0.) +//! - VARIABLE (default: "brickVar") +//! - BYTE_OFFSET (default: 0) //! //! The following BOV tags are currently unsupported: //! - DATA_ENDIAN //! - CENTERING -//! - BYTE_OFFSET //! - DIVIDE_BRICK //! - DATA_BRICKLETS //! - DATA_COMPONENTS diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index 14a4a89ee5..377bcda2ed 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -107,18 +107,18 @@ int BOVCollection::Initialize(const std::vector &paths) if (_dataFormat == _defaultFormat) { return _missingValueError(FORMAT_TOKEN); } if (_gridSize == _defaultGridSize) { return _missingValueError(GRID_SIZE_TOKEN); } - std::ifstream infile(_dataFile); - if (infile.bad()) { - SetErrMsg(("Failed to open BOV file " + _dataFile).c_str()); - return -1; - } - _populateDataFileMap(); } else { SetErrMsg(("Failed to open BOV file " + paths[0]).c_str()); return -1; } header.close(); + + // If _dataFile is not an absolute path, prepend with the BOV header's path + if (!Wasp::FileUtils::IsPathAbsolute(_dataFile)) { + auto paths = {_currentFilePath, _dataFile}; + _dataFile = Wasp::FileUtils::JoinPaths(paths); + } } return 0; @@ -248,30 +248,9 @@ int BOVCollection::_validateParsedValues() _byteOffsetAssigned = true; } - // If _dataFile is not an absolute path, prepend with the BOV header's path - if (!Wasp::FileUtils::IsPathAbsolute(_dataFile)) { - auto paths = {_currentFilePath, _dataFile}; - _dataFile = Wasp::FileUtils::JoinPaths(paths); - } - // Validate whether we can open the data file FILE *fp = fopen(_dataFile.c_str(), "rb"); if (fp == nullptr) return _invalidFileError(); - - // Validate the data file's size - int formatSize = _sizeOfFormat(_dataFormat); - size_t count = _gridSize[0] * _gridSize[1] * _gridSize[2]; - auto readBuffer = std::unique_ptr(new unsigned char[count * formatSize]); - size_t numElements = fread(readBuffer.get(), formatSize, count, fp); - if (numElements != count) { - fclose(fp); - return _invalidFileSizeError(numElements); - } - if (ferror(fp)) { - fclose(fp); - return _invalidFileError(); - } - fclose(fp); return 0; @@ -368,8 +347,12 @@ template<> int BOVCollection::_findToken(const std::string &token, st if (line.length() == 0) return (int)parseCodes::NOT_FOUND; - while (line[line.length() - 1] == ' ') // If last char is a space, pop it - line.pop_back(); + while (line.length() > 0) { + if (line[line.length() - 1] == ' ') // If last char is a space, pop it + line.pop_back(); + else + break; + } size_t pos = line.find(token); if (pos != std::string::npos) { // We found the token @@ -403,8 +386,12 @@ template int BOVCollection::_findToken(const std::string &token, std if (line.length() == 0) return (int)parseCodes::NOT_FOUND; - while (line[line.length() - 1] == ' ') // If last char is a space, pop it - line.pop_back(); + while (line.length() > 0) { + if (line[line.length() - 1] == ' ') // If last char is a space, pop it + line.pop_back(); + else + break; + } size_t pos = line.find(token); if (pos != std::string::npos) { // We found the token @@ -440,8 +427,12 @@ template int BOVCollection::_findToken(const std::string &token, std if (line.length() == 0) return (int)parseCodes::NOT_FOUND; - while (line[line.length() - 1] == ' ') // If last char is a space, pop it - line.pop_back(); + while (line.length() > 0) { + if (line[line.length() - 1] == ' ') // If last char is a space, pop it + line.pop_back(); + else + break; + } size_t pos = line.find(token); if (pos != std::string::npos) { // We found the token From e599b72e8a4617585cef2add29b4d1967057c623 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Wed, 21 Jul 2021 10:06:49 -0600 Subject: [PATCH 23/28] Add more comments --- include/vapor/DCBOV.h | 31 ++++++++++++++++++++++++++++++- lib/vdc/BOVCollection.cpp | 31 +++++++++++++++++++++++-------- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/include/vapor/DCBOV.h b/include/vapor/DCBOV.h index 745891581d..98038e6ec9 100644 --- a/include/vapor/DCBOV.h +++ b/include/vapor/DCBOV.h @@ -16,6 +16,33 @@ namespace VAPoR { class BOVCollection; +// Example BOV header file, bovA1.bov +// +// # TIME is a floating point value specifying the timestep being read in DATA_FILE +// TIME: 1.1 +// +// # DATA_FILE points to a binary data file. It can be a full file path, or a path relative to the BOV header. +// DATA_FILE: bovA1.bin +// +// # The data size corresponds to NX,NY,NZ in the above example code. +// DATA_SIZE: 10 10 10 +// +// # Allowable values for DATA_FORMAT are: INT,FLOAT,DOUBLE +// DATA_FORMAT: FLOAT +// +// # VARIABLE is a string that specifies the variable being read in DATA_FILE +// VARIABLE: myVariable +// +// # BRICK_ORIGIN lets you specify a new coordinate system origin for # the mesh that will be created to suit your data. +// BRICK_ORIGIN: 0. 0. 0. +// +// # BRICK_SIZE lets you specify the size of the brick. +// BRICK_SIZE: 10. 20. 5. +// +// # BYTE_OFFSET is optional and lets you specify some number of +// # bytes to skip at the front of the file. This can be useful for # skipping the 4-byte header that Fortran tends to write to files. # If your file does no +// BYTE_OFFSET: 4 + //! //! \class DCBOV //! \ingroup Public_VDCBOV @@ -35,13 +62,15 @@ class BOVCollection; //! - VARIABLE (default: "brickVar") //! - BYTE_OFFSET (default: 0) //! -//! The following BOV tags are currently unsupported: +//! The following BOV tags are currently unsupported. They can be included in a BOV header, +//! but they will be unused. //! - DATA_ENDIAN //! - CENTERING //! - DIVIDE_BRICK //! - DATA_BRICKLETS //! - DATA_COMPONENTS //! +//! If duplicate key/value pairs exist in a BOV header, the value closest to the bottom of the file will be used. //! Scientific notation is supported for floating point values like BRICK_ORIGIN and BRICK_SIZE. //! Scientific notation is not supported for integer values like DATA_SIZE. //! Wild card characters are not currently supported in the DATA_FILE token. diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index 377bcda2ed..a660c2b721 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -23,28 +23,32 @@ const std::string BOVCollection::DATA_FILE_TOKEN = "DATA_FILE"; const std::string BOVCollection::GRID_SIZE_TOKEN = "DATA_SIZE"; const std::string BOVCollection::FORMAT_TOKEN = "DATA_FORMAT"; const std::string BOVCollection::VARIABLE_TOKEN = "VARIABLE"; -const std::string BOVCollection::ENDIAN_TOKEN = "DATA_ENDIAN"; -const std::string BOVCollection::CENTERING_TOKEN = "CENTERING"; const std::string BOVCollection::ORIGIN_TOKEN = "BRICK_ORIGIN"; const std::string BOVCollection::BRICK_SIZE_TOKEN = "BRICK_SIZE"; const std::string BOVCollection::OFFSET_TOKEN = "BYTE_OFFSET"; + +// These tokens are parsed, but not used in ReadRegion() logic +const std::string BOVCollection::ENDIAN_TOKEN = "DATA_ENDIAN"; +const std::string BOVCollection::CENTERING_TOKEN = "CENTERING"; const std::string BOVCollection::DIVIDE_BRICK_TOKEN = "DIVIDE_BRICK"; const std::string BOVCollection::DATA_BRICKLETS_TOKEN = "DATA_BRICKLETS"; const std::string BOVCollection::DATA_COMPONENTS_TOKEN = "DATA_COMPONENTS"; const std::array BOVCollection::_defaultOrigin = {0., 0., 0.}; const std::array BOVCollection::_defaultBrickSize = {1., 1., 1.}; -const std::array BOVCollection::_defaultBricklets = {0, 0, 0}; const std::array BOVCollection::_defaultGridSize = {0, 0, 0}; const DC::XType BOVCollection::_defaultFormat = DC::XType::INVALID; const std::string BOVCollection::_defaultFile = ""; -const std::string BOVCollection::_defaultEndian = "LITTLE"; const std::string BOVCollection::_defaultVar = "brickVar"; -const std::string BOVCollection::_defaultCentering = "ZONAL"; const double BOVCollection::_defaultTime = 0.; const size_t BOVCollection::_defaultByteOffset = 0; -const size_t BOVCollection::_defaultComponents = 1; + +// Currently unused in ReadRegion() logic +const std::string BOVCollection::_defaultEndian = "LITTLE"; +const std::string BOVCollection::_defaultCentering = "ZONAL"; const bool BOVCollection::_defaultDivBrick = false; +const std::array BOVCollection::_defaultBricklets = {0, 0, 0}; +const size_t BOVCollection::_defaultComponents = 1; const std::string BOVCollection::_xDim = "x"; const std::string BOVCollection::_yDim = "y"; @@ -62,6 +66,13 @@ BOVCollection::BOVCollection() _divideBrick(_defaultDivBrick), _dataComponents(_defaultComponents), _tmpDataFormat(_defaultFormat), _tmpByteOffset(_defaultByteOffset), _gridSizeAssigned(false), _formatAssigned(false), _brickOriginAssigned(false), _brickSizeAssigned(false), _byteOffsetAssigned(false), _timeDimension(_timeDim) { + // Note: the following variables are unused in the ReadRegion() logic + // _defaultEndian + // _defaultCentering + // _defaultDivBrick + // _defaultBricklets + // _defaultComponents + _dataFiles.clear(); _times.clear(); _gridSize = _defaultGridSize; @@ -516,9 +527,13 @@ template int BOVCollection::ReadRegion(std::string varname, size_t ts, size_t yOffset = _gridSize[0] * j; size_t offset = formatSize * (xOffset + yOffset + zOffset) + _byteOffset; - fseek(fp, offset, SEEK_SET); - size_t rc = fread(readBuffer, formatSize, count, fp); + size_t rc = fseek(fp, offset, SEEK_SET); + if (rc != 0) { + MyBase::SetErrMsg("Unable to seek on file: %M"); + return -1; + } + rc = fread(readBuffer, formatSize, count, fp); if (rc != count) { if (ferror(fp) != 0) { MyBase::SetErrMsg("Error reading input file: %M"); From 22f8615a68b653085e12892c5215456d42cb3645 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Wed, 21 Jul 2021 11:40:42 -0600 Subject: [PATCH 24/28] add more documentation, add varname validator --- include/vapor/BOVCollection.h | 29 ++++++++++++++++++----------- include/vapor/DCBOV.h | 12 +++++++----- lib/vdc/BOVCollection.cpp | 30 +++++++++++++++++++++--------- 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/include/vapor/BOVCollection.h b/include/vapor/BOVCollection.h index 2974e0f769..66da921bb2 100644 --- a/include/vapor/BOVCollection.h +++ b/include/vapor/BOVCollection.h @@ -38,14 +38,16 @@ class BOVCollection : public Wasp::MyBase { DC::XType _dataFormat; std::string _variable; std::vector _variables; - std::string _dataEndian; - std::string _centering; std::array _brickOrigin; std::array _brickSize; size_t _byteOffset; - bool _divideBrick; - std::array _dataBricklets; - int _dataComponents; + + // These values are currently parsed and assigned, but are unimplemented (not used) + bool _divideBrick; + std::string _dataEndian; + std::string _centering; + int _dataComponents; + std::array _dataBricklets; // Placeholder variables to store values read from BOV descriptor files. // These values must be consistent among BOV files, and are validated before @@ -80,6 +82,7 @@ class BOVCollection : public Wasp::MyBase { int _sizeOfFormat(DC::XType) const; + int _invalidVarNameError() const; int _invalidFileSizeError(size_t numElements) const; int _invalidFileError() const; int _invalidDimensionError(const std::string &token) const; @@ -94,11 +97,13 @@ class BOVCollection : public Wasp::MyBase { static const std::string GRID_SIZE_TOKEN; static const std::string FORMAT_TOKEN; static const std::string VARIABLE_TOKEN; - static const std::string ENDIAN_TOKEN; - static const std::string CENTERING_TOKEN; static const std::string ORIGIN_TOKEN; static const std::string BRICK_SIZE_TOKEN; static const std::string OFFSET_TOKEN; + + // These tokens are currently parsed but are not used + static const std::string ENDIAN_TOKEN; + static const std::string CENTERING_TOKEN; static const std::string DIVIDE_BRICK_TOKEN; static const std::string DATA_BRICKLETS_TOKEN; static const std::string DATA_COMPONENTS_TOKEN; @@ -107,15 +112,17 @@ class BOVCollection : public Wasp::MyBase { static const std::string _defaultFile; static const DC::XType _defaultFormat; static const std::string _defaultVar; - static const std::string _defaultEndian; - static const std::string _defaultCentering; static const size_t _defaultByteOffset; - static const size_t _defaultComponents; - static const bool _defaultDivBrick; static const std::array _defaultOrigin; static const std::array _defaultBrickSize; static const std::array _defaultGridSize; + + // These defaults are currently unimplemented in the BOV reader logic + static const std::string _defaultEndian; + static const std::string _defaultCentering; + static const bool _defaultDivBrick; static const std::array _defaultBricklets; + static const size_t _defaultComponents; static const std::string _xDim; static const std::string _yDim; diff --git a/include/vapor/DCBOV.h b/include/vapor/DCBOV.h index 98038e6ec9..ad3f0a1796 100644 --- a/include/vapor/DCBOV.h +++ b/include/vapor/DCBOV.h @@ -24,23 +24,23 @@ class BOVCollection; // # DATA_FILE points to a binary data file. It can be a full file path, or a path relative to the BOV header. // DATA_FILE: bovA1.bin // -// # The data size corresponds to NX,NY,NZ in the above example code. +// # The data size corresponds to NX,NY,NZ in the above example code. It must contain three values // DATA_SIZE: 10 10 10 // // # Allowable values for DATA_FORMAT are: INT,FLOAT,DOUBLE // DATA_FORMAT: FLOAT // -// # VARIABLE is a string that specifies the variable being read in DATA_FILE +// # VARIABLE is a string that specifies the variable being read in DATA_FILE. Must be alphanumeric (abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890) // VARIABLE: myVariable // -// # BRICK_ORIGIN lets you specify a new coordinate system origin for # the mesh that will be created to suit your data. +// # BRICK_ORIGIN lets you specify a new coordinate system origin for # the mesh that will be created to suit your data. It must contain three values. // BRICK_ORIGIN: 0. 0. 0. // -// # BRICK_SIZE lets you specify the size of the brick. +// # BRICK_SIZE lets you specify the size of the brick on X, Y, and Z. It must contain three values. // BRICK_SIZE: 10. 20. 5. // // # BYTE_OFFSET is optional and lets you specify some number of -// # bytes to skip at the front of the file. This can be useful for # skipping the 4-byte header that Fortran tends to write to files. # If your file does no +// # bytes to skip at the front of the file. This can be useful for # skipping the 4-byte header that Fortran tends to write to files. # If your file does not have a header then DO NOT USE BYTE_OFFSET. // BYTE_OFFSET: 4 //! @@ -71,10 +71,12 @@ class BOVCollection; //! - DATA_COMPONENTS //! //! If duplicate key/value pairs exist in a BOV header, the value closest to the bottom of the file will be used. +//! If duplicate values exist for whatever reason, all entries must be valid (except for DATA_FILE, which gets validated after parsing) //! Scientific notation is supported for floating point values like BRICK_ORIGIN and BRICK_SIZE. //! Scientific notation is not supported for integer values like DATA_SIZE. //! Wild card characters are not currently supported in the DATA_FILE token. //! Each .bov file can only refer to a single data file. +//! VARIABLE must be alphanumeric (abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890) //! //! \author Scott Pearse //! \date May, 2021 diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index a660c2b721..24dbe6e1ef 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -62,8 +62,8 @@ const std::string BOVCollection::_floatFormatString = "FLOAT"; const std::string BOVCollection::_doubleFormatString = "DOUBLE"; BOVCollection::BOVCollection() -: _time(_defaultTime), _dataFile(_defaultFile), _dataFormat(_defaultFormat), _variable(_defaultVar), _dataEndian(_defaultEndian), _centering(_defaultCentering), _byteOffset(_defaultByteOffset), - _divideBrick(_defaultDivBrick), _dataComponents(_defaultComponents), _tmpDataFormat(_defaultFormat), _tmpByteOffset(_defaultByteOffset), _gridSizeAssigned(false), _formatAssigned(false), +: _time(_defaultTime), _dataFile(_defaultFile), _dataFormat(_defaultFormat), _variable(_defaultVar), _byteOffset(_defaultByteOffset), _divideBrick(_defaultDivBrick), _dataEndian(_defaultEndian), + _centering(_defaultCentering), _dataComponents(_defaultComponents), _tmpDataFormat(_defaultFormat), _tmpByteOffset(_defaultByteOffset), _gridSizeAssigned(false), _formatAssigned(false), _brickOriginAssigned(false), _brickSizeAssigned(false), _byteOffsetAssigned(false), _timeDimension(_timeDim) { // Note: the following variables are unused in the ReadRegion() logic @@ -106,6 +106,12 @@ int BOVCollection::Initialize(const std::vector &paths) return -1; } + // If _dataFile is not an absolute path, prepend with the BOV header's path + if (!Wasp::FileUtils::IsPathAbsolute(_dataFile)) { + auto paths = {_currentFilePath, _dataFile}; + _dataFile = Wasp::FileUtils::JoinPaths(paths); + } + rc = _validateParsedValues(); if (rc < 0) { SetErrMsg("Validating BOV tokens failed"); @@ -124,12 +130,6 @@ int BOVCollection::Initialize(const std::vector &paths) return -1; } header.close(); - - // If _dataFile is not an absolute path, prepend with the BOV header's path - if (!Wasp::FileUtils::IsPathAbsolute(_dataFile)) { - auto paths = {_currentFilePath, _dataFile}; - _dataFile = Wasp::FileUtils::JoinPaths(paths); - } } return 0; @@ -264,6 +264,8 @@ int BOVCollection::_validateParsedValues() if (fp == nullptr) return _invalidFileError(); fclose(fp); + if (_variable.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890") != std::string::npos) return _invalidVarNameError(); + return 0; } @@ -277,6 +279,13 @@ void BOVCollection::_populateDataFileMap() _dataFileMap[_variable][_time] = _dataFile; } +int BOVCollection::_invalidVarNameError() const +{ + SetErrMsg("Invalid variable name. (Must be alphanumeric)"); + return -1; +} + + int BOVCollection::_invalidFileSizeError(size_t numElements) const { SetErrMsg(("Data file " + _dataFile + ", which has " + to_string(numElements) @@ -375,8 +384,11 @@ template<> int BOVCollection::_findToken(const std::string &token, st value = DC::FLOAT; else if (format == _doubleFormatString) value = DC::DOUBLE; - else + else { value = DC::INVALID; + _invalidFormatError(token); + return (int)parseCodes::PARSE_ERROR; + } if (verbose) { std::cout << std::setw(20) << token << " " << value << std::endl; } return (int)parseCodes::FOUND; From 48241d0c108f796d1ab6f01fbdc9351f9fc59fc5 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Wed, 21 Jul 2021 12:02:36 -0600 Subject: [PATCH 25/28] Address sam's comments --- include/vapor/DCBOV.h | 8 ++++---- lib/vdc/BOVCollection.cpp | 11 +++-------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/include/vapor/DCBOV.h b/include/vapor/DCBOV.h index ad3f0a1796..b4eae1e4d2 100644 --- a/include/vapor/DCBOV.h +++ b/include/vapor/DCBOV.h @@ -30,7 +30,7 @@ class BOVCollection; // # Allowable values for DATA_FORMAT are: INT,FLOAT,DOUBLE // DATA_FORMAT: FLOAT // -// # VARIABLE is a string that specifies the variable being read in DATA_FILE. Must be alphanumeric (abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890) +// # VARIABLE is a string that specifies the variable being read in DATA_FILE. Must be alphanumeric (abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-) // VARIABLE: myVariable // // # BRICK_ORIGIN lets you specify a new coordinate system origin for # the mesh that will be created to suit your data. It must contain three values. @@ -40,8 +40,8 @@ class BOVCollection; // BRICK_SIZE: 10. 20. 5. // // # BYTE_OFFSET is optional and lets you specify some number of -// # bytes to skip at the front of the file. This can be useful for # skipping the 4-byte header that Fortran tends to write to files. # If your file does not have a header then DO NOT USE BYTE_OFFSET. -// BYTE_OFFSET: 4 +// # bytes to skip at the front of the file. This can be useful for # skipping the 4-byte header that Fortran tends to write to files. # If your file does not have a header then DO NOT USE +// BYTE_OFFSET. BYTE_OFFSET: 4 //! //! \class DCBOV @@ -76,7 +76,7 @@ class BOVCollection; //! Scientific notation is not supported for integer values like DATA_SIZE. //! Wild card characters are not currently supported in the DATA_FILE token. //! Each .bov file can only refer to a single data file. -//! VARIABLE must be alphanumeric (abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890) +//! VARIABLE must be alphanumeric (abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-) //! //! \author Scott Pearse //! \date May, 2021 diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index 24dbe6e1ef..15562d8d75 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -10,7 +10,7 @@ #include "vapor/VAssert.h" #include "vapor/utils.h" #include "vapor/FileUtils.h" -#include +#include #include #include @@ -259,12 +259,7 @@ int BOVCollection::_validateParsedValues() _byteOffsetAssigned = true; } - // Validate whether we can open the data file - FILE *fp = fopen(_dataFile.c_str(), "rb"); - if (fp == nullptr) return _invalidFileError(); - fclose(fp); - - if (_variable.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890") != std::string::npos) return _invalidVarNameError(); + if (_variable.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-") != std::string::npos) return _invalidVarNameError(); return 0; } @@ -539,7 +534,7 @@ template int BOVCollection::ReadRegion(std::string varname, size_t ts, size_t yOffset = _gridSize[0] * j; size_t offset = formatSize * (xOffset + yOffset + zOffset) + _byteOffset; - size_t rc = fseek(fp, offset, SEEK_SET); + int rc = fseek(fp, offset, SEEK_SET); if (rc != 0) { MyBase::SetErrMsg("Unable to seek on file: %M"); return -1; From ea9376e560669586a4cf5dd8f620353ef4a2bef5 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Wed, 21 Jul 2021 22:10:51 -0600 Subject: [PATCH 26/28] fix variable name and delete pointer --- lib/vdc/BOVCollection.cpp | 4 ++-- lib/vdc/DCBOV.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index 15562d8d75..cd4fc81051 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -108,8 +108,8 @@ int BOVCollection::Initialize(const std::vector &paths) // If _dataFile is not an absolute path, prepend with the BOV header's path if (!Wasp::FileUtils::IsPathAbsolute(_dataFile)) { - auto paths = {_currentFilePath, _dataFile}; - _dataFile = Wasp::FileUtils::JoinPaths(paths); + auto dirAndPath = {_currentFilePath, _dataFile}; + _dataFile = Wasp::FileUtils::JoinPaths(dirAndPath); } rc = _validateParsedValues(); diff --git a/lib/vdc/DCBOV.cpp b/lib/vdc/DCBOV.cpp index 15db3c5384..1b16d512db 100644 --- a/lib/vdc/DCBOV.cpp +++ b/lib/vdc/DCBOV.cpp @@ -36,6 +36,7 @@ DCBOV::~DCBOV() int DCBOV::initialize(const vector &paths, const std::vector &options) { + if (_bovCollection != nullptr) delete _bovCollection; _bovCollection = new BOVCollection(); int rc = _bovCollection->Initialize(paths); if (rc < 0) { From aec3ade12f67cb116caebd3bc0895d6de8d7d641 Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Wed, 21 Jul 2021 22:23:18 -0600 Subject: [PATCH 27/28] remove duplicate zeros from variable scrubber --- include/vapor/DCBOV.h | 4 ++-- lib/vdc/BOVCollection.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/vapor/DCBOV.h b/include/vapor/DCBOV.h index b4eae1e4d2..ba792a1966 100644 --- a/include/vapor/DCBOV.h +++ b/include/vapor/DCBOV.h @@ -30,7 +30,7 @@ class BOVCollection; // # Allowable values for DATA_FORMAT are: INT,FLOAT,DOUBLE // DATA_FORMAT: FLOAT // -// # VARIABLE is a string that specifies the variable being read in DATA_FILE. Must be alphanumeric (abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-) +// # VARIABLE is a string that specifies the variable being read in DATA_FILE. Must be alphanumeric (abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-) // VARIABLE: myVariable // // # BRICK_ORIGIN lets you specify a new coordinate system origin for # the mesh that will be created to suit your data. It must contain three values. @@ -76,7 +76,7 @@ class BOVCollection; //! Scientific notation is not supported for integer values like DATA_SIZE. //! Wild card characters are not currently supported in the DATA_FILE token. //! Each .bov file can only refer to a single data file. -//! VARIABLE must be alphanumeric (abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-) +//! VARIABLE must be alphanumeric (abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-) //! //! \author Scott Pearse //! \date May, 2021 diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index cd4fc81051..f2ebd7c39b 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -259,7 +259,7 @@ int BOVCollection::_validateParsedValues() _byteOffsetAssigned = true; } - if (_variable.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-") != std::string::npos) return _invalidVarNameError(); + if (_variable.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-") != std::string::npos) return _invalidVarNameError(); return 0; } From 410855088c8341b1cdc0b35e25c7eddeee46933c Mon Sep 17 00:00:00 2001 From: Scott Pearse Date: Wed, 21 Jul 2021 22:26:58 -0600 Subject: [PATCH 28/28] new return code for fread --- lib/vdc/BOVCollection.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vdc/BOVCollection.cpp b/lib/vdc/BOVCollection.cpp index f2ebd7c39b..7e43e9b06d 100644 --- a/lib/vdc/BOVCollection.cpp +++ b/lib/vdc/BOVCollection.cpp @@ -540,8 +540,8 @@ template int BOVCollection::ReadRegion(std::string varname, size_t ts, return -1; } - rc = fread(readBuffer, formatSize, count, fp); - if (rc != count) { + size_t fread_rc = fread(readBuffer, formatSize, count, fp); + if (fread_rc != count) { if (ferror(fp) != 0) { MyBase::SetErrMsg("Error reading input file: %M"); } else {