CONFIG LIB 1.5
Configuration Files Library (by TGG 2020)
Loading...
Searching...
No Matches
mass_file.cpp
1/*********************************************************************/
2/* */
3/* Config files library - (C) JM 2020 */
4/* */
5/*********************************************************************/
6/* Warszawa, 2020 */
7/*********************************************************************/
8/* */
9/* File: mass_file.h */
10/* */
11/* Author: J.Mieloszyk, modif. T.Grabowski */
12/* */
13/* Contents - MASS_FILE class definition (I/O functions) */
14/* */
15/* */
16/*********************************************************************/
17/* */
18/* */
19
20#include "mass_file.h"
21
22using namespace std;
23
24MASS_FILE::MASS_FILE( void ){ Clean (); }
25
26MASS_FILE::~MASS_FILE( void ){}
27
28void MASS_FILE::Clean( void )
29{
30 n_Masses = 0;
31
32 mObjs.resize(0);
33
34 m_glob = 0;
35 CGx_glob = 0;
36 CGy_glob = 0;
37 CGz_glob = 0;
38 Ixx_glob = 0;
39 Iyy_glob = 0;
40 Izz_glob = 0;
41 Ixy_glob = 0;
42 Iyz_glob = 0;
43 Izx_glob = 0;
44}
45
46int MASS_FILE::Read( const char *FileName )
47{
48 std::string sVal;
49
51
52 ifstream in(FileName);
53
54 if(!in)
55 return 1;
56
57 in >> sVal >> n_Masses;
58 in >> sVal >> RefInertia >> Ref_x >> Ref_y >> Ref_z;
59
60 for(int j=0; j<33; j++) //Read & remove header
61 in >> sVal;
62
63 for(unsigned int i=0; i<n_Masses; i++) //Read data rows
64 {
65 mObj.Read(in);
66 mObjs.push_back(mObj);
67 }
68
69 in.close();
70
71 return (0);
72}
73
74int MASS_FILE::Write( const char *FileName )
75{
77
78 ofstream out(FileName);
79
80 if(!out)
81 return 1;
82
83 out << fixed << setprecision(6);
84 out << setw(12) << std::left << "DataRows: " << n_Masses << endl;
85 out << setw(12) << std::left << "RefInertia: " << setw(12) << RefInertia;
86 out << setw(12) << std::left << Ref_x;
87 out << setw(12) << std::left << Ref_y;
88 out << setw(12) << std::left << Ref_z;
89 out << endl << endl;
90
91 WriteHeader(out);
92
93 for(unsigned int i=0; i<n_Masses; i++)
94 mObjs[i].Write(out, i);
95
96 out << setw(44) << std::right << "Global: ";
97
98 out << setw(36) << std::left << m_glob;
99 out << setw(12) << std::left << CGx_glob;
100 out << setw(12) << std::left << CGy_glob;
101 out << setw(12) << std::left << CGz_glob;
102 out << setw(12) << std::left << Ixx_glob;
103 out << setw(12) << std::left << Iyy_glob;
104 out << setw(12) << std::left << Izz_glob;
105 out << setw(12) << std::left << Ixy_glob;
106 out << setw(12) << std::left << Iyz_glob;
107 out << setw(12) << std::left << Izx_glob;
108
109 out.close();
110
111 return (0);
112}
113
114void MASS_FILE::WriteHeader(std::ofstream &out)
115{
116 out << setw(4) << std::left << "Id";
117 out << setw(8) << std::left << "Active";
118 out << setw(80) << std::left << "Name";
119 out << setw(12) << std::left << "Type";
120
121 out << setw(12) << std::left << "m";
122 out << setw(12) << std::left << "ro";
123 out << setw(12) << std::left << "Vol";
124
125 out << setw(12) << std::left << "CGx"; // CG global
126 out << setw(12) << std::left << "CGy";
127 out << setw(12) << std::left << "CGz";
128
129 out << setw(12) << std::left << "Ixx";
130 out << setw(12) << std::left << "Iyy";
131 out << setw(12) << std::left << "Izz";
132 out << setw(12) << std::left << "Ixy";
133 out << setw(12) << std::left << "Iyz";
134 out << setw(12) << std::left << "Izx";
135
136 out << setw(12) << std::left << "Base_x"; // Base point
137 out << setw(12) << std::left << "Base_y"; // Base point
138 out << setw(12) << std::left << "Base_z"; // Base point
139 out << setw(12) << std::left << "Tip_x"; // Direction component
140 out << setw(12) << std::left << "Tip_y"; // Direction component
141 out << setw(12) << std::left << "Tip_z"; // Direction component
142 out << setw(12) << std::left << "Side_x"; // Direction component
143 out << setw(12) << std::left << "Side_y"; // Direction component
144 out << setw(12) << std::left << "Side_z"; // Direction component
145
146 out << setw(12) << std::left << "R";
147 out << setw(12) << std::left << "r";
148 out << setw(12) << std::left << "H";
149 out << setw(12) << std::left << "a";
150 out << setw(12) << std::left << "b";
151 out << setw(12) << std::left << "c";
152 out << setw(12) << std::left << "th";
153
154 out << setw(4) << std::left << "Color" << endl;
155}
156
int Read(const char *FileName)
reads masses file
Definition mass_file.cpp:46
double Iyy_glob
global inertia moment wrt CG [kg m^2]
Definition mass_file.h:48
unsigned int RefInertia
type of origin for inertia moment computation: CG/CS/Arbitrary
Definition mass_file.h:36
double Ixx_glob
global inertia moment wrt CG [kg m^2]
Definition mass_file.h:47
std::vector< MASS_OBJECT_DATA > mObjs
vector of mass objects
Definition mass_file.h:41
unsigned int n_Masses
number of mass objects
Definition mass_file.h:35
double Izx_glob
global inertia moment wrt CG [kg m^2]
Definition mass_file.h:52
double CGx_glob
global CG position X [m]
Definition mass_file.h:44
double Izz_glob
global inertia moment wrt CG [kg m^2]
Definition mass_file.h:49
void Clean()
cleans local variables
Definition mass_file.cpp:28
double Iyz_glob
global inertia moment wrt CG [kg m^2]
Definition mass_file.h:51
double Ref_y
arbitrary reference point y coordinate
Definition mass_file.h:38
double CGy_glob
global CG position Y [m]
Definition mass_file.h:45
double Ref_z
arbitrary reference point z coordinate
Definition mass_file.h:39
int Write(const char *Filename)
writes masses file
Definition mass_file.cpp:74
double CGz_glob
global CG position Z [m]
Definition mass_file.h:46
double Ixy_glob
global inertia moment wrt CG [kg m^2]
Definition mass_file.h:50
double Ref_x
arbitrary reference point x coordinate
Definition mass_file.h:37
double m_glob
global mass value [kg]
Definition mass_file.h:43
MASS_OBJECT_DATA class and functions.
Definition mass_data.h:54
void Read(std::ifstream &in)
reads single mass object