FEDEM Solver  R8.0
Source code of the dynamics solver
FiASCFile.H
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2023 SAP SE
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // This file is part of FEDEM - https://openfedem.org
7 
13 #ifndef FI_ASC_FILE_H
14 #define FI_ASC_FILE_H
15 
16 #include "FiDeviceFunctionBase.H"
17 
18 
31 {
32  typedef std::vector<double> Doubles;
33  typedef std::vector<std::string> Strings;
34 
35 public:
39  FiASCFile(const char* fname = NULL, int nchan = 1);
41  virtual ~FiASCFile() {}
42 
44  virtual size_t getValueCount() const { return myValues.size(); }
45 
53  virtual double getValue(double x, int channel,
54  bool zeroAdjust, double vertShift, double scaleFac);
55 
66  virtual bool getValues(double x0, double x1, Doubles& x, Doubles& y,
67  int channel, bool zeroAdj, double shift, double scale);
68 
75  virtual void getRawData(Doubles& x, Doubles& y,
76  double minX, double maxX, int channel);
83  virtual void getData(Doubles& x, Doubles& y,
84  const std::string& channel, double minX, double maxX);
85 
87  virtual void setValue(double x, double y);
89  virtual bool setData(const Doubles& x, const Doubles& y);
90 
92  virtual void setDescription(const std::string& desc);
94  virtual void setEmptyChannel(const std::string& desc);
95 
97  virtual void setPrecision(int type) { outputFormat = type; }
98 
100  static int getNoChannels(const char* fname);
102  static bool isMultiChannel(FT_FILE fd, const char* fname = NULL,
103  bool rewind = false);
104 
106  virtual bool getChannelList(Strings& list);
108  virtual int isChannelPresentInFile(const std::string& channel);
110  virtual bool isChannelPresentInFile(int channel);
111 
116  static int readHeader(FT_FILE fd, Strings& header);
122  static bool readNext(FT_FILE fd, const std::vector<int>& columns,
123  Doubles& values);
124 
125 protected:
127  virtual bool concludingDeviceWrite(bool noHeader);
129  virtual bool initialDeviceRead();
131  virtual bool preliminaryDeviceWrite() { return true; }
132 
133 private:
135  int readChannel(int channel);
136 
141  static char* readLine(FT_FILE fd, bool commentsOnly = false);
143  static int countColumns(FT_FILE fd);
144 
145 public:
146  static size_t bufferSize;
147 
148 private:
150  typedef std::map<double,Doubles> ValuesMap;
151  typedef ValuesMap::iterator ValuesIter;
152 
157  int myChannel;
160  bool isCSVt;
161 };
162 
163 #endif
#define FT_FILE
File pointer.
Definition: FFaIO.H:136
static char * fname[_MAX_DBFIL]
Definition: binaryDB.c:35
Class representing external device functions based on ASCII files.
Definition: FiASCFile.H:31
virtual bool preliminaryDeviceWrite()
Dummy method doing nothing.
Definition: FiASCFile.H:131
virtual bool setData(const Doubles &x, const Doubles &y)
Adds a channel to current file by interpolation.
Definition: FiASCFile.C:628
virtual void getRawData(Doubles &x, Doubles &y, double minX, double maxX, int channel)
Extracts all function data point values within specified interval.
Definition: FiASCFile.C:732
virtual bool getChannelList(Strings &list)
Extracts the list of channel names (file column labels).
Definition: FiASCFile.C:510
int myChannel
Channel (column index) that currently resides in core.
Definition: FiASCFile.H:157
bool isCSVt
If true, this file has microsec as first column.
Definition: FiASCFile.H:160
int myNumChannels
Number of columns minus 1 (column 1 is the X-values)
Definition: FiASCFile.H:158
ValuesMap::iterator ValuesIter
Convenience type definition.
Definition: FiASCFile.H:151
static size_t bufferSize
Buffer size for ASCII output in KBytes.
Definition: FiASCFile.H:146
FiASCFile(const char *fname=NULL, int nchan=1)
Default constructor.
Definition: FiASCFile.C:29
virtual bool concludingDeviceWrite(bool noHeader)
Writes all function data to file.
Definition: FiASCFile.C:396
static int readHeader(FT_FILE fd, Strings &header)
Reads the header section of a specified file.
Definition: FiASCFile.C:818
virtual void getData(Doubles &x, Doubles &y, const std::string &channel, double minX, double maxX)
Extracts all function data point values within specified interval.
Definition: FiASCFile.C:725
std::vector< double > Doubles
Convenience type definition.
Definition: FiASCFile.H:32
virtual size_t getValueCount() const
Returns the number of (x,y) pairs of the function.
Definition: FiASCFile.H:44
virtual ~FiASCFile()
Empty destructor.
Definition: FiASCFile.H:41
static bool isMultiChannel(FT_FILE fd, const char *fname=NULL, bool rewind=false)
Checks if the specified file consists of two or more columns.
Definition: FiASCFile.C:478
virtual bool getValues(double x0, double x1, Doubles &x, Doubles &y, int channel, bool zeroAdj, double shift, double scale)
Evaluates the function at all points within specified interval.
Definition: FiASCFile.C:768
virtual void setValue(double x, double y)
Assigns a function value for a single-channel function.
Definition: FiASCFile.C:619
virtual bool initialDeviceRead()
Reads the file and loads the first channel into core.
Definition: FiASCFile.C:241
std::vector< std::string > Strings
Convenience type definition.
Definition: FiASCFile.H:33
static char * readLine(FT_FILE fd, bool commentsOnly=false)
Reads one line of data from specified file.
Definition: FiASCFile.C:43
static int getNoChannels(const char *fname)
Counts the number of channels (number of columns minus one).
Definition: FiASCFile.C:495
static int countColumns(FT_FILE fd)
Returns the number of columns in the file fd.
Definition: FiASCFile.C:460
std::map< double, Doubles > ValuesMap
Mapping from x-value (time) to channel values.
Definition: FiASCFile.H:150
virtual void setEmptyChannel(const std::string &desc)
Adds an empty channel to the file.
Definition: FiASCFile.C:710
virtual void setPrecision(int type)
Defines the output precision.
Definition: FiASCFile.H:97
virtual double getValue(double x, int channel, bool zeroAdjust, double vertShift, double scaleFac)
Evaluates the function for a given x value.
Definition: FiASCFile.C:543
static bool readNext(FT_FILE fd, const std::vector< int > &columns, Doubles &values)
Reads the next line of data from specified file.
Definition: FiASCFile.C:832
int readChannel(int channel)
Reads the specified channel into core.
Definition: FiASCFile.C:89
int outputFormat
0: 4-digits, 1: 8 digits, 2: 16-digits
Definition: FiASCFile.H:159
ValuesIter vit0
Start iterator of last evaluation interval.
Definition: FiASCFile.H:155
ValuesMap myValues
Curve data, either for all or one channel.
Definition: FiASCFile.H:154
virtual void setDescription(const std::string &desc)
Assigns a name to the (last) channel in file.
Definition: FiASCFile.C:612
ValuesIter vit1
End iterator of last evaluation interval.
Definition: FiASCFile.H:156
virtual int isChannelPresentInFile(const std::string &channel)
Returns the column index of the named channel.
Definition: FiASCFile.C:522
Strings chn
Channel names (columns labels)
Definition: FiASCFile.H:153
Definition: FiDeviceFunctionBase.H:19
integer(ptr), save, private x
Definition: extCtrlSysRoutinesModule.f90:16
type(fnvcolumntype), dimension(:), pointer, save columns
Definition: FNVwaveForceModule.f90:39
integer channel
Column index for data file.
Definition: initiateFunctionTypeModule.f90:26
character(len=40) type
Function type flag.
Definition: initiateFunctionTypeModule.f90:33
subroutine scale(vec, a)
Definition: windTurbineRoutinesModule.f90:510