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

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

#2638, closed domains AGRIF new convention + various add ons

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