diff --git a/src/common/utility/StringHelpers.h b/src/common/utility/StringHelpers.h index b1786d4bba..cbfb571d20 100644 --- a/src/common/utility/StringHelpers.h +++ b/src/common/utility/StringHelpers.h @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -20,14 +21,6 @@ #include // for CIStringSet, CIStringSetVector defs -#if __GNUC__ >= 3 -# define MUST_CHECK __attribute__ ((warn_unused_result)) -#else -# define MUST_CHECK /*nothing*/ -#endif - - - namespace StringHelpers { const std::string NON_RELEVANT_CHARS = @@ -97,73 +90,124 @@ namespace StringHelpers std::string UTILITY_API EscapeSpecialChars(const std::string &str); -// **************************************************************************** -// Function: str_to_u_numeric -// -// Purpose: Converts a string value into an unsigned numeric type as given by -// the template parameter. -// WARNING: This is likely to compile and silently fail if given a -// signed type in the template parameter. -// -// Programmer: Tom Fogal -// Creation: August 11, 2008 -// -// Modifications: -// -// Tom Fogal, Fri Aug 29 16:15:17 EDT 2008 -// Reorganized to propagate error upward. -// -// Tom Fogal, Tue Sep 23 11:08:02 MDT 2008 -// Removed a statically-false branch which was causing an annoying warning. -// -// **************************************************************************** - template - MUST_CHECK bool str_to_u_numeric(const char * const s, UT *retval) + // **************************************************************************** + // Function: vstrtonum + // + // Purpose: Replacement for strtoX() and atoX() methods. + // + // Instead of any of these kinds of uses... + // + // int k = atoi(numstr); + // float f1 = atof(numstr); + // + // unsigned u = (unsigned) strtoul(numstr, 0); + // if (errno != 0) u = 0xFFFFFFFF; // set to default val + // + // float f2 = (float) strtod(numstr, 0); + // if (errno != 0) { + // f2 = -1.0; // set to default value + // debug5 << numstr << " bad value" << endl; // log error + // } + // + // ...do this... + // + // int k = vstrtonum(numstr); + // float f1 = vstrtonum(numstr); + // + // unsigned u = vstrtonum(numstr, 0xFFFFFFFF); + // float f = vstrtonum(numstr, -1.0, debug5); + // + // Templatized methods to convert strings to language-native typed + // numeric values, perform some minimal error checking and optionally + // emit error messages with potentially useful context when errors + // are encountered. + // + // This should always be used in place of strtoX() or atoX() when + // reading ascii numerical data. + // + // We do a minimal amount of error checking for a signed conversion + // by checking if first non-whitespace character is a minus sign and + // artificially setting errno to EDOM (not something strtoX/atoX + // would ever do). We could add more error checking for different + // cases too by, for example, checking value read for int type and + // seeing if it is too big to fit in an int. We currently do not + // do this but it would be easy to add. We could also easily add + // logic for other, less frequently used types such as shorts or + // maybe int64_t, etc. + // + // The default method treats all ascii as long double for the strtoX + // conversion and then casts it to correct type. We specialize some + // cases for slightly better behavior. + // + // I ran performance tests on macOS doing 1 million conversions with + // these methods (including error checking) and 1 million directly + // with strtoX and atoX methods and observed no significant diffs + // in performance. In addition, keep in mind that these methods are + // typically being used in conjunction with file I/O, which almost + // certainly dominates performance. The only time this might not be + // true is for memory resident "files", mmaps, and/or SSDs. + // + // At some point, it would make sense to enhance this to use locale + // so we can handle different character encodings as well as regional + // specific interpretations (e.g. European 1.234.456,89). The idea + // would be to set the locale VisIt is using (a pref. maybe) and then + // these methods would just use that locale in calls to strtoX. That + // could be achieved globally in VisIt with a call to setlocale(). + // However, when in the United States reading an ascii data file + // formatted for human readability in Germany the desire would be + // to specify "de_DE" for the locale during the read of just that + // file suggesting something more complicated than just a global + // setting. + // + // Mark C. Miller, Wed Jan 10 17:10:21 PST 2024 + // **************************************************************************** + template inline T _vstrtonum(char const *numstr, char **eptr, int /* unused */) { return static_cast(strtold(numstr, eptr)); } + + // Specialize int/long cases to use int conversion strtol which with base of 0 can handle octal and hex also + #define _VSTRTONUMI(T,F) template<> inline T _vstrtonum(char const *numstr, char **eptr, int base) { return static_cast(F(numstr, eptr, base)); } + _VSTRTONUMI(int,std::strtol) + _VSTRTONUMI(long,std::strtol) + _VSTRTONUMI(long long,std::strtoll) + + // Specialize unsigned cases to use unsigned conversion strtoul and error checking passing negated arg + // Note that size_t is an alias almost certainly to one of these types and so we do not have to + // explicitly handle it here but any caller can still use it as in vstrtonum(). + #define _VSTRTONUMU(T,F) template<> inline T _vstrtonum(char const *numstr, char **eptr, int base) { char const *s=numstr; while (isspace(*s)) s++; T retval = static_cast(F(numstr, eptr, base)); if (*s=='-') errno = EDOM; return retval;} + _VSTRTONUMU(unsigned int,std::strtoul) + _VSTRTONUMU(unsigned long,std::strtoul) + _VSTRTONUMU(unsigned long long,std::strtoull) + + // dummy ostream for default (no ostream) cases + static std::ostream NO_OSTREAM(std::cerr.rdbuf()); + + template T + inline vstrtonum(char const *numstr, int base = 10, T dfltval = 0, std::ostream& errstrm = NO_OSTREAM, char **eptr = 0) { - // strtoul() will happily convert a negative string into an unsigned - // integer. Do a simple check and bail out if we're given a negative - // number. - if(s[0] == '-') - { - return false; - } - - const char *str = s; - // get rid of leading 0's; they confuse strtoul. - if(str[0] == '0' && str[1] != '\0' && str[1] != 'x') - { - while(*str == '0') { ++str; } - } - - // One might want to think about switching this to an `unsigned long - // long' and using `strtoull' below. That will catch more cases, but - // this is more portable. - unsigned long ret; - char *end; + char *_eptr; + char **eptrptr = eptr==0?&_eptr:eptr; errno = 0; - ret = strtoul(str, &end, 0); - *retval = static_cast(ret); - switch(errno) + T retval = _vstrtonum(numstr, eptrptr, base); + int errno_save = errno; + + // emit possible error messages + if (errno_save != 0) { - case 0: /* success */ break; - case ERANGE: - // Constant does not fit in sizeof(unsigned long) bytes. - return false; - break; - case EINVAL: - // Bad base (3rd arg) given; this should be impossible. - return false; - break; - default: - // Unknown error. - return false; - break; + retval = dfltval; + if (&errstrm != &NO_OSTREAM) + { + errstrm << "Problem converting \"" << numstr << "\" to a number (\"" << strerror(errno_save) << "\")" << std::endl; + } } - if(end == s) { - // junk characters start the string .. is this a number? - return false; + if (*eptrptr == numstr) + { + retval = dfltval; + if (&errstrm != &NO_OSTREAM) + { + errstrm << "Problem converting \"" << numstr << "\" to a number (\"no digits to convert\")" << std::endl; + } } - return true; + + return retval; } } #endif diff --git a/src/common/utility/StringHelpers_test.C b/src/common/utility/StringHelpers_test.C index c851b36a60..8458102662 100644 --- a/src/common/utility/StringHelpers_test.C +++ b/src/common/utility/StringHelpers_test.C @@ -68,16 +68,16 @@ int main(int argc, char **argv) falseNegatives.push_back(__LINE__); size_t s_to_num_tmp; - if(str_to_u_numeric("42", &s_to_num_tmp) == false || - s_to_num_tmp != 42) + s_to_num_tmp = vstrtonum("42"); + if (s_to_num_tmp != 42) falseNegatives.push_back(__LINE__); - if(str_to_u_numeric("0", &s_to_num_tmp) == false || - s_to_num_tmp != 0) + s_to_num_tmp = vstrtonum("0"); + if (s_to_num_tmp != 0) falseNegatives.push_back(__LINE__); - if(str_to_u_numeric("2147483648", &s_to_num_tmp) == false || - s_to_num_tmp != 2147483648UL) + s_to_num_tmp = vstrtonum("2147483648"); + if (s_to_num_tmp != 2147483648UL) falseNegatives.push_back(__LINE__); { @@ -354,6 +354,30 @@ int main(int argc, char **argv) "../kerry/apple///banana/./././///../../../grape", "/foo/bar/grape"); +#if 0 +#define CHECK_STRTONUM(T, S, V, DF, L, E) \ +T v = vstrtonum(S); \ +if (v != V + + + + CHECK_STRTONUM("555", 555, 555 + // + // Check strtonum conversion cases + // + char *numstrs[] = {"555", "0555", "0x555", "0x555.5", "555.5", " \t-1", "abcdef", "1.5e-1207", + "0xFFFFFFFF", "4290000000", "15E+3", "7.652abc"}; + for (int i = 0; i < sizeof(numstrs)/sizeof(numstrs[0]); i++) + { + int iv = vstrtonum(numstrs[i], 0, i, "int", &std::cerr); + double dv = vstrtonum(numstrs[i], 0, i, "double", &std::cerr); + unsigned int uiv = vstrtonum(numstrs[i], 0, i, "unsigned", &std::cerr); + printf("str = \"%s\", int=%d, double=%g, unsigned int=%u\n", numstrs[i], iv, dv, uiv); + } +#endif + + + int all_errors = falseNegatives.size() + falsePositives.size() + pluralizing_errors + diff --git a/src/common/utility/maptypes.h b/src/common/utility/maptypes.h index c77e0ee170..13754ab875 100644 --- a/src/common/utility/maptypes.h +++ b/src/common/utility/maptypes.h @@ -5,6 +5,7 @@ #ifndef VISIT_MAP_TYPES_H #define VISIT_MAP_TYPES_H #include +#include #include #include #include @@ -16,15 +17,19 @@ typedef StringIntMap LevelColorMap; typedef std::map StringStringVectorMap; typedef std::map DoubleIntMap; - // CI short for Case-Insenstive +// The two transform lines here previously used C lib `tolower` as the 4th argument +// That is incorrect as it works on ints, not chars. C++ transform over strings is +// expecting a method that operates on chars. Using C++ tolower works but there are +// multiple std::twolower methods and so we use a lambda notation to force it to +// find the correct one. struct CIComparator { bool operator() (const std::string& s1, const std::string& s2) const { std::string str1(s1.length(),' '); std::string str2(s2.length(),' '); - std::transform(s1.begin(), s1.end(), str1.begin(), tolower); - std::transform(s2.begin(), s2.end(), str2.begin(), tolower); + std::transform(s1.begin(), s1.end(), str1.begin(), [](unsigned char c)->char{return std::tolower(c);}); + std::transform(s2.begin(), s2.end(), str2.begin(), [](unsigned char c)->char{return std::tolower(c);}); return str1 < str2; } }; diff --git a/src/databases/AMR/AMRreaderInterface.C b/src/databases/AMR/AMRreaderInterface.C index 28b14985af..e8605e8bd1 100644 --- a/src/databases/AMR/AMRreaderInterface.C +++ b/src/databases/AMR/AMRreaderInterface.C @@ -46,6 +46,11 @@ AMRreaderInterface::~AMRreaderInterface() #include #include +using DebugStream::Level1; +using DebugStream::Stream1; +#include +using StringHelpers::vstrtonum; +using StringHelpers::NO_OSTREAM; #include AMRreaderInterface * @@ -54,7 +59,7 @@ InstantiateAMRreader() int typ=0; char* amrlvl=getenv("AMRLEVEL"); if( amrlvl ) - typ = atoi(amrlvl); + typ = vstrtonum(amrlvl,10,0,Level1()?Stream1():NO_OSTREAM); AMRreaderInterface *reader = NULL; switch(typ) diff --git a/src/databases/ANSYS/avtANSYSFileFormat.C b/src/databases/ANSYS/avtANSYSFileFormat.C index a460bdba09..8869b6ad79 100644 --- a/src/databases/ANSYS/avtANSYSFileFormat.C +++ b/src/databases/ANSYS/avtANSYSFileFormat.C @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include @@ -37,6 +37,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; using std::string; @@ -169,32 +171,19 @@ avtANSYSFileFormat::ActivateTimestep() // // Justin Privitera, Tue Jul 5 14:40:55 PDT 2022 // Changed 'supressed' to 'suppressed'. +// +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // **************************************************************************** -int -get_errno() -{ - int eno = 0; -#ifdef WIN32 - _get_errno(&eno); -#else - eno = errno; -#endif - return eno; -} - - - #define CHECK_COORD_COMPONENT(Coord) \ do { \ - int _errno = get_errno(); \ - char msg[512] = "Further warnings will be suppressed"; \ - if (_errno != 0 && invalidCoordCompWarning++ < 5) \ + char msg[512] = "Further warnings will be suppressed"; \ + if (std::isnan(Coord) && invalidCoordCompWarning++ < 5) \ { \ if (invalidCoordCompWarning < 5) \ snprintf(msg, sizeof(msg),"Encountered invalid value " \ - "\"%s\" (%s) at or near line %d", strerror(_errno), \ - valstart, lineIndex); \ + "\"%s\" at or near line %d", valstart, lineIndex); \ debug1 << msg; \ TRY \ { \ @@ -206,8 +195,8 @@ do { \ cerr << msg << endl; \ } \ ENDTRY \ + Coord = 0; \ } \ - endptr = 0; \ } while (0) bool @@ -282,10 +271,8 @@ avtANSYSFileFormat::ReadFile(const char *name, int nLines) if(expectedLineLength > 0 && linelen < expectedLineLength) { memset(line + linelen + 1, 0, (MAX_ANSYS_LINE - linelen - 1) * sizeof(char)); -#if 0 debug5 << "Padding line with NULLs" << endl; debug5 << line << endl; -#endif } // Give it a chance to break out of coordinate reading. @@ -307,31 +294,28 @@ avtANSYSFileFormat::ReadFile(const char *name, int nLines) { char *valstart = line + fieldStart; char *valend = valstart + fieldWidth; - char *endptr = 0; - pt[2] = strtod(valstart, &endptr); + pt[2] = vstrtonum(valstart,10,NAN); CHECK_COORD_COMPONENT(pt[2]); valstart -= fieldWidth; valend -= fieldWidth; *valend = '\0'; - pt[1] = strtod(valstart, &endptr); + pt[1] = vstrtonum(valstart,10,NAN); CHECK_COORD_COMPONENT(pt[1]); valstart -= fieldWidth; valend -= fieldWidth; *valend = '\0'; - pt[0] = strtod(valstart, &endptr); + pt[0] = vstrtonum(valstart,10,NAN); CHECK_COORD_COMPONENT(pt[0]); -#if 0 - debug4 << pt[0] << ", " << pt[1] << ", " << pt[2] << endl; -#endif + debug5 << pt[0] << ", " << pt[1] << ", " << pt[2] << endl; pts->InsertNextPoint(pt); } else if(readingConnectivity) { // Get whether this cell is real from column 0 line[fieldWidth] = '\0'; - bool realCell = atoi(line) > 0; + bool realCell = vstrtonum(line) > 0; if(!realCell) { expectedLineLength = 0; @@ -344,7 +328,7 @@ avtANSYSFileFormat::ReadFile(const char *name, int nLines) line[ncellsColumn * fieldWidth] = '\0'; if(nverts == -1) { - nverts = atoi(line + (ncellsColumn-1) * fieldWidth); + nverts = vstrtonum(line + (ncellsColumn-1) * fieldWidth); } if(nverts == 8) @@ -353,18 +337,16 @@ avtANSYSFileFormat::ReadFile(const char *name, int nLines) char *valend = valstart + fieldWidth; for(int i = 0; i < 8; ++i) { - int ivalue = atoi(valstart); + int ivalue = vstrtonum(valstart); verts[7-i] = (ivalue > 0) ? (ivalue - 1) : ivalue; valstart -= fieldWidth; valend -= fieldWidth; *valend = '\0'; } -#if 0 for(int j = 0; j < 8; ++j) - debug4 << ", " << verts[j]; - debug4 << endl; -#endif + debug5 << ", " << verts[j]; + debug5 << endl; ugrid->InsertNextCell(VTK_HEXAHEDRON, 8, verts); } else if(nverts == 10) @@ -373,7 +355,7 @@ avtANSYSFileFormat::ReadFile(const char *name, int nLines) char *valend = valstart + fieldWidth; for(int i = 0; i < 8; ++i) { - int ivalue = atoi(valstart); + int ivalue = vstrtonum(valstart); verts[7-i] = (ivalue > 0) ? (ivalue - 1) : ivalue; valstart -= fieldWidth; valend -= fieldWidth; @@ -386,18 +368,16 @@ avtANSYSFileFormat::ReadFile(const char *name, int nLines) *valend = '\0'; for(int i = 0; i < 2; ++i) { - int ivalue = atoi(valstart); + int ivalue = vstrtonum(valstart); verts[9-i] = (ivalue > 0) ? (ivalue - 1) : ivalue; valstart -= fieldWidth; valend -= fieldWidth; *valend = '\0'; } -#if 0 for(int j = 0; j < 10; ++j) - debug4 << ", " << verts[j]; - debug4 << endl; -#endif + debug5 << ", " << verts[j]; + debug5 << endl; ugrid->InsertNextCell(VTK_QUADRATIC_TETRA, 10, verts); } @@ -418,7 +398,7 @@ avtANSYSFileFormat::ReadFile(const char *name, int nLines) if(comma != 0) { char *cols = comma + 1; - numFields = atoi(cols); + numFields = vstrtonum(cols); debug4 << mName << "Coordinate data stored in " << numFields << " columns." << endl; char *comma2 = strstr(comma+1, ","); @@ -468,7 +448,7 @@ avtANSYSFileFormat::ReadFile(const char *name, int nLines) // these cells are wrong (they have the incorrect amount of vertices listed // as well as repeated vertex ids) and we ignore them. char *cols = comma + 1; - numFields = atoi(cols); + numFields = vstrtonum(cols); debug4 << mName << "Connectivity data stored in " << numFields << " columns." << endl; recognized = true; diff --git a/src/databases/Boxlib3D/avtBoxlibFileFormat.C b/src/databases/Boxlib3D/avtBoxlibFileFormat.C index f58af256db..313493febf 100644 --- a/src/databases/Boxlib3D/avtBoxlibFileFormat.C +++ b/src/databases/Boxlib3D/avtBoxlibFileFormat.C @@ -82,6 +82,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; // Map symbol names // Ugly hack, but fixes crash on Mac @@ -159,6 +161,9 @@ static int VSSearch(const vector &, const string &); // // Mark C. Miller, Tue Nov 8 21:14:00 PST 2005 // Refactored from constructor +// +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // **************************************************************************** static int GetCycleFromRootPath(const std::string &rpath) { @@ -176,7 +181,7 @@ static int GetCycleFromRootPath(const std::string &rpath) } if (last != NULL) { - cyc = atoi(last + strlen("plt")); + cyc = vstrtonum(last + strlen("plt")); return cyc; } @@ -324,6 +329,8 @@ AVTBOXLIBFILEFORMAT::ActivateTimestep(void) // Hank Childs, Sun Mar 6 16:21:15 PST 2005 // Add support for GeoDyne material names. // +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // **************************************************************************** void @@ -406,7 +413,7 @@ AVTBOXLIBFILEFORMAT::InitializeReader(void) if (varNames[i].find("frac") == 0) { varUsedElsewhere[i] = true; - int val = atoi(varNames[i].c_str()+4); + int val = vstrtonum(varNames[i].c_str()+4); if (val > nMaterials) nMaterials = val; @@ -420,7 +427,7 @@ AVTBOXLIBFILEFORMAT::InitializeReader(void) if (varNames[i].find("vf_") == 0) { varUsedElsewhere[i] = true; - int val = atoi(varNames[i].c_str()+3); + int val = vstrtonum(varNames[i].c_str()+3); if (val > nMaterials) nMaterials = val; @@ -854,7 +861,7 @@ AVTBOXLIBFILEFORMAT::ReadHeader(void) // Read in time if (iDoReading) in >> double_tmp; - time = atof(double_tmp.c_str()); + time = vstrtonum(double_tmp.c_str()); BroadcastDouble(time); haveReadTimeAndCycle = true; if (metadata != NULL) @@ -885,12 +892,12 @@ AVTBOXLIBFILEFORMAT::ReadHeader(void) for (i = 0; i < dimension; ++i) { in >> double_tmp; - probLo[i] = atof(double_tmp.c_str()); + probLo[i] = vstrtonum(double_tmp.c_str()); } for (i = 0; i < dimension; ++i) { in >> double_tmp; - probHi[i] = atof(double_tmp.c_str()); + probHi[i] = vstrtonum(double_tmp.c_str()); } } BroadcastDouble(probLo[0]); @@ -926,12 +933,12 @@ AVTBOXLIBFILEFORMAT::ReadHeader(void) for (levI = 0; levI < nLevels; levI++) { in >> double_tmp; - deltaX.push_back(atof(double_tmp.c_str())); + deltaX.push_back(vstrtonum(double_tmp.c_str())); in >> double_tmp; - deltaY.push_back(atof(double_tmp.c_str())); + deltaY.push_back(vstrtonum(double_tmp.c_str())); #if BL_SPACEDIM==3 in >> double_tmp; - deltaZ.push_back(atof(double_tmp.c_str())); + deltaZ.push_back(vstrtonum(double_tmp.c_str())); #endif } } @@ -997,7 +1004,7 @@ AVTBOXLIBFILEFORMAT::ReadHeader(void) // Read in the time (again) in >> double_tmp; - //time = atof(double_tmp.c_str()); + //time = vstrtonum(double_tmp.c_str()); // Read in iLevelSteps in >> integer; @@ -1006,18 +1013,18 @@ AVTBOXLIBFILEFORMAT::ReadHeader(void) for (i = 0; i < myNPatch; ++i) { in >> double_tmp; - xMin.push_back(atof(double_tmp.c_str())); + xMin.push_back(vstrtonum(double_tmp.c_str())); in >> double_tmp; - xMax.push_back(atof(double_tmp.c_str())); + xMax.push_back(vstrtonum(double_tmp.c_str())); in >> double_tmp; - yMin.push_back(atof(double_tmp.c_str())); + yMin.push_back(vstrtonum(double_tmp.c_str())); in >> double_tmp; - yMax.push_back(atof(double_tmp.c_str())); + yMax.push_back(vstrtonum(double_tmp.c_str())); #if BL_SPACEDIM==3 in >> double_tmp; - zMin.push_back(atof(double_tmp.c_str())); + zMin.push_back(vstrtonum(double_tmp.c_str())); in >> double_tmp; - zMax.push_back(atof(double_tmp.c_str())); + zMax.push_back(vstrtonum(double_tmp.c_str())); #endif } diff --git a/src/databases/CGNS/CGNSCommonPluginInfo.C b/src/databases/CGNS/CGNSCommonPluginInfo.C index 40cccef56e..6d6c9712ec 100644 --- a/src/databases/CGNS/CGNSCommonPluginInfo.C +++ b/src/databases/CGNS/CGNSCommonPluginInfo.C @@ -11,6 +11,9 @@ #include #include #include +#include +using StringHelpers::vstrtonum; +using StringHelpers::NO_OSTREAM; // **************************************************************************** // Method: CGNSCommonPluginInfo constructor @@ -103,7 +106,7 @@ CGNSCommonPluginInfo::SetupDatabase(const char *const *list, break; } char *str2; - long int nBlocks = strtol(&str[5], &str2, 10); + long int nBlocks = vstrtonum(&str[5],10,LONG_MAX,NO_OSTREAM,&str2); if (nBlocks == 0 || nBlocks == LONG_MAX || nBlocks == LONG_MIN || nBlocks < 0 || nBlocks > nList || @@ -119,7 +122,7 @@ CGNSCommonPluginInfo::SetupDatabase(const char *const *list, break; } char *str3; - long int iBlock = strtol(&str2[1], &str3, 10); + long int iBlock = vstrtonum(&str2[1],10,LONG_MAX,NO_OSTREAM,&str3); if (iBlock == LONG_MAX || iBlock == LONG_MIN || iBlock < 0 || iBlock >= nBlocks || iBlock != f % nBlocks || str3[0] != '\0') diff --git a/src/databases/CTRL/avtCTRLFileFormat.C b/src/databases/CTRL/avtCTRLFileFormat.C index 42fdb318d4..73cd98b5d3 100644 --- a/src/databases/CTRL/avtCTRLFileFormat.C +++ b/src/databases/CTRL/avtCTRLFileFormat.C @@ -22,6 +22,8 @@ #include #include +#include +using StringHelpers::vstrtonum; #include @@ -306,25 +308,25 @@ avtCTRLFileFormat::ReadAllMetaData() string n = s.substr(10,4); if (n == "ALAT") { - alat = atof(s.substr(15).c_str()); + alat = vstrtonum(s.substr(15).c_str()); } else if (n == "PLAT") { - unitCell[0][0] = alat*atof(s.substr(15,10).c_str()); - unitCell[0][1] = alat*atof(s.substr(26,10).c_str()); - unitCell[0][2] = alat*atof(s.substr(37,10).c_str()); + unitCell[0][0] = alat*vstrtonum(s.substr(15,10).c_str()); + unitCell[0][1] = alat*vstrtonum(s.substr(26,10).c_str()); + unitCell[0][2] = alat*vstrtonum(s.substr(37,10).c_str()); in.getline(line, 132); s = line; - unitCell[1][0] = alat*atof(s.substr(15,10).c_str()); - unitCell[1][1] = alat*atof(s.substr(26,10).c_str()); - unitCell[1][2] = alat*atof(s.substr(37,10).c_str()); + unitCell[1][0] = alat*vstrtonum(s.substr(15,10).c_str()); + unitCell[1][1] = alat*vstrtonum(s.substr(26,10).c_str()); + unitCell[1][2] = alat*vstrtonum(s.substr(37,10).c_str()); in.getline(line, 132); s = line; - unitCell[2][0] = alat*atof(s.substr(15,10).c_str()); - unitCell[2][1] = alat*atof(s.substr(26,10).c_str()); - unitCell[2][2] = alat*atof(s.substr(37,10).c_str()); + unitCell[2][0] = alat*vstrtonum(s.substr(15,10).c_str()); + unitCell[2][1] = alat*vstrtonum(s.substr(26,10).c_str()); + unitCell[2][2] = alat*vstrtonum(s.substr(37,10).c_str()); } in.getline(line, 132); @@ -373,8 +375,8 @@ avtCTRLFileFormat::ReadAtoms() string s(line); string e = s.substr(15,2); string z = s.substr(20,2); - cerr << "'"< '"< '"<(z.c_str())<<"'\n"; + atommap[e] = vstrtonum(z.c_str()); in.getline(line, 132); if (line[0] != ' ') @@ -406,9 +408,9 @@ avtCTRLFileFormat::ReadAtoms() a.element[0] = e[0]; a.element[1] = e[1]; a.element[2] = '\0'; - a.x = atof(x.c_str()) * alat; - a.y = atof(y.c_str()) * alat; - a.z = atof(z.c_str()) * alat; + a.x = vstrtonum(x.c_str()) * alat; + a.y = vstrtonum(y.c_str()) * alat; + a.z = vstrtonum(z.c_str()) * alat; atoms.push_back(a); } diff --git a/src/databases/Cale/avtCaleFileFormat.C b/src/databases/Cale/avtCaleFileFormat.C index 2c65c016ec..380b269012 100644 --- a/src/databases/Cale/avtCaleFileFormat.C +++ b/src/databases/Cale/avtCaleFileFormat.C @@ -34,6 +34,8 @@ #include #include +#include +using StringHelpers::vstrtonum; #include #include @@ -1433,7 +1435,7 @@ avtCaleFileFormat::GetCycleFromFilename(const char *f) const cycstr = static_cast(malloc(j+1*sizeof(char))); cycstr[j] = '\0'; strncpy(cycstr,f+i+1,j); - c = atoi(cycstr); + c = vstrtonum(cycstr); debug4 << " cycle from name " << cycstr << endl; free(cycstr); } diff --git a/src/databases/CaleHDF5/avtCaleHDF5FileFormat.C b/src/databases/CaleHDF5/avtCaleHDF5FileFormat.C index dd1d731175..db52dc6658 100644 --- a/src/databases/CaleHDF5/avtCaleHDF5FileFormat.C +++ b/src/databases/CaleHDF5/avtCaleHDF5FileFormat.C @@ -34,6 +34,11 @@ #include #include +using DebugStream::Level4; +using DebugStream::Stream4; +#include +using StringHelpers::vstrtonum; +using StringHelpers::NO_OSTREAM; #include #include @@ -1542,6 +1547,9 @@ avtCaleHDF5FileFormat::GetCycle(void) // // Purpose: Return the cycle associated with this file // +// Modifications: +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // *************************************************************************** int @@ -1576,7 +1584,7 @@ avtCaleHDF5FileFormat::GetCycleFromFilename(const char *f) const if (j > 0) { strncpy(cycstr,f+i+1,j); - c = atoi(cycstr); + c = vstrtonum(cycstr,10,0,Level4()?Stream4():NO_OSTREAM); } else { diff --git a/src/databases/CarpetHDF5/avtCarpetHDF5FileFormat.C b/src/databases/CarpetHDF5/avtCarpetHDF5FileFormat.C index e432646929..5d07d4b777 100644 --- a/src/databases/CarpetHDF5/avtCarpetHDF5FileFormat.C +++ b/src/databases/CarpetHDF5/avtCarpetHDF5FileFormat.C @@ -36,6 +36,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; #include #include @@ -1168,7 +1170,7 @@ static herr_t H5iter(hid_t group_id, const char *member_name, void *operator_dat int map = 0; if (strstr(member_name, "m=")) { - map = atoi(strstr(member_name, "m=")+2); + map = vstrtonum(strstr(member_name, "m=")+2); } // find out scalar type of variable diff --git a/src/databases/Chombo/avtChomboFileFormat.C b/src/databases/Chombo/avtChomboFileFormat.C index b818c13863..f42e1b014d 100644 --- a/src/databases/Chombo/avtChomboFileFormat.C +++ b/src/databases/Chombo/avtChomboFileFormat.C @@ -46,6 +46,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; #include #include #include @@ -416,6 +418,8 @@ static hid_t OpenHDF5File(char const *fname) // Mark C. Miller, Wed Feb 9 13:37:12 PST 2022 // Use new method, OpenHDF5File, to open the file. // +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum void avtChomboFileFormat::InitializeReader(void) { @@ -1376,7 +1380,7 @@ avtChomboFileFormat::InitializeReader(void) { if (varnames[i].find("fraction-") == 0) { - int val = atoi(varnames[i].c_str()+9) + 1; + int val = vstrtonum(varnames[i].c_str()+9) + 1; if (val > nMaterials) nMaterials = val; diff --git a/src/databases/Claw/avtClawFileFormat.C b/src/databases/Claw/avtClawFileFormat.C index 73bacc368f..7f429092a7 100644 --- a/src/databases/Claw/avtClawFileFormat.C +++ b/src/databases/Claw/avtClawFileFormat.C @@ -21,6 +21,8 @@ #include #include #include +using StringHelpers::vstrtonum; +using StringHelpers::NO_OSTREAM; #include #include @@ -1302,7 +1304,7 @@ avtClawFileFormat::GetVar(int timeState, int domain, const char *varname) // convert this column's value to float char *bufptmp = 0; errno = 0; - float val = (float) strtod(bufp, &bufptmp); + float val = (float) vstrtonum(bufp,10,0,NO_OSTREAM,&bufptmp); if (((val == 0.0) && (bufp == bufptmp)) || (errno != 0)) { char msg[256]; diff --git a/src/databases/CosmosPP/avtCosmosPPFileFormat.C b/src/databases/CosmosPP/avtCosmosPPFileFormat.C index 76260ff02f..177d3897a2 100644 --- a/src/databases/CosmosPP/avtCosmosPPFileFormat.C +++ b/src/databases/CosmosPP/avtCosmosPPFileFormat.C @@ -37,6 +37,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; #include #include @@ -61,6 +63,9 @@ typedef struct // Programmer: panninos -- generated by xml2avt // Creation: Wed Mar 16 09:14:06 PDT 2016 // +// Modifications: +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // **************************************************************************** avtCosmosPPFileFormat::avtCosmosPPFileFormat(const char *fname) @@ -122,11 +127,11 @@ avtCosmosPPFileFormat::avtCosmosPPFileFormat(const char *fname) string c; ReadString(ifile, c); - cycles[i] = atoi(c.c_str()); + cycles[i] = vstrtonum(c.c_str()); string t; ReadString(ifile, t); - times[i] = atof(t.c_str()); + times[i] = vstrtonum(t.c_str()); string tmp; ReadString(ifile, tmp); @@ -148,11 +153,11 @@ avtCosmosPPFileFormat::avtCosmosPPFileFormat(const char *fname) string c; ReadString(ifile, c); - cycles[i] = atoi(c.c_str()); + cycles[i] = vstrtonum(c.c_str()); string t; ReadString(ifile, t); - times[i] = atof(t.c_str()); + times[i] = vstrtonum(t.c_str()); string tmp; ReadString(ifile, tmp); diff --git a/src/databases/Cube/CubeReader.C b/src/databases/Cube/CubeReader.C index ebdf02aea8..fd669353d9 100644 --- a/src/databases/Cube/CubeReader.C +++ b/src/databases/Cube/CubeReader.C @@ -10,6 +10,8 @@ #include #include +#include +using StringHelpers::vstrtonum; #include #include @@ -141,10 +143,10 @@ CubeReader::readMetaData(bool keepFileOpen) copy(istream_iterator(iss), istream_iterator(), back_inserter >(tokens)); if(tokens.size() >= 4) { - natoms = atoi(tokens[0].c_str()); - x_origin = atof(tokens[1].c_str()); - y_origin = atof(tokens[2].c_str()); - z_origin = atof(tokens[3].c_str()); + natoms = vstrtonum(tokens[0].c_str()); + x_origin = vstrtonum(tokens[1].c_str()); + y_origin = vstrtonum(tokens[2].c_str()); + z_origin = vstrtonum(tokens[3].c_str()); } else { @@ -176,10 +178,10 @@ CubeReader::readMetaData(bool keepFileOpen) copy(istream_iterator(iss), istream_iterator(), back_inserter >(tokens)); if(tokens.size() >= 4) { - x_size = atoi(tokens[0].c_str()); - dx[0] = atof(tokens[1].c_str()); - dx[1] = atof(tokens[2].c_str()); - dx[2] = atof(tokens[3].c_str()); + x_size = vstrtonum(tokens[0].c_str()); + dx[0] = vstrtonum(tokens[1].c_str()); + dx[1] = vstrtonum(tokens[2].c_str()); + dx[2] = vstrtonum(tokens[3].c_str()); } else { @@ -204,10 +206,10 @@ CubeReader::readMetaData(bool keepFileOpen) copy(istream_iterator(iss), istream_iterator(), back_inserter >(tokens)); if(tokens.size() >= 4) { - y_size = atoi(tokens[0].c_str()); - dy[0] = atof(tokens[1].c_str()); - dy[1] = atof(tokens[2].c_str()); - dy[2] = atof(tokens[3].c_str()); + y_size = vstrtonum(tokens[0].c_str()); + dy[0] = vstrtonum(tokens[1].c_str()); + dy[1] = vstrtonum(tokens[2].c_str()); + dy[2] = vstrtonum(tokens[3].c_str()); } else { @@ -231,10 +233,10 @@ CubeReader::readMetaData(bool keepFileOpen) copy(istream_iterator(iss), istream_iterator(), back_inserter >(tokens)); if(tokens.size() >= 4) { - z_size = atoi(tokens[0].c_str()); - dz[0] = atof(tokens[1].c_str()); - dz[1] = atof(tokens[2].c_str()); - dz[2] = atof(tokens[3].c_str()); + z_size = vstrtonum(tokens[0].c_str()); + dz[0] = vstrtonum(tokens[1].c_str()); + dz[1] = vstrtonum(tokens[2].c_str()); + dz[2] = vstrtonum(tokens[3].c_str()); } else { @@ -275,11 +277,11 @@ CubeReader::readMetaData(bool keepFileOpen) copy(istream_iterator(iss), istream_iterator(), back_inserter >(tokens)); if(tokens.size() >= 5) { - atom_types.push_back(atoi(tokens[0].c_str())); - //isotope = atof( tokens[1].c_str() ); - atom_locations.push_back(atof(tokens[2].c_str())); - atom_locations.push_back(atof(tokens[3].c_str())); - atom_locations.push_back(atof(tokens[4].c_str())); + atom_types.push_back(vstrtonum(tokens[0].c_str())); + //isotope = vstrtonum( tokens[1].c_str() ); + atom_locations.push_back(vstrtonum(tokens[2].c_str())); + atom_locations.push_back(vstrtonum(tokens[3].c_str())); + atom_locations.push_back(vstrtonum(tokens[4].c_str())); } else { @@ -309,7 +311,7 @@ CubeReader::readMetaData(bool keepFileOpen) } if(!tokens.empty()) { - int norbitals = atoi(tokens[0].c_str()); + int norbitals = vstrtonum(tokens[0].c_str()); if(tokens.size() < (norbitals+1)) { errorString = "Cube reader: Number of orbitals does not match the number of orbitals given."; @@ -320,7 +322,7 @@ CubeReader::readMetaData(bool keepFileOpen) debug4 << "Found " << norbitals << " orbitals" << endl; for (int o = 1; o <= norbitals; o++) { - orbitals.push_back(atoi(tokens[o].c_str())); + orbitals.push_back(vstrtonum(tokens[o].c_str())); debug4 << " "<< orbitals[o-1] << endl; } } @@ -490,7 +492,7 @@ CubeReader::GetOrbitalValues(float* vals, const char* varname) string keyword = "orbital_"; string num_str = var.substr(keyword.length(), var.length()-keyword.length()); debug4 << "num_str = " << num_str; - int orbital_num = atoi(num_str.c_str()); + int orbital_num = vstrtonum(num_str.c_str()); debug4 << "determined target orbital_num to be " << orbital_num << endl; int index = -1; diff --git a/src/databases/Curve2D/avtCurve2DFileFormat.C b/src/databases/Curve2D/avtCurve2DFileFormat.C index 04772ed1ec..03f28852b5 100644 --- a/src/databases/Curve2D/avtCurve2DFileFormat.C +++ b/src/databases/Curve2D/avtCurve2DFileFormat.C @@ -22,6 +22,8 @@ #include #include #include +using StringHelpers::vstrtonum; +using StringHelpers::NO_OSTREAM; #include #include @@ -30,6 +32,7 @@ #include #include #include +#include using std::vector; using std::string; @@ -293,6 +296,9 @@ avtCurve2DFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md) // // Justin Privitera, Tue Jul 5 14:40:55 PDT 2022 // Changed 'supressed' to 'suppressed'. +// +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // **************************************************************************** #define INVALID_POINT_WARNING(X) \ @@ -402,10 +408,7 @@ avtCurve2DFileFormat::ReadFile(void) if ( timePos != string::npos) { string tStr = headerName.substr(timePos+4); - char *endstr = NULL; - curveTime = strtod(tStr.c_str(), &endstr); - if (strcmp(endstr, tStr.c_str()) == 0) - curveTime = INVALID_TIME; + curveTime = vstrtonum(tStr.c_str(),10,INVALID_TIME); } else { @@ -413,10 +416,7 @@ avtCurve2DFileFormat::ReadFile(void) if ( cyclePos != string::npos) { string cyStr = headerName.substr(cyclePos+5); - char *endstr = NULL; - curveCycle = (int)strtod(cyStr.c_str(), &endstr); - if (strcmp(endstr, cyStr.c_str()) == 0) - curveCycle = INVALID_CYCLE; + curveCycle = vstrtonum(cyStr.c_str(),10,INVALID_CYCLE); } } } @@ -484,10 +484,7 @@ avtCurve2DFileFormat::ReadFile(void) if ( timePos != string::npos) { string tStr = headerName.substr(timePos+4); - char *endstr = NULL; - curveTime = strtod(tStr.c_str(), &endstr); - if (strcmp(endstr, tStr.c_str()) == 0) - curveTime = INVALID_TIME; + curveTime = vstrtonum(tStr.c_str(),10,INVALID_TIME); } else { @@ -495,10 +492,7 @@ avtCurve2DFileFormat::ReadFile(void) if ( cyclePos != string::npos) { string cyStr = headerName.substr(cyclePos+5); - char *endstr = NULL; - curveCycle = (int)strtod(cyStr.c_str(), &endstr); - if (strcmp(endstr, cyStr.c_str()) == 0) - curveCycle = INVALID_CYCLE; + curveCycle = vstrtonum(cyStr.c_str(),10,INVALID_CYCLE); } } } @@ -715,17 +709,11 @@ avtCurve2DFileFormat::GetPoint(istream &ifile, double &x, double &y, string &ln) } char *ystr = NULL; - - errno = 0; - x = strtod(line, &ystr); - if (((x == 0.0) && (ystr == line)) || (errno == ERANGE)) + x = vstrtonum(line,10,NAN,NO_OSTREAM,&ystr); + if (std::isnan(x)) { return INVALID_POINT; } - if (ystr == NULL) - { - return VALID_XVALUE; - } ystr = strstr(ystr, " "); if (ystr == NULL || ystr == line) { @@ -735,10 +723,8 @@ avtCurve2DFileFormat::GetPoint(istream &ifile, double &x, double &y, string &ln) // Get past the space. ystr++; - char *tmpstr; - errno = 0; - y = strtod(ystr, &tmpstr); - if (((y == 0.0) && (tmpstr == ystr)) || (errno == ERANGE)) + y = vstrtonum(ystr,10,NAN); + if (std::isnan(y)) { return INVALID_POINT; } diff --git a/src/databases/Curve3D/avtCurve3DFileFormat.C b/src/databases/Curve3D/avtCurve3DFileFormat.C index 8e5a258cc3..3ed30027fd 100644 --- a/src/databases/Curve3D/avtCurve3DFileFormat.C +++ b/src/databases/Curve3D/avtCurve3DFileFormat.C @@ -37,12 +37,13 @@ #include #include #include +using StringHelpers::vstrtonum; +using StringHelpers::NO_OSTREAM; #include #include #include "visit_gzstream.h" -#include #include #include @@ -300,6 +301,9 @@ avtCurve3DFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md) // Copied from Curve2D plugin as of Jul 5, 2022 and adjusted for 3D // and make a global mesh with materials out of the figures. // +// Modifications: +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // **************************************************************************** #define INVALID_POINT_WARNING(X) \ @@ -445,9 +449,7 @@ avtCurve3DFileFormat::ReadFile(bool clearData = false) { string tStr = headerName.substr(timePos+4); char *endstr = NULL; - curveTime = strtod(tStr.c_str(), &endstr); - if (strcmp(endstr, tStr.c_str()) == 0) - curveTime = INVALID_TIME; + curveTime = vstrtonum(tStr.c_str(),10,INVALID_TIME); } else { @@ -456,9 +458,7 @@ avtCurve3DFileFormat::ReadFile(bool clearData = false) { string cyStr = headerName.substr(cyclePos+5); char *endstr = NULL; - curveCycle = (int)strtod(cyStr.c_str(), &endstr); - if (strcmp(endstr, cyStr.c_str()) == 0) - curveCycle = INVALID_CYCLE; + curveCycle = vstrtonum(cyStr.c_str(),10,INVALID_CYCLE); } } } @@ -563,9 +563,7 @@ avtCurve3DFileFormat::ReadFile(bool clearData = false) { string tStr = headerName.substr(timePos+4); char *endstr = NULL; - curveTime = strtod(tStr.c_str(), &endstr); - if (strcmp(endstr, tStr.c_str()) == 0) - curveTime = INVALID_TIME; + curveTime = vstrtonum(tStr.c_str(),10,INVALID_TIME); } else { @@ -574,9 +572,7 @@ avtCurve3DFileFormat::ReadFile(bool clearData = false) { string cyStr = headerName.substr(cyclePos+5); char *endstr = NULL; - curveCycle = (int)strtod(cyStr.c_str(), &endstr); - if (strcmp(endstr, cyStr.c_str()) == 0) - curveCycle = INVALID_CYCLE; + curveCycle = vstrtonum(cyStr.c_str(),10,INVALID_CYCLE); } } } @@ -748,6 +744,9 @@ avtCurve3DFileFormat::ReadFile(bool clearData = false) // Copied from Curve2D plugin as of Aug 31, 2018 and adjusted for 3D // and make a global mesh with materials out of the figures. // +// Modifications: +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // **************************************************************************** Curve3DToken @@ -820,9 +819,8 @@ avtCurve3DFileFormat::GetPoint(istream &ifile, double &x, double &y, double &z, char *ystr = NULL; char *tmpstr; - errno = 0; - x = strtod(line, &ystr); - if (((x == 0.0) && (ystr == line)) || (errno == ERANGE)) + x = vstrtonum(line,10,0,NO_OSTREAM,&ystr); + if ((x == 0.0) && (ystr == line)) { return INVALID_POINT; } @@ -839,9 +837,8 @@ avtCurve3DFileFormat::GetPoint(istream &ifile, double &x, double &y, double &z, // Get past the space. ystr++; - errno = 0; - y = strtod(ystr, &tmpstr); - if (((y == 0.0) && (tmpstr == ystr)) || (errno == ERANGE)) + y = vstrtonum(ystr,10,0,NO_OSTREAM,&tmpstr); + if ((y == 0.0) && (tmpstr == ystr)) { return INVALID_POINT; } @@ -858,9 +855,8 @@ avtCurve3DFileFormat::GetPoint(istream &ifile, double &x, double &y, double &z, // Get past the space. ystr++; - errno = 0; - z = strtod(ystr, &tmpstr); - if (((z == 0.0) && (tmpstr == ystr)) || (errno == ERANGE)) + z = vstrtonum(ystr,10,0,NO_OSTREAM,&tmpstr); + if ((z == 0.0) && (tmpstr == ystr)) { return INVALID_POINT; } diff --git a/src/databases/EnSight/avtEnSightFileFormat.C b/src/databases/EnSight/avtEnSightFileFormat.C index 3f2d251365..c724eb84b7 100644 --- a/src/databases/EnSight/avtEnSightFileFormat.C +++ b/src/databases/EnSight/avtEnSightFileFormat.C @@ -40,6 +40,7 @@ #include #include #include +using StringHelpers::vstrtonum; using std::vector; @@ -170,7 +171,7 @@ avtEnSightFileFormat::InstantiateReader(const char *fname_c) if(line.find("filename start number:") != std::string::npos) { std::string fileStart = line.substr(line.find(":")+1); - geomFileNameStart = atoi(fileStart.c_str()); + geomFileNameStart = vstrtonum(fileStart.c_str()); } } diff --git a/src/databases/Enzo/avtEnzoFileFormat.C b/src/databases/Enzo/avtEnzoFileFormat.C index d096d8f70e..4eb114dc52 100644 --- a/src/databases/Enzo/avtEnzoFileFormat.C +++ b/src/databases/Enzo/avtEnzoFileFormat.C @@ -31,6 +31,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; // Define this symbol BEFORE including hdf5.h to indicate the HDF5 code // in this file uses version 1.6 of the HDF5 API. This is harmless for @@ -381,7 +383,7 @@ avtEnzoFileFormat::ReadHierachyFile() buff = ""; while ((c=h.get()) != '['); while ((c=h.get()) != ']') buff += c; - int gridID = atoi(buff.c_str()); + int gridID = vstrtonum(buff.c_str()); h.get(); // - h.get(); // > h >> buff; @@ -844,7 +846,7 @@ int avtEnzoFileFormat::GetCycleFromFilename(const char *cfilename) const if (f.length() > 4) f = f.substr(f.length() - 4); - return atoi(f.c_str()); + return vstrtonum(f.c_str()); } // **************************************************************************** diff --git a/src/databases/ExtrudedVol/avtExtrudedVolFileFormat.C b/src/databases/ExtrudedVol/avtExtrudedVolFileFormat.C index 69aeb236cb..198e689a15 100644 --- a/src/databases/ExtrudedVol/avtExtrudedVolFileFormat.C +++ b/src/databases/ExtrudedVol/avtExtrudedVolFileFormat.C @@ -21,6 +21,8 @@ #include #include +#include +using StringHelpers::vstrtonum; #include #include @@ -53,7 +55,7 @@ avtExtrudedVolFileFormat::avtExtrudedVolFileFormat(const char *filename, const D ifile >> tmp; // "NUMCHUNKS: "; ifile >> tmp; - numChunks = atoi(tmp.c_str()); + numChunks = vstrtonum(tmp.c_str()); if (numChunks <= 0) { EXCEPTION1(VisItException, "This does not appear to be a valid " @@ -62,7 +64,7 @@ avtExtrudedVolFileFormat::avtExtrudedVolFileFormat(const char *filename, const D ifile >> tmp; // "NTIMES: "; ifile >> tmp; - nTimesteps = atoi(tmp.c_str()); + nTimesteps = vstrtonum(tmp.c_str()); if (nTimesteps <= 0) { EXCEPTION1(VisItException, "This does not appear to be a valid " @@ -71,7 +73,7 @@ avtExtrudedVolFileFormat::avtExtrudedVolFileFormat(const char *filename, const D ifile >> tmp; // "VARIABLES: "; ifile >> tmp; - int nVars = atoi(tmp.c_str()); + int nVars = vstrtonum(tmp.c_str()); if (nVars <= 0) { EXCEPTION1(VisItException, "This does not appear to be a valid " diff --git a/src/databases/Fluent/avtFluentFileFormat.C b/src/databases/Fluent/avtFluentFileFormat.C index c17dac2d45..f720aa7097 100644 --- a/src/databases/Fluent/avtFluentFileFormat.C +++ b/src/databases/Fluent/avtFluentFileFormat.C @@ -18,6 +18,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; @@ -450,7 +452,7 @@ int avtFluentFileFormat::GetCaseIndex() { sindex.push_back(CaseBuffer.at(i++)); } - return atoi(sindex.c_str()); + return vstrtonum(sindex.c_str()); } //---------------------------------------------------------------------------- @@ -493,7 +495,7 @@ int avtFluentFileFormat::GetDataIndex() { sindex.push_back(DataBuffer.at(i++)); } - return atoi(sindex.c_str()); + return vstrtonum(sindex.c_str()); } //---------------------------------------------------------------------------- @@ -2278,7 +2280,7 @@ int avtFluentFileFormat::GetDimension() int start = CaseBuffer.find('(', 1); //int end = CaseBuffer.find(')',1); string info = CaseBuffer.substr(start+4, 1 ); - return atoi(info.c_str()); + return vstrtonum(info.c_str()); } //---------------------------------------------------------------------------- diff --git a/src/databases/Geqdsk/avtGeqdskFileFormat.C b/src/databases/Geqdsk/avtGeqdskFileFormat.C index d20026f26e..4346784d5c 100644 --- a/src/databases/Geqdsk/avtGeqdskFileFormat.C +++ b/src/databases/Geqdsk/avtGeqdskFileFormat.C @@ -33,6 +33,8 @@ #include #include +#include +using StringHelpers::vstrtonum; using std::string; @@ -73,11 +75,11 @@ avtGeqdskFileFormat::avtGeqdskFileFormat(const char *filename, const DBOptionsAt // Strip off the last three int and convert them to ints. strncpy(tmpInt, &(tmp[48]), 4 ); - //idum = atoi( tmpInt ); + //idum = vstrtonum( tmpInt ); strncpy(tmpInt, &(tmp[52]), 4 ); - nw = atoi( tmpInt ); + nw = vstrtonum( tmpInt ); strncpy(tmpInt, &(tmp[56]), 4 ); - nh = atoi( tmpInt ); + nh = vstrtonum( tmpInt ); if( nw < 0 || nh < 0 ) { @@ -95,12 +97,12 @@ avtGeqdskFileFormat::avtGeqdskFileFormat(const char *filename, const DBOptionsAt sscanf( tmp, "%s %s %s %s", id, date, run, time ) == 4 ) { cycles.resize( 1 ); - cycles[0] = atoi( time ); + cycles[0] = vstrtonum( time ); std::string timeStr(time); times.resize( 1 ); - times[0] = atof( time ); + times[0] = vstrtonum( time ); if( timeStr.find("ms") != std::string::npos ) times[0] *= 1.0e-3; @@ -114,10 +116,10 @@ avtGeqdskFileFormat::avtGeqdskFileFormat(const char *filename, const DBOptionsAt id, date, run, time ) == 4 ) { cycles.resize( 1 ); - cycles[0] = (int) (atof( time ) * 1000.0); + cycles[0] = (int) (vstrtonum( time ) * 1000.0); times.resize( 1 ); - times[0] = atof( time ); + times[0] = vstrtonum( time ); n = 7; } diff --git a/src/databases/H5Nimrod/avtH5NimrodFileFormat.C b/src/databases/H5Nimrod/avtH5NimrodFileFormat.C index 7a20af67a4..b9e0e27a9c 100644 --- a/src/databases/H5Nimrod/avtH5NimrodFileFormat.C +++ b/src/databases/H5Nimrod/avtH5NimrodFileFormat.C @@ -28,6 +28,8 @@ #include #include +#include +using StringHelpers::vstrtonum; #include @@ -234,7 +236,7 @@ avtH5NimrodFileFormat::avtH5NimrodFileFormat (const char *filename): EXCEPTION1( InvalidVariableException, "H5NIMROD Read Attribute - 'Step number' was not found or wrong type" ); } - cycles.push_back( atoi(stepnumber) ); + cycles.push_back( vstrtonum(stepnumber) ); debug5 << "step number: " << stepnumber << std::endl; diff --git a/src/databases/IDX/pidx_idx_io.C b/src/databases/IDX/pidx_idx_io.C index 7e0b742aa3..9d900ffd09 100644 --- a/src/databases/IDX/pidx_idx_io.C +++ b/src/databases/IDX/pidx_idx_io.C @@ -184,7 +184,7 @@ bool PIDXIO::openDataset(const String filename) VisitIDXIO::Field my_field; - my_field.ncomponents = variable[var]->vps;//atoi((const char*)(variable[var]->type_name)); + my_field.ncomponents = variable[var]->vps; char typetocheck[32]; strncpy(typetocheck, variable[var]->type_name, 32); if(isdigit(typetocheck[0])) diff --git a/src/databases/Image/avtImageFileFormat.C b/src/databases/Image/avtImageFileFormat.C index 9a188b3ae5..264e419657 100644 --- a/src/databases/Image/avtImageFileFormat.C +++ b/src/databases/Image/avtImageFileFormat.C @@ -43,6 +43,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; #define EXPOSE_DEPTH #ifdef EXPOSE_DEPTH @@ -274,12 +276,12 @@ avtImageFileFormat::ReadImageVolumeHeader(void) continue; if (strncmp(line, "Z_START:", strlen("Z_START:")) == 0) { - zStart = atof(line + strlen("Z_START:")); + zStart = vstrtonum(line + strlen("Z_START:")); specifiedZStart = true; } else if (strncmp(line, "Z_STEP:", strlen("Z_STEP:")) == 0) { - zStep = atof(line + strlen("Z_STEP:")); + zStep = vstrtonum(line + strlen("Z_STEP:")); specifiedZStep = true; } else diff --git a/src/databases/Image/vtkStimulateReader.C b/src/databases/Image/vtkStimulateReader.C index f5caa54bcd..fda4a9acd0 100644 --- a/src/databases/Image/vtkStimulateReader.C +++ b/src/databases/Image/vtkStimulateReader.C @@ -13,6 +13,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; #include @@ -239,7 +241,7 @@ bool vtkStimulateReader::ReadSPRFile(const char *spr_name) char line[1024]; spr_file.getline(line, 1024); - int ndims = atoi(line); + int ndims = vstrtonum(line); if (ndims != 2) { vtkErrorMacro(<<"Unable to read SPR file, ndims = " << ndims @@ -248,7 +250,7 @@ bool vtkStimulateReader::ReadSPRFile(const char *spr_name) } spr_file.getline(line, 1024); - dims[0] = atoi(line); + dims[0] = vstrtonum(line); if (dims[0] < 0) { vtkErrorMacro(<<"Unable to read SPR file, dims[0] = " << dims[0] @@ -257,9 +259,9 @@ bool vtkStimulateReader::ReadSPRFile(const char *spr_name) } spr_file.getline(line, 1024); - origin[0] = atof(line); + origin[0] = vstrtonum(line); spr_file.getline(line, 1024); - step[0] = atof(line); + step[0] = vstrtonum(line); if (step[0] < 0.) { vtkErrorMacro(<<"Unable to read SPR file step in X is negative"); @@ -267,7 +269,7 @@ bool vtkStimulateReader::ReadSPRFile(const char *spr_name) } spr_file.getline(line, 1024); - dims[1] = atoi(line); + dims[1] = vstrtonum(line); if (dims[1] < 0) { vtkErrorMacro(<<"Unable to read SPR file, dims[1] = " << dims[1] @@ -276,9 +278,9 @@ bool vtkStimulateReader::ReadSPRFile(const char *spr_name) } spr_file.getline(line, 1024); - origin[1] = atof(line); + origin[1] = vstrtonum(line); spr_file.getline(line, 1024); - step[1] = atof(line); + step[1] = vstrtonum(line); if (step[1] < 0.) { vtkErrorMacro(<<"Unable to read SPR file step in Y is negative"); diff --git a/src/databases/MFEM/avtMFEMFileFormat.C b/src/databases/MFEM/avtMFEMFileFormat.C index 99739bd9bd..a6b1eb753f 100644 --- a/src/databases/MFEM/avtMFEMFileFormat.C +++ b/src/databases/MFEM/avtMFEMFileFormat.C @@ -20,6 +20,7 @@ #include #include #include +using StringHelpers::vstrtonum; #include #include @@ -33,18 +34,6 @@ #include - -#ifdef _WIN32 -#define strncasecmp _strnicmp -static unsigned long long -v_strtoull(const char *__restrict str, char **__restrict endptr, int base) -{ - return (unsigned long long)strtoul(str, endptr, base); -} -#else -#define v_strtoull strtoull -#endif - using std::string; using std::ostringstream; using std::vector; @@ -160,7 +149,7 @@ avtMFEMFileFormat::BuildCatFileMap(string const &cat_path) string line; std::getline(catfile, line); - size_t hdrsz = (size_t) v_strtoull(&line[0], 0, 10); + size_t hdrsz = vstrtonum(&line[0]); size_t zip = strchr(&line[0], 'z')==0?(size_t)0:(size_t)1; catFileMap["@header_size@"] = std::pair(hdrsz,hdrsz); catFileMap["@compressed@"] = std::pair(zip,zip); @@ -172,8 +161,8 @@ avtMFEMFileFormat::BuildCatFileMap(string const &cat_path) std::getline(catfile, line); size_t offat = line.find_last_of(' '); size_t sizat = line.find_last_of(' ', offat-1); - size_t off = (size_t) v_strtoull(&line[offat+1], 0, 10); - size_t siz = (size_t) v_strtoull(&line[sizat+1], 0, 10); + size_t off = (size_t) vstrtonum(&line[offat+1]); + size_t siz = (size_t) vstrtonum(&line[sizat+1]); line.resize(sizat); debug5 << " key=\"" << line << "\", size=" << siz << ", off=" << off << endl; catFileMap[line] = std::pair(siz,off); @@ -313,8 +302,8 @@ avtMFEMFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md) { JSONRootDataSet &dset = root_md.DataSet(dset_names[i]); int nblocks = dset.NumberOfDomains(); - int spatial_dim = atoi(dset.Mesh().Tag("spatial_dim").c_str()); - int topo_dim = atoi(dset.Mesh().Tag("topo_dim").c_str()); + int spatial_dim = vstrtonum(dset.Mesh().Tag("spatial_dim").c_str()); + int topo_dim = vstrtonum(dset.Mesh().Tag("topo_dim").c_str()); int block_origin = 0; double *extents = NULL; @@ -329,7 +318,7 @@ avtMFEMFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md) block_origin, spatial_dim, topo_dim); - md->GetMeshes(i).LODs = atoi(dset.Mesh().Tag("max_lods").c_str()); + md->GetMeshes(i).LODs = vstrtonum(dset.Mesh().Tag("max_lods").c_str()); // Indicate that we're providing original cells. md->GetMeshes(i).containsOriginalCells = true; // Add builtin mfem fields related to the mesh: @@ -353,7 +342,7 @@ avtMFEMFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md) { JSONRootEntry &field = dset.Field(field_names[j]); std::string slod = field.Tag("lod"); - int ilod = std::min(md->GetMeshes(i).LODs,atoi(slod.c_str())); + int ilod = std::min(md->GetMeshes(i).LODs,vstrtonum(slod.c_str())); selectedLOD = std::max(selectedLOD,ilod); std::string f_assoc = field.Tag("assoc"); @@ -847,7 +836,7 @@ avtMFEMFileFormat::GetRefinedVar(const std::string &var_name, JSONRootEntry &field = root->DataSet(mesh_name).Field(var_name); string field_path = field.Path().Expand(domain); bool var_is_nodal = field.Tag("assoc") == "nodes"; - int ncomps = atoi(field.Tag("comps").c_str()); + int ncomps = vstrtonum(field.Tag("comps").c_str()); string cat_path = root->DataSet(mesh_name).CatPath().Get(); GridFunction *gf = 0; diff --git a/src/databases/MFIXCDF/avtMFIXCDFFileFormat.C b/src/databases/MFIXCDF/avtMFIXCDFFileFormat.C index 4358f81dbb..2c7335be79 100644 --- a/src/databases/MFIXCDF/avtMFIXCDFFileFormat.C +++ b/src/databases/MFIXCDF/avtMFIXCDFFileFormat.C @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -711,6 +712,10 @@ avtMFIXCDFFileFormat::GetAuxiliaryData(const char * var, // given a target number of domains. Unfortunately VisIt doesn't seem to // support this unless the number of domains is exactly PAR_Rank. I am // leaving it here out of optimism for the future. +// +// Modifications +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // void // avtMFIXCDFFileFormat::CalcDomainBreakdown2D(long targetDomains, // int cellsX, int cellsY, int* nX, int* nY) @@ -777,8 +782,8 @@ avtMFIXCDFFileFormat::inferVectorVariableNames(avtDatabaseMetaData *md, } else if (!strncmp(s.c_str(),"U_s_",4)) { - long index= strtol(s.c_str()+4, NULL, 10); - if (index==0 || index==LONG_MIN || index==LONG_MAX) + long index = StringHelpers::vstrtonum(s.c_str()+4, 10, 0); + if (index==0) EXCEPTION1(InvalidFilesException,filePath->c_str()); char buf[100]; snprintf(buf,sizeof(buf),"Vel_s_%03ld",index); diff --git a/src/databases/Miranda/avtMirandaFileFormat.C b/src/databases/Miranda/avtMirandaFileFormat.C index ba489bd803..277180e39d 100644 --- a/src/databases/Miranda/avtMirandaFileFormat.C +++ b/src/databases/Miranda/avtMirandaFileFormat.C @@ -37,6 +37,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; using std::string; using std::vector; @@ -631,7 +633,7 @@ avtMirandaFileFormat::GetFortranDouble( ifstream &f ) s[ii] = 'e'; } } - double r = atof(s.c_str()); + double r = vstrtonum(s.c_str()); return r; } diff --git a/src/databases/NASTRAN/avtNASTRANFileFormat.C b/src/databases/NASTRAN/avtNASTRANFileFormat.C index 34e2314d32..cc12d4f631 100644 --- a/src/databases/NASTRAN/avtNASTRANFileFormat.C +++ b/src/databases/NASTRAN/avtNASTRANFileFormat.C @@ -26,6 +26,9 @@ using namespace NASTRANDBOptions; #include #include #include +#include +using StringHelpers::vstrtonum; +using StringHelpers::NO_OSTREAM; #include // @@ -43,7 +46,6 @@ using namespace NASTRANDBOptions; #include #endif -#include #include #include #include @@ -222,18 +224,16 @@ static double GetVal(const char *s) if (i>0 && (t[i]=='-' || t[i]=='+') && strchr("0123456789",t[i-1])) t.insert(i, "E"); - errno = 0; - dval = strtod(t.c_str(), &endptr); + dval = vstrtonum(t.c_str(),10,0,NO_OSTREAM,&endptr); // Handle cases where conversion failed for one reason or another - if ((dval == 0 && endptr == t.c_str()) || errno) + if ((dval == 0 && endptr == t.c_str())) { static int nwarnings = 0; if (nwarnings <= 5) { char msg[512]; - snprintf(msg, sizeof(msg), "%s problem converting numerical value from \"%32s\"\n", - errno?strerror(errno):"", t.c_str()); + snprintf(msg, sizeof(msg), "problem converting numerical value from \"%32s\"\n", t.c_str()); if (!avtCallback::IssueWarning(msg)) { cerr << msg << endl; diff --git a/src/databases/OVERFLOW/avtOVERFLOWFileFormat.C b/src/databases/OVERFLOW/avtOVERFLOWFileFormat.C index 7ff4db306a..836a2a45ea 100644 --- a/src/databases/OVERFLOW/avtOVERFLOWFileFormat.C +++ b/src/databases/OVERFLOW/avtOVERFLOWFileFormat.C @@ -21,6 +21,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; #include #include @@ -732,7 +734,7 @@ avtOVERFLOWFileFormat::GetVar(int domain, const char *varname) EXCEPTION1(InvalidVariableException, varname); } - int varindex = atoi(&varname[1]) - 1; + int varindex = vstrtonum(&varname[1]) - 1; if (varindex < 0 || varindex >= nq) { EXCEPTION1(InvalidVariableException, varname); diff --git a/src/databases/OpenPMD/avtOpenPMDFileFormat.C b/src/databases/OpenPMD/avtOpenPMDFileFormat.C index f708818730..e89914ed21 100644 --- a/src/databases/OpenPMD/avtOpenPMDFileFormat.C +++ b/src/databases/OpenPMD/avtOpenPMDFileFormat.C @@ -32,6 +32,8 @@ #include #include +#include +using StringHelpers::vstrtonum; #include #include @@ -160,6 +162,8 @@ avtOpenPMDFileFormat::GetNTimesteps(void) // Programmer: mlobet -- generated by xml2avt // Creation: Tue Oct 18 11:49:37 PDT 2016 // +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // **************************************************************************** void avtOpenPMDFileFormat::GetCycles(std::vector &cycles) @@ -174,7 +178,7 @@ avtOpenPMDFileFormat::GetCycles(std::vector &cycles) for (std::vector::iterator it = iterations->begin() ; it != iterations->end(); ++it) { - cycle = atoi(it->name.c_str()); + cycle = vstrtonum(it->name.c_str()); // Store the cycles in the vector. cycles.push_back(cycle); diff --git a/src/databases/PATRAN/avtPATRANFileFormat.C b/src/databases/PATRAN/avtPATRANFileFormat.C index 1fb8ea1d11..da37419329 100644 --- a/src/databases/PATRAN/avtPATRANFileFormat.C +++ b/src/databases/PATRAN/avtPATRANFileFormat.C @@ -27,6 +27,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; #define PATRAN_PACKET_NODE_DATA 1 #define PATRAN_PACKET_ELEMENT_DATA 2 @@ -40,11 +42,6 @@ #define MAX_CELL_PROPERTIES 5 -//#define DEBUG_PRINT_HEADER -//#define DEBUG_PRINT_CELL_VERTS -//#define DEBUG_PRINT_NODES -//#define DEBUG_PRINT_MATERIAL_NAMES - #define VARNAME_ELEMENTIDS "elementIds" #define VARNAME_ELEMENTMATS "elementMats" @@ -227,6 +224,8 @@ avtPATRANFileFormat::ActivateTimestep() // // Modifications: // +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // **************************************************************************** inline void @@ -236,23 +235,21 @@ AddPoint(char *line, const int ptid, int &nPoints, vtkPoints *pts) char *valstart = line + 2 * LONG_FIELD_WIDTH; char *valend = valstart + LONG_FIELD_WIDTH; float pt[3]; - pt[2] = atof(valstart); + pt[2] = vstrtonum(valstart); valstart -= LONG_FIELD_WIDTH; valend -= LONG_FIELD_WIDTH; *valend = '\0'; - pt[1] = atof(valstart); + pt[1] = vstrtonum(valstart); valstart -= LONG_FIELD_WIDTH; valend -= LONG_FIELD_WIDTH; *valend = '\0'; - pt[0] = atof(valstart); + pt[0] = vstrtonum(valstart); -#ifdef DEBUG_PRINT_NODES debug4 << "Node: " << pt[0] << ", " << pt[1] << ", " << pt[0] << endl; -#endif #ifdef USE_POINT_INDICES_TO_INSERT if(ptid < nPoints) @@ -299,6 +296,8 @@ AddPoint(char *line, const int ptid, int &nPoints, vtkPoints *pts) // // Modifications: // +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // **************************************************************************** inline bool @@ -320,16 +319,14 @@ AddCell(char *line, const int cellNumNodes, const int IV, for(int v = 0; v < cellNumNodes; ++v) { *valend = '\0'; - verts[v] = atoi(valstart)-1; + verts[v] = vstrtonum(valstart)-1; valstart -= SHORT_FIELD_WIDTH; valend -= SHORT_FIELD_WIDTH; } -#ifdef DEBUG_PRINT_CELL_VERTS debug4 << "Cell verts: "; for(int i = 0; i < cellNumNodes; ++i) debug4 << ", " << verts[i]; debug4 << endl; -#endif ugrid->InsertNextCell(IVToVTKCell[IV], cellNumNodes, verts); } @@ -363,6 +360,8 @@ AddCell(char *line, const int cellNumNodes, const int IV, // // Modifications: // +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // **************************************************************************** inline void @@ -378,7 +377,7 @@ ProcessComponent(char *line, const int compno, const int ncomps, { // Get the cellid. *valend = '\0'; - int cellid = atoi(valstart)-1; + int cellid = vstrtonum(valstart)-1; // Try and map that cellid back to a cell index. If we can do the // mapping then save the cell index. @@ -464,6 +463,8 @@ ProcessComponent(char *line, const int compno, const int ncomps, // Jeremy Meredith, Thu Jan 14 11:37:39 EST 2010 // Was slightly too aggressive with one of the new error checks. // +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // **************************************************************************** bool @@ -590,34 +591,32 @@ avtPATRANFileFormat::ReadFile(const char *name, int nLines) // Ignore N2,N3,N4,N5 for now. *valend = '\0'; - N1 = atoi(valstart); + N1 = vstrtonum(valstart); valstart -= SHORT_FIELD_WIDTH; valend -= SHORT_FIELD_WIDTH; *valend = '\0'; - KC = atoi(valstart); + KC = vstrtonum(valstart); valstart -= SHORT_FIELD_WIDTH; valend -= SHORT_FIELD_WIDTH; *valend = '\0'; - IV = atoi(valstart); + IV = vstrtonum(valstart); valstart -= SHORT_FIELD_WIDTH; valend -= SHORT_FIELD_WIDTH; *valend = '\0'; - ID = atoi(valstart); + ID = vstrtonum(valstart); line[2] = '\0'; - IT = atoi(line); + IT = vstrtonum(line); -#ifdef DEBUG_PRINT_HEADER debug4 << "IT=" << IT << ", ID=" << ID << ", IV=" << IV << ", KC=" << KC << ", N1=" << N1 << endl; -#endif // Read the values for IT, ID, IV, KC out of the line. ++card; @@ -644,11 +643,11 @@ avtPATRANFileFormat::ReadFile(const char *name, int nLines) char *valstart = line + 2 * SHORT_FIELD_WIDTH; char *valend = valstart + SHORT_FIELD_WIDTH; *valend = '\0'; - cellMatno = atof(valstart); + cellMatno = vstrtonum(valstart); // Get the number of nodes in this cell. line[SHORT_FIELD_WIDTH] = '\0'; - cellNumNodes = atoi(line); + cellNumNodes = vstrtonum(line); } else if(card == 2) { @@ -675,9 +674,7 @@ avtPATRANFileFormat::ReadFile(const char *name, int nLines) if(card == 1) { componentNames.push_back(line); -#ifdef DEBUG_PRINT_MATERIAL_NAMES debug4 << "partName = " << line << endl; -#endif } #ifndef MDSERVER // Don't process the material numbers in the mdserver. @@ -705,7 +702,7 @@ avtPATRANFileFormat::ReadFile(const char *name, int nLines) for(int col = MAX_CELL_PROPERTIES-1; col >= 0; col--) { *valend = '\0'; - double tmp = atof(valstart); + double tmp = vstrtonum(valstart); valstart -= LONG_FIELD_WIDTH; valend -= LONG_FIELD_WIDTH; properties[col]->InsertNextTuple(&tmp); diff --git a/src/databases/PVLD/pvldReader.C b/src/databases/PVLD/pvldReader.C index 9babc4b796..9b4c584d2d 100644 --- a/src/databases/PVLD/pvldReader.C +++ b/src/databases/PVLD/pvldReader.C @@ -16,6 +16,8 @@ #include #endif #include +#include +using StringHelpers::vstrtonum; #include using std::set; @@ -24,7 +26,7 @@ using std::string; static int STOI(const std::string &s) { - return atoi(s.c_str()); + return vstrtonum(s.c_str()); } void OutputVectorInt( ostream& os, const string& cmt, const vector& vec ) @@ -1947,7 +1949,7 @@ ReadInfo( hid_t file_id, const char* name, } else { - npart = atoi(spt); + npart = vstrtonum(spt); if( npart>0 ) { part.resize( npart+1 ); diff --git a/src/databases/Pixie/avtPixieFileFormat.C b/src/databases/Pixie/avtPixieFileFormat.C index 78a6f4f777..feef953c9e 100644 --- a/src/databases/Pixie/avtPixieFileFormat.C +++ b/src/databases/Pixie/avtPixieFileFormat.C @@ -29,12 +29,17 @@ #include #include #include +using DebugStream::Level4; +using DebugStream::Stream4; #include #include #include #include #include #include +#include +using StringHelpers::vstrtonum; +using StringHelpers::NO_OSTREAM; // Define this symbol BEFORE including hdf5.h to indicate the HDF5 code // in this file uses version 1.6 of the HDF5 API. This is harmless for @@ -2308,9 +2313,9 @@ avtPixieFileFormat::GetVariableList(hid_t group, const char *name, int cycle; if (varName[9] == '_') - cycle = atoi(varName.substr(10).c_str()); + cycle = vstrtonum(varName.substr(10).c_str(),10,0,Level4()?Stream4():NO_OSTREAM); else - cycle = atoi(varName.substr(9).c_str()); + cycle = vstrtonum(varName.substr(9).c_str(),10,0,Level4()?Stream4():NO_OSTREAM); info->This->cycles.push_back(cycle); } diff --git a/src/databases/PlainText/avtPlainTextFileFormat.C b/src/databases/PlainText/avtPlainTextFileFormat.C index d36170efee..c5e0d854ee 100644 --- a/src/databases/PlainText/avtPlainTextFileFormat.C +++ b/src/databases/PlainText/avtPlainTextFileFormat.C @@ -24,6 +24,7 @@ #include #include #include +using StringHelpers::vstrtonum; #include "visit_gzstream.h" @@ -540,7 +541,7 @@ avtPlainTextFileFormat::ReadFile() } else { - double value = atof(start); + double value = vstrtonum(start); row.push_back(value); } start = end+1; @@ -577,7 +578,7 @@ avtPlainTextFileFormat::ReadFile() } else { - double value = atof(start); + double value = vstrtonum(start); row.push_back(value); } } diff --git a/src/databases/ProteinDataBank/avtProteinDataBankFileFormat.C b/src/databases/ProteinDataBank/avtProteinDataBankFileFormat.C index 2322038bdf..dfe35717ff 100644 --- a/src/databases/ProteinDataBank/avtProteinDataBankFileFormat.C +++ b/src/databases/ProteinDataBank/avtProteinDataBankFileFormat.C @@ -24,6 +24,7 @@ #include #include #include +using StringHelpers::vstrtonum; #include @@ -1274,7 +1275,7 @@ ScanInt(const char *line, int len, int start, int end, int *val) tmpbuff[i - first] = line[i]; } tmpbuff[i - first] = '\0'; - *val = atoi(tmpbuff); + *val = vstrtonum(tmpbuff); } static inline void @@ -1298,7 +1299,7 @@ ScanFloat(const char *line, int len, int start, int end, float *val) tmpbuff[i - first] = '\0'; //sscanf(tmpbuff, "%f", val); - *val = atof(tmpbuff); + *val = vstrtonum(tmpbuff); } // **************************************************************************** diff --git a/src/databases/PuReMD/avtPuReMDFileFormat.C b/src/databases/PuReMD/avtPuReMDFileFormat.C index b3f8a6aeb3..8407ac179d 100644 --- a/src/databases/PuReMD/avtPuReMDFileFormat.C +++ b/src/databases/PuReMD/avtPuReMDFileFormat.C @@ -27,6 +27,9 @@ #include #include +#include +using StringHelpers::vstrtonum; + using std::string; using std::pair; @@ -475,7 +478,7 @@ avtPuReMDFileFormat::ReadAllMetaData() if (strncmp(line, "number_of_atoms:", 16) == 0) { - nAtoms = atoi(line+16); + nAtoms = vstrtonum(line+16); } else if (strncmp(line, "atom_info:", 10) == 0) { @@ -570,7 +573,7 @@ avtPuReMDFileFormat::ReadAllMetaData() break; if (strncmp(line, "step:", 5) == 0) - step = atoi(line+5); + step = vstrtonum(line+5); else if (strncmp(line, "time_in_ps:", 11) == 0) time_in_ps = strtod(line+11,NULL); else if (strncmp(line, "box_dimensions:", 15) == 0) diff --git a/src/databases/STAR/ConfigFileReader.C b/src/databases/STAR/ConfigFileReader.C index 3efb1ff1f2..531d1cf102 100644 --- a/src/databases/STAR/ConfigFileReader.C +++ b/src/databases/STAR/ConfigFileReader.C @@ -42,6 +42,9 @@ // stardata includes #include "StarObject.h" #include "ConfigFileReader.h" +#include +using StringHelpers::vstrtonum; +using StringHelpers::NO_OSTREAM; #include #include @@ -302,7 +305,7 @@ int ConfigFileReader::findIntValue(const char* id, const char* section) char* endptr = NULL; int value = 0; - value = strtol(findValue(id,section), &endptr, 10); + value = vstrtonum(findValue(id,section),10,-9999,NO_OSTREAM,&endptr); if(endptr != NULL and endptr[0] != '\0') { WARNING("Parse Error: Unable to convert string '%s' " @@ -327,7 +330,7 @@ long long ConfigFileReader::findLongValue(const char* id, const char* section) char* endptr = NULL; long long value = 0; - value = strtoll(findValue(id,section), &endptr, 10); + value = vstrtonum(findValue(id,section),10,-999999,NO_OSTREAM,&endptr); if(endptr != NULL and endptr[0] != '\0') { WARNING("Parse Error: Unable to convert string '%s' " @@ -352,7 +355,7 @@ float ConfigFileReader::findFloatValue(const char* id, const char* section) char* endptr = NULL; float value = 0.0; - value = strtof(findValue(id,section), &endptr); + value = vstrtonum(findValue(id,section),10,-999.99,NO_OSTREAM,&endptr); if(endptr != NULL and endptr[0] != '\0') { WARNING("Parse Error: Unable to convert string '%s' " @@ -377,7 +380,7 @@ double ConfigFileReader::findDoubleValue(const char* id, const char* section) char* endptr = NULL; float value = 0.0; - value = strtod(findValue(id,section), &endptr); + value = vstrtonum(findValue(id,section),10,-999.99,NO_OSTREAM,&endptr); if(endptr != NULL and endptr[0] != '\0') { WARNING("Parse Error: Unable to convert string '%s' " diff --git a/src/databases/Shapefile/dbfFile.C b/src/databases/Shapefile/dbfFile.C index 37a1d2891b..58b08c29e2 100644 --- a/src/databases/Shapefile/dbfFile.C +++ b/src/databases/Shapefile/dbfFile.C @@ -6,6 +6,9 @@ #include #include +#include +using StringHelpers::vstrtonum; + #define DBF_LITTLE_ENDIAN 0 #define DBF_BIG_ENDIAN 1 @@ -795,6 +798,8 @@ dbfFileReadField(dbfFile_t *fileObj, const char *fieldName, dbfReadError_t *code // Brad Whitlock, Wed Apr 6 10:26:02 PDT 2005 // I removed common storage since it was used so little. // +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // **************************************************************************** void * @@ -881,8 +886,7 @@ dbfFileReadField2(dbfFile_t *fileObj, const char *fieldName, void *data, if(fread((void *)tmp, 1, fieldDescriptor->fieldLength, fileObj->fp) == fieldDescriptor->fieldLength) { - char *endptr = 0; - *fptr = (float)strtod(tmp, &endptr); + *fptr = vstrtonum(tmp); ++fptr; /* Seek to the start of the field in the next record. */ if(fseek(fileObj->fp, offset, SEEK_CUR) != 0) @@ -912,8 +916,7 @@ dbfFileReadField2(dbfFile_t *fileObj, const char *fieldName, void *data, if(fread((void *)tmp, 1, fieldDescriptor->fieldLength, fileObj->fp) == fieldDescriptor->fieldLength) { - char *endptr = 0; - *dptr = strtod(tmp, &endptr); + *dptr = vstrtonum(tmp); ++dptr; /* Seek to the start of the field in the next record. */ if(fseek(fileObj->fp, offset, SEEK_CUR) != 0) diff --git a/src/databases/Silo/avtSiloFileFormat.C b/src/databases/Silo/avtSiloFileFormat.C index 4a910b8ef4..0aa58de398 100644 --- a/src/databases/Silo/avtSiloFileFormat.C +++ b/src/databases/Silo/avtSiloFileFormat.C @@ -65,11 +65,16 @@ #include #include #include +using DebugStream::Level3; +using DebugStream::Stream3; #include #include #include #include #include +#include +using StringHelpers::vstrtonum; +using StringHelpers::NO_OSTREAM; #include #include @@ -2780,7 +2785,7 @@ GetRestrictedMaterialIndices(const avtDatabaseMetaData *md, const char *const va int rnspn = strspn(region_pnames[i], "0123456789"); if (rnlen == rnspn) // Must be just a number { - int regno = strtol(region_pnames[i], 0, 10); + int regno = vstrtonum(region_pnames[i],10,0,Level3()?Stream3():NO_OSTREAM); regionNamesButMaterialNumbers = false; debug3 << " Comparing using regno=" << regno << "..." << endl; for (j = 0; j < (size_t)mmd->numMaterials; j++) @@ -2789,7 +2794,7 @@ GetRestrictedMaterialIndices(const avtDatabaseMetaData *md, const char *const va // "%d (matno)" or "%d (matno) %s (matname)". Either way, // strtol should convert the number part correctly. errno = 0; - int matno = strtol(mmd->materialNames[j].c_str(), 0, 10); + int matno = vstrtonum(mmd->materialNames[j].c_str(),10,0,Level3()?Stream3():NO_OSTREAM); debug3 << " for \"" << mmd->materialNames[j] << "\" got matno=" << matno; if (errno == 0 && regno == matno) @@ -17892,5 +17897,5 @@ db_get_index(DBnamescheme const *ns, int natnum) if (!name_str[i]) return -1; - return (int) strtol(&name_str[i], 0, 10); + return vstrtonum(&name_str[i]); } diff --git a/src/databases/TCGA/avtTCGAFileFormat.C b/src/databases/TCGA/avtTCGAFileFormat.C index 7fc52a680f..981fca79fb 100644 --- a/src/databases/TCGA/avtTCGAFileFormat.C +++ b/src/databases/TCGA/avtTCGAFileFormat.C @@ -22,6 +22,8 @@ #include #include +#include +using StringHelpers::vstrtonum; #include #include @@ -449,7 +451,8 @@ avtTCGAFileFormat::GetVectorVar(int domain, const char *varname) // Creation: November 5, 2014 // // Modifications: -// +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum //**************************************************************************** static void @@ -461,6 +464,6 @@ extractXY(const string &str, const string &suffix, int &x, int &y) string yStr = str.substr(i1+1, (i0-i1-1)); string xStr = str.substr(i2+1, (i1-i2-1)); - x = atoi(xStr.c_str()); - y = atoi(yStr.c_str()); + x = vstrtonum(xStr.c_str()); + y = vstrtonum(yStr.c_str()); } diff --git a/src/databases/Tecplot/avtTecplotFileFormat.C b/src/databases/Tecplot/avtTecplotFileFormat.C index 02a816b0c2..568a0849db 100644 --- a/src/databases/Tecplot/avtTecplotFileFormat.C +++ b/src/databases/Tecplot/avtTecplotFileFormat.C @@ -27,6 +27,9 @@ #include #include #include +#include +using StringHelpers::vstrtonum; +using StringHelpers::NO_OSTREAM; #ifdef _MSC_VER #include @@ -38,14 +41,6 @@ using std::vector; #define MAX(a,b) ((a)>(b)?(a):(b)) #endif - -#if defined(_MSC_VER) || !defined(HAVE_STRTOF) || !defined(HAVE_STRTOF_PROTOTYPE) -#ifndef strtof -#define strtof(f1,f2) ((float)strtod(f1,f2)) -#endif -#endif - - // **************************************************************************** // Method: GetCoord/GuessCoord // @@ -412,12 +407,12 @@ avtTecplotFileFormat::ParseArraysPoint(int numNodes, int numElements) char *endptr; const char *cptr; repeatCounter = 1; - currentValue = strtof((cptr=tok.c_str()), &endptr); + currentValue = vstrtonum((cptr=tok.c_str()),10,0,NO_OSTREAM,&endptr); int numparsed = endptr-cptr; if (numparsed < toklen && tok[numparsed] == '*') { - currentValue = atof(tok.substr(numparsed+1).c_str()); - repeatCounter = atoi(tok.substr(0,numparsed).c_str()); + currentValue = vstrtonum(tok.substr(numparsed+1).c_str()); + repeatCounter = vstrtonum(tok.substr(0,numparsed).c_str()); } } allptr[v][i] = currentValue; @@ -525,12 +520,12 @@ avtTecplotFileFormat::ParseArraysBlock(int numNodes, int numElements) char *endptr; const char *cptr; repeatCounter = 1; - currentValue = strtof((cptr=tok.c_str()), &endptr); + currentValue = vstrtonum((cptr=tok.c_str()),10,0,NO_OSTREAM,&endptr); int numparsed = endptr-cptr; if (numparsed < toklen && tok[numparsed] == '*') { - currentValue = atof(tok.substr(numparsed+1).c_str()); - repeatCounter = atoi(tok.substr(0,numparsed).c_str()); + currentValue = vstrtonum(tok.substr(numparsed+1).c_str()); + repeatCounter = vstrtonum(tok.substr(0,numparsed).c_str()); } } @@ -677,7 +672,7 @@ avtTecplotFileFormat::ParseElements(int numElements, const string &elemType) tok = GetNextToken(); } - int val = atoi(tok.c_str()); + int val = vstrtonum(tok.c_str()); *nl++ = val - 1; } } @@ -1358,27 +1353,27 @@ avtTecplotFileFormat::ReadFile() else if (tok == "I") { GetNextToken(); // skip the equals sign - numI = atoi(GetNextToken().c_str()); + numI = vstrtonum(GetNextToken().c_str()); } else if (tok == "J") { GetNextToken(); // skip the equals sign - numJ = atoi(GetNextToken().c_str()); + numJ = vstrtonum(GetNextToken().c_str()); } else if (tok == "K") { GetNextToken(); // skip the equals sign - numK = atoi(GetNextToken().c_str()); + numK = vstrtonum(GetNextToken().c_str()); } else if (tok == "N" || tok == "NODES") { GetNextToken(); // skip the equals sign - numNodes = atoi(GetNextToken().c_str()); + numNodes = vstrtonum(GetNextToken().c_str()); } else if (tok == "E" || tok == "ELEMENTS") { GetNextToken(); // skip the equals sign - numElements = atoi(GetNextToken().c_str()); + numElements = vstrtonum(GetNextToken().c_str()); } else if (tok == "ET" || tok == "ZONETYPE") { @@ -1438,14 +1433,14 @@ avtTecplotFileFormat::ReadFile() // eventually do something like that.... string first = c.substr(0,pos); string last = c.substr(pos+1); - int beg = atoi(first.c_str()); - int end = atoi(last.c_str()); + int beg = vstrtonum(first.c_str()); + int end = vstrtonum(last.c_str()); for (int ind=beg; ind<=end; ind++) varindices.push_back(ind); } else { - varindices.push_back(atoi(c.c_str())); + varindices.push_back(vstrtonum(c.c_str())); } c = GetNextToken(); } @@ -1536,14 +1531,14 @@ avtTecplotFileFormat::ReadFile() // eventually do something like that.... string first = c.substr(0,pos); string last = c.substr(pos+1); - int beg = atoi(first.c_str()); - int end = atoi(last.c_str()); + int beg = vstrtonum(first.c_str()); + int end = vstrtonum(last.c_str()); for (int ind=beg; ind<=end; ind++) varindices.push_back(ind); } else { - varindices.push_back(atoi(c.c_str())); + varindices.push_back(vstrtonum(c.c_str())); } c = GetNextToken(); } @@ -1552,7 +1547,7 @@ avtTecplotFileFormat::ReadFile() if (c == "=") { c = GetNextToken(); - dest = atoi(c.c_str()); + dest = vstrtonum(c.c_str()); // next.... c = GetNextToken(); } @@ -1576,7 +1571,7 @@ avtTecplotFileFormat::ReadFile() { GetNextToken(); // skip the equals sign string fromzone = GetNextToken(); - connectivitycopy = atoi(fromzone.c_str()) - 1; // change 1-origin to 0-origin + connectivitycopy = vstrtonum(fromzone.c_str()) - 1; // change 1-origin to 0-origin } tok = GetNextToken(); debug5 << "Tecplot: NEXT TOKEN: " << tok << "\n"; diff --git a/src/databases/Tetrad/avtTetradFileFormat.C b/src/databases/Tetrad/avtTetradFileFormat.C index a5fcbe39ec..13d2a4d45d 100644 --- a/src/databases/Tetrad/avtTetradFileFormat.C +++ b/src/databases/Tetrad/avtTetradFileFormat.C @@ -21,6 +21,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; #include @@ -339,6 +341,9 @@ avtTetradFileFormat::GetVar(int ts, const char *var) // // Mark C. Miller, Tue May 17 18:48:38 PDT 2005 // Added timeState argument +// +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // **************************************************************************** void @@ -366,7 +371,7 @@ avtTetradFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md, time_index_pair *pairs = new time_index_pair[ntimes]; for (i = 0 ; i < ntimes ; i++) { - pairs[i].dtime = atof(timesteps[i].c_str()); + pairs[i].dtime = vstrtonum(timesteps[i].c_str()); pairs[i].index = i; } qsort(pairs, ntimes, sizeof(time_index_pair), TimeIndexPairSorter); @@ -386,7 +391,7 @@ avtTetradFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md, vector dtimesteps; for (i = 0 ; i < timesteps.size() ; i++) { - dtimesteps.push_back(atof(timesteps[i].c_str())); + dtimesteps.push_back(vstrtonum(timesteps[i].c_str())); } md->SetTimes(dtimesteps); md->SetTimesAreAccurate(true); diff --git a/src/databases/Uintah/avtUintahFileFormat.C b/src/databases/Uintah/avtUintahFileFormat.C index b70fd59efb..0ee7f9d381 100644 --- a/src/databases/Uintah/avtUintahFileFormat.C +++ b/src/databases/Uintah/avtUintahFileFormat.C @@ -36,6 +36,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; #include #include @@ -1327,7 +1329,7 @@ avtUintahFileFormat::GetMesh(int timestate, int domain, const char *meshname) int matlNo = -1; if (matl.compare("*") != 0) - matlNo = atoi(matl.c_str()); + matlNo = vstrtonum(matl.c_str()); // int t2 = visitTimer->StartTimer(); @@ -1379,7 +1381,7 @@ avtUintahFileFormat::GetMesh(int timestate, int domain, const char *meshname) // same as GetVar(timestate, domain, "particleID"); int matlNo = -1; if (matl.compare("*") != 0) - matlNo = atoi(matl.c_str()); + matlNo = vstrtonum(matl.c_str()); ParticleDataRaw *pd = NULL; @@ -1764,7 +1766,7 @@ avtUintahFileFormat::GetVar(int timestate, int domain, const char *varname) int matlNo = -1; if (matl.compare("*") != 0) - matlNo = atoi(matl.c_str()); + matlNo = vstrtonum(matl.c_str()); ParticleDataRaw *pd = NULL; @@ -1992,7 +1994,7 @@ avtUintahFileFormat::GetVar(int timestate, int domain, const char *varname) { int matlNo = -1; if (matl.compare("All") != 0) - matlNo = atoi(matl.c_str()); + matlNo = vstrtonum(matl.c_str()); #ifdef SERIALIZED_READS int numProcs, rank; diff --git a/src/databases/VASP/avtOUTCARFileFormat.C b/src/databases/VASP/avtOUTCARFileFormat.C index a9323d9154..e0b69dd7dc 100644 --- a/src/databases/VASP/avtOUTCARFileFormat.C +++ b/src/databases/VASP/avtOUTCARFileFormat.C @@ -25,6 +25,8 @@ #include #include +#include +using StringHelpers::vstrtonum; #include #include @@ -735,21 +737,21 @@ avtOUTCARFileFormat::ReadAllMetaData() in.getline(line, 4096); s = line; - unitCell[0][0] = atof(s.substr( 7,15).c_str()); - unitCell[0][1] = atof(s.substr(23,15).c_str()); - unitCell[0][2] = atof(s.substr(39,15).c_str()); + unitCell[0][0] = vstrtonum(s.substr( 7,15).c_str()); + unitCell[0][1] = vstrtonum(s.substr(23,15).c_str()); + unitCell[0][2] = vstrtonum(s.substr(39,15).c_str()); in.getline(line, 4096); s = line; - unitCell[1][0] = atof(s.substr( 7,15).c_str()); - unitCell[1][1] = atof(s.substr(23,15).c_str()); - unitCell[1][2] = atof(s.substr(39,15).c_str()); + unitCell[1][0] = vstrtonum(s.substr( 7,15).c_str()); + unitCell[1][1] = vstrtonum(s.substr(23,15).c_str()); + unitCell[1][2] = vstrtonum(s.substr(39,15).c_str()); in.getline(line, 4096); s = line; - unitCell[2][0] = atof(s.substr( 7,15).c_str()); - unitCell[2][1] = atof(s.substr(23,15).c_str()); - unitCell[2][2] = atof(s.substr(39,15).c_str()); + unitCell[2][0] = vstrtonum(s.substr( 7,15).c_str()); + unitCell[2][1] = vstrtonum(s.substr(23,15).c_str()); + unitCell[2][2] = vstrtonum(s.substr(39,15).c_str()); }*/ else if (!strncmp(line," direct lattice vectors",28)) { @@ -863,7 +865,7 @@ avtOUTCARFileFormat::ReadAllMetaData() istringstream sin(line+65); string arg1; sin >> arg1; - nions_doublecheck = atoi(arg1.c_str()); + nions_doublecheck = vstrtonum(arg1.c_str()); } else if (!all_ions_read && !strncmp(line," ions per type =",18)) { @@ -903,7 +905,7 @@ avtOUTCARFileFormat::ReadAllMetaData() index++; } tmp[j] = '\0'; - int n = atoi(tmp); + int n = vstrtonum(tmp); natoms += n; element_counts.push_back(n); } @@ -925,7 +927,7 @@ avtOUTCARFileFormat::ReadAllMetaData() istringstream sin(line); string arg1,arg2,arg3; sin >> arg1 >> arg2 >> arg3; - potim = strtod(arg3.c_str(), NULL); + potim = vstrtonum(arg3.c_str()); } diff --git a/src/databases/VLI/avtVLIFileFormat.C b/src/databases/VLI/avtVLIFileFormat.C index 3543e3f480..0c4ba77fbb 100644 --- a/src/databases/VLI/avtVLIFileFormat.C +++ b/src/databases/VLI/avtVLIFileFormat.C @@ -28,6 +28,11 @@ #include #include #include +using DebugStream::Level5; +using DebugStream::Stream5; +#include +using StringHelpers::vstrtonum; +using StringHelpers::NO_OSTREAM; #include #ifdef PARALLEL @@ -63,6 +68,8 @@ using std::string; // Jeremy Meredith, Thu Aug 7 14:45:49 EDT 2008 // Use %ld for size_t variables. // +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // **************************************************************************** int AllocateSocket(std::string hostname, int port) { @@ -125,7 +132,7 @@ int InvokeRemoteCall(std::string host, int port, int call) { if (read(conn, in_buffer, 4) == 4) { - if (atoi(in_buffer)) { + if (vstrtonum(in_buffer,10,0,Level5()?Stream5():NO_OSTREAM)) { VLIDEBUG << "InvokeRemoteCall(): Client couldn't call server function " << (call ? "Count." : "Query.") << endl; return -1; } @@ -322,6 +329,9 @@ avtVLIFileFormat::~avtVLIFileFormat() { // Programmer: Markus Glatter -- generated by xml2avt // Creation: Mon May 7 13:54:06 PST 2007 // +// Modifications: +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // **************************************************************************** void *avtVLIFileFormat::threadCommServer(void *in) { @@ -342,15 +352,15 @@ void *avtVLIFileFormat::threadCommServer(void *in) { d = '1'; ServerRead(conn, buf, 39, -1); char *dbuf = strdup(buf); - int _nservers = atoi(&dbuf[36]); dbuf[36] = 0; - int _nitems = atoi(&dbuf[21]); dbuf[21] = 0; - int _nattr = atoi(&dbuf[18]); dbuf[18] = 0; - int _itemsz = atoi(&dbuf[15]); dbuf[15] = 0; + int _nservers = vstrtonum(&dbuf[36],10,0,Level5()?Stream5():NO_OSTREAM); dbuf[36] = 0; + int _nitems = vstrtonum(&dbuf[21],10,0,Level5()?Stream5():NO_OSTREAM); dbuf[21] = 0; + int _nattr = vstrtonum(&dbuf[18],10,0,Level5()?Stream5():NO_OSTREAM); dbuf[18] = 0; + int _itemsz = vstrtonum(&dbuf[15],10,0,Level5()?Stream5():NO_OSTREAM); dbuf[15] = 0; int _dims[3]; - _dims[2] = atoi(&dbuf[11]); dbuf[11] = 0; - _dims[1] = atoi(&dbuf[7]); dbuf[7] = 0; - _dims[0] = atoi(&dbuf[3]); dbuf[3] = 0; - int _files = atoi(dbuf); + _dims[2] = vstrtonum(&dbuf[11],10,0,Level5()?Stream5():NO_OSTREAM); dbuf[11] = 0; + _dims[1] = vstrtonum(&dbuf[7],10,0,Level5()?Stream5():NO_OSTREAM); dbuf[7] = 0; + _dims[0] = vstrtonum(&dbuf[3],10,0,Level5()?Stream5():NO_OSTREAM); dbuf[3] = 0; + int _files = vstrtonum(dbuf,10,0,Level5()?Stream5():NO_OSTREAM); sprintf(tmp, "**** nservers = %d, nitems = %d, nattr = %d, itemsz = %d, dims = %d %d %d, files = %d\n", _nservers, _nitems, _nattr, _itemsz, _dims[0], _dims[1], _dims[2], _files); VLIDEBUG << tmp; @@ -362,7 +372,7 @@ void *avtVLIFileFormat::threadCommServer(void *in) { ServerRead(conn, sbuf, 255, -1); if ((st = strstr(sbuf, ":")) != NULL) { *st++ = 0; - this->sport[i] = atoi(st); + this->sport[i] = vstrtonum(st,10,0,Level5()?Stream5():NO_OSTREAM); this->shostname[i] = std::string(sbuf); } else d = '0'; diff --git a/src/databases/VTK/avtVTKFileReader.C b/src/databases/VTK/avtVTKFileReader.C index d4b1653e02..d6c3133b8e 100644 --- a/src/databases/VTK/avtVTKFileReader.C +++ b/src/databases/VTK/avtVTKFileReader.C @@ -42,6 +42,7 @@ #include #include #include +using StringHelpers::vstrtonum; #include @@ -1125,7 +1126,7 @@ avtVTKFileReader::GetVar(int domain, const char *real_name) if (strstr(var, VARNAME) != NULL) { const char *numstr = var + strlen(VARNAME); - int num = atoi(numstr); + int num = vstrtonum(numstr); int npointvars = dataset->GetPointData()->GetNumberOfArrays(); if (num < npointvars) { diff --git a/src/databases/VisItXdmf/avtVisItXdmfFileFormat.C b/src/databases/VisItXdmf/avtVisItXdmfFileFormat.C index ba9f0641c7..781ddeae16 100644 --- a/src/databases/VisItXdmf/avtVisItXdmfFileFormat.C +++ b/src/databases/VisItXdmf/avtVisItXdmfFileFormat.C @@ -34,6 +34,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; #include @@ -1836,12 +1838,12 @@ avtVisItXdmfFileFormat::ParseUniformGrid(std::vector &meshList, { meshInfo->order = new int[nNodes]; char *str = NULL, *str2 = NULL; - int iVal = (int)strtol(order.c_str(), &str, 10); + int iVal = vstrtonum(order.c_str()); meshInfo->order[0] = (iVal < 0) ? 0 : ((iVal < nNodes) ? iVal : nNodes - 1); for (int i = 1; i < nNodes; i++) { - iVal = (int)strtol(str, &str2, 10); + iVal = vstrtonum(str); meshInfo->order[i] = (iVal < 0) ? 0 : ((iVal < nNodes) ? iVal : nNodes - 1); str = str2; diff --git a/src/databases/Vs/avtVsFileFormat.C b/src/databases/Vs/avtVsFileFormat.C index 590192d7bd..03c9933eb4 100644 --- a/src/databases/Vs/avtVsFileFormat.C +++ b/src/databases/Vs/avtVsFileFormat.C @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -4436,6 +4437,8 @@ void avtVsFileFormat::ActivateTimestep() // // Modifications: // +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum /* void avtVsFileFormat::UpdateCyclesAndTimes(avtDatabaseMetaData* md) { @@ -4486,7 +4489,7 @@ void avtVsFileFormat::UpdateCyclesAndTimes(avtDatabaseMetaData* md) << "Step is \"" << step << "\"" << std::endl; - timeStep = atoi(step.c_str()); + timeStep = StringHelpers::vstrtonum(step.c_str(),10,0,VsLog::debugLog()); VsLog::debugLog() << CLASSFUNCLINE <<"Converted to integer is \"" << timeStep << "\"" diff --git a/src/databases/WellLogs/avtWellLogsFileFormat.C b/src/databases/WellLogs/avtWellLogsFileFormat.C index 2a230e4456..1d06760a8c 100644 --- a/src/databases/WellLogs/avtWellLogsFileFormat.C +++ b/src/databases/WellLogs/avtWellLogsFileFormat.C @@ -28,6 +28,9 @@ #include #include +#include +using StringHelpers::vstrtonum; + using std::string; @@ -236,13 +239,13 @@ avtWellLogsFileFormat::ReadFile(void) wellIds.push_back((int)wellNames.size()-1); } else if (utm83EId == idx) - X.push_back(atof(s)); + X.push_back(vstrtonum(s)); else if (utm83NId == idx) - Y.push_back(atof(s)); + Y.push_back(vstrtonum(s)); else if (wellBottomId == idx) - Z1.push_back(atof(s)); + Z1.push_back(vstrtonum(s)); else if (groundElevationId == idx || depenvId == idx) - Z2.push_back(atof(s)); + Z2.push_back(vstrtonum(s)); } else { @@ -250,13 +253,13 @@ avtWellLogsFileFormat::ReadFile(void) if (wellId == idx) twellName = s; else if (utm83EId == idx) - tX = (atof(s)); + tX = (vstrtonum(s)); else if (utm83NId == idx) - tY = (atof(s)); + tY = (vstrtonum(s)); else if (wellBottomId == idx) - tZ = (atof(s)); + tZ = (vstrtonum(s)); else if (depenvId == idx) - tD = (atof(s)); + tD = (vstrtonum(s)); } s = next; idx++; diff --git a/src/databases/XSF/avtXSFFileFormat.C b/src/databases/XSF/avtXSFFileFormat.C index 0b6e2c74ce..aa28ab8db3 100644 --- a/src/databases/XSF/avtXSFFileFormat.C +++ b/src/databases/XSF/avtXSFFileFormat.C @@ -26,6 +26,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; #include @@ -545,7 +547,7 @@ avtXSFFileFormat::ReadAtomsForTimestep(int ts) Atom &a = currentAtoms[i]; string species; in >> species; - a.e = atoi(species.c_str()); + a.e = vstrtonum(species.c_str()); if (a.e == 0) a.e = ElementNameToAtomicNumber(species.c_str()); in >> a.x >> a.y >> a.z; diff --git a/src/databases/XYZ/avtXYZFileFormat.C b/src/databases/XYZ/avtXYZFileFormat.C index 9d3114c0f9..9f214a2da4 100644 --- a/src/databases/XYZ/avtXYZFileFormat.C +++ b/src/databases/XYZ/avtXYZFileFormat.C @@ -23,6 +23,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; using std::string; @@ -431,7 +433,7 @@ avtXYZFileFormat::ReadTimeStep(int timestep) e[timestep][a] = ElementNameToAtomicNumber(element); if (e[timestep][a] <= 0) - e[timestep][a] = atoi(element); + e[timestep][a] = vstrtonum(element); if (e[timestep][a] < 0 || e[timestep][a] > MAX_ELEMENT_NUMBER) e[timestep][a] = 0; // not valid; 0==unknown } @@ -488,7 +490,7 @@ avtXYZFileFormat::ReadAllMetaData() file_positions.push_back(current_pos); // we expect the first line to be a number for a simple XYZ file - int natoms_tmp = atoi(buff); + int natoms_tmp = vstrtonum(buff); // if that failed, it's not a simple XYZ file if (natoms_tmp != 0) diff --git a/src/databases/lata/LataFilter.C b/src/databases/lata/LataFilter.C index 2b6735e2ee..9dfa32fd53 100644 --- a/src/databases/lata/LataFilter.C +++ b/src/databases/lata/LataFilter.C @@ -44,6 +44,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; static const entier cache_info_level = 5; static const entier filter_info_level = 4; @@ -52,10 +54,8 @@ entier LataOptions::read_int_opt(const Nom & s) const char *ptr = strstr(s, "="); if (!ptr) ptr = s; - errno = 0; - char *errorptr = 0; - entier x = strtol(ptr+1, &errorptr, 0 /* base 10 par defaut */); - if (errno || *errorptr != 0) { + entier x = vstrtonum(ptr+1,10,-9999,Journal()); + if (x == -9999) { Journal() << "LataOptions error reading int parameter: " << s << endl; throw; } @@ -67,10 +67,8 @@ double LataOptions::read_float_opt(const Nom & s) const char *ptr = strstr(s, "="); if (!ptr) ptr = s; - errno = 0; - char *errorptr = 0; - double x = strtod(ptr+1, &errorptr); - if (errno || *errorptr != 0) { + double x = vstrtonum(ptr+1,10,-9999.9999,Journal()); + if (x == -9999.9999) { Journal() << "LataOptions error reading float parameter: " << s << endl; throw; } diff --git a/src/databases/lata/LmlReader.C b/src/databases/lata/LmlReader.C index 08fd082d3a..8d15e4acdd 100644 --- a/src/databases/lata/LmlReader.C +++ b/src/databases/lata/LmlReader.C @@ -34,6 +34,8 @@ #include #include #include +#include +using StringHelpers::vstrtonum; // lml files contain double precision values that can overflow or underflow // if converted to float. Check for overflow, ignore underflow static inline float double_to_float(double x) @@ -169,7 +171,7 @@ void lml_reader(const char * lmlfilename, const char * data_filename, LataDB & l elements.nb_comp_ = 6; } else if (motlu.debute_par("POLYEDRE_")) { lata_db.set_elemtype(tstep, elements.geometry_, motlu); - elements.nb_comp_ = atoi(((const char *)motlu) + strlen("polyedre_")); + elements.nb_comp_ = vstrtonum(((const char *)motlu) + strlen("polyedre_")); borne_index_min=-1; } else { Journal() << "Error reading TOPOLOGIE: unknown element type" << endl; diff --git a/src/engine/main/Engine.C b/src/engine/main/Engine.C index 8eedad2649..e838504ec3 100644 --- a/src/engine/main/Engine.C +++ b/src/engine/main/Engine.C @@ -2056,6 +2056,8 @@ Engine::ProcessInput() // Kathleen Biagas, Wed Aug 17, 2022 // Incorporate ARSanderson's OSPRAY 2.8.0 work for VTK 9. // +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoX/strtoX with vstrtonum // **************************************************************************** void @@ -2079,8 +2081,8 @@ Engine::ProcessCommandLine(int argc, char **argv) } else if (strcmp(argv[i], "-n-gpus-per-node") == 0 && i+1 < argc) { - if(!StringHelpers::str_to_u_numeric(argv[i+1], - &this->nDisplays)) + this->nDisplays = StringHelpers::vstrtonum(argv[i+1], 10, 99999); + if (this->nDisplays == 99999) { if (DebugStream::Level1()) { diff --git a/src/launcher/main/SocketRelayMain.C b/src/launcher/main/SocketRelayMain.C index 6f08be3183..1994c5f5d2 100644 --- a/src/launcher/main/SocketRelayMain.C +++ b/src/launcher/main/SocketRelayMain.C @@ -5,9 +5,11 @@ #include #include #include -#include #include +#include +#include + // **************************************************************************** // Function: main @@ -22,7 +24,8 @@ // Creation: Thu Jan 14 15:21:38 PST 2010 // // Modifications: -// +// Mark C. Miller, Fri Jan 12 17:04:46 PST 2024 +// Replace atoi with vstrtonum // **************************************************************************** int main(int argc, const char* argv[]) @@ -34,7 +37,7 @@ int main(int argc, const char* argv[]) } const char *remoteHost = argv[1]; - int remotePort = std::atoi(argv[2]); + int remotePort = StringHelpers::vstrtonum(argv[2]); // Like in the component launcher we pick a random port and assume that // it is available.