22#include "../../kernel.hpp"
23#include "../ui/language.hpp"
24#include "../utils/tools.hpp"
25#include "../utils/BasicExcel.hpp"
26#include "../ui/error.hpp"
27#include "../structures.hpp"
28#include "../built-in.hpp"
29#include "../maths/parser_functions.hpp"
56 if (!sFileName.length())
66 while (!sFileName.length());
163 nLines = _data.
getLines(sCache) + nHeadlineCount;
173 if (nLines == nHeadlineCount)
177 string** sOut =
new std::string*[nLines];
179 for (
long long int i = 0; i < nLines; i++)
181 sOut[i] =
new std::string[nCols];
188 for (
long long int i = 0; i < nLines; i++)
190 for (
long long int j = 0; j < nCols; j++)
201 if (_out.
isCompact() && (
int)sOut[i][j].length() > 11 && !bSave)
204 sOut[i][j].replace(8, std::string::npos,
"...");
206 else if (nHeadlineCount > 1 && sOut[i][j].find(
'\n') != string::npos)
209 string sHead = sOut[i][j];
212 for (
unsigned int n = 0; n < sHead.length(); n++)
214 if (sHead[n] ==
'\n')
216 sOut[i + nCount][j] = sHead.substr(0, n);
217 sHead.erase(0, n + 1);
223 sOut[i + nCount][j] = sHead;
228 i = nHeadlineCount - 1;
257 sprintf(cBuffer,
"%.*g", 4, _data.
getElement(i - nHeadlineCount, j, sCache).real());
259 sprintf(cBuffer,
"%.*g", nPrecision, _data.
getElement(i - nHeadlineCount, j, sCache).real());
261 sOut[i][j] = cBuffer;
283 string sCache = _sCache;
295 long long int nLine = 0;
296 long long int nCol = 0;
297 int nHeadlineCount = 0;
300 string** sOut =
make_stringmatrix(_data, _out, _option, sCache, nLine, nCol, nHeadlineCount, nPrecision,
false);
303 if (sCache.front() ==
'*')
318 _out.
format(sOut, nCol, nLine, _option,
true, nHeadlineCount);
326 for (
long long int i = 0; i < nLine; i++)
357 if (cmdParser.
hasParam(
"all") && (sFileList.find(
'*') != string::npos || sFileList.find(
'?') != string::npos))
360 if (sFileList.find(
'/') == string::npos)
361 sFileList =
"<loadpath>/" + sFileList;
364 vector<string> vFilelist =
getFileList(sFileList, _option,
true);
367 if (!vFilelist.size())
371 for (
size_t i = 0; i < vFilelist.size(); i++)
397 nArgument =
intCast(vPar.front());
404 nArgument =
intCast(vPar.front());
407 info = _data.
openFile(sFileList,
false, nArgument);
453 string sAutoSave = _option.
getSavePath() +
"/cache.tmp";
454 string sCache_file = _option.
getExePath() +
"/numere.cache";
458 remove(sAutoSave.c_str());
459 remove(sCache_file.c_str());
487 if (sCache.substr(0, sCache.find(
'(')) == iter->first)
509 if (_data.
isEmpty(iter->first))
544 if (sCluster.substr(0, sCluster.find(
'{')) == iter->first)
584 bool bSuccess =
false;
587 std::string sExpr = cmdParser.
getExpr();
590 while (sExpr.length())
624 bool bTranspose = cmdParser.
hasParam(
"transpose");
628 std::string sTarget = cmdParser.
getTargetTable(_iTargetIndex,
"table");
659 bool bTranspose = cmdParser.
hasParam(
"transpose");
663 std::string sTarget = cmdParser.
getTargetTable(_iTargetIndex,
"");
666 if (!sTarget.length())
716 else if (_iTargetIndex.
row.
size())
764 for (
unsigned int i = 0; i < _iSourceIndex.
row.
size(); i++)
766 for (
unsigned int j = 0; j < _iSourceIndex.
col.
size(); j++)
783 for (
long long int i = 0; i < _cache.
getLines(
"table",
false); i++)
788 if (i >= _iTargetIndex.
row.
size())
793 if (i >= _iTargetIndex.
col.
size())
796 for (
long long int j = 0; j < _cache.
getCols(
"table",
false); j++)
807 if (j > _iTargetIndex.
col.
size())
820 if (j > _iTargetIndex.
row.
size())
846 vector<int> vSortIndex;
861 if (vSortIndex.size())
864 vector<mu::value_type> vDoubleSortIndex;
866 for (
size_t i = 0; i < vSortIndex.size(); i++)
867 vDoubleSortIndex.push_back(vSortIndex[i]);
893 vector<int> vSortIndex;
905 if (vSortIndex.size())
908 vector<mu::value_type> vDoubleSortIndex;
910 for (
size_t i = 0; i < vSortIndex.size(); i++)
911 vDoubleSortIndex.push_back(vSortIndex[i]);
935 vector<int> vSortIndex;
972 if (vSortIndex.size())
975 vector<mu::value_type> vDoubleSortIndex;
976 for (
size_t i = 0; i < vSortIndex.size(); i++)
977 vDoubleSortIndex.push_back(vSortIndex[i]);
1003 bool bAppend =
false;
1005 bool bNoQuotes = cmdParser.
hasParam(
"nq") || cmdParser.
hasParam(
"noquotes");
1006 bool bKeepEmptyLines = cmdParser.
hasParam(
"keepdim") || cmdParser.
hasParam(
"k");
1021 if (sFileName.substr(sFileName.rfind(
'.')) ==
".nprc"
1022 || sFileName.substr(sFileName.rfind(
'.')) ==
".nscr"
1023 || sFileName.substr(sFileName.rfind(
'.')) ==
".ndat")
1027 if (sFileName.substr(sFileName.rfind(
'.')) ==
".nprc")
1029 else if (sFileName.substr(sFileName.rfind(
'.')) ==
".nscr")
1031 else if (sFileName.substr(sFileName.rfind(
'.')) ==
".ndat")
1043 if (sMode ==
"append" || sMode ==
"app")
1045 else if (sMode ==
"trunc")
1047 else if (sMode ==
"override" || sMode ==
"overwrite")
1058 if (!sFileName.length())
1062 std::string sExpression = cmdParser.
getExpr();
1068 sExpression +=
" -komq";
1077 fFile.open(sFileName.c_str(), ios_base::app | ios_base::out | ios_base::ate);
1083 ofstream fTemp(sFileName.c_str());
1085 fFile.open(sFileName.c_str());
1093 if ((!sExpression.length() || sExpression ==
"\"\"") && !bKeepEmptyLines)
1098 while (sExpression.length())
1105 if (bNoQuotes && sArgument[0] ==
'"' && sArgument[sArgument.length() - 1] ==
'"')
1106 sArgument = sArgument.substr(1, sArgument.length() - 2);
1109 if ((!sArgument.length() || sArgument ==
"\"\"") && !bKeepEmptyLines)
1121 fFile << sArgument << endl;
1124 if (sExpression ==
",")
1129 if (fFile.is_open())
1147 std::string sInput =
"";
1151 bool bKeepEmptyLines = cmdParser.
hasParam(
"keepdim") || cmdParser.
hasParam(
"k");
1153 if (sCommentEscapeSequence !=
" ")
1162 if (!sFileName.length())
1171 if (sCommentEscapeSequence.length())
1173 replaceAll(sCommentEscapeSequence,
"\\t",
"\t");
1183 sStringSequence.length() != 0);
1187 vector<string> vFileContents;
1195 if (!sLine.length() || sLine ==
"\"\"" || sLine ==
"\"")
1198 vFileContents.push_back(
"\"\"");
1204 if (sLine.front() !=
'"')
1205 sLine =
'"' + sLine;
1207 if (sLine.back() !=
'"')
1211 vFileContents.push_back(sLine);
1216 if (vFileContents.size())
1238 std::string sChannels =
"grey";
1240 std::vector<mu::value_type> vIndices;
1243 std::string sTargetCache = cmdParser.
getTargetTable(_idx,
"image");
1248 if (cmdParser.
hasParam(
"channels"))
1252 if (!sFileName.length())
1256 wxInitAllImageHandlers();
1261 g_logger.
info(
"Loading image file '" + sFileName +
"'.");
1265 if (!image.LoadFile(sFileName, wxBITMAP_TYPE_ANY))
1271 int nWidth = image.GetWidth();
1272 int nHeight = image.GetHeight();
1273 unsigned char* imageData = image.GetData();
1284 vIndices.push_back(_idx.
row.
min()+1);
1285 vIndices.push_back(_idx.
row.
max()+1);
1286 vIndices.push_back(_idx.
col.
min()+1);
1287 vIndices.push_back(_idx.
col.
max()+1);
1293 for (
int i = 0; i < nWidth; i++)
1301 for (
int i = 0; i < nHeight; i++)
1308 if (sChannels ==
"grey")
1312 for (
size_t n = 0; n < sChannels.length(); n++)
1313 _table->
writeData(rowmax, _idx.
col[2+i + n*nHeight], 0.0);
1324 #pragma omp parallel for
1325 for (
int j = 0; j < nHeight; j++)
1332 if (sChannels ==
"grey")
1336 for (
size_t n = 0; n < sChannels.length(); n++)
1340 for (
int i = 0; i < nWidth; i++)
1346 if (sChannels ==
"grey")
1350 _idx.
col[2 + (nHeight - j - 1)],
1351 imageData[j * 3 * nWidth + iData] * 0.299
1352 + imageData[j * 3 * nWidth + iData + 1] * 0.587
1353 + imageData[j * 3 * nWidth + iData + 2] * 0.114);
1357 for (
size_t n = 0; n < sChannels.length(); n++)
1360 switch (sChannels[n])
1364 _idx.
col[2 + (nHeight - j - 1) + n*nHeight],
1365 imageData[j * 3 * nWidth + iData]);
1369 _idx.
col[2 + (nHeight - j - 1) + n*nHeight],
1370 imageData[j * 3 * nWidth + iData + 1]);
1374 _idx.
col[2 + (nHeight - j - 1) + n*nHeight],
1375 imageData[j * 3 * nWidth + iData + 2]);
This class provides the functionality to extract the different components of a command line into the ...
DataAccessParser getExprAsDataObject() const
Parses the expression to a DataAccessParser, which will extract the needed information for the curren...
const std::string & getCommandLine() const
Returns the command line used for constructing this instance (e.g. for errors).
std::vector< mu::value_type > getParameterValueAsNumericalValue(const std::string &sParameter) const
Parses the selected parameter as (one or more) numerical value(s) and returns them as a vector of dou...
std::string getParameterValueAsString(const std::string &sParameter, const std::string &sDefaultValue, bool stripAlways=false, bool onlyStringEvaluation=false) const
Parses the selected parameter value as a string and returns it. If the parameter is not found,...
const std::string & getExpr() const
Returns the expression as plain value.
const std::string & getParameterList() const
Returns the parameter list.
std::string getFileParameterValueForSaving(std::string sFileExt, const std::string &sBaseFolder="", const std::string &sDefaultName="") const
Parses the value of the common "file" command line parameter and returns a valid filename....
std::string getTargetTable(Indices &_targetIndices, const std::string &sDefaultTableName)
Evaluates any target=TABLE() statements in the parameter list and returns the needed information....
void setReturnValue(const std::string &sRetVal)
Sets the return value of the current command by simply appending it to the return value statement.
void clearReturnValue()
Removes the return value statement.
std::string parseExprAsString() const
Prepares the expression by handling all string operations and removing the surrounding quotation mark...
std::string getParameterValue(const std::string &sParameter) const
Simply returns the parameter value or an empty string. Does not do any parsing steps.
@ CMD_DAT_PAR
Command-dataobject-parameter sequence (e.g. fit)
std::string getExprAsFileName(std::string sFileExt, const std::string &sBasePath="") const
Converts the expression to a file name and removes the surrounding quotation marks,...
bool hasParam(const std::string &sParameter) const
Simple wrapper around findParameter(), if used as a boolean flag.
This class is defined to abstrahize the determination of the correct data object and the calculation ...
Indices & getIndices()
Returns a reference to the stored indices.
void evalIndices()
Evaluates open end indices using the identified data object size.
bool isCluster() const
Determines, whether the data access references a cluster.
std::string & getDataObject()
Returns a reference to the data object identifier.
void info(const std::string &sMessage)
Convenience member function.
void debug(const std::string &sMessage)
Convenience member function.
This class extends the std::vector for endlessness.
This class implements the basic input/ output file system and provides functionalities to work with f...
void initializeFromKernel()
Member function to remote-initialize the class from the kernel. Cannot be used during kernel start-up...
std::string getPath() const
Returns the default path of this FileSystem instance.
This class handles the internal language system and returns the language strings of the selected lang...
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
This class represents a single table in memory, or a - so to say - single memory page to be handled b...
void markModified()
Mark this table as modified.
void writeData(int _nLine, int _nCol, const mu::value_type &_dData)
This member function writes the passed value to the selected position. The table is automatically enl...
void writeDataDirectUnsafe(int _nLine, int _nCol, const mu::value_type &_dData)
This member function provides an even more unsafe but direct way of writing data to the table....
bool setHeadLineElement(size_t _i, const std::string &_sHead)
Writes a new table column headline to the selected column.
This class represents the central memory managing instance. It will handle all tables and clusters,...
void removeData(bool bAutoSave=false)
Removes the "data()" table, if it is available.
mu::value_type getElement(int _nLine, int _nCol, const std::string &_sTable) const
int getHeadlineCount(const std::string &_sTable) const
bool getSaveStatus() const
Returns, whether there's at least a single table in memory, which has not been saved yet.
std::vector< int > sortElements(const std::string &sLine)
This member function wraps the sorting functionality and evaluates the passed parameter string before...
bool isValidElement(long long int _nLine, long long int _nCol, const std::string &_sTable) const
std::string getTopHeadLineElement(int _i, const std::string &_sTable) const
void removeTablesFromMemory()
Removes all tables in memory and re- initializes the MemoryManager with the default table.
void deleteBulk(const std::string &_sCache, int i1, int i2, int j1=0, int j2=0)
NumeRe::TableMetaData getMetaData(const std::string &_sTable) const
int getLines(StringView sTable, bool _bFull=false) const
const std::map< std::string, std::pair< size_t, size_t > > & getTableMap() const
bool isEmpty(const std::string &sTable) const
void setMetaData(const std::string &_sTable, const NumeRe::TableMetaData &meta)
NumeRe::Table extractTable(const std::string &_sTable, const VectorIndex &lines=VectorIndex(0, VectorIndex::OPEN_END), const VectorIndex &cols=VectorIndex(0, VectorIndex::OPEN_END))
std::string getHeadLineElement(int _i, const std::string &_sTable) const
bool isValid() const
Evaluates, whether there's at least a single non-empty table.
void deleteEntry(int _nLine, int _nCol, const std::string &_sCache)
Memory * getTable(const std::string &sTable)
This member function returns a pointer to an existing Memory instance representing the selected table...
void writeToTable(int _nLine, int _nCol, const std::string &_sCache, const mu::value_type &_dData)
bool setHeadLineElement(int _i, const std::string &_sTable, std::string _sHead)
int getCols(StringView sTable, bool _bFull=false) const
This class represents a whole cluster. The single items are stored as pointers to the abstract cluste...
size_t size() const
This member function returns the size of the internal memory buffer as items.
std::vector< int > sortElements(long long int i1, long long int i2, const std::string &sSortingExpression)
This public member function provides access to the sorting algorithm for the cluster object.
void deleteItems(long long int i1, long long int i2)
This public member function erases elements located from the index i1 to i2.
Cluster & getCluster(StringView sCluster)
This member function returns a reference to the cluster indicated by the passed cluster identifier.
bool isCluster(StringView sCluster) const
This member function returns true, if the passed cluster identifier can be found in the internal map.
const std::map< std::string, Cluster > & getClusterMap() const
std::string getDataFileName(const std::string &sTable) const
This member function will return the file name of the selected table. Will default to the table name.
void setbLoadEmptyColsInNextFile(bool _bLoadEmptyCols)
Set, whether empty columns shall be loaded in the next file.
FileHeaderInfo openFile(std::string _sFile, bool loadToCache=false, bool overrideTarget=false, int _nHeadline=0, const std::string &sTargetTable="")
This member function loads the contents of the selected file to a new Memory class instance....
StringParserRetVal evalAndFormat(std::string &sLine, std::string &sCache, bool bSilent=false, bool bCheckAssertions=false)
This public member function evaluates the passed string expression and formats the results for the co...
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
NumeRe::StringParser & getStringParser()
static void getline(std::string &sLine)
This function is an implementation replacing the std::getline() function.
static void printPreFmt(const std::string &__sLine, bool printingEnabled=true)
This member function appends the pre- formatted string to the buffer and informs the terminal that we...
MemoryManager & getMemoryManager()
static void print(const std::string &__sLine, bool printingEnabled=true)
This member function appends the passed string as a new output line to the buffer and informs the ter...
static void showTable(NumeRe::Table _table, std::string __name, bool openeditable=false)
This member function passes a table to the GUI to be displayed in the table viewer....
static void toggleTableStatus()
Toggles the table writing status, which will reduce the number or events send to the terminal.
void format(std::string **_sMatrix, long long int _nCol, long long int _nLine, const Settings &_option, bool bDontAsk=false, int nHeadLineCount=1)
void setPrefix(std::string _sPrefix)
void setPluginName(std::string _sPluginName)
void setCompact(bool _bCompact)
This class manages the setting values of the internal (kernel) settings of this application.
bool systemPrints() const
Returns, whether system messages shall be printed to the terminal.
bool useExternalDocWindow() const
Returns, whether documentations shall be displayed in external windows.
bool isDeveloperMode() const
Returns, whether the developer mode is currently enabled.
std::string getSavePath() const
Returns the current saving path.
std::string getExePath() const
Returns the current application root folder path.
unsigned int getStringCols() const
unsigned int getStringElements(unsigned int nCol=std::string::npos) const
std::vector< int > sortStringElements(long long int i1, long long int i2, long long int j1, long long int j2, const std::string &sSortingExpression)
This class represents a text file in memory (e.g. a code file). This class will try to lex the loaded...
std::string getStrippedLine(size_t line) const
Returns the selected line (without the line termination characters and without any comments).
void reStyle(const std::string &sComLine, const std::string &sDocComLine, const std::string &sComBlockStart, const std::string &sDocComBlockStart, const std::string &sComBlockEnd, const std::string &sStrMarks="", bool strings=true)
Can be used to change the code style detection sequences and to re-apply the lexer to the currently l...
int getLinesCount() const
Returns the number of lines in the current loaded file.
std::string getLine(size_t line) const
Returns the selected line (without the line termination characters).
Common exception class for all exceptions thrown in NumeRe.
@ TABLE_DOESNT_EXIST
INSERT HERE.
@ FILETYPE_MAY_NOT_BE_WRITTEN
static size_t invalid_position
This class abstracts all the index logics, i.e. the logical differences between single indices and in...
VectorIndex subidx(size_t pos, size_t nLen=std::string::npos) const
This member function returns a subset of the internal stored index just like the std::string::substr(...
int last() const
This member function returns the last index value, which can be reached by the values stored internal...
int max() const
This function calculates the maximal index value obtained from the values stored internally.
size_t size() const
This member function returns the size of the indices stored in this class.
bool isOpenEnd() const
This member function determines, whether the internal index set has an open end.
void setRange(int nMin, int nMax)
This member function can be used to force the indices stored internally to be in a defined interval....
std::string to_string() const
This member function converts the vector indexes contents into a human-readable string representation...
int & back()
This member function returns a reference to the final index value stored internally.
int min() const
This member function calculates the minimal index value obtained from the values stored internally.
int & front()
This member function returns a reference to the first index value stored internally.
Mathematical expressions parser.
Indices getIndices(StringView sCmd, mu::Parser &_parser, MemoryManager &_data, const Settings &_option)
Wrapper for the new getIndices function interface.
bool isValidIndexSet(const Indices &_idx)
bool sortData(CommandLineParser &cmdParser)
This function is a wrapper for the corresponding member function of the Datafile object.
bool readImage(CommandLineParser &cmdParser)
This function reads image data from an image file and stores it as a cache table.
static std::string ** make_stringmatrix(MemoryManager &_data, Output &_out, Settings &_option, const std::string &sCache, long long int &nLines, long long int &nCols, int &nHeadlineCount, size_t nPrecision, bool bSave)
This function transforms the data into a string matrix and returns the corresponding pointer.
static bool searchAndDeleteTable(const string &sCache, Parser &_parser, MemoryManager &_data, const Settings &_option)
This static function searches for the named table in the cache map, evaluates the specified indices a...
bool moveData(CommandLineParser &cmdParser)
This function will move the selected part of a data table to a new location.
bool CopyData(CommandLineParser &cmdParser)
This function copies whole chunks of data between tables.
void load_data(MemoryManager &_data, Settings &_option, Parser &_parser, string sFileName)
This function is a wrapper for the Datafile object. It will simply do the whole UI stuff and let the ...
std::string removeQuotationMarks(const std::string &)
This function simply removes the surrounding quotation marks.
bool deleteCacheEntry(CommandLineParser &cmdParser)
This function removes one or multiple entries in the selected table or cluster.
bool readFromFile(CommandLineParser &cmdParser)
This function reads the content of a file as strings and copies them to a temporary string vector var...
static bool searchAndDeleteCluster(const string &sCluster, Parser &_parser, MemoryManager &_data, const Settings &_option)
This static function searches for the named cluster in the cluster map, evaluates the specified indic...
static bool sortStrings(CommandLineParser &cmdParser, Indices &_idx)
This static function sorts strings and is called by sortData, if the selected data object equals "str...
void clear_cache(MemoryManager &_data, Settings &_option, bool bIgnore)
This function removes all allocated tables and frees the assigned memory.
void append_data(CommandLineParser &cmdParser)
This function handles appending data sets to already existing data.
static void performDataOperation(const string &sSource, const string &sTarget, const Indices &_iSourceIndex, const Indices &_iTargetIndex, MemoryManager &_data, bool bMove, bool bTranspose)
This function will perform the actual data operation.
static void evaluateTransposeForDataOperation(const string &sTarget, Indices &_iSourceIndex, Indices &_iTargetIndex, const MemoryManager &_data, bool bTranspose)
This function evaluates the transpose flag and switches the indices correspondingly.
bool writeToFile(CommandLineParser &cmdParser)
This function writes the string contents in the command to a file.
void show_data(MemoryManager &_data, Output &_out, Settings &_option, const string &_sCache, size_t nPrecision)
This function presents the passed data to the user in a visual way.
static bool sortClusters(CommandLineParser &cmdParser, const string &sCluster, Indices &_idx)
This static function sorts clusters and is called by sortData, if the selected data object equals a c...
bool fileExists(const string &)
This function checks, whether the file with the passed file name exists.
CONSTCD11 std::enable_if<!std::chrono::treat_as_floating_point< T >::value, T >::type trunc(T t) NOEXCEPT
CONSTCD11 std::chrono::duration< Rep, Period > abs(std::chrono::duration< Rep, Period > d)
bool isinf(const value_type &v)
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
This structure is central for managing the indices of a table or cluster read or write data access....
long long int intCast(const std::complex< double > &)
Casts the real part of the complex number to an integer and avoids rounding errors.
std::string toString(int)
Converts an integer to a string without the Settings bloat.