Index: /issm/trunk-jpl/src/m/contrib/musselman/write_netCDF_commit.py
===================================================================
--- /issm/trunk-jpl/src/m/contrib/musselman/write_netCDF_commit.py	(revision 27833)
+++ /issm/trunk-jpl/src/m/contrib/musselman/write_netCDF_commit.py	(revision 27834)
@@ -1,3 +1,4 @@
 # imports
+import netCDF4
 from netCDF4 import Dataset
 import numpy as np
@@ -6,4 +7,5 @@
 from os import path, remove
 from model import *
+from results import *
 
 
@@ -37,8 +39,44 @@
     # Walk through the model_var class and compare subclass states to empty_model
     walk_through_model(model_var, model_name)
-    
+
+    # in order to handle some subclasses in the results class, we have to utilize this band-aid
+    # there will likely be more band-aids added unless a class name library is created with all class names that might be added to a model
+    try:
+        # if results has meaningful data, save the name of the subclass and class instance
+        NetCDF.groups['results']
+        results_subclasses_bandaid(model_var)
+        # otherwise, ignore
+    except KeyError:
+        pass
+        
     NetCDF.close()
     print('Model successfully saved as NetCDF4')
     
+
+
+def results_subclasses_bandaid(model_var):
+    # since the results class may have nested classes within it, we need to record the name of the 
+    # nested class instance variable as it appears in the model that we're trying to save
+    quality_control = []
+    for class_instance_name in model_var.results.__dict__.keys():
+        # for each class instance in results, see which class its from and record that info in the netcdf to recreate structure later
+        # check to see if there is a solutionstep class instance
+        if isinstance(model_var.results.__dict__[class_instance_name],solutionstep):
+            quality_control.append(1)
+            write_string_to_netcdf(variable_name=str('solutionstep'), adress_of_child=str(class_instance_name), group=NetCDF.groups['results'])
+        # check to see if there is a solution class instance
+        if isinstance(model_var.results.__dict__[class_instance_name],solution):
+            quality_control.append(1)
+            write_string_to_netcdf(variable_name=str('solution'), adress_of_child=str(class_instance_name), group=NetCDF.groups['results'])
+        # check to see if there is a resultsdakota class instance
+        if isinstance(model_var.results.__dict__[class_instance_name],resultsdakota):
+            quality_control.append(1)
+            write_string_to_netcdf(variable_name=str('resultsdakota'), adress_of_child=str(class_instance_name), group=NetCDF.groups['results'])
+    if len(quality_control) != len(model_var.results.__dict__.keys()):
+        print('Error: The class instance within your model.results class is not currently supported by this application')
+        print(type(model_var.results.__dict__[class_instance_name]))
+    else:
+        print('The results class was successfully stored on disk')
+
 
     
@@ -82,6 +120,6 @@
     try:
         # enter the subclass, see if it has nested classes and/or attributes
-        # then compare attribute states between models and write to netCDF if they differ
-        # repeat starting from new location
+        # then compare attributes between models and write to netCDF if they differ
+        # if subclass found, walk through it and repeat
         for child in eval(adress + '.__dict__.keys()'):
             # make a string variable so we can send thru this func again
@@ -89,13 +127,20 @@
             # If the attribute is unchanged, move onto the next layer
             adress_of_child_in_empty_class = 'empty_model' + adress_of_child.removeprefix(str(model_name))
-            if type(child) == type(eval(adress_of_child_in_empty_class)):
-                walk_through_subclasses(model_var, adress_of_child, model_name)
-            # If it has been modified, record it in the NetCDF file
-            else:
+            # using try/except here because sometimes a model can have class instances/attributes that are not 
+            # in the framework of an empty model. If this is the case, we move to the except statement
+            try:
+                if type(child) == type(eval(adress_of_child_in_empty_class)):
+                    walk_through_subclasses(model_var, adress_of_child, model_name)
+                # If it has been modified, record it in the NetCDF file
+                else:
+                    create_group(model_var, adress_of_child)
+                    walk_through_subclasses(model_var, adress_of_child, model_name)
+            except AttributeError:
                 create_group(model_var, adress_of_child)
                 walk_through_subclasses(model_var, adress_of_child, model_name)
-    except: pass
-
- 
+    except Exception as e: print(e)
+
+
+        
 def create_group(model_var, adress_of_child):
     # start by splitting the adress_of_child into its components
@@ -133,22 +178,23 @@
         variable = group.createVariable(variable_name, float, ('float',))
         variable[:] = eval(adress_of_child)
-        
+
     # or a string
     elif isinstance(eval(adress_of_child), str):
         write_string_to_netcdf(variable_name, adress_of_child, group)
         
-    # or a list of strings -- this needs work as it can only handle a list of 1 string
-    elif isinstance(eval(adress_of_child)[0],str):
-        for string in eval(adress_of_child):
-            write_string_to_netcdf(variable_name, string, group)
-        
-    # or a list
-    elif isinstance(eval(adress_of_child), list):
-        variable = group.createVariable(variable_name, type(eval(adress_of_child)[0]), ('Unlim',))
-        variable[:] = eval(adress_of_child)
-        
     # or an empty list
     elif isinstance(eval(adress_of_child), list) and len(eval(adress_of_child))==0:
         variable = group.createVariable(variable_name, int, ('int',))
+
+    # or a list of strings -- this needs work as it can only handle a list of 1 string
+    elif isinstance(eval(adress_of_child),list) and isinstance(eval(adress_of_child)[0],str):
+        for string in eval(adress_of_child):
+            write_string_to_netcdf(variable_name, string, group)
+
+    # or a regular list
+    elif isinstance(eval(adress_of_child), list):
+        print(eval(adress_of_child))
+        variable = group.createVariable(variable_name, type(eval(adress_of_child)[0]), ('Unlim',))
+        variable[:] = eval(adress_of_child)
 
     # anything else... (will likely need to add more cases; ie dict)
@@ -163,4 +209,6 @@
     print('Successfully transferred data from ' + adress_of_child + ' to the NetCDF')
     
+
+
 
 def write_string_to_netcdf(variable_name, adress_of_child, group):
@@ -171,5 +219,5 @@
         length_of_the_string = len(the_string_to_save)
         numpy_datatype = 'S' + str(length_of_the_string)
-        str_out = netCDF4.stringtochar(np.array(['the_string_to_save'], dtype=numpy_datatype))
+        str_out = netCDF4.stringtochar(np.array([the_string_to_save], dtype=numpy_datatype))
     #otherwise we need to treat it like a string:
     except: 
@@ -177,15 +225,15 @@
         length_of_the_string = len(the_string_to_save)
         numpy_datatype = 'S' + str(length_of_the_string)
-        str_out = netCDF4.stringtochar(np.array(['the_string_to_save'], dtype=numpy_datatype))        
+        str_out = netCDF4.stringtochar(np.array([the_string_to_save], dtype=numpy_datatype))        
 
     # we'll need to make a new dimension for the string if it doesn't already exist
+    name_of_dimension = 'char' + str(length_of_the_string)
     try: 
-        name_of_dimension = 'char' + str(length_of_the_string)
         group.createDimension(name_of_dimension, length_of_the_string)
     except: pass
     # now we can make a variable in this dimension:
-    string = group.createVariable(variable_name, 'S1', ('nchar'))
+    string = group.createVariable(variable_name, 'S1', (name_of_dimension))
     #finally we can write the variable:
-    string[:] = the_string_to_save    
+    string[:] = str_out
 
 
