CONFIG LIB 1.5
Configuration Files Library (by TGG 2020)
Loading...
Searching...
No Matches
sdsa_file.cpp
1/*********************************************************************/
2/* */
3/* Config files library - (C) TGG 2015 */
4/* */
5/*********************************************************************/
6/* Warszawa, 2018 */
7/*********************************************************************/
8/* */
9/* File: sdsa_file.cpp */
10/* */
11/* Author: T.Grabowski */
12/* */
13/* Contents - sdsa file (simple output file) class definition */
14/* */
15/* */
16/*********************************************************************/
17/* */
18/* */
19
20#include "sdsa_file.h"
21
22SDSA_FILE::SDSA_FILE( void ){ Clean(); }
23
24SDSA_FILE::~SDSA_FILE( void ){}
25
26void SDSA_FILE::Clean( void )
27{
28 S = B = MAC = Swet = 0.0;
29 X = Z = 0.0;
30 Alfa = Beta = Mach = 0.0;
31 P = Q = R = 0.0;
32 Cx = Cy = Cz = Cl = Cm = Cn = 0.0;
33 Cxs = Cys = Czs = Cls = Cms = Cns = 0.0;
34 Cxi = Czi = 0.0;
35
36 file_flag = 0;
37}
38
39void SDSA_FILE::SetName( const char* SDSA_file )
40{
41 strcpy( file_name, SDSA_file );
42 file_flag = 1;
43}
44
45int SDSA_FILE::Read( const char* SDSA_file )
46{
47 FILE *File;
48 File = fopen( SDSA_file, "r" );
49 if( File == NULL )
50 {
51 fprintf( stderr, "[.sdsa] file open error to reading (%s)\n", SDSA_file );
52 return (-1);
53 }
54
55 ReadPar( File, "%lf", &S );
56 ReadPar( File, "%lf", &MAC );
57 ReadPar( File, "%lf", &B );
58 ReadPar( File, "%lf", &Swet );
59 ReadPar( File, "%lf %lf", &X, &Z );
60 ReadPar( File, "%lf", &Alfa );
61 ReadPar( File, "%lf", &Beta );
62 ReadPar( File, "%lf", &Mach );
63 ReadPar( File, "%lf", &P );
64 ReadPar( File, "%lf", &Q );
65 ReadPar( File, "%lf", &R );
66 ReadPar( File, "%lf", &Cx );
67 ReadPar( File, "%lf", &Cy );
68 ReadPar( File, "%lf", &Cz );
69 ReadPar( File, "%lf", &Cl );
70 ReadPar( File, "%lf", &Cm );
71 ReadPar( File, "%lf", &Cn );
72 ReadPar( File, "%lf", &Cxs );
73 ReadPar( File, "%lf", &Cys );
74 ReadPar( File, "%lf", &Czs );
75 ReadPar( File, "%lf", &Cls );
76 ReadPar( File, "%lf", &Cms );
77 ReadPar( File, "%lf", &Cns );
78 ReadPar( File, "%lf", &Cxi );
79 ReadPar( File, "%lf", &Czi );
80
81 fclose( File );
82
83 return 0;
84}
85
86int SDSA_FILE::Read( void )
87{
88 if( file_flag == 0 )return -1;
89 return Read( file_name );
90}
91
92int SDSA_FILE::Write( const char* SDSA_file )
93{
94 FILE *File;
95 File = fopen( SDSA_file, "w" );
96 if( File == NULL )
97 {
98 fprintf( stderr, "[.sdsa] file open error to writing (%s)\n", SDSA_file );
99 return (-1);
100 }
101
102 fprintf( File, "%14.8G # S\n", S );
103 fprintf( File, "%14.8G # MAC\n", MAC );
104 fprintf( File, "%14.8G # B\n", B );
105 fprintf( File, "%14.8G # Swet\n", Swet );
106 fprintf( File, "%14.8G %f # X,Y (ref)\n", X, Z );
107 fprintf( File, "%14.8G # Alfa\n", Alfa );
108 fprintf( File, "%14.8G # Beta\n", Beta );
109 fprintf( File, "%14.8G # Mach\n", Mach );
110 fprintf( File, "%14.8G # P\n", P );
111 fprintf( File, "%14.8G # Q\n", Q );
112 fprintf( File, "%14.8G # R\n", R );
113 fprintf( File, "%14.8G # Cx\n", Cx );
114 fprintf( File, "%14.8G # Cy\n", Cy );
115 fprintf( File, "%14.8G # Cz\n", Cz );
116 fprintf( File, "%14.8G # Cl\n", Cl );
117 fprintf( File, "%14.8G # Cm\n", Cm );
118 fprintf( File, "%14.8G # Cn\n", Cn );
119 fprintf( File, "%14.8G # Cxs\n", Cxs );
120 fprintf( File, "%14.8G # Cys\n", Cys );
121 fprintf( File, "%14.8G # Czs\n", Czs );
122 fprintf( File, "%14.8G # Cls\n", Cls );
123 fprintf( File, "%14.8G # Cms\n", Cms );
124 fprintf( File, "%14.8G # Cns\n", Cns );
125 fprintf( File, "%14.8G # Cxi\n", Cxi );
126 fprintf( File, "%14.8G # Czi\n", Czi );
127
128 fclose( File );
129
130 return 0;
131}
132
134{
135 if( file_flag == 0 )return -1;
136 return Write( file_name );
137}
138
static FILE * fopen(const char *filename, const char *mode)
Cross-platform function to fopen function that supports UTF-8 encoded name.
Definition iofun.cpp:358
static int ReadPar(FILE *stream, const char *Format, void *Par)
Function to read one variable. The type of variable depends on Format, compatible with stdio library.
Definition iofun.cpp:67
double B
reference wingspan
Definition sdsa_file.h:36
double R
yaw rate [rad/s]
Definition sdsa_file.h:45
double Mach
Mach number.
Definition sdsa_file.h:42
double Cxi
induced drag coefficient
Definition sdsa_file.h:58
int Read(void)
reads the [.sdsa] file defined by SetName function
Definition sdsa_file.cpp:86
double S
reference area
Definition sdsa_file.h:34
double Z
Z coordinate fo the origin for moment components.
Definition sdsa_file.h:39
double Cls
rolling moment coefficient (stability axis system)
Definition sdsa_file.h:55
void Clean(void)
cleans local variables
Definition sdsa_file.cpp:26
double Cxs
drag coefficient (stability axis system - pressure component)
Definition sdsa_file.h:52
double Cx
drag coefficient (body axis system - pressure component)
Definition sdsa_file.h:46
double Cl
rolling moment coefficient (body axis system)
Definition sdsa_file.h:49
double Swet
wetted area
Definition sdsa_file.h:37
double Czi
lift coefficients that relates to induced drag
Definition sdsa_file.h:59
double Cys
sideforce coefficient (stability axis system)
Definition sdsa_file.h:53
double X
X coordinate fo the origin for moment components.
Definition sdsa_file.h:38
double Cns
yawing moment coefficient (stability axis system)
Definition sdsa_file.h:57
double Beta
sideslip angle [deg]
Definition sdsa_file.h:41
double Cz
lift coefficient (body axis system)
Definition sdsa_file.h:48
double Cn
yawing moment coefficient (body axis system)
Definition sdsa_file.h:51
void SetName(const char *FileName)
set pathname for the [.sdsa] file
Definition sdsa_file.cpp:39
double P
roll rate [rad/s]
Definition sdsa_file.h:43
double Cms
pitching moment coefficient (stability axis system)
Definition sdsa_file.h:56
double MAC
mean aerodynamic chord
Definition sdsa_file.h:35
double Q
pitch rate [rad/s]
Definition sdsa_file.h:44
double Cm
pitching moment coefficient (body axis system)
Definition sdsa_file.h:50
double Cy
sideforce coefficient (body axis system)
Definition sdsa_file.h:47
double Czs
lift coefficient (stability axis system)
Definition sdsa_file.h:54
double Alfa
angle of attack [deg]
Definition sdsa_file.h:40
int Write(void)
writes the [.sdsa] file defined by SetName function