"""Copyright (c) 2024 MPI-M, Clara Bayley----- CLEO -----File: pysetuptxt.pyProject: sdmout_srcCreated Date: Tuesday 24th October 2023Author: Clara Bayley (CB)Additional Contributors:-----Last Modified: Tuesday 7th May 2024Modified By: CB-----License: BSD 3-Clause "New" or "Revised" Licensehttps://opensource.org/licenses/BSD-3-Clause-----File Description:functions for reading setup.txt fileoutput alongside zarr storage"""from..importcxx2py
[docs]defget_consts(setuptxt,isprint=True):"""returns dictionary of constants read from from setup.txt file"""returnconsts_dict(setuptxt,isprint=isprint)
[docs]defget_config(setuptxt,nattrs=3,isprint=True):"""returns dictionary of configuration parameters read from from setup.txt file"""returnconfig_dict(setuptxt,nattrs=nattrs,isprint=isprint)
[docs]defread_configparams_fromsetuptxt_into_floats(filename):"""returns dictionary of value: float from values assigned in a config .txt file. Also returns dictionary of notfloats for values that couldn't be converted."""floats={}notfloats={}withopen(filename)asfile:rlines=[]filelines=file.readlines()forlineinfilelines:if(line[0]!="#")and(line[0]!="/")and(":"inline):goodline=cxx2py.remove_excess_line(line)rlines.append(goodline)forlineinrlines:ind=line.find(":")name=line[:ind]value=line[ind+1:]try:floats[name]=float(value)exceptValueError:notfloats[name]=valuetry:floats["nspacedims"]=int(floats["nspacedims"])# no spatial coords to SDsexceptKeyErrorase:print("Warning, ignoring error",e)passreturnfloats