wustl_file_pattern.cwl

 1#!/usr/bin/env cwl-runner
 2### Expression evaluator to format a file name for pollution files downloaded from WashU
 3#  Copyright (c) 2021-2023. Harvard University
 4#
 5#  Developed by Research Software Engineering,
 6#  Faculty of Arts and Sciences, Research Computing (FAS RC)
 7#  Author: Michael A Bouzinier
 8#
 9#  Licensed under the Apache License, Version 2.0 (the "License");
10#  you may not use this file except in compliance with the License.
11#  You may obtain a copy of the License at
12#
13#         http://www.apache.org/licenses/LICENSE-2.0
14#
15#  Unless required by applicable law or agreed to in writing, software
16#  distributed under the License is distributed on an "AS IS" BASIS,
17#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18#  See the License for the specific language governing permissions and
19#  limitations under the License.
20#
21
22cwlVersion: v1.2
23class: ExpressionTool
24
25requirements:
26  StepInputExpressionRequirement: {}
27  InlineJavascriptRequirement: {}
28
29doc: |
30  Given input directory, variable (band), year and month,
31  evaluates the expected file name for the input data
32
33inputs:
34  downloads:
35    type: Directory
36  year:
37    type: int
38  variables:
39    type: string[]
40
41expression: |
42  ${
43    var files = [];
44    var i;
45    for (i in inputs.variables) {
46      var v = inputs.variables[i].toUpperCase();
47      var y = String(inputs.year);
48      var f;
49      if (v == 'PM25') {
50        f = "V4NA03_" + v + "_NA_" + y + "01_" + y + "12-RH35.nc";
51      } else {
52        if (y == '2017') {
53          f = "GWRwSPEC.HEI_" + v + "p_NA_" + y + "01_" + y + "12-wrtSPECtotal.nc"
54        } else {
55          f = "GWRwSPEC_" + v + "p_NA_" + y + "01_" + y + "12-wrtSPECtotal.nc"
56        };
57      };
58      f = inputs.downloads.location + '/' + f;
59      files.push({
60        "class": "File",
61        "location": f
62      });
63    };
64    return {
65      netcdf_files: files
66    }
67  }
68
69outputs:
70  netcdf_files:
71    type: File[]