@@ -160,7 +160,7 @@ class NLVar:
160160 """Class to hold information about a namelist variable entry"""
161161
162162 # For unique dimension names
163- __new_dim_suffix = 0
163+ __new_dim_suffix = {}
164164
165165 # For validity error messages
166166 __kind_errstr = "Conflicting kind arguments, '{}' and '{}' for '{}'"
@@ -327,9 +327,9 @@ def _parse_array_desc(cls, alen, name):
327327 should have been sanitized by _parse_xml_type.
328328
329329 >>> NLVar._parse_array_desc("10", "foo")
330- ((10,), ('cam_nl_autogen1_dimension ',))
330+ ((10,), ('foo_dimension ',))
331331 >>> NLVar._parse_array_desc("15,3", "bar")
332- ((15, 3), ('cam_nl_autogen2_dimension ', 'cam_nl_autogen3_dimension '))
332+ ((15, 3), ('bar_dimension ', 'bar_dimension_2 '))
333333 >>> NLVar._parse_array_desc("15,,3", "foobar")
334334 Traceback (most recent call last):
335335 ...
@@ -338,7 +338,7 @@ def _parse_array_desc(cls, alen, name):
338338 if alen :
339339 try :
340340 alens = tuple ([int (x .strip ()) for x in alen .split (',' )])
341- anames = tuple ([cls ._new_nl_dimname () for x in alens ])
341+ anames = tuple ([cls ._new_nl_dimname (name ) for x in alens ])
342342 except :
343343 emsg = f"Invalid array argument, '{ alen } ', for { name } "
344344 raise ParseInternalError (emsg )
@@ -462,10 +462,23 @@ def write_decl(self, file, indent, intent=None):
462462 file .write (decl , indent )
463463
464464 @classmethod
465- def _new_nl_dimname (cls ):
465+ def _new_nl_dimname (cls , var_name ):
466466 """Return a new dimension name for use with a namelist array variable"""
467- cls .__new_dim_suffix += 1
468- return f"cam_nl_autogen{ cls .__new_dim_suffix } _dimension"
467+
468+ # Update number of dimensions for the
469+ # specified namelist variable:
470+ if var_name in cls .__new_dim_suffix :
471+ cls .__new_dim_suffix [var_name ] += 1
472+ else :
473+ cls .__new_dim_suffix [var_name ] = 1
474+
475+ # Create new dimension name based
476+ # on the variable name and number of
477+ # variable dimensions:
478+ if cls .__new_dim_suffix [var_name ] > 1 :
479+ return f"{ var_name } _dimension_{ cls .__new_dim_suffix [var_name ]} "
480+ else :
481+ return f"{ var_name } _dimension"
469482
470483 def var_mpi_type (self ):
471484 """Return the MPI variable type constant of this NLVar object.
@@ -483,7 +496,7 @@ def write_dimension_decls(self, ofile, indent):
483496 """
484497 for index , alen in enumerate (self .array_len ):
485498 aname = self .__array_names [index ]
486- ofile .write (f"integer, parameter :: { aname } = { alen } " , indent )
499+ ofile .write (f"integer, public, parameter :: { aname } = { alen } " , indent )
487500 # end for
488501
489502 @property
0 commit comments