From 8bb810ec21e1bf9d8e7363af6bae8603d67552b2 Mon Sep 17 00:00:00 2001 From: Eric Bryant Date: Mon, 16 Oct 2017 00:44:41 -0400 Subject: [PATCH 1/2] new program to remove unmatched datacheck fps --- fpcull/fpcull.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 fpcull/fpcull.cpp diff --git a/fpcull/fpcull.cpp b/fpcull/fpcull.cpp new file mode 100644 index 00000000..ad153bc7 --- /dev/null +++ b/fpcull/fpcull.cpp @@ -0,0 +1,72 @@ +// Travel Mapping Project, Eric Bryant, 2017 +using namespace std; +#include +#include + +class entry +{ public: + string text; + bool cull; + entry *prev, *next; + + // init alpha + entry() {prev = 0; next = 0; cull = 0;} + // insertions + entry(entry *cursor) // cursor, in this case, is a pointer to the prev entry + { prev = cursor; + next = 0; + cull = 0; + } +}; + +bool find(string needle, entry *haystack) +{ while (haystack) + { if (needle == haystack->text) return 1; + haystack = haystack->next; + } + return 0; +} + +int main(int argc, char *argv[]) +{ entry *cList = new entry; + entry *fList = new entry; + entry *cursor; + if (argc != 4) { cout << "usage: ./fpcull CullFile FullFile OutputFile\n"; return 0; } + // init ifstreams + ifstream cFile(argv[1], ios::in); + if (!cFile.is_open()) { cout << argv[1] << " file not found!" << endl; return 0; } + ifstream fFile(argv[2], ios::in); + if (!fFile.is_open()) { cout << argv[2] << " file not found!" << endl; return 0; } + + // create cull list + cFile >> cList->text; //TODO: enclose in an IF in case hell breaks loose (IE, no text in cFile) //FIXME: see below + cursor = new entry(cList); + while (cFile >> cursor->text) //FIXME: This expects every line to be one text string and every text string to be one line. This will not always be the case. + // For example, see line 6613 of https://github.com/TravelMapping/HighwayData/blob/d33d0f6e93eec8ce7f71f31af94336a473161e5f/datacheckfps.csv + { cursor->prev->next = cursor; + cursor = new entry(cursor); + } + delete cursor; + + // create full list + fFile >> fList->text; //TODO: enclose in an IF in case hell breaks loose (IE, no text in fFile) //FIXME: see below + cursor = new entry(fList); + while (fFile >> cursor->text) //FIXME: This expects every line to be one text string and every text string to be one line. This will not always be the case. + // For example, see line 6613 of https://github.com/TravelMapping/HighwayData/blob/d33d0f6e93eec8ce7f71f31af94336a473161e5f/datacheckfps.csv + { cursor->prev->next = cursor; + cursor = new entry(cursor); + } + delete cursor; + + // flag unmatchedfps as to-be-culled + for (cursor = fList; cursor; cursor = cursor->next) + if (find(cursor->text, cList)) cursor->cull = 1; + + // output + ofstream oFile(argv[3]); + cursor = fList; + while (cursor) + { if (!cursor->cull) oFile << cursor->text << endl; + cursor = cursor->next; + } +} From 730d7deef562b32c2ca4ae8ee713d39ca62edd57 Mon Sep 17 00:00:00 2001 From: Eric Bryant Date: Sat, 21 Oct 2017 13:56:21 -0400 Subject: [PATCH 2/2] endl -> \n --- fpcull/fpcull.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fpcull/fpcull.cpp b/fpcull/fpcull.cpp index ad153bc7..7c66c4a7 100644 --- a/fpcull/fpcull.cpp +++ b/fpcull/fpcull.cpp @@ -34,9 +34,9 @@ int main(int argc, char *argv[]) if (argc != 4) { cout << "usage: ./fpcull CullFile FullFile OutputFile\n"; return 0; } // init ifstreams ifstream cFile(argv[1], ios::in); - if (!cFile.is_open()) { cout << argv[1] << " file not found!" << endl; return 0; } + if (!cFile.is_open()) { cout << argv[1] << " file not found!\n"; return 0; } ifstream fFile(argv[2], ios::in); - if (!fFile.is_open()) { cout << argv[2] << " file not found!" << endl; return 0; } + if (!fFile.is_open()) { cout << argv[2] << " file not found!\n"; return 0; } // create cull list cFile >> cList->text; //TODO: enclose in an IF in case hell breaks loose (IE, no text in cFile) //FIXME: see below