1 /*
2 * Copyright (C) 2008-2012 Thorsten Liebig (Thorsten.Liebig@gmx.de)
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "tinyxml.h"
19
20 #include "CSPropDumpBox.h"
21
CSPropDumpBox(ParameterSet * paraSet)22 CSPropDumpBox::CSPropDumpBox(ParameterSet* paraSet) : CSPropProbeBox(paraSet) {Type=DUMPBOX;Init();}
CSPropDumpBox(CSProperties * prop)23 CSPropDumpBox::CSPropDumpBox(CSProperties* prop) : CSPropProbeBox(prop) {Type=DUMPBOX;Init();}
CSPropDumpBox(unsigned int ID,ParameterSet * paraSet)24 CSPropDumpBox::CSPropDumpBox(unsigned int ID, ParameterSet* paraSet) : CSPropProbeBox(ID,paraSet) {Type=DUMPBOX;Init();}
~CSPropDumpBox()25 CSPropDumpBox::~CSPropDumpBox() {}
26
Init()27 void CSPropDumpBox::Init()
28 {
29 DumpType = 0;
30 DumpMode = 0;
31 FileType = 0;
32 MultiGridLevel = 0;
33 m_SubSampling=false;
34 SubSampling[0]=1;
35 SubSampling[1]=1;
36 SubSampling[2]=1;
37 m_OptResolution=false;
38 OptResolution[0]=1;
39 OptResolution[1]=1;
40 OptResolution[2]=1;
41 }
42
SetSubSampling(int ny,unsigned int val)43 void CSPropDumpBox::SetSubSampling(int ny, unsigned int val)
44 {
45 if ((ny<0) || (ny>2)) return;
46 if (val<1) return;
47 m_SubSampling=true;
48 SubSampling[ny] = val;
49 }
50
SetSubSampling(unsigned int val[])51 void CSPropDumpBox::SetSubSampling(unsigned int val[])
52 {
53 for (int ny=0;ny<3;++ny)
54 SetSubSampling(ny,val[ny]);
55 }
56
SetSubSampling(const char * vals)57 void CSPropDumpBox::SetSubSampling(const char* vals)
58 {
59 if (vals==NULL) return;
60 std::vector<int> values = SplitString2Int(std::string(vals),',');
61 for (int ny=0;ny<3 && ny<(int)values.size();++ny)
62 SetSubSampling(ny,values.at(ny));
63 }
64
GetSubSampling(int ny)65 unsigned int CSPropDumpBox::GetSubSampling(int ny)
66 {
67 if ((ny<0) || (ny>2)) return 1;
68 return SubSampling[ny];
69 }
70
SetOptResolution(int ny,double val)71 void CSPropDumpBox::SetOptResolution(int ny, double val)
72 {
73 if ((ny<0) || (ny>2)) return;
74 if (val<0) return;
75 m_OptResolution=true;
76 OptResolution[ny] = val;
77 }
78
SetOptResolution(double val[])79 void CSPropDumpBox::SetOptResolution(double val[])
80 {
81 for (int ny=0;ny<3;++ny)
82 SetOptResolution(ny,val[ny]);
83 }
84
SetOptResolution(const char * vals)85 void CSPropDumpBox::SetOptResolution(const char* vals)
86 {
87 if (vals==NULL) return;
88 std::vector<double> values = SplitString2Double(std::string(vals),',');
89 if (values.size()==1) //allow one resolution for all directions
90 {
91 for (int ny=0;ny<3;++ny)
92 SetOptResolution(ny,values.at(0));
93 return;
94 }
95 for (int ny=0;ny<3 && ny<(int)values.size();++ny)
96 SetOptResolution(ny,values.at(ny));
97 }
98
GetOptResolution(int ny)99 double CSPropDumpBox::GetOptResolution(int ny)
100 {
101 if ((ny<0) || (ny>2)) return 1;
102 return OptResolution[ny];
103 }
104
Write2XML(TiXmlNode & root,bool parameterised,bool sparse)105 bool CSPropDumpBox::Write2XML(TiXmlNode& root, bool parameterised, bool sparse)
106 {
107 if (CSPropProbeBox::Write2XML(root,parameterised,sparse) == false) return false;
108 TiXmlElement* prop=root.ToElement();
109 if (prop==NULL) return false;
110
111 prop->SetAttribute("DumpType",DumpType);
112 prop->SetAttribute("DumpMode",DumpMode);
113 prop->SetAttribute("FileType",FileType);
114 prop->SetAttribute("MultiGridLevel",MultiGridLevel);
115
116 if (m_SubSampling)
117 {
118 std::stringstream ss;
119 ss << GetSubSampling(0) << "," << GetSubSampling(1) << "," << GetSubSampling(2) ;
120 prop->SetAttribute("SubSampling",ss.str().c_str());
121 }
122 if (m_OptResolution)
123 {
124 std::stringstream ss;
125 ss << GetOptResolution(0) << "," << GetOptResolution(1) << "," << GetOptResolution(2) ;
126 prop->SetAttribute("OptResolution",ss.str().c_str());
127 }
128
129 return true;
130 }
131
ReadFromXML(TiXmlNode & root)132 bool CSPropDumpBox::ReadFromXML(TiXmlNode &root)
133 {
134 if (CSPropProbeBox::ReadFromXML(root)==false) return false;
135
136 TiXmlElement *prop = root.ToElement();
137 if (prop==NULL) return false;
138
139 if (prop->QueryIntAttribute("DumpType",&DumpType)!=TIXML_SUCCESS) DumpType=0;
140 if (prop->QueryIntAttribute("DumpMode",&DumpMode)!=TIXML_SUCCESS) DumpMode=0;
141 if (prop->QueryIntAttribute("FileType",&FileType)!=TIXML_SUCCESS) FileType=0;
142 if (prop->QueryIntAttribute("MultiGridLevel",&MultiGridLevel)!=TIXML_SUCCESS) MultiGridLevel=0;
143
144 SetSubSampling(prop->Attribute("SubSampling"));
145 SetOptResolution(prop->Attribute("OptResolution"));
146
147 return true;
148 }
149
ShowPropertyStatus(std::ostream & stream)150 void CSPropDumpBox::ShowPropertyStatus(std::ostream& stream)
151 {
152 //skip output of prarent CSPropProbeBox
153 CSProperties::ShowPropertyStatus(stream);
154 stream << " --- Dump Properties --- " << std::endl;
155 stream << " DumpType: " << DumpType << " DumpMode: " << DumpMode << " FileType: " << FileType << " MultiGridLevel: " << MultiGridLevel << std::endl;
156 if (m_FD_Samples.size()>0)
157 stream << " Dump Frequencies: " << CombineVector2String(m_FD_Samples,',') << std::endl;
158 }
159