old_code/InputFile.cpp
// Helper function to convert ASCII line into vector of values
Helper function to convert ASCII line into vector of values
Helper function to convert ASCII line into vector of values
static bool GetValues(std::istream& is, const std::string& file_name, std::vector<double>& values,
                      char delim, char comment_marker, long& row_num)
{
    if (!is) return false;
    char first = is.peek();
    while (std::isspace(first)) { is.get(first); first = is.peek(); }
    if (first == comment_marker) {
        is.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
        return GetValues(is,file_name,values,delim,comment_marker,row_num);
    }
    const int nval = values.size();
    if (delim == '\0') {
        double temp;
        for(int i=0;i<nval;++i) {
            is >> temp;
            values[i] = temp;
        }
    } else {
        ConvertibleString temp;
        for(int i=0;i<nval;++i) {
            getline(is,temp,delim);
            values[i] = temp;
        }
    }
    if (!is) return false;
    is.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    bool has_nan = false;
    for(int i=0;i<nval;++i) if (IsNan(values[i])) has_nan = true;
    if (has_nan) {
        std::cerr<<"WARNING: Skipping row "<<row_num<<" in "<<file_name<<
            " because it has a NaN.\n";
        ++row_num;
        return GetValues(is,file_name,values,delim,comment_marker,row_num);
    }
    return true;
}
static bool GetValues ( std :: istream & is , const std :: string & file_name , std :: vector < double > & values , char delim , char comment_marker , long & row_num ) { if ( ! is ) return false ; char first = is . peek ( ) ; while ( std :: isspace ( first ) ) { is . get ( first ) ; first = is . peek ( ) ; } if ( first == comment_marker ) { is . ignore ( std :: numeric_limits < std :: streamsize > :: max ( ) , ' \n ' ) ; return GetValues ( is , file_name , values , delim , comment_marker , row_num ) ; } const int nval = values . size ( ) ; if ( delim == ' \0 ' ) { double temp ; for ( int i = 0 ; i < nval ; ++ i ) { is >> temp ; values [ i ] = temp ; } } else { ConvertibleString temp ; for ( int i = 0 ; i < nval ; ++ i ) { getline ( is , temp , delim ) ; values [ i ] = temp ; } } if ( ! is ) return false ; is . ignore ( std :: numeric_limits < std :: streamsize > :: max ( ) , ' \n ' ) ; bool has_nan = false ; for ( int i = 0 ; i < nval ; ++ i ) if ( IsNan ( values [ i ] ) ) has_nan = true ; if ( has_nan ) { std :: cerr << " " << row_num << " " << file_name << " \n " ; ++ row_num ; return GetValues ( is , file_name , values , delim , comment_marker , row_num ) ; } return true ; }
Helper function to convert ASCII line into vector of values
Helper function to convert ASCII line into vector of values
// Check that the istream is valid to start with. // Skip if this is a comment. // Skip initial whitespace // If now starts with comment_marker, skip this line. // Read values // Read to the end of the line // Skip this line if there are any nan's in the input.