forked from RDCEP/psims
-
Notifications
You must be signed in to change notification settings - Fork 0
/
psims-all.swift
74 lines (63 loc) · 2.47 KB
/
psims-all.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
type file;
app (external e) pysims (string campaign, string param, string tlatidx, string tlonidx, int slatidx, int slonidx, int split, string rundir) {
pysims "--campaign" campaign "--param" param "--tlatidx" tlatidx "--tlonidx" tlonidx "--slatidx" slatidx "--slonidx" slonidx "--split" split "--rundir" rundir;
}
app (file output) findLats (string workDir, external[string][][] exts) {
findLats workDir stdout=@output;
}
app (external e) combinelon (string params, string inputdir, string cwd, int split, external[string][][] exts) {
combinelon "--params" params "--inputdir" inputdir "--outputdir" cwd "--split" split;
}
app (external e) combinelat (string params, string cwd, int split, external[string] exts) {
combinelat "--params" params "--inputdir" cwd "--outputdir" cwd "--split" split;
}
app (external e) aggregate (string rundir, string param, string var, int chunk, external ext) {
aggregate "-i" rundir "-p" param "-v" var "-c" chunk;
}
string campaign = arg("campaign");
string param = arg("param");
string rundir = arg("cwd");
int split = toInt(arg("split"));
string tileList[] = readData("tileList.txt");
string vars[] = strsplit(strcat(arg("variables"), ",", arg("cal_vars")), ",");
int numchunks = toInt(arg("num_chunks"));
external parts_e[string][][];
external combinelon_e[string];
external combinelat_e;
external aggregate_e[string][int];
# Parts
tracef("\nCreating part files . . .\n");
foreach tile in tileList {
string indices[] = strsplit(tile, "/");
string tlatidx = indices[0];
string tlonidx = indices[1];
foreach slatidx in [1:split] {
foreach slonidx in [1:split] {
external e;
e = pysims(campaign, param, tlatidx, tlonidx, slatidx, slonidx, split, rundir);
parts_e[tile][slatidx][slonidx] = e;
}
}
}
# Combinelon
tracef("\nRunning combine lons . . .%k\n", parts_e);
file find_lats_txt <"findLats.txt">;
find_lats_txt = findLats(rundir, parts_e);
string lats[] = readData(find_lats_txt);
foreach lat in lats {
external e;
e = combinelon(param, lat, rundir, split, parts_e);
combinelon_e[lat] = e;
}
# Combinelat
tracef("\nRunning combine lats . . .%k\n", combinelon_e);
combinelat_e = combinelat(param, rundir, split, combinelon_e);
# Aggregate
tracef("\nRunning aggregate . . .%k\n", combinelat_e);
foreach var in vars {
foreach chunk in [1 : numchunks] {
external e;
e = aggregate(rundir, param, var, chunk, combinelat_e);
aggregate_e[var][chunk] = e;
}
}