The CDAT software was developed by LLNL. This tutorial was written by Charles Doutriaux. This work was performed under the auspices of the U.S. Department of Energy by Lawrence Livermore National Laboratory under Contract DE-AC52-07NA27344.
import genutil
# Define your string template
file_template = "%(path)/%(variable).%(model).nc"
# Create a StringConstructor object
S = genutil.StringConstructor(file_template)
# Fill the StringConstructor with the values for each key
S.path = "blah"
S.variable = "tas"
S.model= "CNRM"
my_path = S()
print("My file path is:",my_path)
# You can also pass keys at retrieval time
print("My file path for variable 'pr' is:",S(variable="pr"))
# You can easily loop through keys like this:
for model in ["modelA","modelB","modelC"]:
for variable in ["tas","pr","zg","u","v"]:
S.model = model
path = S(variable=variable)
print("PATH IS:",path)
# in some case you can even reverse ingeneer
print("key/values pairs:",S.reverse(path))