       Re: Q: (how?) notebooks with I/O loop

• To: mathgroup at smc.vnet.net
• Subject: [mg40270] Re: Q: (how?) notebooks with I/O loop
• From: sodastereo at eudoramail.com (Julius Carver)
• Date: Fri, 28 Mar 2003 04:33:04 -0500 (EST)
• References: <b5rme7\$eum\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Jason Miller <millerj at truman.edu> wrote in message news:<b5rme7\$eum\$1 at smc.vnet.net>...
> Dear Mathematica Gurus.
>
> I am working with a student (undergraduate math major) who is using
> Wavelet Explorer to process numerous datasets using a multiresolution
> analysis with various parameter settings.  We would like to know how
> we might create a notebook that would
> 	(1) read in a datafile from a list of files in a local
> directory (or in a hardcoded array),

Ok Jason. First of all you need to create a list of the files in your
local directory. If you work with Linux/Unix you can do that writing
"ls >> inputfiles.txt" in the shell. If you work with Windows, you can
use Cygwin, A Unix enviroment under Windows.

Now well, to avoid writing the complete route of the files you have to
use

In:=
SetDirectory["D:\\local directory"]

Out=
"D:\\local directory"

Then you have to transform the list into a Mathematica list

In:=

Out=
{"a1.txt", "a2.txt", "a3.txt", "inputfiles.txt"}

In every ai.txt I wrote arrays of numbers of order 3 x 3. In order to
read and use them as matrices I use

In:=
data = ReadList[#, Number, RecordLists -> True] & /@ Drop[inputfiles,
-1]

Out=
{{{1, 3, 5}, {4, 6, 8}, {5, 7, 9}}, {{2, 3, 9}, {1, 4, 2}, {5, 8, 4}},
{{7, 3, 6}, {9, 4, 1}, {5, 0, 3}}}

> 	(2) run a multiresolution analysis on the file (this analysis
> 	(3) save the results (e.g., in the form of a mathematica notebook),

Suppose that you want to calculate the determinants of data and save
the results in  a notebook with the same name of input file. First you
make the calculations

In:=
results = Det[#] & /@ data

Out=
{0, -90, -102}

After that you have to make a list of outputfiles

In:=
outputfiles = Drop[StringReplace[#, "txt" -> "nb"] & /@ inputfiles,
-1]

Out=
{"a1.nb", "a2.nb", "a3.nb"}

And finally you have to put the results in the outputfiles

In:=
Table[Put[results[[i]], outputfiles[[i]]], {i, Length[results]}]

Out=
{Null, Null, Null}

> 	(4) do the same in turn for each of the datasets in a local
> directory, as described in (1).
> Having a way to create such a 'loop' would save us much time, but
> we're don't know how to direct Mathematica to save the results of
> each analysis.

The function that makes all this for you is

In:=
data =
ReadList[#, Number, RecordLists -> True] & /@ Drop[inputfiles,
-1];
outputfiles = Drop[StringReplace[#, "txt" -> "nb"] & /@
inputfiles, -1];
results = Det[#] & /@ data;
Table[Put[results[[i]], outputfiles[[i]]], {i, Length[results]}]]

>
> Can anybody tell us how we might do this, or if it's a reasonable thing to do?
>