-
Notifications
You must be signed in to change notification settings - Fork 0
/
addtoxcdf.cpp
57 lines (44 loc) · 1.14 KB
/
addtoxcdf.cpp
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
#include <iostream>
//#include "TMath.h"
#include <fstream>
#include <string>
#include <vector>
#include <xcdf/XCDF.h>
#include <xcdf/XCDFField.h>
#include <xcdf/XCDFFile.h>
#include <xcdf/utility/XCDFUtility.h>
#include <sstream>
using namespace std;
template <class Type>
Type stringToNum(const string& str)
{
istringstream iss(str);
Type num;
iss >> num;
return num;
}
int main(int argc, char** argv) {
//char* name=getFileName(argv[0]);
XCDFFile rec;
rec.Open(argv[1], "r");
XCDFFile recFile(argv[2],"w");
FieldCopyBuffer buffer(recFile);
XCDFFloatingPointField newfield = recFile.AllocateFloatingPointField("rec.proba", 0.000000001);
std::set<std::string> fields;
GetFieldNamesVisitor getFieldNamesVisitor(fields);
rec.ApplyFieldVisitor(getFieldNamesVisitor);
SelectFieldVisitor selectFieldVisitor(rec, fields, buffer);
rec.ApplyFieldVisitor(selectFieldVisitor);
ifstream file ( argv[3]);
string value;
while ( rec.Read() )
{
getline ( file, value);
newfield <<stringToNum<double>(value);
buffer.CopyData();
recFile.Write();
}
rec.Close();
recFile.Close();
return 0;
}