CONFIG LIB 1.5
Configuration Files Library (by TGG 2020)
Loading...
Searching...
No Matches
TXT_OUT_FILE Class Reference

General output text file. More...

#include <txt_out_file.h>

Inheritance diagram for TXT_OUT_FILE:
IOFUN CZY_FILE POLAR_FILE

Public Member Functions

 TXT_OUT_FILE (int iTypeIn=0)
 constructor
 
virtual void Clean (void)
 cleans local variables
 
virtual void CleanTabs (void)
 cleans (deletes) arrays
 
virtual void InitTabs (int n, int m)
 initialises arrays (n - number of columns, m - number of rows )
 
virtual void SetName (const char *FileName)
 set pathname for of the output text file
 
virtual char * GetName (void)
 returns pathname of the output text file
 
virtual int Read (const char *FileName)
 reads the [.czy] file
 
virtual int Read (void)
 reads the [.czy] file defined by SetName function
 
virtual int Write (const char *FileName)
 writes the [.czy] file
 
virtual int Write (void)
 writes the [.czy] file defined by SetName function
 

Public Attributes

int nCol
 number of columns/variables (up to NCOL_MAX)
 
int nRow
 number of rows
 
char cName [NCOL_MAX][32]
 array of variable names - up to NCOL_MAX names, 32 characters each
 
int iType
 type of txt file - possible types:
0 - nCol x nRow - only double type values
1 - (nCol-1) x nRow + first column int type
 
int * iObj
 pointer to array [nRow] first column value (int)
 
double ** dResult
 pointer to array (size depends on iType) containing the results for all variables
 

Additional Inherited Members

- Static Public Member Functions inherited from IOFUN
static void Win2Unix (char *s)
 conversion of directory separators - MS Windows to Unix
 
static void Unix2Win (char *s)
 conversion of directory separators - Unix to MS Windows
 
static int ReadComm (FILE *stream)
 Function to read of a comment till the end of line. It returns 0 or EOF if it is performed.
 
static void ReadDummy (FILE *stream)
 Function to read a comment line.
 
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.
 
static int ReadPar (FILE *stream, const char *Format, void *Par1, void *Par2)
 Function to read two variables. The type of variables depends on Format, compatible with stdio library.
 
static int ReadPar (FILE *stream, const char *Format, void *Par1, void *Par2, void *Par3)
 Function to read three variables. The type of variables depends on Format, compatible with stdio library.
 
static int ReadPar (FILE *stream, const char *Format, void *Par1, void *Par2, void *Par3, void *Par4)
 Function to read four variables. The type of variables depends on Format, compatible with stdio library.
 
static int ReadVect3 (FILE *stream, double *Par, double dScal=1.)
 Function to read double vector "Par" of "3" dimension from FILE "stream". The read values are scaled by multiplier "dScal".
 
static int ReadVect3 (FILE *stream, float *Par, float fScal=1.)
 Function to read float vector "Par" of "3" dimension from FILE "stream". The read values are scaled by multiplier "fScal".
 
static int ReadVect3 (FILE *stream, long *Par, long lScal=1)
 Function to read long vector "Par" of "3" dimension from FILE "stream". The read values are scaled by multiplier "lScal".
 
static int ReadVect3 (FILE *stream, int *Par, int iScal=1)
 Function to read int vector "Par" of "3" dimension from FILE "stream". The read values are scaled by multiplier "iScal".
 
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 by multiplier "dScal".
 
static int ReadVect (FILE *stream, float *Par, int n, float fScal=1.)
 Function to read float vector "Par" of "n" dimension from FILE "stream". The read values are scaled by multiplier "fScal".
 
static int ReadVect (FILE *stream, long *Par, int n, long lScal=1)
 Function to read long vector "Par" of "n" dimension from FILE "stream". The read values are scaled by multiplier "lScal".
 
