@@ -447,12 +447,45 @@ def writeInitCSV(initValues, filename):
447447# initValues = dictionary of Musica varnames and (WACCM name, value, units)
448448def writeInitJSON (initValues , filename ):
449449
450- # set up dictionary of vars and initial values
451- dictName = "chemical species "
450+ # set up dictionary of CSV files and JSON initial values
451+ dictName = "conditions "
452452 initConfig = {dictName : {}}
453453
454+ # two sections of conditions
455+ dataName = "data"
456+ pathsName = "filepaths"
457+ initConfig [dictName ][dataName ] = []
458+ initConfig [dictName ][pathsName ] = []
459+
460+ # build the column headers
461+ headerList = []
454462 for key , value in initValues .items ():
455- initConfig [dictName ][key ] = {f"initial value [{ value [unitIndex ]} ]" : value [valueIndex ]}
463+ reaction_type = "CONC"
464+ if isSystem (key ):
465+ reaction_type = None
466+ if isEnvironment (key ):
467+ reaction_type = "ENV"
468+
469+ titleString = conditions_manager .ConditionsManager .format_reaction_var_units (
470+ key , units = value [unitIndex ], prefix = reaction_type )
471+ headerList .append (titleString )
472+
473+ # build the rows of chemical concentrations
474+ concArray = []
475+ firstColumn = next (iter (initValues .items ()))
476+ numDataRows = len (firstColumn [1 ][valueIndex ])
477+ logger .debug (f"numDataRows = { numDataRows } " )
478+ for ri in range (numDataRows ):
479+ # write the variable values
480+ oneRow = []
481+ for key , value in initValues .items ():
482+ oneRow .append (value [valueIndex ][ri ])
483+ concArray .append (oneRow )
484+
485+ # create row of variables and units
486+ headersName = "headers"
487+ rowsName = "rows"
488+ initConfig [dictName ][dataName ].append ({headersName : headerList , rowsName : concArray })
456489
457490 # write JSON content to the file
458491 fpJson = open (filename , "w" )
0 commit comments