Blame view

src/ParamOutputImpl/Download/FileWriterASCIITabular.cc 4.1 KB
fbe3c2bb   Benjamin Renard   First commit
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
/**
 * FileWriterASCIIATabular.cc
 *  Created on: 21 oct. 2014
 *      Author: AKKA
 */

#include "FileWriterASCIITabular.hh"

namespace AMDA {
namespace ParamOutputImpl {
namespace Download {
namespace FileWriter {

FileWriterASCIITabular::FileWriterASCIITabular(AMDA::Parameters::ParameterManager& pParameterManager) :
		FileWriterASCIIAbstract(pParameterManager)
{
}

FileWriterASCIITabular::~FileWriterASCIITabular(void)
{
}

std::string FileWriterASCIITabular::getExtension(void)
{
	return "txt";
}

std::string FileWriterASCIITabular::getDataFillCharacter(void)
{
	return " ";
}

9d8ec7d4   Benjamin Renard   Define a specific...
33
34
std::string FileWriterASCIITabular::getNanString(void)
{
120932d0   Benjamin Renard   Replace nan by Na...
35
	return "NaN";
9d8ec7d4   Benjamin Renard   Define a specific...
36
37
}

fbe3c2bb   Benjamin Renard   First commit
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
void FileWriterASCIITabular::writeBeginFile(void)
{
	//nothing to do
}

void FileWriterASCIITabular::writeEndFile(void)
{
	//nothing to do
}

void FileWriterASCIITabular::writeBeginGeneralDescription(void)
{
	//nothing to do
}

void FileWriterASCIITabular::writeEndGeneralDescription(void)
{
	//nothing to do
}

void FileWriterASCIITabular::writeErrorInfo(std::string msg)
{
	if (!_outputFile.is_open())
		return;
	_outputFile << msg;
}

void FileWriterASCIITabular::writeBeginInfoGroup(std::string title, int level)
{
	if (!_outputFile.is_open())
		return;

	if (title.empty() || level > 0)
	{
		_outputFile << "#" << std::endl;
		return;
	}

	std::string fullTitle = title;
	fullTitle += " :";

	std::string separatorLine;
	for (unsigned int i = 0; i < fullTitle.size(); ++i)
		separatorLine += "-";

	_outputFile << "# " << separatorLine << std::endl;
	_outputFile << "# " << fullTitle << std::endl;
	_outputFile << "# " << separatorLine << std::endl;
}

void FileWriterASCIITabular::writeEndInfoGroup(int level)
{
	if (!_outputFile.is_open())
		return;
	if (level == 0)
		_outputFile << "#" << std::endl;
}

void FileWriterASCIITabular::writeSingleInfo(std::string key, std::string value, int level)
{
	if (!_outputFile.is_open())
		return;
	std::string prefix;
	for (int i = 0; i < level; ++i)
		prefix += "  ";
c49df00f   Benjamin Renard   Fix #5375 - heade...
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
	std::stringstream ss(value);
	std::string info_line;
	bool first_line = true;
	while(std::getline(ss,info_line,'\n')){
		_outputFile << "# " << prefix;
		if (first_line) {
			_outputFile << key << " : ";
			first_line = false;
		}
		else {
			for (int i = 0; i < (int)key.size()+3; ++i)
				_outputFile << " ";
		}
		_outputFile << info_line << std::endl;
	}
fbe3c2bb   Benjamin Renard   First commit
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
}

void FileWriterASCIITabular::writeBeginInfoList(std::string /*title*/, int /*level*/)
{
	//nothing to do
}

void FileWriterASCIITabular::writeEndInfoList(void)
{
	//nothing to do
}

void FileWriterASCIITabular::writeBeginFieldsDescription(void)
{
	if (!_outputFile.is_open())
		return;
	writeBeginInfoGroup("DATA", 0);
	_outputFile << "# DATA_COLUMNS : ";
}

void FileWriterASCIITabular::writeEndFieldsDescription(void)
{
	if (!_outputFile.is_open())
		return;
	_outputFile << std::endl;
	_outputFile << "#" << std::endl;
}

void FileWriterASCIITabular::writeFieldDescription(std::string paramId)
{
	if (!_outputFile.is_open())
		return;

	if (_fieldInfoMap[paramId].type != DT_TIME)
		_outputFile << ", ";

	if (_fieldInfoMap[paramId].dimSize1 * _fieldInfoMap[paramId].dimSize2 == 1)
	{
		//it's a scalar
		_outputFile << paramId;
	}
	else
	{
		bool isfirstComponent = true;
		for (auto component : _fieldInfoMap[paramId].componentsList)
		{
			if (!isfirstComponent)
				_outputFile << ", ";
			_outputFile << paramId << "[" << component.getDim1Index();
			if (_fieldInfoMap[paramId].dimSize2 > 1)
				_outputFile << "," << component.getDim2Index();
			_outputFile << "]";
			isfirstComponent = false;
		}
	}
}

void FileWriterASCIITabular::writeBeginData(void)
{
	//nothing to do
}

void FileWriterASCIITabular::writeEndData(void)
{
	//nothing to do
}

std::string FileWriterASCIITabular::getDataStartTag(bool /* isTimeData */)
{
	return "";
}

std::string FileWriterASCIITabular::getDataStopTag(void)
{
	return "";
}

void FileWriterASCIITabular::writeDataRecord(std::string record)
{
	if (!_outputFile.is_open())
		return;
	_outputFile << record << std::endl;
}

std::string FileWriterASCIITabular::getDataValueSeparator(void)
{
	return "";
}

} /* namespace FileWriter */
} /* namespace Download */
} /* namespace ParamOutputImpl */
} /* namespace AMDA */