static int ReadVect (FILE *stream, int *Par, int n, int iScal=1)
 Function to read int vector "Par" of "n" dimension from FILE "stream". The read values are scaled by multiplier "iScal".
 
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". The starting and ending blanc charaters are clipped.
 
static void ReadStrL (FILE *stream, char *Par, int *len)
 Function to read the string (Par) from FILE "stream". It reads from current pointer of FILE to the end of line or EOF. Number of read characters is returned in "len".
 
static void ClipString (char *string)
 Clipping of the "string" up to the first blanc character or comment "#" character.
 
static void ClipFileName (char *string)
 Clipping of the ending blanc characters of "string".
 
static bool CompareStrings (char *str1, char *str2)
 Compares two strings (str1 and str2). Returns true if they match, false otherwise.
 
static int file_exist (const char *name)
 Returns true (1) if file "name" does exist, 0 otherwise.
 
static const char * filename_name (const char *name)
 Returns pointer to filename without path.
 
static const char * filename_ext (const char *buf)
 Returns pointer to filename extension.
 
static char * filename_setext (char *buf, int buflen, const char *ext)
 set/change filename extension
 
static int filename_dir (char *name)
 returns the length of the path in (path)name
 
static const char * filename_date (const char *name)
 Returns pointer to the string that contains the date of last file modification/creation.
 
static FILE * fopen (const char *filename, const char *mode)
 Cross-platform function to fopen function that supports UTF-8 encoded name.
 
static int stat (const char *f, struct stat *b)
 Cross-platform function to stat() a file using a UTF-8 encoded name or value.
 
static size_t strlcpy (char *d, const char *s, size_t bufsize)
 The implementation of nonstandard strlcpy function.
 
static int nLines (FILE *stream)
 Returns number of lines of text file from current pointer to EOF.
 
static int nColumns (FILE *stream, char Par[][32])
 Returns number of columns of text file (number of strings in the first line). Names of columns are stored in Par array.
 
static int isstrblank (char *cc, int iLen)
 Checks if string (cc) is blank (1/0)
 
static void ReadVect3 (FILE *stream, VECTOR_3D *Vec, double dScal=1.)
 Function to read VECTOR_3D Vec components from FILE "stream". The read values are scaled by multiplier "dScal".
 
static int readln (FILE *ff, char *value_x)
 Pascal style "readln" function to read string.
 
static int readln (FILE *ff, int *value_x)
 Pascal style "readln" function to read int.
 
static int readln (FILE *ff, long *value_x)
 Pascal style "readln" function to read long.
 
static int readln (FILE *ff, float *value_x)
 Pascal style "readln" function to read float.
 
static int readln (FILE *ff, double *value_x)
 Pascal style "readln" function to read double.
 
static int readln (FILE *ff, long double *value_x)
 Pascal style "readln" function to read long double.
 
static int readln (FILE *ff)
 Pascal style "readln" function to read comment.
 
static int readln (FILE *ff, VECTOR_3D *vec)
 Pascal style "readln" function to read VECTOR_3D components.
 
static int read (FILE *ff, char *value_x)
 Pascal style "read" function to read string.
 
static int read (FILE *ff, int *value_x)
 Pascal style "read" function to read int.
 
static int read (FILE *ff, long *value_x)
 Pascal style "read" function to read long.
 
static int read (FILE *ff, float *value_x)
 Pascal style "read" function to read float.
 
static int read (FILE *ff, double *value_x)
 Pascal style "read" function to read double.
 
static int read (FILE *ff, long double *value_x)
 Pascal style "read" function to read long double.
 
static int read (FILE *ff, VECTOR_3D *vec)
 Pascal style "read" function to read VECTOR_3D components.
 

Detailed Description

General output text file.

Definition at line 29 of file txt_out_file.h.

Constructor & Destructor Documentation

◆ TXT_OUT_FILE()

TXT_OUT_FILE::TXT_OUT_FILE ( int iTypeIn = 0)

constructor

Definition at line 22 of file txt_out_file.cpp.

