Skip to content

Commit 7c6fae2

Browse files
authored
Merge pull request #10 from CMCC-Foundation/dims_logic_fix
Further revision of dimensions identification logic
2 parents 817f3f4 + 08cfbe1 commit 7c6fae2

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="py_nemo_rebuild",
8-
version="0.0.1",
8+
version="0.8.0",
99
author="Piergiuseppe Fogli",
1010
author_email="[email protected]",
1111
description="Rebuild NEMO/XIOS multiple output/restart files in a single file.",

src/py_nemo_rebuild/nemo_rebuild.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env python
22

3-
from __future__ import print_function
4-
53
import sys
64
import os
75
import re
@@ -33,20 +31,30 @@
3331

3432
# SemVer version
3533
_major_version = 0
36-
_minor_version = 6
34+
_minor_version = 8
3735
_patch = 0
3836

3937
#_release = 'beta'
4038
_release = ''
4139

42-
_date = '24-01-2025'
40+
_date = '04-06-2025'
4341

4442
_version = '{:d}.{:d}'.format(_major_version, _minor_version)
4543
if (_patch>0):
4644
_version += '.{:d}'.format(_patch)
4745
if (len(_release)>0):
4846
_version += '-'+_release
4947

48+
# Figure out if name is a global horizontal dimension name
49+
def isgdim(name):
50+
if name in ('x', 'y', 'i', 'j', 'nav_lon', 'nav_lat'):
51+
return True
52+
elif ('lat' in name or 'lon' in name):
53+
return True
54+
else:
55+
return False
56+
#
57+
5058
def nemo_rebuild(in_file=None,
5159
out_file=None,
5260
numdom=0,
@@ -210,9 +218,6 @@ def nemo_rebuild(in_file=None,
210218
ncfmt+='_CLASSIC'
211219
oncid = nc.Dataset(out_file, mode='w', format=ncfmt, parallel=parallel, comm=comm, info=info)
212220
#
213-
if (verbose):
214-
print(rank, 'oncid ', oncid, flush=True)
215-
#
216221
####################################################################
217222
#
218223
# Copy/update global attributes, except excluded ones
@@ -263,7 +268,7 @@ def nemo_rebuild(in_file=None,
263268
print(dim)
264269
if dim.isunlimited():
265270
oncid.createDimension(dim.name, None)
266-
elif (dim.size in ldimszs):
271+
elif (dim.size in ldimszs and isgdim(dim.name)):
267272
idx = 0 if ldimszs[0]==dim.size else 1
268273
oncid.createDimension(dim.name, gdimszs[idx])
269274
gdims[idx] = dim.name
@@ -310,6 +315,9 @@ def nemo_rebuild(in_file=None,
310315
#
311316
del in_file0
312317
#
318+
if (verbose):
319+
print(rank, 'oncid ', oncid, flush=True)
320+
#
313321
####################################################################
314322
#
315323
remgrp = None
@@ -410,7 +418,8 @@ def nemo_rebuild(in_file=None,
410418
raise RuntimeError('Error with index!')
411419
#
412420
#if (bnd):
413-
# print(rank, niter, 'POST', gi1,gi2,gj1,gj2,li1,li2,lj1,lj2, lnx, lny, flush=True)
421+
#if (verbose):
422+
# print('IDXs: ', rank, niter, gi1,gi2,gj1,gj2,li1,li2,lj1,lj2, lnx, lny, flush=True)
414423
#
415424
################################################################
416425
#
@@ -421,9 +430,8 @@ def nemo_rebuild(in_file=None,
421430
print('\n', rank, niter, name, var, flush=True)
422431
#
423432
ovid = oncid.variables[name]
424-
# Set collective I/O mode
425433
if (parallel):
426-
ovid.set_collective(True)
434+
ovid.set_collective(True) # Set collective I/O mode
427435
#
428436
# Variables to be rebuilt
429437
if (gdims[0] in var.dimensions and gdims[1] in var.dimensions):

0 commit comments

Comments
 (0)