[Swift-user] many-to-one mapping

Mihael Hategan hategan at mcs.anl.gov
Fri Dec 7 14:35:00 CST 2012


Yes, but you can't invoke stuff inside mapping specs. So you need
something like:

foreach {
   string m = @strcat(...);
   file[] foo <...;..., match = m,...>;
}

Mihael

On Fri, 2012-12-07 at 10:51 -0600, Neil Best wrote:
> Is it possible to declare a mapping within a foreach loop so that
> different realizations of that mapping are driven by the loop
> parameter?
> 
> I tried this:
> 
> foreach year in [1979:2011] {
>   ncList[ year] = @filenames(
>     file foo[]<structured_regexp_mapper;
>       source= nc1,
>       match= @strcat( "^data/nc/", year, "../narr-a_221_", year,
> "...._..00_000.single.nc$");>)
>   annual[ year]= cdo( "-O mergetime", ncList[ year]);
>   tmin[ year]= cdo( "-O daymin -selname,TMP", @annual[ year]);
>   tmax[ year]= cdo( "-O daymax -selname,TMP", @annual[ year]);
>   precip[ year]= cdo( "-O daysum -selname,APCP", @annual[ year]);
>   solar[ year]= cdo( "-O daymean -selname,DSWRF", @annual[ year]);
> }
> 
> The idea is that the annual[] files are the product of merging ~3000
> 3-hour reports.  The set of reports for each year is a subset of all
> of the 3-hour reports across all of the years.
> 
> I have a feeling that my syntax is not legal where I am trying to work
> in terms of first class objects and functional programming, but I am
> not sure to what extent Swift can accept these constructs.  Is it
> clear what I am trying to do?  Is there an idiom for this?  I don't
> see any exmaples where a mapper is parameterized by a variable within
> a loop.
> 
> Complete listing is here:
> https://github.com/RDCEP/narr2wth/blob/master/narr.swift
> _______________________________________________
> Swift-user mailing list
> Swift-user at ci.uchicago.edu
> https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-user





More information about the Swift-user mailing list