23{
24 iType = iTypeIn;
25 Clean();
26}
virtual void Clean(void)
cleans local variables
int iType
type of txt file - possible types: 0 - nCol x nRow - only double type values 1 - (nCol-1) x nRow ...

◆ ~TXT_OUT_FILE()

TXT_OUT_FILE::~TXT_OUT_FILE ( void )
virtual

Definition at line 28 of file txt_out_file.cpp.

29{
30 CleanTabs();
31}
virtual void CleanTabs(void)
cleans (deletes) arrays

Member Function Documentation

◆ Clean()

void TXT_OUT_FILE::Clean ( void )
virtual

cleans local variables

Reimplemented in CZY_FILE, and POLAR_FILE.

Definition at line 33 of file txt_out_file.cpp.

34{
35 nRow = 0;
36 nCol = NCOL_MAX;
37
38 for( int i=0; i<nCol; i++ )sprintf(cName[i],"Var %d",i);
39
40 file_flag = 0;
41 dResult = NULL;
42 iObj = NULL;
43}
int nRow
number of rows
char cName[NCOL_MAX][32]
array of variable names - up to NCOL_MAX names, 32 characters each
int nCol
number of columns/variables (up to NCOL_MAX)
int * iObj
pointer to array [nRow] first column value (int)
double ** dResult
pointer to array (size depends on iType) containing the results for all variables

Referenced by CZY_FILE::Clean(), POLAR_FILE::Clean(), and TXT_OUT_FILE().

◆ CleanTabs()

void TXT_OUT_FILE::CleanTabs ( void )
virtual

cleans (deletes) arrays

Definition at line 45 of file txt_out_file.cpp.

46{
47 if( dResult )
48 {
49 for( int i=0; i<nCol; i++ )if( dResult[i] ){ delete [] dResult[i]; dResult[i] = NULL; }
50 delete [] dResult;
51 dResult = NULL;
52 }
53 if( iObj )delete [] iObj;
54 iObj = NULL;
55}

Referenced by InitTabs(), and Read().

◆ GetName()

char * TXT_OUT_FILE::GetName ( void )
virtual

returns pathname of the output text file

Definition at line 74 of file txt_out_file.cpp.

75{
76 return file_name;
77}

◆ InitTabs()

void TXT_OUT_FILE::InitTabs ( int n,
int m )
virtual

initialises arrays (n - number of columns, m - number of rows )

Definition at line 57 of file txt_out_file.cpp.

58{
59 CleanTabs();
60
61 nCol = n;
62 nRow = m;
63 dResult = new double*[nCol];
64 for( int i=0; i<nCol; i++ )dResult[i] = new double[nRow];
65 if ( iType ) iObj = new int[nRow];
66}

◆ Read() [1/2]

int TXT_OUT_FILE::Read ( const char * FileName)
virtual

reads the [.czy] file

Definition at line 79 of file txt_out_file.cpp.

80{
81 SetName( TXT_file);
82 FILE *File;
83 File = fopen( TXT_file, "r" );
84 if( File == NULL )
85 {
86 fprintf( stderr, "File open error to reading (%s)\n", TXT_file );
87 return (-1);
88 }
89
90 memset( cName, 0, NCOL_MAX*32 );
91 CleanTabs();
92
93 nCol = nColumns( File, cName ) - iType;
94 nRow = nLines( File );
95
96 dResult = new double*[nCol];
97 for( int i=0; i<nCol; i++ )dResult[i] = new double[nRow];
98 iObj = new int[nRow];
99
100 for( int j=0; j<nRow; j++ )
101 {
102 if(iType)fscanf( File, "%d", &iObj[j] );
103 for( int i=0; i<nCol; i++ )fscanf( File, "%lf", &dResult[i][j] );
104 }
105
106 fclose( File );
107
108 return 0;
109}
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 nColumns(FILE *stream, char Par[][32])
Returns number of columns of text file (number of strings in the first line). Names of columns are st...
Definition iofun.cpp:447
static int nLines(FILE *stream)
Returns number of lines of text file from current pointer to EOF.
Definition iofun.cpp:426
virtual void SetName(const char *FileName)
set pathname for of the output text file

