aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--parse_csv.c33
-rw-r--r--parse_csv.h3
-rw-r--r--poiss.c26
3 files changed, 32 insertions, 30 deletions
diff --git a/parse_csv.c b/parse_csv.c
index 12e98f3..423fe77 100644
--- a/parse_csv.c
+++ b/parse_csv.c
@@ -168,17 +168,42 @@ vector<vector<datum> > readCSV(istream &in) {
return table;
}
+// Scan the data array,
+// looking for records that look like headers
+// (as opposed to numerical data).
+template<class datum = qstring>
+int count_header(vector<vector<datum> > const aoa){
+ int NR = aoa.size();
+ int hh = 0;
+ for (; hh < NR; hh++) {
+ if (aoa[hh].size() == 0) continue;
+ string word = aoa[hh][0];
+ size_t where;
+ where = word.find_first_not_of(" ");
+ if (where == string::npos) continue;
+ word = word.substr(where);
+ try {
+ stod(word, &where); // don't care about return value
+ }
+ catch (exception& ee) {
+ continue;
+ }
+ word = word.substr(where);
+ where = word.find_first_not_of(" ");
+ if (where == string::npos) break;
+ }
+ return hh;
+}
+
// Explicit instantiation for the <qstring> version.
// If you want some other version, you'll have to instantiate it.
template vector<qstring> readCSVRow<qstring>(istream& input);
template vector<vector<qstring> >readCSV<qstring>(istream &in);
-// Apparently it's not necessary to mention get_q() here,
-// but probably more portable to do it anyway:
-////template int get_q<qstring>(qstring const&);
+template int count_header(vector<vector<qstring> > const aoa);
#if 1
// Explicit instantiation for the <string> version.
template vector<string> readCSVRow<string>(istream& input);
template vector<vector<string> >readCSV<string>(istream &in);
-/////template int get_q<string>(string const&);
+template int count_header(vector<vector<string> > const aoa);
#endif
diff --git a/parse_csv.h b/parse_csv.h
index 362c478..771e8fe 100644
--- a/parse_csv.h
+++ b/parse_csv.h
@@ -31,4 +31,7 @@ std::vector<datum> readCSVRow(std::istream& input);
template <class datum = qstring>
std::vector<std::vector<datum> > readCSV(std::istream &in);
+template<class datum = qstring>
+int count_header(std::vector<std::vector<datum> > const aoa);
+
#endif
diff --git a/poiss.c b/poiss.c
index 70a20b9..a286184 100644
--- a/poiss.c
+++ b/poiss.c
@@ -148,32 +148,6 @@ double limp(unsigned int const nprm, double const* _prm,
return rslt;
}
-// Scan the data array,
-// looking for records that look like headers
-// (as opposed to numerical data).
-int count_header(vector<vector<string> > const aoa){
- int NR = aoa.size();
- int hh = 0;
- for (; hh < NR; hh++) {
- if (aoa[hh].size() == 0) continue;
- string word = aoa[hh][0];
- size_t where;
- where = word.find_first_not_of(" ");
- if (where == string::npos) continue;
- word = word.substr(where);
- try {
- stod(word, &where); // don't care about return value
- }
- catch (exception& ee) {
- continue;
- }
- word = word.substr(where);
- where = word.find_first_not_of(" ");
- if (where == string::npos) break;
- }
- return hh;
-}
-
// Some tricky heuristics.
// Guess a starting point for the fitting process
// (i.e. minimization process).