Permalink
Browse files

added method for saving data to an external file

  • Loading branch information...
scribeGriff committed Aug 10, 2012
1 parent 9ab3ba5 commit 9d1332c6397454b98825351a09e1e297e0fdd204
Showing with 50 additions and 3 deletions.
  1. +14 −2 README.md
  2. +16 −0 external/data/outtest.txt
  3. +0 −1 lib/ConvoLab.dart
  4. +20 −0 lib/utilities/ConvoLabResults.dart
View
@@ -37,6 +37,10 @@ The variable y is actually an object with several return values. In addition, t
-2.00
-2.00 - 2.00j
+You can save this data to an external file using the export(String filename) method of the base results class as follows:
+
+ y.export('pathName/filename.txt');
+
To perform an inverse fft to recover the original sequence, one can pass the data field of y to ifft():
var x = ifft(y.data);
@@ -81,7 +85,11 @@ To display the transformed data (usually an array of complex numbers) as String,
y.show();
-as in the example above.
+as in the example above. You can also save the calculated data (ie, y.data) in tab delimited format to an external file as follows:
+
+ y.export('myPath/myExternalFile.txt');
+
+This format allows you to import your data to Matlab, Scilab or other similar tools for plotting, post processing, etc.
**IFFT:** Performs an inverse FFT and is similar in performance and requirements as the FFT.
@@ -105,7 +113,11 @@ To just display the output data as String you can also simply write:
x.show();
-
+You can also save the calculated data (ie, x.data) in tab delimited format to an external file as follows:
+
+ x.export('myPath/myExternalFile.txt');
+
+This format allows you to import your data to Matlab, Scilab or other similar tools for plotting, post processing, etc.
**RandomizedSelection:** Performs a linear time selection for a certain order statistic from a list of unsorted data. A thorough description of the algorithm can be found at [the blog entry at scribegriff.com](http://http://www.scribegriff.com/studios/index.php?post/2012/05/31/A-Linear-Time-Randomized-Selection-Algorithm-in-Dart "Linear Time Randomized Selection Algorithm"). A simple example is as follows:
View
@@ -0,0 +1,16 @@
+0.0 0.0
+0.0 0.0
+-4.0 9.66
+0.0 0.0
+0.0 0.0
+0.0 0.0
+-4.0 1.66
+0.0 0.0
+0.0 0.0
+0.0 0.0
+-4.0 -1.66
+0.0 0.0
+0.0 0.0
+0.0 0.0
+-4.0 -9.66
+0.0 0.0
View
@@ -32,4 +32,3 @@
#source('math/Complex.dart');
#source('math/hyperbolic.dart');
#source('math/logarithm.dart');
-
@@ -8,4 +8,24 @@ class ConvoLabResults {
final int value;
ConvoLabResults(this.data, this.value);
+
+ // Method: export writes data list to a file. If the data is complex,
+ // the external file is tab delimited. Data can then be read into
+ // Matlab, Scilab, etc. This is temporary until we develop the html5
+ // data visualizer (ie, ConvoWeb).
+ void export(String filename) {
+ File fileHandle = new File(filename);
+ RandomAccessFile dataFile = fileHandle.openSync(FileMode.WRITE);
+ if (this.data.every(f(element) => element is Complex)) {
+ for (var i = 0; i < this.data.length; i++) {
+ this.data[i] = this.data[i].cround2;
+ dataFile.writeStringSync("${this.data[i].real}\t${this.data[i].imag}\n");
+ }
+ } else {
+ for (var i = 0; i < this.data.length; i++) {
+ dataFile.writeStringSync("${this.data[i]}\n");
+ }
+ }
+ dataFile.closeSync();
+ }
}

0 comments on commit 9d1332c

Please sign in to comment.