Changeset 597 for trunk/se/lu/thep/wenni/lib/c++_tools/gslapi/vector.cc
- Timestamp:
- Feb 28, 2008, 12:36:46 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/se/lu/thep/wenni/lib/c++_tools/gslapi/vector.cc
r110 r597 165 165 166 166 167 vector::vector(std::string& line, char sep) 168 throw (utility::IO_error,std::exception) 169 : view_(NULL), const_view_(NULL) 170 { 171 // Empty line 172 if (!line.size()) 173 return; 174 175 std::vector<double> v; 176 v.reserve(line.length()/2); 177 std::string element; 178 std::stringstream ss(line); 179 bool ok=true; 180 while(ok) { 181 if(sep=='\0') 182 ok=(ss>>element); 183 else 184 ok=getline(ss, element, sep); 185 if(!ok) 186 break; 187 188 if(utility::is_double(element)) { 189 v.push_back(atof(element.c_str())); 190 } 191 else if (!element.size() || utility::is_nan(element)) { 192 v.push_back(std::numeric_limits<double>::quiet_NaN()); 193 } 194 } 195 if (sep!='\0' && line[line.size()-1]==sep) // add NaN for final separator 196 v.push_back(std::numeric_limits<double>::quiet_NaN()); 197 198 // convert the data to a gsl vector 199 v_ = gsl_vector_alloc(v.size()); 200 size_t n=0; 201 for (size_t i=0; i<v.size(); i++) 202 gsl_vector_set(v_, n++, v[i]); 203 } 204 205 206 167 207 vector::~vector(void) 168 208 {
Note: See TracChangeset
for help on using the changeset viewer.