New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
make_namelist.py in utils/tools/DOMAINcfg – NEMO

source: utils/tools/DOMAINcfg/make_namelist.py @ 15331

Last change on this file since 15331 was 15279, checked in by jchanut, 3 years ago

#2222 and #2638: Enable creating agrif meshes with different vertical grids (geopotential only as a start)

  • Property svn:executable set to *
File size: 4.5 KB
Line 
1#!/usr/bin/env python
2# coding: utf-8
3import argparse
4import sys
5
6if len(sys.argv) == 1 :
7   namfile='namelist_cfg'
8   topofile='GEBCO_2020.nc' 
9elif len(sys.argv) == 2 :
10   namfile=sys.argv[1]
11   topofile='GEBCO_2020.nc' 
12elif len(sys.argv) == 3 :
13   namfile=sys.argv[1]
14   topofile=sys.argv[2] 
15else:
16   print ("Usage : make_namelist.py namelist_cfg topofile")
17   sys.exit (1)
18
19
20Agrilefile="AGRIF_FixedGrids.in"
21grid=[]
22nbghostcells  = 4 
23
24with open(Agrilefile) as fp:
25   line = fp.readline()
26   cnt = 1
27   while line:
28#       print("Line {}: {}".format(cnt, line.strip()))
29     #  print (line.strip(' '))
30       if len(line.split()) >=4 :
31            #print(line.split())
32            grid.append(line.split()[0:6])
33           #for word in line.split() :
34               #print(word)
35       line = fp.readline()
36       cnt += 1
37
38print("Found", len(grid), "grids", ":")
39
40f1="namelist_cfg"
41
42
43
44cnt = 1
45for g in range(len(grid)) :
46   
47    f2 = open(str(cnt)+'_'+f1,'w')
48    with open(f1) as fp:
49        line = fp.readline()
50        cnt1 = 1
51        while line :
52           line = fp.readline()
53           if line.strip().startswith('Ni0glo'):
54               Ni0glo_parent=line.strip().split()[2]               
55           f2.write(line)
56           if line.strip().startswith('Nj0glo'):
57               Nj0glo_parent=line.strip().split()[2]               
58           f2.write(line)
59           cnt1 += 1
60    f2.close()
61
62    print(int(Ni0glo_parent), int(Nj0glo_parent))
63
64    nbghostcells_x_e = nbghostcells
65    nbghostcells_x_w = nbghostcells
66    nbghostcells_y_n = nbghostcells
67    nbghostcells_y_s = nbghostcells
68    if (int(grid[cnt-1][2]) == 1 ):
69        nbghostcells_y_s = 1 
70    if int(grid[cnt-1][3]) == int(Nj0glo_parent)-1 :
71        nbghostcells_y_n = 1 
72    if (int(grid[cnt-1][0]) == 1 ):
73        nbghostcells_x_w = 1 
74    if int(grid[cnt-1][1]) == int(Ni0glo_parent)-1 :
75        nbghostcells_x_e = 1 
76    if int(grid[cnt-1][3]) == int(Nj0glo_parent) :
77        nbghostcells_y_n = 0 
78    if int(grid[cnt-1][1]) - int(grid[cnt-1][0]) == int(Ni0glo_parent) :
79        nbghostcells_x_w = 0
80        nbghostcells_x_e = 0
81
82    Ni0glo = (int(grid[cnt-1][1])-int(grid[cnt-1][0]))*int(grid[cnt-1][4]) + nbghostcells_x_w  + nbghostcells_x_e
83    Nj0glo = (int(grid[cnt-1][3])-int(grid[cnt-1][2]))*int(grid[cnt-1][5]) + nbghostcells_y_n  + nbghostcells_y_s
84    #print( "Grid "+str(cnt)+" : jpiglo = "+cnt(jpiglo)+ "  jpjglo = "+str(jpjglo) )
85    print(int(grid[cnt-1][0]), int(grid[cnt-1][1]), int(grid[cnt-1][2]),int(grid[cnt-1][3]))
86    print(nbghostcells_x_w, nbghostcells_x_e,  nbghostcells_y_s, nbghostcells_y_n)
87    print('Grid {:1d} : Ni0glo = {:3d} , Nj0glo = {:3d}'.format(cnt, Ni0glo, Nj0glo))
88
89    f2 = open(str(cnt)+'_'+namfile,'w')
90    with open(namfile) as fp:
91        line = fp.readline()
92        cnt1 = 1
93        while line :
94           line = fp.readline()
95           if line.strip().startswith('jperio'):
96               if int(grid[cnt-1][1]) - int(grid[cnt-1][0]) == int(Ni0glo_parent):
97                   line = "   jperio = 1\n"
98               else:
99                   line = "   jperio = 0\n"
100               if nbghostcells_y_n == 0:
101                   line = "   jperio = 4\n"
102           if line.strip().startswith('nn_bathy'):
103                  line = "   nn_bathy = 2\n"
104           if line.strip().startswith('nn_interp'):
105               line = "   nn_interp = 1\n"
106           if line.strip().startswith('cn_topo'):
107               line = "   cn_topo = '"+topofile+"'\n"
108           if line.strip().startswith('cn_bath'):
109               line = "   cn_bath = 'elevation'\n"
110           if line.strip().startswith('cn_lon'):
111               line = "   cn_lon = 'lon'\n"
112           if line.strip().startswith('cn_lat'):
113               line = "   cn_lat = 'lat'\n"
114           if line.strip().startswith('rn_scale'):
115               line = "   rn_scale = -1\n"
116           if line.strip().startswith('Ni0glo'):
117               line = "   Ni0glo = "+str(Ni0glo)+"\n"
118           if line.strip().startswith('Nj0glo'):
119               line = "   Nj0glo = "+str(Nj0glo)+"\n"
120           if line.strip().startswith('jpidta'):
121               line = "   jpidta = "+str(Ni0glo)+"\n"
122           if line.strip().startswith('jpjdta'):
123               line = "   jpjdta = "+str(Nj0glo)+"\n"
124           if line.strip().startswith('cp_cfg'):
125               line = "   cp_cfg = 'dumb'\n"     
126           if line.strip().startswith('ln_read_cfg'):
127               line = "   ln_read_cfg = .false.\n"             
128           f2.write(line)
129           cnt1 += 1
130    f2.close()     
131    cnt +=1         
Note: See TracBrowser for help on using the repository browser.