[Swift-user] many-to-one mapping

Mihael Hategan hategan at mcs.anl.gov
Fri Dec 7 15:21:33 CST 2012


On Fri, 2012-12-07 at 15:08 -0600, Neil Best wrote:
> On Fri, Dec 7, 2012 at 2:35 PM, Mihael Hategan <hategan at mcs.anl.gov> wrote:
> >
> > foreach {
> >    string m = @strcat(...);
> >    file[] foo <...;..., match = m,...>;
> > }
> >
> 
> Shouldn't m also be an array?

It's the pattern, so I'm guessing no.

> 
> Also, I don't recognize "file[] foo" in your notation.

Oh, I see. I'll add that you cannot declare variables inside invocation
argument lists. And I'm becoming a bit unsure about my previous
statement. You might be able to invoke stuff in mapper params. But let's
try what's more likely to work:

foreach year in [1979:2011] {
  string m = @strcat( "^data/nc/",year, "../narr-a_221_", year,
"...._..00_000.single.nc$");
  file[] foo <structured_regexp_mapper; source= nc1, match= m>;
  ncList[year] = @filenames(foo);
  ...
}

or you could do ncList[year] = foo; and then apply @filenames in the app
call.

Mihael

> 
> I tried this:
> 
> foreach year in [1979:2011] {
>   m[ year] = @strcat( "^data/nc/", year, "../narr-a_221_", year,
> "...._..00_000.single.nc$");
>   ncList[ year] = @filenames(
>     file foo[]<structured_regexp_mapper;
>       source= nc1,
>       match= m[ year];>);
>   annual[ year]= cdo( "-O mergetime", ncList[ year]);
> }
> 
> It still doesn't like that the mapper is an argument to @filenames(), I guess.
> 
> Could not compile SwiftScript source: line 90:10: expecting ')', found 'foo'
> 
> I hope it is clear what I am trying to do.  Each member of ncList[]
> would be a long string enumerating the input files for the cdo command
> and must be different for each year.





More information about the Swift-user mailing list