Blame view

src/ParamOutputImpl/Download/FileWriterASCIIVOTable.cc 5.96 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
/**
 * FileWriterASCIIVOTable.cc
 *  Created on: 21 oct. 2014
 *      Author: AKKA
 */

#include "FileWriterASCIIVOTable.hh"
#include "TimeUtil.hh"

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

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

FileWriterASCIIVOTable::~FileWriterASCIIVOTable(void)
{
	if (_outputFile.is_open())
		writeEndFile();
}

4f3abe6a   Benjamin Renard   Give the possibil...
26
bool FileWriterASCIIVOTable::isInfoInSeparateFile(bool /* separateInfoFile */, bool /* onlyOneInterval */, OutputStructure /* outputStructure */)
fbe3c2bb   Benjamin Renard   First commit
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{
	return false;
}

std::string FileWriterASCIIVOTable::getExtension(void)
{
	return "vot";
}

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

9d8ec7d4   Benjamin Renard   Define a specific...
41
42
43
44
45
std::string FileWriterASCIIVOTable::getNanString(void)
{
	return "NaN";
}

fbe3c2bb   Benjamin Renard   First commit
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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
void FileWriterASCIIVOTable::writeBeginFile(void)
{
	if (!_outputFile.is_open())
		return;
	_outputFile << "<?xml version=\"1.0\"?>" << std::endl;
	_outputFile << "<VOTABLE version=\"1.3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.ivoa.net/xml/VOTable/v1.3\" xmlns:stc=\"http://www.ivoa.net/xml/STC/v1.30\">" << std::endl;
	_outputFile << "  <RESOURCE name=\"CDPP/AMDA Resource\">" << std::endl;
	_outputFile << "    <TABLE name=\"CDPP/AMDA Table\">" << std::endl;

}

void FileWriterASCIIVOTable::writeEndFile(void)
{
	if (!_outputFile.is_open())
		return;
	_outputFile << "    </TABLE>" << std::endl;
	_outputFile << "  </RESOURCE>" << std::endl;
	_outputFile << "</VOTABLE>" << std::endl;
}

void FileWriterASCIIVOTable::writeBeginGeneralDescription(void)
{
	if (!_outputFile.is_open())
		return;
	_outputFile << "      <DESCRIPTION>" << std::endl;
}

void FileWriterASCIIVOTable::writeEndGeneralDescription(void)
{
	if (!_outputFile.is_open())
		return;
	_outputFile << "      </DESCRIPTION>" << std::endl;
}

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

void FileWriterASCIIVOTable::writeBeginInfoGroup(std::string title, int level)
{
	if (!_outputFile.is_open())
		return;
	if (title.empty() || level > 0)
		_outputFile << std::endl;
	else
		_outputFile << "* " << title << " :" << std::endl;
}

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

void FileWriterASCIIVOTable::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 += "  ";
	_outputFile << prefix << key << " : " << value << std::endl;
}

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

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

void FileWriterASCIIVOTable::writeBeginFieldsDescription(void)
{
	//nothing to do
}

void FileWriterASCIIVOTable::writeEndFieldsDescription(void)
{
	//nothing to do
}

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

	_outputFile << "      <FIELD name=\"";
	_outputFile << _fieldInfoMap[paramId].name << "\" ID=\"";
	_outputFile << paramId << "\" ucd=\"";
	_outputFile << _fieldInfoMap[paramId].ucd << "\" datatype=\"";

	switch (_fieldInfoMap[paramId].type)
	{
	case DT_FLOAT :
		_outputFile << "float\" utype=\"\"";
		break;
	case DT_SHORT :
	case DT_LOGICAL :
		_outputFile << "short\" utype=\"\"";
		break;
	case DT_INT :
		_outputFile << "int\" utype=\"\"";
		break;
	case DT_DOUBLE :
	case DT_LONGDOUBLE :
		_outputFile << "double\" utype=\"\"";
		break;
	case DT_TIME :
		_outputFile << "char\" xtype=\"dateTime\" utype=\"\"";
		break;
	default:
		_outputFile << "\"";
	}

	_outputFile << " arraysize=\"";
	if ((_fieldInfoMap[paramId].type != DT_TIME) &&
		!_fieldInfoMap[paramId].componentsList.empty() &&
		(_fieldInfoMap[paramId].dimSize1 * _fieldInfoMap[paramId].dimSize2 != (int)_fieldInfoMap[paramId].componentsList.size()))
	{
		//some components are not write
		_outputFile << _fieldInfoMap[paramId].componentsList.size();
	}
	else if (_fieldInfoMap[paramId].type == DT_TIME)
		_outputFile << "*";
	else
	{
		//all components are write
		_outputFile <<  _fieldInfoMap[paramId].dimSize1;
		if (_fieldInfoMap[paramId].dimSize2 > 1)
		{
			_outputFile <<  "x";
			_outputFile <<  _fieldInfoMap[paramId].dimSize2;
		}
	}
	_outputFile << "\"";

	_outputFile << "/>" << std::endl;
}

void FileWriterASCIIVOTable::writeBeginData(void)
{
	if (!_outputFile.is_open())
		return;
	_outputFile << "      <DATA>" << std::endl;
	_outputFile << "        <TABLEDATA>" << std::endl;
}

void FileWriterASCIIVOTable::writeEndData(void)
{
	if (!_outputFile.is_open())
		return;
	_outputFile << "        </TABLEDATA>" << std::endl;
	_outputFile << "      </DATA>" << std::endl;
}

void FileWriterASCIIVOTable::writeDataRecord(std::string record)
{
	if (!_outputFile.is_open())
		return;
	_outputFile << "          <TR>" << std::endl;
	_outputFile << record << std::endl;
	_outputFile << "          </TR>" << std::endl;
}

std::string FileWriterASCIIVOTable::getDataStartTag(bool isTimeData)
{
	if (isTimeData)
		return "            <TD>";
	return "<TD>";
}

std::string FileWriterASCIIVOTable::getDataStopTag(void)
{
	return "</TD>";
}

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

bool FileWriterASCIIVOTable::writeTimeData(std::string paramId, double data, OutputFormatTime /*timeFormat*/, bool isFirstParam)
{
	//force ISO format for time field
	if (!isFirstParam)
			return true; //time already write for this record, no error

	std::fstream *crtFile = _fieldInfoMap[paramId].file;
	if (crtFile == NULL)
		return false;

	(*crtFile) << getDataStartTag(true);

	TimeUtil::formatTimeDateInIso(data, *crtFile);

	(*crtFile) << "Z";

	(*crtFile) << getDataStopTag();

	return true;
}

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