◆ Read() [2/2]

int TXT_OUT_FILE::Read ( void )
virtual

reads the [.czy] file defined by SetName function

Definition at line 111 of file txt_out_file.cpp.

112{
113 if( file_flag == 0 )return -1;
114 return Read( file_name );
115}
virtual int Read(void)
reads the [.czy] file defined by SetName function

Referenced by Read().

◆ SetName()

void TXT_OUT_FILE::SetName ( const char * FileName)
virtual

set pathname for of the output text file

Definition at line 68 of file txt_out_file.cpp.

69{
70 strcpy( file_name, TXT_file );
71 file_flag = 1;
72}

Referenced by Read(), and Write().

◆ Write() [1/2]

int TXT_OUT_FILE::Write ( const char * FileName)
virtual

writes the [.czy] file

Definition at line 117 of file txt_out_file.cpp.

118{
119 SetName( TXT_file);
120 FILE *File;
121 File = fopen( TXT_file, "w" );
122 if( File == NULL )
123 {
124 fprintf( stderr, "File open error to writing (%s)\n", TXT_file );
125 return (-1);
126 }
127
128 for( int i=0; i<nCol+iType; i++ )fprintf( File, " %s", cName[i] );
129 fprintf( File, "\n" );
130 for( int j=0; j<nRow; j++ )
131 {
132 if(iType)fprintf( File, " %5d", iObj[j] );
133 for( int i=0; i<nCol; i++ )fprintf( File, " %#16.8g", dResult[i][j] );
134 fprintf( File, "\n" );
135 }
136 fclose( File );
137
138 return 0;
139}

◆ Write() [2/2]

int TXT_OUT_FILE::Write ( void )
virtual

writes the [.czy] file defined by SetName function

Definition at line 141 of file txt_out_file.cpp.

142{
143 if( file_flag == 0 )return -1;
144 return Write( file_name );
145}
virtual int Write(void)
writes the [.czy] file defined by SetName function

Referenced by Write().

Member Data Documentation

◆ cName

char TXT_OUT_FILE::cName[NCOL_MAX][32]

array of variable names - up to NCOL_MAX names, 32 characters each

Definition at line 39 of file txt_out_file.h.

Referenced by CZY_FILE::Clean(), POLAR_FILE::Clean(), Clean(), Read(), and Write().

◆ dResult

double** TXT_OUT_FILE::dResult

pointer to array (size depends on iType) containing the results for all variables

Definition at line 45 of file txt_out_file.h.

Referenced by Clean(), CleanTabs(), InitTabs(), Read(), and Write().

◆ iObj

int* TXT_OUT_FILE::iObj

pointer to array [nRow] first column value (int)

Definition at line 44 of file txt_out_file.h.

Referenced by Clean(), CleanTabs(), InitTabs(), Read(), and Write().

◆ iType

int TXT_OUT_FILE::iType

type of txt file - possible types:
0 - nCol x nRow - only double type values
1 - (nCol-1) x nRow + first column int type

Definition at line 41 of file txt_out_file.h.

Referenced by InitTabs(), Read(), TXT_OUT_FILE(), and Write().

◆ nCol

int TXT_OUT_FILE::nCol

number of columns/variables (up to NCOL_MAX)

Definition at line 36 of file txt_out_file.h.

Referenced by CZY_FILE::Clean(), POLAR_FILE::Clean(), Clean(), CleanTabs(), InitTabs(), Read(), and Write().

◆ nRow

int TXT_OUT_FILE::nRow

number of rows

Definition at line 37 of file txt_out_file.h.

Referenced by Clean(), InitTabs(), Read(), and Write().


The documentation for this class was generated from the following files: