Skip to content

Commit

Permalink
itextstream: Make operator bool() fail if all bound fields weren't read
Browse files Browse the repository at this point in the history
Make it easier to detect malformed input files (e.g., those missing columns).
  • Loading branch information
mjuric committed Apr 14, 2010
1 parent c707945 commit 094dc8e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
20 changes: 10 additions & 10 deletions galaxy.kdevelop
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<kdevautoproject>
<general>
<activetarget>src/galfast.x</activetarget>
<useconfiguration>debug</useconfiguration>
<useconfiguration>optimized</useconfiguration>
</general>
<run>
<mainprogram>/home/mjuric/projects/galaxy/debug/src/galfast.x</mainprogram>
Expand Down Expand Up @@ -79,16 +79,16 @@
<ccompiler>kdevgccoptions</ccompiler>
<cxxcompiler>kdevgppoptions</cxxcompiler>
<f77compiler>kdevg77options</f77compiler>
<cxxflags>-O2 -g</cxxflags>
<configargs>--enable-debug=full --prefix=$HOME/projects/galaxy/workspace/staging --with-cuda --enable-cuda-devemu --with-libpeyton=$HOME/projects/libpeyton --with-libpeyton-libdir=$HOME/projects/libpeyton/lib-optimized</configargs>
<topsourcedir/>
<cxxflags>-O2 -Wstrict-aliasing -fno-strict-aliasing</cxxflags>
<configargs>--with-cuda --enable-cuda-devemuX --with-sm=/usr/local --with-libpeyton=$HOME/projects/libpeyton --prefix=$HOME/projects/galaxy/workspace/staging --with-cfitsio-include=/usr/include/cfitsio --with-libpeyton-libdir=$HOME/projects/libpeyton/lib-optimized</configargs>
<topsourcedir></topsourcedir>
<cppflags>-DDEBUGMODE=0</cppflags>
<ldflags/>
<ccompilerbinary/>
<cxxcompilerbinary/>
<f77compilerbinary/>
<cflags/>
<f77flags/>
<ldflags>-rdynamic -L/opt/cudatools/2.3/lib</ldflags>
<ccompilerbinary></ccompilerbinary>
<cxxcompilerbinary></cxxcompilerbinary>
<f77compilerbinary></f77compilerbinary>
<cflags></cflags>
<f77flags></f77flags>
<envvars/>
</optimized>
<debug>
Expand Down
18 changes: 15 additions & 3 deletions src/common/textstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ class itextstream : public textstream {
public:
int nread;
std::string line;
int m_line;
bool is_comment;
public:

public:
itextstream(std::istream &f_) : f(f_), nread(0), max_field(0), ret_comments(false) {}
itextstream(std::istream &f_) : f(f_), nread(0), max_field(0), ret_comments(false), m_line(0) {}

void bind(std::string &s, int p) { fields[p] = field(p, s); max_field = std::max(max_field, p); }
void bind(double &s, int p) { fields[p] = field(p, s); max_field = std::max(max_field, p); }
Expand All @@ -77,7 +78,13 @@ class itextstream : public textstream {
}

bool returncomments(bool rc) { ret_comments = rc; }


void getline(std::istream &is, std::string &str)
{
std::getline(is, str);
m_line++;
}

itextstream &skip(int n = 1)
{
while(n > 0)
Expand All @@ -102,6 +109,7 @@ class itextstream : public textstream {
itextstream &next()
{
nread = -1;
is_comment = false;
do {
getline(f, line);
// std::cerr << "LINE: [" << line << "] " << (bool)*this << "\n";
Expand Down Expand Up @@ -167,7 +175,11 @@ class itextstream : public textstream {
return *this;
}*/

operator bool() { return nread != -1; }
int last_line_read() const { return m_line; }

bool noerror() { return *this || f.eof(); }
operator bool() { return iscomment() || (nread == fields.size()); }
//operator bool() { return nread != -1; }
bool iscomment() { return is_comment; }
};

Expand Down
6 changes: 5 additions & 1 deletion src/modules/photometry_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ bool os_photometry::construct(const Config &cfg, otable &t, opipeline &pipe)
{
v[FeH].push_back(mc);
}
assert(!v.empty());
if(v.empty() || !in.noerror())
{
THROW(EAny, "Error reading color-metallicity-magnitude relations from '" + fname + "' around line " + str(in.last_line_read())
+ ". Is the formatted correctly, and does it contain " + str(2+ncolors) + " columns?");
}

#if 1
double dFeH, dMr;
Expand Down

0 comments on commit 094dc8e

Please sign in to comment.