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

Last change on this file since 14684 was 14674, checked in by ldebreu, 3 years ago

AGFdomcfg: corrections for east-west cyclic grids, #2368

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