source: src/Matrix.cpp@ 6bc51d

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 6bc51d was 6bc51d, checked in by Saskia Metzler <metzler@…>, 15 years ago

Work-in-progress commit of change tracker and parser

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * Matrix.cpp
3 *
4 * Created on: Mar 2, 2010
5 * Author: metzler
6 */
7
8/**
9 * Gets the value as string.
10 */
11string FieldContent::getAsString() {
12 return value;
13}
14
15/**
16 * Gets the value as integer.
17 */
18int FieldContent::getAsInt() {
19 return value.intVal();
20}
21
22/**
23 * Gets the value as double.
24 */
25double FieldContent::getAsDouble() {
26 return value.getAsdouble();
27}
28
29/**
30 * Sets the value as string.
31 */
32void FieldContent::set(string valueToSet) {
33 value = valueToSet;
34}
35
36/**
37 * Sets the value as string.
38 */
39void FieldContent::set(int valueToSet) {
40 value = string(valueToSet);
41}
42
43/**
44 * Sets the value as string.
45 */
46void FieldContent::set(double valueToSet) {
47 value = string(valueToSet);
48}
49
50/**
51 * Matrix constructor.
52 *
53 * \param number of rows to initialize the matrix with
54 * \param number of columns to initialize the matrix with
55 */
56Matrix::Matrix() {
57 fields = new vector<vector<FieldContent> >();
58}
59
60/**
61 * Matrix destructor.
62 */
63Matrix::~Matrix() {
64 vector<vector<FieldContent> >::iterator row;
65 for (row = fields.begin(); row < fields.end(); it++ )
66 delete(*row);
67
68 delete(fields);
69 delete(header);
70}
71
72/**
73 * Sets the matrix header.
74 *
75 * \param char* matrix header
76 */
77void setHeader(const string text) {
78 header = text;
79}
80
81/**
82 * Gets the header.
83 */
84string getHeader() {
85 return header;
86}
87
88/**
89 * Gets the number of rows.
90 */
91int getNumberOfRows() {
92 return numberOfRows;
93}
94
95/**
96 * Gets the number of columns.
97 */
98int getNumberOfColumns() {
99 return numberOfColumns;
100}
101
102/**
103 * Sets the value of a field.
104 *
105 * \param row index
106 * \param column index
107 * \param value to set
108 */
109void setField(int rowIndex, int columnIndex, FieldContent value) {
110 fields[rowIndex][columnIndex] = value;
111}
112
113/**
114 * Gets the value of a field.
115 *
116 * \param row index
117 * \param column index
118 */
119FieldContent getField(int rowIndex, int columnIndex) {
120 return fields[rowIndex][columnIndex];
121}
122
123/**
124 * Constructor which initializes the reader with default delimiters.
125 */
126MatrixReader::MatrixReader() : skipBegin('#'), skipEnd('\n'),
127 columnSeparator('\t'), rowBegin(''), rowEnd('\n') {}
128
129/**
130 * Constructor for customized delimiters.
131 *
132 * \param column separating character
133 * \param row begin indicator
134 * \param row end indicator
135 * \param comment begin indicator
136 * \param comment end indicator
137 */
138MatrixReader::MatrixReader(char columnSep, char rowInitializer, char rowTerminator, char skipInitiator, char skipTerminator) :
139 skipBegin(skipInitiator), skipEnd(skipTerminator), columnSeparator(columnSep),
140 rowBegin(rowInitializer), rowEnd(rowTerminator) {}
141
142/**
143 * Determines the number of columns assuming that the number of columns found in
144 * the first data line is appropriate for all other lines.
145 *
146 * \return number of columns
147 */
148int MatrixReader::determineNumberOfColumns() {
149
150}
151
152/**
153 * Reads a matrix from a given file using the default delimiter set consisting
154 * of \t (tab) separating columns and \n (newline) separating rows if not
155 * initialized differently
156 *
157 * \param file name where to read the matrix from
158 * \param number of initial rows to skip
159 * \param number of initial columns to skip
160 */
161Matrix* MatrixReader::read(char* fileName, int rowOffset, int columnOffset) {
162
163}
164
165/**
166 * Writes a matrix to a file.
167 *
168 * \param file name
169 * \param matrix to write
170 * \param column separating character
171 * \param row begin indicating character
172 * \param row end indicating character
173 */
174void write(char* fileName, Matrix* matrix, char columnSeparator, char rowInitializer, char rowTerminator) {
175 ofstream output;
176 stringstream line;
177
178 line << fileName;
179 output.open(line.str().c_str(), ios::out);
180 if (output == NULL) {
181 throw new Exception("Unable to open matrix output file %s.\n", line.str());
182 }
183 output << matrix->getHeader() << endl;
184 for(int i = 0; i < matrix->getNumberOfRows(); i++) {
185 output << rowInitializer;
186 for(int j = 0; j < matrix->getNumberOfColumns(); j++) {
187 output << scientific << matrix->getField(j, k) << columnSeparator;
188 }
189 output << rowTerminator;
190 }
191 output.close();
192}
Note: See TracBrowser for help on using the repository browser.