[Swift-user] many-to-one mapping
Neil Best
nbest at ci.uchicago.edu
Fri Dec 7 11:21:35 CST 2012
On Fri, Dec 7, 2012 at 10:51 AM, Neil Best <nbest at ci.uchicago.edu> 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
I meant to mention that Swift says the following when I try to run the above:
Could not compile SwiftScript source: line 88:10: expecting ')', found 'foo'
More information about the Swift-user
mailing list