[Swift-devel] readData

Michael Wilde wilde at mcs.anl.gov
Wed Oct 10 09:00:22 CDT 2007


Mihael, all - readdata() works great, and I think gives Andrew exactly 
what he asked for.

I updated the example parameter-sweep loop to use readdata to grab the 
multi-column input file.

One note: as far as I can tell, you use the conventions the data columns 
must be exactly 16 characters wide, space separated. Is that correct? (I 
assume we'll generalize this time permits).

Here's the new example, Andrew.

- Mike

type file;

// Simulate encapsulating an app's parameters as a struct

type params {
   int x;
   int y;
   float r;
   boolean b;
   string infilename;
   string outfilename;
};

// Simulate an app

myapp(params p, file infile, file outfile )
{
     app {
         db "pecho:" p.x p.y p.r p.b p.infilename p.outfilename  @infile 
@outfile ;
     }
}

// Loop over the parameter array, calling app in parallel

doall(params plist[])
{
   foreach pval,j in plist {

     // convert filename string to mapped file reference
     file infile <single_file_mapper;file=pval.infilename>;
     file outfile <single_file_mapper;file=pval.outfilename>;

     // Call the application
     myapp(pval,infile, outfile);
   }
}

// Main

params plist[];
plist = readdata("parameters");
doall(plist);

// Data File "parameters" follows.  Data files listed in it must exist.
// each line is greater than 80 bytes and is only wrapped here by email
// (actual files attached)

x               y               r               b 
infilename      outfilename
1               2               1.234           1 
inf001.data     outf001.data
3               4               5.678           0 
inf002.data     outf002.data





On 10/10/07 5:23 AM, Ben Clifford wrote:
> Mihael added the below language construct to the language the other day.
> 
> This might be useful where the csv_mapper was being used before to read in 
> non-file data.
> 
> Its in the SVN.
> 
> 
> Mihael Hategan wrote:
> 
> There's a new function: readData. It's not an @function, so don't use it
> that way because it won't work (it needs to know what variable it
> assigns to, so that it knows how to interpret the contents of the
> file). 
> 
> It can read primitive things, arrays of primitive things, structs and
> arrays of structs. 
> 
> It can either take a file or a string as a parameter, although I
> recommend the former since it can deal with data dependencies.
> 
> For example usage, see tests/language-behaviour/readData.swift.
> 
> Here's a short preview:
> type circle {
>         int x;
>         int y;
>         float r;
>         string name;
> }
> 
> circle ca[];
> 
> ca = readData("readData.circleArray.in");
> 
> readData.circleArray.in:
> x               y               r               name
> 1               1               5               CircleOne
> 2               2               7               CircleTwo
> 
> It doesn't deal with spaces in strings in the CSV format for now, but
> it's a start.
> 
> Mihael
> 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: t5g.swift
URL: <http://lists.mcs.anl.gov/pipermail/swift-devel/attachments/20071010/2f0367c7/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: parameters
URL: <http://lists.mcs.anl.gov/pipermail/swift-devel/attachments/20071010/2f0367c7/attachment-0001.ksh>


More information about the Swift-devel mailing list