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 @ 14962

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

#2638, update python script to accomodate multiply nested zooms

  • Property svn:executable set to *
File size: 4.1 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 = nbghostcells
65    nbghostcells_y = nbghostcells
66    nbghostcells_y_n = nbghostcells_y
67    nbghostcells_y_s = nbghostcells_y
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][1]) - int(grid[cnt-1][0]) == int(Ni0glo_parent) :
73        nbghostcells_x = 0
74
75    Ni0glo = (int(grid[cnt-1][1])-int(grid[cnt-1][0]))*int(grid[cnt-1][4]) + 2*nbghostcells_x
76    Nj0glo = (int(grid[cnt-1][3])-int(grid[cnt-1][2]))*int(grid[cnt-1][5]) + nbghostcells_y_n  + nbghostcells_y_s
77    #print( "Grid "+str(cnt)+" : jpiglo = "+cnt(jpiglo)+ "  jpjglo = "+str(jpjglo) )
78    print(int(grid[cnt-1][0]), int(grid[cnt-1][1]), int(grid[cnt-1][2]),int(grid[cnt-1][3]))
79    print(nbghostcells_x, nbghostcells_y_s, nbghostcells_y_n)
80    print('Grid {:1d} : Ni0glo = {:3d} , Nj0glo = {:3d}'.format(cnt, Ni0glo, Nj0glo))
81
82    f2 = open(str(cnt)+'_'+namfile,'w')
83    with open(namfile) as fp:
84        line = fp.readline()
85        cnt1 = 1
86        while line :
87           line = fp.readline()
88           if line.strip().startswith('jperio'):
89               if int(grid[cnt-1][1]) - int(grid[cnt-1][0]) == int(Ni0glo_parent):
90                   line = "   jperio = 1\n"
91               else:
92                   line = "   jperio = 0\n"
93           if line.strip().startswith('nn_bathy'):
94                  line = "   nn_bathy = 2\n"
95           if line.strip().startswith('nn_interp'):
96               line = "   nn_interp = 1\n"
97           if line.strip().startswith('cn_topo'):
98               line = "   cn_topo = '"+topofile+"'\n"
99           if line.strip().startswith('cn_bath'):
100               line = "   cn_bath = 'elevation'\n"
101           if line.strip().startswith('cn_lon'):
102               line = "   cn_lon = 'lon'\n"
103           if line.strip().startswith('cn_lat'):
104               line = "   cn_lat = 'lat'\n"
105           if line.strip().startswith('rn_scale'):
106               line = "   rn_scale = -1\n"
107           if line.strip().startswith('Ni0glo'):
108               line = "   Ni0glo = "+str(Ni0glo)+"\n"
109           if line.strip().startswith('Nj0glo'):
110               line = "   Nj0glo = "+str(Nj0glo)+"\n"
111           if line.strip().startswith('jpidta'):
112               line = "   jpidta = "+str(Ni0glo)+"\n"
113           if line.strip().startswith('jpjdta'):
114               line = "   jpjdta = "+str(Nj0glo)+"\n"
115           if line.strip().startswith('cp_cfg'):
116               line = "   cp_cfg = 'dumb'\n"     
117           if line.strip().startswith('ln_read_cfg'):
118               line = "   ln_read_cfg = .false.\n"             
119           f2.write(line)
120           cnt1 += 1
121    f2.close()     
122    cnt +=1         
Note: See TracBrowser for help on using the repository browser.