CONFIG LIB 1.5
Configuration Files Library (by TGG 2020)
Loading...
Searching...
No Matches
panukl_con.cpp
1/*********************************************************************/
2/* */
3/* Config files library - (C) TGG 2015 */
4/* */
5/*********************************************************************/
6/* Warszawa, 2015 */
7/*********************************************************************/
8/* */
9/* File: panukl_con.cpp */
10/* */
11/* Author: T.Grabowski */
12/* */
13/* Contents - con file data (grid connection) class */
14/* */
15/* */
16/*********************************************************************/
17/* */
18/* */
19
20#include "panukl_con.h"
21
22CON_FILE::CON_FILE( void ){ Clean(); }
23
24CON_FILE::~CON_FILE( void ){}
25
26void CON_FILE::Clean( void )
27{
28 memset( DAT_file_1, 0, 256 );
29 memset( DAT_file_2, 0, 256 );
30 memset( DAT_file, 0, 256 );
31 memset( CON_file, 0, 256 );
32
33 for( int i=0; i<3; i++ )
34 {
35 dTrans1[i] = 0.;
36 dTrans2[i] = 0.;
37 dRot1[i] = 0.;
38 dRot2[i] = 0.;
39 dOrig1[i] = 0.;
40 dOrig2[i] = 0.;
41 }
42
43 iRotFlag1 = 0;
44 iRotFlag2 = 0;
45
46 dSref = 0.;
47 dBref = 0.;
48 dMACref = 0.;
49 dX25ref = 0.;
50 dZ25ref = 0.;
51 iFlagRef = 0;
52}
53
54int CON_FILE::ReadCON( char *FileName )
55{
56 FILE *File;
57 File = fopen( FileName, "r" );
58 if( File == NULL )
59 {
60 fprintf( stderr, "[.CON] file open error to reading (%s)\n", FileName );
61 return (-1);
62 }
63
64 //ReadComm( File );
65 char cRob[256];
66
67 ReadStr( File, DAT_file_1 );
69
70 ReadVect( File, dTrans1, 3 );
71 ReadVect( File, dRot1, 3 );
72 ReadPar ( File, "%d", &iRotFlag1 );
73 ReadVect( File, dOrig1, 3 );
74
75 ReadStr( File, DAT_file_2 );
77
78 ReadVect( File, dTrans2, 3 );
79 ReadVect( File, dRot2, 3 );
80 ReadPar ( File, "%d", &iRotFlag2 );
81 ReadVect( File, dOrig2, 3 );
82
83 ReadStr( File, DAT_file );
85
86 ReadPar ( File, "%d", &iFlagRef );
87 ReadStr( File, cRob );
88 sscanf( cRob, "%lf %lf %lf %lf %lf", &dSref, &dBref, &dMACref, &dX25ref, &dZ25ref );
89
90 fclose( File );
91
92 return (0);
93}
94
95int CON_FILE::WriteCON( char *FileName )
96{
97 FILE *File;
98 File = fopen( FileName, "w" );
99 if( File == NULL )
100 {
101 fprintf( stderr, "[.CON] file open error to writing (%s)\n", FileName );
102 return (-1);
103 }
104
105 fprintf( File, "# Connection program configuration file\n");
106 fprintf( File, "%s # master input data file [.DAT]\n", DAT_file_1 );
107 fprintf( File, "%f %f %f # translation coordinates X Y Z (master)\n", dTrans1[0], dTrans1[1], dTrans1[2] );
108 fprintf( File, "%f %f %f # rotation angles phi theta psi (master)\n", dRot1[0], dRot1[1], dRot1[2] );
109 fprintf( File, "%3d # rotation origin option (0 user defined, 1 (0,0,0), 2 1/4 of MAC)\n", iRotFlag1 );
110 fprintf( File, "%f %f %f # rotation origin coordinates (master)\n", dOrig1[0], dOrig1[1], dOrig1[2] );
111 fprintf( File, "%s # slave input data file [.DAT]\n", DAT_file_2 );
112 fprintf( File, "%f %f %f # translation coordinates X Y Z (slave)\n", dTrans2[0], dTrans2[1], dTrans2[2] );
113 fprintf( File, "%f %f %f # rotation angles phi theta psi (slave)\n", dRot2[0], dRot2[1], dRot2[2] );
114 fprintf( File, "%3d # rotation origin option (0 user defined, 1 (0,0,0), 2 1/4 of MAC)\n", iRotFlag2 );
115 fprintf( File, "%f %f %f # rotation origin coordinates (slave)\n", dOrig2[0], dOrig2[1], dOrig2[2] );
116 fprintf( File, "%s # output data file [.DAT]\n", DAT_file );
117 fprintf( File, "%3d # reference values option (0 user defined, 1 master, 2 slave)\n", iFlagRef );
118 fprintf( File, "%f %f %f %f %f # User defined reference values :S, B, MAC, X25, Z25\n",
120
121 fclose( File );
122
123 return (0);
124}
125
double dZ25ref
Z coordinate of reference origin for moment calculation defined by user.
Definition panukl_con.h:49
int iRotFlag2
2nd grid rotation origin option (0 user defined, 1 (0,0,0), 2 1/4 of MAC)
Definition panukl_con.h:43
double dRot2[3]
rotation of the 2nd grid (3 angles) [deg]
Definition panukl_con.h:39
void Clean(void)
cleans local variables
double dSref
reference area defined by user
Definition panukl_con.h:45
char DAT_file_1[256]
1st data (mesh+wake) file [.DAT] - input
Definition panukl_con.h:31
double dRot1[3]
rotation of the 1st grid (3 angles) [deg]
Definition panukl_con.h:38
int ReadCON(char *FileName)
reads parameters [.con] file
char DAT_file[256]
connected data (mesh+wake) file [.DAT] - output
Definition panukl_con.h:34
char DAT_file_2[256]
2nd data (mesh+wake) file [.DAT] - input
Definition panukl_con.h:32
char CON_file[256]
name of current [.con] file
Definition panukl_con.h:52
double dTrans1[3]
translation of the 1st grid (3 coordinates)
Definition panukl_con.h:36
double dOrig1[3]
origin of rotation of the 1st grid (3 coordinates)
Definition panukl_con.h:40
double dX25ref
X coordinate of reference origin for moment calculation defined by user.
Definition panukl_con.h:48
double dBref
reference wingspan defined by user
Definition panukl_con.h:46
int iRotFlag1
1st grid rotation origin option (0 user defined, 1 (0,0,0), 2 1/4 of MAC)
Definition panukl_con.h:42
int iFlagRef
reference values option (0 user defined, 1 master, 2 slave)
Definition panukl_con.h:50
double dMACref
mean aerodynamic chord by user
Definition panukl_con.h:47
double dOrig2[3]
origin of rotation of the 2nd grid (3 coordinates)
Definition panukl_con.h:41
double dTrans2[3]
translation of the 2nd grid (3 coordinates)
Definition panukl_con.h:37
int WriteCON(char *Filename)
writes parameters [.con] file
static int ReadVect(FILE *stream, double *Par, int n, double dScal=1.)
Function to read double vector "Par" of "n" dimension from FILE "stream". The read values are scaled ...
Definition iofun.cpp:99
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 void ClipFileName(char *string)
Clipping of the ending blanc characters of "string".
Definition iofun.cpp:250
static int ReadStr(FILE *stream, char *Par)
Function to read the new line from FILE "stream" and to store it in table of char "Par"....
Definition iofun.cpp:163
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