Changeset 434 for trunk/lib/gslapi/matrix.cc
- Timestamp:
- Dec 15, 2005, 12:23:46 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/gslapi/matrix.cc
r421 r434 5 5 #include <c++_tools/gslapi/vector.h> 6 6 #include <c++_tools/utility/stl_utility.h> 7 #include <c++_tools/utility/utility.h> 7 8 8 9 #include <cmath> … … 31 32 32 33 33 34 34 // Constructor that gets data from istream 35 matrix::matrix(std::istream& is) throw (utility::IO_error,std::exception) 35 matrix::matrix(std::istream& is, char sep) 36 throw (utility::IO_error,std::exception) 36 37 : view_(NULL) 37 38 { 39 // Markus to Jari, somewhere we should check that quiet_NaNs are supported 40 // std::numeric_limits<double>::has_quiet_NaN has to be true. 41 // Also in vector 42 38 43 // read the data file and store in stl vectors (dynamically 39 44 // expandable) … … 41 46 u_int nof_columns=0; 42 47 u_int nof_rows = 0; 43 std:: vector<double> v;44 for (nof_rows = 0; utility::read_to_double(is, v); nof_rows++){48 std::string line; 49 while(getline(is, line, '\n')){ 45 50 // Ignoring empty lines 46 if (!v.size()) { 47 nof_rows--; 51 if (!line.size()) { 48 52 continue; 49 53 } 54 nof_rows++; 55 std::vector<double> v; 56 std::string element; 57 std::stringstream ss(line); 58 bool ok=true; 59 while(ok) { 60 if(sep=='\0') 61 ok=(ss>>element); 62 else 63 ok=getline(ss, element, sep); 64 if(!ok) 65 break; 66 67 if(utility::is_double(element)) { 68 v.push_back(atof(element.c_str())); 69 } 70 else if (!element.size() || utility::is_nan(element)) { 71 v.push_back(std::numeric_limits<double>::quiet_NaN()); 72 } 73 else { 74 // Jari, this should be communicated with as an exception. 75 // std::cerr << "Warning: '" << vec_str[i] 76 // << "' is not an integer." << std::endl; 77 } 78 } 50 79 if (!nof_columns) 51 80 nof_columns=v.size(); 52 81 else if (v.size()!=nof_columns) { 53 82 std::ostringstream s; 54 s << "matrix::matrix(std::istream& ) data file error: "83 s << "matrix::matrix(std::istream&, char) data file error: " 55 84 << "line" << nof_rows+1 << " has " << v.size() 56 85 << " columns; expected " << nof_columns << " columns."; … … 68 97 gsl_matrix_set( m_, i, j, data_matrix[i][j] ); 69 98 } 70 71 99 72 100
Note: See TracChangeset
for help on using the changeset viewer.