Function that autogenerates PRINTF statements for binaryc. intput is a dictionary where the key is the header of that logging line and items which are lists of parameters\
that will be put in that logging line
Example::
{'MY_STELLAR_DATA':
[
'model.time',
'star[0].mass',
'model.probability',
'model.dt'
]
}
"""
# Check if the input is of the correct form
ifnottype(logging_dict)==dict:
print("Error: please use a dictionary as input")
returnNone
code=""
# Loop over dict keys
forkeyinlogging_dict:
logging_dict_entry=logging_dict[key]
# Check if item is of correct type:
iftype(logging_dict_entry)==list:
# Construct print statement
code+='Printf("{}'.format(key)
code+=" {}".format("%g "*len(logging_dict_entry))
code=code.strip()
code+='\\n"'
# Add format keys
forparaminlogging_dict_entry:
code+=",((double)stardata->{})".format(param)
code+=");\n"
else:
print(
"Error: please use a list for the list of parameters that you want to have logged"
)
code=code.strip()
# print("MADE AUTO CODE\n\n{}\n\n{}\n\n{}\n".format('*'*60, repr(code), '*'*60))