NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
dataops.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2018 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#include <wx/image.h>
20#include "dataops.hpp"
21#include "container.hpp"
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"
30std::string removeQuotationMarks(const std::string&);
31
32using namespace std;
33
34static void evaluateTransposeForDataOperation(const string& sTarget, Indices& _iSourceIndex, Indices& _iTargetIndex, const MemoryManager& _data, bool bTranspose);
35static void performDataOperation(const string& sSource, const string& sTarget, const Indices& _iSourceIndex, const Indices& _iTargetIndex, MemoryManager& _data, bool bMove, bool bTranspose);
36
37extern Language _lang;
38
39
53void load_data(MemoryManager& _data, Settings& _option, Parser& _parser, string sFileName)
54{
55 // check, if the filename is available
56 if (!sFileName.length())
57 {
58 // If not, prompt to the user
59 NumeReKernel::print(LineBreak(_lang.get("BUILTIN_LOADDATA_ENTER_NAME", _data.getPath()), _option));
60 do
61 {
63 NumeReKernel::getline(sFileName); // gesamte Zeile einlesen: Koennte ja auch eine Leerstelle enthalten sein
64 StripSpaces(sFileName);
65 }
66 while (!sFileName.length());
67
68 // If the user entered a 0 then he wants to abort
69 if (sFileName == "0")
70 {
71 NumeReKernel::print(_lang.get("COMMON_CANCEL"));
72 return;
73 }
74
75 }
76 // No data available in memory?
77 if (_data.isEmpty("data")) // Es sind noch keine Daten vorhanden?
78 {
79 _data.openFile(sFileName);
80 }
81 else // Sind sie doch? Dann muessen wir uns was ueberlegen...
82 {
83 // append the data?
84 string c = "";
85 NumeReKernel::print(LineBreak(_lang.get("BUILTIN_LOADDATA_ASK_APPEND", _data.getDataFileName("data")), _option));
88
89 // Abort, if user entered a zero
90 if (c == "0")
91 {
92 NumeReKernel::print(_lang.get("COMMON_CANCEL"));
93 return;
94 }
95 else if (c == _lang.YES()) // Anhaengen?
96 {
97 // append the data -> hand the control over to the corresponding function
98 CommandLineParser appCmdParser("append \"" + sFileName + "\"", "append", CommandLineParser::CMD_DAT_PAR);
99 append_data(appCmdParser);
100 }
101 else // Nein? Dann vielleicht ueberschreiben?
102 {
103 // overwrite?
104 c = "";
105 NumeReKernel::print(LineBreak(_lang.get("BUILTIN_LOADDATA_ASK_OVERRIDE"), _option));
106 NumeReKernel::printPreFmt("|\n|<- ");
108
109 if (c == _lang.YES()) // Also ueberschreiben
110 {
111 // Clear memory
112 _data.removeData(); // Speicher freigeben...
113
114 // Open the file and copy its contents
115 _data.openFile(sFileName);
116 }
117 else // Kannst du dich vielleicht mal entscheiden?
118 {
119 // User aborts
120 NumeReKernel::print(_lang.get("COMMON_CANCEL"));
121 }
122 }
123 }
124}
125
126
147static 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)
148{
149 nHeadlineCount = 1;
150
151 // Deactivate the compact flag, if the user uses the external viewer
152 if (_option.useExternalDocWindow())
153 _out.setCompact(false);
154
155 // If the compact flag is not set
156 if (!_out.isCompact())
157 {
158 // Get the dimensions of the complete headline (i.e. including possible linebreaks)
159 nHeadlineCount = _data.getHeadlineCount(sCache);
160 }
161
162 // Get the dimensions of the data and add the needed headlins
163 nLines = _data.getLines(sCache) + nHeadlineCount; // Wir muessen Zeilen fuer die Kopfzeile hinzufuegen
164 nCols = _data.getCols(sCache);
165
166 // Check for a reasonable dimension
167 if (!nCols)
169
170 if (_option.isDeveloperMode())
171 NumeReKernel::print("DEBUG: nLine = " + toString(nLines) + ", nCol = " + toString(nCols) );
172
173 if (nLines == nHeadlineCount)
174 nLines++;
175
176 // Create the formatting memory
177 string** sOut = new std::string*[nLines]; // die eigentliche Ausgabematrix. Wird spaeter gefuellt an Output::format(string**,int,int,Output&) uebergeben
178
179 for (long long int i = 0; i < nLines; i++)
180 {
181 sOut[i] = new std::string[nCols]; // Vollstaendig Allozieren!
182 }
183
184 // create a character buffer for sprintf
185 char cBuffer[50];
186
187 // Format the table
188 for (long long int i = 0; i < nLines; i++)
189 {
190 for (long long int j = 0; j < nCols; j++)
191 {
192 // The first line (at least) is reserved for the headline
193 if (!i) // Erste Zeile? -> Kopfzeilen uebertragen
194 {
195 // Get the headlines
196 if (_out.isCompact())
197 sOut[i][j] = _data.getTopHeadLineElement(j, sCache);
198 else
199 sOut[i][j] = _data.getHeadLineElement(j, sCache);
200
201 if (_out.isCompact() && (int)sOut[i][j].length() > 11 && !bSave)
202 {
203 // Truncate the headlines, if they are too long
204 sOut[i][j].replace(8, std::string::npos, "...");
205 }
206 else if (nHeadlineCount > 1 && sOut[i][j].find('\n') != string::npos)
207 {
208 // Store the complete headlines separated into the different rows
209 string sHead = sOut[i][j];
210 int nCount = 0;
211
212 for (unsigned int n = 0; n < sHead.length(); n++)
213 {
214 if (sHead[n] == '\n')
215 {
216 sOut[i + nCount][j] = sHead.substr(0, n);
217 sHead.erase(0, n + 1);
218 n = 0;
219 nCount++;
220 }
221 }
222
223 sOut[i + nCount][j] = sHead;
224 }
225
226 // If this is the last column, then set the line counter to the last headline row
227 if (j == nCols - 1)
228 i = nHeadlineCount - 1;
229 continue;
230 }
231
232 // Handle invalid numbers
233 if (!_data.isValidElement(i - nHeadlineCount, j, sCache))
234 {
235 sOut[i][j] = "---"; // Nullzeile? -> Da steht ja in Wirklichkeit auch kein Wert drin...
236 continue;
237 }
238
239 // Handle infinity
240 if (isinf(abs(_data.getElement(i - nHeadlineCount, j, sCache))) && _data.getElement(i - nHeadlineCount, j, sCache).real() > 0)
241 {
242 sOut[i][j] = "inf";
243 continue;
244 }
245
246 // Handle negative infinity
247 if (isinf(abs(_data.getElement(i - nHeadlineCount, j, sCache))) && _data.getElement(i - nHeadlineCount, j, sCache).real() < 0)
248 {
249 sOut[i][j] = "-inf";
250 continue;
251 }
252
253 // Transform the data to strings and write it to the string table
254 // We use the C-style conversion function sprintf(), because it is 4 times faster than
255 // using the stringstream conversion way.
256 if (_out.isCompact() && !bSave)
257 sprintf(cBuffer, "%.*g", 4, _data.getElement(i - nHeadlineCount, j, sCache).real());
258 else
259 sprintf(cBuffer, "%.*g", nPrecision, _data.getElement(i - nHeadlineCount, j, sCache).real());
260
261 sOut[i][j] = cBuffer;
262 }
263 }
264 // return the string table
265 return sOut;
266}
267
268
281void show_data(MemoryManager& _data, Output& _out, Settings& _option, const string& _sCache, size_t nPrecision)
282{
283 string sCache = _sCache;
284 string sFileName;
285
286 // Do only stuff, if data is available
287 if (_data.isValid()) // Sind ueberhaupt Daten vorhanden?
288 {
289 if (_option.useExternalDocWindow())
290 {
291 NumeReKernel::showTable(_data.extractTable(sCache), sCache.substr(sCache.front() == '*' ? 1 : 0));
292 return;
293 }
294
295 long long int nLine = 0;
296 long long int nCol = 0;
297 int nHeadlineCount = 0;
298
299 // Get the string matrix
300 string** sOut = make_stringmatrix(_data, _out, _option, sCache, nLine, nCol, nHeadlineCount, nPrecision, false);
301
302 // Remove the possible asterisk at the front of the cache name
303 if (sCache.front() == '*')
304 sCache.erase(0, 1); // Vorangestellten Unterstrich wieder entfernen
305
306 _out.setPrefix(sCache);
307
308 // Set the "plugin origin"
309 _out.setPluginName("Datenanzeige der Daten aus " + _data.getDataFileName(sCache)); // Anzeige-Plugin-Parameter: Nur Kosmetik
310
311 // Print the table to the console: write the headline
313 make_hline();
314 NumeReKernel::print("NUMERE: " + toUpperCase(sCache) + "()");
315 make_hline();
316
317 // Format the table (either for the console or for the target file)
318 _out.format(sOut, nCol, nLine, _option, true, nHeadlineCount); // Eigentliche Ausgabe
319 _out.reset();
320
321 // Print the table to the console: write the footer
323 make_hline();
324
325 // Clear the created memory
326 for (long long int i = 0; i < nLine; i++)
327 {
328 delete[] sOut[i]; // WICHTIG: Speicher immer freigeben!
329 }
330
331 delete[] sOut;
332 }
333 else
335}
336
337
347{
349 const Settings& _option = NumeReKernel::getInstance()->getSettings();
350
351 // Copy the default path and the path tokens
352 int nArgument = 0;
353 std::string sFileList = cmdParser.parseExprAsString();
354
355 // If the command expression contains the parameter "all" and the
356 // argument (i.e. the filename) contains wildcards
357 if (cmdParser.hasParam("all") && (sFileList.find('*') != string::npos || sFileList.find('?') != string::npos))
358 {
359 // Insert the default loadpath, if no path is passed
360 if (sFileList.find('/') == string::npos)
361 sFileList = "<loadpath>/" + sFileList;
362
363 // Get the file list, which fulfills the file path scheme
364 vector<string> vFilelist = getFileList(sFileList, _option, true);
365
366 // Ensure that at least one file exists
367 if (!vFilelist.size())
369
370 // Go through all elements in the vFilelist list
371 for (size_t i = 0; i < vFilelist.size(); i++)
372 {
373 // Load the data. The melting of multiple files
374 // is processed automatically
375 _data.setbLoadEmptyColsInNextFile(cmdParser.hasParam("keepdim") || cmdParser.hasParam("complete"));
376 _data.openFile(vFilelist[i]);
377 }
378
379 // Inform the user and return
380 if (!_data.isEmpty("data") && _option.systemPrints())
381 NumeReKernel::print(LineBreak(_lang.get("BUILTIN_APPENDDATA_ALL_SUCCESS", toString((int)vFilelist.size()), sFileList, toString(_data.getLines("data", false)), toString(_data.getCols("data", false))), _option));
382
383 return;
384 }
385
387
388 _data.setbLoadEmptyColsInNextFile(cmdParser.hasParam("keepdim") || cmdParser.hasParam("complete"));
389 // Simply load the data directly -> Melting is done automatically
390 if (cmdParser.hasParam("head") || cmdParser.hasParam("h"))
391 {
392 if (cmdParser.hasParam("head"))
393 {
394 auto vPar = cmdParser.getParameterValueAsNumericalValue("head");
395
396 if (vPar.size())
397 nArgument = intCast(vPar.front());
398 }
399 else
400 {
401 auto vPar = cmdParser.getParameterValueAsNumericalValue("h");
402
403 if (vPar.size())
404 nArgument = intCast(vPar.front());
405 }
406
407 info = _data.openFile(sFileList, false, nArgument);
408 }
409 else
410 info = _data.openFile(sFileList);
411
412 // Inform the user
413 if (!_data.isEmpty("data") && _option.systemPrints())
414 NumeReKernel::print(LineBreak(_lang.get("BUILTIN_LOADDATA_SUCCESS", info.sFileName, toString(info.nRows), toString(info.nCols)), _option));
415}
416
417
428void clear_cache(MemoryManager& _data, Settings& _option, bool bIgnore)
429{
430 // Only if there is valid data in the cache
431 if (_data.isValid())
432 {
433 // If the flag "ignore" is not set, ask the user for confirmation
434 if (!bIgnore)
435 {
436 string c = "";
437
438 if (!_data.getSaveStatus())
439 NumeReKernel::print(LineBreak(_lang.get("BUILTIN_CLEARCACHE_CONFIRM_NOTSAFED"), _option));
440 else
441 NumeReKernel::print(LineBreak(_lang.get("BUILTIN_CLEARCACHE_CONFIRM"), _option));
442
443 NumeReKernel::printPreFmt("|\n|<- ");
445
446 if (c != _lang.YES())
447 {
448 NumeReKernel::print(_lang.get("COMMON_CANCEL"));
449 return;
450 }
451 }
452
453 string sAutoSave = _option.getSavePath() + "/cache.tmp";
454 string sCache_file = _option.getExePath() + "/numere.cache";
455
456 // Clear the complete cache and remove the cache files
458 remove(sAutoSave.c_str());
459 remove(sCache_file.c_str());
460
461 // Inform the user, if printing is allowed
462 if (_option.systemPrints())
463 NumeReKernel::print(LineBreak(_lang.get("BUILTIN_CLEARCACHE_SUCCESS"), _option));
464 }
465 else if (_option.systemPrints())
466 NumeReKernel::print(LineBreak(_lang.get("BUILTIN_CLEARCACHE_EMPTY"), _option));
467}
468
469
483static bool searchAndDeleteTable(const string& sCache, Parser& _parser, MemoryManager& _data, const Settings& _option)
484{
485 for (auto iter = _data.getTableMap().begin(); iter != _data.getTableMap().end(); ++iter)
486 {
487 if (sCache.substr(0, sCache.find('(')) == iter->first)
488 {
489 // Cache was found
490 // Get the indices from the cache expression
491 Indices _iDeleteIndex = getIndices(sCache, _parser, _data, _option);
492
493 // Check the indices
494 if (!isValidIndexSet(_iDeleteIndex))
495 return false;
496
497 // Evaluate the indices
498 if (_iDeleteIndex.row.isOpenEnd())
499 _iDeleteIndex.row.setRange(0, _data.getLines(iter->first, false)-1);
500
501 if (_iDeleteIndex.col.isOpenEnd())
502 _iDeleteIndex.col.setRange(0, _data.getCols(iter->first)-1);
503
504 // Delete the section identified by the cache expression
505 // The indices are vectors
506 _data.deleteBulk(iter->first, _iDeleteIndex.row, _iDeleteIndex.col);
507
508 // If everything is deleted, reset the meta data as well
509 if (_data.isEmpty(iter->first))
510 {
511 NumeRe::TableMetaData meta = _data.getMetaData(iter->first);
512 meta.comment.clear();
513 meta.source.clear();
514 meta.modify();
515 _data.setMetaData(iter->first, meta);
516 }
517
518 // Return true
519 return true;
520 }
521 }
522
523 return false;
524}
525
526
540static bool searchAndDeleteCluster(const string& sCluster, Parser& _parser, MemoryManager& _data, const Settings& _option)
541{
542 for (auto iter = _data.getClusterMap().begin(); iter != _data.getClusterMap().end(); ++iter)
543 {
544 if (sCluster.substr(0, sCluster.find('{')) == iter->first)
545 {
546 // Cache was found
547 // Get the indices from the cache expression
548 Indices _iDeleteIndex = getIndices(sCluster, _parser, _data, _option);
549
550 // Check the indices
551 if (!isValidIndexSet(_iDeleteIndex))
552 return false;
553
554 // Evaluate the indices
555 if (_iDeleteIndex.row.isOpenEnd())
556 _iDeleteIndex.row.setRange(0, _data.getCluster(iter->first).size()-1);
557
558 // Delete the section identified by the cache expression
559 // The indices are vectors
560 _data.getCluster(iter->first).deleteItems(_iDeleteIndex.row);
561
562 // Return true
563 return true;
564 }
565 }
566
567 return false;
568}
569
570
580{
583 const Settings& _option = NumeReKernel::getInstance()->getSettings();
584 bool bSuccess = false;
585
586 // Remove the command from the command line
587 std::string sExpr = cmdParser.getExpr();
588
589 // As long as a next argument may be extracted
590 while (sExpr.length())
591 {
592 // Get the next argument
593 string sCache = getNextArgument(sExpr, true);
594
595 // Try to find the current cache in the list of available caches
596 StripSpaces(sCache);
597
598 // Is it a normal table?
599 if (!_data.isCluster(sCache) && searchAndDeleteTable(sCache, _parser, _data, _option))
600 bSuccess = true;
601
602 // Is it a cluster?
603 if (_data.isCluster(sCache) && searchAndDeleteCluster(sCache, _parser, _data, _option))
604 bSuccess = true;
605 }
606
607 // return the value of the boolean flag
608 return bSuccess;
609}
610
611
621{
623
624 bool bTranspose = cmdParser.hasParam("transpose");
625 Indices _iTargetIndex;
626
627 // Get the target from the option or use the default one
628 std::string sTarget = cmdParser.getTargetTable(_iTargetIndex, "table");
629
630 // Get the actual source data name and the corresponding indices
631 DataAccessParser accessParser = cmdParser.getExprAsDataObject();
632 accessParser.evalIndices();
633
634 if (!accessParser.getDataObject().length())
635 return false;
636
637 // Apply the transpose flag on the indices, if necessary
638 evaluateTransposeForDataOperation(sTarget, accessParser.getIndices(), _iTargetIndex, _data, bTranspose);
639
640 // Perform the actual data operation. Move is set to false
641 performDataOperation(accessParser.getDataObject(), sTarget, accessParser.getIndices(), _iTargetIndex, _data, false, bTranspose);
642
643 return true;
644}
645
646
656{
658
659 bool bTranspose = cmdParser.hasParam("transpose");
660 Indices _iTargetIndex;
661
662 // Get the target expression from the option. The default one is empty and will raise an error
663 std::string sTarget = cmdParser.getTargetTable(_iTargetIndex, "");
664
665 // If the target cache name is empty, raise an error
666 if (!sTarget.length())
667 return false;
668
669 // Get the actual source data name and the corresponding indices
670 DataAccessParser accessParser = cmdParser.getExprAsDataObject();
671 accessParser.evalIndices();
672
673 if (!accessParser.getDataObject().length())
674 return false;
675
676 // Apply the transpose flag on the indices, if necessary
677 evaluateTransposeForDataOperation(sTarget, accessParser.getIndices(), _iTargetIndex, _data, bTranspose);
678
679 // Perform the actual data operation. Move is set to true
680 performDataOperation(accessParser.getDataObject(), sTarget, accessParser.getIndices(), _iTargetIndex, _data, true, bTranspose);
681
682 return true;
683}
684
685
698static void evaluateTransposeForDataOperation(const string& sTarget, Indices& _iSourceIndex, Indices& _iTargetIndex, const MemoryManager& _data, bool bTranspose)
699{
700 if (!isValidIndexSet(_iTargetIndex))
701 {
702 // This section is for cases, in which the target was not defined
703 // Get the dimensions of the target to calculate the indices correspondingly
704 // Depending on the transpose flag, the rows and columns are exchanged
705 if (!bTranspose)
706 {
707 _iTargetIndex.row = VectorIndex(0LL, _iSourceIndex.row.size());
708 _iTargetIndex.col = VectorIndex(_data.getCols(sTarget, false), _data.getCols(sTarget, false) + _iSourceIndex.col.size());
709 }
710 else
711 {
712 _iTargetIndex.row = VectorIndex(0LL, _iSourceIndex.col.size());
713 _iTargetIndex.col = VectorIndex(_data.getCols(sTarget, false), _data.getCols(sTarget, false) + _iSourceIndex.row.size());
714 }
715 }
716 else if (_iTargetIndex.row.size())
717 {
718 // This section is for cases, in which the target was defined via vectors
719 // Get the dimensions of the target to calculate the indices correspondingly
720 // Depending on the transpose flag, the rows and columns are exchanged
721 //
722 // The vectors are cleared because they will probably contain not reasonable data
723 if (!bTranspose)
724 {
725 if (_iTargetIndex.row.isOpenEnd())
726 _iTargetIndex.row = VectorIndex(_iTargetIndex.row.front(), _iTargetIndex.row.front() + _iSourceIndex.row.size());
727
728 if (_iTargetIndex.col.isOpenEnd())
729 _iTargetIndex.col = VectorIndex(_iTargetIndex.col.front(), _iTargetIndex.col.front() + _iSourceIndex.col.size());
730 }
731 else
732 {
733 if (_iTargetIndex.row.isOpenEnd())
734 _iTargetIndex.row = VectorIndex(_iTargetIndex.row.front(), _iTargetIndex.row.front() + _iSourceIndex.col.size());
735
736 if (_iTargetIndex.col.isOpenEnd())
737 _iTargetIndex.col = VectorIndex(_iTargetIndex.col.front(), _iTargetIndex.col.front() + _iSourceIndex.row.size());
738 }
739 }
740}
741
742
757static void performDataOperation(const string& sSource, const string& sTarget, const Indices& _iSourceIndex, const Indices& _iTargetIndex, MemoryManager& _data, bool bMove, bool bTranspose)
758{
759 MemoryManager _cache;
760
761 // First step: copy the contents to the Datafile _cache
762 // If the move flag is set, then the contents are cleared at the source location
763 // vector indices
764 for (unsigned int i = 0; i < _iSourceIndex.row.size(); i++)
765 {
766 for (unsigned int j = 0; j < _iSourceIndex.col.size(); j++)
767 {
768 if (!i)
769 _cache.setHeadLineElement(j, "table", _data.getHeadLineElement(_iSourceIndex.col[j], sSource));
770
771 if (_data.isValidElement(_iSourceIndex.row[i], _iSourceIndex.col[j], sSource))
772 {
773 _cache.writeToTable(i, j, "table", _data.getElement(_iSourceIndex.row[i], _iSourceIndex.col[j], sSource));
774
775 if (bMove)
776 _data.deleteEntry(_iSourceIndex.row[i], _iSourceIndex.col[j], sSource);
777 }
778 }
779 }
780
781 // Second step: Copy the contents in "_cache" to the new location in the original Datafile object
782
783 for (long long int i = 0; i < _cache.getLines("table", false); i++)
784 {
785 // Break the operation, if the indices are marking a smaller section
786 if (!bTranspose)
787 {
788 if (i >= _iTargetIndex.row.size())
789 break;
790 }
791 else
792 {
793 if (i >= _iTargetIndex.col.size())
794 break;
795 }
796 for (long long int j = 0; j < _cache.getCols("table", false); j++)
797 {
798 if (!bTranspose)
799 {
800 // Write the headlines
801 if (!_iTargetIndex.row[i] && _data.getHeadLineElement(_iTargetIndex.col[j], sTarget).substr(0, 6) == "Spalte")
802 {
803 _data.setHeadLineElement(_iTargetIndex.col[j], sTarget, _cache.getHeadLineElement(j, "table"));
804 }
805
806 // Break the operation, if the indices are marking a smaller section
807 if (j > _iTargetIndex.col.size())
808 break;
809
810 // Write the data. Invalid data is deleted explicitly, because it might already contain old data
811 if (_cache.isValidElement(i, j, "table"))
812 _data.writeToTable(_iTargetIndex.row[i], _iTargetIndex.col[j], sTarget, _cache.getElement(i, j, "table"));
813 else if (_data.isValidElement(_iTargetIndex.row[i], _iTargetIndex.col[j], sTarget))
814 _data.deleteEntry(_iTargetIndex.row[i], _iTargetIndex.col[j], sTarget);
815 }
816 else
817 {
818 // We don't have headlines in this case
819 // Break the operation, if the indices are marking a smaller section
820 if (j > _iTargetIndex.row.size())
821 break;
822
823 // Write the data. Invalid data is deleted explicitly, because it might already contain old data
824 if (_cache.isValidElement(i, j, "table"))
825 _data.writeToTable(_iTargetIndex.col[j], _iTargetIndex.row[i], sTarget, _cache.getElement(i, j, "table"));
826 else if (_data.isValidElement(_iTargetIndex.col[j], _iTargetIndex.row[i], sTarget))
827 _data.deleteEntry(_iTargetIndex.col[j], _iTargetIndex.row[i], sTarget);
828 }
829 }
830 }
831}
832
833
844static bool sortStrings(CommandLineParser& cmdParser, Indices& _idx)
845{
846 vector<int> vSortIndex;
848
849 // Evalulate special index values
850 if (_idx.row.isOpenEnd())
851 _idx.row.setRange(0, _data.getStringElements(_idx.col.front())-1);
852
853 if (_idx.col.isOpenEnd())
854 _idx.col.setRange(0, _data.getStringCols()-1);
855
856 // Perform the actual sorting operation
857 // The member function will be able to handle the remaining command line parameters by itself
858 vSortIndex = _data.sortStringElements(_idx.row.front(), _idx.row.back(), _idx.col.front(), _idx.col.back(), cmdParser.getParameterList());
859
860 // If the sorting index contains elements, the user had requested them
861 if (vSortIndex.size())
862 {
863 // Transform the integer indices into doubles
864 vector<mu::value_type> vDoubleSortIndex;
865
866 for (size_t i = 0; i < vSortIndex.size(); i++)
867 vDoubleSortIndex.push_back(vSortIndex[i]);
868
869 // Set the vector name and set the vector for the parser
870 cmdParser.setReturnValue(vDoubleSortIndex);
871 }
872 else
873 cmdParser.clearReturnValue(); // simply clear, if the user didn't request a sorting index
874
875 // Return true
876 return true;
877}
878
879
891static bool sortClusters(CommandLineParser& cmdParser, const string& sCluster, Indices& _idx)
892{
893 vector<int> vSortIndex;
895
896 // Evalulate special index values
897 if (_idx.row.isOpenEnd())
898 _idx.row.setRange(0, cluster.size()-1);
899
900 // Perform the actual sorting operation
901 // The member function will be able to handle the remaining command line parameters by itself
902 vSortIndex = cluster.sortElements(_idx.row.front(), _idx.row.back(), cmdParser.getParameterList());
903
904 // If the sorting index contains elements, the user had requested them
905 if (vSortIndex.size())
906 {
907 // Transform the integer indices into doubles
908 vector<mu::value_type> vDoubleSortIndex;
909
910 for (size_t i = 0; i < vSortIndex.size(); i++)
911 vDoubleSortIndex.push_back(vSortIndex[i]);
912
913 // Set the vector name and set the vector for the parser
914 cmdParser.setReturnValue(vDoubleSortIndex);
915 }
916 else
917 cmdParser.clearReturnValue(); // simply clear, if the user didn't request a sorting index
918
919 // Return true
920 return true;
921}
922
923
934{
935 vector<int> vSortIndex;
936 DataAccessParser _accessParser = cmdParser.getExprAsDataObject();
937
938 if (!_accessParser.getDataObject().length())
940
941 // Get the indices
942 Indices& _idx = _accessParser.getIndices();
943
944 // Ensure that the indices are reasonable
945 if (!isValidIndexSet(_idx))
946 throw SyntaxError(SyntaxError::INVALID_INDEX, cmdParser.getCommandLine(), "", _idx.row.to_string() + ", " + _idx.col.to_string());
947
948 // If the current cache equals to "string", leave the function at
949 // this point and redirect the control to the string sorting
950 // function
951 if (_accessParser.getDataObject() == "string")
952 return sortStrings(cmdParser, _idx);
953
954 // If the current cache equals a cluster, leave the function at
955 // this point and redirect the control to the cluster sorting
956 // function
957 if (_accessParser.isCluster())
958 return sortClusters(cmdParser, _accessParser.getDataObject(), _idx);
959
961
962 // Evalulate special index values
963 _accessParser.evalIndices();
964
965 // Perform the actual sorting operation
966 // The member function will be able to handle the remaining command line parameters by itself
967 vSortIndex = _data.sortElements(_accessParser.getDataObject(),
968 _idx.row.front(), _idx.row.last(), _idx.col.front(), _idx.col.last(),
969 cmdParser.getParameterList());
970
971 // If the sorting index contains elements, the user had requested them
972 if (vSortIndex.size())
973 {
974 // Transform the integer indices into doubles
975 vector<mu::value_type> vDoubleSortIndex;
976 for (size_t i = 0; i < vSortIndex.size(); i++)
977 vDoubleSortIndex.push_back(vSortIndex[i]);
978
979 // Set the vector name and set the vector for the parser
980 cmdParser.setReturnValue(vDoubleSortIndex);
981 }
982 else
983 cmdParser.clearReturnValue(); // simply clear, if the user didn't request a sorting index
984
985 // Return true
986 return true;
987}
988
989
999{
1000 fstream fFile;
1001 string sFileName;
1002
1003 bool bAppend = false;
1004 bool bTrunc = true;
1005 bool bNoQuotes = cmdParser.hasParam("nq") || cmdParser.hasParam("noquotes");
1006 bool bKeepEmptyLines = cmdParser.hasParam("keepdim") || cmdParser.hasParam("k");
1007 FileSystem _fSys;
1008 _fSys.initializeFromKernel();
1009
1010 // Try to find the parameter string
1011 if (cmdParser.getParameterList().length())
1012 {
1013 // Get the file name
1014 if (cmdParser.hasParam("file"))
1015 {
1016 sFileName = cmdParser.getFileParameterValueForSaving(".txt", "<savepath>", "");
1017
1018 // Scripts, procedures and data files may not be written directly
1019 // this avoids reloads during the execution and other unexpected
1020 // behavior
1021 if (sFileName.substr(sFileName.rfind('.')) == ".nprc"
1022 || sFileName.substr(sFileName.rfind('.')) == ".nscr"
1023 || sFileName.substr(sFileName.rfind('.')) == ".ndat")
1024 {
1025 string sErrorToken;
1026
1027 if (sFileName.substr(sFileName.rfind('.')) == ".nprc")
1028 sErrorToken = "NumeRe-Prozedur";
1029 else if (sFileName.substr(sFileName.rfind('.')) == ".nscr")
1030 sErrorToken = "NumeRe-Script";
1031 else if (sFileName.substr(sFileName.rfind('.')) == ".ndat")
1032 sErrorToken = "NumeRe-Datenfile";
1033
1035 }
1036 }
1037
1038 // Get the file open mode
1039 std::string sMode = cmdParser.getParameterValue("mode");
1040
1041 if (sMode.length())
1042 {
1043 if (sMode == "append" || sMode == "app")
1044 bAppend = true;
1045 else if (sMode == "trunc")
1046 bTrunc = true;
1047 else if (sMode == "override" || sMode == "overwrite")
1048 {
1049 bAppend = false;
1050 bTrunc = false;
1051 }
1052 else
1053 return false;
1054 }
1055 }
1056
1057 // Ensure that a filename is available
1058 if (!sFileName.length())
1060
1061 // Extract the expression
1062 std::string sExpression = cmdParser.getExpr();
1063
1064 // Parse the expression, which should be a string
1065 if (NumeReKernel::getInstance()->getStringParser().isStringExpression(sExpression)
1066 || NumeReKernel::getInstance()->getMemoryManager().containsClusters(sExpression))
1067 {
1068 sExpression += " -komq";
1069 string sDummy = "";
1070 NumeReKernel::getInstance()->getStringParser().evalAndFormat(sExpression, sDummy, true);
1071 }
1072 else
1074
1075 // Open the file in the selected mode
1076 if (bAppend)
1077 fFile.open(sFileName.c_str(), ios_base::app | ios_base::out | ios_base::ate);
1078 else if (bTrunc)
1079 fFile.open(sFileName.c_str(), ios_base::trunc | ios_base::out);
1080 else
1081 {
1082 if (!fileExists(sFileName))
1083 ofstream fTemp(sFileName.c_str());
1084
1085 fFile.open(sFileName.c_str());
1086 }
1087
1088 // Ensure that the file is read- and writable
1089 if (fFile.fail())
1091
1092 // Ensure that the expression has a length and is not only an empty quotation marks pair
1093 if ((!sExpression.length() || sExpression == "\"\"") && !bKeepEmptyLines)
1095
1096 // Write the expression linewise
1097 // Add linebreaks after each subexpression
1098 while (sExpression.length())
1099 {
1100 // get the next argument
1101 std::string sArgument = getNextArgument(sExpression, true);
1102 StripSpaces(sArgument);
1103
1104 // Remove quotation marks if desired
1105 if (bNoQuotes && sArgument[0] == '"' && sArgument[sArgument.length() - 1] == '"')
1106 sArgument = sArgument.substr(1, sArgument.length() - 2);
1107
1108 // Write only strings, which are not empty
1109 if ((!sArgument.length() || sArgument == "\"\"") && !bKeepEmptyLines)
1110 continue;
1111
1112 // Remove escaped characters
1113 //while (sArgument.find("\\\"") != string::npos)
1114 //{
1115 // sArgument.erase(sArgument.find("\\\""), 1);
1116 //}
1117 //if (sArgument.length() >= 2 && sArgument.substr(sArgument.length() - 2) == "\\ ")
1118 // sArgument.pop_back();
1119
1120 // Pass the curent argument to the file stream
1121 fFile << sArgument << endl;
1122
1123 // Break the loop, if the expression only contains a single comma
1124 if (sExpression == ",")
1125 break;
1126 }
1127
1128 // close the file stream if it is open and return
1129 if (fFile.is_open())
1130 fFile.close();
1131
1132 return true;
1133}
1134
1135
1146{
1147 std::string sInput = "";
1148 std::string sCommentEscapeSequence = cmdParser.getParameterValueAsString("comments", "");
1149 std::string sStringSequence = cmdParser.getParameterValueAsString("qmarks", "");
1150
1151 bool bKeepEmptyLines = cmdParser.hasParam("keepdim") || cmdParser.hasParam("k");
1152
1153 if (sCommentEscapeSequence != " ")
1154 StripSpaces(sCommentEscapeSequence);
1155
1156 StripSpaces(sStringSequence);
1157
1158 // Get the source file name from the command string or the parameter list
1159 std::string sFileName = cmdParser.getExprAsFileName(".txt");
1160
1161 // Ensure that a filename is present
1162 if (!sFileName.length())
1164
1165 // Open the file and ensure that it is readable
1166 StyledTextFile fFile(sFileName);
1167
1168 if (!fFile.getLinesCount())
1170
1171 if (sCommentEscapeSequence.length())
1172 {
1173 replaceAll(sCommentEscapeSequence, "\\t", "\t");
1174 replaceAll(sStringSequence, "\\\"", "\"");
1175
1176 EndlessVector<std::string> args = getAllArguments(sCommentEscapeSequence);
1177 fFile.reStyle(removeQuotationMarks(args[0]),
1178 removeQuotationMarks(args[0]),
1179 removeQuotationMarks(args[1]),
1180 removeQuotationMarks(args[1]),
1181 removeQuotationMarks(args[2]),
1182 sStringSequence,
1183 sStringSequence.length() != 0);
1184 }
1185
1186 // create a new vector for the file's contents
1187 vector<string> vFileContents;
1188
1189 // Read the complete file, where each line is a separate string expression
1190 for (int i = 0; i < fFile.getLinesCount(); i++)
1191 {
1192 std::string sLine = sCommentEscapeSequence.length() ? fFile.getStrippedLine(i) : fFile.getLine(i);
1193
1194 // Omit empty lines
1195 if (!sLine.length() || sLine == "\"\"" || sLine == "\"")
1196 {
1197 if (bKeepEmptyLines && i+1 < fFile.getLinesCount())
1198 vFileContents.push_back("\"\"");
1199
1200 continue;
1201 }
1202
1203 // Add the missing quotation marks
1204 if (sLine.front() != '"')
1205 sLine = '"' + sLine;
1206
1207 if (sLine.back() != '"')
1208 sLine += '"';
1209
1210 // Append the parsed string to the vector
1211 vFileContents.push_back(sLine);
1212 }
1213
1214 // Create a new temporary variable, if we actually
1215 // read something from the file
1216 if (vFileContents.size())
1217 cmdParser.setReturnValue(vFileContents);
1218 else
1219 cmdParser.setReturnValue("\"\"");
1220
1221 // return true
1222 return true;
1223}
1224
1225
1235{
1237
1238 std::string sChannels = "grey";
1239 Indices _idx;
1240 std::vector<mu::value_type> vIndices;
1241
1242 // Get the target cache from the command line or use the default one
1243 std::string sTargetCache = cmdParser.getTargetTable(_idx, "image");
1244
1245 // Get the file name from the command line or the parameter list
1246 std::string sFileName = cmdParser.getExprAsFileName(".bmp");
1247
1248 if (cmdParser.hasParam("channels"))
1249 sChannels = cmdParser.getParameterValueAsString("channels", "grey");
1250
1251 // Ensure that a filename is present
1252 if (!sFileName.length())
1254
1255 // Initialize all wxWidgets image handlers (should already be available, though)
1256 wxInitAllImageHandlers();
1257
1258 // Create the image object
1259 wxImage image;
1260
1261 g_logger.info("Loading image file '" + sFileName + "'.");
1262
1263 // Load the file to the image object (wxWidgets will try to autodetect the image file format)
1264 // and throw an error, if it doesn't succeed
1265 if (!image.LoadFile(sFileName, wxBITMAP_TYPE_ANY))
1266 {
1268 }
1269
1270 // Get the dimensions of the data and the pointer to the data itself
1271 int nWidth = image.GetWidth();
1272 int nHeight = image.GetHeight();
1273 unsigned char* imageData = image.GetData();
1274
1275 // Evaluate the indices correspondingly
1276 if (_idx.row.isOpenEnd())
1277 _idx.row.setRange(0, _idx.row.front() + std::max(nWidth, nHeight)-1);
1278
1279 if (_idx.col.isOpenEnd() && sChannels == "grey")
1280 _idx.col.setRange(0, _idx.col.front() + 2 + nHeight-1);
1281 else if (_idx.col.isOpenEnd())
1282 _idx.col.setRange(0, _idx.col.front() + 2 + sChannels.length()*nHeight - 1);
1283
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);
1288
1289 int rowmax = _idx.row.subidx(0, nWidth).max();
1290 Memory* _table = _data.getTable(sTargetCache);
1291
1292 // Write the axes to the target cache
1293 for (int i = 0; i < nWidth; i++)
1294 {
1295 if (_idx.row[i] == VectorIndex::INVALID)
1296 break;
1297
1298 _table->writeData(_idx.row[i], _idx.col.front(), i + 1);
1299 }
1300
1301 for (int i = 0; i < nHeight; i++)
1302 {
1303 if (_idx.row[i] == VectorIndex::INVALID)
1304 break;
1305
1306 _table->writeData(_idx.row[i], _idx.col[1], i + 1);
1307
1308 if (sChannels == "grey")
1309 _table->writeData(rowmax, _idx.col[2+i], 0.0);
1310 else
1311 {
1312 for (size_t n = 0; n < sChannels.length(); n++)
1313 _table->writeData(rowmax, _idx.col[2+i + n*nHeight], 0.0);
1314 }
1315 }
1316
1317 // Write headlines
1318 _data.setHeadLineElement(_idx.col[0], sTargetCache, "x");
1319 _data.setHeadLineElement(_idx.col[1], sTargetCache, "y");
1320
1321 g_logger.debug("Writing image data to table.");
1322
1323 // Copy the average of the RGB channels (grey scale) to the data object
1324 #pragma omp parallel for
1325 for (int j = 0; j < nHeight; j++)
1326 {
1327 int iData = 0;
1328
1329 if (_idx.col[j+2] == VectorIndex::INVALID)
1330 continue;
1331
1332 if (sChannels == "grey")
1333 _table->setHeadLineElement(_idx.col[2+j], "z(x(:),y(" + toString(j+1) + "))");
1334 else
1335 {
1336 for (size_t n = 0; n < sChannels.length(); n++)
1337 _table->setHeadLineElement(_idx.col[2+j + n*nHeight], "z(x(:),y(" + toString(j) + "))_"+sChannels[n]);
1338 }
1339
1340 for (int i = 0; i < nWidth; i++)
1341 {
1342 if (_idx.row[i] == VectorIndex::INVALID)
1343 break;
1344
1345 // The actual copy process
1346 if (sChannels == "grey")
1347 {
1348 // Calculate the luminosity of the three channels and write it to the table
1349 _table->writeDataDirectUnsafe(_idx.row[i],
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);
1354 }
1355 else
1356 {
1357 for (size_t n = 0; n < sChannels.length(); n++)
1358 {
1359 // Store the selected channel
1360 switch (sChannels[n])
1361 {
1362 case 'r':
1363 _table->writeDataDirectUnsafe(_idx.row[i],
1364 _idx.col[2 + (nHeight - j - 1) + n*nHeight],
1365 imageData[j * 3 * nWidth + iData]);
1366 break;
1367 case 'g':
1368 _table->writeDataDirectUnsafe(_idx.row[i],
1369 _idx.col[2 + (nHeight - j - 1) + n*nHeight],
1370 imageData[j * 3 * nWidth + iData + 1]);
1371 break;
1372 case 'b':
1373 _table->writeDataDirectUnsafe(_idx.row[i],
1374 _idx.col[2 + (nHeight - j - 1) + n*nHeight],
1375 imageData[j * 3 * nWidth + iData + 2]);
1376 break;
1377 }
1378 }
1379 }
1380
1381 // Advance the iterator three channels
1382 iData += 3;
1383 }
1384 }
1385
1386 _table->markModified();
1387 g_logger.debug("Image file loaded.");
1388
1389 cmdParser.setReturnValue(vIndices);
1390
1391 // return true
1392 return true;
1393}
1394
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 ...
Definition: dataaccess.hpp:38
Indices & getIndices()
Returns a reference to the stored indices.
Definition: dataaccess.cpp:196
void evalIndices()
Evaluates open end indices using the identified data object size.
Definition: dataaccess.cpp:141
bool isCluster() const
Determines, whether the data access references a cluster.
Definition: dataaccess.cpp:209
std::string & getDataObject()
Returns a reference to the data object identifier.
Definition: dataaccess.cpp:170
void info(const std::string &sMessage)
Convenience member function.
Definition: logger.hpp:106
void debug(const std::string &sMessage)
Convenience member function.
Definition: logger.hpp:94
This class extends the std::vector for endlessness.
Definition: structures.hpp:838
This class implements the basic input/ output file system and provides functionalities to work with f...
Definition: filesystem.hpp:92
void initializeFromKernel()
Member function to remote-initialize the class from the kernel. Cannot be used during kernel start-up...
Definition: filesystem.cpp:750
std::string getPath() const
Returns the default path of this FileSystem instance.
Definition: filesystem.cpp:547
This class handles the internal language system and returns the language strings of the selected lang...
Definition: language.hpp:38
std::string YES() const
Definition: language.hpp:197
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 ...
Definition: language.cpp:292
This class represents a single table in memory, or a - so to say - single memory page to be handled b...
Definition: memory.hpp:68
void markModified()
Mark this table as modified.
Definition: memory.cpp:1121
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...
Definition: memory.cpp:1219
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....
Definition: memory.cpp:1271
bool setHeadLineElement(size_t _i, const std::string &_sHead)
Writes a new table column headline to the selected column.
Definition: memory.cpp:1068
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...
Definition: cluster.hpp:325
size_t size() const
This member function returns the size of the internal memory buffer as items.
Definition: cluster.cpp:356
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.
Definition: cluster.cpp:1009
void deleteItems(long long int i1, long long int i2)
This public member function erases elements located from the index i1 to i2.
Definition: cluster.cpp:1072
Cluster & getCluster(StringView sCluster)
This member function returns a reference to the cluster indicated by the passed cluster identifier.
Definition: cluster.cpp:2077
bool isCluster(StringView sCluster) const
This member function returns true, if the passed cluster identifier can be found in the internal map.
Definition: cluster.cpp:2041
const std::map< std::string, Cluster > & getClusterMap() const
Definition: cluster.hpp:475
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.
Definition: kernel.hpp:221
NumeRe::StringParser & getStringParser()
Definition: kernel.hpp:286
static void getline(std::string &sLine)
This function is an implementation replacing the std::getline() function.
Definition: kernel.cpp:3621
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...
Definition: kernel.cpp:2683
mu::Parser & getParser()
Definition: kernel.hpp:281
MemoryManager & getMemoryManager()
Definition: kernel.hpp:263
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...
Definition: kernel.cpp:2636
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....
Definition: kernel.cpp:3191
static void toggleTableStatus()
Toggles the table writing status, which will reduce the number or events send to the terminal.
Definition: kernel.cpp:3671
Settings & getSettings()
Definition: kernel.hpp:296
void format(std::string **_sMatrix, long long int _nCol, long long int _nLine, const Settings &_option, bool bDontAsk=false, int nHeadLineCount=1)
Definition: output.cpp:403
void setPrefix(std::string _sPrefix)
Definition: output.cpp:897
void setPluginName(std::string _sPluginName)
Definition: output.cpp:204
bool isCompact() const
Definition: output.hpp:79
void reset()
Definition: output.cpp:75
void setCompact(bool _bCompact)
Definition: output.cpp:141
This class manages the setting values of the internal (kernel) settings of this application.
Definition: settings.hpp:663
bool systemPrints() const
Returns, whether system messages shall be printed to the terminal.
Definition: settings.hpp:1140
bool useExternalDocWindow() const
Returns, whether documentations shall be displayed in external windows.
Definition: settings.hpp:1171
bool isDeveloperMode() const
Returns, whether the developer mode is currently enabled.
Definition: settings.hpp:892
std::string getSavePath() const
Returns the current saving path.
Definition: settings.hpp:1029
std::string getExePath() const
Returns the current application root folder path.
Definition: settings.hpp:1010
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.
Definition: error.hpp:32
@ TABLE_DOESNT_EXIST
INSERT HERE.
Definition: error.hpp:211
@ NO_CACHED_DATA
Definition: error.hpp:158
@ CANNOT_READ_FILE
Definition: error.hpp:75
@ FILE_NOT_EXIST
Definition: error.hpp:105
@ INVALID_INDEX
Definition: error.hpp:129
@ NO_STRING_FOR_WRITING
Definition: error.hpp:180
@ NO_FILENAME
Definition: error.hpp:169
@ FILETYPE_MAY_NOT_BE_WRITTEN
Definition: error.hpp:103
static size_t invalid_position
Definition: error.hpp:235
This class abstracts all the index logics, i.e. the logical differences between single indices and in...
Definition: structures.hpp:42
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(...
Definition: structures.hpp:238
int last() const
This member function returns the last index value, which can be reached by the values stored internal...
Definition: structures.hpp:693
int max() const
This function calculates the maximal index value obtained from the values stored internally.
Definition: structures.hpp:558
size_t size() const
This member function returns the size of the indices stored in this class.
Definition: structures.hpp:314
bool isOpenEnd() const
This member function determines, whether the internal index set has an open end.
Definition: structures.hpp:614
void setRange(int nMin, int nMax)
This member function can be used to force the indices stored internally to be in a defined interval....
Definition: structures.hpp:712
std::string to_string() const
This member function converts the vector indexes contents into a human-readable string representation...
Definition: structures.hpp:770
int & back()
This member function returns a reference to the final index value stored internally.
Definition: structures.hpp:653
int min() const
This member function calculates the minimal index value obtained from the values stored internally.
Definition: structures.hpp:576
int & front()
This member function returns a reference to the first index value stored internally.
Definition: structures.hpp:640
Mathematical expressions parser.
Definition: muParser.h:51
Indices getIndices(StringView sCmd, mu::Parser &_parser, MemoryManager &_data, const Settings &_option)
Wrapper for the new getIndices function interface.
Definition: indices.cpp:49
bool isValidIndexSet(const Indices &_idx)
Definition: dataaccess.hpp:81
bool sortData(CommandLineParser &cmdParser)
This function is a wrapper for the corresponding member function of the Datafile object.
Definition: dataops.cpp:933
bool readImage(CommandLineParser &cmdParser)
This function reads image data from an image file and stores it as a cache table.
Definition: dataops.cpp:1234
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.
Definition: dataops.cpp:147
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...
Definition: dataops.cpp:483
bool moveData(CommandLineParser &cmdParser)
This function will move the selected part of a data table to a new location.
Definition: dataops.cpp:655
bool CopyData(CommandLineParser &cmdParser)
This function copies whole chunks of data between tables.
Definition: dataops.cpp:620
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 ...
Definition: dataops.cpp:53
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.
Definition: dataops.cpp:579
bool readFromFile(CommandLineParser &cmdParser)
This function reads the content of a file as strings and copies them to a temporary string vector var...
Definition: dataops.cpp:1145
Language _lang
Definition: kernel.cpp:39
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...
Definition: dataops.cpp:540
static bool sortStrings(CommandLineParser &cmdParser, Indices &_idx)
This static function sorts strings and is called by sortData, if the selected data object equals "str...
Definition: dataops.cpp:844
void clear_cache(MemoryManager &_data, Settings &_option, bool bIgnore)
This function removes all allocated tables and frees the assigned memory.
Definition: dataops.cpp:428
void append_data(CommandLineParser &cmdParser)
This function handles appending data sets to already existing data.
Definition: dataops.cpp:346
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.
Definition: dataops.cpp:757
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.
Definition: dataops.cpp:698
bool writeToFile(CommandLineParser &cmdParser)
This function writes the string contents in the command to a file.
Definition: dataops.cpp:998
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.
Definition: dataops.cpp:281
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...
Definition: dataops.cpp:891
string sErrorToken
bool fileExists(const string &)
This function checks, whether the file with the passed file name exists.
Definition: tools.cpp:2500
DetachedLogger g_logger
Definition: logger.cpp:23
CONSTCD11 std::enable_if<!std::chrono::treat_as_floating_point< T >::value, T >::type trunc(T t) NOEXCEPT
Definition: date.h:1113
CONSTCD11 std::chrono::duration< Rep, Period > abs(std::chrono::duration< Rep, Period > d)
Definition: date.h:1317
bool isinf(const value_type &v)
Definition: muParserDef.h:374
#define max(a, b)
Definition: resampler.cpp:30
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
std::string toUpperCase(const std::string &sLowerCase)
Converts lowercase letters to uppercase ones.
std::string getNextArgument(std::string &sArgList, bool bCut)
Definition: tools.cpp:2294
void replaceAll(std::string &sToModify, const char *sToRep, const char *sNewValue, size_t nStart, size_t nEnd)
This function replaces all occurences of the string sToRep in the string sToModify with the new value...
This structure is central for managing the indices of a table or cluster read or write data access....
VectorIndex col
VectorIndex row
This structure wraps all necessary meta information of a single file.
Definition: file.hpp:41
long long int nCols
Definition: file.hpp:47
std::string sFileName
Definition: file.hpp:43
long long int nRows
Definition: file.hpp:46
Encapsulating structure to gather all table meta data information.
Definition: table.hpp:32
std::string source
Definition: table.hpp:34
std::string comment
Definition: table.hpp:33
long long int intCast(const std::complex< double > &)
Casts the real part of the complex number to an integer and avoids rounding errors.
Definition: tools.cpp:1824
std::string toString(int)
Converts an integer to a string without the Settings bloat.
vector< string > getFileList(const string &sDirectory, const Settings &_option, int nFlags)
This function returns a list of files (including their paths, if nFlags & 1).
Definition: tools.cpp:2853
std::string LineBreak(std::string sOutput, const Settings &_option, bool bAllowDashBreaks, int nFirstIndent, int nIndent)
This function takes a string, splits it into multiple lines if it is too long and returns the result.
Definition: tools.cpp:2205
EndlessVector< StringView > getAllArguments(StringView sArgList)
Splits up the complete argument list and returns them as an EndlessVector.
Definition: tools.cpp:2346
void make_hline(int nLength=-1)
This function prints a horizontal line to the terminal using either minus or equal signs.
Definition: kernel.cpp:3720