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

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

#2368, Add AGRIF zoom coincident with North and South boundaries in python script

  • Property svn:executable set to *
File size: 3.9 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 
23nbghostcells_x = nbghostcells
24nbghostcells_y = nbghostcells
25nbghostcells_y_n = nbghostcells_y
26nbghostcells_y_s = nbghostcells_y
27
28
29with open(Agrilefile) as fp:
30   line = fp.readline()
31   cnt = 1
32   while line:
33#       print("Line {}: {}".format(cnt, line.strip()))
34     #  print (line.strip(' '))
35       if len(line.split()) >=4 :
36            #print(line.split())
37            grid.append(line.split()[0:6])
38           #for word in line.split() :
39               #print(word)
40       line = fp.readline()
41       cnt += 1
42
43print("Found", len(grid), "grids", ":")
44
45f1="namelist_ref"
46
47
48
49cnt = 1
50for g in range(len(grid)) :
51   
52    f2 = open(str(cnt)+'_'+f1,'w')
53    with open(f1) as fp:
54        line = fp.readline()
55        cnt1 = 1
56        while line :
57           line = fp.readline()
58           if line.strip().startswith('Ni0glo'):
59               Ni0glo_parent=line.strip().split()[2]               
60           f2.write(line)
61           if line.strip().startswith('Nj0glo'):
62               Nj0glo_parent=line.strip().split()[2]               
63           f2.write(line)
64           cnt1 += 1
65    f2.close()
66
67    if int(grid[cnt-1][2]) == 1:
68        nbghostcells_y_s = 0
69    if int(grid[cnt-1][3]) == int(Nj0glo_parent) + 1:
70        nbghostcells_y_n = 0
71    if int(grid[cnt-1][1]) + int(grid[cnt-1][0]) == int(Ni0glo_parent) + 2 :
72        nbghostcells_x = 0
73    Ni0glo = (int(grid[cnt-1][1])-int(grid[cnt-1][0]))*int(grid[cnt-1][4]) + 2*nbghostcells_x
74    Nj0glo = (int(grid[cnt-1][3])-int(grid[cnt-1][2]))*int(grid[cnt-1][5]) + nbghostcells_y_n  + nbghostcells_y_s
75    #print( "Grid "+str(cnt)+" : jpiglo = "+cnt(jpiglo)+ "  jpjglo = "+str(jpjglo) )
76    print('Grid {:1d} : Ni0glo = {:3d} , Nj0glo = {:3d}'.format(cnt, Ni0glo, Nj0glo))
77
78    f2 = open(str(cnt)+'_'+namfile,'w')
79    with open(namfile) as fp:
80        line = fp.readline()
81        cnt1 = 1
82        while line :
83           line = fp.readline()
84           if line.strip().startswith('jperio'):
85               if int(grid[cnt-1][1]) + int(grid[cnt-1][0]) == int(Ni0glo_parent) + 2:
86                   line = "   jperio = 1\n"
87               else:
88                   line = "   jperio = 0\n"
89           if line.strip().startswith('nn_bathy'):
90                  line = "   nn_bathy = 2\n"
91           if line.strip().startswith('nn_interp'):
92               line = "   nn_interp = 1\n"
93           if line.strip().startswith('cn_topo'):
94               line = "   cn_topo = '"+topofile+"'\n"
95           if line.strip().startswith('cn_bath'):
96               line = "   cn_bath = 'elevation'\n"
97           if line.strip().startswith('cn_lon'):
98               line = "   cn_lon = 'lon'\n"
99           if line.strip().startswith('cn_lat'):
100               line = "   cn_lat = 'lat'\n"
101           if line.strip().startswith('rn_scale'):
102               line = "   rn_scale = -1\n"
103           if line.strip().startswith('Ni0glo'):
104               line = "   Ni0glo = "+str(Ni0glo)+"\n"
105           if line.strip().startswith('Nj0glo'):
106               line = "   Nj0glo = "+str(Nj0glo)+"\n"
107           if line.strip().startswith('jpidta'):
108               line = "   jpidta = "+str(Ni0glo)+"\n"
109           if line.strip().startswith('jpjdta'):
110               line = "   jpjdta = "+str(Nj0glo)+"\n"
111           if line.strip().startswith('cp_cfg'):
112               line = "   cp_cfg = 'dumb'\n"     
113           if line.strip().startswith('ln_read_cfg'):
114               line = "   ln_read_cfg = .false.\n"             
115           f2.write(line)
116           cnt1 += 1
117    f2.close()     
118    cnt +=1         
Note: See TracBrowser for help on using the repository browser.