source: CPL/oasis3-mct/branches/OASIS3-MCT_5.0_branch/pyoasis/examples/11-test-interpolation/python/utils.py @ 6331

Last change on this file since 6331 was 6331, checked in by aclsce, 17 months ago

Moved oasis-mct_5.0 in oasis3-mct/branches directory.

File size: 3.5 KB
Line 
1def grid_longname(grid):
2    grid_ln = {"torc": "ORCA 2 deg",
3               "nogt": "ORCA 1 deg",
4               "nogh": "ORCA 0.25 deg",
5               "to25": "ORCA 0.25 deg",
6               "bggd": "reg. lon/lat 144x143",
7               "ssea": "red. Gaussian T127",
8               "sse7": "red. Gaussian T127 (7 corners)",
9               "t359": "red. Gaussian T359",
10               "icos": "icosahedral Dynamico",
11               "icoh": "HR icosahedral Dynamico"}
12    return grid_ln[grid]
13
14
15def grid_shape(grid):
16    grid_sz = {"torc": [182, 149],
17               "nogt": [362, 294],
18               "nogh": [1442, 1050],
19               "to25": [1442, 1050],
20               "bggd": [144, 143],
21               "ssea": [24572, 1],
22               "sse7": [24572, 1],
23               "t359": [181724, 1],
24               "icos": [15212, 1],
25               "icoh": [2016012, 1]}
26
27    return grid_sz[grid][0], grid_sz[grid][1]
28
29
30def grid_size(grid):
31    nx, ny = grid_shape(grid)
32    return nx * ny
33
34
35def grid_perio(grid):
36    grid_pe = {"torc": ["P", 2],
37               "nogt": ["P", 2],
38               "nogh": ["P", 2],
39               "to25": ["P", 2],
40               "bggd": ["P", 0],
41               "ssea": ["P", 0],
42               "sse7": ["P", 0],
43               "t359": ["P", 0],
44               "icos": ["P", 0],
45               "icoh": ["P", 0]}
46
47    return grid_pe[grid]
48
49
50def grid_struct(grid):
51    grid_st = {"torc": "LR",
52               "nogt": "LR",
53               "nogh": "LR",
54               "to25": "LR",
55               "bggd": "LR",
56               "ssea": "D",
57               "sse7": "D",
58               "t359": "D",
59               "icos": "U",
60               "icoh": "U"}
61
62    return grid_st[grid]
63
64
65valid_grids = ('torc', 'nogt', 'bggd', 'sse7', 'icos')
66ocean_grids = ('torc', 'nogt')
67
68
69def grid_is_valid(grid):
70    return grid in valid_grids
71
72
73def grid_is_ocean(grid):
74    return grid in ocean_grids
75
76
77def grid_is_hr(grid):
78    return grid in ('icoh', 'to25', 'nogh')
79
80
81def write_namcouple(sgrid, dgrid, has_graphics):
82    namcouple = open("namcouple", "w")
83    print("############################################", file=namcouple)
84    print("$NFIELDS", file=namcouple)
85    print("1", file=namcouple)
86    print("$END", file=namcouple)
87    print("############################################", file=namcouple)
88    print("$RUNTIME", file=namcouple)
89    print("21600", file=namcouple)
90    print("$END", file=namcouple)
91    print("############################################", file=namcouple)
92    print("$NLOGPRT", file=namcouple)
93    print("0 0", file=namcouple)
94    print("$END", file=namcouple)
95    print("############################################", file=namcouple)
96    print("$STRINGS", file=namcouple)
97    if has_graphics:
98        print("FSENDANA FRECVANA 1 7200 1 rst.nc EXPORTED", file=namcouple)
99    else:
100        print("FSENDANA FRECVANA 1 7200 1 rst.nc EXPOUT", file=namcouple)
101    print("{} {} {} {} {} {}".format(grid_shape(sgrid)[0], grid_shape(sgrid)[1],
102                                     grid_shape(dgrid)[0], grid_shape(dgrid)[1],
103                                     sgrid, dgrid), file=namcouple)
104    print("{} {} {} {}".format(grid_perio(sgrid)[0], grid_perio(sgrid)[1],
105                               grid_perio(dgrid)[0], grid_perio(dgrid)[1]),
106                               file=namcouple)
107    print("SCRIPR", file=namcouple)
108    print("CONSERV {} SCALAR LATLON 1 FRACAREA FIRST".format(grid_struct(sgrid)),
109                                                             file=namcouple)
110    print("$END", file=namcouple)
111    namcouple.close()
Note: See TracBrowser for help on using the repository browser.