Commit 6ef8ba85 authored by Alvarez, Gonzalo's avatar Alvarez, Gonzalo
Browse files

InputNg reads file between words

parent b89a9a85
Loading
Loading
Loading
Loading
+71 −22
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ DISCLOSED WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS.
#include "Map.h"
#include "Matrix.h"
#include "loki/TypeTraits.h"
#include "PsiBase64.h"

namespace PsimagLite {

@@ -161,6 +162,22 @@ public:
		      file_(file),
		      inputCheck_(inputCheck),
		      verbose_(false)
		{
			internal(file);
		}

		Writeable(const String& file,
		          const InputCheckType& inputCheck,
		          PsimagLite::String start,
		          PsimagLite::String end)
		    : data_(""),
		      line_(0),
		      state_(IN_LABEL),
		      numericVector_(0),
		      lastLabel_(""),
		      file_(file),
		      inputCheck_(inputCheck),
		      verbose_(false)
		{
			std::ifstream fin(file.c_str());
			if (!fin || !fin.good() || fin.bad()) {
@@ -169,34 +186,39 @@ public:
				throw RuntimeError(s.c_str());
			}

			char c=0;
			PsimagLite::String buffer = "";
			int mode = 0;
			while (!fin.eof()) {
				fin.get(c);
				data_ += c;
				PsimagLite::String str;
				fin>>str;
				if (str == start) {
					mode = 1;
					continue;
				}

			fin.close();
			check();
				if (str = end) {
					mode = 2;
					break;
				}

			if (verbose_) {
				std::cout<<"START\n";
				printMap(mapStrStr_,"StrStr");
				std::cout<<"END\nSTART\n";
				printMap(mapStrVec_,"StrVec");
				std::cout<<"END\n";
				if (mode == 1) buffer += str;
			}

			if (mode == 0) {
				internal(file);
				return;
			}

		Writeable(const String& data, const InputCheckType& inputCheck, int)
		    : data_(data),
		      line_(0),
		      state_(IN_LABEL),
		      numericVector_(0),
		      lastLabel_(""),
		      file_("-"),
		      inputCheck_(inputCheck),
		      verbose_(false)
		{
			if (mode == 1) {
				String s(__FILE__);
				s += " File " + file + " contains " + start + " but no " + end +"\n";
				throw RuntimeError(s.c_str());
			}

			assert(mode == 2);

			PsiBase64 base;
			data_ = base.decode(buffer);
			check();

			if (verbose_) {
@@ -223,6 +245,33 @@ public:

	private:

		void internal(PsimagLite::String file)
		{
			std::ifstream fin(file.c_str());
			if (!fin || !fin.good() || fin.bad()) {
				String s(__FILE__);
				s += " Cannot open file " + file + "\n";
				throw RuntimeError(s.c_str());
			}

			char c=0;
			while (!fin.eof()) {
				fin.get(c);
				data_ += c;
			}

			fin.close();
			check();

			if (verbose_) {
				std::cout<<"START\n";
				printMap(mapStrStr_,"StrStr");
				std::cout<<"END\nSTART\n";
				printMap(mapStrVec_,"StrVec");
				std::cout<<"END\n";
			}
		}

		void check()
		{
			String buffer="";