This repository has been archived by the owner on Nov 23, 2019. It is now read-only.
forked from yayahjb/ncdist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileWriter.h
executable file
·142 lines (124 loc) · 4.87 KB
/
FileWriter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef FILEWRITER_H
#define FILEWRITER_H
#include <list>
#include <string>
#include "Follow.h"
#include "Glitch.h"
#include "Mat66.h"
#include "G6.h"
#include "CreateFileName.h"
#include "FollowerConstants.h"
#include "FollowerTools.h"
#include "Mat66.h"
#include "G6.h"
#include "ReportTools.h"
#include "SVG_Writer.h"
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <string>
template<typename TVEC, typename TMAT>
class FileWriter
{
public:
//FileWriter( const std::string& fileName, const Follow<G6,Mat66> & follow, const std::vector<Glitch<G6> >& glitches );
//void Write( void );
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
FileWriter(const std::string& sFileName, const Follow<TVEC, TMAT> & follow, const std::vector<Glitch<TVEC> >& glitches)
: sFileName(sFileName)
, follow(follow)
, glitches(glitches)
, probePath(follow.GetProbeList())
, secondProbePath(follow.GetSecondProbeList())
, distances(follow.GetDistances())
, itDist(distances.begin())
, itP1(probePath.begin())
, itP2(secondProbePath.begin())
, itLastDist(distances.end())
/*-------------------------------------------------------------------------------------*/
{
assert(!follow.empty());
assert(!probePath.empty());
assert(probePath.size() == secondProbePath.size());
assert(probePath.size() == distances.size());
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
Glitch<TVEC> FindGlitch(const int n, const std::vector<Glitch<TVEC> >& glitches)const
/*-------------------------------------------------------------------------------------*/
{
const size_t nGlitches = glitches.size();
if (glitches.empty())
{
return(Glitch<TVEC>());
}
else
{
for (unsigned int i = 0; i<nGlitches; ++i)
{
if (n == glitches[i].GetGlitchElement1().GetPosition())
{
return(glitches[i]);
}
}
}
return(Glitch<TVEC>());
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
std::string OnePosition(const std::list<double>::const_iterator& itDist,
const typename std::vector<TVEC>::const_iterator& itP1,
const typename std::vector<TVEC>::const_iterator& itP2,
const int counter) const {
std::string s =
ToString(*itP1, " ", *itP2, " ")
+ ToString(*itDist, follow.GetBoundaryString(counter));
const Glitch<TVEC> singleGlitch = FindGlitch(counter, glitches);
if (singleGlitch.GetGlitchElement1().GetPosition() > 0)
{
s += " *****";
}
s += "\n";
return(s);
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void Write(void)
/*-------------------------------------------------------------------------------------*/
{
if (FollowerConstants::globalFollowerMode == FollowerConstants::globalWeb)
return;
std::ofstream folOut;
FollowerTools::OpenOutputFile(folOut, sFileName.c_str());
if (folOut.is_open())
{
itLastDist = distances.end();
itDist = distances.begin();
folOut << sFileName << " Output is probe cell, reduced cell, NCDist distance between" << std::endl;
typename std::list<double>::const_iterator itDist = distances.begin();
typename std::vector<TVEC>::const_iterator itP1 = probePath.begin();
typename std::vector<TVEC>::const_iterator itP2 = secondProbePath.begin();
const std::list<double>::const_iterator itLastDist = distances.end();
for (int counter = 0; itDist != itLastDist; ++itP1, ++itP2, ++itDist, ++counter)
folOut << OnePosition(itDist, itP1, itP2, counter);
folOut.close();
}
else
{
std::cout << "Could not open file " << sFileName << " for write" << std::endl;
}
}
private:
const std::string sFileName;
const Follow<TVEC,TMAT> & follow;
const std::vector<Glitch<TVEC> >& glitches;
const std::vector<TVEC> probePath;
const std::vector<TVEC> secondProbePath;
const std::list<double> distances;
std::list<double>:: const_iterator itDist;
typename std::vector<TVEC>:: const_iterator itP1;
typename std::vector<TVEC>:: const_iterator itP2;
typename std::list<double>:: const_iterator itLastDist;
//std::string OnePosition( const std::list<double>::const_iterator& itDist,
// const std::vector<G6>:: const_iterator& itP1,
// const std::vector<G6>:: const_iterator& itP2,
// const int counter ) const;
};
#endif