00001 #include "SundanceMeshReaderBase.hpp" 00002 #include "PlayaExceptions.hpp" 00003 #include "SundancePathUtils.hpp" 00004 #include "SundanceOut.hpp" 00005 00006 00007 using namespace Sundance; 00008 using namespace Sundance; 00009 00010 using namespace Teuchos; 00011 using namespace Sundance; 00012 00013 00014 MeshReaderBase::MeshReaderBase(const ParameterList& params) 00015 : MeshSourceBase(params), 00016 filename_() 00017 { 00018 filename_ = params.get<string>("Filename"); 00019 } 00020 00021 00022 00023 int MeshReaderBase::atoi(const std::string& x) const 00024 { 00025 #ifndef TFLOP 00026 return std::atoi(x.c_str()); 00027 #else 00028 return ::atoi(x.c_str()); 00029 #endif 00030 } 00031 00032 double MeshReaderBase::atof(const std::string& x) const 00033 { 00034 #ifndef TFLOP 00035 return std::atof(x.c_str()); 00036 #else 00037 return ::atof(x.c_str()); 00038 #endif 00039 } 00040 00041 bool MeshReaderBase::isEmptyLine(const std::string& x) const 00042 { 00043 return x.length()==0 || StrUtils::isWhite(x); 00044 } 00045 00046 bool MeshReaderBase::getNextLine(std::istream& is, std::string& line, 00047 Array<string>& tokens, 00048 char comment) const 00049 { 00050 bool rtn = false; 00051 while ((rtn=StrUtils::readLine(is, line))) 00052 { 00053 SUNDANCE_OUT(this->verb() >= 3, 00054 "read line [" << line << "]"); 00055 00056 if (line.length() > 0) line = StrUtils::before(line,comment); 00057 if (isEmptyLine(line)) continue; 00058 if (line.length() > 0) break; 00059 } 00060 tokens = StrUtils::stringTokenizer(line); 00061 return rtn; 00062 } 00063 00064 RCP<std::ifstream> MeshReaderBase::openFile(const std::string& fname, 00065 const std::string& description) const 00066 { 00067 std::string f = searchForFile(fname); 00068 RCP<std::ifstream> rtn = rcp(new std::ifstream(f.c_str())); 00069 00070 SUNDANCE_OUT(this->verb() > 2, 00071 "trying to open " << description << " file " << f); 00072 00073 TEUCHOS_TEST_FOR_EXCEPTION(rtn.get()==0 || *rtn==0, std::runtime_error, 00074 "MeshReaderBase::openFile() unable to open " 00075 << description << " file " << f); 00076 00077 SUNDANCE_OUT(this->verb() > 0, 00078 "reading " << description << " from " << fname); 00079 00080 return rtn; 00081 }